You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be great to write an optic which works like a lens over E which always gets me the x, no matter which variant it's from.
This could work if we could define LensRef and LensMut in terms of a Fn(&mut T) -> &mut Image instead of a field (if T: Clone, then we can implement Lens too). But I wonder if there's also a more direct but weird way, like "traverse all prisms of all enum variants", then apply the x lens to each, the result being a Prism which always has an image (since exactly one Prism will match). I don't know how to express that though.
It's the equivalent of the pattern match E::A(A { x, .. }) | E::B(B { x, .. })
The text was updated successfully, but these errors were encountered:
Hey I was recently working on a POC that is very similar to the use case. I worked on lenses that were supposed to peek inside themselves ,and get the variants of a struct field
This is a weird one, and I don't even know what the equivalent in Haskell lenses would be...but I often wind up with enums like this:
i.e. all variants of E have a field
x: u8
.It would be great to write an optic which works like a lens over E which always gets me the
x
, no matter which variant it's from.This could work if we could define
LensRef
andLensMut
in terms of aFn(&mut T) -> &mut Image
instead of a field (ifT: Clone
, then we can implementLens
too). But I wonder if there's also a more direct but weird way, like "traverse all prisms of all enum variants", then apply thex
lens to each, the result being a Prism which always has an image (since exactly one Prism will match). I don't know how to express that though.It's the equivalent of the pattern match
E::A(A { x, .. }) | E::B(B { x, .. })
The text was updated successfully, but these errors were encountered: