Created
July 21, 2021 00:53
-
-
Save rafd/df2eb2a8ace1e3b628a3f484cc811c65 to your computer and use it in GitHub Desktop.
clojure meetup 2021-07-20
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
(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