FoundationExtension
FoundationExtension is common Foundation/UIKit/Cocoa shortcuts and snippets collection.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
NSAFunctional.h
Go to the documentation of this file.
1 //
2 // NSAFunctional.h
3 // FoundationExtension
4 //
5 // Created by Jeong YunWon on 12. 10. 30..
6 // Copyright (c) 2012 youknowone.org. All rights reserved.
7 //
8 
46 #import <Foundation/Foundation.h>
47 
49 
50 #if NS_BLOCKS_AVAILABLE
51 
55 typedef void (^NSAObjectProcedure)(id obj);
59 typedef void (^NSAObjectProcedureWithIndex)(id obj, NSUInteger index);
63 typedef void (^NSAObjectProcedureWithKey)(id obj, id key);
67 typedef id (^NSAObjectUnaryOperator)(id obj);
71 typedef id (^NSAObjectUnaryOperatorWithIndex)(id obj, NSUInteger index);
75 typedef id (^NSAObjectUnaryOperatorWithKey)(id obj, id key);
79 typedef BOOL (^NSAObjectPicker)(id obj);
83 typedef BOOL (^NSAObjectPickerWithIndex)(id obj, NSUInteger index);
87 typedef BOOL (^NSAObjectPickerWithKey)(id obj, id key);
91 typedef id (^NSAObjectBinaryOperator)(id obj1, id obj2);
92 
93 
99 FOUNDATION_EXTERN void NSAApply(id<NSFastEnumeration> enumerator, NSAObjectProcedure procedure);
100 
106 FOUNDATION_EXTERN void NSAApplyWithIndex(id<NSFastEnumeration> enumerator, NSAObjectProcedureWithIndex procedure);
107 
108 
115 FOUNDATION_EXTERN NSEnumerator *NSAMap(id<NSFastEnumeration> enumerator, NSAObjectUnaryOperator mapper);
116 
123 FOUNDATION_EXTERN NSEnumerator *NSAMapWithIndex(id<NSFastEnumeration> enumerator, NSAObjectUnaryOperatorWithIndex mapper);
124 
125 
134 FOUNDATION_EXTERN NSEnumerator *NSAMapFilter(NSEnumerator *enumerator, NSAObjectUnaryOperator mapper);
135 
144 FOUNDATION_EXTERN NSEnumerator *NSAMapFilterWithIndex(NSEnumerator *enumerator, NSAObjectUnaryOperatorWithIndex mapper);
145 
146 
153 FOUNDATION_EXTERN NSEnumerator *NSAFilter(NSEnumerator *enumerator, NSAObjectPicker filter);
154 
161 FOUNDATION_EXTERN NSEnumerator *NSAFilterWithIndex(NSEnumerator *enumerator, NSAObjectPickerWithIndex filter);
162 
163 
172 FOUNDATION_EXTERN id NSAReduce(NSEnumerator *enumerator, NSAObjectBinaryOperator operation);
173 
183 FOUNDATION_EXTERN id NSAReduceWithInitialObject(id<NSFastEnumeration> enumerator, NSAObjectBinaryOperator operation, id initialObject);
184 
185 
192 
198 - (void)applyProcedure:(NSAObjectProcedure)procedure;
199 
205 - (void)applyProcedureWithIndex:(NSAObjectProcedureWithIndex)procedure;
206 
212 - (NSArray *)arrayByMappingOperator:(NSAObjectUnaryOperator)mapper;
213 
219 - (NSArray *)arrayByMappingOperatorWithIndex:(NSAObjectUnaryOperatorWithIndex)mapper;
220 
226 - (NSArray *)arrayByMapFilteringOperator:(NSAObjectUnaryOperator)mapper;
227 
233 - (NSArray *)arrayByMapFilteringOperatorWithIndex:(NSAObjectUnaryOperatorWithIndex)mapper;
234 
240 - (NSArray *)arrayByFilteringOperator:(NSAObjectPicker)filter;
241 
247 - (NSArray *)arrayByFilteringOperatorWithIndex:(NSAObjectPickerWithIndex)filter;
248 
254 - (id)reduce:(NSAObjectBinaryOperator)reduce;
255 
261 - (id)reduce:(NSAObjectBinaryOperator)reduce initialObject:(id)initialObject;
262 
268 - (id)firstObjectByFilteringOperator:(NSAObjectPicker)filter;
269 
270 @end
271 
272 
279 
285 - (void)applyProcedure:(NSAObjectProcedure)procedure;
286 
292 - (void)applyProcedureWithIndex:(NSAObjectProcedureWithIndex)procedure;
293 
299 - (NSArray *)arrayByMappingOperator:(NSAObjectUnaryOperator)mapper;
300 
306 - (NSArray *)arrayByMappingOperatorWithIndex:(NSAObjectUnaryOperatorWithIndex)mapper;
307 
313 - (NSArray *)arrayByMapFilteringOperator:(NSAObjectUnaryOperator)mapper;
314 
320 - (NSArray *)arrayByMapFilteringOperatorWithIndex:(NSAObjectUnaryOperatorWithIndex)mapper;
321 
328 - (NSArray *)arrayByFilteringOperator:(NSAObjectPicker)filter;
329 
335 - (NSArray *)arrayByFilteringOperatorWithIndex:(NSAObjectPickerWithIndex)filter;
336 
342 - (id)reduce:(NSAObjectBinaryOperator)reduce;
343 
349 - (id)reduce:(NSAObjectBinaryOperator)reduce initialObject:(id)initialObject;
350 
356 - (id)firstObjectByFilteringOperator:(NSAObjectPicker)filter;
357 
363 - (id)firstObjectByFilteringOperatorWithIndex:(NSAObjectPickerWithIndex)filter;
364 
365 @end
366 
367 
374 
379 - (void)map:(NSAObjectUnaryOperator)mapper;
380 
385 - (void)mapWithIndex:(NSAObjectUnaryOperatorWithIndex)mapper;
386 
391 - (void)mapFilter:(NSAObjectUnaryOperator)mapper;
392 
397 - (void)mapFilterWithIndex:(NSAObjectUnaryOperatorWithIndex)mapper;
398 
403 - (void)filter:(NSAObjectPicker)filter;
404 
409 - (void)filterWithIndex:(NSAObjectPickerWithIndex)filter;
410 
411 @end
412 
413 
421 
427 - (void)applyProcedureWithKey:(NSAObjectProcedureWithKey)procedure;
428 
434 - (NSDictionary *)dictionaryByMappingOperator:(NSAObjectUnaryOperator)mapper;
435 
441 - (NSDictionary *)dictionaryByMappingOperatorWithKey:(NSAObjectUnaryOperatorWithKey)mapper;
442 
448 - (NSDictionary *)dictionaryByMapFilteringOperator:(NSAObjectUnaryOperator)mapper;
449 
455 - (NSDictionary *)dictionaryByMapFilteringOperatorWithKey:(NSAObjectUnaryOperatorWithKey)mapper;
456 
462 - (NSDictionary *)dictionaryByFilteringOperator:(NSAObjectPicker)filter;
463 
469 - (NSDictionary *)dictionaryByFilteringOperatorWithKey:(NSAObjectPickerWithKey)filter;
470 
476 - (id)firstObjectByFilteringOperator:(NSAObjectPicker)filter;
477 
483 - (id)firstObjectByFilteringOperatorWithKey:(NSAObjectPickerWithKey)filter;
484 
490 - (id)firstKeyByFilteringOperatorWithKey:(NSAObjectPickerWithKey)filter;
491 
492 @end
493 
494 
502 
507 - (void)map:(NSAObjectUnaryOperator)mapper;
508 
513 - (void)mapWithKey:(NSAObjectUnaryOperatorWithKey)mapper;
514 
519 - (void)mapFilter:(NSAObjectUnaryOperator)mapper;
520 
525 - (void)mapFilterWithKey:(NSAObjectUnaryOperatorWithKey)mapper;
526 
531 - (void)filter:(NSAObjectPicker)filter;
532 
537 - (void)filterWithKey:(NSAObjectPickerWithKey)filter;
538 
539 @end
540 
541 
548 
554 - (void)applyProcedure:(NSAObjectProcedure)procedure;
555 
561 - (NSArray *)arrayByMappingOperator:(NSAObjectUnaryOperator)mapper;
562 
568 - (NSArray *)arrayByMapFilteringOperator:(NSAObjectUnaryOperator)mapper;
569 
576 - (NSArray *)arrayByFilteringOperator:(NSAObjectPicker)filter;
577 
583 - (id)reduce:(NSAObjectBinaryOperator)reduce;
584 
590 - (id)reduce:(NSAObjectBinaryOperator)reduce initialObject:(id)initialObject;
591 
597 - (NSSet *)setByMappingOperator:(NSAObjectUnaryOperator)mapper;
598 
604 - (NSSet *)setByMapFilteringOperator:(NSAObjectUnaryOperator)mapper;
605 
611 - (NSSet *)setByFilteringOperator:(NSAObjectPicker)filter;
612 
618 - (id)firstObjectByFilteringOperator:(NSAObjectPicker)filter;
619 
620 @end
621 
628 
634 - (void)applyProcedure:(NSAObjectProcedure)procedure;
635 
641 - (void)applyProcedureWithIndex:(NSAObjectProcedureWithIndex)procedure;
642 
648 - (NSArray *)arrayByMappingOperator:(NSAObjectUnaryOperator)mapper;
649 
655 - (NSArray *)arrayByMappingOperatorWithIndex:(NSAObjectUnaryOperatorWithIndex)mapper;
656 
662 - (NSArray *)arrayByMapFilteringOperator:(NSAObjectUnaryOperator)mapper;
663 
669 - (NSArray *)arrayByMapFilteringOperatorWithIndex:(NSAObjectUnaryOperatorWithIndex)mapper;
670 
676 - (NSArray *)arrayByFilteringOperator:(NSAObjectPicker)filter;
677 
683 - (NSArray *)arrayByFilteringOperatorWithIndex:(NSAObjectPickerWithIndex)filter;
684 
690 - (id)reduce:(NSAObjectBinaryOperator)reduce;
691 
697 - (id)reduce:(NSAObjectBinaryOperator)reduce initialObject:(id)initialObject;
698 
704 - (NSSet *)setByMappingOperator:(NSAObjectUnaryOperator)mapper;
705 
711 - (NSSet *)setByMapFilteringOperator:(NSAObjectUnaryOperator)mapper;
712 
718 - (NSSet *)setByFilteringOperator:(NSAObjectPicker)filter;
719 
720 @end
721 
722 
723 typedef void (^NSAObjectProcedureWithCount)(id obj, NSUInteger count);
724 typedef id (^NSAObjectUnaryOperatorWithCount)(id obj, NSUInteger count);
725 typedef BOOL (^NSAObjectPickerWithCount)(id obj, NSUInteger count);
726 
733 
739 - (void)applyProcedureWithCount:(NSAObjectProcedureWithCount)procedure;
740 
746 - (NSArray *)arrayByMappingOperatorWithCount:(NSAObjectUnaryOperatorWithCount)mapper;
747 
753 - (NSArray *)arrayByMapFilteringOperatorWithCount:(NSAObjectUnaryOperatorWithCount)mapper;
754 
760 - (NSArray *)arrayByFilteringOperatorWithCount:(NSAObjectPickerWithCount)filter;
761 
762 @end
763 
764 #endif
See Map/Filter/Reduce for concept of functional tools.
Definition: NSAFunctional.h:420
void(^ NSAObjectProcedureWithKey)(id obj, id key)
Procedure take an object with key. Take an object and execute job.
Definition: NSAFunctional.h:63
BOOL(^ NSAObjectPickerWithIndex)(id obj, NSUInteger index)
Object selection block. Take an object with index and returns a boolean.
Definition: NSAFunctional.h:83
FOUNDATION_EXTERN NSEnumerator * NSAFilterWithIndex(NSEnumerator *enumerator, NSAObjectPickerWithIndex filter)
Applies filter with index to every item of given enumerator and returns an enumerator with the filter...
See Map/Filter/Reduce for concept of functional tools.
Definition: NSAFunctional.h:732
FOUNDATION_EXTERN NSEnumerator * NSAMapWithIndex(id< NSFastEnumeration > enumerator, NSAObjectUnaryOperatorWithIndex mapper)
Applies mapper with index to every item of enumerator and returns an enumerator with every result ite...
BOOL(^ NSAObjectPickerWithKey)(id obj, id key)
Object selection block. Take an object with key and returns a boolean.
Definition: NSAFunctional.h:87
See Map/Filter/Reduce for concept of functional tools.
Definition: NSAFunctional.h:627
See Map/Filter/Reduce for concept of functional tools.
Definition: NSAFunctional.h:547
void(^ NSAObjectProcedureWithCount)(id obj, NSUInteger count)
Definition: NSAFunctional.h:723
BOOL(^ NSAObjectPickerWithCount)(id obj, NSUInteger count)
Definition: NSAFunctional.h:725
id(^ NSAObjectUnaryOperatorWithCount)(id obj, NSUInteger count)
Definition: NSAFunctional.h:724
id(^ NSAObjectUnaryOperator)(id obj)
Object unary operation block. Take an object and returns an object.
Definition: NSAFunctional.h:67
FOUNDATION_EXTERN NSEnumerator * NSAFilter(NSEnumerator *enumerator, NSAObjectPicker filter)
Applies filter to every item of given enumerator and returns an enumerator with the filter result is ...
void(^ NSAObjectProcedureWithIndex)(id obj, NSUInteger index)
Procedure take an object with index. Take an object and execute job.
Definition: NSAFunctional.h:59
FOUNDATION_EXTERN NSEnumerator * NSAMapFilterWithIndex(NSEnumerator *enumerator, NSAObjectUnaryOperatorWithIndex mapper)
Applies mapper with index to every item of enumerator and returns an enumerator with every result ite...
FOUNDATION_EXTERN void NSAApplyWithIndex(id< NSFastEnumeration > enumerator, NSAObjectProcedureWithIndex procedure)
Applies mapper with index to every item of enumerator.
FOUNDATION_EXTERN NSEnumerator * NSAMap(id< NSFastEnumeration > enumerator, NSAObjectUnaryOperator mapper)
Applies mapper to every item of enumerator and returns an enumerator with every result items...
id(^ NSAObjectUnaryOperatorWithIndex)(id obj, NSUInteger index)
Object unary operation block. Take an object with index and returns an object.
Definition: NSAFunctional.h:71
id(^ NSAObjectUnaryOperatorWithKey)(id obj, id key)
Object unary operation block. Take an object with key and returns an object.
Definition: NSAFunctional.h:75
void(^ NSAObjectProcedure)(id obj)
Procedure take an object. Take an object and execute job.
Definition: NSAFunctional.h:55
FOUNDATION_EXTERN id NSAReduceWithInitialObject(id< NSFastEnumeration > enumerator, NSAObjectBinaryOperator operation, id initialObject)
Applies operation of two arguments cumulatively to the items of enumerator, from left to right...
See Map/Filter/Reduce for concept of functional tools.
Definition: NSAFunctional.h:373
FOUNDATION_EXTERN NSEnumerator * NSAMapFilter(NSEnumerator *enumerator, NSAObjectUnaryOperator mapper)
Applies mapper to every item of enumerator and returns an enumerator with every result items except n...
See Map/Filter/Reduce for concept of functional tools.
Definition: NSAFunctional.h:191
See Map/Filter/Reduce for concept of functional tools.
Definition: NSAFunctional.h:278
id(^ NSAObjectBinaryOperator)(id obj1, id obj2)
Object binary operation block. Take 2 objects and returns an object.
Definition: NSAFunctional.h:91
BOOL(^ NSAObjectPicker)(id obj)
Object selection block. Take an object and returns a boolean.
Definition: NSAFunctional.h:79
See Map/Filter/Reduce for concept of functional tools.
Definition: NSAFunctional.h:501
FOUNDATION_EXTERN id NSAReduce(NSEnumerator *enumerator, NSAObjectBinaryOperator operation)
Applies operation of two arguments cumulatively to the items of enumerator, from left to right...
FOUNDATION_EXTERN void NSAApply(id< NSFastEnumeration > enumerator, NSAObjectProcedure procedure)
Applies mapper to every item of enumerator.