ClojureDocs

导航

命名空间

disj!

clojure.core

在 1.1 中提供 (源代码)
  • (disj! set)
  • (disj! set key)
  • (disj! set key & ks)
disj[oin]. Returns a transient set of the same (hashed/sorted) type, that
does not contain key(s).
2 Examples
;; Note how we always use the return value of disj! and conj! in these examples
;; for all future modifications, rather than (incorrectly) ignoring the return
;; value and continuing to modify the original transient set.  See examples for
;; assoc! and dissoc! for more discussion and examples of this.
;; Also see one example for conj! that contains a detailed example
;; of a wrong result that can occur if you do not use its return value.

user=> (def foo (transient #{'pore-pore 'slow 'yukkuri}))
#'user/foo
user=> (count foo)
3
user=> (def foo (disj! foo 'yukkuri))
#'user/foo
user=> foo
#<TransientHashSet clojure.lang.PersistentHashSet$TransientHashSet@3bd840d9>
user=> (count foo)
2
user=> (def foo (conj! foo 'yukkuri))
#'user/foo
user=> foo
#<TransientHashSet clojure.lang.PersistentHashSet$TransientHashSet@3bd840d9>
user=> (count foo)
3
user=> (def foo (persistent! foo))
#'user/foo
user=> foo
#{yukkuri slow pore-pore}
;; A faster implementation of disj for a large number of keys to disjoin:

(defn disj* [s & ks]
  (persistent!
    (reduce disj! (transient s) ks)))

(let [s (set (range 1000))
      xs (range 400 600)]
  (count (apply disj* s xs)))
;; 800
See Also

When applied to a transient map, adds mapping of key(s) to val(s). When applied to a transient vec...

Added by jafingerhut

Returns a transient map that doesn't contain a mapping for key(s).

Added by jafingerhut

disj[oin]. Returns a new set of the same (hashed/sorted) type, that does not contain key(s).

Added by reborg

Adds x to the transient collection, and return coll. The 'addition' may happen at different 'place...

Added by jafingerhut
0 Notes
No notes for disj!