RAC flattenMap

flattenMap:

RACSubject * subject = [RACSubject subject];


    RACSignal * binSignal = [subject flattenMap:^__kindof RACSignal * _Nullable(id  _Nullable value) {


        //        value 原信號的內容

        value = [NSString stringWithFormat:@"數據處理: %@",value];


        return [RACReturnSignal return:value];

    }];


    [binSignal subscribeNext:^(id  _Nullable x) {

        NSLog(@"%@",x);

    }];


    [subject sendNext:@"123"];

样例2

RACSequence * s1 = [@[@(1), @(2), @(3)] rac_sequence];

    RACSequence * s2 = [@[@(1), @(3), @(9)] rac_sequence];

    RACSequence * s3 = [[@[s1,s2] rac_sequence]

                        flattenMap:^__kindof RACSequence * _Nullable(id  _Nullable value) {

        return [value filter:^BOOL(id  _Nullable value) {

            return [value integerValue] % 3 == 0;

        }];

    }];

    NSLog(@"%@",[s3 array]);//打印3、3、9

你可能感兴趣的:(RAC flattenMap)