Skip to content

Instantly share code, notes, and snippets.

@leandrob13
Created April 16, 2016 16:21
Show Gist options
  • Save leandrob13/f30e2da0ea7e898378153e1c5866c833 to your computer and use it in GitHub Desktop.
Save leandrob13/f30e2da0ea7e898378153e1c5866c833 to your computer and use it in GitHub Desktop.
Scala worksheet with a simple ListT test
import cats.data.{Kleisli, ListT}
import cats.std.list._
type ListTA[A] = ListT[List, A]
val (f, g, h, x) = (
(a: Int) => a match {
case 0 => ListT.fromList(List(List(0, 1)))
case 1 => ListT.fromList(List(List(0), List(1)))
},
(b: Int) => b match{
case 0 => ListT.fromList(List(List(0, 1)))
case 1 => ListT.fromList(List(List(0), List(1)))
},
(c: Int) => c match {
case 0 => ListT.fromList(List(List(0, 1)))
case 1 => ListT.fromList(List(List(0), List(1)))
}, 1
)
val (kf, kg, kh) =
(Kleisli[ListTA, Int, Int](f), Kleisli[ListTA, Int, Int](g), Kleisli[ListTA, Int, Int](h))
val z = ((kf andThen kg) andThen kh).run(0).toList
val y = (kf andThen (kg andThen kh)).run(0).toList
z == y
val fa = ListT.fromList(List(List(1)))
val a = fa.flatMap(f).flatMap(g).toList
val b = fa.flatMap(a => f(a).flatMap(g)).toList
a == b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment