Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between RACSequence and RACSignal

Maybe I'm totally missing this but according to the documentation on ReactiveCocoa on their types, RACSequences are signals.

However. I see examples where you have code like this:

RACSignal *letters = [@"A B C D E F G H I" componentsSeparatedByString:@" "].rac_sequence.signal;

// Outputs: A B C D E F G H I
[letters subscribeNext:^(NSString *x) {
     NSLog(@"%@", x);
}];

And also

RACSequence *letters = [@"A B C D E F G H I" componentsSeparatedByString:@" "].rac_sequence;

// Contains: AA BB CC DD EE FF GG HH II
RACSequence *mapped = [letters map:^(NSString *value) {
    return [value stringByAppendingString:value];
}];

A lot of the examples have RACSequence and RACSignal. What's the difference between rac_sequence.signal or just subscribing to the signal itself?

like image 758
Max Alexander Avatar asked Dec 11 '22 00:12

Max Alexander


1 Answers

One is pull driven (RACSequence) and the other is push driven (RACSignal). From here:

Push-driven means that values for the signal are not defined at the moment of signal creation and may become available at a later time (for example, as a result from network request, or any user input). Pull-driven means that values in the sequence are defined at the moment of signal creation and we can query values from the stream one-by-one.

In your case, you make the RACSignal pull-driven, because you are already have its values.

like image 181
Rui Peres Avatar answered Dec 17 '22 09:12

Rui Peres