Public Vars

Back

transient (clj)

(source)

function

(transient coll)
Returns a new, transient version of the collection, in constant time.

Examples

thheller/shadow-cljs
(ns shadow.remote.runtime.cljs.js-builtins
  (:require
    [goog.object :as gobj]
    [clojure.core.protocols :as p]))

(extend-protocol p/Datafiable
  ;; FIXME: this is kind of a bad idea
  ;; can't do this for all objects, since none of the CLJS types implement this
  ;; protocol either. the protocol dispatch will end up using object
  ;; FIXME: this could detect CLJS types to some extent
  ;; or should it just implement the protocols for the types?
  object
  (datafy [o]
    (if-not (identical? (.-__proto__ o) js/Object.prototype)
      o
      (with-meta
        (->> (gobj/getKeys o)
             (reduce
               (fn [m key]
                 (assoc! m key (gobj/get o key)))
               (transient {}))
             (persistent!))
typedclojure/typedclojure
(ns ^:no-doc typed.ann.clojure
  "Type annotations for the base Clojure distribution."
  #?(:cljs (:require-macros [typed.ann-macros.clojure :as macros]))
  (:require [clojure.core :as cc]
            [typed.clojure :as t]
            #?(:clj [typed.ann-macros.clojure :as macros])
            #?(:clj typed.ann.clojure.jvm) ;; jvm annotations
            #?(:clj clojure.core.typed))
  #?(:clj
     (:import (clojure.lang PersistentHashSet PersistentList
                            APersistentMap #_IPersistentCollection
                            #_ITransientSet
                            IRef)
              (java.util Comparator Collection))))

;;FIXME sorted collections, strings, vectors, arrays etc need special keys. needs richer types
;;TODO transient
cc/contains? [(t/U (t/Associative t/Any t/Any)
                   #?(:clj (t/Instance java.util.Map))
                   #?(:clj (t/Instance java.util.Set))
                   #?(:clj (t/Instance clojure.lang.ITransientSet))
                   #?(:clj (t/Instance clojure.lang.ITransientAssociative2))
                   #?(:clj (ReadOnlyArray t/Any))
                   t/Str
                   (t/Set t/Any))
              t/Any :-> t/Bool]
clojure/core.rrb-vector
(ns clojure.core.rrb-vector.transients
  (:require [clojure.core.rrb-vector.parameters :as p]
            [clojure.core.rrb-vector.nodes :refer [ranges last-range
                                                   overflow?]])
  (:import (clojure.core.rrb_vector.nodes NodeManager)
           (clojure.core ArrayManager)
           (java.util.concurrent.atomic AtomicReference)))

(def ^ITransientHelper transient-helper
  (reify ITransientHelper
    (editableRoot [this nm am root]
      (let [new-arr (clojure.core/aclone ^objects (.array nm root))]
        (if (== 33 (alength ^objects new-arr))
          (aset new-arr 32 (aclone (ints (aget ^objects new-arr 32)))))
        (.node nm (AtomicReference. (Thread/currentThread)) new-arr)))
clojure/core.rrb-vector
(ns clojure.core.rrb-vector.transients
  (:require [clojure.core.rrb-vector.parameters :as p]
            [clojure.core.rrb-vector.nodes :refer [ranges last-range
                                                   overflow?]])
  (:import (clojure.core.rrb_vector.nodes NodeManager)
           (clojure.core ArrayManager)
           (java.util.concurrent.atomic AtomicReference)))

(def ^ITransientHelper transient-helper
  (reify ITransientHelper
    (editableRoot [this nm am root]
      (let [new-arr (clojure.core/aclone ^objects (.array nm root))]
        (if (== p/non-regular-array-len (alength ^objects new-arr))
          (aset new-arr p/max-branches (aclone (ints (aget ^objects new-arr p/max-branches)))))
        (.node nm (AtomicReference. (Thread/currentThread)) new-arr)))
datastax/fallout
(ns clojure.core.rrb-vector.transients
  (:require [clojure.core.rrb-vector.nodes :refer [ranges last-range]])
  (:import (clojure.core.rrb_vector.nodes NodeManager)
           (clojure.core ArrayManager)
           (java.util.concurrent.atomic AtomicReference)))

(def ^ITransientHelper transient-helper
  (reify ITransientHelper
    (editableRoot [this nm am root]
      (.node nm
             (AtomicReference. (Thread/currentThread))
             (clojure.core/aclone ^objects (.array nm root))))