# ANN: new package Reconstructables.jl for easier "modifications" of immutable structs

**URL:** <https://discourse.julialang.org/t/ann-new-package-reconstructables-jl-for-easier-modifications-of-immutable-structs/9157>\
**Category:** Community\
**Tags:** package, announcement\
**Created:** [February 19, 2018, 7:50am UTC](https://discourse.julialang.org/t/ann-new-package-reconstructables-jl-for-easier-modifications-of-immutable-structs/9157 "2018-02-19T07:50:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [February 19, 2018, 7:50am UTC](https://discourse.julialang.org/t/ann-new-package-reconstructables-jl-for-easier-modifications-of-immutable-structs/9157/1 "2018-02-19T07:50:54Z")

</div>

Hi, let me announce a beta package Reconstructables.jl:  
[https://github.com/tkf/Reconstructables.jl](https://github.com/tkf/Reconstructables.jl)

Reconstructables.jl provides helper functions and macros to work with immutable structs in Julia. For example, using `@recon` macro, you can reconstruct a new struct with the nested field `.x.y.z` modified from the one in `old` by:

```julia
new = @recon old.x.y.z = 3

```

It works even when `old`, `x` and `y` are all immutable, provided that their they have keyword-only constructor. To generate keyword-only constructor, it also provides another macro `@add_kwonly`. For example,

```julia
struct A
    x
    y
    @add_kwonly A(x, y=2) = new(x, y)
end

```

expands to:

```julia
struct A
    x
    y
    A(x, y) = new(x, y)
    A(; x = throw(UndefKeywordError(:x)), y=2) = new(x, y)
end

```

Note that `@recon` and `@add_kwonly` are independent tools (in some sense). For example, `@recon` also works nicely with `@with_kw` from [Parameters.jl](https://github.com/mauro3/Parameters.jl). You may want to use `@add_kwonly` instead of `@with_kw` if you need to do something inside the inner constructor, like handling type parameters.

See more details in [README](https://github.com/tkf/Reconstructables.jl).

~~I just sent a PR to METADATA.jl so if you want to try it out right now, use:~~ It’s now in METADATA. You can install it by:

```julia
Pkg.add("Reconstructables")

```

A bit of history: this package is a spin-off from a [PR in JuliaDiffEq/DiffEqBase.jl](https://github.com/JuliaDiffEq/DiffEqBase.jl/pull/87) where we tried to solve a similar problem. I wrote `@add_kwonly` for DiffEqBase.jl and then @ChrisRackauckas suggested to make a package out of it since it may be useful elsewhere (Thanks!). But I thought one macro is not enough for a package so I wrote `@recon` 🙂
