data-or-1.0.0: A data type for non-exclusive disjunction.

PortabilityHaskell98 + CPP
Stabilityprovisional
Maintainerwren@community.haskell.org

Data.Or

Contents

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

(Eq a, Eq b) => Eq (Or a b) 
(Read a, Read b) => Read (Or a b) 
(Show a, Show b) => Show (Or a b) 

elimOr :: (a -> c) -> (a -> b -> c) -> (b -> c) -> Or a b -> cSource

Functional eliminator for Or.

eitherOr :: Either a b -> Or a bSource

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] -> cSource

A variant of zipOr with a custom list-homomorphism.

zipOrWithBySource

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 (:).