mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			33 lines
		
	
	
		
			764 B
		
	
	
	
		
			Objective-C
		
	
			
		
		
	
	
			33 lines
		
	
	
		
			764 B
		
	
	
	
		
			Objective-C
		
	
| #import "NSArray+Functional.h"
 | |
| 
 | |
| @implementation NSArray (Functional)
 | |
| 
 | |
| - (BOOL)contains:(BOOL (^)(id))predicate {
 | |
|     for (id object in self) {
 | |
|         BOOL isPredicateSatisfied = predicate(object);
 | |
|         if (isPredicateSatisfied) { return YES; }
 | |
|     }
 | |
|     return NO;
 | |
| }
 | |
| 
 | |
| - (NSArray *)filtered:(BOOL (^)(id))isIncluded {
 | |
|     NSMutableArray *result = [NSMutableArray new];
 | |
|     for (id object in self) {
 | |
|         if (isIncluded(object)) {
 | |
|             [result addObject:object];
 | |
|         }
 | |
|     }
 | |
|     return result;
 | |
| }
 | |
| 
 | |
| - (NSArray *)map:(id (^)(id))transform {
 | |
|     NSMutableArray *result = [NSMutableArray new];
 | |
|     for (id object in self) {
 | |
|         id transformedObject = transform(object);
 | |
|         [result addObject:transformedObject];
 | |
|     }
 | |
|     return result;
 | |
| }
 | |
| 
 | |
| @end
 |