Reactive Cocoa Conditional Split ?

181 views Asked by At

I have been playing with reactive cocoa and I cannot seem to figure out a more elegant way to do a conditional split without running the function twice.

So here is my solution

 RACSignal* registrationSignal = [self isRegistrationDone];

    [[[[[registrationSignal filter:^BOOL(id value) {

        if ([value boolValue] == YES) return YES;
        return NO;

    }] map:^id(id value) {

        return [self isNewDay];
    }] flattenMap:^RACStream *(id value) {
        return  [self willSavePreviousDay];
    }] flattenMap:^RACStream *(id value) {
        return  [self willGenerateNotificationsForNewDay];
    }]
     subscribeNext:^(id x) {
        NSLog(@"New Day is Checked and Saved Notifications have been completed.");
    }];


    [[registrationSignal filter:^BOOL(id value) {
        if([value boolValue] == NO) return YES;
        return NO;
    }] subscribeNext:^(id x) {
        [self useOnboardingController];

    }];

is there a better way to write this ?

Cheers!

0

There are 0 answers