Link Search Menu Expand Document

Computation overview

A Computation is a way to chain consecutive operations while collecting logs. It’s useful for guarding against unwanted input conditions, and is used in this libary for matrix decomposition.

Added in v1.0.0


Table of contents


Combinators

apFirst

Signature

export declare const apFirst: <E, B>(second: Computation<E, B>) => <A>(first: Computation<E, A>) => Computation<E, A>

Added in v1.0.0

apSecond

Signature

export declare const apSecond: <E, B>(second: Computation<E, B>) => <A>(first: Computation<E, A>) => Computation<E, B>

Added in v1.0.0

chainEitherK

Signature

export declare const chainEitherK: <A, E, B>(
  f: (a: A) => E.Either<E, B>
) => (ma: Computation<E, A>) => Computation<E, B>

Added in v1.0.0

chainFirst

Signature

export declare const chainFirst: <A, E, B>(
  f: (a: A) => Computation<E, B>
) => (first: Computation<E, A>) => Computation<E, A>

Added in v1.0.0

chainOptionK

Signature

export declare const chainOptionK: <E>(
  onNone: Lazy<E>
) => <A, B>(f: (a: A) => O.Option<B>) => (ma: Computation<E, A>) => Computation<E, B>

Added in v1.0.0

Constructors

of

Signature

export declare const of: <A>(value: A) => Computation<never, A>

Added in v1.0.0

Destructors

getOrThrow

Signature

export declare const getOrThrow: <E>(onError: (e: E) => string) => <A>(c: Computation<E, A>) => A

Added in v1.1.0

getOrThrowS

Signature

export declare const getOrThrowS: <A>(c: Computation<string, A>) => A

Added in v1.1.0

runComputation

Signature

export declare const runComputation: <E, A>(c: Computation<E, A>) => E.Either<E, A>

Added in v1.1.0

runLogs

Signature

export declare const runLogs: <E, O>(f: (e: E) => IO.IO<O>) => <A>(c: Computation<E, A>) => IO.IO<readonly O[]>

Added in v1.1.0

Do Notation

Do

Signature

export declare const Do: Computation<never, {}>

Added in v1.0.0

apS

Signature

export declare const apS: <N, A, E, B>(
  name: Exclude<N, keyof A>,
  fb: Computation<E, B>
) => (fa: Computation<E, A>) => Computation<E, { readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>

Added in v1.0.0

bind

Signature

export declare const bind: <N, A, E, B>(
  name: Exclude<N, keyof A>,
  f: (a: A) => Computation<E, B>
) => (ma: Computation<E, A>) => Computation<E, { readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>

Added in v1.0.0

bindTo

Signature

export declare const bindTo: <N>(name: N) => <E, A>(fa: Computation<E, A>) => Computation<E, { readonly [K in N]: A }>

Added in v1.0.0

bindW

Signature

export declare const bindW: <N extends string, A, E2, B>(
  name: Exclude<N, keyof A>,
  f: (a: A) => Computation<E2, B>
) => <E1>(fa: Computation<E1, A>) => Computation<E2 | E1, { readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>

Added in v1.0.0

Instance Operations

Apply

Signature

export declare const Apply: Ap.Apply2<'Computation'>

Added in v1.0.0

ap

Signature

export declare const ap: <E, A, B>(fab: Computation<E, (a: A) => B>) => (fa: Computation<E, A>) => Computation<E, B>

Added in v1.0.0

bimap

Signature

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

Added in v1.0.0

chain

Signature

export declare const chain: <E, A, B>(f: (a: A) => Computation<E, B>) => (fa: Computation<E, A>) => Computation<E, B>

Added in v1.0.0

chainW

Signature

export declare const chainW: <E1, E2, A, B>(
  f: (a: A) => Computation<E1, B>
) => ([fa, logs]: Computation<E2, A>) => Computation<E1 | E2, B>

Added in v1.0.0

fromEither

Signature

export declare const fromEither: NaturalTransformation22<'Either', 'Computation'>

Added in v1.0.0

map

Signature

export declare const map: <A, B>(f: (a: A) => B) => <E>(fa: Computation<E, A>) => Computation<E, B>

Added in v1.0.0

mapLeft

Signature

export declare const mapLeft: <E, G>(f: (e: E) => G) => <A>(fa: Computation<E, A>) => Computation<G, A>

Added in v1.0.0

throwError

Signature

export declare const throwError: <E>(e: E) => Computation<E, never>

Added in v1.0.0

Instances

Applicative

Signature

export declare const Applicative: Apl.Applicative2<'Computation'>

Added in v1.0.0

Bifunctor

Signature

export declare const Bifunctor: BiFun.Bifunctor2<'Computation'>

Added in v1.0.0

Chain

Signature

export declare const Chain: Chn.Chain2<'Computation'>

Added in v1.0.0

FromEither

Signature

export declare const FromEither: FE.FromEither2<'Computation'>

Added in v1.0.0

Functor

Signature

export declare const Functor: Fun.Functor2<'Computation'>

Added in v1.0.0

Monad

Signature

export declare const Monad: Mon.Monad2<'Computation'>

Added in v1.0.0

MonadThrow

Signature

export declare const MonadThrow: MonThrow.MonadThrow2<'Computation'>

Added in v1.0.0

URI

Signature

export declare const URI: 'Computation'

Added in v1.0.0

URI (type alias)

Signature

export type URI = typeof URI

Added in v1.0.0

Model

Computation (type alias)

Signature

export type Computation<E, A> = readonly [E.Either<E, A>, ReadonlyArray<E>]

Added in v1.0.0

Natural Transformations

fromOption

Signature

export declare const fromOption: <E>(onNone: Lazy<E>) => NaturalTransformation12C<'Option', 'Computation', E>

Added in v1.0.0

fromPredicate

Signature

export declare const fromPredicate: {
  <A, B, E>(refinement: Refinement<A, B>, onFalse: (a: A) => E): (a: A) => Computation<E, B>
  <A, E>(predicate: Predicate<A>, onFalse: (a: A) => E): <B>(b: B) => Computation<E, B>
  <A, E>(predicate: Predicate<A>, onFalse: (a: A) => E): (a: A) => Computation<E, A>
}

Added in v1.1.0

toOption

Signature

export declare const toOption: <E, A>(c: Computation<E, A>) => O.Option<A>

Added in v1.1.0

Refinements

isLeft

Signature

export declare const isLeft: <E, A>(e: Computation<E, A>) => e is readonly [E.Left<E>, readonly E[]]

Added in v1.0.0

isRight

Signature

export declare const isRight: <E, A>(e: Computation<E, A>) => e is readonly [E.Right<A>, readonly E[]]

Added in v1.0.0

Utilities

bilog

Log one message on left, and a different on right

Signature

export declare const bilog: <E>(onLeft: () => E, onRight: () => E) => <A>(fa: Computation<E, A>) => Computation<E, A>

Added in v1.1.0

filter

Signature

export declare const filter: <E, A>(
  predicate: (a: A) => boolean,
  onFalse: (a: A) => E
) => (fa: Computation<E, A>) => Computation<E, A>

Added in v1.0.0

filterOptionK

Signature

export declare const filterOptionK: <E, A, B>(
  test: (a: A) => O.Option<B>,
  onFalse: (a: A) => E
) => (a: A) => Computation<E, B>

Added in v1.0.0

log

Signature

export declare const log: <E>(message: E) => <A>(fa: Computation<E, A>) => Computation<E, A>

Added in v1.0.0

logOption

Signature

export declare const logOption: <E, A>(
  getOptionalMesasge: (a: A) => O.Option<E>
) => (fa: Computation<E, A>) => Computation<E, A>

Added in v1.0.0

tell

Signature

export declare const tell: <E>(message: E) => Computation<E, void>

Added in v1.0.0