Skip to content

Instantly share code, notes, and snippets.

@roman
Created August 23, 2011 17:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save roman/1165891 to your computer and use it in GitHub Desktop.
Save roman/1165891 to your computer and use it in GitHub Desktop.
Haskell's zip and zipWith functionality in Clojure
(def fst-elems (map first [[1 4] [2 5] [3 6]]))
(println fst-elems)
; Output: (1 2 3)
(def numbers
(map vector [1 2 3] [4 5 6]))
(println numbers)
; Output: ((1 4) (2 5) (3 6)
numbers :: [Int]
numbers = zip [1, 2, 3] [4, 5, 6]
main :: IO ()
main = print numbers
-- Output: [(1,4), (2,5), (3,6)]
(defn sum-lists [xs ys]
(map + xs ys))
(defn print-user [name last-name age]
(println name " " last-name " has " age " years old"))
(map print-user ["john", "mary"] ["doe", "watson"] [25 23])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment