Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra functions #25

Merged
merged 2 commits into from
Sep 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/Data/These.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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(..))

Expand Down Expand Up @@ -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