mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-09-30 13:03:19 -09:00
add apply-each and aliases
This commit is contained in:
parent
752aa3f640
commit
fcdf3c6c9d
@ -71,10 +71,42 @@
|
|||||||
`(do ~@exprs#
|
`(do ~@exprs#
|
||||||
nil)))
|
nil)))
|
||||||
|
|
||||||
|
(defn apply-each
|
||||||
|
"[& fs vs]
|
||||||
|
fs is a list of funcitons of length N
|
||||||
|
vs is a list of values of length N
|
||||||
|
|
||||||
|
this function returns a vector where each value is the result of applying
|
||||||
|
an f from fs to the corresponding v from vs"
|
||||||
|
[& args]
|
||||||
|
(let [n (/ (count args) 2)]
|
||||||
|
(->> (zipmap (take n args)
|
||||||
|
(take-last n args))
|
||||||
|
(mapv #((first %) (second %))))))
|
||||||
|
|
||||||
|
(defn apply-each-v
|
||||||
|
"[& fs vs]
|
||||||
|
fs is a list of funcitons of length N
|
||||||
|
v is a vector of values of length N
|
||||||
|
|
||||||
|
this function returns a vector where each value is the result of applying
|
||||||
|
an f from fs to the corresponding v from vs"
|
||||||
|
[& args]
|
||||||
|
(->> (zipmap (drop-last args)
|
||||||
|
(last args))
|
||||||
|
(mapv #((first %) (second %)))))
|
||||||
|
|
||||||
|
(def p partial)
|
||||||
|
|
||||||
|
(def a apply)
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(map (static-fn Long/parseLong) ["123" "456"])
|
(map (static-fn Long/parseLong) ["123" "456"])
|
||||||
input-cache
|
input-cache
|
||||||
|
|
||||||
|
(apply-each #(* % 2) #(+ % 5) 5 10)
|
||||||
|
(apply-each-v #(* % 2) #(+ % 5) [5 10])
|
||||||
|
|
||||||
(log (+ 5 5)
|
(log (+ 5 5)
|
||||||
(- 2 1))
|
(- 2 1))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user