### Non-holding Distributivity Law Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Zip.html An example of a law that does not hold for zip and align. ```haskell distrThesePair <$> align (zip xs ys) zs ≢ zip (align xs zs) (align ys zs) ``` -------------------------------- ### Achieving Legacy Unalign Behavior Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Align.html Demonstrates how to replicate the version 1 behavior of unalign using unzipWith. ```haskell >>> **unzipWith (unalign . Just) [This 'a', That 'b', These 'c' 'd'] **([Just 'a',Nothing,Just 'c'],[Nothing,Just 'b',Just 'd']) ``` -------------------------------- ### Zip Instance Methods Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Zip.html Standard zip and zipWith methods defined for various data types. ```haskell zip :: ZipList a -> ZipList b -> ZipList (a, b) zipWith :: (a -> b -> c) -> ZipList a -> ZipList b -> ZipList c ``` ```haskell zip :: Identity a -> Identity b -> Identity (a, b) zipWith :: (a -> b -> c) -> Identity a -> Identity b -> Identity c ``` ```haskell zip :: NonEmpty a -> NonEmpty b -> NonEmpty (a, b) zipWith :: (a -> b -> c) -> NonEmpty a -> NonEmpty b -> NonEmpty c ``` ```haskell zip :: IntMap a -> IntMap b -> IntMap (a, b) zipWith :: (a -> b -> c) -> IntMap a -> IntMap b -> IntMap c ``` ```haskell zip :: Seq a -> Seq b -> Seq (a, b) zipWith :: (a -> b -> c) -> Seq a -> Seq b -> Seq c ``` ```haskell zip :: Tree a -> Tree b -> Tree (a, b) zipWith :: (a -> b -> c) -> Tree a -> Tree b -> Tree c ``` ```haskell zip :: Vector a -> Vector b -> Vector (a, b) zipWith :: (a -> b -> c) -> Vector a -> Vector b -> Vector c ``` ```haskell zip :: Maybe a -> Maybe b -> Maybe (a, b) zipWith :: (a -> b -> c) -> Maybe a -> Maybe b -> Maybe c ``` ```haskell zip :: [a] -> [b] -> [(a, b)] zipWith :: (a -> b -> c) -> [a] -> [b] -> [c] ``` ```haskell zip :: Proxy a -> Proxy b -> Proxy (a, b) zipWith :: (a -> b -> c) -> Proxy a -> Proxy b -> Proxy c ``` ```haskell zip :: Map k a -> Map k b -> Map k (a, b) zipWith :: (a -> b -> c) -> Map k a -> Map k b -> Map k c ``` ```haskell zip :: HashMap k a -> HashMap k b -> HashMap k (a, b) zipWith :: (a -> b -> c) -> HashMap k a -> HashMap k b -> HashMap k c ``` ```haskell zip :: Stream m a -> Stream m b -> Stream m (a, b) zipWith :: (a -> b -> c) -> Stream m a -> Stream m b -> Stream m c ``` ```haskell zip :: Tagged b a -> Tagged b b0 -> Tagged b (a, b0) zipWith :: (a -> b0 -> c) -> Tagged b a -> Tagged b b0 -> Tagged b c ``` ```haskell 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 ``` ```haskell 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 ``` ```haskell zip :: (e -> a) -> (e -> b) -> e -> (a, b) zipWith :: (a -> b -> c) -> (e -> a) -> (e -> b) -> e -> c ``` ```haskell 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 ``` -------------------------------- ### Zip With Definition Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Zip.html Defines the relationship between zipWith and zip. ```haskell zipWith f a b ≡ f <$> zip a b ``` -------------------------------- ### Alignment Utility Functions Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Align.html Common utility functions for aligning and padding structures. ```Haskell salign :: (Semialign f, Semigroup a) => f a -> f a -> f a padZip :: Semialign f => f a -> f b -> f (Maybe a, Maybe b) padZipWith :: Semialign f => (Maybe a -> Maybe b -> c) -> f a -> f b -> f c lpadZip :: [a] -> [b] -> [(Maybe a, b)] lpadZipWith :: (Maybe a -> b -> c) -> [a] -> [b] -> [c] rpadZip :: [a] -> [b] -> [(a, Maybe b)] rpadZipWith :: (a -> Maybe b -> c) -> [a] -> [b] -> [c] alignVectorWith :: (Vector v a, Vector v b, Vector v c) => (These a b -> c) -> v a -> v b -> v c ``` -------------------------------- ### Distributivity Laws for Zip and Align Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Zip.html Laws describing how zip and align interact with pair structures. ```haskell 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) ``` -------------------------------- ### Unzip Default Implementation Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Zip.html A default implementation of unzip for Functor instances. ```haskell unzipDefault :: Functor f => f (a, b) -> (f a, f b) ``` -------------------------------- ### padZip Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Semialign.html Aligns two structures similar to zip, filling missing values with Nothing. ```APIDOC ## padZip ### Description Align two structures as in `zip`, but filling in blanks with `Nothing`. ### Signature `padZip :: Semialign f => f a -> f b -> f (Maybe a, Maybe b)` ``` -------------------------------- ### Unzip Typeclass Definition Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Zip.html The minimal complete definition and method signatures for the Unzip typeclass. ```haskell unzipWith :: (c -> (a, b)) -> f c -> (f a, f b) unzip :: f (a, b) -> (f a, f b) ``` -------------------------------- ### zipWith :: (a -> b -> c) -> f a -> f b -> f c Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Zip.html Combines two structures by taking the intersection of their shapes and combining the elements with the given function. ```APIDOC ## zipWith ### Description Combines two structures by taking the intersection of their shapes and combining the elements with the given function. ### Signature zipWith :: (a -> b -> c) -> f a -> f b -> f c ``` -------------------------------- ### salign Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Semialign.html Aligns two structures and combines them using the Semigroup operation. ```APIDOC ## salign ### Description Align two structures and combine with `<>`. ### Signature `salign :: (Semialign f, Semigroup a) => f a -> f a -> f a` ``` -------------------------------- ### padZipWith Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Semialign.html Aligns two structures similar to zipWith, providing Maybe values to the combining function. ```APIDOC ## padZipWith ### Description Align two structures as in `zipWith`, but filling in blanks with `Nothing`. ### Signature `padZipWith :: Semialign f => (Maybe a -> Maybe b -> c) -> f a -> f b -> f c` ``` -------------------------------- ### unzip Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Zip.html Splits a structure of pairs into a pair of structures. ```APIDOC ## unzip ### Description Takes a structure containing pairs and returns a pair of structures, where the first contains the first elements of the pairs and the second contains the second elements. ### Signature unzip :: f (a, b) -> (f a, f b) ``` -------------------------------- ### Bicrosswalk Laws Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Crosswalk.html Defines the expected behavior for Bicrosswalk instances. ```haskell bicrosswalk (const empty) (const empty) = const empty bicrosswalk f g = bisequenceL . bimap f g ``` -------------------------------- ### lpadZipWith Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Semialign.html Performs a left-padded zipWith operation on lists. ```APIDOC ## lpadZipWith ### Description Left-padded `zipWith`. ### Signature `lpadZipWith :: (Maybe a -> b -> c) -> [a] -> [b] -> [c]` ``` -------------------------------- ### rpadZipWith Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Semialign.html Performs a right-padded zipWith operation on lists. ```APIDOC ## rpadZipWith ### Description Right-padded `zipWith`. ### Signature `rpadZipWith :: (a -> Maybe b -> c) -> [a] -> [b] -> [c]` ``` -------------------------------- ### RepeatWithIndex Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Semialign-Indexed.html The RepeatWithIndex type-class allows for the creation of structures where elements are generated based on their index. ```APIDOC ## class RepeatWithIndex i f ### Description Provides the `irepeat` method to generate a structure where each element is determined by a function of its index. ### Methods - **irepeat** :: (i -> a) -> f a - Generates a structure `f a` where each element at index `i` is produced by the provided function. ``` -------------------------------- ### alignWith :: (These a b -> c) -> f a -> f b -> f c Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Align.html Combines two structures by taking the union of their shapes and combining the elements with the given function. ```APIDOC ## alignWith ### Description Analogous to zipWith, combines two structures by taking the union of their shapes and combining the elements with the given function. ### Signature alignWith :: (These a b -> c) -> f a -> f b -> f c ``` -------------------------------- ### With Law Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Align.html Defines the relationship between alignWith and align. ```haskell alignWith f a b ≡ f <$> align a b ``` -------------------------------- ### lpadZip Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Semialign.html Performs a left-padded zip operation on lists. ```APIDOC ## lpadZip ### Description Left-padded `zip`. ### Signature `lpadZip :: [a] -> [b] -> [(Maybe a, b)]` ``` -------------------------------- ### zip :: f a -> f b -> f (a, b) Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Zip.html Combines two structures by taking the intersection of their shapes and using a pair to hold the elements. ```APIDOC ## zip ### Description Combines two structures by taking the intersection of their shapes and using pair to hold the elements. ### Signature zip :: f a -> f b -> f (a, b) ``` -------------------------------- ### Align and Unalign Type-classes Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Align.html Extends Semialign with nil and unalign operations. ```Haskell class Semialign f => Align (f :: Type -> Type) where nil :: f a class Semialign f => Unalign (f :: Type -> Type) where unalign :: f (These a b) -> (f a, f b) unalignWith :: (c -> These a b) -> f c -> (f a, f b) ``` -------------------------------- ### align :: f a -> f b -> f (These a b) Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Align.html Combines two structures by taking the union of their shapes and using These to hold the elements. ```APIDOC ## align ### Description Analogous to zip, combines two structures by taking the union of their shapes and using These to hold the elements. ### Signature align :: f a -> f b -> f (These a b) ``` -------------------------------- ### rpadZip Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Semialign.html Performs a right-padded zip operation on lists. ```APIDOC ## rpadZip ### Description Right-padded `zip`. ### Signature `rpadZip :: [a] -> [b] -> [(a, Maybe b)]` ``` -------------------------------- ### Unzip Laws Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Zip.html Defines the expected behavior for unzip operations, noting that behavior may differ between sequence-like and map-like types. ```haskell uncurry zip (unzip xs) ≡ xs unzip (zip xs xs) ≡ (xs, (xs)) ``` ```haskell unzip (zip xs ys) ≢ (xs, _) or (_, ys) ``` -------------------------------- ### Crosswalk Laws Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Crosswalk.html Defines the expected behavior for Crosswalk instances. ```haskell crosswalk (const nil) = const nil crosswalk f = sequenceL . fmap f ``` -------------------------------- ### Unzip Typeclass Methods Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Semialign.html The Unzip typeclass defines methods for decomposing structures containing pairs. Users can implement these for custom types to enable splitting functionality. ```APIDOC ## unzipWith :: (c -> (a, b)) -> f c -> (f a, f b) ### Description Maps each element of the structure to a pair, then splits the structure into two separate structures. ## unzip :: f (a, b) -> (f a, f b) ### Description Splits a structure of pairs into a pair of structures. ``` -------------------------------- ### Functoriality Law for Zip Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Zip.html Defines the relationship between mapping functions over structures and the zip operation. ```haskell zip (f <$> x) (g <$> y) ≡ bimap f g <$> zip x y ``` -------------------------------- ### ZipWithIndex Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Semialign-Indexed.html The ZipWithIndex type-class provides an indexed version of Zip, allowing for zipping operations that utilize the index of the elements. ```APIDOC ## class ZipWithIndex i f ### Description An indexed version of the Zip type-class. It provides the `izipWith` method to zip two structures while providing the index to the combining function. ### Methods - **izipWith** :: (i -> a -> b -> c) -> f a -> f b -> f c - Analogous to `zipWith`, but also provides an index `i` to the combining function. ``` -------------------------------- ### Repeat Class Definition and Laws Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Zip.html Defines the Repeat class for zippable functors and its associated laws. ```haskell class Zip f => Repeat (f :: Type -> Type) where ``` ```haskell fst <$> zip xs (repeat y) ≡ xs snd <$> zip (repeat x) ys ≡ ys ``` ```haskell repeat :: a -> f a ``` -------------------------------- ### unzipWith Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Zip.html Splits a structure of values into a pair of structures by applying a function to each element. ```APIDOC ## unzipWith ### Description Applies a function to each element in a structure to produce a pair, then splits the structure into two separate structures. ### Signature unzipWith :: (c -> (a, b)) -> f c -> (f a, f b) ``` -------------------------------- ### Zippy Newtype Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Zip.html Definition of the Zippy newtype wrapper. ```haskell newtype Zippy (f :: Type -> Type) a ``` -------------------------------- ### Zip Associativity Law Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Zip.html Defines the associativity law for the Zip operation. ```haskell zip x (zip y z) ≡ assoc <$> zip (zip x y) z ``` -------------------------------- ### unalignWith Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Semialign.html Maps a function over a structure and then unaligns the result. ```APIDOC ## unalignWith ### Description Applies a function `(c -> These a b)` to elements of a structure `f c` and returns a pair of structures `(f a, f b)`. ### Signature `unalignWith :: (c -> These a b) -> f c -> (f a, f b)` ``` -------------------------------- ### unalign Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Semialign.html Splits a structure of 'These a b' values into a pair of structures containing 'a' and 'b' values respectively. ```APIDOC ## unalign ### Description Takes a structure `f` containing `These a b` values and returns a pair of structures `(f a, f b)`. ### Signature `unalign :: f (These a b) -> (f a, f b)` ``` -------------------------------- ### Semialign Type-class Definition Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Align.html Defines the core Semialign type-class for functors supporting union-based alignment. ```Haskell class Unzip f => Semialign (f :: Type -> Type) where align :: f a -> f b -> f (These a b) alignWith :: (These a b -> c) -> f a -> f b -> f c ``` -------------------------------- ### SemialignWithIndex Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Semialign-Indexed.html The SemialignWithIndex type-class provides an indexed version of Semialign, allowing for alignment operations that utilize the index of the elements. ```APIDOC ## class SemialignWithIndex i f ### Description An indexed version of the Semialign type-class. It provides the `ialignWith` method to align two structures while providing the index to the combining function. ### Methods - **ialignWith** :: (i -> These a b -> c) -> f a -> f b -> f c - Analogous to `alignWith`, but also provides an index `i` to the combining function. ``` -------------------------------- ### Zip Commutativity Law Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Zip.html Defines the commutativity law for the Zip operation. ```haskell zip x y ≡ swap <$> zip y x ``` -------------------------------- ### Zippyness Laws Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Zip.html Identities relating zip to fst and snd projections. ```haskell fmap fst (zip x x) ≡ x fmap snd (zip x x) ≡ x zip (fmap fst x) (fmap snd x) ≡ x ``` -------------------------------- ### Unalign Algebraic Laws Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Align.html Defines the primary law for unalign operations. ```haskell unalign (align xs ys) ≡ (xs, ys) ``` -------------------------------- ### Zip Idempotency Law Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Zip.html Defines the idempotency law for the Zip operation. ```haskell join zip ≡ fmap (join (,)) ``` -------------------------------- ### Align Laws Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Align.html Defines the identity laws for the align operation when combined with an empty structure. ```haskell (`align` nil) ≡ fmap This (nil `align`) ≡ fmap That ``` -------------------------------- ### Zip Absorption Laws Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Zip.html Defines the absorption laws relating Zip and Align operations. ```haskell 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 ``` -------------------------------- ### Repeat Typeclass Definition Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Semialign.html The Repeat typeclass defines structures that support left and right units for zipping. ```haskell fst <$> zip xs (repeat y) ≡ xs snd <$> zip (repeat x) ys ≡ ys ``` ```haskell class Zip f => Repeat (f :: Type -> Type) where repeat :: a -> f a ``` -------------------------------- ### alignVectorWith Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Semialign.html Aligns two vectors using a combining function. ```APIDOC ## alignVectorWith ### Description Aligns two vectors using the provided function. ### Signature `alignVectorWith :: (Vector v a, Vector v b, Vector v c) => (These a b -> c) -> v a -> v b -> v c` ``` -------------------------------- ### Historical Unalign Law Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Align.html The right inverse law that was removed in version 1.4 to support list-like instances. ```haskell uncurry align (unalign xs) ≡ xs ``` -------------------------------- ### Idempotency Law Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Align.html Defines the idempotency property for the align operation. ```haskell join align ≡ fmap (join These) ``` -------------------------------- ### Alignedness Law Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Align.html Defines the alignedness property for Foldable structures. ```haskell toList x ≡ toListOf (folded . here) (align x y) ≡ mapMaybe justHere (toList (align x y)) ``` -------------------------------- ### Associativity Law Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Align.html Defines the associativity property for the align operation. ```haskell align x (align y z) ≡ assoc <$> align (align x y) z ``` -------------------------------- ### Commutativity Law Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Align.html Defines the commutativity property for the align operation. ```haskell align x y ≡ swap <$> align y x ``` -------------------------------- ### Functoriality Law Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Align.html Defines the functoriality property for the align operation. ```haskell align (f <$> x) (g <$> y) ≡ bimap f g <$> align x y ``` -------------------------------- ### Unalign Type Class Definition Source: https://hackage.haskell.org/package/semialign-1.4/docs/Data-Align.html Defines the Unalign class for functors that support splitting a union shape into component parts. ```haskell class Semialign f => Unalign (f :: Type -> Type) where ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.