RAC的高阶操作:repeat、flatten组合
改变某个值的个数:
RACSignal *signalA = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
[subscriber sendNext:@1];
[subscriber sendNext:@2];
[subscriber sendNext:@3];
[subscriber sendNext:@4];
[subscriber sendNext:@5];
[subscriber sendCompleted];
return [RACDisposable disposableWithBlock:^{
NSLog(@"signalA1完成");
}];
}];
RACSignal *signalB = [[signalA map:^id(NSNumber *value) {
return [[[RACSignal return:value] repeat] take:value.integerValue];
}] flatten];
[signalB subscribeNext:^(RACSignal *x) {
NSLog(@"subscribeNext:%@",x);
}];
2021-04-15 16:18:15.494267+0800 XXXXXX[3806:1098169] subscribeNext:1
2021-04-15 16:18:15.495839+0800 XXXXXX[3806:1098169] subscribeNext:2
2021-04-15 16:18:15.495970+0800 XXXXXX[3806:1098169] subscribeNext:3
2021-04-15 16:18:15.496114+0800 XXXXXX[3806:1098169] subscribeNext:4
2021-04-15 16:18:15.496359+0800 XXXXXX[3806:1098169] subscribeNext:5
2021-04-15 16:18:15.497260+0800 XXXXXX[3806:1098169] signalA1完成
2021-04-15 16:18:24.786032+0800 XXXXXX[3806:1098169] subscribeNext:2
2021-04-15 16:18:24.787346+0800 XXXXXX[3806:1098169] subscribeNext:3
2021-04-15 16:18:24.787594+0800 XXXXXX[3806:1098169] subscribeNext:4
2021-04-15 16:18:24.788007+0800 XXXXXX[3806:1098169] subscribeNext:5
2021-04-15 16:18:24.788239+0800 XXXXXX[3806:1098169] subscribeNext:3
2021-04-15 16:18:24.788723+0800 XXXXXX[3806:1098169] subscribeNext:4
2021-04-15 16:18:24.789010+0800 XXXXXX[3806:1098169] subscribeNext:5
2021-04-15 16:18:24.789369+0800 XXXXXX[3806:1098169] subscribeNext:4
2021-04-15 16:18:24.789648+0800 XXXXXX[3806:1098169] subscribeNext:5
2021-04-15 16:18:24.789986+0800 XXXXXX[3806:1098169] subscribeNext:5