In Optics, is there no way to focus on a Either.Ri...
# arrow
l
In Optics, is there no way to focus on a Either.Right/Either.Left? For example, let's say I have this class:
Copy code
@optics
data class Foo(
    val bar: Either<Throwable, Bar>,
}
How would I focus
bar
only if it's a
Either.Right
. I expected something like
Foo.bar.right.modify(...)
to exist but it doesn't seem so...
I am using version 1.0.1 if it's relevant
t
Out of memory, i think prisms where there to help with sealed classes https://arrow-kt.io/docs/optics/prism/
l
I know I can easily define my own implementation. I was just wondering if there was already something to use out of the box, and if not, why not?
a
If it’s not there, I’m pretty sure it’s because it was forgotten, not any deep reason. There are others for null ability, for example.
Feel free to open an issue if you cannot find them
s
Oh, it used to be there 🤔 I think it got lost at some point. Something like this should work, we put them on the
Companion
of
Prism
. It probably also deserves specialised syntax in the DSL. Such that you can do.
Copy code
Foo.bar.right.modify(foo) { bar -> ... }
instead of
Copy code
(Foo.bar compose pRight()).modify(bar) { bar -> ... }
Feel free to open an issue if you cannot find them
I'd also be happy to help if you're interested in contributing this improvement! Feel free to DM me, or ask any questions in #arrow-contributors if you're not sure what to do to contribute. Here is the contribution guide on Github, https://github.com/arrow-kt/arrow/blob/main/CONTRIBUTING.md
l
I might have some free time in a couple hours but I'm not sure...