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 153
153
154
154
(s/or :even even? :small #(< % 42))
155
155
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."
159
160
[& key-pred-forms]
160
161
(let [pairs (partition 2 key-pred-forms)
161
162
keys (mapv first pairs)
197
198
198
199
(s/alt :even even? :small #(< % 42))
199
200
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."
202
205
[& key-pred-forms]
203
206
(let [pairs (partition 2 key-pred-forms)
204
207
keys (mapv first pairs)
Original file line number Diff line number Diff line change 603
603
(with-gen* [_ gfn] (tuple-impl forms preds gfn))
604
604
(describe* [_] `(tuple ~@forms)))))
605
605
606
+ (defn- tagged-ret [v]
607
+ (specify! v
608
+ IMapEntry
609
+ (-key [_] (-nth v 0 ))
610
+ (-val [_] (-nth v 1 ))))
606
611
607
612
(defn ^:skip-wiki or-spec-impl
608
613
" Do not call this directly, use 'or'"
616
621
(let [ret (dt pred x (nth forms i))]
617
622
(if (= ::invalid ret)
618
623
(recur (inc i))
619
- [(keys i) ret])))
624
+ ( tagged-ret [(keys i) ret]) )))
620
625
::invalid )))]
621
626
(reify
622
627
IFn
747
752
(if (nil? pr)
748
753
(if k1
749
754
(if (accept? p1)
750
- (accept [k1 (:ret p1)])
755
+ (accept ( tagged-ret [k1 (:ret p1)]) )
751
756
ret)
752
757
p1)
753
758
ret)))))
799
804
::pcat (add-ret p0 ret k)
800
805
::alt (let [[[p0] [k0]] (filter-alt ps ks forms accept-nil?)
801
806
r (if (nil? p0) ::nil (preturn p0))]
802
- (if k0 [k0 r] r)))))
807
+ (if k0 ( tagged-ret [k0 r]) r)))))
803
808
804
809
(defn- op-unform [p x]
805
810
; ;(prn {:p p :x x})
You can’t perform that action at this time.
0 commit comments