title | nav_order | parent |
---|---|---|
IOEither.ts |
52 |
Modules |
IOEither<E, A>
represents a synchronous computation that either yields a value of type A
or fails yielding an
error of type E
. If you want to represent a synchronous computation that never fails, please see IO
.
Added in v2.0.0
- Alt
- Apply
- Bifunctor
- Functor
- Monad
- MonadThrow
- Pointed
- combinators
- apFirst
- apFirstW
- apSecond
- apSecondW
- chainEitherK
- chainEitherKW
- chainFirst
- chainFirstEitherK
- chainFirstEitherKW
- chainFirstIOK
- chainFirstW
- chainIOK
- chainOptionK
- filterOrElse
- filterOrElseW
- flap
- flatten
- flattenW
- fromEitherK
- fromIOK
- fromOptionK
- orElse
- orElseFirst
- orElseFirstIOK
- orElseFirstW
- orElseW
- orLeft
- swap
- constructors
- destructors
- instances
- interop
- model
- natural transformations
- utils
Identifies an associative operation on a type constructor. It is similar to Semigroup
, except that it applies to
types of kind * -> *
.
Signature
export declare const alt: <E, A>(that: Lazy<IOEither<E, A>>) => (fa: IOEither<E, A>) => IOEither<E, A>
Added in v2.0.0
Less strict version of alt
.
Signature
export declare const altW: <E2, B>(that: Lazy<IOEither<E2, B>>) => <E1, A>(fa: IOEither<E1, A>) => IOEither<E2, B | A>
Added in v2.9.0
Apply a function to an argument under a type constructor.
Signature
export declare const ap: <E, A>(fa: IOEither<E, A>) => <B>(fab: IOEither<E, (a: A) => B>) => IOEither<E, B>
Added in v2.0.0
Less strict version of ap
.
Signature
export declare const apW: <E2, A>(
fa: IOEither<E2, A>
) => <E1, B>(fab: IOEither<E1, (a: A) => B>) => IOEither<E2 | E1, B>
Added in v2.8.0
Map a pair of functions over the two type arguments of the bifunctor.
Signature
export declare const bimap: <E, G, A, B>(f: (e: E) => G, g: (a: A) => B) => (fa: IOEither<E, A>) => IOEither<G, B>
Added in v2.0.0
Map a function over the first type argument of a bifunctor.
Signature
export declare const mapLeft: <E, G>(f: (e: E) => G) => <A>(fa: IOEither<E, A>) => IOEither<G, A>
Added in v2.0.0
map
can be used to turn functions (a: A) => B
into functions (fa: F<A>) => F<B>
whose argument and return types
use the type constructor F
to represent some computational context.
Signature
export declare const map: <A, B>(f: (a: A) => B) => <E>(fa: IOEither<E, A>) => IOEither<E, B>
Added in v2.0.0
Composes computations in sequence, using the return value of one computation to determine the next computation.
Signature
export declare const chain: <E, A, B>(f: (a: A) => IOEither<E, B>) => (ma: IOEither<E, A>) => IOEither<E, B>
Added in v2.0.0
Less strict version of chain
.
Signature
export declare const chainW: <E2, A, B>(
f: (a: A) => IOEither<E2, B>
) => <E1>(ma: IOEither<E1, A>) => IOEither<E2 | E1, B>
Added in v2.6.0
Signature
export declare const throwError: <E, A>(e: E) => IOEither<E, A>
Added in v2.7.0
Signature
export declare const of: <E = never, A = never>(a: A) => IOEither<E, A>
Added in v2.8.5
Combine two effectful actions, keeping only the result of the first.
Derivable from Apply
.
Signature
export declare const apFirst: <E, B>(second: IOEither<E, B>) => <A>(first: IOEither<E, A>) => IOEither<E, A>
Added in v2.0.0
Less strict version of apFirst
.
Signature
export declare const apFirstW: <E2, A, B>(
second: IOEither<E2, B>
) => <E1>(first: IOEither<E1, A>) => IOEither<E2 | E1, A>
Added in v2.12.0
Combine two effectful actions, keeping only the result of the second.
Derivable from Apply
.
Signature
export declare const apSecond: <E, B>(second: IOEither<E, B>) => <A>(first: IOEither<E, A>) => IOEither<E, B>
Added in v2.0.0
Less strict version of apSecond
.
Signature
export declare const apSecondW: <E2, A, B>(
second: IOEither<E2, B>
) => <E1>(first: IOEither<E1, A>) => IOEither<E2 | E1, B>
Added in v2.12.0
Signature
export declare const chainEitherK: <E, A, B>(f: (a: A) => E.Either<E, B>) => (ma: IOEither<E, A>) => IOEither<E, B>
Added in v2.4.0
Less strict version of chainEitherK
.
Signature
export declare const chainEitherKW: <E2, A, B>(
f: (a: A) => E.Either<E2, B>
) => <E1>(ma: IOEither<E1, A>) => IOEither<E2 | E1, B>
Added in v2.6.1
Composes computations in sequence, using the return value of one computation to determine the next computation and keeping only the result of the first.
Derivable from Chain
.
Signature
export declare const chainFirst: <E, A, B>(f: (a: A) => IOEither<E, B>) => (ma: IOEither<E, A>) => IOEither<E, A>
Added in v2.0.0
Signature
export declare const chainFirstEitherK: <A, E, B>(f: (a: A) => E.Either<E, B>) => (ma: IOEither<E, A>) => IOEither<E, A>
Added in v2.12.0
Signature
export declare const chainFirstEitherKW: <A, E2, B>(
f: (a: A) => E.Either<E2, B>
) => <E1>(ma: IOEither<E1, A>) => IOEither<E2 | E1, A>
Added in v2.12.0
Signature
export declare const chainFirstIOK: <A, B>(f: (a: A) => I.IO<B>) => <E>(first: IOEither<E, A>) => IOEither<E, A>
Added in v2.10.0
Less strict version of chainFirst
.
Derivable from Chain
.
Signature
export declare const chainFirstW: <E2, A, B>(
f: (a: A) => IOEither<E2, B>
) => <E1>(ma: IOEither<E1, A>) => IOEither<E2 | E1, A>
Added in v2.8.0
Signature
export declare const chainIOK: <A, B>(f: (a: A) => I.IO<B>) => <E>(first: IOEither<E, A>) => IOEither<E, B>
Added in v2.10.0
Signature
export declare const chainOptionK: <E>(
onNone: Lazy<E>
) => <A, B>(f: (a: A) => Option<B>) => (ma: IOEither<E, A>) => IOEither<E, B>
Added in v2.10.0
Signature
export declare const filterOrElse: {
<E, A, B extends A>(refinement: Refinement<A, B>, onFalse: (a: A) => E): (ma: IOEither<E, A>) => IOEither<E, B>
<E, A>(predicate: Predicate<A>, onFalse: (a: A) => E): <B extends A>(mb: IOEither<E, B>) => IOEither<E, B>
<E, A>(predicate: Predicate<A>, onFalse: (a: A) => E): (ma: IOEither<E, A>) => IOEither<E, A>
}
Added in v2.0.0
Less strict version of filterOrElse
.
Signature
export declare const filterOrElseW: {
<A, B extends A, E2>(refinement: Refinement<A, B>, onFalse: (a: A) => E2): <E1>(
ma: IOEither<E1, A>
) => IOEither<E2 | E1, B>
<A, E2>(predicate: Predicate<A>, onFalse: (a: A) => E2): <E1, B extends A>(
mb: IOEither<E1, B>
) => IOEither<E2 | E1, B>
<A, E2>(predicate: Predicate<A>, onFalse: (a: A) => E2): <E1>(ma: IOEither<E1, A>) => IOEither<E2 | E1, A>
}
Added in v2.9.0
Derivable from Functor
.
Signature
export declare const flap: <A>(a: A) => <E, B>(fab: IOEither<E, (a: A) => B>) => IOEither<E, B>
Added in v2.10.0
Derivable from Chain
.
Signature
export declare const flatten: <E, A>(mma: IOEither<E, IOEither<E, A>>) => IOEither<E, A>
Added in v2.0.0
Less strict version of flatten
.
Signature
export declare const flattenW: <E1, E2, A>(mma: IOEither<E1, IOEither<E2, A>>) => IOEither<E1 | E2, A>
Added in v2.11.0
Signature
export declare const fromEitherK: <E, A extends readonly unknown[], B>(
f: (...a: A) => E.Either<E, B>
) => (...a: A) => IOEither<E, B>
Added in v2.4.0
Signature
export declare const fromIOK: <A, B>(f: (...a: A) => I.IO<B>) => <E>(...a: A) => IOEither<E, B>
Added in v2.10.0
Signature
export declare const fromOptionK: <E>(
onNone: Lazy<E>
) => <A, B>(f: (...a: A) => Option<B>) => (...a: A) => IOEither<E, B>
Added in v2.10.0
Signature
export declare const orElse: <E1, A, E2>(onLeft: (e: E1) => IOEither<E2, A>) => (ma: IOEither<E1, A>) => IOEither<E2, A>
Added in v2.0.0
Signature
export declare const orElseFirst: <E, B>(onLeft: (e: E) => IOEither<E, B>) => <A>(ma: IOEither<E, A>) => IOEither<E, A>
Added in v2.11.0
Signature
export declare const orElseFirstIOK: <E, B>(onLeft: (e: E) => I.IO<B>) => <A>(ma: IOEither<E, A>) => IOEither<E, A>
Added in v2.12.0
Signature
export declare const orElseFirstW: <E1, E2, B>(
onLeft: (e: E1) => IOEither<E2, B>
) => <A>(ma: IOEither<E1, A>) => IOEither<E1 | E2, A>
Added in v2.11.0
Less strict version of orElse
.
Signature
export declare const orElseW: <E1, E2, B>(
onLeft: (e: E1) => IOEither<E2, B>
) => <A>(ma: IOEither<E1, A>) => IOEither<E2, B | A>
Added in v2.10.0
Signature
export declare const orLeft: <E1, E2>(onLeft: (e: E1) => I.IO<E2>) => <A>(fa: IOEither<E1, A>) => IOEither<E2, A>
Added in v2.11.0
Signature
export declare const swap: <E, A>(ma: IOEither<E, A>) => IOEither<A, E>
Added in v2.0.0
Signature
export declare const fromPredicate: {
<E, A, B extends A>(refinement: Refinement<A, B>, onFalse: (a: A) => E): (a: A) => IOEither<E, B>
<E, A>(predicate: Predicate<A>, onFalse: (a: A) => E): <B extends A>(b: B) => IOEither<E, B>
<E, A>(predicate: Predicate<A>, onFalse: (a: A) => E): (a: A) => IOEither<E, A>
}
Added in v2.0.0
Signature
export declare const left: <E = never, A = never>(l: E) => IOEither<E, A>
Added in v2.0.0
Signature
export declare const leftIO: <E = never, A = never>(me: I.IO<E>) => IOEither<E, A>
Added in v2.0.0
Signature
export declare const right: <E = never, A = never>(a: A) => IOEither<E, A>
Added in v2.0.0
Signature
export declare const rightIO: <E = never, A = never>(ma: I.IO<A>) => IOEither<E, A>
Added in v2.0.0
Alias of matchE
.
Signature
export declare const fold: <E, A, B>(
onLeft: (e: E) => I.IO<B>,
onRight: (a: A) => I.IO<B>
) => (ma: IOEither<E, A>) => I.IO<B>
Added in v2.0.0
Alias of matchEW
.
Signature
export declare const foldW: <E, B, A, C>(
onLeft: (e: E) => I.IO<B>,
onRight: (a: A) => I.IO<C>
) => (ma: IOEither<E, A>) => I.IO<B | C>
Added in v2.10.0
Signature
export declare const getOrElse: <E, A>(onLeft: (e: E) => I.IO<A>) => (ma: IOEither<E, A>) => I.IO<A>
Added in v2.0.0
Less strict version of getOrElse
.
Signature
export declare const getOrElseW: <E, B>(onLeft: (e: E) => I.IO<B>) => <A>(ma: IOEither<E, A>) => I.IO<B | A>
Added in v2.6.0
Signature
export declare const match: <E, B, A>(onLeft: (e: E) => B, onRight: (a: A) => B) => (ma: IOEither<E, A>) => I.IO<B>
Added in v2.10.0
Signature
export declare const matchE: <E, A, B>(
onLeft: (e: E) => I.IO<B>,
onRight: (a: A) => I.IO<B>
) => (ma: IOEither<E, A>) => I.IO<B>
Added in v2.10.0
Less strict version of matchE
.
Signature
export declare const matchEW: <E, B, A, C>(
onLeft: (e: E) => I.IO<B>,
onRight: (a: A) => I.IO<C>
) => (ma: IOEither<E, A>) => I.IO<B | C>
Added in v2.10.0
Less strict version of match
.
Signature
export declare const matchW: <E, B, A, C>(
onLeft: (e: E) => B,
onRight: (a: A) => C
) => (ma: IOEither<E, A>) => I.IO<B | C>
Added in v2.10.0
Signature
export declare const Alt: Alt2<'IOEither'>
Added in v2.7.0
Signature
export declare const ApplicativePar: Applicative2<'IOEither'>
Added in v2.8.4
Signature
export declare const ApplicativeSeq: Applicative2<'IOEither'>
Added in v2.8.4
Signature
export declare const ApplyPar: Apply2<'IOEither'>
Added in v2.10.0
Signature
export declare const Bifunctor: Bifunctor2<'IOEither'>
Added in v2.7.0
Signature
export declare const Chain: Chain2<'IOEither'>
Added in v2.10.0
Signature
export declare const FromEither: FromEither2<'IOEither'>
Added in v2.10.0
Signature
export declare const FromIO: FromIO2<'IOEither'>
Added in v2.10.0
Signature
export declare const Functor: Functor2<'IOEither'>
Added in v2.7.0
Signature
export declare const Monad: Monad2<'IOEither'>
Added in v2.7.0
Signature
export declare const MonadIO: MonadIO2<'IOEither'>
Added in v2.7.0
Signature
export declare const MonadThrow: MonadThrow2<'IOEither'>
Added in v2.7.0
Signature
export declare const Pointed: Pointed2<'IOEither'>
Added in v2.10.0
Signature
export declare const URI: 'IOEither'
Added in v2.0.0
Signature
export type URI = typeof URI
Added in v2.0.0
Signature
export declare function getAltIOValidation<E>(S: Semigroup<E>): Alt2C<URI, E>
Added in v2.7.0
Signature
export declare function getApplicativeIOValidation<E>(S: Semigroup<E>): Applicative2C<URI, E>
Added in v2.7.0
Signature
export declare const getCompactable: <E>(M: Monoid<E>) => Compactable2C<'IOEither', E>
Added in v2.10.0
Signature
export declare function getFilterable<E>(M: Monoid<E>): Filterable2C<URI, E>
Added in v2.1.0
Use ApplicativePar
instead
Signature
export declare const Applicative: Applicative2<'IOEither'>
Added in v2.7.0
Use getApplicativeMonoid
instead.
Signature
export declare const getApplyMonoid: <E, A>(M: Monoid<A>) => Monoid<IOEither<E, A>>
Added in v2.0.0
Use getApplySemigroup
instead.
Signature
export declare const getApplySemigroup: <E, A>(S: Semigroup<A>) => Semigroup<IOEither<E, A>>
Added in v2.0.0
Use getApplicativeIOValidation
and getAltIOValidation
.
Signature
export declare function getIOValidation<E>(
SE: Semigroup<E>
): Monad2C<URI, E> & Bifunctor2<URI> & Alt2C<URI, E> & MonadIO2C<URI, E> & MonadThrow2C<URI, E>
Added in v2.0.0
Use getApplySemigroup
instead.
Signature
export declare const getSemigroup: <E, A>(S: Semigroup<A>) => Semigroup<IOEither<E, A>>
Added in v2.0.0
Use small, specific instances instead.
Signature
export declare const ioEither: Monad2<'IOEither'> &
Bifunctor2<'IOEither'> &
Alt2<'IOEither'> &
MonadIO2<'IOEither'> &
MonadThrow2<'IOEither'>
Added in v2.0.0
Signature
export declare const toUnion: <E, A>(fa: IOEither<E, A>) => I.IO<E | A>
Added in v2.10.0
Constructs a new IOEither
from a function that performs a side effect and might throw
See also tryCatchK
.
Signature
export declare const tryCatch: <E, A>(f: Lazy<A>, onThrow: (reason: unknown) => E) => IOEither<E, A>
Added in v2.0.0
Converts a function that may throw to one returning a IOEither
.
Signature
export declare const tryCatchK: <A extends readonly unknown[], B, E>(
f: (...a: A) => B,
onThrow: (reason: unknown) => E
) => (...a: A) => IOEither<E, B>
Added in v2.10.0
Signature
export interface IOEither<E, A> extends IO<Either<E, A>> {}
Added in v2.0.0
Signature
export declare const fromEither: NaturalTransformation22<'Either', 'IOEither'>
Added in v2.0.0
Signature
export declare const fromIO: NaturalTransformation12<'IO', 'IOEither'>
Added in v2.7.0
Signature
export declare const fromOption: <E>(onNone: Lazy<E>) => NaturalTransformation12C<'Option', 'IOEither', E>
Added in v2.0.0
Signature
export declare const ApT: IOEither<never, readonly []>
Added in v2.11.0
Signature
export declare const Do: IOEither<never, {}>
Added in v2.9.0
Signature
export declare const apS: <N, A, E, B>(
name: Exclude<N, keyof A>,
fb: IOEither<E, B>
) => (fa: IOEither<E, A>) => IOEither<E, { readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
Added in v2.8.0
Signature
export declare const apSW: <A, N extends string, E2, B>(
name: Exclude<N, keyof A>,
fb: IOEither<E2, B>
) => <E1>(fa: IOEither<E1, A>) => IOEither<E2 | E1, { readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
Added in v2.8.0
Signature
export declare const bind: <N, A, E, B>(
name: Exclude<N, keyof A>,
f: (a: A) => IOEither<E, B>
) => (ma: IOEither<E, A>) => IOEither<E, { readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
Added in v2.8.0
Signature
export declare const bindTo: <N>(name: N) => <E, A>(fa: IOEither<E, A>) => IOEither<E, { readonly [K in N]: A }>
Added in v2.8.0
Signature
export declare const bindW: <N extends string, A, E2, B>(
name: Exclude<N, keyof A>,
f: (a: A) => IOEither<E2, B>
) => <E1>(fa: IOEither<E1, A>) => IOEither<E2 | E1, { readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
Added in v2.8.0
Make sure that a resource is cleaned up in the event of an exception (*). The release action is called regardless of whether the body action throws (*) or returns.
(*) i.e. returns a Left
Signature
export declare const bracket: <E, A, B>(
acquire: IOEither<E, A>,
use: (a: A) => IOEither<E, B>,
release: (a: A, e: E.Either<E, B>) => IOEither<E, void>
) => IOEither<E, B>
Added in v2.0.0
Signature
export declare const sequenceArray: <E, A>(arr: readonly IOEither<E, A>[]) => IOEither<E, readonly A[]>
Added in v2.9.0
Signature
export declare const sequenceSeqArray: <E, A>(arr: readonly IOEither<E, A>[]) => IOEither<E, readonly A[]>
Added in v2.9.0
Signature
export declare const traverseArray: <A, E, B>(
f: (a: A) => IOEither<E, B>
) => (as: readonly A[]) => IOEither<E, readonly B[]>
Added in v2.9.0
Signature
export declare const traverseArrayWithIndex: <A, E, B>(
f: (index: number, a: A) => IOEither<E, B>
) => (as: readonly A[]) => IOEither<E, readonly B[]>
Added in v2.9.0
Equivalent to ReadonlyArray#traverseWithIndex(ApplicativePar)
.
Signature
export declare const traverseReadonlyArrayWithIndex: <A, E, B>(
f: (index: number, a: A) => IOEither<E, B>
) => (as: readonly A[]) => IOEither<E, readonly B[]>
Added in v2.11.0
Equivalent to ReadonlyArray#traverseWithIndex(ApplicativeSeq)
.
Signature
export declare const traverseReadonlyArrayWithIndexSeq: <A, E, B>(
f: (index: number, a: A) => IOEither<E, B>
) => (as: readonly A[]) => IOEither<E, readonly B[]>
Added in v2.11.0
Equivalent to ReadonlyNonEmptyArray#traverseWithIndex(ApplicativePar)
.
Signature
export declare const traverseReadonlyNonEmptyArrayWithIndex: <A, E, B>(
f: (index: number, a: A) => IOEither<E, B>
) => (as: ReadonlyNonEmptyArray<A>) => IOEither<E, ReadonlyNonEmptyArray<B>>
Added in v2.11.0
Equivalent to ReadonlyNonEmptyArray#traverseWithIndex(ApplicativeSeq)
.
Signature
export declare const traverseReadonlyNonEmptyArrayWithIndexSeq: <A, E, B>(
f: (index: number, a: A) => IOEither<E, B>
) => (as: ReadonlyNonEmptyArray<A>) => IOEither<E, ReadonlyNonEmptyArray<B>>
Added in v2.11.0
Signature
export declare const traverseSeqArray: <A, E, B>(
f: (a: A) => IOEither<E, B>
) => (as: readonly A[]) => IOEither<E, readonly B[]>
Added in v2.9.0
Signature
export declare const traverseSeqArrayWithIndex: <A, E, B>(
f: (index: number, a: A) => IOEither<E, B>
) => (as: readonly A[]) => IOEither<E, readonly B[]>
Added in v2.9.0