ClojureDocs

Nav

Namespaces

persistent!

clojure.core

Available since 1.1 (source)
  • (persistent! coll)
Returns a new, persistent version of the transient collection, in
constant time. The transient collection cannot be used after this
call, any such use will throw an exception.
2 Examples
user> (def foo (transient [1 2 3]))
#'user/foo
user> foo
#<TransientVector clojure.lang.PersistentVector$TransientVector@12c9b4d1>
user> (persistent! foo)
[1 2 3]
user> foo
#<TransientVector clojure.lang.PersistentVector$TransientVector@12c9b4d1>
user> (conj! foo 4)
→ ERROR:Transient used after persistent! call
user> (persistent! foo)
→ ERROR: Transient used after persistent! call
;; Use persistent! to evaluate your object,
;; once the computation is complete

(loop [large-set (transient #{})
       i 0]
  (if (< i 100000)
    (recur (conj! large-set i) (inc i))
    (persistent! large-set)))

;; Returns a large set *much* faster than its
;; persistent version. While keeping the same
;; code structure
See Also

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

Added by gstamp
0 Notes
No notes for persistent!