mirror of
https://github.com/github/semantic.git
synced 2025-01-03 04:51:57 +03:00
Add an apThese function.
This commit is contained in:
parent
ec4ff0cf14
commit
50beaefa99
@ -3,6 +3,7 @@ module Data.Bifunctor.These where
|
|||||||
import Data.Bifunctor
|
import Data.Bifunctor
|
||||||
import Data.Bifoldable
|
import Data.Bifoldable
|
||||||
import Data.Bitraversable
|
import Data.Bitraversable
|
||||||
|
import Control.Arrow
|
||||||
|
|
||||||
data These a b = This a | That b | These a b
|
data These a b = This a | That b | These a b
|
||||||
deriving (Eq, Show)
|
deriving (Eq, Show)
|
||||||
@ -32,6 +33,10 @@ maybeFst = these Just (const Nothing) ((Just .) . const)
|
|||||||
maybeSnd :: These a b -> Maybe b
|
maybeSnd :: These a b -> Maybe b
|
||||||
maybeSnd = these (const Nothing) Just ((Just .) . flip const)
|
maybeSnd = these (const Nothing) Just ((Just .) . flip const)
|
||||||
|
|
||||||
|
apThese :: These (a -> b) (c -> d) -> These a c -> Maybe (These b d)
|
||||||
|
apThese fg ab = uncurry maybeThese $ uncurry (***) (bimap (<*>) (<*>) (unpack fg)) (unpack ab)
|
||||||
|
where unpack = fromThese Nothing Nothing . bimap Just Just
|
||||||
|
|
||||||
|
|
||||||
-- Instances
|
-- Instances
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user