Created
August 4, 2020 06:40
-
-
Save bsless/6f2029d830a1fb24f12e50f6cdd09441 to your computer and use it in GitHub Desktop.
sort of cons-ing of sequences
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
| (require '[clojure.core.protocols :as p]) | |
| (deftype Concatenation [coll1 coll2] | |
| clojure.lang.IReduceInit | |
| (reduce [_ f init] | |
| (reduce f coll2 (reduce f init coll1 ))) | |
| clojure.lang.Seqable | |
| (seq [this] (concat coll1 coll2))) | |
| (defn concatenation | |
| ([coll1] coll1) | |
| ([coll1 coll2] (Concatenation. coll1 coll2)) | |
| ([coll1 coll2 coll3] | |
| (-> coll1 | |
| (Concatenation. coll2) | |
| (Concatenation. coll3))) | |
| ([coll1 coll2 coll3 & colls] | |
| (loop [c (-> coll1 | |
| (Concatenation. coll2) | |
| (Concatenation. coll3)) | |
| [coll & colls] colls] | |
| (if coll | |
| (Concatenation. c coll) | |
| c)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment