Mo'Problems, Mo'Nads

35761e3936deba2f8189c2d20982c771?s=47 Kyle Simpson
September 14, 2020

Mo'Problems, Mo'Nads

Monads; just that word alone probably either made you shudder or roll your eyes. But don't run away!

Functional Programming (FP) offers many benefits to our programs, even in a loose/flexible language like JS. But we often avoid them just because of intimidating terminology, notation, and math theory. Rarely is this more prevalent than with monads.

This talk is not a dissertation on monads and broader category theory. We're merely dipping our toe into the shallow end here, not plunging head first into the deep end. But I hope maybe it entices you to swim around, because the water's actually quite pleasant!

We'll look at familiar problems in code that we typically solve imperatively, and then see how some of the de-mystified behaviors associated with monads (and friends!) can help. After this talk, I hope you'll look more closely at monads and other algebraic structures.

Topics illustrated: selecting values with conditional logic, forking behavior on exceptions, and juggling asynchronous side effects.

35761e3936deba2f8189c2d20982c771?s=128

Kyle Simpson

September 14, 2020
Tweet

Transcript

  1. Mo’Problems, Mo’nads getify (kyle simpson)

  2. "Some people, when confronted with a problem, think 'I know,

    I'll use regular expressions.' Now they have two problems." -- Jamie Zawinski
  3. regexes get a bad rap

  4. None
  5. “right tool … blah blah…” specialized vs generalized

  6. Monads unit(a) >>= λx → f(x) ↔ f(a) ma >>=

    λx → unit(x) ↔ ma ma >>= λx → (f(x) >>= λy → g(y)) ↔ (ma >>= λx → f(x)) >>= λy → g(y)
  7. "algebras, and categories, and type theory… oh my!"

  8. None
  9. there’s only one right way to explain monads!

  10. types vs values

  11. types: behaviors we can expect values: behaviors we can use

  12. what does monad mean? the Monad (type/interface) vs a monad

    (value)
  13. the Monad: 3 laws a monad: data structure

  14. https://github.com/getify/Monio

  15. None
  16. monads & friends

  17. None
  18. why monads?

  19. 1. choose a value or fallback? 2. gracefully handle exceptions?

    3. manage side effects? how could I...
  20. 1. choose a value or fallback? Maybe Monad

  21. None
  22. None
  23. None
  24. 2. gracefully handle exceptions? Either Monad

  25. None
  26. 3. manage side effects? IO Monad

  27. None
  28. None
  29. https://codepen.io/getify/pen/YzyJqZa?editors=1011 3. IO + Maybe + Either + ...

  30. None