Fork me on GitHub
#beginners
<
2016-03-21
>
urbanslug09:03:29

Hey I just saw something new in some arguments passed I saw ...{:keys [foo bar] :or {foobar :baz}… What is the :or for?

urbanslug09:03:14

I haven’t seen it in any book with destructuring. Also google is not helping

lmergen13:03:59

urbanslug: by any chance, was that something like buddy-auth ?

lmergen13:03:22

that :or is just a key

lmergen13:03:43

so what you're actually constructing is a map with two keys, :keys and :or

urbanslug14:03:54

@lmergen: I don’t know what buddy-auth is.

lmergen14:03:01

doesn't matter

urbanslug14:03:02

I wasn’t constructing it was during destructuring. It creates a new key and value if it doesn’t find it in the map.

Alex Miller (Clojure team)14:03:15

@urbanslug: :or allows you to provide default values in the case that the keys are not present

Alex Miller (Clojure team)14:03:47

which reminds me that I am overdue for finalizing the destructuring guide for http://clojure.org https://github.com/clojure/clojure-site/pull/24

urbanslug16:03:35

@alexmiller: Claps for you 😄