Module

Data.Align

Package
purescript-these
Repository
purescript-contrib/purescript-these

#Align Source

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

  • align :: forall a b c. (These a b -> c) -> f a -> f b -> f c

Instances

#aligned Source

aligned :: forall a b f. Align f => f a -> f b -> f (These a b)

Convenience combinator for align identity.

#Alignable Source

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 (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

Members

Instances