std.lib.mutable
defmutable
macro
added in 3.0
(defmutable tp-name fields & protos)allows definition of a mutable datastructure
(def -h- (Hello. “dog” 1))
(get -h- :name) => “dog”
IMutable
protocol
members
-clone
(-clone this)-fields
(-fields this)-set
(-set this k v)-set-new
(-set-new this k v)mutable:clone
added in 3.0
(mutable:clone obj)creates a copy of the object
(-> (Hello. “dog” 123) (mutable:clone) ((juxt :name :value))) => “dog” 123
mutable:copy
added in 3.0
(mutable:copy obj source)(mutable:copy obj source ks)copies values from a given source
(-> (Hello. “dog” 123) (mutable:copy (Hello. “cat” 456)) ((juxt :name :value))) => “cat” 456
mutable:fields
added in 3.0
(mutable:fields obj)returns all the fields of
(mutable:fields (Hello. “dog” 1)) => :name :value
mutable:set
added in 3.0
(mutable:set obj m)(mutable:set obj k v)sets the value of a given field
(-> (mutable:set -h- :name “cat”) :name) => “cat”
mutable:set-new
added in 3.0
(mutable:set-new obj m)(mutable:set-new obj k v)sets the value of a given field only when it is nil
(-> (Hello. “cat” nil) (mutable:set-new :name “dog”)) => (throws)
mutable:update
added in 3.0
(mutable:update obj k f & args)applies a function to a given field
(-> (Hello. “dog” 123) (mutable:update :value inc) :value) => 124