The lightning talk version of this talk.
Monads you’vealready put in prodTejas DinkarNilenso Software
View Slide
about.me• Hi, I’m Tejas• Nilenso: Partner• twitter: tdinkar• github: gja
If you think you understand Monads,you don't understand Monads.
This talk is inaccurate and willmake a mathematician cry
Monads• Programmable Semicolons• Used to hide plumbing away from you• Monads are just monoids in the category ofendofunctors
ValuesValue
MonadsValueBox
Monads• Monads define two functions• return takes a value and puts it in a box• bind takes a box & function, and returns a boxwith f(value)
Some math(√4) + 5
Some math(√4) + 53 or 7!
Value4
Monad[4]
returndef m_return(x)[x]end# m_r(4) => [4]
Square Root fndef sqrt(x)s = Math.sqrt(x)[s, -s]end# sqrt(4) => [2, -2]
Bind Functionx = m_return(4)y = ?????(x) { |p|sqrt(p)}# I want [-2, 2]
Bind Functionx = m_return(4)y = x.flat_map {|p|sqrt(p)}# y => [2, -2]
Increment Fndef inc_5(x)[x + 5]end# inc_5(1) => [6]
Putting it togetherm_return(4).flat_map {|p| sqrt(p)}.flat_map {|p| inc_5(p)}# => [3, 7]
You have invented theList Monad, used tomodel non-determinismCongrats