Created
November 28, 2017 22:40
-
-
Save sderosiaux/42103f75b265c6b14f641b6069784673 to your computer and use it in GitHub Desktop.
Trampoline using Cats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def value(i: List[Int]): Trampoline[List[Int]] = i match { | |
case Nil => Free.pure(Nil) | |
case head :: tail => Free.defer(value(tail)).flatMap { l => Free.pure(head + 1 :: l) } | |
} | |
import cats.implicits._ | |
println(value((1 to 10).toList).run) // List(2, 3, 4, 5, 6, 7, 8, 9, 10, 11) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment