RAC的Aggregate操作
2021-04-23 本文已影响0人
凯司机
数量操作——Aggregate:以及各种变种的操作
// 数量操作——Aggregate:
RACSignal *signalA = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
[subscriber sendNext:@1];
[subscriber sendNext:@2];
[subscriber sendNext:@4];
[subscriber sendCompleted];
return [RACDisposable disposableWithBlock:^{
NSLog(@"完成");
}];
}];
RACSignal *signalB = [signalA aggregateWithStart:@0 reduce:^id(NSNumber *running, NSNumber *next) {
return @(running.integerValue + next.integerValue);
}];
[[signalB subscribeNext:^(id x) {
NSLog(@"subscribeNext:%@",x);
}] dispose];
// 结果:7