mirror of https://github.com/oxen-io/session-ios
Merge branch 'charlesmchen/brokenSignalTests'
commit
27023c9d83
@ -1,25 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
@interface NSArray (FunctionalUtil)
|
||||
|
||||
/// Returns true when any of the items in this array match the given predicate.
|
||||
- (bool)any:(int (^)(id item))predicate;
|
||||
|
||||
/// Returns true when all of the items in this array match the given predicate.
|
||||
- (bool)all:(int (^)(id item))predicate;
|
||||
|
||||
/// Returns the first item in this array that matches the given predicate, or else returns nil if none match it.
|
||||
- (id)firstMatchingElseNil:(int (^)(id item))predicate;
|
||||
|
||||
/// Returns an array of all the results of passing items from this array through the given projection function.
|
||||
- (NSArray *)map:(id (^)(id item))projection;
|
||||
|
||||
/// Returns an array of all the results of passing items from this array through the given projection function.
|
||||
- (NSArray *)filter:(int (^)(id item))predicate;
|
||||
|
||||
- (NSDictionary *)keyedBy:(id (^)(id))keySelector;
|
||||
- (NSDictionary *)groupBy:(id (^)(id value))keySelector;
|
||||
|
||||
@end
|
@ -1,86 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "FunctionalUtil.h"
|
||||
|
||||
@implementation NSArray (FunctionalUtil)
|
||||
- (bool)any:(int (^)(id item))predicate {
|
||||
OWSAssertDebug(predicate != nil);
|
||||
for (id e in self) {
|
||||
if (predicate(e)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
- (bool)all:(int (^)(id item))predicate {
|
||||
OWSAssertDebug(predicate != nil);
|
||||
for (id e in self) {
|
||||
if (!predicate(e)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
- (id)firstMatchingElseNil:(int (^)(id item))predicate {
|
||||
OWSAssertDebug(predicate != nil);
|
||||
for (id e in self) {
|
||||
if (predicate(e)) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
- (NSArray *)map:(id (^)(id item))projection {
|
||||
OWSAssertDebug(projection != nil);
|
||||
|
||||
NSMutableArray *r = [NSMutableArray arrayWithCapacity:self.count];
|
||||
for (id e in self) {
|
||||
[r addObject:projection(e)];
|
||||
}
|
||||
return r;
|
||||
}
|
||||
- (NSArray *)filter:(int (^)(id item))predicate {
|
||||
OWSAssertDebug(predicate != nil);
|
||||
|
||||
NSMutableArray *r = [NSMutableArray array];
|
||||
for (id e in self) {
|
||||
if (predicate(e)) {
|
||||
[r addObject:e];
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
- (NSDictionary *)keyedBy:(id (^)(id value))keySelector {
|
||||
OWSAssertDebug(keySelector != nil);
|
||||
|
||||
NSMutableDictionary *result = [NSMutableDictionary dictionary];
|
||||
|
||||
for (id value in self) {
|
||||
result[keySelector(value)] = value;
|
||||
}
|
||||
OWSAssertDebug(result.count == self.count);
|
||||
|
||||
return result;
|
||||
}
|
||||
- (NSDictionary *)groupBy:(id (^)(id value))keySelector {
|
||||
OWSAssertDebug(keySelector != nil);
|
||||
|
||||
NSMutableDictionary *result = [NSMutableDictionary dictionary];
|
||||
|
||||
for (id item in self) {
|
||||
id key = keySelector(item);
|
||||
|
||||
NSMutableArray *group = result[key];
|
||||
if (group == nil) {
|
||||
group = [NSMutableArray array];
|
||||
result[key] = group;
|
||||
}
|
||||
[group addObject:item];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@end
|
@ -1,9 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SignalBaseTest.h"
|
||||
|
||||
@interface FunctionalUtilTest : SignalBaseTest
|
||||
|
||||
@end
|
Loading…
Reference in New Issue