This file contains hidden or 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 map(fa: Foo[A])(f: A => B): Foo[B] = ??? |
This file contains hidden or 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
// A function which calls itself explicitly: | |
def length[A](list: List[A]) = list match { | |
case h::t => 1 + length(t) | |
case Nil => 0 | |
} |
This file contains hidden or 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
// 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] |
This file contains hidden or 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
List(1, 2, 3).foldl(0)(_ + _) | |
// foldl removes the explicit recursion. | |
// FOLD, REDUCE, ... already are recursion scheme |