jw3126 / Setfield.jl

Update deeply nested immutable structs.
Other
167 stars 17 forks source link

Set multiple lenses successively #74

Open singularitti opened 5 years ago

singularitti commented 5 years ago

For example, I have the following code:

struct M
    c
end

struct N
    d
end

struct A
    a::M
    b::N
end

x = A(M(1), N(2))
lens1 = @lens _.a.c
lens2 = @lens _.b.d

If I want to set the two lenses successively, I need to write

set(set(x, lens1, 4), lens2, 5)

This code is a bit lacking readability. Could we provide a syntax that can set independent lenses successively? Thank you!

tkf commented 5 years ago

FYI I wrote Kaleido.@batchlens to do this. See: https://github.com/tkf/Kaleido.jl

singularitti commented 5 years ago

Wow, this is pretty cool!!! Thank you, I will take a look!

jw3126 commented 5 years ago

Yeah Kaleido is pretty cool. I would love to have a batch @set someday.