AG
Size: a a a
AG
KC
AG
VM
(loop [physical nil
postal nil
[{:keys [type text]} :as r] (get-in value [:organization :resource :address])]
(cond
physical physical
(empty? r) postal
:else (recur ({"physical" text} type)
(or postal ({"postal" text} type))
(rest r))))
TP
IG
(s/and ::my-map-spec ::check-keys)
IG
::check-keys
это функция типаIG
(fn [{:keys [field1 field2]}] (= field1 field2))
IG
TP
TP
IG
TP
AG
AG
MK
ST
(loop [physical nil
postal nil
[{:keys [type text]} :as r] (get-in value [:organization :resource :address])]
(cond
physical physical
(empty? r) postal
:else (recur ({"physical" text} type)
(or postal ({"postal" text} type))
(rest r))))
(defn find-by-priority-pred
"Take sequence of predicated and find first item in xs for best matching predicate."
[preds, xs]
(let [pred (apply some-fn (map-indexed
(fn [i pred] #(when (pred %) [i %]))
preds))]
(second
(reduce (fn [old-res, v]
(let [[^int i _ :as new-res] (pred v)]
(cond
(nil? new-res) old-res
(zero? i) (reduced new-res)
(nil? old-res) new-res
(< i ^int (first old-res)) new-res
:else old-res)))
nil xs))))
=> #'dev.playground/find-by-priority-pred
(find-by-priority-pred [#(= "physical" (:type %))
#(= "postal" (:type %))]
[{:text "42" :type "eternal"}
{:text "123" :type "postal"}
{:text "789" :type "physical"}])
=> {:text "789", :type "physical"}
ST
AC