Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Functional Reactive Programming intro

Functional Reactive Programming intro

Where to start?

Some concepts, use cases, and lots of resources to get a better understanding of this technology, with can be really useful for mobile apps in both iOS and Android worlds.

I prepared this presentation for my workmates at The Mobile Company (www.themobilecompany.com), to showcase this technology and convince them of their usage in the best use cases.

Adrián Moreno Peña

October 13, 2015

More Decks by Adrián Moreno Peña

Other Decks in Technology


  1. REACTIVE VS FUNCTIONAL • Reactive programming is programming with asynchronous

    data streams • Streams of events can be combined, and use one stream as input for other streams
  2. WHAT IS A STREAM? • A sequence of events ordered

    in time • Will produce one final result: • a value • an error • a “completed” signal
  3. EVENTS ARE “CAPTURED” • Always in a async way, by

    subscribing in a Observer pattern (with the possibility of manipulating and transforming the streams being emitted) • Defining handlers for: • emitted values • completed signals • error signals
  4. OBSERVER What we already know, but in 1st line Handling

    of async data streams (e.g: iterators)
  5. TRANSFORMING OPERATORS delay delayWithSelector findIndex map scan debounce debounceWithSelector COMBINING

    OPERATORS combineLatest concat merge sample startWith withLatestFrom zip FILTERING OPERATORS distinct distinctUntilChanged elementAt filter find first last pausable MATHEMATICAL OPERATORS average count max min reduce sum BOOLEAN OPERATORS every some contains sequenceEqual CONDITIONAL OPERATORS amb FUNCTIONS OPERATIONS
  6. - (BOOL)isFormValid { return [self.usernameField.text length] > 0 && [self.emailField.text

    length] > 0 && [self.passwordField.text length] > 0 && [self.passwordField.text isEqual:self.passwordVerificationField.text]; } #pragma mark - UITextFieldDelegate - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { self.createButton.enabled = [self isFormValid]; return YES; } CALLBACK BASED
  7. RACSignal *formValid = [RACSignal combineLatest:@[ self.username.rac_textSignal, self.emailField.rac_textSignal, self.passwordField.rac_textSignal, self.passwordVerificationField.rac_textSignal ]

    reduce:^(NSString *username, NSString *email, NSString *password, NSString *passwordVerification) { return @([username length] > 0 && [email length] > 0 && [password length] > 8 && [password isEqual:passwordVerification]); }]; RAC(self.createButton.enabled) = formValid; REACTIVE FLOW
  8. SOME SOURCES (& RESOURCES) • An introduction to Reactive Programming,

    by André Stalz. • What is Functional Reactive Programming, in Big Nerd Ranch. • RxMarbles.com • ReactiveCocoa by NSHipster • An introduction to ReactiveCocoa, by Alexandros Salazar. • FRP iOS learning links, by Javi Lorbada • MVVM (Model -View-ViewModel) with ReactiveCocoa. • ReactiveCocoa tutorial (part 1, part 2)