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

Data.Zip

Description

Zipping and unzipping of functors with non-uniform shapes.

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 => Zip f where Source #

Functors supporting a zip operation that takes the intersection of non-uniform shapes.

Minimal definition: either zip or zipWith .

Idempotency

join zip   ≡ fmap (join (,))

Commutativity

zip x y ≡ swap <$> zip y x

Associativity

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

Absorption

fst    <$> zip xs (align xs ys) ≡ xs
toThis <$> align xs (zip xs ys) ≡ This <$> xs
  where
    toThis (This a)    = This a
    toThis (These a _) = This a
    toThis (That b)    = That b

With

zipWith f a b ≡ f <$> zip a b

Functoriality

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

Zippyness

fmap fst (zip x x) ≡ x
fmap snd (zip x x) ≡ x
zip (fmap fst x) (fmap snd x) ≡ x

Distributivity

                   align (zip xs ys) zs ≡ undistrThesePair <$> zip (align xs zs) (align ys zs)
distrPairThese <$> zip (align xs ys) zs ≡                      align (zip xs zs) (zip ys zs)
                   zip (align xs ys) zs ≡ undistrPairThese <$> align (zip xs zs) (zip ys zs)

Note , the following doesn't hold:

distrThesePair <$> align (zip xs ys) zs ≢ zip (align xs zs) (align ys zs)

when xs = [] and ys = zs = [0] , then the left hand side is "only" [( That 0, That 0)] , but the right hand side is [( That 0, These 0 0)] .

Minimal complete definition

( zip | zipWith )

Methods

zip :: f a -> f b -> f (a, b) Source #

Combines two structures by taking the intersection of their shapes and using pair to hold the elements.

zipWith :: (a -> b -> c) -> f a -> f b -> f c Source #

Combines two structures by taking the intersection of their shapes and combining the elements with the given function.

Instances

Instances details
Zip [] Source #
Instance details

Defined in Data.Semialign.Internal

Methods

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

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

Zip Maybe Source #
Instance details

Defined in Data.Semialign.Internal

Zip Option Source #
Instance details

Defined in Data.Semialign.Internal

Zip ZipList Source #
Instance details

Defined in Data.Semialign.Internal

Zip Identity Source #
Instance details

Defined in Data.Semialign.Internal

Zip NonEmpty Source #
Instance details

Defined in Data.Semialign.Internal

Zip IntMap Source #
Instance details

Defined in Data.Semialign.Internal

Zip Tree Source #
Instance details

Defined in Data.Semialign.Internal

Methods

zip :: Tree a -> Tree b -> Tree (a, b) Source #

zipWith :: (a -> b -> c) -> Tree a -> Tree b -> Tree c Source #

Zip Seq Source #
Instance details

Defined in Data.Semialign.Internal

Methods

zip :: Seq a -> Seq b -> Seq (a, b) Source #

zipWith :: (a -> b -> c) -> Seq a -> Seq b -> Seq c Source #

Zip Vector Source #
Instance details

Defined in Data.Semialign.Internal

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

Defined in Data.Semialign.Internal

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

Defined in Data.Semialign.Internal

Methods

zip :: Map k a -> Map k b -> Map k (a, b) Source #

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

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

Defined in Data.Semialign.Internal

Methods

zip :: HashMap k a -> HashMap k b -> HashMap k (a, b) Source #

zipWith :: (a -> b -> c) -> HashMap k a -> HashMap k b -> HashMap k c Source #

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

Defined in Data.Semialign.Internal

Methods

zip :: Stream m a -> Stream m b -> Stream m (a, b) Source #

zipWith :: (a -> b -> c) -> Stream m a -> Stream m b -> Stream m c Source #

Zip ( Tagged b) Source #
Instance details

Defined in Data.Semialign.Internal

Methods

zip :: Tagged b a -> Tagged b b0 -> Tagged b (a, b0) Source #

zipWith :: (a -> b0 -> c) -> Tagged b a -> Tagged b b0 -> Tagged b c Source #

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

Defined in Data.Semialign.Internal

Methods

zip :: Bundle m v a -> Bundle m v b -> Bundle m v (a, b) Source #

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

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

Defined in Data.Semialign.Internal

Methods

zip :: (e -> a) -> (e -> b) -> e -> (a, b) Source #

zipWith :: (a -> b -> c) -> (e -> a) -> (e -> b) -> e -> c Source #

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

Defined in Data.Semialign.Internal

Methods

zip :: Product f g a -> Product f g b -> Product f g (a, b) Source #

zipWith :: (a -> b -> c) -> Product f g a -> Product f g b -> Product f g c Source #

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

Defined in Data.Semialign.Internal

Methods

zip :: Compose f g a -> Compose f g b -> Compose f g (a, b) Source #

zipWith :: (a -> b -> c) -> Compose f g a -> Compose f g b -> Compose f g c Source #

class Zip f => Repeat f where Source #

Zippable functors supporting left and right units

Unit

fst <$> zip xs (repeat y) ≡ xs
snd <$> zip (repeat x) ys ≡ ys

Methods

repeat :: a -> f a Source #

A repeat structure.

Instances

Instances details
Repeat [] Source #
Instance details

Defined in Data.Semialign.Internal

Methods

repeat :: a -> [a] Source #

Repeat Maybe Source #
Instance details

Defined in Data.Semialign.Internal

Repeat Option Source #
Instance details

Defined in Data.Semialign.Internal

Repeat ZipList Source #
Instance details

Defined in Data.Semialign.Internal

Repeat Identity Source #
Instance details

Defined in Data.Semialign.Internal

Repeat NonEmpty Source #
Instance details

Defined in Data.Semialign.Internal

Repeat Tree Source #
Instance details

Defined in Data.Semialign.Internal

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

Defined in Data.Semialign.Internal

Repeat ( Tagged b) Source #
Instance details

Defined in Data.Semialign.Internal

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

Defined in Data.Semialign.Internal

Methods

repeat :: a -> e -> a Source #

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

Defined in Data.Semialign.Internal

Methods

repeat :: a -> Product f g a Source #

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

Defined in Data.Semialign.Internal

Methods

repeat :: a -> Compose f g a Source #

class Zip f => Unzip f where Source #

Right inverse of zip .

This class is definable for every Functor . See unzipDefault .

Laws

uncurry zip (unzip xs) ≡ xs
unzip (zip xs xs) ≡ (xs, xs)

Note:

unzip (zip xs ys) ≢ (xs, _) or (_, ys)

For sequence-like types this holds, but for Map-like it doesn't.

Minimal complete definition

unzipWith | unzip

Methods

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

unzip :: f (a, b) -> (f a, f b) Source #

Instances

Instances details
Unzip [] Source #
Instance details

Defined in Data.Semialign.Internal

Methods

unzipWith :: (c -> (a, b)) -> [c] -> ([a], [b]) Source #

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

Unzip Maybe Source #
Instance details

Defined in Data.Semialign.Internal

Unzip Option Source #
Instance details

Defined in Data.Semialign.Internal

Unzip ZipList Source #
Instance details

Defined in Data.Semialign.Internal

Unzip Identity Source #
Instance details

Defined in Data.Semialign.Internal

Unzip NonEmpty Source #
Instance details

Defined in Data.Semialign.Internal

Unzip IntMap Source #
Instance details

Defined in Data.Semialign.Internal

Unzip Tree Source #
Instance details

Defined in Data.Semialign.Internal

Methods

unzipWith :: (c -> (a, b)) -> Tree c -> ( Tree a, Tree b) Source #

unzip :: Tree (a, b) -> ( Tree a, Tree b) Source #

Unzip Seq Source #
Instance details

Defined in Data.Semialign.Internal

Methods

unzipWith :: (c -> (a, b)) -> Seq c -> ( Seq a, Seq b) Source #

unzip :: Seq (a, b) -> ( Seq a, Seq b) Source #

Unzip Vector Source #
Instance details

Defined in Data.Semialign.Internal

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

Defined in Data.Semialign.Internal

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

Defined in Data.Semialign.Internal

Methods

unzipWith :: (c -> (a, b)) -> Map k c -> ( Map k a, Map k b) Source #

unzip :: Map k (a, b) -> ( Map k a, Map k b) Source #

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

Defined in Data.Semialign.Internal

Methods

unzipWith :: (c -> (a, b)) -> HashMap k c -> ( HashMap k a, HashMap k b) Source #

unzip :: HashMap k (a, b) -> ( HashMap k a, HashMap k b) Source #

Unzip ( Tagged b) Source #
Instance details

Defined in Data.Semialign.Internal

Methods

unzipWith :: (c -> (a, b0)) -> Tagged b c -> ( Tagged b a, Tagged b b0) Source #

unzip :: Tagged b (a, b0) -> ( Tagged b a, Tagged b b0) Source #

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

Defined in Data.Semialign.Internal

Methods

unzipWith :: (c -> (a, b)) -> Product f g c -> ( Product f g a, Product f g b) Source #

unzip :: Product f g (a, b) -> ( Product f g a, Product f g b) Source #

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

Defined in Data.Semialign.Internal

Methods

unzipWith :: (c -> (a, b)) -> Compose f g c -> ( Compose f g a, Compose f g b) Source #

unzip :: Compose f g (a, b) -> ( Compose f g a, Compose f g b) Source #

unzipDefault :: Functor f => f (a, b) -> (f a, f b) Source #

newtype Zippy f a Source #

Constructors

Zippy

Fields

Instances

Instances details
Functor f => Functor ( Zippy f) Source #
Instance details

Defined in Data.Zip

Methods

fmap :: (a -> b) -> Zippy f a -> Zippy f b Source #

(<$) :: a -> Zippy f b -> Zippy f a Source #

Repeat f => Applicative ( Zippy f) Source #
Instance details

Defined in Data.Zip

Zip f => Apply ( Zippy f) Source #
Instance details

Defined in Data.Zip

Eq (f a) => Eq ( Zippy f a) Source #
Instance details

Defined in Data.Zip

Ord (f a) => Ord ( Zippy f a) Source #
Instance details

Defined in Data.Zip

Read (f a) => Read ( Zippy f a) Source #
Instance details

Defined in Data.Zip

Show (f a) => Show ( Zippy f a) Source #
Instance details

Defined in Data.Zip

( Zip f, Semigroup a) => Semigroup ( Zippy f a) Source #
Instance details

Defined in Data.Zip

( Repeat f, Monoid a) => Monoid ( Zippy f a) Source #
Instance details

Defined in Data.Zip