Skip to content

Instantly share code, notes, and snippets.

@klaeufer
Last active March 7, 2016 02:16
Show Gist options
  • Select an option

  • Save klaeufer/5bd56a9ab1754e56fc2c to your computer and use it in GitHub Desktop.

Select an option

Save klaeufer/5bd56a9ab1754e56fc2c to your computer and use it in GitHub Desktop.
val zeroTo: GenericCoalgebra[Int, Option, Int] = n => {
require { n >= 0 }
if (n == 0) (0, None)
else (n, Some(n - 1))
}
val treeFromInt: GenericCoalgebra[Int, List, Int] = n => {
require { n >= 0 }
if (n == 0) (0, List.empty)
else (n, List(n - 1, n - 1))
}
def treeFromInt2(n: Int): (Int, () => Stream[Int]) = {
require { n >= 0 }
if (n == 0) (0, () => Stream.empty)
else (n, () => Stream(n - 1, n - 1))
}
// Tree.unfoldTree(3)(treeFromInt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment