Skip to content

Instantly share code, notes, and snippets.

@williamboxhall
Created December 23, 2014 05:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save williamboxhall/1b58acf601c8f6c5c1ca to your computer and use it in GitHub Desktop.
Save williamboxhall/1b58acf601c8f6c5c1ca to your computer and use it in GitHub Desktop.
higher order functions w/ generic collections
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