Skip to content

Instantly share code, notes, and snippets.

View Koisell's full-sized avatar

Nicolas Francois Koisell

View GitHub Profile
def map(fa: Foo[A])(f: A => B): Foo[B] = ???
@Koisell
Koisell / list.scala
Last active September 23, 2019 11:55
// A type which holds a reference to itself:
sealed abstract class List[+A]
final case class Cons[+A](head: A, tail: List[A]) extends List[A]
final case object Nil extends List[Nothing]
// A function which calls itself explicitly:
def length[A](list: List[A]) = list match {
case h::t => 1 + length(t)
case Nil => 0
}
@Koisell
Koisell / foldl.scala
Last active September 23, 2019 11:52
Medium recursion schemes
List(1, 2, 3).foldl(0)(_ + _)
// foldl removes the explicit recursion.
// FOLD, REDUCE, ... already are recursion scheme