Skip to content

Instantly share code, notes, and snippets.

@pulcheri
Forked from roman/Zip.hs
Created February 21, 2017 12:50
Show Gist options
  • Save pulcheri/68411ab82529da52bcc1015e8740ffd2 to your computer and use it in GitHub Desktop.
Save pulcheri/68411ab82529da52bcc1015e8740ffd2 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