semialign-1.3: Align and Zip type-classes from the common Semialign ancestor.
Safe HaskellTrustworthy
LanguageHaskell2010

Data.Zip

Description

Zipping and unzipping of functors with non-uniform shapes.

Synopsis

Documentation

class Functor f => Semialign (f :: Type -> Type) where #

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) #

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 #

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 ZipList #

zipWith = liftA2 .

Instance details

Defined in Data.Semialign.Internal

Methods

align :: ZipList a -> ZipList b -> ZipList (These a b) #

alignWith :: (These a b -> c) -> ZipList a -> ZipList b -> ZipList c #

Semialign Identity # 
Instance details

Defined in Data.Semialign.Internal

Methods

align :: Identity a -> Identity b -> Identity (These a b) #

alignWith :: (These a b -> c) -> Identity a -> Identity b -> Identity c #

Semialign NonEmpty # 
Instance details

Defined in Data.Semialign.Internal

Methods

align :: NonEmpty a -> NonEmpty b -> NonEmpty (These a b) #

alignWith :: (These a b -> c) -> NonEmpty a -> NonEmpty b -> NonEmpty c #

Semialign IntMap # 
Instance details

Defined in Data.Semialign.Internal

Methods

align :: IntMap a -> IntMap b -> IntMap (These a b) #

alignWith :: (These a b -> c) -> IntMap a -> IntMap b -> IntMap c #

Semialign Seq # 
Instance details

Defined in Data.Semialign.Internal

Methods

align :: Seq a -> Seq b -> Seq (These a b) #

alignWith :: (These a b -> c) -> Seq a -> Seq b -> Seq c #

Semialign Tree # 
Instance details

Defined in Data.Semialign.Internal

Methods

align :: Tree a -> Tree b -> Tree (These a b) #

alignWith :: (These a b -> c) -> Tree a -> Tree b -> Tree c #

Semialign Vector # 
Instance details

Defined in Data.Semialign.Internal

Methods

align :: Vector a -> Vector b -> Vector (These a b) #

alignWith :: (These a b -> c) -> Vector a -> Vector b -> Vector c #

Semialign Maybe # 
Instance details

Defined in Data.Semialign.Internal

Methods

align :: Maybe a -> Maybe b -> Maybe (These a b) #

alignWith :: (These a b -> c) -> Maybe a -> Maybe b -> Maybe c #

Semialign [] # 
Instance details

Defined in Data.Semialign.Internal

Methods

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

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

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

Defined in Data.Semialign.Internal

Methods

align :: Proxy a -> Proxy b -> Proxy (These a b) #

alignWith :: (These a b -> c) -> Proxy a -> Proxy b -> Proxy c #

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

Defined in Data.Semialign.Internal

Methods

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

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

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

Defined in Data.Semialign.Internal

Methods

align :: HashMap k a -> HashMap k b -> HashMap k (These a b) #

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

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

Defined in Data.Semialign.Internal

Methods

align :: Stream m a -> Stream m b -> Stream m (These a b) #

alignWith :: (These a b -> c) -> Stream m a -> Stream m b -> Stream m c #

Semialign (Tagged b) # 
Instance details

Defined in Data.Semialign.Internal

Methods

align :: Tagged b a -> Tagged b b0 -> Tagged b (These a b0) #

alignWith :: (These a b0 -> c) -> Tagged b a -> Tagged b b0 -> Tagged b c #

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

Defined in Data.Semialign.Internal

Methods

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

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

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

Defined in Data.Semialign.Internal

Methods

align :: Product f g a -> Product f g b -> Product f g (These a b) #

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

Semialign ((->) e) # 
Instance details

Defined in Data.Semialign.Internal

Methods

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

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

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

Defined in Data.Semialign.Internal

Methods

align :: Compose f g a -> Compose f g b -> Compose f g (These a b) #

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

class Semialign f => Zip (f :: Type -> Type) where #

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) #

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 #

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

Instances

Instances details
Zip ZipList # 
Instance details

Defined in Data.Semialign.Internal

Methods

zip :: ZipList a -> ZipList b -> ZipList (a, b) #

zipWith :: (a -> b -> c) -> ZipList a -> ZipList b -> ZipList c #

Zip Identity # 
Instance details

Defined in Data.Semialign.Internal

Methods

zip :: Identity a -> Identity b -> Identity (a, b) #

zipWith :: (a -> b -> c) -> Identity a -> Identity b -> Identity c #

Zip NonEmpty # 
Instance details

Defined in Data.Semialign.Internal

Methods

zip :: NonEmpty a -> NonEmpty b -> NonEmpty (a, b) #

zipWith :: (a -> b -> c) -> NonEmpty a -> NonEmpty b -> NonEmpty c #

Zip IntMap # 
Instance details

Defined in Data.Semialign.Internal

Methods

zip :: IntMap a -> IntMap b -> IntMap (a, b) #

zipWith :: (a -> b -> c) -> IntMap a -> IntMap b -> IntMap c #

Zip Seq # 
Instance details

Defined in Data.Semialign.Internal

Methods

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

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

Zip Tree # 
Instance details

Defined in Data.Semialign.Internal

Methods

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

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

Zip Vector # 
Instance details

Defined in Data.Semialign.Internal

Methods

zip :: Vector a -> Vector b -> Vector (a, b) #

zipWith :: (a -> b -> c) -> Vector a -> Vector b -> Vector c #

Zip Maybe # 
Instance details

Defined in Data.Semialign.Internal

Methods

zip :: Maybe a -> Maybe b -> Maybe (a, b) #

zipWith :: (a -> b -> c) -> Maybe a -> Maybe b -> Maybe c #

Zip [] # 
Instance details

Defined in Data.Semialign.Internal

Methods

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

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

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

Defined in Data.Semialign.Internal

Methods

zip :: Proxy a -> Proxy b -> Proxy (a, b) #

zipWith :: (a -> b -> c) -> Proxy a -> Proxy b -> Proxy c #

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

Defined in Data.Semialign.Internal

Methods

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

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

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

Defined in Data.Semialign.Internal

Methods

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

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

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

Defined in Data.Semialign.Internal

Methods

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

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

Zip (Tagged b) # 
Instance details

Defined in Data.Semialign.Internal

Methods

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

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

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

Defined in Data.Semialign.Internal

Methods

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

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

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

Defined in Data.Semialign.Internal

Methods

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

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

Zip ((->) e) # 
Instance details

Defined in Data.Semialign.Internal

Methods

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

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

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

Defined in Data.Semialign.Internal

Methods

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

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

class Zip f => Repeat (f :: Type -> Type) where #

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 #

A repeat structure.

Instances

Instances details
Repeat ZipList # 
Instance details

Defined in Data.Semialign.Internal

Methods

repeat :: a -> ZipList a #

Repeat Identity # 
Instance details

Defined in Data.Semialign.Internal

Methods

repeat :: a -> Identity a #

Repeat NonEmpty # 
Instance details

Defined in Data.Semialign.Internal

Methods

repeat :: a -> NonEmpty a #

Repeat Tree # 
Instance details

Defined in Data.Semialign.Internal

Methods

repeat :: a -> Tree a #

Repeat Maybe # 
Instance details

Defined in Data.Semialign.Internal

Methods

repeat :: a -> Maybe a #

Repeat [] # 
Instance details

Defined in Data.Semialign.Internal

Methods

repeat :: a -> [a] #

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

Defined in Data.Semialign.Internal

Methods

repeat :: a -> Proxy a #

Repeat (Tagged b) # 
Instance details

Defined in Data.Semialign.Internal

Methods

repeat :: a -> Tagged b a #

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

Defined in Data.Semialign.Internal

Methods

repeat :: a -> Product f g a #

Repeat ((->) e) # 
Instance details

Defined in Data.Semialign.Internal

Methods

repeat :: a -> e -> a #

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

Defined in Data.Semialign.Internal

Methods

repeat :: a -> Compose f g a #

class Zip f => Unzip (f :: Type -> Type) where #

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) #

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

Instances

Instances details
Unzip ZipList # 
Instance details

Defined in Data.Semialign.Internal

Methods

unzipWith :: (c -> (a, b)) -> ZipList c -> (ZipList a, ZipList b) #

unzip :: ZipList (a, b) -> (ZipList a, ZipList b) #

Unzip Identity # 
Instance details

Defined in Data.Semialign.Internal

Methods

unzipWith :: (c -> (a, b)) -> Identity c -> (Identity a, Identity b) #

unzip :: Identity (a, b) -> (Identity a, Identity b) #

Unzip NonEmpty # 
Instance details

Defined in Data.Semialign.Internal

Methods

unzipWith :: (c -> (a, b)) -> NonEmpty c -> (NonEmpty a, NonEmpty b) #

unzip :: NonEmpty (a, b) -> (NonEmpty a, NonEmpty b) #

Unzip IntMap # 
Instance details

Defined in Data.Semialign.Internal

Methods

unzipWith :: (c -> (a, b)) -> IntMap c -> (IntMap a, IntMap b) #

unzip :: IntMap (a, b) -> (IntMap a, IntMap b) #

Unzip Seq # 
Instance details

Defined in Data.Semialign.Internal

Methods

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

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

Unzip Tree # 
Instance details

Defined in Data.Semialign.Internal

Methods

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

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

Unzip Vector # 
Instance details

Defined in Data.Semialign.Internal

Methods

unzipWith :: (c -> (a, b)) -> Vector c -> (Vector a, Vector b) #

unzip :: Vector (a, b) -> (Vector a, Vector b) #

Unzip Maybe # 
Instance details

Defined in Data.Semialign.Internal

Methods

unzipWith :: (c -> (a, b)) -> Maybe c -> (Maybe a, Maybe b) #

unzip :: Maybe (a, b) -> (Maybe a, Maybe b) #

Unzip [] # 
Instance details

Defined in Data.Semialign.Internal

Methods

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

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

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

Defined in Data.Semialign.Internal

Methods

unzipWith :: (c -> (a, b)) -> Proxy c -> (Proxy a, Proxy b) #

unzip :: Proxy (a, b) -> (Proxy a, Proxy b) #

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

Defined in Data.Semialign.Internal

Methods

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

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

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

Defined in Data.Semialign.Internal

Methods

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

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

Unzip (Tagged b) # 
Instance details

Defined in Data.Semialign.Internal

Methods

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

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

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

Defined in Data.Semialign.Internal

Methods

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

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

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

Defined in Data.Semialign.Internal

Methods

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

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

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

newtype Zippy (f :: Type -> Type) a #

Constructors

Zippy 

Fields

Instances

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

Defined in Data.Zip

Methods

pure :: a -> Zippy f a #

(<*>) :: Zippy f (a -> b) -> Zippy f a -> Zippy f b #

liftA2 :: (a -> b -> c) -> Zippy f a -> Zippy f b -> Zippy f c #

(*>) :: Zippy f a -> Zippy f b -> Zippy f b #

(<*) :: Zippy f a -> Zippy f b -> Zippy f a #

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

Defined in Data.Zip

Methods

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

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

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

Defined in Data.Zip

Methods

(<.>) :: Zippy f (a -> b) -> Zippy f a -> Zippy f b #

(.>) :: Zippy f a -> Zippy f b -> Zippy f b #

(<.) :: Zippy f a -> Zippy f b -> Zippy f a #

liftF2 :: (a -> b -> c) -> Zippy f a -> Zippy f b -> Zippy f c #

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

Defined in Data.Zip

Methods

mempty :: Zippy f a #

mappend :: Zippy f a -> Zippy f a -> Zippy f a #

mconcat :: [Zippy f a] -> Zippy f a #

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

Defined in Data.Zip

Methods

(<>) :: Zippy f a -> Zippy f a -> Zippy f a #

sconcat :: NonEmpty (Zippy f a) -> Zippy f a #

stimes :: Integral b => b -> Zippy f a -> Zippy f a #

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

Defined in Data.Zip

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

Defined in Data.Zip

Methods

showsPrec :: Int -> Zippy f a -> ShowS #

show :: Zippy f a -> String #

showList :: [Zippy f a] -> ShowS #

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

Defined in Data.Zip

Methods

(==) :: Zippy f a -> Zippy f a -> Bool #

(/=) :: Zippy f a -> Zippy f a -> Bool #

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

Defined in Data.Zip

Methods

compare :: Zippy f a -> Zippy f a -> Ordering #

(<) :: Zippy f a -> Zippy f a -> Bool #

(<=) :: Zippy f a -> Zippy f a -> Bool #

(>) :: Zippy f a -> Zippy f a -> Bool #

(>=) :: Zippy f a -> Zippy f a -> Bool #

max :: Zippy f a -> Zippy f a -> Zippy f a #

min :: Zippy f a -> Zippy f a -> Zippy f a #