RACSignal: how to reduce on an arbitrarily large combine

Let's .password an example (rephrased) from the ReactiveCocoa Introduction , which includes: the text fields .password and .passwordConfirm correspond to:

 RAC(self.enabled) = [RACSignal combineLatest:@[ RACAble(self.password), RACAble(self.passwordConfirm) ] reduce:^(NSString *password, NSString *passwordConfirm) { return @([passwordConfirm isEqualToString:password]); }]; 

Here, we know at compile time how many and what things we combine, and it is useful to destroy / map the array to "combine" into several arguments with a reduction block. How about when it doesn't work. For example, if you want:

 RAC(self.enabled) = [RACSignal combineLatest:arrayOfSignals reduceAll:^(NSArray *signalValues) { // made this up! don't try at home. // something ... }]; 

How do you do this with ReactiveCocoa ?

UPDATE: The accepted answers to the answer help explain what I am missing.

+4
source share
1 answer

You can use the card:

 RAC(self.enabled) = [[RACSignal combineLatest:arrayOfSignals] map:^(RACTuple *signalValues) { // something } ]; 

A RACTuple can be manipulated in many ways, it corresponds to NSFastEnumeration , has an allObjects method, as well as a rac_sequence method. You can, for example, combine all the logical values ​​in this way:

 RAC(self.enabled) = [[RACSignal combineLatest:arrayOfSignals] map:^(RACTuple *signalValues) { return @([signalValues.rac_sequence all:^BOOL(NSNumber *value) { return [value boolValue]; }]); } ]; 

Hope this helps.

+7
source

Source: https://habr.com/ru/post/1491147/


All Articles