Skip to content

Latest commit

 

History

History
47 lines (32 loc) · 821 Bytes

Alt.md

File metadata and controls

47 lines (32 loc) · 821 Bytes

Alt

The Alt typeclass provides semigroup-like operations on type constructors instead of values.

Parent

The Alt typeclass extends the Functor typeclass

API

The Alt typeclass provides a single associative binary operation.

interface Alt extends Functor
{
    /**
     * @param F<A> $a
     * @param F<A> $b
     * @return F<A>
     */
    public function alt($a, $b);
}

Its simplified type is

alt :: F<A> -> F<A> -> F<A>

Laws

Associativity

$alternative->alt($alternative->alt($x, $y), $z) == $alternative->alt($x, $alternative->alt($y, $z))

Distributivity with respect to map

$alternative->map($f, $alternative->alt($x, $y)) == $alternative->alt($alternative->map($f, $x), $alternative->map($f, $y))

Implemented instances

  • EitherAlt