#import <ToadSeq.h>
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 |
Concatenate this sequence with the given one. The sequence is still accessed lazily.
seq | The sequence to concatenate with. |
- (ToadSeq *) filter: | (Predicate) | predicate |
Remove all the items from the sequence where the predicate returns false.
predicate | A block that takes an element of the sequence and returns True if the value should be in the resulting sequence |
- (ToadSeq *) foldl: | (Fold) | transform |
Folds from the left of the sequence. The accumulator starts with the first item in the sequence
transform | A block that takes the accumulated value and the next element of the sequence. The accumulated value should be returned from the block. |
- (ToadSeq *) foldl: | (Fold) | transform | ||
startingWith: | (id) | start | ||
Folds from the left of the sequence. The accumulator starts as the startWith parameter passed in.
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. |
- (void) forEach: | (Action) | action |
Loops over the sequence and calls the action block, presumably for sideeffects.
action | Block to act on each element |
- (void) forEach: | (Action) | action | ||
fromGenerator: | (Generator) | gen | ||
- (id) getNext |
Returns the next element of the sequence.
- (BOOL) hasMore |
Return YES if there are more elements available in the sequence.
- (id) initWithGenerator: | (Generator) | generator |
Initialise the sequence with a Generator.
A generator is a block of type ^id(BOOL *end).
generator | A ToadGenerator - the block which pumps out the initial sequence |
- (ToadSeq *) map: | (SimpleTransform) | transform |
Transform all the elements of the sequence to the values transformed by the action.
transform | A block that takes one element and returns the transformed element |
- (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.
- (ToadSeq *) skip: | (int) | howMany |
Ignore the first n elements from the sequence
howMany | How many items to ignore. |
- (ToadSeq *) take: | (int) | howMany |
Return only the first n elements from the sequence.
howMany | How many items to take from the sequence |
- (ToadSeq *) takeWhile: | (Predicate) | predicate |
Continue returning elements from the sequence until the predicate returns false.
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. |
- (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).
- (NSArray *) toArrayFromGenerator: | (Generator) | gen |
+ (ToadSeq *) withGenerator: | (Generator) | generator |
- (id) cachedNext [read, write, assign] |
- (Generator) generator [read, write, copy] |
- (BOOL) nextValueCached [read, write, assign] |
- (NSMutableArray*) transforms [read, write, assign] |