##Scala eXchange 2014 slides
collected by Adam Warski
Feel free to complete the list!
The Binary Compatibility Challenge by Martin Odersky
A Skeptic's Look at scalaz' "Gateway Drugs”: A Practical Exploration by Brendand McAdams
##Scala eXchange 2014 slides
collected by Adam Warski
Feel free to complete the list!
The Binary Compatibility Challenge by Martin Odersky
A Skeptic's Look at scalaz' "Gateway Drugs”: A Practical Exploration by Brendand McAdams
def foldLeft[A,B](as: List[A], b: B)(f: (B, A) => B): B | |
as match { | |
case Nil => b | |
case Cons(h,t) => foldLeft(t, f(b, h))(f) | |
} |
def foldRight[A,B](as: List[A], b: B)(f: (A, B) => B): B = | |
as match { | |
case Nil => b | |
case Cons(x, xs) => f(x, foldRight(xs, b)(f)) | |
} | |
foldRight(List(1, 2, 3)) ((x,y) => x + y) | |
foldRight(Cons(1, Cons(2, Cons(3, Nil))), 0) ((x,y) => x + y) | |
1 + foldRight(Cons(2, Cons(3, Nil)), 0) ((x,y) => x + y) | |
1 + (2 + foldRight(Cons(3, Nil), 0) ((x,y) => x + y)) |
foldLeft(List(1,2,3), 0) (_ + _) | |
foldLeft(Cons(1, Cons(2, Cons(3, Nil))), 0) (_ + _) | |
foldLeft(Cons(2, Cons(3, Nil)), (0 + 1)) (_ + _) | |
foldLeft(Cons(3, Nil), ((0 + 1) + 2)) (_ + _) | |
foldLeft(Nil, (((0 + 1) + 2) + 3)) (_ + _) | |
(((0 + 1) + 2) + 3)) |
// foldLeft's meaty bit | |
case Cons(h,t) => foldLeft(t, f(b, h))(f) | |
// foldRight meaty bit | |
case Cons(x, xs) => f(x, foldRight(xs, b)(f)) |
foldLeft(List(1,2,3), 0)(_ + _) |
def foldLeft[A,B](as: List[A], b: B)(f: (B, A) => B): B = as match { | |
case Nil => b | |
case h :: t => foldLeft(t, f(b, h))(f) | |
} |
foldLeft(2 :: 3 :: Nil, (0 + 1)) (_ + _) |
foldLeft(2 :: 3 :: Nil, (0 + 1)) (_ + _) |
foldLeft(List(1,2,3), 0) (_ + _) | |
foldLeft(1 :: 2 :: 3 :: Nil, 0) (_ + _) | |
foldLeft(2 :: 3 :: Nil, f(0, 1)) (_ + _) | |
foldLeft(2 :: 3 :: Nil, (0 + 1)) (_ + _) | |
foldLeft(3 :: Nil, ((0 + 1) + 2)) (_ + _) |