Created
March 6, 2015 07:31
-
-
Save ray1729/c09c002d3d6adba4cad2 to your computer and use it in GitHub Desktop.
This file contains 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 xs (sort (repeatedly 30 #(rand-int 20)))) | |
(def ys (sort (repeatedly 25 #(rand-int 20)))) | |
(defn merge-sorted-seqs | |
[xs ys] | |
(lazy-seq (cond | |
(empty? xs) (seq ys) | |
(empty? ys) (seq xs) | |
:else (let [x (first xs) y (first ys)] | |
(if (<= x y) | |
(cons x (merge-sorted-seqs (rest xs) ys)) | |
(cons y (merge-sorted-seqs xs (rest ys)))))))) | |
;; If you then want to process equal elements together: | |
(partition-by identity (merge-sorted-seqs xs ys)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment