Socket
Socket
Sign inDemoInstall

@effect/stm

Package Overview
Dependencies
Maintainers
3
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@effect/stm - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

internal/stm.d.ts

111

internal/core.js

@@ -6,3 +6,3 @@ "use strict";

});
exports.zipWith = exports.zipRight = exports.zipLeft = exports.zip = exports.withSTMRuntime = exports.sync = exports.succeed = exports.retry = exports.provideSomeEnvironment = exports.orTry = exports.map = exports.interrupt = exports.foldSTM = exports.flatMap = exports.fail = exports.ensuring = exports.die = exports.commit = exports.catchAll = exports.STMTypeId = exports.STMDriver = void 0;
exports.zipWith = exports.zipRight = exports.zipLeft = exports.zip = exports.withSTMRuntime = exports.unsafeAtomically = exports.sync = exports.succeed = exports.retry = exports.provideSomeEnvironment = exports.orTry = exports.map = exports.interruptWith = exports.interrupt = exports.foldSTM = exports.flatMap = exports.failSync = exports.fail = exports.ensuring = exports.effect = exports.dieSync = exports.dieMessage = exports.die = exports.commit = exports.catchAll = exports.STMTypeId = exports.STMDriver = void 0;
var Cause = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/Cause"));

@@ -64,2 +64,11 @@ var _Debug = /*#__PURE__*/require("@effect/io/Debug");

const trace = (0, _Debug.getCallTrace)();
return unsafeAtomically(self, _Function.constVoid, _Function.constVoid).traced(trace);
};
/**
* @macro traced
* @internal
*/
exports.commit = commit;
const unsafeAtomically = (self, onDone, onInterrupt) => {
const trace = (0, _Debug.getCallTrace)();
return effectCore.withFiberRuntime(state => {

@@ -73,2 +82,3 @@ const fiberId = state.id();

{
onDone(commitResult.exit);
return effectCore.done(commitResult.exit);

@@ -82,23 +92,3 @@ }

};
const io = effectCore.async(k => {
if (STMState.isRunning(state.value)) {
if (Journal.isInvalid(commitResult.journal)) {
const result = tryCommit(fiberId, self, state, env, scheduler);
switch (result.op) {
case 0:
{
completeTryCommit(result.exit, k);
break;
}
case 1:
{
Journal.addTodo(txnId, result.journal, () => tryCommitAsync(fiberId, self, txnId, state, env, scheduler, k));
break;
}
}
} else {
Journal.addTodo(txnId, commitResult.journal, () => tryCommitAsync(fiberId, self, txnId, state, env, scheduler, k));
}
}
});
const effect = effectCore.async(k => tryCommitAsync(fiberId, self, txnId, state, env, scheduler, k));
return effectCore.uninterruptibleMask(restore => effectCore.catchAllCause(cause => {

@@ -110,4 +100,9 @@ let currentState = state.value;

currentState = state.value;
return STMState.isDone(currentState) ? effectCore.done(currentState.exit) : effectCore.failCause(cause);
})(restore(io)));
if (STMState.isDone(currentState)) {
onDone(currentState.exit);
return effectCore.done(currentState.exit);
}
onInterrupt();
return effectCore.failCause(cause);
})(restore(effect)));
}

@@ -118,3 +113,3 @@ }

/** @internal */
exports.commit = commit;
exports.unsafeAtomically = unsafeAtomically;
const tryCommit = (fiberId, stm, state, env, scheduler) => {

@@ -241,2 +236,5 @@ const journal = new Map();

}
getEnv() {
return this.env;
}
pushStack(cont) {

@@ -319,3 +317,3 @@ this.contStack.push(cont);

const annotation = new _cause.StackAnnotation(this.stackToLines(), this.execution?.toChunkReversed() || Chunk.empty());
exit = TExit.die(current.defect, annotation);
exit = TExit.die(current.defect(), annotation);
break;

@@ -329,6 +327,6 @@ }

if (!cont) {
exit = TExit.fail(current.error, annotation);
exit = TExit.fail(current.error(), annotation);
} else {
this.logTrace(cont.trace);
curr = cont.failK(current.error);
curr = cont.failK(current.error());
}

@@ -435,5 +433,23 @@ break;

const trace = (0, _Debug.getCallTrace)();
return dieSync(() => defect).traced(trace);
};
/**
* @macro traced
* @internal
*/
exports.die = die;
const dieMessage = message => {
const trace = (0, _Debug.getCallTrace)();
return dieSync(() => Cause.RuntimeException(message)).traced(trace);
};
/**
* @macro traced
* @internal
*/
exports.dieMessage = dieMessage;
const dieSync = evaluate => {
const trace = (0, _Debug.getCallTrace)();
const stm = Object.create(proto);
stm.opSTM = 9;
stm.defect = defect;
stm.defect = evaluate;
stm.trace = trace;

@@ -446,3 +462,12 @@ return stm;

*/
exports.die = die;
exports.dieSync = dieSync;
const effect = f => {
const trace = (0, _Debug.getCallTrace)();
return withSTMRuntime(_ => succeed(f(_.journal, _.fiberId, _.getEnv()))).traced(trace);
};
/**
* @macro traced
* @internal
*/
exports.effect = effect;
const ensuring = finalizer => {

@@ -459,5 +484,14 @@ const trace = (0, _Debug.getCallTrace)();

const trace = (0, _Debug.getCallTrace)();
return failSync(() => error).traced(trace);
};
/**
* @macro traced
* @internal
*/
exports.fail = fail;
const failSync = evaluate => {
const trace = (0, _Debug.getCallTrace)();
const stm = Object.create(proto);
stm.opSTM = 8;
stm.error = error;
stm.error = evaluate;
stm.trace = trace;

@@ -470,3 +504,3 @@ return stm;

*/
exports.fail = fail;
exports.failSync = failSync;
const flatMap = f => {

@@ -525,2 +559,15 @@ const trace = (0, _Debug.getCallTrace)();

exports.interrupt = interrupt;
const interruptWith = fiberId => {
const trace = (0, _Debug.getCallTrace)();
const stm = Object.create(proto);
stm.opSTM = 10;
stm.trace = trace;
stm.fiberId = fiberId;
return stm;
};
/**
* @macro traced
* @internal
*/
exports.interruptWith = interruptWith;
const map = f => {

@@ -527,0 +574,0 @@ const trace = (0, _Debug.getCallTrace)();

@@ -6,3 +6,3 @@ "use strict";

});
exports.isValid = exports.isInvalid = exports.execTodos = exports.commitJournal = exports.collectTodos = exports.analyzeJournal = exports.addTodo = exports.JournalAnalysisReadWrite = exports.JournalAnalysisReadOnly = exports.JournalAnalysisInvalid = void 0;
exports.prepareResetJournal = exports.isValid = exports.isInvalid = exports.execTodos = exports.commitJournal = exports.collectTodos = exports.analyzeJournal = exports.addTodo = exports.JournalAnalysisReadWrite = exports.JournalAnalysisReadOnly = exports.JournalAnalysisInvalid = void 0;
var Entry = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/stm/internal/stm/entry"));

@@ -47,2 +47,16 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

exports.analyzeJournal = analyzeJournal;
const prepareResetJournal = journal => {
const saved = new Map();
for (const entry of journal) {
saved.set(entry[0], Entry.copy(entry[1]));
}
return () => {
journal.clear();
for (const entry of saved) {
journal.set(entry[0], entry[1]);
}
};
};
/** @internal */
exports.prepareResetJournal = prepareResetJournal;
const collectTodos = journal => {

@@ -49,0 +63,0 @@ const allTodos = new Map();

@@ -35,7 +35,7 @@ "use strict";

modify(f) {
return core.withSTMRuntime(_ => {
const entry = getOrMakeEntry(this, _.journal);
return core.effect(journal => {
const entry = getOrMakeEntry(this, journal);
const [retValue, newValue] = f(Entry.unsafeGet(entry));
Entry.unsafeSet(entry, newValue);
return core.succeed(retValue);
return retValue;
});

@@ -52,6 +52,6 @@ }

const trace = (0, _Debug.getCallTrace)();
return core.withSTMRuntime(_ => {
return core.effect(journal => {
const ref = new TRefImpl(value);
_.journal.set(ref, Entry.make(ref, true));
return core.succeed(ref);
journal.set(ref, Entry.make(ref, true));
return ref;
}).traced(trace);

@@ -58,0 +58,0 @@ };

{
"name": "@effect/stm",
"version": "0.0.5",
"version": "0.0.6",
"license": "MIT",

@@ -5,0 +5,0 @@ "repository": {

@@ -24,3 +24,4 @@ import * as Cause from "@effect/io/Cause"

import * as Equal from "@fp-ts/data/Equal"
import { pipe } from "@fp-ts/data/Function"
import type { LazyArg } from "@fp-ts/data/Function"
import { constVoid, pipe } from "@fp-ts/data/Function"

@@ -116,3 +117,3 @@ /** @internal */

Op<OpCodes.OP_FAIL, {
readonly error: unknown
readonly error: LazyArg<unknown>
}>

@@ -124,3 +125,3 @@ {}

Op<OpCodes.OP_DIE, {
readonly defect: unknown
readonly defect: LazyArg<unknown>
}>

@@ -164,2 +165,15 @@ {}

const trace = getCallTrace()
return unsafeAtomically(self, constVoid, constVoid).traced(trace)
}
/**
* @macro traced
* @internal
*/
export const unsafeAtomically = <R, E, A>(
self: STM.STM<R, E, A>,
onDone: (exit: Exit.Exit<E, A>) => unknown,
onInterrupt: LazyArg<unknown>
): Effect.Effect<R, E, A> => {
const trace = getCallTrace()
return effectCore.withFiberRuntime<R, E, A>((state) => {

@@ -172,2 +186,3 @@ const fiberId = state.id()

case TryCommitOpCodes.OP_DONE: {
onDone(commitResult.exit)
return effectCore.done(commitResult.exit)

@@ -178,34 +193,9 @@ }

const state: { value: STMState.STMState<E, A> } = { value: STMState.running }
const io = effectCore.async(
(k: (effect: Effect.Effect<R, E, A>) => unknown): void => {
if (STMState.isRunning(state.value)) {
if (Journal.isInvalid(commitResult.journal)) {
const result = tryCommit(fiberId, self, state, env, scheduler)
switch (result.op) {
case TryCommitOpCodes.OP_DONE: {
completeTryCommit(result.exit, k)
break
}
case TryCommitOpCodes.OP_SUSPEND: {
Journal.addTodo(
txnId,
result.journal,
() => tryCommitAsync(fiberId, self, txnId, state, env, scheduler, k)
)
break
}
}
} else {
Journal.addTodo(
txnId,
commitResult.journal,
() => tryCommitAsync(fiberId, self, txnId, state, env, scheduler, k)
)
}
}
}
const effect = effectCore.async(
(k: (effect: Effect.Effect<R, E, A>) => unknown): void =>
tryCommitAsync(fiberId, self, txnId, state, env, scheduler, k)
)
return effectCore.uninterruptibleMask((restore) =>
pipe(
restore(io),
restore(effect),
effectCore.catchAllCause((cause) => {

@@ -217,5 +207,8 @@ let currentState = state.value

currentState = state.value
return STMState.isDone(currentState)
? effectCore.done(currentState.exit)
: effectCore.failCause(cause)
if (STMState.isDone(currentState)) {
onDone(currentState.exit)
return effectCore.done(currentState.exit)
}
onInterrupt()
return effectCore.failCause(cause)
})

@@ -438,2 +431,6 @@ )

getEnv(): Context.Context<R> {
return this.env
}
pushStack(cont: Continuation) {

@@ -523,3 +520,3 @@ this.contStack.push(cont)

)
exit = TExit.die(current.defect, annotation)
exit = TExit.die(current.defect(), annotation)
break

@@ -535,6 +532,6 @@ }

if (!cont) {
exit = TExit.fail(current.error, annotation)
exit = TExit.fail(current.error(), annotation)
} else {
this.logTrace(cont.trace)
curr = cont.failK(current.error) as Primitive
curr = cont.failK(current.error()) as Primitive
}

@@ -565,3 +562,3 @@ break

this.logTrace(current.trace)
curr = current.evaluate(this) as Primitive
curr = current.evaluate(this as STMDriver<unknown, unknown, unknown>) as Primitive
break

@@ -641,5 +638,23 @@ }

const trace = getCallTrace()
return dieSync(() => defect).traced(trace)
}
/**
* @macro traced
* @internal
*/
export const dieMessage = (message: string): STM.STM<never, never, never> => {
const trace = getCallTrace()
return dieSync(() => Cause.RuntimeException(message)).traced(trace)
}
/**
* @macro traced
* @internal
*/
export const dieSync = (evaluate: LazyArg<unknown>): STM.STM<never, never, never> => {
const trace = getCallTrace()
const stm = Object.create(proto)
stm.opSTM = OpCodes.OP_DIE
stm.defect = defect
stm.defect = evaluate
stm.trace = trace

@@ -653,2 +668,17 @@ return stm

*/
export const effect = <R, A>(
f: (
journal: Journal.Journal,
fiberId: FiberId.FiberId,
environment: Context.Context<R>
) => A
): STM.STM<R, never, A> => {
const trace = getCallTrace()
return withSTMRuntime((_) => succeed(f(_.journal, _.fiberId, _.getEnv()))).traced(trace)
}
/**
* @macro traced
* @internal
*/
export const ensuring = <R1, B>(finalizer: STM.STM<R1, never, B>) => {

@@ -672,5 +702,14 @@ const trace = getCallTrace()

const trace = getCallTrace()
return failSync(() => error).traced(trace)
}
/**
* @macro traced
* @internal
*/
export const failSync = <E>(evaluate: LazyArg<E>): STM.STM<never, E, never> => {
const trace = getCallTrace()
const stm = Object.create(proto)
stm.opSTM = OpCodes.OP_FAIL
stm.error = error
stm.error = evaluate
stm.trace = trace

@@ -743,2 +782,15 @@ return stm

*/
export const interruptWith = (fiberId: FiberId.FiberId): STM.STM<never, never, never> => {
const trace = getCallTrace()
const stm = Object.create(proto)
stm.opSTM = OpCodes.OP_INTERRUPT
stm.trace = trace
stm.fiberId = fiberId
return stm
}
/**
* @macro traced
* @internal
*/
export const map = <A, B>(f: (a: A) => B) => {

@@ -745,0 +797,0 @@ const trace = getCallTrace()

@@ -59,2 +59,16 @@ import * as Entry from "@effect/stm/internal/stm/entry"

/** @internal */
export const prepareResetJournal = (journal: Journal): () => unknown => {
const saved: Journal = new Map<TRef.TRef<unknown>, Entry.Entry>()
for (const entry of journal) {
saved.set(entry[0], Entry.copy(entry[1]))
}
return () => {
journal.clear()
for (const entry of saved) {
journal.set(entry[0], entry[1])
}
}
}
/** @internal */
export const collectTodos = (journal: Journal): Map<TxnId.TxnId, Todo> => {

@@ -61,0 +75,0 @@ const allTodos: Map<TxnId.TxnId, Todo> = new Map()

@@ -39,7 +39,7 @@ import { getCallTrace } from "@effect/io/Debug"

modify<B>(f: (a: A) => readonly [B, A]): STM.STM<never, never, B> {
return core.withSTMRuntime((_) => {
const entry = getOrMakeEntry(this, _.journal)
return core.effect<never, B>((journal) => {
const entry = getOrMakeEntry(this, journal)
const [retValue, newValue] = f(Entry.unsafeGet(entry) as A)
Entry.unsafeSet(entry, newValue)
return core.succeed(retValue)
return retValue
})

@@ -55,6 +55,6 @@ }

const trace = getCallTrace()
return core.withSTMRuntime((_) => {
return core.effect<never, TRef.TRef<A>>((journal) => {
const ref = new TRefImpl(value)
_.journal.set(ref, Entry.make(ref, true))
return core.succeed(ref)
journal.set(ref, Entry.make(ref, true))
return ref
}).traced(trace)

@@ -61,0 +61,0 @@ }

/**
* @since 1.0.0
*/
import type * as Cause from "@effect/io/Cause"
import type * as Effect from "@effect/io/Effect"
import type * as FiberId from "@effect/io/Fiber/Id"
import * as core from "@effect/stm/internal/core"
import * as stm from "@effect/stm/internal/stm"
import type * as Chunk from "@fp-ts/data/Chunk"
import type * as Context from "@fp-ts/data/Context"
import type * as Either from "@fp-ts/data/Either"
import type { LazyArg } from "@fp-ts/data/Function"
import type * as Option from "@fp-ts/data/Option"
import type { Predicate } from "@fp-ts/data/Predicate"

@@ -85,4 +92,68 @@ /**

/**
* Returns an effect that submerges the error case of an `Either` into the
* `STM`. The inverse operation of `STM.either`.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const absolve: <R, E, E2, A>(self: STM<R, E, Either.Either<E2, A>>) => STM<R, E | E2, A> = stm.absolve
/**
* Maps the success value of this effect to the specified constant value.
*
* @macro traced
* @since 1.0.0
* @category mapping
*/
export const as: <A2>(value: A2) => <R, E, A>(self: STM<R, E, A>) => STM<R, E, A2> = stm.as
/**
* Maps the success value of this effect to an optional value.
*
* @macro traced
* @since 1.0.0
* @category mapping
*/
export const asSome: <R, E, A>(self: STM<R, E, A>) => STM<R, E, Option.Option<A>> = stm.asSome
/**
* Maps the error value of this effect to an optional value.
*
* @macro traced
* @since 1.0.0
* @category mapping
*/
export const asSomeError: <R, E, A>(self: STM<R, E, A>) => STM<R, Option.Option<E>, A> = stm.asSomeError
/**
* Treats the specified `acquire` transaction as the acquisition of a
* resource. The `acquire` transaction will be executed interruptibly. If it
* is a success and is committed the specified `release` workflow will be
* executed uninterruptibly as soon as the `use` workflow completes execution.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const acquireUseRelease: <R, E, A, R2, E2, A2, R3, E3, A3>(
acquire: STM<R, E, A>,
use: (resource: A) => STM<R2, E2, A2>,
release: (resource: A) => STM<R3, E3, A3>
) => Effect.Effect<R | R2 | R3, E | E2 | E3, A2> = stm.acquireUseRelease
/**
* Creates an `STM` value from a partial (but pure) function.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const attempt: <A>(evaluate: LazyArg<A>) => STM<never, unknown, A> = stm.attempt
/**
* Recovers from all errors.
*
* @macro traced
* @since 1.0.0
* @category error handling

@@ -95,4 +166,82 @@ */

/**
* Recovers from some or all of the error cases.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
export const catchSome: <E, R2, E2, A2>(
pf: (error: E) => Option.Option<STM<R2, E2, A2>>
) => <R, A>(self: STM<R, E, A>) => STM<R2 | R, E | E2, A2 | A> = stm.catchSome
/**
* Checks the condition, and if it's true, returns unit, otherwise, retries.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const check: (predicate: LazyArg<boolean>) => STM<never, never, void> = stm.check
/**
* Simultaneously filters and maps the value produced by this effect.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const collect: <A, A2>(pf: (a: A) => Option.Option<A2>) => <R, E>(self: STM<R, E, A>) => STM<R, E, A2> =
stm.collect
/**
* Collects all the transactional effects in a collection, returning a single
* transactional effect that produces a collection of values.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const collectAll: <R, E, A>(iterable: Iterable<STM<R, E, A>>) => STM<R, E, Chunk.Chunk<A>> = stm.collectAll
/**
* Collects all the transactional effects, returning a single transactional
* effect that produces `Unit`.
*
* Equivalent to `pipe(icollectAll(iterable), asUnit)`, but without the cost
* of building the list of results.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const collectAllDiscard: <R, E, A>(iterable: Iterable<STM<R, E, A>>) => STM<R, E, void> = stm.collectAllDiscard
/**
* Collects the first element of the `Iterable<A>` for which the effectual
* function `f` returns `Some`.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const collectFirst: <A, R, E, A2>(
pf: (a: A) => STM<R, E, Option.Option<A2>>
) => (iterable: Iterable<A>) => STM<R, E, Option.Option<A2>> = stm.collectFirst
/**
* Simultaneously filters and flatMaps the value produced by this effect.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const collectSTM: <A, R2, E2, A2>(
pf: (a: A) => Option.Option<STM<R2, E2, A2>>
) => <R, E>(self: STM<R, E, A>) => STM<R2 | R, E2 | E, A2> = stm.collectSTM
/**
* Commits this transaction atomically.
*
* @macro traced
* @since 1.0.0
* @category destructors

@@ -103,11 +252,66 @@ */

/**
* Commits this transaction atomically, regardless of whether the transaction
* is a success or a failure.
*
* @macro traced
* @since 1.0.0
* @category destructors
*/
export const commitEither: <R, E, A>(self: STM<R, E, A>) => Effect.Effect<R, E, A> = stm.commitEither
/**
* Similar to Either.cond, evaluate the predicate, return the given A as
* success if predicate returns true, and the given E as error otherwise
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const cond: <E, A>(predicate: LazyArg<boolean>, error: LazyArg<E>, result: LazyArg<A>) => STM<never, E, A> =
stm.cond
/**
* Fails the transactional effect with the specified defect.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const die: (defect: unknown) => STM<never, never, never> = core.die
/**
* Kills the fiber running the effect with a `Cause.RuntimeException` that
* contains the specified message.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const dieMessage: (message: string) => STM<never, never, never> = core.dieMessage
/**
* Fails the transactional effect with the specified lazily evaluated defect.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const dieSync: (evaluate: LazyArg<unknown>) => STM<never, never, never> = core.dieSync
/**
* Converts the failure channel into an `Either`.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const either: <R, E, A>(self: STM<R, E, A>) => STM<R, never, Either.Either<E, A>> = stm.either
/**
* Executes the specified finalization transaction whether or not this effect
* succeeds. Note that as with all STM transactions, if the full transaction
* fails, everything will be rolled back.
*
* @macro traced
* @since 1.0.0
* @category finalization

@@ -120,2 +324,4 @@ */

/**
* Retrieves the environment inside an stm.
*
* @macro traced

@@ -125,7 +331,176 @@ * @since 1.0.0

*/
export const environment: <R>() => STM<R, never, Context.Context<R>> = stm.environment
/**
* Accesses the environment of the transaction to perform a transaction.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const environmentWith: <R0, R>(f: (environment: Context.Context<R0>) => R) => STM<R0, never, R> =
stm.environmentWith
/**
* Accesses the environment of the transaction to perform a transaction.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const environmentWithSTM: <R0, R, E, A>(
f: (environment: Context.Context<R0>) => STM<R, E, A>
) => STM<R0 | R, E, A> = stm.environmentWithSTM
/**
* Returns an effect that ignores errors and runs repeatedly until it
* eventually succeeds.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const eventually: <R, E, A>(self: STM<R, E, A>) => STM<R, E, A> = stm.eventually
/**
* Determines whether all elements of the `Iterable<A>` satisfy the effectual
* predicate.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const every: <A, R, E>(
predicate: (a: A) => STM<R, E, boolean>
) => (iterable: Iterable<A>) => STM<R, E, boolean> = stm.every
/**
* Determines whether any element of the `Iterable[A]` satisfies the effectual
* predicate `f`.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const exists: <A, R, E>(
predicate: (a: A) => STM<R, E, boolean>
) => (iterable: Iterable<A>) => STM<R, E, boolean> = stm.exists
/**
* Fails the transactional effect with the specified error.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const fail: <E>(error: E) => STM<never, E, never> = core.fail
/**
* Fails the transactional effect with the specified lazily evaluated error.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const failSync: <E>(evaluate: LazyArg<E>) => STM<never, E, never> = core.failSync
/**
* Returns the fiber id of the fiber committing the transaction.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const fiberId: () => STM<never, never, FiberId.FiberId> = stm.fiberId
/**
* Filters the collection using the specified effectual predicate.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const filter: <A, R, E>(
predicate: (a: A) => STM<R, E, boolean>
) => (iterable: Iterable<A>) => STM<R, E, Chunk.Chunk<A>> = stm.filter
/**
* Filters the collection using the specified effectual predicate, removing
* all elements that satisfy the predicate.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const filterNot: <A, R, E>(
predicate: (a: A) => STM<R, E, boolean>
) => (iterable: Iterable<A>) => STM<R, E, Chunk.Chunk<A>> = stm.filterNot
/**
* Dies with specified defect if the predicate fails.
*
* @macro traced
* @since 1.0.0
* @category filtering
*/
export const filterOrDie: <A>(
predicate: Predicate<A>,
defect: LazyArg<unknown>
) => <R, E>(self: STM<R, E, A>) => STM<R, E, A> = stm.filterOrDie
/**
* Dies with a `Cause.RuntimeException` having the specified message if the
* predicate fails.
*
* @macro traced
* @since 1.0.0
* @category filtering
*/
export const filterOrDieMessage: <A>(
predicate: Predicate<A>,
message: string
) => <R, E>(self: STM<R, E, A>) => STM<R, E, A> = stm.filterOrDieMessage
/**
* Supplies `orElse` if the predicate fails.
*
* @macro traced
* @since 1.0.0
* @category filtering
*/
export const filterOrElse: <A, R2, E2, A2>(
predicate: Predicate<A>,
orElse: LazyArg<STM<R2, E2, A2>>
) => <R, E>(self: STM<R, E, A>) => STM<R2 | R, E2 | E, A | A2> = stm.filterOrElse
/**
* Applies `orElse` if the predicate fails.
*
* @macro traced
* @since 1.0.0
* @category filtering
*/
export const filterOrElseWith: <A, R2, E2, A2>(
predicate: Predicate<A>,
orElse: (a: A) => STM<R2, E2, A2>
) => <R, E>(self: STM<R, E, A>) => STM<R2 | R, E2 | E, A | A2> = stm.filterOrElseWith
/**
* Fails with the specified error if the predicate fails.
*
* @macro traced
* @since 1.0.0
* @category filtering
*/
export const filterOrFail: <A, E2>(
predicate: Predicate<A>,
error: LazyArg<E2>
) => <R, E>(self: STM<R, E, A>) => STM<R, E2 | E, A> = stm.filterOrFail
/**
* Feeds the value produced by this effect to the specified function, and then
* runs the returned effect as well to produce its results.
*
* @macro traced
* @since 1.0.0
* @category sequencing

@@ -138,6 +513,76 @@ */

/**
* Creates a composite effect that represents this effect followed by another
* one that may depend on the error produced by this one.
*
* @macro traced
* @since 1.0.0
* @category sequencing
*/
export const flatMapError: <E, R2, E2>(
f: (error: E) => STM<R2, never, E2>
) => <R, A>(self: STM<R, E, A>) => STM<R2 | R, E2, A> = stm.flatMapError
/**
* Flattens out a nested `STM` effect.
*
* @macro traced
* @since 1.0.0
* @category sequencing
*/
export const flatten: <R, E, R2, E2, A>(self: STM<R, E, STM<R2, E2, A>>) => STM<R | R2, E | E2, A> = stm.flatten
/**
* Unwraps the optional error, defaulting to the provided value.
*
* @macro traced
* @since 1.0.0
* @category sequencing
*/
export const flattenErrorOption: <E2>(
fallback: LazyArg<E2>
) => <R, E, A>(self: STM<R, Option.Option<E>, A>) => STM<R, E2 | E, A> = stm.flattenErrorOption
/**
* Flips the success and failure channels of this transactional effect. This
* allows you to use all methods on the error channel, possibly before
* flipping back.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const flip: <R, E, A>(self: STM<R, E, A>) => STM<R, A, E> = stm.flip
/**
* Swaps the error/value parameters, applies the function `f` and flips the
* parameters back
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const flipWith: <R, A, E, R2, A2, E2>(
f: (stm: STM<R, A, E>) => STM<R2, A2, E2>
) => (self: STM<R, E, A>) => STM<R | R2, E | E2, A | A2> = stm.flipWith
/**
* Folds over the `STM` effect, handling both failure and success, but not
* retry.
*
* @macro traced
* @since 1.0.0
* @category folding
*/
export const fold: <E, A2, A, A3>(
f: (error: E) => A2,
g: (value: A) => A3
) => <R>(self: STM<R, E, A>) => STM<R, E, A2 | A3> = stm.fold
/**
* Effectfully folds over the `STM` effect, handling both failure and success.
*
* @macro traced
* @since 1.0.0
* @category folding
*/
export const foldSTM: <E, R1, E1, A1, A, R2, E2, A2>(

@@ -149,11 +594,199 @@ onFailure: (e: E) => STM<R1, E1, A1>,

/**
* Applies the function `f` to each element of the `Iterable<A>` and returns
* a transactional effect that produces a new `Chunk<A2>`.
*
* @macro traced
* @since 1.0.0
* @category traversing
*/
export const forEach: <A, R, E, A2>(
f: (a: A) => STM<R, E, A2>
) => (elements: Iterable<A>) => STM<R, E, Chunk.Chunk<A2>> = stm.forEach
/**
* Applies the function `f` to each element of the `Iterable<A>` and returns a
* transactional effect that produces the unit result.
*
* Equivalent to `pipe(as, forEach(f), asUnit)`, but without the cost of
* building the list of results.
*
* @macro traced
* @since 1.0.0
* @category traversing
*/
export const forEachDiscard: <A, R, E, _>(f: (a: A) => STM<R, E, _>) => (iterable: Iterable<A>) => STM<R, E, void> =
stm.forEachDiscard
/**
* Lifts an `Either` into a `STM`.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const fromEither: <E, A>(either: Either.Either<E, A>) => STM<never, E, A> = stm.fromEither
/**
* Lifts an `Option` into a `STM`.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const fromOption: <A>(option: Option.Option<A>) => STM<never, Option.Option<never>, A> = stm.fromOption
/**
* 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.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
export const head: <R, E, A>(self: STM<R, E, Iterable<A>>) => STM<R, Option.Option<E>, A> = stm.head
/**
* Runs `onTrue` if the result of `b` is `true` and `onFalse` otherwise.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const ifSTM: <R1, R2, E1, E2, A, A1>(
onTrue: STM<R1, E1, A>,
onFalse: STM<R2, E2, A1>
) => <R, E>(self: STM<R, E, boolean>) => STM<R1 | R2 | R, E1 | E2 | E, A | A1> = stm.ifSTM
/**
* Returns a new effect that ignores the success or failure of this effect.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const ignore: <R, E, A>(self: STM<R, E, A>) => STM<R, never, void> = stm.ignore
/**
* Interrupts the fiber running the effect.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const interrupt: () => STM<never, never, never> = core.interrupt
/**
* Interrupts the fiber running the effect with the specified `FiberId`.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const interruptWith: (fiberId: FiberId.FiberId) => STM<never, never, never> = core.interruptWith
/**
* Returns whether this transactional effect is a failure.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
export const isFailure: <R, E, A>(self: STM<R, E, A>) => STM<R, never, boolean> = stm.isFailure
/**
* Returns whether this transactional effect is a success.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
export const isSuccess: <R, E, A>(self: STM<R, E, A>) => STM<R, never, boolean> = stm.isSuccess
/**
* Iterates with the specified transactional function. The moral equivalent
* of:
*
* ```ts
* const s = initial
*
* while (cont(s)) {
* s = body(s)
* }
*
* return s
* ```
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const iterate: <Z>(initial: Z, cont: (z: Z) => boolean) => <R, E>(body: (z: Z) => STM<R, E, Z>) => STM<R, E, Z> =
stm.iterate
/**
* "Zooms in" on the value in the `Left` side of an `Either`, moving the
* possibility that the value is a `Right` to the error channel.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
export const left: <R, E, A, A2>(self: STM<R, E, Either.Either<A, A2>>) => STM<R, Either.Either<E, A2>, A> = stm.left
/**
* Loops with the specified transactional function, collecting the results
* into a list. The moral equivalent of:
*
* ```ts
* const as = []
* let s = initial
*
* while (cont(s)) {
* as.push(body(s))
* s = inc(s)
* }
*
* return as
* ```
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const loop: <Z, R, E, A>(
initial: Z,
cont: (z: Z) => boolean,
inc: (z: Z) => Z,
body: (z: Z) => STM<R, E, A>
) => STM<R, E, Chunk.Chunk<A>> = stm.loop
/**
* Loops with the specified transactional function purely for its
* transactional effects. The moral equivalent of:
*
* ```ts
* let s = initial
*
* while (cont(s)) {
* body(s)
* s = inc(s)
* }
* ```
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const loopDiscard: <Z, R, E, X>(
initial: Z,
cont: (z: Z) => boolean,
inc: (z: Z) => Z,
body: (z: Z) => STM<R, E, X>
) => STM<R, E, void> = stm.loopDiscard
/**
* Maps the value produced by the effect.
*
* @macro traced
* @since 1.0.0
* @category mapping

@@ -164,6 +797,170 @@ */

/**
* Maps the value produced by the effect with the specified function that may
* throw exceptions but is otherwise pure, translating any thrown exceptions
* into typed failed effects.
*
* @macro traced
* @since 1.0.0
* @category mapping
*/
export const mapAttempt: <A, B>(f: (a: A) => B) => <R, E>(self: STM<R, E, A>) => STM<R, unknown, B> = stm.mapAttempt
/**
* Returns an `STM` effect whose failure and success channels have been mapped
* by the specified pair of functions, `f` and `g`.
*
* @macro traced
* @since 1.0.0
* @category mapping
*/
export const mapBoth: <E, E2, A, A2>(
f: (error: E) => E2,
g: (value: A) => A2
) => <R>(self: STM<R, E, A>) => STM<R, E2, A2> = stm.mapBoth
/**
* Maps from one error type to another.
*
* @macro traced
* @since 1.0.0
* @category mapping
*/
export const mapError: <E, E2>(f: (error: E) => E2) => <R, A>(self: STM<R, E, A>) => STM<R, E2, A> = stm.mapError
/**
* Returns a new effect where the error channel has been merged into the
* success channel to their common combined type.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const merge: <R, E, A>(self: STM<R, E, A>) => STM<R, never, E | A> = stm.merge
/**
* Merges an `Iterable<STM>` to a single `STM`, working sequentially.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const mergeAll: <A2, A>(
zero: A2,
f: (a2: A2, a: A) => A2
) => <R, E>(iterable: Iterable<STM<R, E, A>>) => STM<R, E, A2> = stm.mergeAll
/**
* Returns a new effect where boolean value of this effect is negated.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const negate: <R, E>(self: STM<R, E, boolean>) => STM<R, E, boolean> = stm.negate
/**
* Requires the option produced by this value to be `None`.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const none: <R, E, A>(self: STM<R, E, Option.Option<A>>) => STM<R, Option.Option<E>, void> = stm.none
/**
* Converts the failure channel into an `Option`.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const option: <R, E, A>(self: STM<R, E, A>) => STM<R, never, Option.Option<A>> = stm.option
/**
* Translates `STM` effect failure into death of the fiber, making all
* failures unchecked and not a part of the type of the effect.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
export const orDie: <R, E, A>(self: STM<R, E, A>) => STM<R, never, A> = stm.orDie
/**
* Keeps none of the errors, and terminates the fiber running the `STM` effect
* with them, using the specified function to convert the `E` into a defect.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
export const orDieWith: <E>(f: (error: E) => unknown) => <R, A>(self: STM<R, E, A>) => STM<R, never, A> = stm.orDieWith
/**
* Tries this effect first, and if it fails or retries, tries the other
* effect.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
export const orElse: <R2, E2, A2>(
that: LazyArg<STM<R2, E2, A2>>
) => <R, E, A>(self: STM<R, E, A>) => STM<R2 | R, E2, A2 | A> = stm.orElse
/**
* Returns a transactional effect that will produce the value of this effect
* in left side, unless it fails or retries, in which case, it will produce
* the value of the specified effect in right side.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
export const orElseEither: <R2, E2, A2>(
that: LazyArg<STM<R2, E2, A2>>
) => <R, E, A>(self: STM<R, E, A>) => STM<R2 | R, E2, Either.Either<A, A2>> = stm.orElseEither
/**
* Tries this effect first, and if it fails or retries, fails with the
* specified error.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
export const orElseFail: <E2>(error: LazyArg<E2>) => <R, E, A>(self: STM<R, E, A>) => STM<R, E2, A> = stm.orElseFail
/**
* Returns an effect that will produce the value of this effect, unless it
* fails with the `None` value, in which case it will produce the value of the
* specified effect.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
export const orElseOptional: <R2, E2, A2>(
that: LazyArg<STM<R2, Option.Option<E2>, A2>>
) => <R, E, A>(self: STM<R, Option.Option<E>, A>) => STM<R2 | R, Option.Option<E2 | E>, A2 | A> = stm.orElseOptional
/**
* Tries this effect first, and if it fails or retries, succeeds with the
* specified value.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
export const orElseSucceed: <A2>(value: LazyArg<A2>) => <R, E, A>(self: STM<R, E, A>) => STM<R, never, A2 | A> =
stm.orElseSucceed
/**
* Tries this effect first, and if it enters retry, then it tries the other
* effect. This is an equivalent of Haskell's orElse.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
export const orTry: <R1, E1, A1>(

@@ -174,6 +971,32 @@ that: () => STM<R1, E1, A1>

/**
* Feeds elements of type `A` to a function `f` that returns an effect.
* Collects all successes and failures in a tupled fashion.
*
* @macro traced
* @since 1.0.0
* @category traversing
*/
export const partition: <R, E, A, A2>(
f: (a: A) => STM<R, E, A2>
) => (elements: Iterable<A>) => STM<R, E, readonly [Chunk.Chunk<E>, Chunk.Chunk<A2>]> = stm.partition
/**
* Provides the transaction its required environment, which eliminates its
* dependency on `R`.
*
* @macro traced
* @since 1.0.0
* @category environment
*/
export const provideEnvironment: <R>(env: Context.Context<R>) => <E, A>(self: STM<R, E, A>) => STM<never, E, A> =
stm.provideEnvironment
/**
* Transforms the environment being provided to this effect with the specified
* function.
*
* @macro traced
* @since 1.0.0
* @category environment
*/
export const provideSomeEnvironment: <R0, R>(

@@ -184,4 +1007,157 @@ f: (context: Context.Context<R0>) => Context.Context<R>

/**
* Folds an `Iterable<A>` using an effectual function f, working sequentially
* from left to right.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const reduce: <S, A, R, E>(zero: S, f: (s: S, a: A) => STM<R, E, S>) => (iterable: Iterable<A>) => STM<R, E, S> =
stm.reduce
/**
* Reduces an `Iterable<STM>` to a single `STM`, working sequentially.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const reduceAll: <R2, E2, A>(
initial: STM<R2, E2, A>,
f: (x: A, y: A) => A
) => <R, E>(iterable: Iterable<STM<R, E, A>>) => STM<R2 | R, E2 | E, A> = stm.reduceAll
/**
* Folds an `Iterable<A>` using an effectual function f, working sequentially
* from right to left.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const reduceRight: <S, A, R, E>(
zero: S,
f: (s: S, a: A) => STM<R, E, S>
) => (iterable: Iterable<A>) => STM<R, E, S> = stm.reduceRight
/**
* Keeps some of the errors, and terminates the fiber with the rest.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const refineOrDie: <E, E2>(pf: (error: E) => Option.Option<E2>) => <R, A>(self: STM<R, E, A>) => STM<R, E2, A> =
stm.refineOrDie
/**
* Keeps some of the errors, and terminates the fiber with the rest, using the
* specified function to convert the `E` into a `Throwable`.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const refineOrDieWith: <E, E2>(
pf: (error: E) => Option.Option<E2>,
f: (error: E) => unknown
) => <R, A>(self: STM<R, E, A>) => STM<R, E2, A> = stm.refineOrDieWith
/**
* Fail with the returned value if the `PartialFunction` matches, otherwise
* continue with our held value.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const reject: <A, E2>(pf: (a: A) => Option.Option<E2>) => <R, E>(self: STM<R, E, A>) => STM<R, E2 | E, A> =
stm.reject
/**
* Continue with the returned computation if the specified partial function
* matches, translating the successful match into a failure, otherwise continue
* with our held value.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const rejectSTM: <A, R2, E2>(
pf: (a: A) => Option.Option<STM<R2, E2, E2>>
) => <R, E>(self: STM<R, E, A>) => STM<R2 | R, E2 | E, A> = stm.rejectSTM
/**
* 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.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const repeatUntil: <A>(predicate: Predicate<A>) => <R, E>(self: STM<R, E, A>) => STM<R, E, A> = stm.repeatUntil
/**
* 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.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const repeatWhile: <A>(predicate: Predicate<A>) => <R, E>(self: STM<R, E, A>) => STM<R, E, A> = stm.repeatWhile
/**
* Replicates the given effect n times. If 0 or negative numbers are given, an
* empty `Chunk` will be returned.
*
* @since 1.0.0
* @category constructors
*/
export const replicate: (n: number) => <R, E, A>(self: STM<R, E, A>) => Chunk.Chunk<STM<R, E, A>> = stm.replicate
/**
* Performs this transaction the specified number of times and collects the
* results.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const replicateSTM: (n: number) => <R, E, A>(self: STM<R, E, A>) => STM<R, E, Chunk.Chunk<A>> = stm.replicateSTM
/**
* Performs this transaction the specified number of times, discarding the
* results.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const replicateSTMDiscard: (n: number) => <R, E, A>(self: STM<R, E, A>) => STM<R, E, void> =
stm.replicateSTMDiscard
/**
* Abort and retry the whole transaction when any of the underlying
* transactional variables have changed.
*
* @macro traced
* @since 1.0.0
* @category error handling

@@ -192,9 +1168,126 @@ */

/**
* Filters the value produced by this effect, retrying the transaction until
* the predicate returns `true` for the value.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const retryUntil: <A>(predicate: Predicate<A>) => <R, E>(self: STM<R, E, A>) => STM<R, E, A> = stm.retryUntil
/**
* Filters the value produced by this effect, retrying the transaction while
* the predicate returns `true` for the value.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const retryWhile: <A>(predicate: Predicate<A>) => <R, E>(self: STM<R, E, A>) => STM<R, E, A> = stm.retryWhile
/**
* "Zooms in" on the value in the `Right` side of an `Either`, moving the
* possibility that the value is a `Left` to the error channel.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
export const right: <R, E, A, A2>(self: STM<R, E, Either.Either<A, A2>>) => STM<R, Either.Either<A, E>, A2> = stm.right
/**
* Accesses the specified service in the environment of the effect.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const service: <T>(tag: Context.Tag<T>) => STM<T, never, T> = stm.service
/**
* Effectfully accesses the specified service in the environment of the
* effect.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const serviceWith: <T>(tag: Context.Tag<T>) => <A>(f: (service: T) => A) => STM<T, never, A> = stm.serviceWith
/**
* Effectfully accesses the specified service in the environment of the
* effect.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const serviceWithSTM: <T>(
tag: Context.Tag<T>
) => <R, E, A>(f: (service: T) => STM<R, E, A>) => STM<T | R, E, A> = stm.serviceWithSTM
/**
* Converts an option on values into an option on errors.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
export const some: <R, E, A>(self: STM<R, E, Option.Option<A>>) => STM<R, Option.Option<E>, A> = stm.some
/**
* Extracts the optional value, or returns the given 'default'.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
export const someOrElse: <A2>(
orElse: LazyArg<A2>
) => <R, E, A>(self: STM<R, E, Option.Option<A>>) => STM<R, E, A2 | A> = stm.someOrElse
/**
* Extracts the optional value, or executes the effect 'default'.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
export const someOrElseSTM: <R2, E2, A2>(
orElse: LazyArg<STM<R2, E2, A2>>
) => <R, E, A>(self: STM<R, E, Option.Option<A>>) => STM<R2 | R, E2 | E, A2 | A> = stm.someOrElseSTM
/**
* Extracts the optional value, or fails with the given error 'e'.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
export const someOrFail: <E2>(error: LazyArg<E2>) => <R, E, A>(self: STM<R, E, Option.Option<A>>) => STM<R, E2 | E, A> =
stm.someOrFail
/**
* Extracts the optional value, or fails with a
* `Cause.NoSuchElementException`.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
export const someOrFailException: <R, E, A>(
self: STM<R, E, Option.Option<A>>
) => STM<R, E | Cause.NoSuchElementException, A> = stm.someOrFailException
/**
* Returns an `STM` effect that succeeds with the specified value.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const succeed: <A>(value: A) => STM<never, never, A> = core.succeed
/**
* Returns an effect with the value on the left part.
*
* @macro traced

@@ -204,7 +1297,164 @@ * @since 1.0.0

*/
export const succeedLeft: <A>(value: A) => STM<never, never, Either.Either<A, never>> = stm.succeedLeft
/**
* Returns an effect with the empty value.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const succeedNone: () => STM<never, never, Option.Option<never>> = stm.succeedNone
/**
* Returns an effect with the value on the right part.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const succeedRight: <A>(value: A) => STM<never, never, Either.Either<never, A>> = stm.succeedRight
/**
* Returns an effect with the optional value.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const succeedSome: <A>(value: A) => STM<never, never, Option.Option<A>> = stm.succeedSome
/**
* Summarizes a `STM` effect by computing a provided value before and after
* execution, and then combining the values to produce a summary, together
* with the result of execution.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const summarized: <R2, E2, A2, A3>(
summary: STM<R2, E2, A2>,
f: (before: A2, after: A2) => A3
) => <R, E, A>(self: STM<R, E, A>) => STM<R2 | R, E2 | E, readonly [A3, A]> = stm.summarized
/**
* Suspends creation of the specified transaction lazily.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const suspend: <R, E, A>(evaluate: LazyArg<STM<R, E, A>>) => STM<R, E, A> = stm.suspend
/**
* Returns an `STM` effect that succeeds with the specified lazily evaluated
* value.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const sync: <A>(evaluate: () => A) => STM<never, never, A> = core.sync
/**
* "Peeks" at the success of transactional effect.
*
* @macro traced
* @since 1.0.0
* @category sequencing
*/
export const tap: <A, R2, E2, _>(f: (a: A) => STM<R2, E2, _>) => <R, E>(self: STM<R, E, A>) => STM<R2 | R, E2 | E, A> =
stm.tap
/**
* "Peeks" at both sides of an transactional effect.
*
* @macro traced
* @since 1.0.0
* @category sequencing
*/
export const tapBoth: <E, R2, E2, A2, A, R3, E3, A3>(
f: (error: E) => STM<R2, E2, A2>,
g: (value: A) => STM<R3, E3, A3>
) => <R>(self: STM<R, E, A>) => STM<R2 | R3 | R, E | E2 | E3, A> = stm.tapBoth
/**
* "Peeks" at the error of the transactional effect.
*
* @macro traced
* @since 1.0.0
* @category sequencing
*/
export const tapError: <E, R2, E2, _>(
f: (error: E) => STM<R2, E2, _>
) => <R, A>(self: STM<R, E, A>) => STM<R2 | R, E | E2, A> = stm.tapError
/**
* Imports a synchronous side-effect into a pure value, translating any thrown
* exceptions into typed failed effects.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const tryCatch: <E, A>(attempt: () => A, onThrow: (u: unknown) => E) => Effect.Effect<never, E, A> = stm.tryCatch
/**
* Converts a `STM<R, Either<E, A>, A2>` into a `STM<R, E, Either<A2, A>>`.
* The inverse of `left`.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
export const unleft: <R, E, A, A2>(self: STM<R, Either.Either<E, A>, A2>) => STM<R, E, Either.Either<A2, A>> =
stm.unleft
/**
* The moral equivalent of `if (!p) exp`
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const unless: (predicate: LazyArg<boolean>) => <R, E, A>(self: STM<R, E, A>) => STM<R, E, Option.Option<A>> =
stm.unless
/**
* The moral equivalent of `if (!p) exp` when `p` has side-effects
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const unlessSTM: <R2, E2>(
predicate: STM<R2, E2, boolean>
) => <R, E, A>(self: STM<R, E, A>) => STM<R2 | R, E2 | E, Option.Option<A>> = stm.unlessSTM
/**
* Converts a `STM<R, Either<A, E>, A2>` into a `STM<R, E, Either<A, A2>>`.
* The inverse of `right`.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
export const unright: <R, E, A, A2>(self: STM<R, Either.Either<A, E>, A2>) => STM<R, E, Either.Either<A, A2>> =
stm.unright
/**
* Converts an option on errors into an option on values.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
export const unsome: <R, E, A>(self: STM<R, Option.Option<E>, A>) => STM<R, E, Option.Option<A>> = stm.unsome
/**
* Sequentially zips this value with the specified one.
*
* @macro traced
* @since 1.0.0
* @category zipping

@@ -217,2 +1467,5 @@ */

/**
* Sequentially zips this value with the specified one, discarding the second
* element of the tuple.
*
* @macro traced

@@ -227,2 +1480,5 @@ * @since 1.0.0

/**
* Sequentially zips this value with the specified one, discarding the first
* element of the tuple.
*
* @macro traced

@@ -237,2 +1493,5 @@ * @since 1.0.0

/**
* Sequentially zips this value with the specified one, combining the values
* using the specified combiner function.
*
* @macro traced

@@ -246,1 +1505,83 @@ * @since 1.0.0

) => <R, E>(self: STM<R, E, A>) => STM<R1 | R, E1 | E, A2> = core.zipWith
/**
* Returns an `STM` effect that succeeds with `Unit`.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export const unit: () => STM<never, never, void> = stm.unit
/**
* Feeds elements of type `A` to `f` and accumulates all errors in error
* channel or successes in success channel.
*
* This combinator is lossy meaning that if there are errors all successes
* will be lost. To retain all information please use `STM.partition`.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const validateAll: <R, E, A, B>(
f: (a: A) => STM<R, E, B>
) => (elements: Iterable<A>) => STM<R, Chunk.NonEmptyChunk<E>, Chunk.Chunk<B>> = stm.validateAll
/**
* Feeds elements of type `A` to `f` until it succeeds. Returns first success
* or the accumulation of all errors.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const validateFirst: <R, E, A, B>(
f: (a: A) => STM<R, E, B>
) => (elements: Iterable<A>) => STM<R, Chunk.Chunk<E>, B> = stm.validateFirst
/**
* The moral equivalent of `if (p) exp`.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const when: (predicate: LazyArg<boolean>) => <R, E, A>(self: STM<R, E, A>) => STM<R, E, Option.Option<A>> =
stm.when
/**
* Runs an effect when the supplied partial function matches for the given
* value, otherwise does nothing.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const whenCase: <R, E, A, B>(
evaluate: () => A,
pf: (a: A) => Option.Option<STM<R, E, B>>
) => STM<R, E, Option.Option<B>> = stm.whenCase
/**
* Runs an effect when the supplied partial function matches for the given
* effectful value, otherwise does nothing.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const whenCaseSTM: <A, R2, E2, A2>(
pf: (a: A) => Option.Option<STM<R2, E2, A2>>
) => <R, E>(self: STM<R, E, A>) => STM<R2 | R, E2 | E, Option.Option<A2>> = stm.whenCaseSTM
/**
* The moral equivalent of `if (p) exp` when `p` has side-effects.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export const whenSTM: <R2, E2>(
predicate: STM<R2, E2, boolean>
) => <R, E, A>(self: STM<R, E, A>) => STM<R2 | R, E2 | E, Option.Option<A>> = stm.whenSTM
/**
* @since 1.0.0
*/
import type * as Cause from "@effect/io/Cause";
import type * as Effect from "@effect/io/Effect";
import type * as FiberId from "@effect/io/Fiber/Id";
import type * as Chunk from "@fp-ts/data/Chunk";
import type * as Context from "@fp-ts/data/Context";
import type * as Either from "@fp-ts/data/Either";
import type { LazyArg } from "@fp-ts/data/Function";
import type * as Option from "@fp-ts/data/Option";
import type { Predicate } from "@fp-ts/data/Predicate";
/**

@@ -72,4 +79,58 @@ * @since 1.0.0

/**
* Returns an effect that submerges the error case of an `Either` into the
* `STM`. The inverse operation of `STM.either`.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const absolve: <R, E, E2, A>(self: STM<R, E, Either.Either<E2, A>>) => STM<R, E | E2, A>;
/**
* Maps the success value of this effect to the specified constant value.
*
* @macro traced
* @since 1.0.0
* @category mapping
*/
export declare const as: <A2>(value: A2) => <R, E, A>(self: STM<R, E, A>) => STM<R, E, A2>;
/**
* Maps the success value of this effect to an optional value.
*
* @macro traced
* @since 1.0.0
* @category mapping
*/
export declare const asSome: <R, E, A>(self: STM<R, E, A>) => STM<R, E, Option.Option<A>>;
/**
* Maps the error value of this effect to an optional value.
*
* @macro traced
* @since 1.0.0
* @category mapping
*/
export declare const asSomeError: <R, E, A>(self: STM<R, E, A>) => STM<R, Option.Option<E>, A>;
/**
* Treats the specified `acquire` transaction as the acquisition of a
* resource. The `acquire` transaction will be executed interruptibly. If it
* is a success and is committed the specified `release` workflow will be
* executed uninterruptibly as soon as the `use` workflow completes execution.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const acquireUseRelease: <R, E, A, R2, E2, A2, R3, E3, A3>(acquire: STM<R, E, A>, use: (resource: A) => STM<R2, E2, A2>, release: (resource: A) => STM<R3, E3, A3>) => Effect.Effect<R | R2 | R3, E | E2 | E3, A2>;
/**
* Creates an `STM` value from a partial (but pure) function.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const attempt: <A>(evaluate: LazyArg<A>) => STM<never, unknown, A>;
/**
* Recovers from all errors.
*
* @macro traced
* @since 1.0.0
* @category error handling

@@ -79,4 +140,68 @@ */

/**
* Recovers from some or all of the error cases.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
export declare const catchSome: <E, R2, E2, A2>(pf: (error: E) => Option.Option<STM<R2, E2, A2>>) => <R, A>(self: STM<R, E, A>) => STM<R2 | R, E | E2, A2 | A>;
/**
* Checks the condition, and if it's true, returns unit, otherwise, retries.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const check: (predicate: LazyArg<boolean>) => STM<never, never, void>;
/**
* Simultaneously filters and maps the value produced by this effect.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const collect: <A, A2>(pf: (a: A) => Option.Option<A2>) => <R, E>(self: STM<R, E, A>) => STM<R, E, A2>;
/**
* Collects all the transactional effects in a collection, returning a single
* transactional effect that produces a collection of values.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const collectAll: <R, E, A>(iterable: Iterable<STM<R, E, A>>) => STM<R, E, Chunk.Chunk<A>>;
/**
* Collects all the transactional effects, returning a single transactional
* effect that produces `Unit`.
*
* Equivalent to `pipe(icollectAll(iterable), asUnit)`, but without the cost
* of building the list of results.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const collectAllDiscard: <R, E, A>(iterable: Iterable<STM<R, E, A>>) => STM<R, E, void>;
/**
* Collects the first element of the `Iterable<A>` for which the effectual
* function `f` returns `Some`.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const collectFirst: <A, R, E, A2>(pf: (a: A) => STM<R, E, Option.Option<A2>>) => (iterable: Iterable<A>) => STM<R, E, Option.Option<A2>>;
/**
* Simultaneously filters and flatMaps the value produced by this effect.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const collectSTM: <A, R2, E2, A2>(pf: (a: A) => Option.Option<STM<R2, E2, A2>>) => <R, E>(self: STM<R, E, A>) => STM<R2 | R, E2 | E, A2>;
/**
* Commits this transaction atomically.
*
* @macro traced
* @since 1.0.0
* @category destructors

@@ -86,10 +211,59 @@ */

/**
* Commits this transaction atomically, regardless of whether the transaction
* is a success or a failure.
*
* @macro traced
* @since 1.0.0
* @category destructors
*/
export declare const commitEither: <R, E, A>(self: STM<R, E, A>) => Effect.Effect<R, E, A>;
/**
* Similar to Either.cond, evaluate the predicate, return the given A as
* success if predicate returns true, and the given E as error otherwise
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const cond: <E, A>(predicate: LazyArg<boolean>, error: LazyArg<E>, result: LazyArg<A>) => STM<never, E, A>;
/**
* Fails the transactional effect with the specified defect.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const die: (defect: unknown) => STM<never, never, never>;
/**
* Kills the fiber running the effect with a `Cause.RuntimeException` that
* contains the specified message.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const dieMessage: (message: string) => STM<never, never, never>;
/**
* Fails the transactional effect with the specified lazily evaluated defect.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const dieSync: (evaluate: LazyArg<unknown>) => STM<never, never, never>;
/**
* Converts the failure channel into an `Either`.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const either: <R, E, A>(self: STM<R, E, A>) => STM<R, never, Either.Either<E, A>>;
/**
* Executes the specified finalization transaction whether or not this effect
* succeeds. Note that as with all STM transactions, if the full transaction
* fails, everything will be rolled back.
*
* @macro traced
* @since 1.0.0
* @category finalization

@@ -99,2 +273,4 @@ */

/**
* Retrieves the environment inside an stm.
*
* @macro traced

@@ -104,6 +280,134 @@ * @since 1.0.0

*/
export declare const environment: <R>() => STM<R, never, Context.Context<R>>;
/**
* Accesses the environment of the transaction to perform a transaction.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const environmentWith: <R0, R>(f: (environment: Context.Context<R0>) => R) => STM<R0, never, R>;
/**
* Accesses the environment of the transaction to perform a transaction.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const environmentWithSTM: <R0, R, E, A>(f: (environment: Context.Context<R0>) => STM<R, E, A>) => STM<R0 | R, E, A>;
/**
* Returns an effect that ignores errors and runs repeatedly until it
* eventually succeeds.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const eventually: <R, E, A>(self: STM<R, E, A>) => STM<R, E, A>;
/**
* Determines whether all elements of the `Iterable<A>` satisfy the effectual
* predicate.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const every: <A, R, E>(predicate: (a: A) => STM<R, E, boolean>) => (iterable: Iterable<A>) => STM<R, E, boolean>;
/**
* Determines whether any element of the `Iterable[A]` satisfies the effectual
* predicate `f`.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const exists: <A, R, E>(predicate: (a: A) => STM<R, E, boolean>) => (iterable: Iterable<A>) => STM<R, E, boolean>;
/**
* Fails the transactional effect with the specified error.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const fail: <E>(error: E) => STM<never, E, never>;
/**
* Fails the transactional effect with the specified lazily evaluated error.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const failSync: <E>(evaluate: LazyArg<E>) => STM<never, E, never>;
/**
* Returns the fiber id of the fiber committing the transaction.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const fiberId: () => STM<never, never, FiberId.FiberId>;
/**
* Filters the collection using the specified effectual predicate.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const filter: <A, R, E>(predicate: (a: A) => STM<R, E, boolean>) => (iterable: Iterable<A>) => STM<R, E, Chunk.Chunk<A>>;
/**
* Filters the collection using the specified effectual predicate, removing
* all elements that satisfy the predicate.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const filterNot: <A, R, E>(predicate: (a: A) => STM<R, E, boolean>) => (iterable: Iterable<A>) => STM<R, E, Chunk.Chunk<A>>;
/**
* Dies with specified defect if the predicate fails.
*
* @macro traced
* @since 1.0.0
* @category filtering
*/
export declare const filterOrDie: <A>(predicate: Predicate<A>, defect: LazyArg<unknown>) => <R, E>(self: STM<R, E, A>) => STM<R, E, A>;
/**
* Dies with a `Cause.RuntimeException` having the specified message if the
* predicate fails.
*
* @macro traced
* @since 1.0.0
* @category filtering
*/
export declare const filterOrDieMessage: <A>(predicate: Predicate<A>, message: string) => <R, E>(self: STM<R, E, A>) => STM<R, E, A>;
/**
* Supplies `orElse` if the predicate fails.
*
* @macro traced
* @since 1.0.0
* @category filtering
*/
export declare const filterOrElse: <A, R2, E2, A2>(predicate: Predicate<A>, orElse: LazyArg<STM<R2, E2, A2>>) => <R, E>(self: STM<R, E, A>) => STM<R2 | R, E2 | E, A | A2>;
/**
* Applies `orElse` if the predicate fails.
*
* @macro traced
* @since 1.0.0
* @category filtering
*/
export declare const filterOrElseWith: <A, R2, E2, A2>(predicate: Predicate<A>, orElse: (a: A) => STM<R2, E2, A2>) => <R, E>(self: STM<R, E, A>) => STM<R2 | R, E2 | E, A | A2>;
/**
* Fails with the specified error if the predicate fails.
*
* @macro traced
* @since 1.0.0
* @category filtering
*/
export declare const filterOrFail: <A, E2>(predicate: Predicate<A>, error: LazyArg<E2>) => <R, E>(self: STM<R, E, A>) => STM<R, E2 | E, A>;
/**
* Feeds the value produced by this effect to the specified function, and then
* runs the returned effect as well to produce its results.
*
* @macro traced
* @since 1.0.0
* @category sequencing

@@ -113,16 +417,228 @@ */

/**
* Creates a composite effect that represents this effect followed by another
* one that may depend on the error produced by this one.
*
* @macro traced
* @since 1.0.0
* @category sequencing
*/
export declare const flatMapError: <E, R2, E2>(f: (error: E) => STM<R2, never, E2>) => <R, A>(self: STM<R, E, A>) => STM<R2 | R, E2, A>;
/**
* Flattens out a nested `STM` effect.
*
* @macro traced
* @since 1.0.0
* @category sequencing
*/
export declare const flatten: <R, E, R2, E2, A>(self: STM<R, E, STM<R2, E2, A>>) => STM<R | R2, E | E2, A>;
/**
* Unwraps the optional error, defaulting to the provided value.
*
* @macro traced
* @since 1.0.0
* @category sequencing
*/
export declare const flattenErrorOption: <E2>(fallback: LazyArg<E2>) => <R, E, A>(self: STM<R, Option.Option<E>, A>) => STM<R, E2 | E, A>;
/**
* Flips the success and failure channels of this transactional effect. This
* allows you to use all methods on the error channel, possibly before
* flipping back.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const flip: <R, E, A>(self: STM<R, E, A>) => STM<R, A, E>;
/**
* Swaps the error/value parameters, applies the function `f` and flips the
* parameters back
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const flipWith: <R, A, E, R2, A2, E2>(f: (stm: STM<R, A, E>) => STM<R2, A2, E2>) => (self: STM<R, E, A>) => STM<R | R2, E | E2, A | A2>;
/**
* Folds over the `STM` effect, handling both failure and success, but not
* retry.
*
* @macro traced
* @since 1.0.0
* @category folding
*/
export declare const fold: <E, A2, A, A3>(f: (error: E) => A2, g: (value: A) => A3) => <R>(self: STM<R, E, A>) => STM<R, E, A2 | A3>;
/**
* Effectfully folds over the `STM` effect, handling both failure and success.
*
* @macro traced
* @since 1.0.0
* @category folding
*/
export declare const foldSTM: <E, R1, E1, A1, A, R2, E2, A2>(onFailure: (e: E) => STM<R1, E1, A1>, onSuccess: (a: A) => STM<R2, E2, A2>) => <R>(self: STM<R, E, A>) => STM<R1 | R2 | R, E1 | E2, A1 | A2>;
/**
* Applies the function `f` to each element of the `Iterable<A>` and returns
* a transactional effect that produces a new `Chunk<A2>`.
*
* @macro traced
* @since 1.0.0
* @category traversing
*/
export declare const forEach: <A, R, E, A2>(f: (a: A) => STM<R, E, A2>) => (elements: Iterable<A>) => STM<R, E, Chunk.Chunk<A2>>;
/**
* Applies the function `f` to each element of the `Iterable<A>` and returns a
* transactional effect that produces the unit result.
*
* Equivalent to `pipe(as, forEach(f), asUnit)`, but without the cost of
* building the list of results.
*
* @macro traced
* @since 1.0.0
* @category traversing
*/
export declare const forEachDiscard: <A, R, E, _>(f: (a: A) => STM<R, E, _>) => (iterable: Iterable<A>) => STM<R, E, void>;
/**
* Lifts an `Either` into a `STM`.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const fromEither: <E, A>(either: Either.Either<E, A>) => STM<never, E, A>;
/**
* Lifts an `Option` into a `STM`.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const fromOption: <A>(option: Option.Option<A>) => STM<never, Option.Option<never>, A>;
/**
* 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.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
export declare const head: <R, E, A>(self: STM<R, E, Iterable<A>>) => STM<R, Option.Option<E>, A>;
/**
* Runs `onTrue` if the result of `b` is `true` and `onFalse` otherwise.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const ifSTM: <R1, R2, E1, E2, A, A1>(onTrue: STM<R1, E1, A>, onFalse: STM<R2, E2, A1>) => <R, E>(self: STM<R, E, boolean>) => STM<R1 | R2 | R, E1 | E2 | E, A | A1>;
/**
* Returns a new effect that ignores the success or failure of this effect.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const ignore: <R, E, A>(self: STM<R, E, A>) => STM<R, never, void>;
/**
* Interrupts the fiber running the effect.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const interrupt: () => STM<never, never, never>;
/**
* Interrupts the fiber running the effect with the specified `FiberId`.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const interruptWith: (fiberId: FiberId.FiberId) => STM<never, never, never>;
/**
* Returns whether this transactional effect is a failure.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
export declare const isFailure: <R, E, A>(self: STM<R, E, A>) => STM<R, never, boolean>;
/**
* Returns whether this transactional effect is a success.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
export declare const isSuccess: <R, E, A>(self: STM<R, E, A>) => STM<R, never, boolean>;
/**
* Iterates with the specified transactional function. The moral equivalent
* of:
*
* ```ts
* const s = initial
*
* while (cont(s)) {
* s = body(s)
* }
*
* return s
* ```
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const iterate: <Z>(initial: Z, cont: (z: Z) => boolean) => <R, E>(body: (z: Z) => STM<R, E, Z>) => STM<R, E, Z>;
/**
* "Zooms in" on the value in the `Left` side of an `Either`, moving the
* possibility that the value is a `Right` to the error channel.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
export declare const left: <R, E, A, A2>(self: STM<R, E, Either.Either<A, A2>>) => STM<R, Either.Either<E, A2>, A>;
/**
* Loops with the specified transactional function, collecting the results
* into a list. The moral equivalent of:
*
* ```ts
* const as = []
* let s = initial
*
* while (cont(s)) {
* as.push(body(s))
* s = inc(s)
* }
*
* return as
* ```
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const loop: <Z, R, E, A>(initial: Z, cont: (z: Z) => boolean, inc: (z: Z) => Z, body: (z: Z) => STM<R, E, A>) => STM<R, E, Chunk.Chunk<A>>;
/**
* Loops with the specified transactional function purely for its
* transactional effects. The moral equivalent of:
*
* ```ts
* let s = initial
*
* while (cont(s)) {
* body(s)
* s = inc(s)
* }
* ```
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const loopDiscard: <Z, R, E, X>(initial: Z, cont: (z: Z) => boolean, inc: (z: Z) => Z, body: (z: Z) => STM<R, E, X>) => STM<R, E, void>;
/**
* Maps the value produced by the effect.
*
* @macro traced
* @since 1.0.0
* @category mapping

@@ -132,16 +648,299 @@ */

/**
* Maps the value produced by the effect with the specified function that may
* throw exceptions but is otherwise pure, translating any thrown exceptions
* into typed failed effects.
*
* @macro traced
* @since 1.0.0
* @category mapping
*/
export declare const mapAttempt: <A, B>(f: (a: A) => B) => <R, E>(self: STM<R, E, A>) => STM<R, unknown, B>;
/**
* Returns an `STM` effect whose failure and success channels have been mapped
* by the specified pair of functions, `f` and `g`.
*
* @macro traced
* @since 1.0.0
* @category mapping
*/
export declare const mapBoth: <E, E2, A, A2>(f: (error: E) => E2, g: (value: A) => A2) => <R>(self: STM<R, E, A>) => STM<R, E2, A2>;
/**
* Maps from one error type to another.
*
* @macro traced
* @since 1.0.0
* @category mapping
*/
export declare const mapError: <E, E2>(f: (error: E) => E2) => <R, A>(self: STM<R, E, A>) => STM<R, E2, A>;
/**
* Returns a new effect where the error channel has been merged into the
* success channel to their common combined type.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const merge: <R, E, A>(self: STM<R, E, A>) => STM<R, never, E | A>;
/**
* Merges an `Iterable<STM>` to a single `STM`, working sequentially.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const mergeAll: <A2, A>(zero: A2, f: (a2: A2, a: A) => A2) => <R, E>(iterable: Iterable<STM<R, E, A>>) => STM<R, E, A2>;
/**
* Returns a new effect where boolean value of this effect is negated.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const negate: <R, E>(self: STM<R, E, boolean>) => STM<R, E, boolean>;
/**
* Requires the option produced by this value to be `None`.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const none: <R, E, A>(self: STM<R, E, Option.Option<A>>) => STM<R, Option.Option<E>, void>;
/**
* Converts the failure channel into an `Option`.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const option: <R, E, A>(self: STM<R, E, A>) => STM<R, never, Option.Option<A>>;
/**
* Translates `STM` effect failure into death of the fiber, making all
* failures unchecked and not a part of the type of the effect.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
export declare const orDie: <R, E, A>(self: STM<R, E, A>) => STM<R, never, A>;
/**
* Keeps none of the errors, and terminates the fiber running the `STM` effect
* with them, using the specified function to convert the `E` into a defect.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
export declare const orDieWith: <E>(f: (error: E) => unknown) => <R, A>(self: STM<R, E, A>) => STM<R, never, A>;
/**
* Tries this effect first, and if it fails or retries, tries the other
* effect.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
export declare const orElse: <R2, E2, A2>(that: LazyArg<STM<R2, E2, A2>>) => <R, E, A>(self: STM<R, E, A>) => STM<R2 | R, E2, A2 | A>;
/**
* Returns a transactional effect that will produce the value of this effect
* in left side, unless it fails or retries, in which case, it will produce
* the value of the specified effect in right side.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
export declare const orElseEither: <R2, E2, A2>(that: LazyArg<STM<R2, E2, A2>>) => <R, E, A>(self: STM<R, E, A>) => STM<R2 | R, E2, Either.Either<A, A2>>;
/**
* Tries this effect first, and if it fails or retries, fails with the
* specified error.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
export declare const orElseFail: <E2>(error: LazyArg<E2>) => <R, E, A>(self: STM<R, E, A>) => STM<R, E2, A>;
/**
* Returns an effect that will produce the value of this effect, unless it
* fails with the `None` value, in which case it will produce the value of the
* specified effect.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
export declare const orElseOptional: <R2, E2, A2>(that: LazyArg<STM<R2, Option.Option<E2>, A2>>) => <R, E, A>(self: STM<R, Option.Option<E>, A>) => STM<R2 | R, Option.Option<E2 | E>, A2 | A>;
/**
* Tries this effect first, and if it fails or retries, succeeds with the
* specified value.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
export declare const orElseSucceed: <A2>(value: LazyArg<A2>) => <R, E, A>(self: STM<R, E, A>) => STM<R, never, A2 | A>;
/**
* Tries this effect first, and if it enters retry, then it tries the other
* effect. This is an equivalent of Haskell's orElse.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
export declare const orTry: <R1, E1, A1>(that: () => STM<R1, E1, A1>) => <R, E, A>(self: STM<R, E, A>) => STM<R1 | R, E1 | E, A1 | A>;
/**
* Feeds elements of type `A` to a function `f` that returns an effect.
* Collects all successes and failures in a tupled fashion.
*
* @macro traced
* @since 1.0.0
* @category traversing
*/
export declare const partition: <R, E, A, A2>(f: (a: A) => STM<R, E, A2>) => (elements: Iterable<A>) => STM<R, E, readonly [Chunk.Chunk<E>, Chunk.Chunk<A2>]>;
/**
* Provides the transaction its required environment, which eliminates its
* dependency on `R`.
*
* @macro traced
* @since 1.0.0
* @category environment
*/
export declare const provideEnvironment: <R>(env: Context.Context<R>) => <E, A>(self: STM<R, E, A>) => STM<never, E, A>;
/**
* Transforms the environment being provided to this effect with the specified
* function.
*
* @macro traced
* @since 1.0.0
* @category environment
*/
export declare const provideSomeEnvironment: <R0, R>(f: (context: Context.Context<R0>) => Context.Context<R>) => <E, A>(self: STM<R, E, A>) => STM<R0, E, A>;
/**
* Folds an `Iterable<A>` using an effectual function f, working sequentially
* from left to right.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const reduce: <S, A, R, E>(zero: S, f: (s: S, a: A) => STM<R, E, S>) => (iterable: Iterable<A>) => STM<R, E, S>;
/**
* Reduces an `Iterable<STM>` to a single `STM`, working sequentially.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const reduceAll: <R2, E2, A>(initial: STM<R2, E2, A>, f: (x: A, y: A) => A) => <R, E>(iterable: Iterable<STM<R, E, A>>) => STM<R2 | R, E2 | E, A>;
/**
* Folds an `Iterable<A>` using an effectual function f, working sequentially
* from right to left.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const reduceRight: <S, A, R, E>(zero: S, f: (s: S, a: A) => STM<R, E, S>) => (iterable: Iterable<A>) => STM<R, E, S>;
/**
* Keeps some of the errors, and terminates the fiber with the rest.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const refineOrDie: <E, E2>(pf: (error: E) => Option.Option<E2>) => <R, A>(self: STM<R, E, A>) => STM<R, E2, A>;
/**
* Keeps some of the errors, and terminates the fiber with the rest, using the
* specified function to convert the `E` into a `Throwable`.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const refineOrDieWith: <E, E2>(pf: (error: E) => Option.Option<E2>, f: (error: E) => unknown) => <R, A>(self: STM<R, E, A>) => STM<R, E2, A>;
/**
* Fail with the returned value if the `PartialFunction` matches, otherwise
* continue with our held value.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const reject: <A, E2>(pf: (a: A) => Option.Option<E2>) => <R, E>(self: STM<R, E, A>) => STM<R, E2 | E, A>;
/**
* Continue with the returned computation if the specified partial function
* matches, translating the successful match into a failure, otherwise continue
* with our held value.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const rejectSTM: <A, R2, E2>(pf: (a: A) => Option.Option<STM<R2, E2, E2>>) => <R, E>(self: STM<R, E, A>) => STM<R2 | R, E2 | E, A>;
/**
* 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.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const repeatUntil: <A>(predicate: Predicate<A>) => <R, E>(self: STM<R, E, A>) => STM<R, E, 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.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const repeatWhile: <A>(predicate: Predicate<A>) => <R, E>(self: STM<R, E, A>) => STM<R, E, A>;
/**
* Replicates the given effect n times. If 0 or negative numbers are given, an
* empty `Chunk` will be returned.
*
* @since 1.0.0
* @category constructors
*/
export declare const replicate: (n: number) => <R, E, A>(self: STM<R, E, A>) => Chunk.Chunk<STM<R, E, A>>;
/**
* Performs this transaction the specified number of times and collects the
* results.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const replicateSTM: (n: number) => <R, E, A>(self: STM<R, E, A>) => STM<R, E, Chunk.Chunk<A>>;
/**
* Performs this transaction the specified number of times, discarding the
* results.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const replicateSTMDiscard: (n: number) => <R, E, A>(self: STM<R, E, A>) => STM<R, E, void>;
/**
* Abort and retry the whole transaction when any of the underlying
* transactional variables have changed.
*
* @macro traced
* @since 1.0.0
* @category error handling

@@ -151,8 +950,106 @@ */

/**
* Filters the value produced by this effect, retrying the transaction until
* the predicate returns `true` for the value.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const retryUntil: <A>(predicate: Predicate<A>) => <R, E>(self: STM<R, E, A>) => STM<R, E, A>;
/**
* Filters the value produced by this effect, retrying the transaction while
* the predicate returns `true` for the value.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const retryWhile: <A>(predicate: Predicate<A>) => <R, E>(self: STM<R, E, A>) => STM<R, E, A>;
/**
* "Zooms in" on the value in the `Right` side of an `Either`, moving the
* possibility that the value is a `Left` to the error channel.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
export declare const right: <R, E, A, A2>(self: STM<R, E, Either.Either<A, A2>>) => STM<R, Either.Either<A, E>, A2>;
/**
* Accesses the specified service in the environment of the effect.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const service: <T>(tag: Context.Tag<T>) => STM<T, never, T>;
/**
* Effectfully accesses the specified service in the environment of the
* effect.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const serviceWith: <T>(tag: Context.Tag<T>) => <A>(f: (service: T) => A) => STM<T, never, A>;
/**
* Effectfully accesses the specified service in the environment of the
* effect.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const serviceWithSTM: <T>(tag: Context.Tag<T>) => <R, E, A>(f: (service: T) => STM<R, E, A>) => STM<T | R, E, A>;
/**
* Converts an option on values into an option on errors.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
export declare const some: <R, E, A>(self: STM<R, E, Option.Option<A>>) => STM<R, Option.Option<E>, A>;
/**
* Extracts the optional value, or returns the given 'default'.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
export declare const someOrElse: <A2>(orElse: LazyArg<A2>) => <R, E, A>(self: STM<R, E, Option.Option<A>>) => STM<R, E, A2 | A>;
/**
* Extracts the optional value, or executes the effect 'default'.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
export declare const someOrElseSTM: <R2, E2, A2>(orElse: LazyArg<STM<R2, E2, A2>>) => <R, E, A>(self: STM<R, E, Option.Option<A>>) => STM<R2 | R, E2 | E, A2 | A>;
/**
* Extracts the optional value, or fails with the given error 'e'.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
export declare const someOrFail: <E2>(error: LazyArg<E2>) => <R, E, A>(self: STM<R, E, Option.Option<A>>) => STM<R, E2 | E, A>;
/**
* Extracts the optional value, or fails with a
* `Cause.NoSuchElementException`.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
export declare const someOrFailException: <R, E, A>(self: STM<R, E, Option.Option<A>>) => STM<R, E | Cause.NoSuchElementException, A>;
/**
* Returns an `STM` effect that succeeds with the specified value.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const succeed: <A>(value: A) => STM<never, never, A>;
/**
* Returns an effect with the value on the left part.
*
* @macro traced

@@ -162,6 +1059,134 @@ * @since 1.0.0

*/
export declare const succeedLeft: <A>(value: A) => STM<never, never, Either.Either<A, never>>;
/**
* Returns an effect with the empty value.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const succeedNone: () => STM<never, never, Option.Option<never>>;
/**
* Returns an effect with the value on the right part.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const succeedRight: <A>(value: A) => STM<never, never, Either.Either<never, A>>;
/**
* Returns an effect with the optional value.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const succeedSome: <A>(value: A) => STM<never, never, Option.Option<A>>;
/**
* Summarizes a `STM` effect by computing a provided value before and after
* execution, and then combining the values to produce a summary, together
* with the result of execution.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const summarized: <R2, E2, A2, A3>(summary: STM<R2, E2, A2>, f: (before: A2, after: A2) => A3) => <R, E, A>(self: STM<R, E, A>) => STM<R2 | R, E2 | E, readonly [A3, A]>;
/**
* Suspends creation of the specified transaction lazily.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const suspend: <R, E, A>(evaluate: LazyArg<STM<R, E, A>>) => STM<R, E, A>;
/**
* Returns an `STM` effect that succeeds with the specified lazily evaluated
* value.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const sync: <A>(evaluate: () => A) => STM<never, never, A>;
/**
* "Peeks" at the success of transactional effect.
*
* @macro traced
* @since 1.0.0
* @category sequencing
*/
export declare const tap: <A, R2, E2, _>(f: (a: A) => STM<R2, E2, _>) => <R, E>(self: STM<R, E, A>) => STM<R2 | R, E2 | E, A>;
/**
* "Peeks" at both sides of an transactional effect.
*
* @macro traced
* @since 1.0.0
* @category sequencing
*/
export declare const tapBoth: <E, R2, E2, A2, A, R3, E3, A3>(f: (error: E) => STM<R2, E2, A2>, g: (value: A) => STM<R3, E3, A3>) => <R>(self: STM<R, E, A>) => STM<R2 | R3 | R, E | E2 | E3, A>;
/**
* "Peeks" at the error of the transactional effect.
*
* @macro traced
* @since 1.0.0
* @category sequencing
*/
export declare const tapError: <E, R2, E2, _>(f: (error: E) => STM<R2, E2, _>) => <R, A>(self: STM<R, E, A>) => STM<R2 | R, E | E2, A>;
/**
* Imports a synchronous side-effect into a pure value, translating any thrown
* exceptions into typed failed effects.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const tryCatch: <E, A>(attempt: () => A, onThrow: (u: unknown) => E) => Effect.Effect<never, E, A>;
/**
* Converts a `STM<R, Either<E, A>, A2>` into a `STM<R, E, Either<A2, A>>`.
* The inverse of `left`.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
export declare const unleft: <R, E, A, A2>(self: STM<R, Either.Either<E, A>, A2>) => STM<R, E, Either.Either<A2, A>>;
/**
* The moral equivalent of `if (!p) exp`
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const unless: (predicate: LazyArg<boolean>) => <R, E, A>(self: STM<R, E, A>) => STM<R, E, Option.Option<A>>;
/**
* The moral equivalent of `if (!p) exp` when `p` has side-effects
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const unlessSTM: <R2, E2>(predicate: STM<R2, E2, boolean>) => <R, E, A>(self: STM<R, E, A>) => STM<R2 | R, E2 | E, Option.Option<A>>;
/**
* Converts a `STM<R, Either<A, E>, A2>` into a `STM<R, E, Either<A, A2>>`.
* The inverse of `right`.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
export declare const unright: <R, E, A, A2>(self: STM<R, Either.Either<A, E>, A2>) => STM<R, E, Either.Either<A, A2>>;
/**
* Converts an option on errors into an option on values.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
export declare const unsome: <R, E, A>(self: STM<R, Option.Option<E>, A>) => STM<R, E, Option.Option<A>>;
/**
* Sequentially zips this value with the specified one.
*
* @macro traced
* @since 1.0.0
* @category zipping

@@ -171,2 +1196,5 @@ */

/**
* Sequentially zips this value with the specified one, discarding the second
* element of the tuple.
*
* @macro traced

@@ -178,2 +1206,5 @@ * @since 1.0.0

/**
* Sequentially zips this value with the specified one, discarding the first
* element of the tuple.
*
* @macro traced

@@ -185,2 +1216,5 @@ * @since 1.0.0

/**
* Sequentially zips this value with the specified one, combining the values
* using the specified combiner function.
*
* @macro traced

@@ -191,2 +1225,65 @@ * @since 1.0.0

export declare const zipWith: <R1, E1, A1, A, A2>(that: STM<R1, E1, A1>, f: (a: A, b: A1) => A2) => <R, E>(self: STM<R, E, A>) => STM<R1 | R, E1 | E, A2>;
/**
* Returns an `STM` effect that succeeds with `Unit`.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
export declare const unit: () => STM<never, never, void>;
/**
* Feeds elements of type `A` to `f` and accumulates all errors in error
* channel or successes in success channel.
*
* This combinator is lossy meaning that if there are errors all successes
* will be lost. To retain all information please use `STM.partition`.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const validateAll: <R, E, A, B>(f: (a: A) => STM<R, E, B>) => (elements: Iterable<A>) => STM<R, Chunk.NonEmptyChunk<E>, Chunk.Chunk<B>>;
/**
* Feeds elements of type `A` to `f` until it succeeds. Returns first success
* or the accumulation of all errors.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const validateFirst: <R, E, A, B>(f: (a: A) => STM<R, E, B>) => (elements: Iterable<A>) => STM<R, Chunk.Chunk<E>, B>;
/**
* The moral equivalent of `if (p) exp`.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const when: (predicate: LazyArg<boolean>) => <R, E, A>(self: STM<R, E, A>) => STM<R, E, Option.Option<A>>;
/**
* Runs an effect when the supplied partial function matches for the given
* value, otherwise does nothing.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const whenCase: <R, E, A, B>(evaluate: () => A, pf: (a: A) => Option.Option<STM<R, E, B>>) => STM<R, E, Option.Option<B>>;
/**
* Runs an effect when the supplied partial function matches for the given
* effectful value, otherwise does nothing.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const whenCaseSTM: <A, R2, E2, A2>(pf: (a: A) => Option.Option<STM<R2, E2, A2>>) => <R, E>(self: STM<R, E, A>) => STM<R2 | R, E2 | E, Option.Option<A2>>;
/**
* The moral equivalent of `if (p) exp` when `p` has side-effects.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
export declare const whenSTM: <R2, E2>(predicate: STM<R2, E2, boolean>) => <R, E, A>(self: STM<R, E, A>) => STM<R2 | R, E2 | E, Option.Option<A>>;
//# sourceMappingURL=STM.d.ts.map

1235

STM.js

@@ -6,4 +6,6 @@ "use strict";

});
exports.zipWith = exports.zipRight = exports.zipLeft = exports.zip = exports.sync = exports.succeed = exports.retry = exports.provideSomeEnvironment = exports.orTry = exports.map = exports.interrupt = exports.foldSTM = exports.flatMap = exports.fail = exports.ensuring = exports.die = exports.commit = exports.catchAll = exports.STMTypeId = void 0;
exports.serviceWith = exports.service = exports.right = exports.retryWhile = exports.retryUntil = exports.retry = exports.replicateSTMDiscard = exports.replicateSTM = exports.replicate = exports.repeatWhile = exports.repeatUntil = exports.rejectSTM = exports.reject = exports.refineOrDieWith = exports.refineOrDie = exports.reduceRight = exports.reduceAll = exports.reduce = exports.provideSomeEnvironment = exports.provideEnvironment = exports.partition = exports.orTry = exports.orElseSucceed = exports.orElseOptional = exports.orElseFail = exports.orElseEither = exports.orElse = exports.orDieWith = exports.orDie = exports.option = exports.none = exports.negate = exports.mergeAll = exports.merge = exports.mapError = exports.mapBoth = exports.mapAttempt = exports.map = exports.loopDiscard = exports.loop = exports.left = exports.iterate = exports.isSuccess = exports.isFailure = exports.interruptWith = exports.interrupt = exports.ignore = exports.ifSTM = exports.head = exports.fromOption = exports.fromEither = exports.forEachDiscard = exports.forEach = exports.foldSTM = exports.fold = exports.flipWith = exports.flip = exports.flattenErrorOption = exports.flatten = exports.flatMapError = exports.flatMap = exports.filterOrFail = exports.filterOrElseWith = exports.filterOrElse = exports.filterOrDieMessage = exports.filterOrDie = exports.filterNot = exports.filter = exports.fiberId = exports.failSync = exports.fail = exports.exists = exports.every = exports.eventually = exports.environmentWithSTM = exports.environmentWith = exports.environment = exports.ensuring = exports.either = exports.dieSync = exports.dieMessage = exports.die = exports.cond = exports.commitEither = exports.commit = exports.collectSTM = exports.collectFirst = exports.collectAllDiscard = exports.collectAll = exports.collect = exports.check = exports.catchSome = exports.catchAll = exports.attempt = exports.asSomeError = exports.asSome = exports.as = exports.acquireUseRelease = exports.absolve = exports.STMTypeId = void 0;
exports.zipWith = exports.zipRight = exports.zipLeft = exports.zip = exports.whenSTM = exports.whenCaseSTM = exports.whenCase = exports.when = exports.validateFirst = exports.validateAll = exports.unsome = exports.unright = exports.unlessSTM = exports.unless = exports.unleft = exports.unit = exports.tryCatch = exports.tapError = exports.tapBoth = exports.tap = exports.sync = exports.suspend = exports.summarized = exports.succeedSome = exports.succeedRight = exports.succeedNone = exports.succeedLeft = exports.succeed = exports.someOrFailException = exports.someOrFail = exports.someOrElseSTM = exports.someOrElse = exports.some = exports.serviceWithSTM = void 0;
var core = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/stm/internal/core"));
var stm = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/stm/internal/stm"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

@@ -17,30 +19,217 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

/**
* Returns an effect that submerges the error case of an `Either` into the
* `STM`. The inverse operation of `STM.either`.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.STMTypeId = STMTypeId;
const absolve = stm.absolve;
/**
* Maps the success value of this effect to the specified constant value.
*
* @macro traced
* @since 1.0.0
* @category mapping
*/
exports.absolve = absolve;
const as = stm.as;
/**
* Maps the success value of this effect to an optional value.
*
* @macro traced
* @since 1.0.0
* @category mapping
*/
exports.as = as;
const asSome = stm.asSome;
/**
* Maps the error value of this effect to an optional value.
*
* @macro traced
* @since 1.0.0
* @category mapping
*/
exports.asSome = asSome;
const asSomeError = stm.asSomeError;
/**
* Treats the specified `acquire` transaction as the acquisition of a
* resource. The `acquire` transaction will be executed interruptibly. If it
* is a success and is committed the specified `release` workflow will be
* executed uninterruptibly as soon as the `use` workflow completes execution.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.asSomeError = asSomeError;
const acquireUseRelease = stm.acquireUseRelease;
/**
* Creates an `STM` value from a partial (but pure) function.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.acquireUseRelease = acquireUseRelease;
const attempt = stm.attempt;
/**
* Recovers from all errors.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
exports.STMTypeId = STMTypeId;
exports.attempt = attempt;
const catchAll = core.catchAll;
/**
* Recovers from some or all of the error cases.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
exports.catchAll = catchAll;
const catchSome = stm.catchSome;
/**
* Checks the condition, and if it's true, returns unit, otherwise, retries.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.catchSome = catchSome;
const check = stm.check;
/**
* Simultaneously filters and maps the value produced by this effect.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.check = check;
const collect = stm.collect;
/**
* Collects all the transactional effects in a collection, returning a single
* transactional effect that produces a collection of values.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.collect = collect;
const collectAll = stm.collectAll;
/**
* Collects all the transactional effects, returning a single transactional
* effect that produces `Unit`.
*
* Equivalent to `pipe(icollectAll(iterable), asUnit)`, but without the cost
* of building the list of results.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.collectAll = collectAll;
const collectAllDiscard = stm.collectAllDiscard;
/**
* Collects the first element of the `Iterable<A>` for which the effectual
* function `f` returns `Some`.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.collectAllDiscard = collectAllDiscard;
const collectFirst = stm.collectFirst;
/**
* Simultaneously filters and flatMaps the value produced by this effect.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.collectFirst = collectFirst;
const collectSTM = stm.collectSTM;
/**
* Commits this transaction atomically.
*
* @macro traced
* @since 1.0.0
* @category destructors
*/
exports.catchAll = catchAll;
exports.collectSTM = collectSTM;
const commit = core.commit;
/**
* Commits this transaction atomically, regardless of whether the transaction
* is a success or a failure.
*
* @macro traced
* @since 1.0.0
* @category destructors
*/
exports.commit = commit;
const commitEither = stm.commitEither;
/**
* Similar to Either.cond, evaluate the predicate, return the given A as
* success if predicate returns true, and the given E as error otherwise
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.commit = commit;
exports.commitEither = commitEither;
const cond = stm.cond;
/**
* Fails the transactional effect with the specified defect.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.cond = cond;
const die = core.die;
/**
* Kills the fiber running the effect with a `Cause.RuntimeException` that
* contains the specified message.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.die = die;
const dieMessage = core.dieMessage;
/**
* Fails the transactional effect with the specified lazily evaluated defect.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.dieMessage = dieMessage;
const dieSync = core.dieSync;
/**
* Converts the failure channel into an `Either`.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.dieSync = dieSync;
const either = stm.either;
/**
* Executes the specified finalization transaction whether or not this effect
* succeeds. Note that as with all STM transactions, if the full transaction
* fails, everything will be rolled back.
*
* @macro traced
* @since 1.0.0
* @category finalization
*/
exports.die = die;
exports.either = either;
const ensuring = core.ensuring;
/**
* Retrieves the environment inside an stm.
*
* @macro traced

@@ -51,60 +240,856 @@ * @since 1.0.0

exports.ensuring = ensuring;
const environment = stm.environment;
/**
* Accesses the environment of the transaction to perform a transaction.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.environment = environment;
const environmentWith = stm.environmentWith;
/**
* Accesses the environment of the transaction to perform a transaction.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.environmentWith = environmentWith;
const environmentWithSTM = stm.environmentWithSTM;
/**
* Returns an effect that ignores errors and runs repeatedly until it
* eventually succeeds.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.environmentWithSTM = environmentWithSTM;
const eventually = stm.eventually;
/**
* Determines whether all elements of the `Iterable<A>` satisfy the effectual
* predicate.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.eventually = eventually;
const every = stm.every;
/**
* Determines whether any element of the `Iterable[A]` satisfies the effectual
* predicate `f`.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.every = every;
const exists = stm.exists;
/**
* Fails the transactional effect with the specified error.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.exists = exists;
const fail = core.fail;
/**
* Fails the transactional effect with the specified lazily evaluated error.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.fail = fail;
const failSync = core.failSync;
/**
* Returns the fiber id of the fiber committing the transaction.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.failSync = failSync;
const fiberId = stm.fiberId;
/**
* Filters the collection using the specified effectual predicate.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.fiberId = fiberId;
const filter = stm.filter;
/**
* Filters the collection using the specified effectual predicate, removing
* all elements that satisfy the predicate.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.filter = filter;
const filterNot = stm.filterNot;
/**
* Dies with specified defect if the predicate fails.
*
* @macro traced
* @since 1.0.0
* @category filtering
*/
exports.filterNot = filterNot;
const filterOrDie = stm.filterOrDie;
/**
* Dies with a `Cause.RuntimeException` having the specified message if the
* predicate fails.
*
* @macro traced
* @since 1.0.0
* @category filtering
*/
exports.filterOrDie = filterOrDie;
const filterOrDieMessage = stm.filterOrDieMessage;
/**
* Supplies `orElse` if the predicate fails.
*
* @macro traced
* @since 1.0.0
* @category filtering
*/
exports.filterOrDieMessage = filterOrDieMessage;
const filterOrElse = stm.filterOrElse;
/**
* Applies `orElse` if the predicate fails.
*
* @macro traced
* @since 1.0.0
* @category filtering
*/
exports.filterOrElse = filterOrElse;
const filterOrElseWith = stm.filterOrElseWith;
/**
* Fails with the specified error if the predicate fails.
*
* @macro traced
* @since 1.0.0
* @category filtering
*/
exports.filterOrElseWith = filterOrElseWith;
const filterOrFail = stm.filterOrFail;
/**
* Feeds the value produced by this effect to the specified function, and then
* runs the returned effect as well to produce its results.
*
* @macro traced
* @since 1.0.0
* @category sequencing
*/
exports.fail = fail;
exports.filterOrFail = filterOrFail;
const flatMap = core.flatMap;
/**
* Creates a composite effect that represents this effect followed by another
* one that may depend on the error produced by this one.
*
* @macro traced
* @since 1.0.0
* @category sequencing
*/
exports.flatMap = flatMap;
const flatMapError = stm.flatMapError;
/**
* Flattens out a nested `STM` effect.
*
* @macro traced
* @since 1.0.0
* @category sequencing
*/
exports.flatMapError = flatMapError;
const flatten = stm.flatten;
/**
* Unwraps the optional error, defaulting to the provided value.
*
* @macro traced
* @since 1.0.0
* @category sequencing
*/
exports.flatten = flatten;
const flattenErrorOption = stm.flattenErrorOption;
/**
* Flips the success and failure channels of this transactional effect. This
* allows you to use all methods on the error channel, possibly before
* flipping back.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.flattenErrorOption = flattenErrorOption;
const flip = stm.flip;
/**
* Swaps the error/value parameters, applies the function `f` and flips the
* parameters back
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.flip = flip;
const flipWith = stm.flipWith;
/**
* Folds over the `STM` effect, handling both failure and success, but not
* retry.
*
* @macro traced
* @since 1.0.0
* @category folding
*/
exports.flatMap = flatMap;
exports.flipWith = flipWith;
const fold = stm.fold;
/**
* Effectfully folds over the `STM` effect, handling both failure and success.
*
* @macro traced
* @since 1.0.0
* @category folding
*/
exports.fold = fold;
const foldSTM = core.foldSTM;
/**
* Applies the function `f` to each element of the `Iterable<A>` and returns
* a transactional effect that produces a new `Chunk<A2>`.
*
* @macro traced
* @since 1.0.0
* @category traversing
*/
exports.foldSTM = foldSTM;
const forEach = stm.forEach;
/**
* Applies the function `f` to each element of the `Iterable<A>` and returns a
* transactional effect that produces the unit result.
*
* Equivalent to `pipe(as, forEach(f), asUnit)`, but without the cost of
* building the list of results.
*
* @macro traced
* @since 1.0.0
* @category traversing
*/
exports.forEach = forEach;
const forEachDiscard = stm.forEachDiscard;
/**
* Lifts an `Either` into a `STM`.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.foldSTM = foldSTM;
exports.forEachDiscard = forEachDiscard;
const fromEither = stm.fromEither;
/**
* Lifts an `Option` into a `STM`.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.fromEither = fromEither;
const fromOption = stm.fromOption;
/**
* 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.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
exports.fromOption = fromOption;
const head = stm.head;
/**
* Runs `onTrue` if the result of `b` is `true` and `onFalse` otherwise.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.head = head;
const ifSTM = stm.ifSTM;
/**
* Returns a new effect that ignores the success or failure of this effect.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.ifSTM = ifSTM;
const ignore = stm.ignore;
/**
* Interrupts the fiber running the effect.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.ignore = ignore;
const interrupt = core.interrupt;
/**
* Interrupts the fiber running the effect with the specified `FiberId`.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.interrupt = interrupt;
const interruptWith = core.interruptWith;
/**
* Returns whether this transactional effect is a failure.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
exports.interruptWith = interruptWith;
const isFailure = stm.isFailure;
/**
* Returns whether this transactional effect is a success.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
exports.isFailure = isFailure;
const isSuccess = stm.isSuccess;
/**
* Iterates with the specified transactional function. The moral equivalent
* of:
*
* ```ts
* const s = initial
*
* while (cont(s)) {
* s = body(s)
* }
*
* return s
* ```
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.isSuccess = isSuccess;
const iterate = stm.iterate;
/**
* "Zooms in" on the value in the `Left` side of an `Either`, moving the
* possibility that the value is a `Right` to the error channel.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
exports.iterate = iterate;
const left = stm.left;
/**
* Loops with the specified transactional function, collecting the results
* into a list. The moral equivalent of:
*
* ```ts
* const as = []
* let s = initial
*
* while (cont(s)) {
* as.push(body(s))
* s = inc(s)
* }
*
* return as
* ```
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.left = left;
const loop = stm.loop;
/**
* Loops with the specified transactional function purely for its
* transactional effects. The moral equivalent of:
*
* ```ts
* let s = initial
*
* while (cont(s)) {
* body(s)
* s = inc(s)
* }
* ```
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.loop = loop;
const loopDiscard = stm.loopDiscard;
/**
* Maps the value produced by the effect.
*
* @macro traced
* @since 1.0.0
* @category mapping
*/
exports.interrupt = interrupt;
exports.loopDiscard = loopDiscard;
const map = core.map;
/**
* Maps the value produced by the effect with the specified function that may
* throw exceptions but is otherwise pure, translating any thrown exceptions
* into typed failed effects.
*
* @macro traced
* @since 1.0.0
* @category mapping
*/
exports.map = map;
const mapAttempt = stm.mapAttempt;
/**
* Returns an `STM` effect whose failure and success channels have been mapped
* by the specified pair of functions, `f` and `g`.
*
* @macro traced
* @since 1.0.0
* @category mapping
*/
exports.mapAttempt = mapAttempt;
const mapBoth = stm.mapBoth;
/**
* Maps from one error type to another.
*
* @macro traced
* @since 1.0.0
* @category mapping
*/
exports.mapBoth = mapBoth;
const mapError = stm.mapError;
/**
* Returns a new effect where the error channel has been merged into the
* success channel to their common combined type.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.mapError = mapError;
const merge = stm.merge;
/**
* Merges an `Iterable<STM>` to a single `STM`, working sequentially.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.merge = merge;
const mergeAll = stm.mergeAll;
/**
* Returns a new effect where boolean value of this effect is negated.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.mergeAll = mergeAll;
const negate = stm.negate;
/**
* Requires the option produced by this value to be `None`.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.negate = negate;
const none = stm.none;
/**
* Converts the failure channel into an `Option`.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.none = none;
const option = stm.option;
/**
* Translates `STM` effect failure into death of the fiber, making all
* failures unchecked and not a part of the type of the effect.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
exports.map = map;
exports.option = option;
const orDie = stm.orDie;
/**
* Keeps none of the errors, and terminates the fiber running the `STM` effect
* with them, using the specified function to convert the `E` into a defect.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
exports.orDie = orDie;
const orDieWith = stm.orDieWith;
/**
* Tries this effect first, and if it fails or retries, tries the other
* effect.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
exports.orDieWith = orDieWith;
const orElse = stm.orElse;
/**
* Returns a transactional effect that will produce the value of this effect
* in left side, unless it fails or retries, in which case, it will produce
* the value of the specified effect in right side.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
exports.orElse = orElse;
const orElseEither = stm.orElseEither;
/**
* Tries this effect first, and if it fails or retries, fails with the
* specified error.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
exports.orElseEither = orElseEither;
const orElseFail = stm.orElseFail;
/**
* Returns an effect that will produce the value of this effect, unless it
* fails with the `None` value, in which case it will produce the value of the
* specified effect.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
exports.orElseFail = orElseFail;
const orElseOptional = stm.orElseOptional;
/**
* Tries this effect first, and if it fails or retries, succeeds with the
* specified value.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
exports.orElseOptional = orElseOptional;
const orElseSucceed = stm.orElseSucceed;
/**
* Tries this effect first, and if it enters retry, then it tries the other
* effect. This is an equivalent of Haskell's orElse.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
exports.orElseSucceed = orElseSucceed;
const orTry = core.orTry;
/**
* Feeds elements of type `A` to a function `f` that returns an effect.
* Collects all successes and failures in a tupled fashion.
*
* @macro traced
* @since 1.0.0
* @category traversing
*/
exports.orTry = orTry;
const partition = stm.partition;
/**
* Provides the transaction its required environment, which eliminates its
* dependency on `R`.
*
* @macro traced
* @since 1.0.0
* @category environment
*/
exports.orTry = orTry;
exports.partition = partition;
const provideEnvironment = stm.provideEnvironment;
/**
* Transforms the environment being provided to this effect with the specified
* function.
*
* @macro traced
* @since 1.0.0
* @category environment
*/
exports.provideEnvironment = provideEnvironment;
const provideSomeEnvironment = core.provideSomeEnvironment;
/**
* Folds an `Iterable<A>` using an effectual function f, working sequentially
* from left to right.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.provideSomeEnvironment = provideSomeEnvironment;
const reduce = stm.reduce;
/**
* Reduces an `Iterable<STM>` to a single `STM`, working sequentially.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.reduce = reduce;
const reduceAll = stm.reduceAll;
/**
* Folds an `Iterable<A>` using an effectual function f, working sequentially
* from right to left.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.reduceAll = reduceAll;
const reduceRight = stm.reduceRight;
/**
* Keeps some of the errors, and terminates the fiber with the rest.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.reduceRight = reduceRight;
const refineOrDie = stm.refineOrDie;
/**
* Keeps some of the errors, and terminates the fiber with the rest, using the
* specified function to convert the `E` into a `Throwable`.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.refineOrDie = refineOrDie;
const refineOrDieWith = stm.refineOrDieWith;
/**
* Fail with the returned value if the `PartialFunction` matches, otherwise
* continue with our held value.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.refineOrDieWith = refineOrDieWith;
const reject = stm.reject;
/**
* Continue with the returned computation if the specified partial function
* matches, translating the successful match into a failure, otherwise continue
* with our held value.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.reject = reject;
const rejectSTM = stm.rejectSTM;
/**
* 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.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.rejectSTM = rejectSTM;
const repeatUntil = stm.repeatUntil;
/**
* 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.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.repeatUntil = repeatUntil;
const repeatWhile = stm.repeatWhile;
/**
* Replicates the given effect n times. If 0 or negative numbers are given, an
* empty `Chunk` will be returned.
*
* @since 1.0.0
* @category constructors
*/
exports.repeatWhile = repeatWhile;
const replicate = stm.replicate;
/**
* Performs this transaction the specified number of times and collects the
* results.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.replicate = replicate;
const replicateSTM = stm.replicateSTM;
/**
* Performs this transaction the specified number of times, discarding the
* results.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.replicateSTM = replicateSTM;
const replicateSTMDiscard = stm.replicateSTMDiscard;
/**
* Abort and retry the whole transaction when any of the underlying
* transactional variables have changed.
*
* @macro traced
* @since 1.0.0
* @category error handling
*/
exports.provideSomeEnvironment = provideSomeEnvironment;
exports.replicateSTMDiscard = replicateSTMDiscard;
const retry = core.retry;
/**
* Filters the value produced by this effect, retrying the transaction until
* the predicate returns `true` for the value.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.retry = retry;
const retryUntil = stm.retryUntil;
/**
* Filters the value produced by this effect, retrying the transaction while
* the predicate returns `true` for the value.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.retryUntil = retryUntil;
const retryWhile = stm.retryWhile;
/**
* "Zooms in" on the value in the `Right` side of an `Either`, moving the
* possibility that the value is a `Left` to the error channel.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
exports.retryWhile = retryWhile;
const right = stm.right;
/**
* Accesses the specified service in the environment of the effect.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.retry = retry;
exports.right = right;
const service = stm.service;
/**
* Effectfully accesses the specified service in the environment of the
* effect.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.service = service;
const serviceWith = stm.serviceWith;
/**
* Effectfully accesses the specified service in the environment of the
* effect.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.serviceWith = serviceWith;
const serviceWithSTM = stm.serviceWithSTM;
/**
* Converts an option on values into an option on errors.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
exports.serviceWithSTM = serviceWithSTM;
const some = stm.some;
/**
* Extracts the optional value, or returns the given 'default'.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
exports.some = some;
const someOrElse = stm.someOrElse;
/**
* Extracts the optional value, or executes the effect 'default'.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
exports.someOrElse = someOrElse;
const someOrElseSTM = stm.someOrElseSTM;
/**
* Extracts the optional value, or fails with the given error 'e'.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
exports.someOrElseSTM = someOrElseSTM;
const someOrFail = stm.someOrFail;
/**
* Extracts the optional value, or fails with a
* `Cause.NoSuchElementException`.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
exports.someOrFail = someOrFail;
const someOrFailException = stm.someOrFailException;
/**
* Returns an `STM` effect that succeeds with the specified value.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.someOrFailException = someOrFailException;
const succeed = core.succeed;
/**
* Returns an effect with the value on the left part.
*
* @macro traced

@@ -115,11 +1100,157 @@ * @since 1.0.0

exports.succeed = succeed;
const succeedLeft = stm.succeedLeft;
/**
* Returns an effect with the empty value.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.succeedLeft = succeedLeft;
const succeedNone = stm.succeedNone;
/**
* Returns an effect with the value on the right part.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.succeedNone = succeedNone;
const succeedRight = stm.succeedRight;
/**
* Returns an effect with the optional value.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.succeedRight = succeedRight;
const succeedSome = stm.succeedSome;
/**
* Summarizes a `STM` effect by computing a provided value before and after
* execution, and then combining the values to produce a summary, together
* with the result of execution.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.succeedSome = succeedSome;
const summarized = stm.summarized;
/**
* Suspends creation of the specified transaction lazily.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.summarized = summarized;
const suspend = stm.suspend;
/**
* Returns an `STM` effect that succeeds with the specified lazily evaluated
* value.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.suspend = suspend;
const sync = core.sync;
/**
* "Peeks" at the success of transactional effect.
*
* @macro traced
* @since 1.0.0
* @category sequencing
*/
exports.sync = sync;
const tap = stm.tap;
/**
* "Peeks" at both sides of an transactional effect.
*
* @macro traced
* @since 1.0.0
* @category sequencing
*/
exports.tap = tap;
const tapBoth = stm.tapBoth;
/**
* "Peeks" at the error of the transactional effect.
*
* @macro traced
* @since 1.0.0
* @category sequencing
*/
exports.tapBoth = tapBoth;
const tapError = stm.tapError;
/**
* Imports a synchronous side-effect into a pure value, translating any thrown
* exceptions into typed failed effects.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.tapError = tapError;
const tryCatch = stm.tryCatch;
/**
* Converts a `STM<R, Either<E, A>, A2>` into a `STM<R, E, Either<A2, A>>`.
* The inverse of `left`.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
exports.tryCatch = tryCatch;
const unleft = stm.unleft;
/**
* The moral equivalent of `if (!p) exp`
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.unleft = unleft;
const unless = stm.unless;
/**
* The moral equivalent of `if (!p) exp` when `p` has side-effects
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.unless = unless;
const unlessSTM = stm.unlessSTM;
/**
* Converts a `STM<R, Either<A, E>, A2>` into a `STM<R, E, Either<A, A2>>`.
* The inverse of `right`.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
exports.unlessSTM = unlessSTM;
const unright = stm.unright;
/**
* Converts an option on errors into an option on values.
*
* @macro traced
* @since 1.0.0
* @category getters
*/
exports.unright = unright;
const unsome = stm.unsome;
/**
* Sequentially zips this value with the specified one.
*
* @macro traced
* @since 1.0.0
* @category zipping
*/
exports.sync = sync;
exports.unsome = unsome;
const zip = core.zip;
/**
* Sequentially zips this value with the specified one, discarding the second
* element of the tuple.
*
* @macro traced

@@ -132,2 +1263,5 @@ * @since 1.0.0

/**
* Sequentially zips this value with the specified one, discarding the first
* element of the tuple.
*
* @macro traced

@@ -140,2 +1274,5 @@ * @since 1.0.0

/**
* Sequentially zips this value with the specified one, combining the values
* using the specified combiner function.
*
* @macro traced

@@ -147,3 +1284,73 @@ * @since 1.0.0

const zipWith = core.zipWith;
/**
* Returns an `STM` effect that succeeds with `Unit`.
*
* @macro traced
* @since 1.0.0
* @category constructors
*/
exports.zipWith = zipWith;
const unit = stm.unit;
/**
* Feeds elements of type `A` to `f` and accumulates all errors in error
* channel or successes in success channel.
*
* This combinator is lossy meaning that if there are errors all successes
* will be lost. To retain all information please use `STM.partition`.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.unit = unit;
const validateAll = stm.validateAll;
/**
* Feeds elements of type `A` to `f` until it succeeds. Returns first success
* or the accumulation of all errors.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.validateAll = validateAll;
const validateFirst = stm.validateFirst;
/**
* The moral equivalent of `if (p) exp`.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.validateFirst = validateFirst;
const when = stm.when;
/**
* Runs an effect when the supplied partial function matches for the given
* value, otherwise does nothing.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.when = when;
const whenCase = stm.whenCase;
/**
* Runs an effect when the supplied partial function matches for the given
* effectful value, otherwise does nothing.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.whenCase = whenCase;
const whenCaseSTM = stm.whenCaseSTM;
/**
* The moral equivalent of `if (p) exp` when `p` has side-effects.
*
* @macro traced
* @since 1.0.0
* @category mutations
*/
exports.whenCaseSTM = whenCaseSTM;
const whenSTM = stm.whenSTM;
exports.whenSTM = whenSTM;
//# sourceMappingURL=STM.js.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc