Add <??, a null-safe variant of <?.

This commit is contained in:
Richard Newman 2016-11-08 12:09:13 -08:00
parent 7e50528788
commit 8e6f8399ae

View file

@ -71,6 +71,13 @@
(consume-pair (cljs.core.async/<! ~pc-chan)) (consume-pair (cljs.core.async/<! ~pc-chan))
(consume-pair (clojure.core.async/<! ~pc-chan)))) (consume-pair (clojure.core.async/<! ~pc-chan))))
(defmacro <??
"Takes from the channel if it's non-nil."
[pc-chan]
`(let [c# ~pc-chan]
(when c#
(datomish.pair-chan/<? c#))))
(defn consume-pair (defn consume-pair
"When passed a [value nil] pair, returns value. When passed a [nil error] pair, "When passed a [value nil] pair, returns value. When passed a [nil error] pair,
throws error. See also `<?`." throws error. See also `<?`."