Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
(apply assoc m1 (interleave ks (repeat itm))) Demonstration: $ clj Clojure 1.10.3 user=> (def m1 {:a 1 :b 2}) #'user/m1 user=> (def itm 3) #'user/itm user=> (def ks [:c :d :e]) #'...
Answer
#1: Initial revision
`(apply assoc m1 (interleave ks (repeat itm)))` Demonstration: ```clojure $ clj Clojure 1.10.3 user=> (def m1 {:a 1 :b 2}) #'user/m1 user=> (def itm 3) #'user/itm user=> (def ks [:c :d :e]) #'user/ks user=> (apply assoc m1 (interleave ks (repeat itm))) {:a 1, :b 2, :c 3, :d 3, :e 3} ``` A variation on the other answer, this one uses `interleave` and `apply`: * [`interleave`](https://clojuredocs.org/clojure.core/interleave) returns a lazy sequence of the first element from each argument and then the second element from each argument and then the third, etc, until one runs out. * [`apply`](https://clojuredocs.org/clojure.core/apply) calls the given function by treating the last argument (which must be a sequence) as if the elements it contains were directly in the function call. (Works similarly to [spread syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax) in Javascript and [iterable unpacking](https://docs.python.org/3/tutorial/controlflow.html#tut-unpacking-arguments) in Python 3.)