NSArray+OCTotallyLazy.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #import <Foundation/Foundation.h>
  2. #import "Option.h"
  3. #import "Mappable.h"
  4. #import "Flattenable.h"
  5. #import "Types.h"
  6. @class Sequence;
  7. @class Pair;
  8. @interface NSArray (OCTotallyLazy) <Mappable, Foldable, Enumerable, Flattenable>
  9. - (NSArray *)add:(id)value;
  10. - (NSArray *)cons:(id)value;
  11. - (NSArray *)drop:(int)toDrop;
  12. - (NSArray *)dropWhile:(PREDICATE)funcBlock;
  13. - (NSArray *)filter:(PREDICATE)filterBlock;
  14. - (Option *)find:(PREDICATE)filterBlock;
  15. - (NSArray *)flatMap:(FUNCTION1)functorBlock;
  16. - (NSArray *)flatten;
  17. - (id)fold:(id)value with:(id (^)(id accumulator, id item))functorBlock;
  18. - (void)foreach:(void (^)(id))funcBlock;
  19. - (BOOL)isEmpty;
  20. - (NSArray *)groupBy:(FUNCTION1)groupingBlock;
  21. - (NSArray *)grouped:(int)n;
  22. - (id)head;
  23. - (Option *)headOption;
  24. - (NSArray *)join:(id<Enumerable>)toJoin;
  25. - (id)mapWithIndex:(id (^)(id, NSInteger))funcBlock;
  26. - (Pair *)partition:(PREDICATE)toJoin;
  27. - (id)reduce:(id (^)(id, id))functorBlock;
  28. - (NSArray *)reverse;
  29. - (Pair *)splitAt:(int)splitIndex;
  30. - (Pair *)splitOn:(id)splitItem;
  31. - (Pair *)splitWhen:(PREDICATE)predicate;
  32. - (NSArray *)tail;
  33. - (NSArray *)take:(int)n;
  34. - (NSArray *)takeWhile:(PREDICATE)funcBlock;
  35. - (NSArray *)takeRight:(int)n;
  36. - (NSString *)toString;
  37. - (NSString *)toString:(NSString *)separator;
  38. - (NSString *)toString:(NSString *)start separator:(NSString *)separator end:(NSString *)end;
  39. - (NSArray *)zip:(NSArray *)otherSequence;
  40. - (NSArray *)zipWithIndex;
  41. - (Sequence *)asSequence;
  42. - (NSSet *)asSet;
  43. - (NSArray *)asArray;
  44. - (NSDictionary *)asDictionary;
  45. @end
  46. static NSArray *array(id items , ...) {
  47. NSMutableArray *array = [NSMutableArray array];
  48. va_list args;
  49. va_start(args, items);
  50. for (id arg = items; arg != nil; arg = va_arg(args, id)) {
  51. [array addObject:arg];
  52. }
  53. va_end(args);
  54. return array;
  55. }