data-or-1.0.0.7: A data type for non-exclusive disjunction.
CopyrightCopyright (c) 2010--2021 wren gayle romano
LicenseBSD
Maintainerwren@cpan.org
Stabilityprovisional
PortabilityHaskell98 + CPP
Safe HaskellNone
LanguageHaskell98

Data.Or

Description

A data type for non-exclusive disjunction. This is helpful for things like a generic merge function on sets/maps which could be union, mutual difference, etc. based on which Or value a function argument returns. Also useful for non-truncating zips (cf. zipOr) and other cases where you sometimes want an Either and sometimes want a pair.

Synopsis

Documentation

data Or a b Source #

A data type for non-exclusive disjunction.

Constructors

Fst a 
Both a b 
Snd b 

Instances

Instances details
(Eq a, Eq b) => Eq (Or a b) Source # 
Instance details

Defined in Data.Or

Methods

(==) :: Or a b -> Or a b -> Bool #

(/=) :: Or a b -> Or a b -> Bool #

(Read a, Read b) => Read (Or a b) Source # 
Instance details

Defined in Data.Or

Methods

readsPrec :: Int -> ReadS (Or a b) #

readList :: ReadS [Or a b] #

readPrec :: ReadPrec (Or a b) #

readListPrec :: ReadPrec [Or a b] #

(Show a, Show b) => Show (Or a b) Source # 
Instance details

Defined in Data.Or

Methods

showsPrec :: Int -> Or a b -> ShowS #

show :: Or a b -> String #

showList :: [Or a b] -> ShowS #

elimOr :: (a -> c) -> (a -> b -> c) -> (b -> c) -> Or a b -> c Source #

Functional eliminator for Or.

eitherOr :: Either a b -> Or a b Source #

Convert an Either into an Or.

Non-truncating zipping functions

zipOr :: [a] -> [b] -> [Or a b] Source #

A variant of zip which exhausts both lists, annotating which list the elements came from. It will return zero or more Both, followed by either zero or more Fst or else zero or more Snd.

On GHC this is a "good producer" for list fusion.

zipOrWith :: (Or a b -> c) -> [a] -> [b] -> [c] Source #

A variant of zipOr with a custom Or-homomorphism.

On GHC this is a "good producer" for list fusion.

zipOrBy :: (Or a b -> c -> c) -> c -> [a] -> [b] -> c Source #

A variant of zipOr with a custom list-homomorphism.

zipOrWithBy Source #

Arguments

:: (Or a b -> c)

Or homomorphism

-> (c -> d -> d)

list homomorphism, (:) part

-> d

list homomorphism, [] part

-> [a] 
-> [b] 
-> d 

A variant of zipOr with both a custom Or-homomorphism and a custom list-homomorphism. This is no more powerful than zipOrBy, but it may be more convenient to separate the handling of Or from the handling of (:).