Skip to content

Instantly share code, notes, and snippets.

@arosien
Last active December 25, 2015 17:19
Show Gist options
  • Save arosien/7011939 to your computer and use it in GitHub Desktop.
Save arosien/7011939 to your computer and use it in GitHub Desktop.
def twice: Int => Option[Int] = i => Some(i * 2)
def stringit: Int => Option[String] = i => Some(i.toString)
val kleislish: Int => Option[String] =
Kleisli.ask[Option, Int] >=> Kleisli(twice) >=> Kleisli(stringit)
type KInt[M[+_], A] = Kleisli[M, Int, A]
val forcomprehensionish: Int => Option[String] =
for {
i <- Kleisli.ask[Option, Int]
ii <- twice(i).liftM[KInt]
s <- stringit(ii).liftM[KInt]
} yield s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment