Last active
February 28, 2016 17:33
-
-
Save ChristopherDavenport/0617a49109c0e9f5f7e4 to your computer and use it in GitHub Desktop.
Scala Problem
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 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