FoundationExtension
FoundationExtension is common Foundation/UIKit/Cocoa shortcuts and snippets collection.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
NSAFunctional.h File Reference

See Map/Filter/Reduce for concept of functional tools. More...

#import <Foundation/Foundation.h>
#import <FoundationExtension/NSMacro.h>

Go to the source code of this file.

Classes

category  NSEnumerator(Functional)
 See Map/Filter/Reduce for concept of functional tools. More...
 
category  NSArray(Functional)
 See Map/Filter/Reduce for concept of functional tools. More...
 
category  NSMutableArray(Functional)
 See Map/Filter/Reduce for concept of functional tools. More...
 
category  NSDictionary(Functional)
 See Map/Filter/Reduce for concept of functional tools. More...
 
category  NSMutableDictionary(Functional)
 See Map/Filter/Reduce for concept of functional tools. More...
 
category  NSSet(Functional)
 See Map/Filter/Reduce for concept of functional tools. More...
 
category  NSOrderedSet(Functional)
 See Map/Filter/Reduce for concept of functional tools. More...
 
category  NSCountedSet(Functional)
 See Map/Filter/Reduce for concept of functional tools. More...
 

Typedefs

typedef void(^ NSAObjectProcedure )(id obj)
 Procedure take an object. Take an object and execute job. More...
 
typedef void(^ NSAObjectProcedureWithIndex )(id obj, NSUInteger index)
 Procedure take an object with index. Take an object and execute job. More...
 
typedef void(^ NSAObjectProcedureWithKey )(id obj, id key)
 Procedure take an object with key. Take an object and execute job. More...
 
typedef id(^ NSAObjectUnaryOperator )(id obj)
 Object unary operation block. Take an object and returns an object. More...
 
typedef id(^ NSAObjectUnaryOperatorWithIndex )(id obj, NSUInteger index)
 Object unary operation block. Take an object with index and returns an object. More...
 
typedef id(^ NSAObjectUnaryOperatorWithKey )(id obj, id key)
 Object unary operation block. Take an object with key and returns an object. More...
 
typedef BOOL(^ NSAObjectPicker )(id obj)
 Object selection block. Take an object and returns a boolean. More...
 
typedef BOOL(^ NSAObjectPickerWithIndex )(id obj, NSUInteger index)
 Object selection block. Take an object with index and returns a boolean. More...
 
typedef BOOL(^ NSAObjectPickerWithKey )(id obj, id key)
 Object selection block. Take an object with key and returns a boolean. More...
 
typedef id(^ NSAObjectBinaryOperator )(id obj1, id obj2)
 Object binary operation block. Take 2 objects and returns an object. More...
 
typedef void(^ NSAObjectProcedureWithCount )(id obj, NSUInteger count)
 
typedef id(^ NSAObjectUnaryOperatorWithCount )(id obj, NSUInteger count)
 
typedef BOOL(^ NSAObjectPickerWithCount )(id obj, NSUInteger count)
 

Functions

FOUNDATION_EXTERN void NSAApply (id< NSFastEnumeration > enumerator, NSAObjectProcedure procedure)
 Applies mapper to every item of enumerator. More...
 
FOUNDATION_EXTERN void NSAApplyWithIndex (id< NSFastEnumeration > enumerator, NSAObjectProcedureWithIndex procedure)
 Applies mapper with index to every item of enumerator. More...
 
FOUNDATION_EXTERN NSEnumerator * NSAMap (id< NSFastEnumeration > enumerator, NSAObjectUnaryOperator mapper)
 Applies mapper to every item of enumerator and returns an enumerator with every result items. More...
 
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 items. More...
 
FOUNDATION_EXTERN NSEnumerator * NSAMapFilter (NSEnumerator *enumerator, NSAObjectUnaryOperator mapper)
 Applies mapper to every item of enumerator and returns an enumerator with every result items except nil. More...
 
FOUNDATION_EXTERN NSEnumerator * NSAMapFilterWithIndex (NSEnumerator *enumerator, NSAObjectUnaryOperatorWithIndex mapper)
 Applies mapper with index to every item of enumerator and returns an enumerator with every result items except nil. More...
 
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 YES. More...
 
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 result is YES. More...
 
FOUNDATION_EXTERN id NSAReduce (NSEnumerator *enumerator, NSAObjectBinaryOperator operation)
 Applies operation of two arguments cumulatively to the items of enumerator, from left to right, so as to reduce the iterable to a single value. Uses first and second value as seed. More...
 
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, so as to reduce the iterable to a single value. More...
 

Detailed Description

See Map/Filter/Reduce for concept of functional tools.

Typedef Documentation

typedef id(^ NSAObjectBinaryOperator)(id obj1, id obj2)

Object binary operation block. Take 2 objects and returns an object.

typedef BOOL(^ NSAObjectPicker)(id obj)

Object selection block. Take an object and returns a boolean.

typedef BOOL(^ NSAObjectPickerWithCount)(id obj, NSUInteger count)
typedef BOOL(^ NSAObjectPickerWithIndex)(id obj, NSUInteger index)

Object selection block. Take an object with index and returns a boolean.

typedef BOOL(^ NSAObjectPickerWithKey)(id obj, id key)

Object selection block. Take an object with key and returns a boolean.

typedef void(^ NSAObjectProcedure)(id obj)

Procedure take an object. Take an object and execute job.

typedef void(^ NSAObjectProcedureWithCount)(id obj, NSUInteger count)
typedef void(^ NSAObjectProcedureWithIndex)(id obj, NSUInteger index)

Procedure take an object with index. Take an object and execute job.

typedef void(^ NSAObjectProcedureWithKey)(id obj, id key)

Procedure take an object with key. Take an object and execute job.

typedef id(^ NSAObjectUnaryOperator)(id obj)

Object unary operation block. Take an object and returns an object.

typedef id(^ NSAObjectUnaryOperatorWithCount)(id obj, NSUInteger count)
typedef id(^ NSAObjectUnaryOperatorWithIndex)(id obj, NSUInteger index)

Object unary operation block. Take an object with index and returns an object.

typedef id(^ NSAObjectUnaryOperatorWithKey)(id obj, id key)

Object unary operation block. Take an object with key and returns an object.

Function Documentation

FOUNDATION_EXTERN void NSAApply ( id< NSFastEnumeration >  enumerator,
NSAObjectProcedure  procedure 
)

Applies mapper to every item of enumerator.

Parameters
enumeratorInput object source enumerator.
procedureA procedure to apply every item.
FOUNDATION_EXTERN void NSAApplyWithIndex ( id< NSFastEnumeration >  enumerator,
NSAObjectProcedureWithIndex  procedure 
)

Applies mapper with index to every item of enumerator.

Parameters
enumeratorInput object source enumerator.
procedureA procedure to apply every item.
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 YES.

Parameters
enumeratorInput object source enumerator.
filterObject filter to decide inclues or not.
Returns
An enumerator with filter result of items of given enumerater is YES.
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 result is YES.

Parameters
enumeratorInput object source enumerator.
filterObject filter to decide inclues or not.
Returns
An enumerator with filter result of items of given enumerater is YES.
FOUNDATION_EXTERN NSEnumerator* NSAMap ( id< NSFastEnumeration >  enumerator,
NSAObjectUnaryOperator  mapper 
)

Applies mapper to every item of enumerator and returns an enumerator with every result items.

Parameters
enumeratorInput object source enumerator.
mapperObject mapper to apply every item.
Returns
An enumerator with every mapper applied result.
FOUNDATION_EXTERN NSEnumerator* NSAMapFilter ( NSEnumerator *  enumerator,
NSAObjectUnaryOperator  mapper 
)

Applies mapper to every item of enumerator and returns an enumerator with every result items except nil.

Parameters
enumeratorInput object source enumerator.
mapperObject mapper to apply every item. Return nil to pass.
Returns
Take each object from given enumerator and returns an enumerator with mapped value by mapper. If the result is nil, it will not be enumerated.
See also
NSAMap
NSAFilter
FOUNDATION_EXTERN NSEnumerator* NSAMapFilterWithIndex ( NSEnumerator *  enumerator,
NSAObjectUnaryOperatorWithIndex  mapper 
)

Applies mapper with index to every item of enumerator and returns an enumerator with every result items except nil.

Parameters
enumeratorInput object source enumerator.
mapperObject mapper to apply every item. Return nil to pass.
Returns
Take each object from given enumerator and returns an enumerator with mapped value by mapper. If the result is nil, it will not be enumerated.
See also
NSAMap
NSAFilter
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 items.

Parameters
enumeratorInput object source enumerator.
mapperObject mapper to apply every item.
Returns
An enumerator with every mapper applied result.
FOUNDATION_EXTERN id NSAReduce ( NSEnumerator *  enumerator,
NSAObjectBinaryOperator  operation 
)

Applies operation of two arguments cumulatively to the items of enumerator, from left to right, so as to reduce the iterable to a single value. Uses first and second value as seed.

Given enumerator must enumerate more than a object.

Parameters
enumeratorInput object source enumerator.
operationAn operator to apply every item and latest result. If it is first object, operation is not used and keep the object as latest result.
Returns
An object.
See also
NSAReduceWithInitialObject
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, so as to reduce the iterable to a single value.

Given enumerator must enumerate more than a object.

Parameters
enumeratorInput object source enumerator.
operationAn operator to apply every item and latest result. If it is first object, uses initialObject as latest result.
initialObjectThe initial value to reduce with first element of enumerator.
Returns
An object.
See also
NSAReduce