Thank you for purchasing Functional Programming in Scala. Please post any errors, other than those listed below, in the book's Author Online Forum. We'll compile a comprehensive list and publish it here for everyone's convenience. Thank you! Last updated January 8, 2015
https://github.com/fpinscala/fpinscala
throw new Exception
Exception
employeesByName.get("Joe")
lookupByName("Joe")
strean elements should be stream elements
Int.MaxValue
Int.maxValue
nonNegativeLessThan
rng
def nonNegativeLessThan(n: Int): Rand[Int] = { rng => val (i, rng2) = nonNegativeInt(rng) val mod = i % n if (i + (n-1) - mod >= 0) (mod, rng2) else nonNegativeLessThan(n)(rng2) }
| in ParserOps.
case class ParserOps[A](p: Parser[A]) { def |[B>:A](p2: Parser[B]): Parser[B] = self.or(p,p2) def or[B>:A](p2: Parser[B]): Parser[B] = self.or(p,p2) }
listOfN
run(listOfN(3, "ab" | "cad"))("ababcad") == Right(List("ab","ab","cad")) run(listOfN(3, "ab" | "cad"))("cadabab") == Right(List("cad","ab","ab")) run(listOfN(3, "ab" | "cad"))("ababab") == Right(List("ab","ab","ab"))
Leaf
case object.
case class:
case class Leaf[A](value: A) extends Tree[A]
map
Option
def map[A,B](oa: Option[A])(f: A => B): Option[B]
printLine
Return
def printLine(s: String): IO[Unit] = Suspend(() => println(s))
val g = List.fill(100000)(f).foldLeft(f) { (a, b) => x => Suspend(() => ()).flatMap { _ => a(x).flatMap(b)} }
def suspend[A](a: => IO[A]) = Suspend(() => ()).flatMap { _ => a } val g = List.fill(100000)(f).foldLeft(f) { (a, b) => x => suspend { a(x).flatMap(b) } }
TrailRec
TailRec
STArray.apply
object STArray { def apply[S,A:Manifest](sz: Int, v: A): ST[S, STArray[S,A]] = ST(new STArray[S,A] { lazy val value = Array.fill(sz)(v) }) }
Await
loop
await
case class Await[A,O]( req: Is[I]#f[A], recv: Either[Throwable,A] => Process[Is[I]#f,O] ) extends Process[Is[I]#f,R] // `R` should be `O`
case class Await[A,O]( req: Is[I]#f[A], recv: Either[Throwable,A] => Process[Is[I]#f,O] ) extends Process[Is[I]#f,O]