|
4434 | 4434 | ([f] (lazy-seq (cons (f) (repeatedly f)))) |
4435 | 4435 | ([n f] (take n (repeatedly f)))) |
4436 | 4436 |
|
| 4437 | +(defn counted? |
| 4438 | + "Returns true if coll implements count in constant time" |
| 4439 | + {:added "1.0" |
| 4440 | + :static true} |
| 4441 | + [coll] (instance? clojure.lang.Counted coll)) |
| 4442 | + |
| 4443 | +(defn empty? |
| 4444 | + "Returns true if coll has no items. To check the emptiness of a seq, |
| 4445 | + please use the idiom (seq x) rather than (not (empty? x))" |
| 4446 | + {:added "1.0" |
| 4447 | + :static true} |
| 4448 | + [coll] |
| 4449 | + (if (counted? coll) |
| 4450 | + (zero? (count coll)) |
| 4451 | + (not (seq coll)))) |
| 4452 | + |
4437 | 4453 | (declare reduce-kv) |
4438 | 4454 |
|
4439 | 4455 | (defn some-vals |
|
4506 | 4522 | gdefaults (when defaults (zipmap (keys defaults) (repeatedly #(gensym "default__")))) |
4507 | 4523 | select (:select b) |
4508 | 4524 | all (:all b) |
| 4525 | + excess (:excess b) |
4509 | 4526 | xf (fn [mk] |
4510 | 4527 | (let [mkns (namespace mk) |
4511 | 4528 | mkn (name mk)] |
|
4529 | 4546 | (if (:as b) |
4530 | 4547 | (conj ret (:as b) gmap) |
4531 | 4548 | ret)))) |
4532 | | - bes (dissoc b :as :or :select :all) |
| 4549 | + bes (dissoc b :as :or :select :all :excess) |
4533 | 4550 | localize (fn [bb] (if (instance? clojure.lang.Named bb) |
4534 | 4551 | (with-meta (symbol nil (name bb)) (meta bb)) bb)) |
4535 | 4552 | push1 (fn [ret bb bk req?] |
|
4550 | 4567 | (-> ret (conj local bv)) |
4551 | 4568 | (pb ret bb bv)))) |
4552 | 4569 | retsel |
4553 | | - (loop [ret ret, sel #{}, bes bes, b->k {}, subs nil, suba nil] |
| 4570 | + (loop [ret ret, sel #{}, bes bes, b->k {}, subs nil, suba nil, subd nil] |
4554 | 4571 | (if (seq bes) |
4555 | 4572 | (let [be (first bes), bb (key be), bk (val be)] |
4556 | 4573 | (if (keyword? bb) |
|
4579 | 4596 | (next bbs) preamp? |
4580 | 4597 | (if preamp? (assoc b->k (localize bb) bk) b->k))))) |
4581 | 4598 | {:ret ret, :sel sel, :b->k b->k}))] |
4582 | | - (recur (:ret retsel) (:sel retsel) (next bes) (:b->k retsel) subs suba)) |
| 4599 | + (recur (:ret retsel) (:sel retsel) (next bes) (:b->k retsel) subs suba subd)) |
4583 | 4600 | (let [subsel? (and select (map? bb)) |
4584 | 4601 | bb (if (or (not subsel?) (:select bb)) |
4585 | 4602 | bb |
|
4591 | 4608 | bb |
4592 | 4609 | (assoc bb :all (gensym "all__"))) |
4593 | 4610 | suba (if suball? (assoc suba bk (:all bb)) suba) |
4594 | | - |
| 4611 | + |
| 4612 | + subexcess? (and excess (map? bb)) |
| 4613 | + bb (if (or (not subexcess?) (:excess bb)) |
| 4614 | + bb |
| 4615 | + (assoc bb :excess (gensym "excess__"))) |
| 4616 | + subd (if subexcess? (assoc subd bk (:excess bb)) subd) |
| 4617 | + |
4595 | 4618 | b->k (if (symbol? bb) (assoc b->k bb bk) b->k)] |
4596 | | - (recur (push1 ret bb bk false) (conj sel bk) (next bes) b->k subs suba)))) |
4597 | | - {:ret ret, :sel sel, :b->k b->k :subs subs :suba suba})) |
| 4619 | + (recur (push1 ret bb bk false) (conj sel bk) (next bes) b->k subs suba subd)))) |
| 4620 | + {:ret ret, :sel sel, :b->k b->k :subs subs :suba suba :subd subd})) |
4598 | 4621 | ret (:ret retsel), sel (:sel retsel), b->k (:b->k retsel) |
4599 | 4622 | new-or-code (and defaults (or defaults-as select all)) |
4600 | 4623 | bk #(if (symbol? %) |
|
4603 | 4626 | (throw (new IllegalArgumentException (str "symbol " % " in :or does not refer to a binding")))) |
4604 | 4627 | bk) |
4605 | 4628 | %) |
4606 | | - dm (when defaults (dissoc (zipmap (map bk (keys gdefaults)) (vals gdefaults)) nil)) |
| 4629 | + dm (when defaults (zipmap (map bk (keys gdefaults)) (vals gdefaults))) |
4607 | 4630 | _ (and new-or-code (not= (count (select-keys dm sel)) (count defaults)) |
4608 | 4631 | (throw (new IllegalArgumentException (str "keys " |
4609 | 4632 | (apply disj (set (keys dm)) sel) |
4610 | 4633 | " appear only in :or")))) |
| 4634 | + dm (if (empty? dm) nil dm) |
4611 | 4635 | ret (if select |
4612 | | - (conj ret select `(when-let [mm# (merge (some-vals ~dm) ~gmap (some-vals ~(:subs retsel)))] |
| 4636 | + (conj ret select `(when-let [mm# (merge ~dm ~gmap (some-vals ~(:subs retsel)))] |
4613 | 4637 | (select-keys mm# ~sel))) |
4614 | 4638 | ret) |
4615 | 4639 | ret (if all |
4616 | | - (conj ret all `(merge (some-vals ~dm) ~gmap (some-vals ~(:suba retsel)))) |
| 4640 | + (conj ret all `(merge ~dm ~gmap (some-vals ~(:suba retsel)))) |
4617 | 4641 | ret) |
| 4642 | + |
| 4643 | + ret (if excess |
| 4644 | + (conj ret excess `(merge (some-vals (apply dissoc ~gmap ~sel)) (some-vals ~(:subd retsel)))) |
| 4645 | + ret) |
| 4646 | + |
4618 | 4647 | ret (if defaults-as (conj ret defaults-as dm) ret)] |
4619 | 4648 | ret)) |
4620 | 4649 |
|
@@ -6417,22 +6446,6 @@ fails, attempts to require sym's namespace and retries." |
6417 | 6446 | :static true} |
6418 | 6447 | [coll] (instance? clojure.lang.Sorted coll)) |
6419 | 6448 |
|
6420 | | -(defn counted? |
6421 | | - "Returns true if coll implements count in constant time" |
6422 | | - {:added "1.0" |
6423 | | - :static true} |
6424 | | - [coll] (instance? clojure.lang.Counted coll)) |
6425 | | - |
6426 | | -(defn empty? |
6427 | | - "Returns true if coll has no items. To check the emptiness of a seq, |
6428 | | - please use the idiom (seq x) rather than (not (empty? x))" |
6429 | | - {:added "1.0" |
6430 | | - :static true} |
6431 | | - [coll] |
6432 | | - (if (counted? coll) |
6433 | | - (zero? (count coll)) |
6434 | | - (not (seq coll)))) |
6435 | | - |
6436 | 6449 | (defn reversible? |
6437 | 6450 | "Returns true if coll implements Reversible" |
6438 | 6451 | {:added "1.0" |
|
0 commit comments