The source for faraday's scan function (https://github.com/ptaoussanis/faraday/blob/master/src/taoensso/faraday.clj#L1197) has a destructuring form that I am struggling to understand...
(source far/scan)
(defn scan
"..."
[client-opts table
& [{:keys [attr-conds last-prim-kvs span-reqs return limit total-segments
filter-expr
segment return-cc?] :as opts
:or {span-reqs {:max 5}}}]]
...)
What does that :or {span-reqs {:max 5}}
do?
It is the default value. For more details please see http://clojure.org/guides/destructuring
(def my-map {:a "A" :b "B" :c 3 :d 4})
(let [{a :a, x :x, :or {x "Not found!"}, :as all} my-map]
(println "I got" a "from" all)
(println "Where is x?" x))
;= I got A from {:a "A" :b "B" :c 3 :d 4}
;= Where is x? Not found!
using :keys
we get
(let [{:keys [a x] :or {x "Not found!"}, :as all} my-map]
(println "I got" a "from" all)
(println "Where is x?" x))
with the same result
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With