File tree Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Original file line number Diff line number Diff line change 153153
154154 (s/or :even even? :small #(< % 42))
155155
156- Returns a destructuring spec that
157- returns a vector containing the key of the first matching pred and the
158- corresponding value."
156+ Returns a destructuring spec that returns a map entry containing the
157+ key of the first matching pred and the corresponding value. Thus the
158+ 'key' and 'val' functions can be used to refer generically to the
159+ components of the tagged return."
159160 [& key-pred-forms]
160161 (let [pairs (partition 2 key-pred-forms)
161162 keys (mapv first pairs)
197198
198199 (s/alt :even even? :small #(< % 42))
199200
200- Returns a regex op that returns a vector containing the key of the
201- first matching pred and the corresponding value."
201+ Returns a regex op that returns a map entry containing the key of the
202+ first matching pred and the corresponding value. Thus the
203+ 'key' and 'val' functions can be used to refer generically to the
204+ components of the tagged return."
202205 [& key-pred-forms]
203206 (let [pairs (partition 2 key-pred-forms)
204207 keys (mapv first pairs)
Original file line number Diff line number Diff line change 603603 (with-gen* [_ gfn] (tuple-impl forms preds gfn))
604604 (describe* [_] `(tuple ~@forms)))))
605605
606+ (defn- tagged-ret [v]
607+ (specify! v
608+ IMapEntry
609+ (-key [_] (-nth v 0 ))
610+ (-val [_] (-nth v 1 ))))
606611
607612(defn ^:skip-wiki or-spec-impl
608613 " Do not call this directly, use 'or'"
616621 (let [ret (dt pred x (nth forms i))]
617622 (if (= ::invalid ret)
618623 (recur (inc i))
619- [(keys i) ret])))
624+ ( tagged-ret [(keys i) ret]) )))
620625 ::invalid )))]
621626 (reify
622627 IFn
747752 (if (nil? pr)
748753 (if k1
749754 (if (accept? p1)
750- (accept [k1 (:ret p1)])
755+ (accept ( tagged-ret [k1 (:ret p1)]) )
751756 ret)
752757 p1)
753758 ret)))))
799804 ::pcat (add-ret p0 ret k)
800805 ::alt (let [[[p0] [k0]] (filter-alt ps ks forms accept-nil?)
801806 r (if (nil? p0) ::nil (preturn p0))]
802- (if k0 [k0 r] r)))))
807+ (if k0 ( tagged-ret [k0 r]) r)))))
803808
804809(defn- op-unform [p x]
805810 ; ;(prn {:p p :x x})
You can’t perform that action at this time.
0 commit comments