blob: 568dbe657649189445176b662ede38a054684457 [file] [log] [blame]
Jorge Canizales30697c92015-02-17 17:09:14 -08001#import <Foundation/Foundation.h>
2
3#import "GRXWriter.h"
4
5// Utility to construct GRXWriter instances from values that are immediately available when
6// required. The returned writers all support pausing and early termination.
7//
8// Unless the writeable callback pauses them or stops them early, these writers will do all their
9// interactions with the writeable before the start method returns.
10@interface GRXImmediateWriter : NSObject<GRXWriter>
11
12// Returns a writer that pulls values from the passed NSEnumerator instance and pushes them to
13// its writeable. The NSEnumerator is released when it finishes.
14+ (id<GRXWriter>)writerWithEnumerator:(NSEnumerator *)enumerator;
15
16// Returns a writer that pushes to its writeable the successive values returned by the passed
17// block. When the block first returns nil, it is released.
18+ (id<GRXWriter>)writerWithValueSupplier:(id (^)())block;
19
20// Returns a writer that iterates over the values of the passed container and pushes them to
21// its writeable. The container is released when the iteration is over.
22//
23// Note that the usual speed gain of NSFastEnumeration over NSEnumerator results from not having to
24// call one method per element. Because GRXWriteable instances accept values one by one, that speed
25// gain doesn't happen here.
26+ (id<GRXWriter>)writerWithContainer:(id<NSFastEnumeration>)container;
27
28// Returns a writer that sends the passed value to its writeable and then finishes (releasing the
29// value).
30+ (id<GRXWriter>)writerWithValue:(id)value;
31
32// Returns a writer that, as part of its start method, sends the passed error to the writeable
33// (then releasing the error).
34+ (id<GRXWriter>)writerWithError:(NSError *)error;
35
36// Returns a writer that, as part of its start method, finishes immediately without sending any
37// values to its writeable.
38+ (id<GRXWriter>)emptyWriter;
39
40@end