1.3.0 permalink Arrow_down_16x16

transient

clojure.core

  • (transient coll)
Alpha - subject to change.
Returns a new, transient version of the collection, in constant time.

2 Examples top

  • ;; As seen on http://clojure.org/transients
    ;; array is initially made transient, modified then
    ;; finally made persistent.
    
    (defn vrange2 [n]
      (loop [i 0 v (transient [])]
        (if (< i n)
          (recur (inc i) (conj! v i))
          (persistent! v))))
    
    user=> (vrange2 10)
    [0 1 2 3 4 5 6 7 8 9]
  • user> (def foo (transient [1 2 3]))
    #'user/foo
    user> (get foo 0)
    1
    user> (count foo)
    3
    user> (nth foo 0)
    1
    user> (def bar (transient {:honda 7 :kagawa 23 :ienaga 14}))
    #'user/bar
    user> (get bar :kagawa)
    23
    user> (count bar)
    3
    
    ;; There is a known bug in Clojure 1.3 where contains? always returns false for
    ;; transients.  http://dev.clojure.org/jira/browse/CLJ-700
    ;; contains? works fine for persistent data structures.
    user> (contains? bar :kagawa)  ; Caution! 
    false
    user> (def bar2 (persistent! bar))
    #'user/bar2
    user> (contains? bar2 :kagawa) ; Caution!
    true
    
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:2923 top

(defn transient 
  "Alpha - subject to change.
  Returns a new, transient version of the collection, in constant time."
  {:added "1.1"
   :static true}
  [^clojure.lang.IEditableCollection coll] 
  (.asTransient coll))
Vars in clojure.core/transient:
Used in 0 other vars

Comments top

No comments for transient. Log in to add a comment.