1
1
mirror of https://github.com/github/semantic.git synced 2024-12-28 17:32:05 +03:00

MaybeBoth is a Crosswalk.

This commit is contained in:
Rob Rix 2016-03-11 16:49:24 -05:00
parent eaf8228932
commit f8afe6208a

View File

@ -1,6 +1,7 @@
{-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Data.Functor.Both where module Data.Functor.Both where
import Data.Align
import Data.Bifunctor import Data.Bifunctor
import Data.Bifunctor.These import Data.Bifunctor.These
import Prelude hiding (zipWith, fst, snd) import Prelude hiding (zipWith, fst, snd)
@ -53,3 +54,6 @@ newtype MaybeBoth a = MaybeBoth { runMaybeBoth :: Both (Maybe a) }
instance Applicative MaybeBoth where instance Applicative MaybeBoth where
pure = MaybeBoth . pure . Just pure = MaybeBoth . pure . Just
MaybeBoth (Both (f, g)) <*> MaybeBoth (Both (a, b)) = MaybeBoth (both (f <*> a) (g <*> b)) MaybeBoth (Both (f, g)) <*> MaybeBoth (Both (a, b)) = MaybeBoth (both (f <*> a) (g <*> b))
instance Crosswalk MaybeBoth where
crosswalk f (MaybeBoth ab) = runBothWith (alignWith (MaybeBoth . maybeBothOfThese)) (maybe nil f <$> ab)