mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-08 08:31:13 +00:00
29 lines
766 B
Objective-C
29 lines
766 B
Objective-C
#import "SSignal+Accumulate.h"
|
|
|
|
@implementation SSignal (Accumulate)
|
|
|
|
- (SSignal *)reduceLeft:(id)value with:(id (^)(id, id))f
|
|
{
|
|
__block id intermediateResult = value;
|
|
|
|
return [[SSignal alloc] initWithGenerator:^(SSubscriber *subscriber)
|
|
{
|
|
id<SDisposable> disposable = [self startWithNext:^(id next)
|
|
{
|
|
intermediateResult = f(intermediateResult, next);
|
|
} error:^(id error)
|
|
{
|
|
SSubscriber_putError(subscriber, error);
|
|
} completed:^
|
|
{
|
|
if (intermediateResult != nil)
|
|
SSubscriber_putNext(subscriber, intermediateResult);
|
|
SSubscriber_putCompletion(subscriber);
|
|
}];
|
|
|
|
[subscriber addDisposable:disposable];
|
|
}];
|
|
}
|
|
|
|
@end
|