我有那些镜头:
getB :: Lens' A (Maybe B)
getC :: Prism' B C
如何从 A 中提取Maybe C
? 我能找到的最好的:
case A ^. getB of
Just b -> b ^? getC
Nothing -> Nothing
还有什么更优雅的吗?
_Just :: Prism' (Maybe a) a
_Just
棱镜将使您从Maybe
中获得价值。
a ^? getB . _Just . getC
或者你可以使用Maybe
的Traversable
实例,如果有的话,它会获取Just
中的值。
-- traverse :: Traversal' (Maybe a) a
a ^? getB . traverse . getC