Link Search Menu Expand Document

Alternative overview

The Alternative type class extends the Alt type class with a value that should be the left and right identity for alt.

It is similar to Monoid, except that it applies to types of kind * -> *, like Array or Option, rather than concrete types like string or number.

Alternative instances should satisfy the following laws:

  1. Left identity: A.alt(zero, fa) <-> fa
  2. Right identity: A.alt(fa, zero) <-> fa
  3. Annihilation: A.map(zero, f) <-> zero
  4. Distributivity: A.ap(A.alt(fab, gab), fa) <-> A.alt(A.ap(fab, fa), A.ap(gab, fa))
  5. Annihilation: A.ap(zero, fa) <-> zero

Added in v2.0.0


Table of contents


type classes

Alternative (interface)

Signature

export interface Alternative<F> extends Applicative<F>, Alt<F>, Zero<F> {}

Added in v2.0.0

Alternative1 (interface)

Signature

export interface Alternative1<F extends URIS> extends Applicative1<F>, Alt1<F>, Zero1<F> {}

Added in v2.0.0

Alternative2 (interface)

Signature

export interface Alternative2<F extends URIS2> extends Applicative2<F>, Alt2<F>, Zero2<F> {}

Added in v2.0.0

Alternative2C (interface)

Signature

export interface Alternative2C<F extends URIS2, E> extends Applicative2C<F, E>, Alt2C<F, E>, Zero2C<F, E> {}

Added in v2.0.0

Alternative3 (interface)

Signature

export interface Alternative3<F extends URIS3> extends Applicative3<F>, Alt3<F>, Zero3<F> {}

Added in v2.0.0

Alternative3C (interface)

Signature

export interface Alternative3C<F extends URIS3, E> extends Applicative3C<F, E>, Alt3C<F, E>, Zero3C<F, E> {}

Added in v2.10.0

Alternative4 (interface)

Signature

export interface Alternative4<F extends URIS4> extends Applicative4<F>, Alt4<F>, Zero4<F> {}

Added in v2.10.0

utils

altAll

Signature

export declare function altAll<F extends URIS4>(
  F: Alternative4<F>
): <S, R, E, A>(as: ReadonlyArray<Kind4<F, S, R, E, A>>) => Kind4<F, S, R, E, A>
export declare function altAll<F extends URIS3>(
  F: Alternative3<F>
): <R, E, A>(as: ReadonlyArray<Kind3<F, R, E, A>>) => Kind3<F, R, E, A>
export declare function altAll<F extends URIS3, E>(
  F: Alternative3C<F, E>
): <R, A>(as: ReadonlyArray<Kind3<F, R, E, A>>) => Kind3<F, R, E, A>
export declare function altAll<F extends URIS2>(
  F: Alternative2<F>
): <E, A>(as: ReadonlyArray<Kind2<F, E, A>>) => Kind2<F, E, A>
export declare function altAll<F extends URIS2, E>(
  F: Alternative2C<F, E>
): <A>(as: ReadonlyArray<Kind2<F, E, A>>) => Kind2<F, E, A>
export declare function altAll<F extends URIS>(F: Alternative1<F>): <A>(as: ReadonlyArray<Kind<F, A>>) => Kind<F, A>
export declare function altAll<F>(F: Alternative<F>): <A>(as: ReadonlyArray<HKT<F, A>>) => HKT<F, A>

Added in v2.11.0