diff --git a/Example.md b/Example.md index b611c81..2217586 100644 --- a/Example.md +++ b/Example.md @@ -7,7 +7,7 @@ MOGTransformation Trim(NSUInteger drop, NSUInteger finalSize) return MOGCompose(MOGDrop(drop), MOGTake(finalSize)); } -MOGMapBlock SortArrayOfNumbers(BOOL ascending) +MOGMapFunc SortArrayOfNumbers(BOOL ascending) { NSSortDescriptor *lowestToHighest = [NSSortDescriptor sortDescriptorWithKey:@"self" ascending:ascending]; @@ -16,14 +16,14 @@ MOGMapBlock SortArrayOfNumbers(BOOL ascending) }; } -MOGMapBlock TrimArray(NSUInteger trimN) +MOGMapFunc TrimArray(NSUInteger trimN) { return ^id(NSArray *values) { return [values mog_transduce:TrimTransducer(trimN, values.count - 2 * trimN)]; }; } -MOGMapBlock MeanOfArrayOfNumbers() +MOGMapFunc MeanOfArrayOfNumbers() { return ^id(NSArray *numbers) { return [numbers valueForKeyPath:@"@avg.self"]; @@ -54,7 +54,7 @@ NSNumber *number = MOGTransform(array, MOGLastValueReducer(), @0, filter); // number == 7.5 // Or we can simulate the numbers coming in from a stream and manually feed numbers to the filter. -MOGMapBlock manualFilter = MOGValueTransformer(filter); +MOGMapFunc manualFilter = MOGValueTransformer(filter); number = manualFilter(@14); // number == 14 number = manualFilter(@13); // number == 14 diff --git a/MogKit/MogReduce.h b/MogKit/MogReduce.h index 5f5a931..19ab281 100644 --- a/MogKit/MogReduce.h +++ b/MogKit/MogReduce.h @@ -10,13 +10,13 @@ /** * Block that generates the initial value of a reduction. */ -typedef id (^MOGReducerInititialBlock) (void); +typedef id (^MOGReducerInititialFunc) (void); /** * Block that is called by `MOGTransform` after a reduction is done, this to allow step functions or the * collection `MOGReducer` to do some final manipulation of the data. */ -typedef id (^MOGReducerCompleteBlock) (id); +typedef id (^MOGReducerCompleteFunc) (id); /** * A reduce block is passed to `MOGReduce` and is used to collect the accumulated value of the @@ -25,16 +25,16 @@ typedef id (^MOGReducerCompleteBlock) (id); * * Set stop to YES to terminate the reduction. */ -typedef id (^MOGReduceBlock) (id acc, id val, BOOL *stop); +typedef id (^MOGReduceFunc) (id acc, id val, BOOL *stop); /** * A reducer takes an accumulated value and the next value and combines them into a new accumulated value. * The return accumulated value is typically passed in as `acc` on successive calls. */ @interface MOGReducer : NSObject -@property (nonatomic, copy) MOGReduceBlock reduce; -@property (nonatomic, copy) MOGReducerInititialBlock initial; -@property (nonatomic, copy) MOGReducerCompleteBlock complete; +@property (nonatomic, copy) MOGReduceFunc reduce; +@property (nonatomic, copy) MOGReducerInititialFunc initial; +@property (nonatomic, copy) MOGReducerCompleteFunc complete; /** * Initialize a `MOGReducer` with blocks to create initial value, completion handler and reduce block. @@ -48,9 +48,9 @@ typedef id (^MOGReduceBlock) (id acc, id val, BOOL *stop); * * @return the reducer * */ -- (instancetype)initWithInitBlock:(MOGReducerInititialBlock)initBlock - completeBlock:(MOGReducerCompleteBlock)completeBlock - reduceBlock:(MOGReduceBlock)reduceBlock; +- (instancetype)initWithInitBlock:(MOGReducerInititialFunc)initBlock + completeBlock:(MOGReducerCompleteFunc)completeBlock + reduceBlock:(MOGReduceFunc)reduceBlock; /** * Class method to create a step reducer (used when implementing transformations). @@ -59,7 +59,7 @@ typedef id (^MOGReduceBlock) (id acc, id val, BOOL *stop); * * @return a newly created step reducer. */ -+ (instancetype)stepReducerWithNextReducer:(MOGReducer *)nextReducer reduceBlock:(MOGReduceBlock)reduceBlock; ++ (instancetype)stepReducerWithNextReducer:(MOGReducer *)nextReducer reduceBlock:(MOGReduceFunc)reduceBlock; /** * Class method to create a step reducer (used when implementing transformations). Use this when the transformation @@ -73,8 +73,8 @@ typedef id (^MOGReduceBlock) (id acc, id val, BOOL *stop); * @return a newly created step reducer. */ + (instancetype)stepReducerWithNextReducer:(MOGReducer *)nextReducer - reduceBlock:(MOGReduceBlock)reduceBlock - completeBlock:(MOGReducerCompleteBlock)completeBlock; + reduceBlock:(MOGReduceFunc)reduceBlock + completeBlock:(MOGReducerCompleteFunc)completeBlock; @end @@ -86,7 +86,7 @@ typedef id (^MOGReduceBlock) (id acc, id val, BOOL *stop); * @param reduceBlock called for each value in the reduction. * */ -MOGReducer *MOGSimpleReducer(MOGReduceBlock reduceBlock); +MOGReducer *MOGSimpleReducer(MOGReduceFunc reduceBlock); /** * A reducer that accumulates values in an array. If the reducer initial block isn't used to produce the @@ -124,4 +124,4 @@ MOGReducer *MOGStringConcatReducer(NSString *separator); * * @return returns the final return value of `reduceBlock`. */ -id MOGReduce(id source, MOGReduceBlock reduceBlock, id initial); \ No newline at end of file +id MOGReduce(id source, MOGReduceFunc reduceBlock, id initial); \ No newline at end of file diff --git a/MogKit/MogReduce.m b/MogKit/MogReduce.m index 027e5cd..35071e1 100644 --- a/MogKit/MogReduce.m +++ b/MogKit/MogReduce.m @@ -7,7 +7,7 @@ #import "MogReduce.h" -MOGReducer *MOGSimpleReducer(MOGReduceBlock reduceBlock) +MOGReducer *MOGSimpleReducer(MOGReduceFunc reduceBlock) { return [[MOGReducer alloc] initWithInitBlock:^id { return nil; } completeBlock:^id(id accumulated) { return accumulated; } @@ -54,7 +54,7 @@ }]; } -id MOGReduce(id source, MOGReduceBlock reduceBlock, id initial) +id MOGReduce(id source, MOGReduceFunc reduceBlock, id initial) { id acc = initial; @@ -71,9 +71,9 @@ id MOGReduce(id source, MOGReduceBlock reduceBlock, id initia @implementation MOGReducer -- (instancetype)initWithInitBlock:(MOGReducerInititialBlock)initBlock - completeBlock:(MOGReducerCompleteBlock)completeBlock - reduceBlock:(MOGReduceBlock)reduceBlock +- (instancetype)initWithInitBlock:(MOGReducerInititialFunc)initBlock + completeBlock:(MOGReducerCompleteFunc)completeBlock + reduceBlock:(MOGReduceFunc)reduceBlock { if (self = [super init]) { self.initial = initBlock; @@ -84,7 +84,7 @@ - (instancetype)initWithInitBlock:(MOGReducerInititialBlock)initBlock return self; } -+ (instancetype)stepReducerWithNextReducer:(MOGReducer *)nextReducer reduceBlock:(MOGReduceBlock)reduceBlock ++ (instancetype)stepReducerWithNextReducer:(MOGReducer *)nextReducer reduceBlock:(MOGReduceFunc)reduceBlock { return [self stepReducerWithNextReducer:nextReducer reduceBlock:reduceBlock @@ -94,8 +94,8 @@ + (instancetype)stepReducerWithNextReducer:(MOGReducer *)nextReducer reduceBlock } + (instancetype)stepReducerWithNextReducer:(MOGReducer *)nextReducer - reduceBlock:(MOGReduceBlock)reduceBlock - completeBlock:(MOGReducerCompleteBlock)completeBlock + reduceBlock:(MOGReduceFunc)reduceBlock + completeBlock:(MOGReducerCompleteFunc)completeBlock { return [[self alloc] initWithInitBlock:^id { return nextReducer.initial(); } completeBlock:completeBlock diff --git a/MogKit/MogTransformation.h b/MogKit/MogTransformation.h index 6521dbe..543ef05 100644 --- a/MogKit/MogTransformation.h +++ b/MogKit/MogTransformation.h @@ -18,10 +18,10 @@ typedef MOGReducer *(^MOGTransformation) (MOGReducer *); /** - * A `MOGMapBlock` is a function you typically use with `MOGMap` which is a transformation of a single value + * A `MOGMapFunc` is a function you typically use with `MOGMap` which is a transformation of a single value * into a new value. */ -typedef id (^MOGMapBlock) (id val); +typedef id (^MOGMapFunc) (id val); /** * `MOGPredicate` is a function that by examining the value returns YES or NO. It's typically used in `MOGFilter` or @@ -44,7 +44,7 @@ MOGTransformation MOGIdentity(void); * * @return a transformation that applies the map transformation. */ -MOGTransformation MOGMap(MOGMapBlock mapBlock); +MOGTransformation MOGMap(MOGMapFunc mapBlock); /** * Creates a transformation that filters all values based on the `predicate` function. Values where `predicate` returns @@ -169,7 +169,7 @@ MOGTransformation MOGReplaceWithDefault(NSDictionary *replacements, id defaultVa * * @see `MOGFilter`, `MOGRemove`. */ -MOGTransformation MOGMapDropNil(MOGMapBlock mapBlock); +MOGTransformation MOGMapDropNil(MOGMapFunc mapBlock); /** * Creates a transformation that drops all duplicates. Whether it's a duplicate is determined by `isEqual:` @@ -208,7 +208,7 @@ MOGTransformation MOGFlatten(void); * * @return a transformation that applies `mapBlock` on all values and then concatenates the result. */ -MOGTransformation MOGFlatMap(MOGMapBlock mapBlock); +MOGTransformation MOGFlatMap(MOGMapFunc mapBlock); /** * Creates a transformation that splits the the values into separate `NSArray`s every time the `partitioningBlock` @@ -218,7 +218,7 @@ MOGTransformation MOGFlatMap(MOGMapBlock mapBlock); * * @return a stateful transformation that splits incoming values into separate partitions. */ -MOGTransformation MOGPartitionBy(MOGMapBlock partitioningBlock); +MOGTransformation MOGPartitionBy(MOGMapFunc partitioningBlock); /** * Creates a transformation that splits the values into separate `NSArray`s every `size` elements. A smaller array may be @@ -303,4 +303,4 @@ id MOGTransformWithInitial(id source, MOGReducer *reducer, id * * @return a function for transforming input values. */ -MOGMapBlock MOGValueTransformer(MOGTransformation transformation); +MOGMapFunc MOGValueTransformer(MOGTransformation transformation); diff --git a/MogKit/MogTransformation.m b/MogKit/MogTransformation.m index 03071ae..433c316 100644 --- a/MogKit/MogTransformation.m +++ b/MogKit/MogTransformation.m @@ -141,7 +141,7 @@ MOGTransformation MOGReplaceWithDefault(NSDictionary *replacements, id defaultVa }); } -MOGTransformation MOGMapDropNil(MOGMapBlock mapBlock) { +MOGTransformation MOGMapDropNil(MOGMapFunc mapBlock) { return MOGCompose(MOGMap(mapBlock), MOGDropNil()); } @@ -197,12 +197,12 @@ MOGTransformation MOGFlatten(void) }; } -MOGTransformation MOGFlatMap(MOGMapBlock mapBlock) +MOGTransformation MOGFlatMap(MOGMapFunc mapBlock) { return MOGCompose(MOGMap(mapBlock), MOGFlatten()); } -MOGTransformation MOGPartitionBy(MOGMapBlock partitioningBlock) { +MOGTransformation MOGPartitionBy(MOGMapFunc partitioningBlock) { return ^MOGReducer *(MOGReducer *reducer) { __block id lastPartitionKey = nil; __block NSMutableArray *currentPartition = [NSMutableArray new]; @@ -313,7 +313,7 @@ id MOGTransformWithInitial(id source, MOGReducer *reducer, id return tr.complete(MOGReduce(source, tr.reduce, initial)); } -MOGMapBlock MOGValueTransformer(MOGTransformation transformation) { +MOGMapFunc MOGValueTransformer(MOGTransformation transformation) { MOGReducer *reducer = transformation(MOGLastValueReducer()); return ^id(id val) { diff --git a/MogKit/NSArray+MogKit.h b/MogKit/NSArray+MogKit.h index 15b87ff..61c9cdc 100644 --- a/MogKit/NSArray+MogKit.h +++ b/MogKit/NSArray+MogKit.h @@ -42,7 +42,7 @@ * * @return a newly created array with the transformed values. */ -- (NSArray *)mog_map:(MOGMapBlock)mapBlock; +- (NSArray *)mog_map:(MOGMapFunc)mapBlock; /** * Convenience method for calling `-mog_transform:` with `MOGFilter`. diff --git a/MogKit/NSArray+MogKit.m b/MogKit/NSArray+MogKit.m index 222cb2d..bd18ff0 100644 --- a/MogKit/NSArray+MogKit.m +++ b/MogKit/NSArray+MogKit.m @@ -21,7 +21,7 @@ + (NSArray *)mog_transformedArrayFromEnumeration:(id)enumerat return MOGTransform(enumeration, MOGArrayReducer(), transformation); } -- (NSArray *)mog_map:(MOGMapBlock)mapBlock +- (NSArray *)mog_map:(MOGMapFunc)mapBlock { return [self mog_transform:MOGMap(mapBlock)]; } diff --git a/MogKitTests/MogTransformationTests.m b/MogKitTests/MogTransformationTests.m index 4cef511..079f6d8 100644 --- a/MogKitTests/MogTransformationTests.m +++ b/MogKitTests/MogTransformationTests.m @@ -502,7 +502,7 @@ - (void)testComposeArrayOfTransformations - (void)testTransformer { - MOGMapBlock add10 = MOGValueTransformer(MOGMap(^id(NSNumber *number) { + MOGMapFunc add10 = MOGValueTransformer(MOGMap(^id(NSNumber *number) { return @(number.intValue + 10); })); @@ -512,7 +512,7 @@ - (void)testTransformer - (void)testTransformerWithTerminatedTransformation { - MOGMapBlock add10TerminateAfter2 = MOGValueTransformer(MOGCompose(MOGTake(2), MOGMap(^id(NSNumber *number) { + MOGMapFunc add10TerminateAfter2 = MOGValueTransformer(MOGCompose(MOGTake(2), MOGMap(^id(NSNumber *number) { return @(number.intValue + 10); })));