2013. október 18., péntek

map, keep, filter, remove, some

clojure.core/map

map

map can be used to call a function for each element of a collection and replace them with the result of the function.

(map even? [1 2 3 4 5 6])
;=> [false true false true false true]

Tip: hash-maps can be used as functions, mapping keys to values.

(map {1 "one", 2 "two", 3 "three"} [2 1 1 3])
;=> ["two" "one" "one" "three"]


Tip: you can give multiple collections to this functions, the result will have the length of the shortest.

(map + [3 2 5 4] (range))
;=> (3 3 7 7)