Created
December 23, 2014 05:47
-
-
Save williamboxhall/1b58acf601c8f6c5c1ca to your computer and use it in GitHub Desktop.
higher order functions w/ generic collections
This file contains 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
val setToSet: Set[Int] => Set[String] = { _.map(_.toString + "potato")} | |
val listToList: List[Int] => List[String] = { _.map(_.toString + "tomato")} | |
val listToIterable: List[Int] => Iterable[String] = { _.map(_.toString + "ristretto")} | |
println(setToSet(Set(1,2))) | |
println(listToList(List(1,2))) | |
println(listToIterable(List(1,2))) | |
def printer(fn: Iterable[Int] => Iterable[String], inputs: Iterable[Int]) = println(fn(inputs)) | |
printer(setToSet, Set(1,2)) // doesn't compile | |
printer(listToList, List(1,2)) // doesn't compile | |
printer(listToIterable, List(1,2)) // doesn't compile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment