mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-07 16:11:13 +00:00
41 lines
900 B
Objective-C
41 lines
900 B
Objective-C
#import "SSignal+Mapping.h"
|
|
|
|
@implementation SSignal (Mapping)
|
|
|
|
- (SSignal *)map:(id (^)(id))f
|
|
{
|
|
return [[SSignal alloc] initWithGenerator:^id<SDisposable> (SSubscriber *subscriber)
|
|
{
|
|
return [self startWithNext:^(id next)
|
|
{
|
|
[subscriber putNext:f(next)];
|
|
} error:^(id error)
|
|
{
|
|
[subscriber putError:error];
|
|
} completed:^
|
|
{
|
|
[subscriber putCompletion];
|
|
}];
|
|
}];
|
|
}
|
|
|
|
- (SSignal *)filter:(bool (^)(id))f
|
|
{
|
|
return [[SSignal alloc] initWithGenerator:^id<SDisposable> (SSubscriber *subscriber)
|
|
{
|
|
return [self startWithNext:^(id next)
|
|
{
|
|
if (f(next))
|
|
[subscriber putNext:next];
|
|
} error:^(id error)
|
|
{
|
|
[subscriber putError:error];
|
|
} completed:^
|
|
{
|
|
[subscriber putCompletion];
|
|
}];
|
|
}];
|
|
}
|
|
|
|
@end
|