From f8afe6208a5d497a8c90b1a901d251431209f5b6 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 11 Mar 2016 16:49:24 -0500 Subject: [PATCH] MaybeBoth is a Crosswalk. --- src/Data/Functor/Both.hs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Data/Functor/Both.hs b/src/Data/Functor/Both.hs index 6e2c29a7e..ee1ebbb0b 100644 --- a/src/Data/Functor/Both.hs +++ b/src/Data/Functor/Both.hs @@ -1,6 +1,7 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-} module Data.Functor.Both where +import Data.Align import Data.Bifunctor import Data.Bifunctor.These import Prelude hiding (zipWith, fst, snd) @@ -53,3 +54,6 @@ newtype MaybeBoth a = MaybeBoth { runMaybeBoth :: Both (Maybe a) } instance Applicative MaybeBoth where pure = MaybeBoth . pure . Just 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)