Permalink
Browse files

al_find

  • Loading branch information...
lavoy committed Jan 2, 2014
1 parent 8e04477 commit f00716e6b365795e9bb8ddae6118d8dcbac17530
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>IDESourceControlProjectIdentifier</key>
+ <string>AE5C8D71-6645-4414-AABE-6C55948D72E1</string>
+ <key>IDESourceControlProjectName</key>
+ <string>ALToolkit</string>
+ <key>IDESourceControlProjectOriginsDictionary</key>
+ <dict>
+ <key>89923B14-15BE-448B-9220-82B030AD5901</key>
+ <string>https://github.com/lavoy/ALToolkit.git</string>
+ </dict>
+ <key>IDESourceControlProjectPath</key>
+ <string>ALToolkit.xcodeproj/project.xcworkspace</string>
+ <key>IDESourceControlProjectRelativeInstallPathDictionary</key>
+ <dict>
+ <key>89923B14-15BE-448B-9220-82B030AD5901</key>
+ <string>../..</string>
+ </dict>
+ <key>IDESourceControlProjectURL</key>
+ <string>https://github.com/lavoy/ALToolkit.git</string>
+ <key>IDESourceControlProjectVersion</key>
+ <integer>110</integer>
+ <key>IDESourceControlProjectWCCIdentifier</key>
+ <string>89923B14-15BE-448B-9220-82B030AD5901</string>
+ <key>IDESourceControlProjectWCConfigurations</key>
+ <array>
+ <dict>
+ <key>IDESourceControlRepositoryExtensionIdentifierKey</key>
+ <string>public.vcs.git</string>
+ <key>IDESourceControlWCCIdentifierKey</key>
+ <string>89923B14-15BE-448B-9220-82B030AD5901</string>
+ <key>IDESourceControlWCCName</key>
+ <string>ALToolkit</string>
+ </dict>
+ </array>
+</dict>
+</plist>
@@ -12,5 +12,6 @@
- (id)safeObjectAtIndex:(NSUInteger)index;
- (NSArray *)al_map:(id (^)(id object))mapBlock;
- (NSArray *)al_filter:(BOOL (^)(id object))filterBlock;
+- (id)al_find:(BOOL (^)(id object))findBlock;
@end
@@ -45,4 +45,15 @@ - (NSArray *)al_filter:(BOOL (^)(id object))filterBlock {
}
+- (id)al_find:(BOOL (^)(id object))findBlock {
+ for (id object in self) {
+ if (findBlock(object)) {
+ return object;
+ }
+ }
+
+ return nil;
+}
+
+
@end
@@ -69,6 +69,25 @@ - (void)testFilter
STAssertEqualObjects(filteredArray[4], @(4), nil);
}
+- (void)testFind
+{
+ NSNumber *foundObject0 = [self.array al_find:^BOOL(NSNumber *num) {
+ return [num integerValue] < 5;
+ }];
+
+ NSNumber *foundObject6 = [self.array al_find:^BOOL(NSNumber *num) {
+ return [num integerValue] > 5;
+ }];
+
+ NSNumber *foundObject20 = [self.array al_find:^BOOL(NSNumber *num) {
+ return [num integerValue] > 19;
+ }];
+
+ STAssertEqualObjects(foundObject0, @(0), nil);
+ STAssertEqualObjects(foundObject6, @(6), nil);
+ STAssertNil(foundObject20, nil);
+}
+
- (void)testSafeObject
{
STAssertEqualObjects([self.array safeObjectAtIndex:0], @(0), nil);

0 comments on commit f00716e

Please sign in to comment.