Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Tortar authored Sep 27, 2024
1 parent 71330a9 commit 8c8bd25
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ This will generate:

1. An immutable struct `S_Immut`;
2. A mutable struct `S_Mut`;
3. Constructors for `S` that can create either the mutable or immutable version.
3. `const S = Union{S_Immut{Y}, S_Mut{Y}} where Y`.

It is then possible to create instances of the specified version:

```julia
julia> s1 = S(1, 2, 3.0; mutable=true)
julia> s1 = S_Mut(1, 2, 3.0)
S_Mut{Int}(1, 2, 3.0)

julia> s2 = S(1, 2, 3.0; mutable=false)
julia> s2 = S_Immut(1, 2, 3.0)
S_Immut{Int}(1, 2.0, 3.0)
```

Expand All @@ -47,13 +47,8 @@ julia> @update s2.y = 3
S_Immut{Int}(1, 3, 3.0)
```

Importantly, there are some catches to keep in mind:

- The constructors are backed by a dummy struct of the same name (e.g `S` in the example above) which means
that it would be incorrect to dispatch on it. Use one of the versions of the structs or the abstract type
instead;
- For an immutable type, the mutation actually involve the creation of a new instance with
[Accessors.jl](https://github.com/JuliaObjects/Accessors.jl).
Importantly, for an immutable type, the mutation actually involve the creation
of a new instance with [Accessors.jl](https://github.com/JuliaObjects/Accessors.jl).


## Contributing
Expand Down

0 comments on commit 8c8bd25

Please sign in to comment.