{.% include intro.html %}

ToadGenerators Class Reference

#import <ToadGenerators.h>

List of all members.

Static Public Member Functions

(Generator) + infiniteSequentialInts
(Generator) + rangeFrom:to:
(Generator) + NSArraySeq:
(Generator) + NSDictionarySeq:
(Generator) + Primes

Detailed Description

Generators are blocks that provide the original source of data for the transformations.

Each block is of the form ^id(BOOL *end). Each time they are called they will return the next value in the sequence and will set *end to be NO. When they have run out of data they will set *end to be YES. They should also return nil - although this should not be relied on.

Note that not all generators will end. For example to infiniteSequentialInts will carry on (its behaviour will be undefined at MaxInt.) It is up to you to make sure you only take as many values as you need.


Member Function Documentation

+ (Generator) infiniteSequentialInts 

Returns an infinite sequence of ints. Will be undefined when it gets to MaxInt. Note the sequence is of objects of type NSNumber. If you need to do arithmetic with the values then use the intValue property of the values.

Returns:
The generator
+ (Generator) NSArraySeq:(NSArray *) arr 

Returns a sequence of the elements of the array.

Parameters:
arr The array containing the elements to create the sequence from
Returns:
The generator
+ (Generator) NSDictionarySeq:(NSDictionary *) dict 

Returns a sequence of the keys of the dictionary.

Parameters:
dict The dictionary
Returns:
The generator
+ (Generator) Primes 

Returns an infinite (subject to memory and time) sequence of prime numbers

Returns:
The generator
+ (Generator) rangeFrom:(int) from
to:(int) to 

Returns a seqence of integers between from and to.

Parameters:
from Start the sequence from this number
to End the sequence after the number.
Returns:
The generator

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

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:
  • /Users/stephenwakely/src/ToadSeq/ToadSeq/ToadSeq.h
  • /Users/stephenwakely/src/ToadSeq/ToadSeq/ToadSeq.m