-
-
Save pulcheri/68411ab82529da52bcc1015e8740ffd2 to your computer and use it in GitHub Desktop.
Haskell's zip and zipWith functionality in Clojure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def fst-elems (map first [[1 4] [2 5] [3 6]])) | |
(println fst-elems) | |
; Output: (1 2 3) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def numbers | |
(map vector [1 2 3] [4 5 6])) | |
(println numbers) | |
; Output: ((1 4) (2 5) (3 6) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
numbers :: [Int] | |
numbers = zip [1, 2, 3] [4, 5, 6] | |
main :: IO () | |
main = print numbers | |
-- Output: [(1,4), (2,5), (3,6)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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