Functional Reactive Programming

Functional Reactive Programming

Slides for a talk by Wilkes Joiner at Nashville Code Co-op Talk Day.

8341c5bff3dcbd8ed34d9d68bd4169f2?s=128

Jason Orendorff

March 30, 2013
Tweet

Transcript

  1. Functional Reactive Programming

  2. “Everything flows, nothing stands still.” Heraclitus

  3. Streams of Events

  4. Streams of Events • Fire and forget events are relatively

    easy to create.
  5. Streams of Events • Fire and forget events are relatively

    easy to create. • UIs
  6. Streams of Events • Fire and forget events are relatively

    easy to create. • UIs • Ajax posts
  7. Streams of Events • Fire and forget events are relatively

    easy to create. • UIs • Ajax posts • Messaging queues
  8. Processing Events

  9. Processing Events • A little trickier

  10. Processing Events • A little trickier • difficult to compose

  11. Processing Events • A little trickier • difficult to compose

    • lots of plumbing
  12. Processing Events • A little trickier • difficult to compose

    • lots of plumbing • Callback Hell
  13. “We’re going to need a bigger boat.”

  14. FRP • A model for values that vary over time

    • Originates from Haskell Community • Several different implementation styles • We are focusing on Microsoft’s ReactiveExtenions style
  15. Observable

  16. Observable • A marriage of Iterables and the Observer Pattern

  17. Observable • A marriage of Iterables and the Observer Pattern

    • Typical Sequence functions - Map, Filter, Reduce, Take
  18. Observable • A marriage of Iterables and the Observer Pattern

    • Typical Sequence functions - Map, Filter, Reduce, Take • Subscribe/OnNext
  19. Observable • A marriage of Iterables and the Observer Pattern

    • Typical Sequence functions - Map, Filter, Reduce, Take • Subscribe/OnNext • Error Handling
  20. Observable • A marriage of Iterables and the Observer Pattern

    • Typical Sequence functions - Map, Filter, Reduce, Take • Subscribe/OnNext • Error Handling • Timing function - Delay
  21. Observable • A marriage of Iterables and the Observer Pattern

    • Typical Sequence functions - Map, Filter, Reduce, Take • Subscribe/OnNext • Error Handling • Timing function - Delay • Buffering - Last N events
  22. Observable • A marriage of Iterables and the Observer Pattern

    • Typical Sequence functions - Map, Filter, Reduce, Take • Subscribe/OnNext • Error Handling • Timing function - Delay • Buffering - Last N events • Composable - SelectMany/FlatMap
  23. Marble Diagrams

  24. A Marble Diagrams

  25. A Marble Diagrams

  26. A B Marble Diagrams

  27. A B Marble Diagrams

  28. A B A.merge(B Marble Diagrams

  29. A B A.merge(B Marble Diagrams

  30. A B A.merge(B Marble Diagrams

  31. A B A.merge(B Marble Diagrams

  32. A B A.merge(B Marble Diagrams

  33. A B A.merge(B Marble Diagrams

  34. A B A.merge(B Marble Diagrams

  35. A B A.merge(B Marble Diagrams

  36. A B A.merge(B Marble Diagrams

  37. A B A.merge(B Marble Diagrams

  38. A B A.merge(B Marble Diagrams

  39. Autocomplete • On Keyup • Get the value of the

    field • Only values of length 3 or more • Make remote call • Filter out bad response • Display results
  40. Autocomplete in reality • On Keyup • Get the value

    of the field • Throttle to 500ms • Only values of length 3 or more • Skip duplicates • Make remote call • Filter out bad response • Display results
  41. Demo Source code: https://github.com/Cicayda/yolk-examples