Bob Glamm
02/10/2023, 2:52 PMSetter<S, T>
method that takes a T
and produces an (S) -> S
? E.g. if I have:
@optics data class Foo(x: Int, y: Double)
val fooStart: Foo = Foo(1, 2.0)
// Foo.x is Lens<Foo, Int>; Foo.y is Lens<Foo, Double>
// `.set` is not the correct method here; the idea is that this just closes over the value to set in the structure
// and the structure to be modified will be supplied later
val setter1: (Foo) -> Foo = Foo.x.set(3)
val setter2: (Foo) -> Foo = Foo.y.set(4.0)
(setter1 compose setter2)(fooStart) == Foo(3, 4.0)
The idea being that all of the sets/updates would be created and then applied in bulk over the original structure.simon.vergauwen
02/13/2023, 8:24 AMlift
, that does this. https://arrow-kt.io/docs/apidocs/arrow-optics/arrow.optics/-p-setter/lift.html
val setter1 : (Foo) -> Foo = Foo.x.lift { 3 }
val setter2: (Foo) -> Foo = Foo.y.lift { 4.0 }
(setter1 compose setter2)(fooStart) == Foo(3, 4.0)
Bob Glamm
02/13/2023, 6:30 PM