Given:
(defn foo [x & {:as args}] [x args])
(foo 1 :bar 2 :baz [:quux])
=> [1 {:bar 2, :baz [:quux]}]
If I have those rest-arguments already in a map, what's the most
elegant way to call foo with them?
(def args {:bar 2 :baz [:quux]})
(foo 1 ?)
I feel like I may be missing some simple way o
There's a disconnect between the function definition and the
datastructures used by the caller.
Either fix the data structure:
(def args [:bar 2 :baz [:quux]])
then use apply
Or change the function definition to take a map:
(defn foo [x {:keys [bar baz]}]
...)
On Jun 16, 4:00 pm, Brian Carpe
On Jun 16, 2010, at 7:07 PM, ataggart wrote:
> There's a disconnect between the function definition and the
> datastructures used by the caller.
>
> Either fix the data structure:
> (def args [:bar 2 :baz [:quux]])
> then use apply
>
> Or change the function definition to take a map:
> (defn foo
On Jun 16, 2010, at 9:21 PM, Michael Gardner wrote:
On Jun 16, 2010, at 7:07 PM, ataggart wrote:
There's a disconnect between the function definition and the
datastructures used by the caller.
Either fix the data structure:
(def args [:bar 2 :baz [:quux]])
then use apply
Or change the funct
On Jun 25, 2:57 am, Chas Emerick wrote:
> This is fairly simple:
>
> user=> (defn foo [& {:as args}] [args])
> #'user/foo
> user=> (def m {:a 5 :b 6})
> #'user/m
> user=> (apply foo (-> m seq flatten))
> [{:a 5, :b 6}]
>
> I'm not sure if it could be made easier, short of changing apply
> (which
On Wed, Jun 16, 2010 at 7:00 PM, Brian Carper wrote:
> Given:
>
> (defn foo [x & {:as args}] [x args])
> (foo 1 :bar 2 :baz [:quux])
> => [1 {:bar 2, :baz [:quux]}]
>
> If I have those rest-arguments already in a map, what's the most
> elegant way to call foo with them?
>
> (def args {:bar 2 :baz