Skip to content
Open
Show file tree
Hide file tree
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: 18 additions & 3 deletions these/src/Data/These.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
module Data.These (
These(..)

-- * Functions to make 'These'
, maybeThese

-- * Functions to get rid of 'These'
, these
, fromThese
Expand Down Expand Up @@ -49,9 +52,9 @@ import Data.Semigroup (Semigroup (..))
import Data.Traversable (Traversable (..))
import GHC.Generics (Generic, Generic1)
import Prelude
(Bool (..), Either (..), Eq (..), Functor (..), Int, Monad (..),
Ord (..), Ordering (..), Read (..), Show (..), fail, id, lex, readParen,
seq, showParen, showString, ($), (&&), (.))
(Bool (..), Either (..), Eq (..), Functor (..), Int, Maybe(..),
Monad (..), Ord (..), Ordering (..), Read (..), Show (..), fail, id,
lex, readParen, seq, showParen, showString, ($), (&&), (.))

-- $setup
-- >>> import Control.Lens
Expand All @@ -75,6 +78,18 @@ import Prelude
data These a b = This a | That b | These a b
deriving (Eq, Ord, Read, Show, Typeable, Data, Generic, Generic1)


-------------------------------------------------------------------------------
-- Constructors
-------------------------------------------------------------------------------

-- | Realises the isomorphism @('Maybe' A, 'Maybe' B) = 'Maybe' ('These' A B)@
maybeThese :: Maybe a -> Maybe b -> Maybe (These a b)
maybeThese (Just x) (Just y) = Just (These x y)
maybeThese (Just x) Nothing = Just (This x)
maybeThese Nothing (Just y) = Just (That y)
maybeThese Nothing Nothing = Nothing

-------------------------------------------------------------------------------
-- Eliminators
-------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion these/these.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: >=1.10
name: these
version: 1.2.1
version: 1.3
x-revision: 2
synopsis: An either-or-both data type.
homepage: https://github.com/haskellari/these
Expand Down