Skip to main content Link Search Menu Expand Document (external link)

DatumEither overview

Added in v2.0.0

Represents a value of one of six possible types (a disjoint union).

An instance of DatumEither is equivalent to Datum<Either<E, A>>

A common use of DatumEither is as a container for dealing with refreshable data values that can have error conditions. The full type list is:

  • Initial
  • Pending
  • Refresh<Either<E, A>>
    • Refresh<Left<E>>
    • Refresh<Right<A>>
  • Replete<Either<E, A>>
    • Replete<Left<E>>
    • Replete<Right<A>>

There are additional helper methods for going from refresh to replete and back.


Table of contents


utils

Alt

Signature

export declare const Alt: Alt2<'@nll/datum/DatumEither'>

Added in v3.5.0

Alternative

Signature

export declare const Alternative: Alternative2<'@nll/datum/DatumEither'>

Added in v3.5.0

Applicative

Signature

export declare const Applicative: Applicative2<'@nll/datum/DatumEither'>

Added in v3.5.0

Apply

Signature

export declare const Apply: Apply2<'@nll/datum/DatumEither'>

Added in v3.5.0

Note: This instance agrees with the standalone Applicative/Chain/Monad instances but disagrees with the deprecated datum mega-instance.

Bifunctor

Signature

export declare const Bifunctor: Bifunctor2<'@nll/datum/DatumEither'>

Added in v3.5.0

Chain

Signature

export declare const Chain: Chain2<'@nll/datum/DatumEither'>

Added in v3.5.0

DatumEither (type alias)

Signature

export type DatumEither<E, A> = D.Datum<Either<E, A>>

Added in v2.1.0

Failure (type alias)

Signature

export type Failure<E> = Valued<Left<E>>

Added in v2.3.0

Foldable

Signature

export declare const Foldable: Foldable2<'@nll/datum/DatumEither'>

Added in v3.5.0

Functor

Signature

export declare const Functor: Functor2<'@nll/datum/DatumEither'>

Added in v3.5.0

Monad

Signature

export declare const Monad: Monad2<'@nll/datum/DatumEither'>

Added in v3.5.0

MonadThrow

Signature

export declare const MonadThrow: MonadThrow2<'@nll/datum/DatumEither'>

Added in v3.5.0

Success (type alias)

Signature

export type Success<A> = Valued<Right<A>>

Added in v2.3.0

ToLeft (type alias)

Signature

export type ToLeft<T> = T extends DatumEither<infer L, infer _> ? L : never

Added in v3.2.0

ToRight (type alias)

Signature

export type ToRight<T> = T extends DatumEither<infer _, infer R> ? R : never

Added in v3.2.0

Traversable

Signature

export declare const Traversable: Traversable2<'@nll/datum/DatumEither'>

Added in v3.5.0

URI

Signature

export declare const URI: '@nll/datum/DatumEither'

Added in v2.0.0

URI (type alias)

Signature

export type URI = typeof URI

Added in v2.0.0

Valued (type alias)

Signature

export type Valued<A> = D.Refresh<A> | D.Replete<A>

Added in v3.4.0

alt

Signature

export declare const alt: <E, A>(
  that: Lazy<D.Datum<Either<E, A>>>
) => (fa: D.Datum<Either<E, A>>) => D.Datum<Either<E, A>>

Added in v2.0.0

ap

Signature

export declare const ap: <E, A>(
  fa: D.Datum<Either<E, A>>
) => <B>(fab: D.Datum<Either<E, (a: A) => B>>) => D.Datum<Either<E, B>>

Added in v4.0.0

apFirst

Signature

export declare const apFirst: <E, B>(
  fb: D.Datum<Either<E, B>>
) => <A>(fa: D.Datum<Either<E, A>>) => D.Datum<Either<E, A>>

Added in v2.0.0

apSecond

Signature

export declare const apSecond: <E, B>(
  fb: D.Datum<Either<E, B>>
) => <A>(fa: D.Datum<Either<E, A>>) => D.Datum<Either<E, B>>

Added in v2.0.0

bimap

Signature

export declare const bimap: <E, G, A, B>(
  f: (e: E) => G,
  g: (a: A) => B
) => (fa: D.Datum<Either<E, A>>) => D.Datum<Either<G, B>>

Added in v2.0.0

chain

Signature

export declare const chain: <E, A, B>(
  f: (a: A) => D.Datum<Either<E, B>>
) => (ma: D.Datum<Either<E, A>>) => D.Datum<Either<E, B>>

Added in v2.0.0

chainFirst

Signature

export declare const chainFirst: <E, A, B>(
  f: (a: A) => D.Datum<Either<E, B>>
) => (ma: D.Datum<Either<E, A>>) => D.Datum<Either<E, A>>

Added in v2.0.0

constInitial

Signature

export declare function constInitial<E = never, D = never>(): DatumEither<E, D>

Added in v2.4.1

constPending

Signature

export declare const constPending: <E = never, D = never>() => D.Datum<Either<E, D>>

Added in v2.4.1

failure

Signature

export declare const failure: <E = never, A = never>(e: E) => D.Datum<Either<E, A>>

Added in v2.1.0

failureR

Signature

export declare const failureR: <E = never, A = never>(e: E) => D.Datum<Either<E, A>>

Added in v3.4.0

flatten

Signature

export declare const flatten: <E, A>(mma: D.Datum<Either<E, D.Datum<Either<E, A>>>>) => D.Datum<Either<E, A>>

Added in v2.0.0

fold

Signature

export declare const fold: <E, A, B>(
  onInitial: Lazy<B>,
  onPending: Lazy<B>,
  onRefreshLeft: FunctionN<[E], B>,
  onRefreshRight: FunctionN<[A], B>,
  onRepleteLeft: FunctionN<[E], B>,
  onRepleteRight: FunctionN<[A], B>
) => (fea: D.Datum<Either<E, A>>) => B

Added in v2.7.0

foldMap

Signature

export declare const foldMap: <M>(M: Monoid<M>) => <A>(f: (a: A) => M) => <E>(fa: D.Datum<Either<E, A>>) => M

Added in v3.4.0

fromNullable

Takes a nullable value, if the value is not nully, turn it into a Success<A>, otherwise Initial.

Signature

export declare const fromNullable: <E, A>(a: A | null | undefined) => D.Datum<Either<E, A>>

Added in v2.4.0

fromOption

Signature

export declare const fromOption: <E, A>(onNone: Lazy<E>) => (o: Option<A>) => D.Datum<Either<E, A>>

Added in v2.2.0

getApplySemigroup

Signature

export declare const getApplySemigroup: <E, A>(S: Semigroup<Either<E, A>>) => Semigroup<D.Datum<Either<E, A>>>

Added in v4.0.0

getMonoid

Signature

export declare const getMonoid: <E, A>(S: Semigroup<Either<E, A>>) => Monoid<D.Datum<Either<E, A>>>

Added in v4.0.0

getSemigroup

Signature

export declare const getSemigroup: <E, A>(S: Semigroup<Either<E, A>>) => Semigroup<D.Datum<Either<E, A>>>

Added in v4.0.0

initial

Signature

export declare const initial: D.Datum<Either<never, never>>

Added in v2.4.1

isFailure

Signature

export declare const isFailure: <E, A>(fea: D.Datum<Either<E, A>>) => fea is Valued<Left<E>>

Added in v2.1.0

isInitial

Signature

export declare const isInitial: <A>(ma: D.Datum<A>) => ma is D.Initial

Added in v2.7.0

isPending

Signature

export declare const isPending: <A>(ma: D.Datum<A>) => ma is D.Pending

Added in v2.7.0

isRefresh

Signature

export declare const isRefresh: <A>(ma: D.Datum<A>) => ma is D.Refresh<A>

Added in v2.7.0

isRefreshLeft

Signature

export declare const isRefreshLeft: <E, A>(fea: D.Datum<Either<E, A>>) => fea is D.Refresh<Left<E>>

Added in v2.7.0

isRefreshRight

Signature

export declare const isRefreshRight: <E, A>(fea: D.Datum<Either<E, A>>) => fea is D.Refresh<Right<A>>

Added in v2.7.0

isReplete

Signature

export declare const isReplete: <A>(ma: D.Datum<A>) => ma is D.Replete<A>

Added in v2.7.0

isRepleteLeft

Signature

export declare const isRepleteLeft: <E, A>(fea: D.Datum<Either<E, A>>) => fea is D.Replete<Left<E>>

Added in v2.7.0

isRepleteRight

Signature

export declare const isRepleteRight: <E, A>(fea: D.Datum<Either<E, A>>) => fea is D.Replete<Right<A>>

Added in v2.7.0

isSuccess

Signature

export declare const isSuccess: <E, A>(fea: D.Datum<Either<E, A>>) => fea is Valued<Right<A>>

Added in v2.1.0

isValued

Signature

export declare const isValued: <A>(ma: D.Datum<A>) => ma is D.Refresh<A> | D.Replete<A>

Added in v2.7.0

map

Signature

export declare const map: <A, B>(f: (a: A) => B) => <E>(fa: D.Datum<Either<E, A>>) => D.Datum<Either<E, B>>

Added in v2.0.0

mapLeft

Signature

export declare const mapLeft: <E, G>(f: (e: E) => G) => <A>(fa: D.Datum<Either<E, A>>) => D.Datum<Either<G, A>>

Added in v2.0.0

pending

Signature

export declare const pending: D.Datum<Either<never, never>>

Added in v2.4.1

reduce

Signature

export declare const reduce: <A, B>(b: B, f: (b: B, a: A) => B) => <E>(fa: D.Datum<Either<E, A>>) => B

Added in v3.4.0

reduceRight

Signature

export declare const reduceRight: <A, B>(b: B, f: (a: A, b: B) => B) => <E>(fa: D.Datum<Either<E, A>>) => B

Added in v3.4.0

refreshFold

Signature

export declare const refreshFold: <E, A, B>(
  onInitial: () => B,
  onPending: () => B,
  onFailure: (e: E, r?: boolean | undefined) => B,
  onSuccess: (a: A, r?: boolean | undefined) => B
) => (fea: D.Datum<Either<E, A>>) => B

Added in v2.1.0

sequenceStruct

Signature

export declare const sequenceStruct: <E, NER>(
  r: (keyof NER extends never ? never : NER) & Record<string, D.Datum<Either<E, any>>>
) => D.Datum<Either<E, { [K in keyof NER]: [NER[K]] extends [D.Datum<Either<any, infer A>>] ? A : never }>>

Added in v4.0.0

sequenceTuple

Signature

export declare const sequenceTuple: <E, T>(
  ...t: T & { readonly 0: D.Datum<Either<E, any>> }
) => D.Datum<Either<E, { [K in keyof T]: [T[K]] extends [D.Datum<Either<E, infer A>>] ? A : never }>>

Added in v4.0.0

squash

Signature

export declare const squash: <E, A, B>(
  onNone: (r?: boolean | undefined) => B,
  onFailure: (e: E, r?: boolean | undefined) => B,
  onSuccess: (a: A, r?: boolean | undefined) => B
) => (fea: D.Datum<Either<E, A>>) => B

Added in v2.3.0

success

Signature

export declare const success: <E = never, A = never>(a: A) => D.Datum<Either<E, A>>

Added in v2.1.0

successR

Signature

export declare const successR: <E = never, A = never>(a: A) => D.Datum<Either<E, A>>

Added in v3.4.0

toRefresh

Signature

export declare const toRefresh: <E, A>(fea: D.Datum<Either<E, A>>) => D.Datum<Either<E, A>>

Added in v2.1.0

toReplete

Signature

export declare const toReplete: <E, A>(fea: D.Datum<Either<E, A>>) => D.Datum<Either<E, A>>

Added in v2.7.0

fromEither2

fromEither2 will replace fromEither in the next major release

Signature

export declare const fromEither2: <E, A>(e: Either<E, A>) => D.Datum<Either<E, A>>

Added in v3.4.0

fromEither

fromEither will remove the Lazy input in the next major release

Signature

export declare const fromEither: <E, A>(e: Lazy<Either<E, A>>) => D.Datum<Either<E, A>>

Added in v2.2.0