NSArray+Functional.h 620 B

1234567891011121314151617181920
  1. //
  2. // NSArray+Functional.h
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 9/25/19.
  6. // Copyright © 2019 Flipboard. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. @interface NSArray<T> (Functional)
  10. /// Actually more like flatmap, but it seems like the objc way to allow returning nil to omit objects.
  11. /// So, return nil from the block to omit objects, and return an object to include it in the new array.
  12. - (NSArray *)flex_mapped:(id(^)(T obj, NSUInteger idx))mapFunc;
  13. - (NSArray<T> *)flex_filtered:(BOOL(^)(T obj, NSUInteger idx))filterFunc;
  14. - (void)flex_forEach:(id(^)(T obj, NSUInteger idx))block;
  15. @end