home *** CD-ROM | disk | FTP | other *** search
- /***
- *
- * Iterator.prg
- * Sample array iterator functions
- * Copyright, Nantucket Corporation, 1990
- *
- * NOTE: compile with /n/w/a/m
- */
-
-
-
- /***
- * IEval( <nCount>, <bBlock> ) --> valueLast
- * Evaluate bBlock nCount times, passing it the current iteration (starting
- * at 1). Return the value the last iteration returns.
- */
- FUNCTION IEval( nCount, bBlock )
- LOCAL i, valResult
-
- FOR i := 1 TO nCount
- valResult := EVAL( bBlock, i )
- NEXT
-
- RETURN( valResult )
-
-
-
- /***
- * Collect( <aArray>, <bBlock> ) --> aResults
- * Evaluate bBlock on each element of aArray and store the results in
- * aResults
- */
- FUNCTION Collect( aArray, bBlock )
- LOCAL aResults[ LEN( aArray ) ]
- LOCAL nCount := 1
-
- AEVAL( aArray, { |element| aResults[nCount++] := EVAL( bBlock, element) } )
-
- RETURN( aResults )
-
-
-
- /***
- * Extract( <aArray>, <bMatch> ) --> aMatches
- * Returns the elements in aArray that match specified criteria. bMatch
- * is passed on element at a time and should return .T. if element matches
- * criteria, false otherwise.
- */
- FUNCTION Extract( aArray, bMatch )
- LOCAL aResults := {}
-
- AEVAL( aArray, {|element| IIF( EVAL( bMatch, element), AADD( aResults, element), NIL )} )
-
- RETURN( aResults )
-
-