Created
October 11, 2012 09:07
-
-
Save plantpurecode/3871152 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef void (^JRIterationBlock)(NSUInteger index); | |
static inline void invokeBlockIterativelyUsingRange(JRIterationBlock block, NSRange rng) { | |
NSParameterAssert(block); | |
for(NSUInteger i = rng.location; i < NSMaxRange(rng); ++i) { | |
block(i); | |
} | |
} | |
@implementation NSNumber (BlockAdditions) | |
- (void)times:(JRIterationBlock)block { | |
invokeBlockIterativelyUsingRange(block, (NSRange) {0, [self unsignedIntegerValue]}); | |
} | |
- (void)upTo:(NSUInteger)upperBound do:(JRIterationBlock)block { | |
NSUInteger value = [self unsignedIntegerValue]; | |
invokeBlockIterativelyUsingRange(block, (NSRange) {value, MAX(value, upperBound)}); | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static inline void invokeBlockIterativelyUsingRange(void(^)(NSUInteger index)block, NSRange rng) { | |
NSParameterAssert(block); | |
for(NSUInteger i = rng.location; i < NSMaxRange(rng); ++i) { | |
block(i); | |
} | |
} | |
@implementation NSNumber (BlockAdditions) | |
- (void)times:(void(^)(NSUInteger index))block { | |
invokeBlockIterativelyUsingRange(block, (NSRange) {0, [self unsignedIntegerValue]}); | |
} | |
- (void)upTo:(NSUInteger)upperBound do:(void(^)(NSUInteger index))block { | |
NSUInteger value = [self unsignedIntegerValue]; | |
invokeBlockIterativelyUsingRange(block, (NSRange) {value, MAX(value, upperBound)}); | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef void (^JRIterationBlock)(NSUInteger index); | |
static inline void invokeBlockIterativelyUsingRange(JRIterationBlock block, NSRange rng) { | |
NSParameterAssert(block); | |
for(NSUInteger i = rng.location; i < NSMaxRange(rng); ++i) { | |
block(i); | |
} | |
} | |
@implementation NSNumber (BlockAdditions) | |
- (void)times:(JRIterationBlock)block { | |
invokeBlockIterativelyUsingRange(block, (NSRange) {0, [self unsignedIntegerValue]}); | |
} | |
- (void)upTo:(NSUInteger)upperBound do:(JRIterationBlock)block { | |
NSUInteger value = [self unsignedIntegerValue]; | |
invokeBlockIterativelyUsingRange(block, (NSRange) {value, MAX(value, upperBound)}); | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static inline void invokeBlockIterativelyUsingRange(void(^)(NSUInteger index)block, NSRange rng) { | |
NSParameterAssert(block); | |
for(NSUInteger i = rng.location; i < NSMaxRange(rng); ++i) { | |
block(i); | |
} | |
} | |
@implementation NSNumber (BlockAdditions) | |
- (void)times:(void(^)(NSUInteger index))block { | |
invokeBlockIterativelyUsingRange(block, (NSRange) {0, [self unsignedIntegerValue]}); | |
} | |
- (void)upTo:(NSUInteger)upperBound do:(void(^)(NSUInteger index))block { | |
NSUInteger value = [self unsignedIntegerValue]; | |
invokeBlockIterativelyUsingRange(block, (NSRange) {value, MAX(value, upperBound)}); | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[@(5) times:^(NSUInteger index) { | |
NSLog(@"%u", index); | |
}]; | |
[@(5) upTo:100 do:^(NSUInteger index) { | |
NSLog(@"%u", index); | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment