JavaScript:
map = (fn, [x, ...xs]) => (x === undefined ? [] : [fn(x), ...map(fn, xs)])
Python:
map = lambda f, xs: [f(x) for x in xs]
Haskell:
map _ [] = []
map f (x:xs) = f x : map f xs
Clojure:
(defn map
[f coll]
(reduce (fn [acc, x] (conj acc (f x))) [] coll))
Kotlin
fun <A, B> map(f: (A) -> B, coll: List<A>) = arrayListOf<B>().apply {
coll.forEach { add(f(it)) }
}
Ruby:
def map(coll, &fn)
acc = []
coll.each do |x|
acc << fn.call(x)
end
acc
end