You probably want either (^?)
, or maybe (^..)
(non-operator names: preview
, toListOf
).
When you have a Lens
(or a Getter
, Iso
, Equality
, etc.), it always refers to exactly one item. So you can use plain old (^.)
(non-operator name: view
). When you have have a Traversal
(or a Fold
, Prism
, etc.), it can refer to 0-or-more items.
Therefore there must be a way to combine them if there's more than one, or a default value to give if there are none. This is done with the Monoid
constraint. toListOf
gives you a list of all the values; preview
gives you either Nothing
or Just
the first value.
You didn't give the types for any of the functions you're using, so I can't really tell what you intended. My guess would be that maybe scene
can fail because you used makeLenses
with a sum type that doesn't define scene
in every summand. In this case you'd probably want to use (^?)
and handle the Nothing
case. But it might be something else.
See also my answer to this question (and this question from yesterday! This seems to be a popular topic).