Skip to content

Instantly share code, notes, and snippets.

@rafd
Created July 21, 2021 00:53
Show Gist options
  • Save rafd/df2eb2a8ace1e3b628a3f484cc811c65 to your computer and use it in GitHub Desktop.
Save rafd/df2eb2a8ace1e3b628a3f484cc811c65 to your computer and use it in GitHub Desktop.
clojure meetup 2021-07-20
(cleave 5 [#(* % 2) dec #(* % %)])
;; => [10 4 25]
(defn cleave [x fs]
((apply juxt fs) x))
(defn cleave2 [x fs]
(map #(% x) fs))
(defn cleave3 [x fs]
(reduce #(conj %1 (%2 x)) [] fs))
(defn cleave4 [x fs]
(->> (iterate
(fn [[result [f & fs]]] [(conj result (f x)) fs])
[[] fs])
(take (inc (count fs)))
last
first))
(defn cleave5 [x fs]
(loop [r []
[f & rest] fs]
(if (nil? f)
r
(recur (conj r (f x)) rest))))
(defn foo [x r [f & rest]]
(if (nil? f)
r
#(foo x (conj r (f x)) rest)))
(defn cleave6 [x fs]
(trampoline foo x [] fs))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment