Skip to content

Instantly share code, notes, and snippets.

@fogus
Created August 24, 2010 16:27
Show Gist options
  • Save fogus/547833 to your computer and use it in GitHub Desktop.
Save fogus/547833 to your computer and use it in GitHub Desktop.
;; returns a map
(def numbered-elements (partial zipmap (iterate inc 0)))
(numbered-elements '[a b c d])
;=> {3 d, 2 c, 1 b, 0 a}
;; returns a seq of pairs
(def numbered-elements #(->> % (interleave (iterate inc 0)) (partition 2)))
(numbered-elements '[a b c d])
;=> ((0 a) (1 b) (2 c) (3 d))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment