Module
Data.Align
- Package
- purescript-these
- Repository
- purescript-contrib/purescript-these
#Align Source
class Align :: (Type -> Type) -> Constraint
class (Functor f) <= Align f where
The Align
type class represents an operation similar to Apply
with
slightly different semantics. For example:
> align identity (Just 1) Nothing :: These Int Int
This 1
Instances are required to satisfy the following laws:
- Idempotency:
join (align identity) == map (join These)
- Commutativity
align identity x y == swap <$> align identity y x
- Associativity
align identity x (align identity y z) == assoc <$> align identity (align identity x y) z
- Functoriality
align identity (f <$> x) (g <$> y) ≡ bimap f g <$> align identity x y
Members
Instances
#Alignable Source
class Alignable :: (Type -> Type) -> Constraint
class (Align f) <= Alignable f where
Alignable
adds an identity value for the align
operation.
Instances are required to satisfy the following laws:
- Left Identity:
align identity nil x == fmap That x
- Right Identity:
align identity x nil ≡ fmap This x
Members
nil :: forall a. f a
Instances
#Crosswalk Source
class Crosswalk :: (Type -> Type) -> Constraint
class (Foldable f, Functor f) <= Crosswalk f where
Crosswalk
is similar to Traversable
, but uses the Align
/Alignable
semantics instead of Apply
/Applicative
for combining values.
For example:
> traverse Int.fromString ["1", "2", "3"]
Just [1, 2, 3]
> crosswalk Int.fromString ["1", "2", "3"]
Just [1, 2, 3]
> traverse Int.fromString ["a", "b", "c"]
Nothing
> crosswalk Int.fromString ["a", "b", "c"]
Nothing
> traverse Int.fromString ["1", "b", "3"]
Nothing
> crosswalk Int.fromString ["1", "b", "3"]
Just [1, 3]
> traverse Int.fromString []
Just []
> crosswalk Int.fromString []
Nothing
Instances are required to satisfy the following laws:
- Annihilation:
crosswalk (const nil) == const nil