Permalink
Browse files

add map/select macros

  • Loading branch information...
1 parent 54d6fe2 commit 9a324d2d997bc053c3bb829d1ee848b218771447 @mikeash committed Oct 11, 2010
Showing with 14 additions and 0 deletions.
  1. +2 −0 MACollectionUtilities.h
  2. +12 −0 main.m
View
@@ -15,6 +15,8 @@
// this is key/object order, not object/key order, thus all the fuss
#define DICT(...) MADictionaryWithKeysAndObjects(IDARRAY(__VA_ARGS__), IDCOUNT(__VA_ARGS__) / 2)
+#define MAP(collection, ...) ([collection ma_map: ^id (id obj) { return (__VA_ARGS__); }])
+#define SELECT(collection, ...) ([collection ma_select: ^BOOL (id obj) { return (__VA_ARGS__); }])
@interface NSArray (MACollectionUtilities)
View
12 main.m
@@ -58,11 +58,23 @@ static void TestArrayMethods(void)
TEST_ASSERT([[array ma_select: ^BOOL (id obj) { return [obj intValue] < 4; }] isEqual: array]);
}
+static void TestArrayMacros(void)
+{
+ NSArray *array = ARRAY(@"1", @"2", @"3");
+
+ TEST_ASSERT([MAP(array, [obj stringByAppendingString: @".0"]) isEqual:
+ ARRAY(@"1.0", @"2.0", @"3.0")]);
+ TEST_ASSERT([SELECT(array, [obj intValue] < 1) isEqual: ARRAY()]);
+ TEST_ASSERT([SELECT(array, [obj intValue] < 3) isEqual: ARRAY(@"1", @"2")]);
+ TEST_ASSERT([SELECT(array, [obj intValue] < 4) isEqual: array]);
+}
+
int main(int argc, char **argv)
{
WithPool(^{
TEST(TestCreation);
TEST(TestArrayMethods);
+ TEST(TestArrayMacros);
NSString *message;
if(gFailureCount)

0 comments on commit 9a324d2

Please sign in to comment.