{"url":"http://clojuredocs.org/v/1734","examples":[{"namespace_id":99,"ns":"clojure.core","updated_at":"2010-09-27 02:46:03.0","function":"map","version":6,"created_at":"2010-07-09 17:16:17.0","library":"Clojure Core","lib_version":"1.2.0","library_id":3,"body":"user=> (map inc [1 2 3 4 5])\n(2 3 4 5 6)\n\n\n;; map can be used with multiple collections. Collections will be consumed\n;; and passed to the mapping function in parallel:\nuser=> (map + [1 2 3] [4 5 6])\n(5 7 9)\n\n\n;; When map is passed more than one collection, the mapping function will\n;; be applied until one of the collections runs out:\nuser=> (map + [1 2 3] (iterate inc 1))\n(2 4 6)\n\n\n\n;; map is often used in conjunction with the # reader macro:\nuser=> (map #(str \"\" % \"\") [\"the\" \"quick\" \"brown\" \"fox\"])\n(\"the\" \"quick\" \"brown\" \"fox\")\n\n;; A useful idiom to pull \"columns\" out of a collection of collections:\nuser=> (apply map vector [[:a :b :c]\n                          [:d :e :f]\n                          [:g :h :i]])\n\n([:a :d :g] [:b :e :h] [:c :f :i])\n\n\n\n;; From http://clojure-examples.appspot.com/clojure.core/map"},{"namespace_id":99,"ns":"clojure.core","updated_at":"2010-09-26 04:50:56.0","function":"map","version":3,"created_at":"2010-07-13 16:06:11.0","library":"Clojure Core","lib_version":"1.2.0","library_id":3,"body":"user=> (map #(vector (first %) (* 2 (second %)))\n            {:a 1 :b 2 :c 3})\n([:a 2] [:b 4] [:c 6])\n\nuser=> (into {} *1)\n{:a 2, :b 4, :c 6}\n"},{"namespace_id":99,"ns":"clojure.core","updated_at":"2011-07-16 14:00:29.0","function":"map","version":1,"created_at":"2011-07-16 14:00:29.0","library":"Clojure Core","lib_version":"1.2.0","library_id":3,"body":";; Use a hash-map as a function to translate values in a collection from the \n;; given key to the associated value\n\nuser=> (map {2 \"two\" 3 \"three\"} [5 3 2])\n(nil \"three\" \"two\")\n\n;; then use (filter identity... to remove the nils\nuser=> (filter identity (map {2 \"two\" 3 \"three\"} [5 3 2]))\n(\"three\" \"two\")"},{"namespace_id":330,"ns":"clojure.core","updated_at":"2012-10-12 07:36:07.0","function":"map","version":5,"created_at":"2011-11-03 15:03:37.0","library":"Clojure Core","lib_version":"1.3.0","library_id":15,"body":";; mapping over a hash-map applies (into) first. \n;; need to use functions that deal with arrays (fn [[key val]] ...)\n(map pprint {:key :val :key1 :val1})\n([:key :val]\n[:key1 :val1]\nnil nil)\n\n;;above, the pprint output appears to be part of the return value but it's not:\n(hash-set (map pprint {:key :val :key1 :val1}))\n[:key :val]\n[:key1 :val1]\n#{(nil nil)}\n\n(map second {:key :val :key1 :val1})\n(:val :val1)"},{"namespace_id":330,"ns":"clojure.core","updated_at":"2012-08-15 20:30:44.0","function":"map","version":4,"created_at":"2012-08-15 20:25:24.0","library":"Clojure Core","lib_version":"1.3.0","library_id":15,"body":"(map fn [a 4 x]\n        [b 5 y]\n        [c 6])    \n;        ^ ^\n; applies fn to a b c as (fn a b c)\n; applies fn to 4 5 6 as (fn 4 5 6)\n; ignores (x y)\n; returns a list of results\n; equivalent to (list (fn a b c) (fn 4 5 6))\n\n;example\n(map list [1 2 3]\n         '(a b c)\n         '(4 5))\n\nuser=> (map list  [1 2 3] '(a b c) '(4 5))\n((1 a 4) (2 b 5))\n;same as\nuser=> (list (list 1 'a 4) (list 2 'b 5))\n((1 a 4) (2 b 5))"}]}