Skip to content

Instantly share code, notes, and snippets.

@8q
Created October 26, 2018 18:12
Show Gist options
  • Save 8q/6bf771404824eb194671e6ed57c4e22e to your computer and use it in GitHub Desktop.
Save 8q/6bf771404824eb194671e6ed57c4e22e to your computer and use it in GitHub Desktop.
scalaでmapを畳み込みを使って作ってみる
object Main {
def main(args: Array[String]): Unit = {
def map[T, U](ls: List[T])(f: T => U): List[U] = ls.foldRight(Nil: List[U])((x, y) => f(x) :: y)
println(map(List(1, 2, 3))(x => x * 2))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment