[arrow-optics] Is there a `Setter<S, T>` met...
# arrow
b
[arrow-optics] Is there a
Setter<S, T>
method that takes a
T
and produces an
(S) -> S
? E.g. if I have:
Copy code
@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.
👍🏾 1
s
There is the function
lift
, that does this. https://arrow-kt.io/docs/apidocs/arrow-optics/arrow.optics/-p-setter/lift.html
Copy code
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)
b
That's exactly what I was looking for. Thanks, Simon 🙂