| Safe Haskell | Trustworthy |
|---|---|
| Language | Haskell2010 |
Data.Align
Contents
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
- class Functor f => Semialign f where
- class Semialign f => Align f where
- nil :: f a
- class Semialign f => Unalign f where
- unalign :: f (These a b) -> (f a, f b)
- unalignWith :: (c -> These a b) -> f c -> (f a, f b)
- 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
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 additional 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))
Methods
align :: f a -> f b -> f (These a b) Source #
Analogous to , combines two structures by taking the union of
their shapes and using zip to hold the elements.These
alignWith :: (These a b -> c) -> f a -> f b -> f c Source #
Analogous to , combines two structures by taking the union of
their shapes and combining the elements with the given function.zipWith
Instances
Instances details
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
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
Specialized aligns
salign :: (Semialign f, Semigroup a) => f a -> f a -> f a Source #
Align two structures and combine with <> .
lpadZipWith :: (Maybe a -> b -> c) -> [a] -> [b] -> [c] Source #
Left-padded zipWith .
rpadZipWith :: (a -> Maybe b -> c) -> [a] -> [b] -> [c] Source #
Right-padded zipWith .