Home

BangBang.jl

BangBang.BangBangModule.

BangBang

Stable Dev Build Status Codecov Coveralls Aqua QA GitHub commits since tagged version

BangBang.jl implements functions whose name ends with !!. Those functions provide a uniform interface for mutable and immutable data structures. Furthermore, those function implement the "widening" fallback for the case the usual mutating function does not work (e.g., push!!(Int[], 1.5) creates a new array Float64[1.5]).

See the supported functions in the documentation

source
BangBang.append!!Method.
append!!(dest, src)

Append items in src to dest. Mutate dest if possible. See also push!!.

Examples

julia> using BangBang

julia> append!!((1, 2), (3, 4))
(1, 2, 3, 4)

julia> append!!([1, 2], (3, 4))
4-element Array{Int64,1}:
 1
 2
 3
 4
source
BangBang.delete!!Method.
delete!!(assoc, key) -> assoc′
source
BangBang.empty!!Method.
empty!!(collection) -> collection′

Examples

julia> using BangBang

julia> empty!!((1, 2, 3))
()

julia> empty!!((a=1, b=2, c=3))
NamedTuple()

julia> xs = [1, 2, 3];

julia> empty!!(xs)
0-element Array{Int64,1}

julia> xs
0-element Array{Int64,1}
source
BangBang.pop!!Method.
pop!!(sequence) -> (sequence′, value)
pop!!(assoc, key) -> (assoc′, value)
pop!!(assoc, key, default) -> (assoc′, value)

Examples

julia> using BangBang

julia> pop!!([0, 1])
([0], 1)

julia> pop!!((0, 1))
((0,), 1)

julia> pop!!(Dict(:a => 1), :a)
(Dict{Symbol,Int64}(), 1)

julia> pop!!((a=1,), :a)
(NamedTuple(), 1)
source
popfirst!!(sequence) -> (sequence′, value)

Examples

julia> using BangBang

julia> popfirst!!([0, 1])
([1], 0)

julia> popfirst!!((0, 1))
((1,), 0)
source
BangBang.push!!Method.
push!!(collection, items...)

Push one or more items to collection. Create a copy of collection if it cannot be mutated or the element type does not match.

Examples

julia> using BangBang

julia> push!!((1, 2), 3)
(1, 2, 3)

julia> push!!([1, 2], 3)
3-element Array{Int64,1}:
 1
 2
 3

julia> push!!([1, 2], 3.0)
3-element Array{Float64,1}:
 1.0
 2.0
 3.0
source
pushfirst!!(collection, items...)

Examples

julia> using BangBang

julia> pushfirst!!((1, 2), 3, 4)
(3, 4, 1, 2)

julia> pushfirst!!([1, 2], 3, 4)
4-element Array{Int64,1}:
 3
 4
 1
 2

julia> pushfirst!!([1, 2], 3, 4.0)
4-element Array{Float64,1}:
 3.0
 4.0
 1.0
 2.0
source
setindex!!(collection, value, indices...) -> collection′
source
setproperty!!(value, name, x)

Examples

julia> using BangBang

julia> setproperty!!((a=1, b=2), :b, 3)
(a = 1, b = 3)

julia> struct Immutable
           a
           b
       end

julia> setproperty!!(Immutable(1, 2), :b, 3)
Immutable(1, 3)

julia> mutable struct Mutable
           a
           b
       end

julia> s = Mutable(1, 2);

julia> setproperty!!(s, :b, 3)
Mutable(1, 3)

julia> s
Mutable(1, 3)
source
BangBang.splice!!Method.
splice!!(sequence, i, [replacement]) -> (sequence′, item)
source