mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-09-30 07:23:18 -09:00
add apply-each and aliases
This commit is contained in:
parent
752aa3f640
commit
fcdf3c6c9d
@ -71,10 +71,42 @@
|
||||
`(do ~@exprs#
|
||||
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
|
||||
(map (static-fn Long/parseLong) ["123" "456"])
|
||||
input-cache
|
||||
|
||||
(apply-each #(* % 2) #(+ % 5) 5 10)
|
||||
(apply-each-v #(* % 2) #(+ % 5) [5 10])
|
||||
|
||||
(log (+ 5 5)
|
||||
(- 2 1))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user