Skip to content
This repository was archived by the owner on Dec 12, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 27 additions & 21 deletions Classes/NSArray+ObjectiveSugar.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,23 @@
/// Alias for -sample
- (id)anyObject;


/**
Allow subscripting to fetch elements within the specified range

@param key An NSString or NSValue wrapping an NSRange. It's intended to behave like Ruby's array range accessors.
@param key An NSString or NSValue wrapping an NSRange. It's intended to behave
like Ruby's array range accessors.

Given array of 10 elements, e.g. [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], you can perform these operations:
Given array of 10 elements, e.g. [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], you
can perform these operations:
array[@"1..3"] will give you [2, 3, 4]
array[@"1...3"] will give you [2, 3] (last value excluded)
array[@"1,3"] implies NSRange(location: 1, length: 3), and gives you [2, 3, 4]
array[@"1,3"] implies NSRange(location: 1, length: 3), and gives you [2,
3, 4]


@return An array with elements within the specified range
*/
- (id)objectForKeyedSubscript:(id <NSCopying>)key;

- (id)objectForKeyedSubscript:(id<NSCopying>)key;

/**
A simpler alias for `enumerateObjectsUsingBlock`
Expand All @@ -77,14 +78,15 @@
- (void)each:(void (^)(id object))block options:(NSEnumerationOptions)options;

/**
A simpler alias for `enumerateObjectsWithOptions:usingBlock:` which also passes in an index
A simpler alias for `enumerateObjectsWithOptions:usingBlock:` which also passes
in an index

@param block A block with the object in its arguments.
@param options Enumerating options.
*/

- (void)eachWithIndex:(void (^)(id object, NSUInteger index))block options:(NSEnumerationOptions)options;

- (void)eachWithIndex:(void (^)(id object, NSUInteger index))block
options:(NSEnumerationOptions)options;

/**
An alias for `containsObject`
Expand Down Expand Up @@ -136,7 +138,6 @@
*/
- (id)detect:(BOOL (^)(id object))block;


/**
Alias for `detect`. Iterate through current array returning the first element
meeting a criteria.
Expand All @@ -149,13 +150,15 @@
/**
Iterate through current array asking whether to remove each element.

@param block A block that returns YES/NO for whether the object should be removed
@param block A block that returns YES/NO for whether the object should be
removed
@return An array of elements not rejected
*/
- (NSArray *)reject:(BOOL (^)(id object))block;

/**
Recurse through self checking for NSArrays and extract all elements into one single array
Recurse through self checking for NSArrays and extract all elements into one
single array

@return An array of all held arrays merged
*/
Expand Down Expand Up @@ -183,18 +186,19 @@
- (NSString *)join:(NSString *)separator;

/**
Run the default comparator on each object in the array
Run the default comparator on each object in the array on the given key

@return A sorted copy of the array
*/
- (NSArray *)sort;
- (NSArray *)sortedArrayByKey:(NSString *)key ascending:(BOOL)ascending;

/**
Sorts the array using the the default comparator on the given key
Sorts the array using the the default comparator on the given keys

@return A sorted copy of the array
*/
- (NSArray *)sortBy:(NSString *)key;
- (NSArray *)sortedArrayByKeys:(NSArray *)keys
ascending:(NSArray *)ascendingArray;

/**
Alias for reverseObjectEnumerator.allObjects
Expand Down Expand Up @@ -233,14 +237,17 @@
Return all the objects that are unique to each array individually
Alias for Ruby's ^ operator. Equivalent of a - b | b - a

@return An array of elements which are in either of the arrays and not in their intersection.
@return An array of elements which are in either of the arrays and not in their
intersection.
*/
- (NSArray *)symmetricDifference:(NSArray *)array;

/**
Return a single value from an array by iterating through the elements and transforming a running total.
Return a single value from an array by iterating through the elements and
transforming a running total.

@return A single value that is the end result of apply the block function to each element successively.
@return A single value that is the end result of apply the block function to
each element successively.
**/
- (id)reduce:(id (^)(id accumulator, id object))block;

Expand All @@ -251,10 +258,9 @@

/**
Produces a duplicate-free version of the array

@return a new array with all unique elements
**/
- (NSArray *)unique;

@end

Loading