// ets_tracing: off import "../../Operator/index.js" import { RuntimeError } from "../../Cause/index.js" import * as T from "../../Effect/index.js" import * as E from "../../Either/index.js" import type { Predicate, Refinement } from "../../Function/index.js" import { constVoid, identity } from "../../Function/index.js" import { NoSuchElementException } from "../../GlobalExceptions/index.js" import * as O from "../../Option/index.js" import { AtomicBoolean } from "../../Support/AtomicBoolean/index.js" import * as P from "./_internal/primitives.js" import { tryCommit, tryCommitAsync } from "./Journal/index.js" import { DoneTypeId, SuspendTypeId } from "./TryCommit/index.js" import { makeTxnId } from "./TxnId/index.js" export { catchAll, catchAll_, chain, chain_, ensuring, ensuring_, fail, failWith, foldM, foldM_, map, map_, provideSome, provideSome_, retry, STM, STMEffect, STMFailException, STMRetryException, succeed, succeedWith, unit, die, dieWith } from "./_internal/primitives.js" export { _catch as catch } export const MaxFrames = 200 /** * Accesses the environment of the transaction. */ export function access(f: (r: R) => A): P.STM { return P.map_(environment(), f) } /** * Accesses the environment of the transaction to perform a transaction. */ export function accessM(f: (r: R0) => P.STM) { return P.chain_(environment(), f) } /** * Submerges the error case of an `Either` into the `STM`. The inverse * operation of `STM.either`. */ export function absolve( z: P.STM> ): P.STM { return P.chain_(z, fromEither) } /** * Propagates the given environment to self. */ export function andThen_( self: P.STM, that: P.STM ): P.STM { return P.chain_(self, (a) => provideAll_(that, a)) } /** * Propagates the given environment to self. * * @ets_data_first andThen_ */ export function andThen( that: P.STM ): (self: P.STM) => P.STM { return (self) => andThen_(self, that) } /** * Maps the success value of this effect to the specified constant value. */ export function as_(self: P.STM, b: B): P.STM { return P.map_(self, () => b) } /** * Maps the success value of this effect to the specified constant value. * * @ets_data_first as_ */ export function as(b: B): (self: P.STM) => P.STM { return (self) => as_(self, b) } /** * Maps the success value of this effect to an optional value. */ export function asSome(self: P.STM): P.STM> { return P.map_(self, O.some) } /** * Maps the error value of this effect to an optional value. */ export function asSomeError(self: P.STM): P.STM, A> { return mapError_(self, O.some) } /** * Returns an `STM` effect whose P.failure and success channels have been mapped by * the specified pair of functions, `f` and `g`. */ export function bimap_( self: P.STM, g: (e: E) => E1, f: (a: A) => B ): P.STM { return P.foldM_( self, (e) => P.fail(g(e)), (a) => P.succeed(f(a)) ) } /** * Returns an `STM` effect whose P.failure and success channels have been mapped by * the specified pair of functions, `f` and `g`. * * @ets_data_first bimap_ */ export function bimap( g: (e: E) => E1, f: (a: A) => B ): (self: P.STM) => P.STM { return (self) => bimap_(self, g, f) } /** * Recovers from specified error. * * @ets_data_first catch_ */ function _catch( tag: N, k: K, f: (e: Extract) => P.STM, __trace?: string ) { return ( self: P.STM ): P.STM | E1, A | A1> => P.catchAll_(self, (e) => { if (typeof e === "object" && e !== null && tag in e && e[tag] === k) { return f(e as any) } return P.fail(e as any) }) } /** * Recovers from specified error. */ export function catch_( self: P.STM, tag: N, k: K, f: (e: Extract) => P.STM ): P.STM | E1, A | A1> { return P.catchAll_(self, (e) => { if (typeof e === "object" && e !== null && tag in e && e[tag] === k) { return f(e as any) } return P.fail(e as any) }) } /** * Recovers from specified error. * * @ets_data_first catchTag_ */ export function catchTag< K extends E["_tag"] & string, E extends { _tag: string }, R1, E1, A1 >(k: K, f: (e: Extract) => P.STM, __trace?: string) { return ( self: P.STM ): P.STM | E1, A | A1> => catchTag_(self, k, f) } /** * Recovers from specified error. */ export function catchTag_< K extends E["_tag"] & string, E extends { _tag: string }, R, A, R1, E1, A1 >( self: P.STM, k: K, f: (e: Extract) => P.STM ): P.STM | E1, A | A1> { return P.catchAll_(self, (e) => { if ("_tag" in e && e["_tag"] === k) { return f(e as any) } return P.fail(e as any) }) } /** * Recovers from some or all of the error cases. */ export function catchSome_( self: P.STM, f: (e: E) => O.Option> ): P.STM { return P.catchAll_( self, (e): P.STM => O.fold_(f(e), () => P.fail(e), identity) ) } /** * Recovers from some or all of the error cases. * * @ets_data_first catchSome_ */ export function catchSome( f: (e: E) => O.Option> ): (self: P.STM) => P.STM { return (self) => catchSome_(self, f) } /** * Simultaneously filters and flatMaps the value produced by this effect. * Continues on the effect returned from pf. */ export function continueOrRetryM_( fa: P.STM, pf: (a: A) => O.Option> ): P.STM { return P.chain_(fa, (a): P.STM => O.getOrElse_(pf(a), () => P.retry)) } /** * Simultaneously filters and flatMaps the value produced by this effect. * Continues on the effect returned from pf. * * @ets_data_first continueOrRetryM_ */ export function continueOrRetryM( pf: (a: A) => O.Option> ): (fa: P.STM) => P.STM { return (fa) => continueOrRetryM_(fa, pf) } /** * Fail with `e` if the supplied `PartialFunction` does not match, otherwise * succeed with the returned value. */ export function continueOrRetry_( fa: P.STM, pf: (a: A) => O.Option ) { return continueOrRetryM_(fa, (x) => O.map_(pf(x), P.succeed)) } /** * Fail with `e` if the supplied `PartialFunction` does not match, otherwise * succeed with the returned value. * * @ets_data_first continueOrRetry_ */ export function continueOrRetry(pf: (a: A) => O.Option) { return (fa: P.STM) => continueOrRetry_(fa, pf) } /** * Fail with `e` if the supplied `PartialFunction` does not match, otherwise * continue with the returned value. */ export function continueOrFailM_( fa: P.STM, e: E1, pf: (a: A) => O.Option> ) { return P.chain_( fa, (a): P.STM => O.getOrElse_(pf(a), () => P.fail(e)) ) } /** * Fail with `e` if the supplied `PartialFunction` does not match, otherwise * continue with the returned value. * * @ets_data_first continueOrFailM_ */ export function continueOrFailM( e: E1, pf: (a: A) => O.Option> ) { return (fa: P.STM) => continueOrFailM_(fa, e, pf) } /** * Fail with `e` if the supplied `PartialFunction` does not match, otherwise * succeed with the returned value. */ export function continueOrFail_( fa: P.STM, e: E1, pf: (a: A) => O.Option ) { return continueOrFailM_(fa, e, (x) => O.map_(pf(x), P.succeed)) } /** * Fail with `e` if the supplied `PartialFunction` does not match, otherwise * succeed with the returned value. * * @ets_data_first continueOrFail_ */ export function continueOrFail(e: E1, pf: (a: A) => O.Option) { return (fa: P.STM) => continueOrFail_(fa, e, pf) } /** * Fail with `e` if the supplied `PartialFunction` does not match, otherwise * continue with the returned value. */ export function continueOrFailWithM_( fa: P.STM, e: () => E1, pf: (a: A) => O.Option> ) { return P.chain_( fa, (a): P.STM => O.getOrElse_(pf(a), () => P.failWith(e)) ) } /** * Fail with `e` if the supplied `PartialFunction` does not match, otherwise * continue with the returned value. * * @ets_data_first continueOrFailWithM_ */ export function continueOrFailWithM( e: () => E1, pf: (a: A) => O.Option> ) { return (fa: P.STM) => continueOrFailWithM_(fa, e, pf) } /** * Fail with `e` if the supplied `PartialFunction` does not match, otherwise * succeed with the returned value. */ export function continueOrFailWith_( fa: P.STM, e: () => E1, pf: (a: A) => O.Option ) { return continueOrFailWithM_(fa, e, (x) => O.map_(pf(x), P.succeed)) } /** * Fail with `e` if the supplied `PartialFunction` does not match, otherwise * succeed with the returned value. * * @ets_data_first continueOrFailWith_ */ export function continueOrFailWith(e: () => E1, pf: (a: A) => O.Option) { return (fa: P.STM) => continueOrFailWith_(fa, e, pf) } /** * Creates a composite effect that represents this effect followed by another * one that may depend on the error produced by this one. * * @ets_data_first chainError_ */ export function chainError(f: (e: E) => P.STM) { return (self: P.STM) => chainError_(self, f) } /** * Creates a composite effect that represents this effect followed by another * one that may depend on the error produced by this one. */ export function chainError_( self: P.STM, f: (e: E) => P.STM ) { return flipWith_(self, (x) => P.chain_(x, f)) } /** * Checks the condition, and if it's true, returns unit, otherwise, retries. */ export function checkWith(predicate: () => boolean) { return suspend(() => (predicate() ? P.unit : P.retry)) } /** * Checks the condition, and if it's true, returns unit, otherwise, retries. */ export function check(predicate: boolean) { return checkWith(() => predicate) } /** * Propagates self environment to that. */ export function compose_( self: P.STM, that: P.STM ) { return andThen_(that, self) } /** * Propagates self environment to that. * * @ets_data_first compose_ */ export function compose(that: P.STM) { return (self: P.STM) => andThen_(that, self) } /** * Commits this transaction atomically. */ export function commit(self: P.STM) { return T.accessM((r: R) => T.suspend((_, fiberId) => { const v = tryCommit(fiberId, self, r) switch (v._typeId) { case DoneTypeId: { return v.io } case SuspendTypeId: { const txnId = makeTxnId() const done = new AtomicBoolean(false) const interrupt = T.succeedWith(() => done.set(true)) const io = T.effectAsync( tryCommitAsync(v.journal, fiberId, self, txnId, done, r) ) return T.ensuring_(io, interrupt) } } }) ) } /** * Commits this transaction atomically, regardless of whether the transaction * is a success or a failure. */ export function commitEither(self: P.STM): T.Effect { return T.absolve(commit(either(self))) } /** * Kills the fiber running the effect with a `RuntimeError` that contains * the specified message. */ export function dieMessage(message: string): P.STM { return P.dieWith(() => new RuntimeError(message)) } /** * Kills the fiber running the effect with a `RuntimeError` that contains * the specified message. */ export function dieMessageWith(message: () => string): P.STM { return P.succeedWith(() => { throw new RuntimeError(message()) }) } /** * Converts the failure channel into an `Either`. */ export function either(self: P.STM): P.STM> { return fold_( self, (x) => E.left(x), (x) => E.right(x) ) } /** * Retrieves the environment inside an stm. */ export function environment(): P.STM { return new P.STMEffect((_, __, r: R) => r) } /** * Returns an effect that ignores errors and runs repeatedly until it eventually succeeds. */ export function eventually(self: P.STM): P.STM { return P.foldM_(self, () => eventually(self), P.succeed) } /** * Dies with specified `unknown` if the predicate fails. * * @ets_data_first filterOrDie_ */ export function filterOrDie( p: Refinement, dieWith: (a: Exclude) => unknown ): (fa: P.STM) => P.STM export function filterOrDie( p: Predicate, dieWith: (a: A) => unknown ): (fa: P.STM) => P.STM export function filterOrDie(p: Predicate, dieWith: unknown) { return (fa: P.STM): P.STM => filterOrDie_(fa, p, dieWith as (a: A) => unknown) } /** * Dies with specified `unknown` if the predicate fails. */ export function filterOrDie_( fa: P.STM, p: Refinement, dieWith: (a: Exclude) => unknown ): P.STM export function filterOrDie_( fa: P.STM, p: Predicate, dieWith: (a: A) => unknown ): P.STM export function filterOrDie_( fa: P.STM, p: Predicate, dieWith: unknown ) { return filterOrElse_(fa, p, (x) => P.dieWith(() => (dieWith as (a: A) => unknown)(x))) } /** * Fails with `failWith` if the predicate fails. * * @ets_data_first filterOrFail_ */ export function filterOrFail( p: Refinement, failWith: (a: Exclude) => E1 ): (fa: P.STM) => P.STM export function filterOrFail( p: Predicate, failWith: (a: A) => E1 ): (fa: P.STM) => P.STM export function filterOrFail(p: Predicate, failWith: unknown) { return (fa: P.STM): P.STM => filterOrFail_(fa, p, failWith as (a: A) => E1) } /** * Fails with `failWith` if the predicate fails. */ export function filterOrFail_( fa: P.STM, p: Refinement, failWith: (a: Exclude) => E1 ): P.STM export function filterOrFail_( fa: P.STM, p: Predicate, failWith: (a: A) => E1 ): P.STM export function filterOrFail_( fa: P.STM, p: Predicate, failWith: unknown ) { return filterOrElse_(fa, p, (x) => P.fail((failWith as (a: A) => E1)(x))) } /** * Applies `or` if the predicate fails. * * @ets_data_first filterOrElse_ */ export function filterOrElse( p: Refinement, or: (a: Exclude) => P.STM ): (fa: P.STM) => P.STM export function filterOrElse( p: Predicate, or: (a: A) => P.STM ): (fa: P.STM) => P.STM export function filterOrElse(p: Predicate, or: unknown) { return (fa: P.STM) => filterOrElse_(fa, p, or as (a: A) => P.STM) } /** * Applies `or` if the predicate fails. */ export function filterOrElse_( fa: P.STM, p: Refinement, or: (a: Exclude) => P.STM ): P.STM export function filterOrElse_( fa: P.STM, p: Predicate, or: (a: A) => P.STM ): P.STM export function filterOrElse_( fa: P.STM, p: Predicate, or: unknown ): P.STM { return P.chain_( fa, (a): P.STM => p(a) ? P.succeed(a) : suspend(() => (or as (a: A) => P.STM)(a)) ) } /** * Dies with a `Error` having the specified text message * if the predicate fails. * * @ets_data_first filterOrDieMessage_ */ export function filterOrDieMessage( p: Refinement, message: (a: Exclude) => string ): (fa: P.STM) => P.STM export function filterOrDieMessage( p: Predicate, message: (a: A) => string ): (fa: P.STM) => P.STM export function filterOrDieMessage(p: Predicate, message: unknown) { return (fa: P.STM): P.STM => filterOrDieMessage_(fa, p, message as (a: A) => string) } /** * Dies with a `Error` having the specified text message * if the predicate fails. */ export function filterOrDieMessage_( fa: P.STM, p: Refinement, message: (a: Exclude) => string ): P.STM export function filterOrDieMessage_( fa: P.STM, p: Predicate, message: (a: A) => string ): P.STM export function filterOrDieMessage_( fa: P.STM, p: Predicate, message: unknown ) { return filterOrDie_(fa, p, (a) => new RuntimeError((message as (a: A) => string)(a))) } /** * Returns an effect that swaps the error/success cases. This allows you to * use all methods on the error channel, possibly before flipping back. */ export function flip(self: P.STM) { return P.foldM_(self, P.succeed, P.fail) } /** * Swaps the error/value parameters, applies the function `f` and flips the parameters back * * @ets_data_first flipWith_ */ export function flipWith( f: (self: P.STM) => P.STM ) { return (self: P.STM): P.STM => flipWith_(self, f) } /** * Swaps the error/value parameters, applies the function `f` and flips the parameters back */ export function flipWith_( self: P.STM, f: (self: P.STM) => P.STM ) { return flip(f(flip(self))) } /** * Folds over the `STM` effect, handling both P.failure and success, but not * retry. */ export function fold_( self: P.STM, g: (e: E) => C, f: (a: A) => B ): P.STM { return P.foldM_( self, (e) => P.succeed(g(e)), (a) => P.succeed(f(a)) ) } /** * Folds over the `STM` effect, handling both P.failure and success, but not * retry. * * @ets_data_first fold_ */ export function fold( g: (e: E) => C, f: (a: A) => B ): (self: P.STM) => P.STM { return (self) => fold_(self, g, f) } /** * Flattens out a nested `STM` effect. */ export function flatten( self: P.STM> ): P.STM { return P.chain_(self, identity) } /** * Unwraps the optional error, defaulting to the provided value. * * @ets_data_first flattenErrorOptionWith_ */ export function flattenErrorOptionWith(def: () => E2) { return (self: P.STM, A>): P.STM => flattenErrorOptionWith_(self, def) } /** * Unwraps the optional error, defaulting to the provided value. */ export function flattenErrorOptionWith_( self: P.STM, A>, def: () => E2 ): P.STM { return mapError_(self, O.fold(def, identity)) } /** * Unwraps the optional error, defaulting to the provided value. * * @ets_data_first flattenErrorOption_ */ export function flattenErrorOption(def: E2) { return (self: P.STM, A>): P.STM => flattenErrorOption_(self, def) } /** * Unwraps the optional error, defaulting to the provided value. */ export function flattenErrorOption_( self: P.STM, A>, def: E2 ): P.STM { return mapError_( self, O.fold(() => def, identity) ) } /** * Applies the function `f` to each element of the `Iterable` and * returns a transactional effect that produces a new `ReadonlyArray`. */ export function forEach_( it: Iterable, f: (a: A) => P.STM ): P.STM { return suspend(() => { let stm = P.succeed([]) as P.STM for (const a of it) { stm = zipWith_(stm, f(a), (acc, b) => { acc.push(b) return acc }) } return stm }) } /** * Applies the function `f` to each element of the `Iterable` and * returns a transactional effect that produces a new `ReadonlyArray`. * * @ets_data_first forEach_ */ export function forEach( f: (a: A) => P.STM ): (it: Iterable) => P.STM { return (self) => forEach_(self, f) } /** * Lifts an `Either` into a `STM`. */ export function fromEitherWith(e: () => E.Either): P.STM { return suspend(() => { return E.fold_(e(), P.fail, P.succeed) }) } /** * Lifts an `Either` into a `STM`. */ export function fromEither(e: E.Either): P.STM { return E.fold_(e, P.fail, P.succeed) } /** * Unwraps the optional success of this effect, but can fail with an None value. */ export function get(self: P.STM>): P.STM, A> { return P.foldM_( self, (x) => P.fail(O.some(x)), O.fold(() => P.fail(O.none), P.succeed) ) } /** * Returns a successful effect with the head of the list if the list is * non-empty or fails with the error `None` if the list is empty. */ export function head( self: P.STM> ): P.STM, A> { return P.foldM_( self, (x) => P.fail(O.some(x)), (x) => { const it = x[Symbol.iterator]() const next = it.next() return next.done ? P.fail(O.none) : P.succeed(next.value) } ) } /** * Returns a new effect that ignores the success or failure of this effect. */ export function ignore(self: P.STM): P.STM { return fold_(self, constVoid, constVoid) } /** * Returns whether this effect is a failure. */ export function isFailure(self: P.STM) { return fold_( self, () => true, () => false ) } /** * Returns whether this effect is a success. */ export function isSuccess(self: P.STM) { return fold_( self, () => false, () => true ) } /** * Returns a successful effect if the value is `Left`, or fails with the error `None`. */ export function left( self: P.STM> ): P.STM, B> { return P.foldM_( self, (e) => P.fail(O.some(e)), E.fold(P.succeed, () => P.fail(O.none)) ) } /** * Returns a successful effect if the value is `Left`, or fails with the error e. */ export function leftOrFail_( self: P.STM>, orFail: (c: C) => E1 ) { return P.chain_( self, E.fold(P.succeed, (x) => P.failWith(() => orFail(x))) ) } /** * Returns a successful effect if the value is `Left`, or fails with the error e. * * @ets_data_first leftOrFail_ */ export function leftOrFail(orFail: (c: C) => E1) { return (self: P.STM>) => leftOrFail_(self, orFail) } /** * Returns a successful effect if the value is `Left`, or fails with a `NoSuchElementException`. */ export function leftOrFailException(self: P.STM>) { return leftOrFail_(self, () => new NoSuchElementException()) } /** * Depending on provided environment returns either this one or the other effect. * * @ets_data_first join_ */ export function join(that: P.STM) { return (self: P.STM): P.STM, E | E1, A | A1> => { return join_(self, that) } } /** * Depending on provided environment returns either this one or the other effect. */ export function join_( self: P.STM, that: P.STM ): P.STM, E | E1, A | A1> { return accessM( (_: E.Either): P.STM => E.fold_( _, (r) => provideAll_(self, r), (r1) => provideAll_(that, r1) ) ) } /** * Depending on provided environment returns either this one or the other effect. */ export function joinEither_( self: P.STM, that: P.STM ): P.STM, E | E1, E.Either> { return accessM( (_: E.Either): P.STM> => E.fold_( _, (r) => P.map_(provideAll_(self, r), E.left), (r1) => P.map_(provideAll_(that, r1), E.right) ) ) } /** * Depending on provided environment returns either this one or the other effect. */ export function joinEither( that: P.STM ): (self: P.STM) => P.STM, E | E1, E.Either> { return (self) => joinEither_(self, that) } /** * Maps from one error type to another. */ export function mapError_( self: P.STM, f: (a: E) => E1 ): P.STM { return P.foldM_(self, (e) => P.fail(f(e)), P.succeed) } /** * Maps from one error type to another. * * @ets_data_first mapError_ */ export function mapError( f: (a: E) => E1 ): (self: P.STM) => P.STM { return (self) => mapError_(self, f) } /** * Provides the transaction its required environment, which eliminates * its dependency on `R`. */ export function provideAll_(self: P.STM, r: R): P.STM { return P.provideSome_(self, () => r) } /** * Provides the transaction its required environment, which eliminates * its dependency on `R`. * * @ets_data_first provideAll_ */ export function provideAll( r: R ): (self: P.STM) => P.STM { return (self) => provideAll_(self, r) } /** * Repeats this `STM` effect until its result satisfies the specified predicate. * * WARNING: * `repeatUntil` uses a busy loop to repeat the effect and will consume a thread until * it completes (it cannot yield). This is because STM describes a single atomic * transaction which must either complete, retry or fail a transaction before * yielding back to the Effect Runtime. * * - Use `retryUntil` instead if you don't need to maintain transaction state for repeats. * - Ensure repeating the STM effect will eventually satisfy the predicate. */ export function repeatUntil_( self: P.STM, f: (a: A) => boolean ): P.STM { return P.chain_(self, (a) => (f(a) ? P.succeed(a) : repeatUntil_(self, f))) } /** * Repeats this `STM` effect until its result satisfies the specified predicate. * * WARNING: * `repeatUntil` uses a busy loop to repeat the effect and will consume a thread until * it completes (it cannot yield). This is because STM describes a single atomic * transaction which must either complete, retry or fail a transaction before * yielding back to the Effect Runtime. * * - Use `retryUntil` instead if you don't need to maintain transaction state for repeats. * - Ensure repeating the STM effect will eventually satisfy the predicate. * * @ets_data_first repeatUntil_ */ export function repeatUntil( f: (a: A) => boolean ): (self: P.STM) => P.STM { return (self) => repeatUntil_(self, f) } /** * Repeats this `STM` effect while its result satisfies the specified predicate. * * WARNING: * `repeatWhile` uses a busy loop to repeat the effect and will consume a thread until * it completes (it cannot yield). This is because STM describes a single atomic * transaction which must either complete, retry or fail a transaction before * yielding back to the Effect Runtime. * * - Use `retryWhile` instead if you don't need to maintain transaction state for repeats. * - Ensure repeating the STM effect will eventually not satisfy the predicate. */ export function repeatWhile_( self: P.STM, f: (a: A) => boolean ): P.STM { return P.chain_(self, (a) => (f(a) ? repeatWhile_(self, f) : P.succeed(a))) } /** * Repeats this `STM` effect while its result satisfies the specified predicate. * * WARNING: * `repeatWhile` uses a busy loop to repeat the effect and will consume a thread until * it completes (it cannot yield). This is because STM describes a single atomic * transaction which must either complete, retry or fail a transaction before * yielding back to the Effect Runtime. * * - Use `retryWhile` instead if you don't need to maintain transaction state for repeats. * - Ensure repeating the STM effect will eventually not satisfy the predicate. * * @ets_data_first repeatWhile_ */ export function repeatWhile( f: (a: A) => boolean ): (self: P.STM) => P.STM { return (self) => repeatWhile_(self, f) } /** * Suspends creation of the specified transaction lazily. */ export function suspend(f: () => P.STM): P.STM { return flatten(P.succeedWith(f)) } /** * "Peeks" at the success of transactional effect. */ export function tap_( self: P.STM, f: (a: A) => P.STM ): P.STM { return P.chain_(self, (a) => as_(f(a), a)) } /** * "Peeks" at the success of transactional effect. * * @ets_data_first tap_ */ export function tap( f: (a: A) => P.STM ): (self: P.STM) => P.STM { return (self) => tap_(self, f) } /** * Returns an effect with the value on the left part. */ export function toLeftWith(a: () => A): P.STM> { return P.chain_(P.succeedWith(a), (x) => P.succeed(E.left(x))) } /** * Returns an effect with the value on the left part. */ export function toLeft(a: A): P.STM> { return P.succeed(E.left(a)) } /** * Sequentially zips this value with the specified one, combining the values * using the specified combiner function. */ export function zipWith_( self: P.STM, that: P.STM, f: (a: A, b: B) => C ): P.STM { return P.chain_(self, (a) => P.map_(that, (b) => f(a, b))) } /** * Sequentially zips this value with the specified one, combining the values * using the specified combiner function. * * @ets_data_first zipWith_ */ export function zipWith( that: P.STM, f: (a: A, b: B) => C ): (self: P.STM) => P.STM { return (self) => P.chain_(self, (a) => P.map_(that, (b) => f(a, b))) }