ToadSeq Class Reference

#import <ToadSeq.h>

List of all members.

Public Member Functions

(id) - initWithGenerator:
(BOOL) - hasMore
(id) - getNext
(NSArray *) - toArray
(void) - forEach:
(ToadSeq *) - map:
(ToadSeq *) - foldl:startingWith:
(ToadSeq *) - foldl:
(ToadSeq *) - filter:
(ToadSeq *) - skip:
(ToadSeq *) - take:
(ToadSeq *) - takeWhile:
(ToadSeq *) - concatWith:
(ToadSeq *) - reverse
(NSArray *) - toArrayFromGenerator:
(void) - forEach:fromGenerator:

Static Public Member Functions

(ToadSeq *) + withGenerator:

Properties

Generator generator
id cachedNext
BOOL nextValueCached
NSMutableArray * transforms

Member Function Documentation

- (ToadSeq *) concatWith: (ToadSeq *)  seq  

Concatenate this sequence with the given one. The sequence is still accessed lazily.

Parameters:
seq The sequence to concatenate with.
Returns:
The ToadSeq object so further transformations can be added
- (ToadSeq *) filter: (Predicate)  predicate  

Remove all the items from the sequence where the predicate returns false.

Parameters:
predicate A block that takes an element of the sequence and returns True if the value should be in the resulting sequence
Returns:
The ToadSeq object so further transformations can be added
- (ToadSeq *) foldl: (Fold)  transform  

Folds from the left of the sequence. The accumulator starts with the first item in the sequence

Parameters:
transform A block that takes the accumulated value and the next element of the sequence. The accumulated value should be returned from the block.
Returns:
The ToadSeq object so further transformations can be added
- (ToadSeq *) foldl: (Fold)  transform
startingWith: (id)  start 

Folds from the left of the sequence. The accumulator starts as the startWith parameter passed in.

Parameters:
transform A block that takes the accumulated value and the next element of the sequence. The accumulated value should be returned from the block.
start The value to initialise the accumulated value as.
Returns:
The ToadSeq object so further transformations can be added
- (void) forEach: (Action)  action  

Loops over the sequence and calls the action block, presumably for sideeffects.

Parameters:
action Block to act on each element
- (void) forEach: (Action)  action
fromGenerator: (Generator)  gen 
- (id) getNext  

Returns the next element of the sequence.

Returns:
The next element
- (BOOL) hasMore  

Return YES if there are more elements available in the sequence.

Returns:
Are the more elements available
- (id) initWithGenerator: (Generator)  generator  

Initialise the sequence with a Generator.

A generator is a block of type ^id(BOOL *end).

Parameters:
generator A ToadGenerator - the block which pumps out the initial sequence
Returns:
ToadSeq
- (ToadSeq *) map: (SimpleTransform)  transform  

Transform all the elements of the sequence to the values transformed by the action.

Parameters:
transform A block that takes one element and returns the transformed element
Returns:
The ToadSeq object so further transformations can be added
- (ToadSeq *) reverse  

Reverses the sequence. Be careful with this one as the whole sequence has to be loaded into memory in order to reverse it.

Will NOT work with infinite sequences.

Returns:
<return value description#>
- (ToadSeq *) skip: (int)  howMany  

Ignore the first n elements from the sequence

Parameters:
howMany How many items to ignore.
Returns:
The ToadSeq object so further transformations can be added
- (ToadSeq *) take: (int)  howMany  

Return only the first n elements from the sequence.

Parameters:
howMany How many items to take from the sequence
Returns:
The ToadSeq object so further transformations can be added
- (ToadSeq *) takeWhile: (Predicate)  predicate  

Continue returning elements from the sequence until the predicate returns false.

Parameters:
predicate A predicate with takes an element of the sequence and returns true if we should continue taking items. When we return False, the sequence ends.
Returns:
The ToadSeq object so further transformations can be added
- (NSArray *) toArray  

Returns an array containing the results of the sequence. Do not call for infinite sequences - it will never return (but will run out of memory).

Returns:
An array of the sequence
- (NSArray *) toArrayFromGenerator: (Generator)  gen  
+ (ToadSeq *) withGenerator: (Generator)  generator  

Property Documentation

- (id) cachedNext [read, write, assign]
- (Generator) generator [read, write, copy]
- (BOOL) nextValueCached [read, write, assign]
- (NSMutableArray*) transforms [read, write, assign]

The documentation for this class was generated from the following files: