44
55Enable mutating immutable plain data fields using ` aref ` wrapper, allowing mutating immutable plain data fields using the following syntax:
66``` julia
7- aref (v)[i]. a. b. _i . _j [] = val
7+ aref (v)[i]. a. b[] = val
88```
99
10- The nested fields can be accessed using either the field name, or the field index prefixed with ` _ ` .
11- Except for the wrapped vector, every field in the chain must be immutable. The final type to be mutated must be bits type.
10+ The nested fields can be accessed using either the field name, or the field index with ` getproperty ` .
11+ The wrapped vector must implement the strided arrays interface and must have ` isbitstype ` element type.
1212
1313Examples:
14- ``` julia
14+ ``` julia-repl
1515julia> using MutatePlainDataArray
1616
1717julia> a = [1, 2, 3];
@@ -25,28 +25,23 @@ julia> a
2525 2
2626 3
2727
28- julia> b = [(tup= (1 , 2.5 ), s= " a " ), (tup= (2 , 4.5 ), s= " b " )];
28+ julia> b = [(; tup=(1, 2.5), s=4 ), (; tup=(2, 4.5), s=5 )];
2929
30- julia> aref (b)[1 ]. tup. _2 [] = Inf
30+ julia> aref(b)[1].tup.:2 [] = Inf
3131Inf
3232
3333julia> b
34- 2 - element Vector{NamedTuple{( : tup, :s ), Tuple{Tuple{ Int64, Float64}, String} }}:
35- (tup = (1 , Inf ), s = " a " )
36- (tup = (2 , 4.5 ), s = " b " )
34+ 2-element Vector{@ NamedTuple{tup:: Tuple{Int64, Float64}, s::Int64 }}:
35+ (tup = (1, Inf), s = 4 )
36+ (tup = (2, 4.5), s = 5 )
3737
38- julia> aref (b)[2 ]. _1 . _1 [] *= 100
38+ julia> ( aref(b)[2].:1).:1 [] *= 100
3939200
4040
4141julia> b
42- 2 - element Vector{NamedTuple{(:tup , :s ), Tuple{Tuple{Int64, Float64}, String}}}:
43- (tup = (1 , Inf ), s = " a" )
44- (tup = (200 , 4.5 ), s = " b" )
45-
46- julia> aref (b)[1 ]. s[] = " invalid"
47- ERROR: The field type String (field s in NamedTuple{(:tup , :s ), Tuple{Tuple{Int64, Float64}, String}}) is not immutable.
48- Stacktrace:
49- ...
42+ 2-element Vector{@NamedTuple{tup::Tuple{Int64, Float64}, s::Int64}}:
43+ (tup = (1, Inf), s = 4)
44+ (tup = (200, 4.5), s = 5)
5045```
5146
5247The mutation provided by this package is
0 commit comments