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

Monads in Kotlin

Monads in Kotlin

In this talk, I discuss what a monad is and some of the advantages of using them in your code base. I also walk through how one might implement some common monads, like the Try or Option monads.

Zachary Smith

July 11, 2018
Tweet

More Decks by Zachary Smith

Other Decks in Programming

Transcript

  1. • A higher order function is one that does at

    least one of the following: ◦ takes one or more functions as arguments ◦ returns a function as its result Higher order functions
  2. A monad wraps a value in a meaningful context. •

    List -> Collection • Observable -> Changing values over time • Single -> A single value over time
  3. A monad wraps a value in a meaningful context. •

    List -> Collection • Observable -> Changing values over time • Single -> A single value over time • Try -> Success or failure • Option -> Presence or absence of value
  4. A monad wraps a value in a meaningful context. A

    monad implements map and flatmap. • List -> Collection • Observable -> Changing values over time • Single -> A single value over time • Try -> Success or failure • Option -> Presence or absence of value
  5. Arrow Functional companion to Kotlin’s Standard Library • Popular data

    types, type classes and abstractions for functional programming: ◦ Option ◦ Try ◦ Either ◦ IO ◦ Functor ◦ Applicative ◦ Monad https://arrow-kt.io/
  6. Resources • Kotlin Functors, Applicatives, And Monads in Pictures ◦

    https://hackernoon.com/kotlin-functors-applicatives-and-monads-in-pictures-part-1-3-c47a1b1ce251 • Arrow Library ◦ https://arrow-kt.io/ ◦ https://github.com/arrow-kt/arrow • The Observable disguised as an IO Monad ◦ https://medium.com/@luijar/the-observable-disguised-as-an-io-monad-c89042aa8f31 • Why Monads Are Useful ◦ https://jameswestby.net/weblog/tech/why-monads-are-useful.html