Thanks for your input Sean
On Saturday, May 4, 2013 3:07:49 AM UTC+3, Sean Corfield wrote:
Just merge the new, known values back in since they've already been
bound to their (possibly defaulted) values:
(let [params (assoc params :my-key my-key)] ...)
Sean
On Fri, May 3, 2013 at
Hi Ryan,
I actually run into this quite often and feel that it's something that's
missing from destructuring:
http://grokbase.com/t/gg/clojure/128z9e3sqj/possible-to-merge-destructuring-or-defaults-with-as
Basically, I'd advocate the addition of a new `:merge-as` destructure
option that
Hey Peter,
I personally found out that I require this functionality more when I am
building web apps because I pass around the url query parameters to other
functions for validation or other tasks and build my sql queries from there
so some default are required. For several other clojure
Hello all,
I have a question regarding the default values when destructuring with :keys
Let's assume that we have the following function:
*(defn my-function [{:keys [my-key] :or {my-key 5} :as params}]
(str my-key value is (:my-key params)))*
A few test runs:
*user= (my-function
The value of :my-key (or the default, if :my-key doesn't exist) is being
bound to the symbol my-key, so all you need to do is this:
(defn my-function [{:keys [my-key] :or {my-key 5} :as params}]
* (str my-key value is my-key))*
On Friday, May 3, 2013 1:52:46 PM UTC-5, Ryan wrote:
Hello
Thanks Anthony for your reply but I was already aware of that. I was hoping
for some solution which would took care of the binding if *:as* was
provided and would append the key-value to the *:as* parameter.
I probably need to do that myselfbut you never know, someone else might
have done
The :as key binds the entire _original_ map.
The :or defaults apply only to the bound variables extracted from the map.
It caught me out when I first used map destructuring but I soon got used to it.
On Fri, May 3, 2013 at 12:08 PM, Ryan arekand...@gmail.com wrote:
Thanks Anthony for your
Well, I need to do something more clever because I am passing the whole
map to another function which does validation on the key-value pairs.
Soi guess I need to append those default associations to the original
map myself...
Something like...
*(defn my-function [{:keys [my-key] :or
What about merging with a default map?
(defn my-function [params]
(let [params (merge {:my-key 5} params)]
(str my-key value is (:my-key params
Well, I need to do something more clever because I am passing the whole
map to another function which does validation on the key-value
Ah, the default nap is a nice idea :)
--
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your
first post.
To
Just merge the new, known values back in since they've already been
bound to their (possibly defaulted) values:
(let [params (assoc params :my-key my-key)] ...)
Sean
On Fri, May 3, 2013 at 12:38 PM, Ryan arekand...@gmail.com wrote:
Well, I need to do something more clever because I am passing
11 matches
Mail list logo