semialign-1.2.0.1: Align and Zip type-classes from the common Semialign ancestor.
Safe Haskell Trustworthy
Language Haskell2010

Data.Align

Description

These -based aligning and unaligning of functors with non-uniform shapes.

For a traversals traversal of (bi)foldable (bi)functors through said functors see Data.Crosswalk .

Synopsis

Documentation

class Functor f => Semialign f where Source #

Functors supporting an align operation that takes the union of non-uniform shapes.

Minimal definition: either align or alignWith .

Laws

The laws of align and zip resemble lattice laws. There is a plenty of laws, but they are simply satisfied.

And an addition property if f is Foldable , which tries to enforce align -feel: neither values are duplicated nor lost.

Note: join f x = f x x

Idempotency

join align ≡ fmap (join These)

Commutativity

align x y ≡ swap <$> align y x

Associativity

align x (align y z) ≡ assoc <$> align (align x y) z

With

alignWith f a b ≡ f <$> align a b

Functoriality

align (f <$> x) (g <$> y) ≡ bimap f g <$> align x y

Alignedness , if f is Foldable

toList x ≡ toListOf (folded . here) (align x y)
         ≡ mapMaybe justHere (toList (align x y))

And an addition property if f is Foldable , which tries to enforce align -feel: neither values are duplicated nor lost.

toList x = toListOf (folded . here) (align x y)
         = mapMaybe justHere (toList (align x y))

Minimal complete definition

( align | alignWith )

Methods

align :: f a -> f b -> f ( These a b) Source #

Analogous to zip , combines two structures by taking the union of their shapes and using These to hold the elements.

alignWith :: ( These a b -> c) -> f a -> f b -> f c Source #

Analogous to zipWith , combines two structures by taking the union of their shapes and combining the elements with the given function.

Instances

Instances details
Semialign [] Source #
Instance details

Defined in Data.Semialign.Internal

Methods

align :: [a] -> [b] -> [ These a b] Source #

alignWith :: ( These a b -> c) -> [a] -> [b] -> [c] Source #

Semialign Maybe Source #
Instance details

Defined in Data.Semialign.Internal

Semialign Option Source #
Instance details

Defined in Data.Semialign.Internal

Semialign ZipList Source #

zipWith = liftA2 .

Instance details

Defined in Data.Semialign.Internal

Semialign Identity Source #
Instance details

Defined in Data.Semialign.Internal

Semialign NonEmpty Source #
Instance details

Defined in Data.Semialign.Internal

Semialign IntMap Source #
Instance details

Defined in Data.Semialign.Internal

Semialign Tree Source #
Instance details

Defined in Data.Semialign.Internal

Semialign Seq Source #
Instance details

Defined in Data.Semialign.Internal

Semialign Vector Source #
Instance details

Defined in Data.Semialign.Internal

Semialign ( Proxy :: Type -> Type ) Source #
Instance details

Defined in Data.Semialign.Internal

Ord k => Semialign ( Map k) Source #
Instance details

Defined in Data.Semialign.Internal

Methods

align :: Map k a -> Map k b -> Map k ( These a b) Source #

alignWith :: ( These a b -> c) -> Map k a -> Map k b -> Map k c Source #

( Eq k, Hashable k) => Semialign ( HashMap k) Source #
Instance details

Defined in Data.Semialign.Internal

Monad m => Semialign ( Stream m) Source #
Instance details

Defined in Data.Semialign.Internal

Semialign ( Tagged b) Source #
Instance details

Defined in Data.Semialign.Internal

Monad m => Semialign ( Bundle m v) Source #
Instance details

Defined in Data.Semialign.Internal

Methods

align :: Bundle m v a -> Bundle m v b -> Bundle m v ( These a b) Source #

alignWith :: ( These a b -> c) -> Bundle m v a -> Bundle m v b -> Bundle m v c Source #

Semialign ((->) e :: Type -> Type ) Source #
Instance details

Defined in Data.Semialign.Internal

Methods

align :: (e -> a) -> (e -> b) -> e -> These a b Source #

alignWith :: ( These a b -> c) -> (e -> a) -> (e -> b) -> e -> c Source #

( Semialign f, Semialign g) => Semialign ( Product f g) Source #
Instance details

Defined in Data.Semialign.Internal

( Semialign f, Semialign g) => Semialign ( Compose f g) Source #
Instance details

Defined in Data.Semialign.Internal

class Semialign f => Align f where Source #

A unit of align .

Laws

(`align` nil) ≡ fmap This
(nil `align`) ≡ fmap That

Methods

nil :: f a Source #

An empty structure. align ing with nil will produce a structure with the same shape and elements as the other input, modulo This or That .

Instances

Instances details
Align [] Source #
Instance details

Defined in Data.Semialign.Internal

Methods

nil :: [a] Source #

Align Maybe Source #
Instance details

Defined in Data.Semialign.Internal

Align Option Source #
Instance details

Defined in Data.Semialign.Internal

Align ZipList Source #
Instance details

Defined in Data.Semialign.Internal

Align IntMap Source #
Instance details

Defined in Data.Semialign.Internal

Align Seq Source #
Instance details

Defined in Data.Semialign.Internal

Align Vector Source #
Instance details

Defined in Data.Semialign.Internal

Align ( Proxy :: Type -> Type ) Source #
Instance details

Defined in Data.Semialign.Internal

Ord k => Align ( Map k) Source #
Instance details

Defined in Data.Semialign.Internal

( Eq k, Hashable k) => Align ( HashMap k) Source #
Instance details

Defined in Data.Semialign.Internal

Monad m => Align ( Stream m) Source #
Instance details

Defined in Data.Semialign.Internal

Monad m => Align ( Bundle m v) Source #
Instance details

Defined in Data.Semialign.Internal

( Align f, Align g) => Align ( Product f g) Source #
Instance details

Defined in Data.Semialign.Internal

( Align f, Semialign g) => Align ( Compose f g) Source #
Instance details

Defined in Data.Semialign.Internal

class Semialign f => Unalign f where Source #

Alignable functors supporting an "inverse" to align : splitting a union shape into its component parts.

Laws

uncurry align (unalign xs) ≡ xs
unalign (align xs ys) ≡ (xs, ys)

Compatibility note

In version 1 unalign was changed to return (f a, f b) pair, instead of (f (Just a), f (Just b)) . Old behaviour can be achieved with if ever needed.

>>> unzipWith (unalign . Just) [This 'a', That 'b', These 'c' 'd']
([Just 'a',Nothing,Just 'c'],[Nothing,Just 'b',Just 'd'])

Minimal complete definition

unalignWith | unalign

Methods

unalign :: f ( These a b) -> (f a, f b) Source #

unalignWith :: (c -> These a b) -> f c -> (f a, f b) Source #

Instances

Instances details
Unalign Maybe Source #
Instance details

Defined in Data.Semialign.Internal

Unalign Option Source #
Instance details

Defined in Data.Semialign.Internal

Unalign IntMap Source #
Instance details

Defined in Data.Semialign.Internal

Unalign ( Proxy :: Type -> Type ) Source #
Instance details

Defined in Data.Semialign.Internal

Ord k => Unalign ( Map k) Source #
Instance details

Defined in Data.Semialign.Internal

( Eq k, Hashable k) => Unalign ( HashMap k) Source #
Instance details

Defined in Data.Semialign.Internal

( Unalign f, Unalign g) => Unalign ( Product f g) Source #
Instance details

Defined in Data.Semialign.Internal

Specialized aligns

salign :: ( Semialign f, Semigroup a) => f a -> f a -> f a Source #

Align two structures and combine with <> .

padZip :: Semialign f => f a -> f b -> f ( Maybe a, Maybe b) Source #

Align two structures as in zip , but filling in blanks with Nothing .

padZipWith :: Semialign f => ( Maybe a -> Maybe b -> c) -> f a -> f b -> f c Source #

Align two structures as in zipWith , but filling in blanks with Nothing .

lpadZip :: [a] -> [b] -> [( Maybe a, b)] Source #

Left-padded zip .

lpadZipWith :: ( Maybe a -> b -> c) -> [a] -> [b] -> [c] Source #

Left-padded zipWith .

rpadZip :: [a] -> [b] -> [(a, Maybe b)] Source #

Right-padded zip .

rpadZipWith :: (a -> Maybe b -> c) -> [a] -> [b] -> [c] Source #

Right-padded zipWith .

alignVectorWith :: ( Vector v a, Vector v b, Vector v c) => ( These a b -> c) -> v a -> v b -> v c Source #