Back
find-derived-1 (clj)
(source)function
(find-derived-1 m k)
Return the map entry in a map, m, where the key is derived from the keyword,
k. If there are no matching keys, nil is returned. If there is more than one
matching key, an ambiguous key exception is raised.
Examples
integrant
(ns integrant.core-test
(:require #?(:clj [clojure.test :refer [are deftest is testing]]
:cljs [cljs.test :refer-macros [are deftest is testing]])
[integrant.core :as ig]
[weavejester.dependency :as dep]))
(deftest find-derived-1-test
(testing "missing key"
(is (nil? (ig/find-derived-1 {} ::p))))
(testing "derived key"
(is (= (ig/find-derived-1 {::a "x" ::p "y"} ::pp)
[::p "y"])))
(testing "ambiguous key"
(is (thrown-with-msg?
#?(:clj clojure.lang.ExceptionInfo :cljs cljs.core.ExceptionInfo)
(re-pattern (str "Ambiguous key: " ::pp "\\. "
"Found multiple candidates: " ::p ", " ::pp))
(ig/find-derived-1 {::a "x" ::p "y", ::pp "z"} ::pp))))
(testing "composite key"
(is (= (ig/find-derived-1 {::a "x" [::b ::x] "y"} ::x)
[[::b ::x] "y"]))))