The Prism'
here comes from optics-core
not lens
. Is there a way to simplify this implementation, or is this as simple as it gets?
{- | Given two @Prism'@'s whose filepaths are distinct (ie., both @a@ and @b@
encode to distinct filepaths), return a new @Prism'@ that combines both.
If this distinctness property does not hold between the input @Prism'@'s, then
the resulting @Prism'@ will not be lawful.
-}
eitherPrism :: Prism' FilePath a -> Prism' FilePath b -> Prism' FilePath (Either a b)
eitherPrism p1 p2 =
prism'
( either
(review p1)
(review p2)
)
( \fp ->
asum
[ Left <$> preview p1 fp
, Right <$> preview p2 fp
]
)