Skip to content

Instantly share code, notes, and snippets.

@ChristopherDavenport
Last active February 28, 2016 17:33
Show Gist options
  • Save ChristopherDavenport/0617a49109c0e9f5f7e4 to your computer and use it in GitHub Desktop.
Save ChristopherDavenport/0617a49109c0e9f5f7e4 to your computer and use it in GitHub Desktop.
Scala Problem
def reverse[A](as: List[A]): List[A] = {
foldLeft(as, List[A]())((acc, x) => x::acc)
}
def foldRightFromFoldLeft[A,B](as: List[A], z:B)(f:(B, A) => B):B ={
foldLeft(reverse(as), z)((onlyNil, x) =>f(onlyNil, x) )
}
// The Problem Child
// Type checker has a problem with both x.toString :: onlyNil or as seen below.
def doubleToString(as: List[Double]): List[String] ={
foldRightFromFoldLeft(as, List[String]())((onlyNil, x) => x.toString :: onlyNil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment