Skip to content

Instantly share code, notes, and snippets.

@NicolasLambert
NicolasLambert / test.clj
Last active September 5, 2021 08:30
[Partition every] How to partition a stream on a time basis #clojure #transducer
(deftest partition-every-test
(testing "Should partition based on elapsed time"
(let [item-count 5
result (into []
(comp
(map deref)
(partition-every 100 :millis))
(repeatedly item-count #(future (Thread/sleep 50) 42)))
flatten-result (flatten result)
count-result (map count result)]
@NicolasLambert
NicolasLambert / test.clj
Last active September 5, 2021 08:31
[Sliding Sort] How to sort element between 2 streams #clojure #transducer
(deftest sliding-sort-test
(testing "Should sort all the given element incrementaly"
(let [xf (sliding-sort 10 <)
input [5 6 7 2 4 0 8 3 1 9]
output (into [] xf input)]
(is (= output [0 1 2 3 4 5 6 7 8 9]))))
(testing "Should sort the given element decrementaly in a sliding window of 5"
(let [xf (sliding-sort 5 >)
input [5 6 7 2 4 0 8 3 1 9]
output (into [] xf input)]