PageRenderTime 15ms CodeModel.GetById 11ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/BlocksKit/NSIndexSet+BlocksKit.h

http://github.com/zwaldowski/BlocksKit
C++ Header | 76 lines | 9 code | 9 blank | 58 comment | 0 complexity | 82dc530b8a118a6dfabd96860f3a2b1c MD5 | raw file
 1//
 2//  NSIndexSet+BlocksKit.h
 3//  %PROJECT
 4//
 5
 6#import "BKGlobals.h"
 7
 8/** Block extensions for NSIndexSet.
 9
10 Both inspired by and resembling Smalltalk syntax, these utilities
11 allows for iteration of an array in a concise way that
12 saves quite a bit of boilerplate code for filtering or finding
13 objects or an object.
14
15 Includes code by the following:
16
17- Robin Lu.	   <https://github.com/robin>.	  2009. MIT.
18- Michael Ash.	<https://github.com/mikeash>.	2010. BSD.
19- Zach Waldowski. <https://github.com/zwaldowski>. 2011. MIT.
20
21 @see NSArray(BlocksKit)
22 @see NSDictionary(BlocksKit)
23 @see NSSet(BlocksKit)
24 */
25@interface NSIndexSet (BlocksKit)
26
27/** Loops through an index set and executes the given block at each index.
28 
29 @param block A single-argument, void-returning code block.
30 */
31- (void)each:(BKIndexBlock)block;
32
33/** Enumerates each index in an index set concurrently and executes the
34 given block once per index.
35 
36 Enumeration will occur on appropriate background queues. 
37 Be aware that the block will not necessarily be executed
38 in order for each index.
39 
40 @param block A single-argument, void-returning code block.
41 */
42- (void)apply:(BKIndexBlock)block;
43
44/** Loops through an array and returns the index matching the block.
45 
46 @param block A single-argument, `BOOL`-returning code block.
47 @return Returns the index if found, `NSNotFound` otherwise.
48 @see select:
49 */
50- (NSUInteger)match:(BKIndexValidationBlock)block;
51
52/** Loops through an index set and returns an all indexes matching the block.
53 
54 @param block A single-argument, BOOL-returning code block.
55 @return Returns an index set of matching indexes found, `nil` otherwise.
56 @see match:
57 */
58- (NSIndexSet *)select:(BKIndexValidationBlock)block;
59
60/** Loops through an index set and returns an all indexes but the ones matching the block.
61 
62 This selector performs *literally* the exact same function as select: but in reverse.
63 
64 @param block A single-argument, BOOL-returning code block.
65 @return Returns an index set of all indexes but those matched, `nil` if all are excluded.
66 */
67- (NSIndexSet *)reject:(BKIndexValidationBlock)block;
68
69/** Call the block once for each index and create an index set with the new values.
70 
71 @param block A block that returns a new index for an index.
72 @return An index set of the indexes returned by the block.
73 */
74- (NSIndexSet *)map:(BKIndexTransformBlock)block;
75
76@end