Skip to content

Commit 94d9322

Browse files
Add extra functions (#25)
* Add extra functions * Update These.purs
1 parent cb027da commit 94d9322

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/Data/These.purs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Control.Extend (class Extend)
66
import Data.Bifunctor (class Bifunctor)
77
import Data.Bitraversable (class Bitraversable, class Bifoldable, bitraverse)
88
import Data.Functor.Invariant (class Invariant, imapF)
9-
import Data.Maybe (Maybe(..))
9+
import Data.Maybe (Maybe(..), isJust)
1010
import Data.Traversable (class Traversable, class Foldable, foldMap, foldl, foldr)
1111
import Data.Tuple (Tuple(..))
1212

@@ -147,3 +147,22 @@ that :: forall a b. These a b -> Maybe b
147147
that = case _ of
148148
That x -> Just x
149149
_ -> Nothing
150+
151+
-- | Returns the `a` and `b` values if and only if they are constructed
152+
-- | with `Both`.
153+
both :: forall a b. These a b -> Maybe (Tuple a b)
154+
both = case _ of
155+
Both a x -> Just (Tuple a x)
156+
_ -> Nothing
157+
158+
-- | Returns `true` when the `These` value is `This`
159+
isThis :: forall a b. These a b -> Boolean
160+
isThis = isJust <<< this
161+
162+
-- | Returns `true` when the `These` value is `That`
163+
isThat :: forall a b. These a b -> Boolean
164+
isThat = isJust <<< that
165+
166+
-- | Returns `true` when the `These` value is `Both`
167+
isBoth :: forall a b. These a b -> Boolean
168+
isBoth = isJust <<< both

0 commit comments

Comments
 (0)