|
38 | 38 | (dissoc-in m ks)))) |
39 | 39 |
|
40 | 40 | (defn- editable? [coll] |
41 | | - #?(:clj (instance? clojure.lang.IEditableCollection coll) |
42 | | - :cljs (satisfies? cljs.core/IEditableCollection coll))) |
| 41 | + #?(:cljs (satisfies? cljs.core/IEditableCollection coll) |
| 42 | + :default (instance? clojure.lang.IEditableCollection coll))) |
43 | 43 |
|
44 | 44 | (defn- assoc-some-transient! [m k v] |
45 | 45 | (if (nil? v) m (assoc! m k v))) |
|
102 | 102 | (defn map-entry |
103 | 103 | "Create a map entry for a key and value pair." |
104 | 104 | [k v] |
105 | | - #?(:clj (clojure.lang.MapEntry. k v) |
106 | | - :cljs (cljs.core/MapEntry. k v nil))) |
| 105 | + #?(:cljs (cljs.core/MapEntry. k v nil) |
| 106 | + :default (clojure.lang.MapEntry. k v))) |
107 | 107 |
|
108 | 108 | (defn map-kv |
109 | 109 | "Maps a function over the key/value pairs of an associative collection. Expects |
|
184 | 184 |
|
185 | 185 | (defn queue |
186 | 186 | "Creates an empty persistent queue, or one populated with a collection." |
187 | | - ([] #?(:clj clojure.lang.PersistentQueue/EMPTY |
188 | | - :cljs cljs.core/PersistentQueue.EMPTY)) |
| 187 | + ([] #?(:cljs cljs.core/PersistentQueue.EMPTY |
| 188 | + :default clojure.lang.PersistentQueue/EMPTY)) |
189 | 189 | ([coll] (into (queue) coll))) |
190 | 190 |
|
191 | 191 | (defn queue? |
192 | 192 | "Returns true if x implements clojure.lang.PersistentQueue." |
193 | 193 | [x] |
194 | | - (instance? #?(:clj clojure.lang.PersistentQueue |
195 | | - :cljs cljs.core/PersistentQueue) x)) |
| 194 | + (instance? #?(:cljs cljs.core/PersistentQueue |
| 195 | + :default clojure.lang.PersistentQueue) x)) |
196 | 196 |
|
197 | 197 | (defn boolean? |
198 | 198 | "Returns true if x is a boolean." |
199 | 199 | [x] |
200 | | - #?(:clj (instance? Boolean x) |
201 | | - :cljs (or (true? x) (false? x)))) |
| 200 | + #?(:cljs (or (true? x) (false? x)) |
| 201 | + :default (instance? Boolean x))) |
202 | 202 |
|
203 | 203 | (defn least |
204 | 204 | "Return the least argument (as defined by the compare function) in O(n) time." |
|
322 | 322 | (persistent! |
323 | 323 | (reduce (fn [m v] |
324 | 324 | (let [k (keyf v)] |
325 | | - (assoc! m k #?(:clj (if-let [kv (find m k)] |
326 | | - (collatef (val kv) v) |
327 | | - (initf v)) |
328 | | - :cljs (if (contains? m k) |
329 | | - (collatef (get m k) v) |
330 | | - (initf v)))))) |
| 325 | + (assoc! m k #?(:cljs |
| 326 | + (if (contains? m k) |
| 327 | + (collatef (get m k) v) |
| 328 | + (initf v)) |
| 329 | + :default |
| 330 | + (if-let [kv (find m k)] |
| 331 | + (collatef (val kv) v) |
| 332 | + (initf v)))))) |
331 | 333 | (transient {}) |
332 | 334 | coll)))) |
333 | 335 |
|
|
453 | 455 | {:added "1.7.0"} |
454 | 456 | ([pred] |
455 | 457 | (fn [rf] |
456 | | - (let [part #?(:clj (java.util.ArrayList.) :cljs (array-list)) |
| 458 | + (let [part #?(:clj (java.util.ArrayList.) |
| 459 | + :cljr (System.Collections.ArrayList.) |
| 460 | + :cljs (array-list)) |
457 | 461 | prev (volatile! ::none)] |
458 | 462 | (fn |
459 | 463 | ([] (rf)) |
460 | 464 | ([result] |
461 | | - (rf (if (.isEmpty part) |
| 465 | + (rf (if #?(:cljr (zero? (.-Count part)) |
| 466 | + :default (.isEmpty part)) |
462 | 467 | result |
463 | | - (let [v (vec (.toArray part))] |
464 | | - (.clear part) |
| 468 | + (let [v (vec (#?(:cljr .ToArray :default .toArray) part))] |
| 469 | + (#?(:cljr .Clear :default .clear) part) |
465 | 470 | (unreduced (rf result v)))))) |
466 | 471 | ([result input] |
467 | 472 | (let [p @prev] |
468 | 473 | (vreset! prev input) |
469 | | - (if (or (#?(:clj identical? :cljs keyword-identical?) p ::none) |
| 474 | + (if (or (#?(:cljs keyword-identical? :default identical?) p ::none) |
470 | 475 | (not (pred p input))) |
471 | | - (do (.add part input) result) |
472 | | - (let [v (vec (.toArray part))] |
473 | | - (.clear part) |
| 476 | + (do (#?(:cljr .Add :default .add) part input) |
| 477 | + result) |
| 478 | + (let [v (vec (#?(:cljr .ToArray :default .toArray) part))] |
| 479 | + (#?(:cljr .Clear :default .clear) part) |
474 | 480 | (let [ret (rf result v)] |
475 | 481 | (when-not (reduced? ret) |
476 | | - (.add part input)) |
| 482 | + (#?(:cljr .Add :default .add) part input)) |
477 | 483 | ret))))))))) |
478 | 484 | ([pred coll] |
479 | 485 | (lazy-seq |
|
601 | 607 | This function therefore acts like an atomic `deref` then `swap!`." |
602 | 608 | {:arglists '([atom f & args])} |
603 | 609 | ([atom f] |
604 | | - #?(:clj (loop [] |
605 | | - (let [value @atom] |
606 | | - (if (compare-and-set! atom value (f value)) |
607 | | - value |
608 | | - (recur)))) |
609 | | - :cljs (let [value @atom] |
610 | | - (reset! atom (f value)) |
611 | | - value))) |
| 610 | + #?(:cljs |
| 611 | + (let [value @atom] |
| 612 | + (reset! atom (f value)) |
| 613 | + value) |
| 614 | + :default |
| 615 | + (loop [] |
| 616 | + (let [value @atom] |
| 617 | + (if (compare-and-set! atom value (f value)) |
| 618 | + value |
| 619 | + (recur)))))) |
612 | 620 | ([atom f & args] |
613 | 621 | (deref-swap! atom #(apply f % args)))) |
614 | 622 |
|
|
624 | 632 | Clojure as well as ClojureScript." |
625 | 633 | [ex] |
626 | 634 | #?(:clj (when (instance? Throwable ex) (.getMessage ^Throwable ex)) |
| 635 | + :cljr (when (instance? Exception ex) (.-Message ^Exception ex)) |
627 | 636 | :cljs (cljs.core/ex-message ex))) |
628 | 637 |
|
629 | 638 | (defn ex-cause |
|
632 | 641 | Clojure as well as ClojureScript." |
633 | 642 | [ex] |
634 | 643 | #?(:clj (when (instance? Throwable ex) (.getCause ^Throwable ex)) |
| 644 | + :cljr (when (instance? Exception ex) (.-InnerException ^Exception ex)) |
635 | 645 | :cljs (cljs.core/ex-cause ex))) |
636 | 646 |
|
637 | 647 | (defn uuid? |
638 | 648 | "Returns true if the value is a UUID." |
639 | 649 | [x] |
640 | | - (instance? #?(:clj java.util.UUID :cljs cljs.core/UUID) x)) |
| 650 | + (instance? #?(:clj java.util.UUID |
| 651 | + :cljr System.Guid |
| 652 | + :cljs cljs.core/UUID) x)) |
641 | 653 |
|
642 | 654 | (defn uuid |
643 | 655 | "Returns a UUID generated from the supplied string. Same as `cljs.core/uuid` |
644 | 656 | in ClojureScript, while in Clojure it returns a `java.util.UUID` object." |
645 | 657 | [s] |
646 | 658 | #?(:clj (java.util.UUID/fromString s) |
| 659 | + :cljr (System.Guid. s) |
647 | 660 | :cljs (cljs.core/uuid s))) |
648 | 661 |
|
649 | 662 | (defn random-uuid |
650 | 663 | "Generates a new random UUID. Same as `cljs.core/random-uuid` except it works |
651 | 664 | for Clojure as well as ClojureScript." |
652 | 665 | [] |
653 | 666 | #?(:clj (java.util.UUID/randomUUID) |
| 667 | + :cljr (System.Guid/NewGuid) |
654 | 668 | :cljs (cljs.core/random-uuid))) |
655 | 669 |
|
656 | 670 | (defn regexp? |
657 | 671 | "Returns true if the value is a regular expression." |
658 | 672 | {:added "1.4.0"} |
659 | 673 | [x] |
660 | | - (instance? #?(:clj java.util.regex.Pattern :cljs js/RegExp) x)) |
| 674 | + (instance? #?(:clj java.util.regex.Pattern |
| 675 | + :cljr System.Text.RegularExpressions.Regex |
| 676 | + :cljs js/RegExp) x)) |
661 | 677 |
|
662 | 678 | (defn index-of |
663 | 679 | "Returns the index of the first occurrence of the item in the sequential |
664 | 680 | collection coll, or nil if not found." |
665 | 681 | {:added "1.9.0"} |
666 | | - [^java.util.List coll item] |
| 682 | + #?(:clj [^java.util.List coll item] |
| 683 | + :cljr [^System.Collections.IEnumerable coll item] |
| 684 | + :default [coll item]) |
667 | 685 | (when (some? coll) |
668 | | - (let [index (.indexOf coll item)] |
| 686 | + (let [index (#?(:cljr .IndexOf :default .indexOf) coll item)] |
669 | 687 | (when-not (neg? index) index)))) |
670 | 688 |
|
671 | 689 | (defn find-in |
|
0 commit comments