From 239255767c25f48d5083938155800386f6de6b4c Mon Sep 17 00:00:00 2001 From: "Thomas R. Honeyman" Date: Fri, 11 Sep 2020 18:37:10 -0700 Subject: [PATCH 1/2] Add extra functions --- src/Data/These.purs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Data/These.purs b/src/Data/These.purs index e7aa2f7..1de76cd 100644 --- a/src/Data/These.purs +++ b/src/Data/These.purs @@ -147,3 +147,22 @@ that :: forall a b. These a b -> Maybe b that = case _ of That x -> Just x _ -> Nothing + +-- | Returns the `a` and `b` values if and only if they are constructed +-- | with `Both`. +both :: forall a b. These a b -> Maybe (Tuple a b) +both = case _ of + Both a x -> Just (Tuple a x) + _ -> Nothing + +-- | Returns `true` when the `These` value is `This` +isThis :: forall a b. These a b -> Boolean +isThis = isJust <<< this + +-- | Returns `true` when the `These` value is `That` +isThat :: forall a b. These a b -> Boolean +isThat = isJust <<< that + +-- | Returns `true` when the `These` value is `Both` +isBoth :: forall a b. These a b -> Boolean +isBoth = isJust <<< both From a243354dbe9805b49e796e62fda13214bf15593c Mon Sep 17 00:00:00 2001 From: Thomas Honeyman Date: Sun, 13 Sep 2020 15:07:29 -0700 Subject: [PATCH 2/2] Update These.purs --- src/Data/These.purs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data/These.purs b/src/Data/These.purs index 1de76cd..36a5df2 100644 --- a/src/Data/These.purs +++ b/src/Data/These.purs @@ -6,7 +6,7 @@ import Control.Extend (class Extend) import Data.Bifunctor (class Bifunctor) import Data.Bitraversable (class Bitraversable, class Bifoldable, bitraverse) import Data.Functor.Invariant (class Invariant, imapF) -import Data.Maybe (Maybe(..)) +import Data.Maybe (Maybe(..), isJust) import Data.Traversable (class Traversable, class Foldable, foldMap, foldl, foldr) import Data.Tuple (Tuple(..))