Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 59f31edd02138b4198d58a50ba830e9cd19d9b12 0 parents
@mtrudel authored
9 Classes/MTCollectionOperators.h
@@ -0,0 +1,9 @@
+//
+// MTCollectionOperators.h
+//
+// Created by Mat Trudel on 2013-03-01.
+// Copyright (c) 2013 Mat Trudel. All rights reserved.
+//
+
+#import "NSArray+MTCollectionOperators.h"
+#import "NSSet+MTCollectionOperators.h"
17 Classes/NSArray+MTCollectionOperators.h
@@ -0,0 +1,17 @@
+//
+// NSArray+MTCollectionOperators.h
+// Pods
+//
+// Created by Mat Trudel on 2013-03-01.
+//
+//
+
+#import <Foundation/Foundation.h>
+
+@interface NSArray (MTCollectionOperators)
+
+- (instancetype)intersectWith:(NSArray *)other;
+- (instancetype)subtractValuesIn:(NSArray *)other;
+- (instancetype)map:(id (^)(id evaluatedObject))block;
+
+@end
35 Classes/NSArray+MTCollectionOperators.m
@@ -0,0 +1,35 @@
+//
+// NSArray+MTCollectionOperators.m
+// Pods
+//
+// Created by Mat Trudel on 2013-03-01.
+//
+//
+
+#import "NSArray+MTCollectionOperators.h"
+
+@implementation NSArray (MTCollectionOperators)
+
+- (instancetype)intersectWith:(NSArray *)other {
+ NSSet *otherAsSet = [NSSet setWithArray:other];
+ return [self filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
+ return [otherAsSet containsObject:evaluatedObject];
+ }]];
+}
+
+- (instancetype)subtractValuesIn:(NSArray *)other {
+ NSSet *otherAsSet = [NSSet setWithArray:other];
+ return [self filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
+ return ![otherAsSet containsObject:evaluatedObject];
+ }]];
+}
+
+- (instancetype)map:(id (^)(id))block {
+ NSMutableArray *result = [NSMutableArray arrayWithCapacity:self.count];
+ for (id obj in self) {
+ [result addObject:block(obj)];
+ }
+ return result;
+}
+
+@end
17 Classes/NSSet+MTCollectionOperators.h
@@ -0,0 +1,17 @@
+//
+// NSSet+MTCollectionOperators.h
+// Pods
+//
+// Created by Mat Trudel on 2013-03-01.
+//
+//
+
+#import <Foundation/Foundation.h>
+
+@interface NSSet (MTCollectionOperators)
+
+- (instancetype)intersectWith:(NSSet *)other;
+- (instancetype)subtractValuesIn:(NSSet *)other;
+- (instancetype)map:(id (^)(id evaluatedObject))block;
+
+@end
33 Classes/NSSet+MTCollectionOperators.m
@@ -0,0 +1,33 @@
+//
+// NSSet+MTCollectionOperators.m
+// Pods
+//
+// Created by Mat Trudel on 2013-03-01.
+//
+//
+
+#import "NSSet+MTCollectionOperators.h"
+
+@implementation NSSet (MTCollectionOperators)
+
+- (instancetype)intersectWith:(NSSet *)other {
+ NSMutableSet *result = [self mutableCopy];
+ [result intersectSet:other];
+ return result;
+}
+
+- (instancetype)subtractValuesIn:(NSSet *)other {
+ NSMutableSet *result = [self mutableCopy];
+ [result minusSet:other];
+ return result;
+}
+
+- (instancetype)map:(id (^)(id))block {
+ NSMutableSet *result = [NSMutableSet setWithCapacity:self.count];
+ for (id obj in self) {
+ [result addObject:block(obj)];
+ }
+ return result;
+}
+
+@end
22 LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2013 Mat Trudel
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 MTCollectionOperators.podspec
@@ -0,0 +1,19 @@
+Pod::Spec.new do |s|
+ s.name = "MTCollectionOperators"
+ s.version = "0.1.0"
+ s.summary = "Adds map, intersect, subtract, etc operators to collection classes."
+ s.description = <<-DESC
+ A set of handy add-ons to Cocoa's basic collection classes.
+ Supports NSSet and NSArray, as well as their
+ mutable subclasses. Provides map, intersect and subtract
+ operations.
+ DESC
+ s.homepage = "https://github.com/mtrudel/MTCollectionOperators"
+ s.license = { :type => 'MIT', :file => 'LICENSE' }
+ s.author = { "Mat Trudel" => "mat@geeky.net" }
+ s.source = { :git => "https://github.com/mtrudel/MTCollectionOperators.git", :tag => "0.1.0" }
+ s.ios.deployment_target = '5.0'
+ s.osx.deployment_target = '10.7'
+ s.source_files = 'Classes', 'Classes/**/*.{h,m}'
+ s.requires_arc = true
+end
14 README.md
@@ -0,0 +1,14 @@
+# MTCollectionOperators
+
+A simple collection of helper methods added to NSSet and NSArray to do inline
+intersection, subtraction, and mapping.
+
+## Usage
+
+Usage is straightforward; see the header files for method details.
+
+## Requirements
+
+MTCollectionOperators should work on any version of iOS or OS X that supports
+ARC. If non-ARC is required, let me know and I'll make this pod non-ARC
+friendly.
Please sign in to comment.
Something went wrong with that request. Please try again.