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.14.0 to 0.15.0

31

internal/core.js

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

exports.effect = effect;
const ensuring = /*#__PURE__*/(0, _Function.dual)(2, (self, finalizer) => matchSTM(self, e => zipRight(finalizer, fail(e)), a => zipRight(finalizer, succeed(a))));
const ensuring = /*#__PURE__*/(0, _Function.dual)(2, (self, finalizer) => matchSTM(self, {
onFailure: e => zipRight(finalizer, fail(e)),
onSuccess: a => zipRight(finalizer, succeed(a))
}));
/** @internal */

@@ -439,3 +442,6 @@ exports.ensuring = ensuring;

exports.flatMap = flatMap;
const matchSTM = /*#__PURE__*/(0, _Function.dual)(3, (self, onFailure, onSuccess) => flatMap(either => {
const matchSTM = /*#__PURE__*/(0, _Function.dual)(2, (self, {
onFailure,
onSuccess
}) => flatMap(either => {
switch (either._tag) {

@@ -454,3 +460,10 @@ case "Left":

exports.matchSTM = matchSTM;
const interrupt = () => withSTMRuntime(_ => {
const withSTMRuntime = f => {
const stm = new STMPrimitive(OpCodes.OP_WITH_STM_RUNTIME);
stm.i1 = f;
return stm;
};
/** @internal */
exports.withSTMRuntime = withSTMRuntime;
const interrupt = /*#__PURE__*/withSTMRuntime(_ => {
const stm = new STMPrimitive(OpCodes.OP_INTERRUPT);

@@ -480,6 +493,3 @@ stm.i1 = _.fiberId;

exports.orTry = orTry;
const retry = () => {
const stm = new STMPrimitive(OpCodes.OP_RETRY);
return stm;
};
const retry = /*#__PURE__*/new STMPrimitive(OpCodes.OP_RETRY);
/** @internal */

@@ -501,9 +511,2 @@ exports.retry = retry;

exports.sync = sync;
const withSTMRuntime = f => {
const stm = new STMPrimitive(OpCodes.OP_WITH_STM_RUNTIME);
stm.i1 = f;
return stm;
};
/** @internal */
exports.withSTMRuntime = withSTMRuntime;
const zip = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => zipWith(that, (a, a1) => [a, a1])(self));

@@ -510,0 +513,0 @@ /** @internal */

import * as Effect from "@effect/io/Effect";
import type * as STM from "@effect/stm/STM";
export declare const bind: (<N extends string, K, R2, E2, A>(tag: Exclude<N, keyof K>, f: (_: K) => STM.STM<R2, E2, A>) => <R, E>(self: STM.STM<R, E, K>) => STM.STM<R2 | R, E2 | E, Effect.MergeRecord<K, { [k in N]: A; }>>) & (<R_1, E_1, N_1 extends string, K_1, R2_1, E2_1, A_1>(self: STM.STM<R_1, E_1, K_1>, tag: Exclude<N_1, keyof K_1>, f: (_: K_1) => STM.STM<R2_1, E2_1, A_1>) => STM.STM<R_1 | R2_1, E_1 | E2_1, Effect.MergeRecord<K_1, { [k_1 in N_1]: A_1; }>>);
export declare const catchTag: (<K extends E["_tag"] & string, E extends {
_tag: string;
}, R1, E1, A1>(k: K, f: (e: Extract<E, {
_tag: K;
}>) => STM.STM<R1, E1, A1>) => <R, A>(self: STM.STM<R, E, A>) => STM.STM<R1 | R, E1 | Exclude<E, {
_tag: K;
}>, A1 | A>) & (<R_1, E_1 extends {
_tag: string;
}, A_1, K_1 extends E_1["_tag"] & string, R1_1, E1_1, A1_1>(self: STM.STM<R_1, E_1, A_1>, k: K_1, f: (e: Extract<E_1, {
_tag: K_1;
}>) => STM.STM<R1_1, E1_1, A1_1>) => STM.STM<R_1 | R1_1, E1_1 | Exclude<E_1, {
_tag: K_1;
}>, A_1 | A1_1>);
//# sourceMappingURL=stm.d.ts.map

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

});
exports.when = exports.validateFirst = exports.validateAll = exports.unsome = exports.unlessSTM = exports.unless = exports.unit = exports.tryCatch = exports.tapError = exports.tapBoth = exports.tap = exports.suspend = exports.summarized = exports.succeedSome = exports.succeedNone = exports.someOrElseSTM = exports.someOrElse = exports.some = exports.retryWhile = exports.retryUntil = 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.provideSomeContext = exports.provideServiceSTM = exports.provideService = exports.provideContext = exports.partition = 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.match = exports.mapError = exports.mapBoth = exports.mapAttempt = exports.loopDiscard = exports.loop = exports.let_ = exports.iterate = exports.isSuccess = exports.isFailure = exports.ignore = exports.ifSTM = exports.head = exports.gen = exports.fromOption = exports.fromEither = exports.forEachDiscard = exports.forEach = exports.flipWith = exports.flip = exports.flatten = exports.filterOrFail = exports.filterOrElseWith = exports.filterOrElse = exports.filterOrDieMessage = exports.filterOrDie = exports.filterNot = exports.filter = exports.fiberId = exports.exists = exports.every = exports.eventually = exports.either = exports.cond = exports.commitEither = exports.collectSTM = exports.collectFirst = exports.collectAllDiscard = exports.collectAll = exports.collect = exports.check = exports.catchSome = exports.bindTo = exports.bind = exports.attempt = exports.asUnit = exports.asSomeError = exports.asSome = exports.as = exports.all = exports.acquireUseRelease = void 0;
exports.whenSTM = void 0;
exports.whenSTM = exports.when = exports.validateFirst = exports.validateAll = exports.unsome = exports.unlessSTM = exports.unless = exports.unit = exports.try_ = exports.tapError = exports.tapBoth = exports.tap = exports.suspend = exports.summarized = exports.succeedSome = exports.succeedNone = exports.some = exports.retryWhile = exports.retryUntil = 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.provideSomeContext = exports.provideServiceSTM = exports.provideService = exports.provideContext = exports.partition = 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.match = exports.mapError = exports.mapBoth = exports.mapAttempt = exports.loop = exports.let_ = exports.iterate = exports.isSuccess = exports.isFailure = exports.ignore = exports.if_ = exports.head = exports.gen = exports.fromOption = exports.fromEither = exports.forEach = exports.flipWith = exports.flip = exports.flatten = exports.filterOrFail = exports.filterOrElse = exports.filterOrDieMessage = exports.filterOrDie = exports.filterNot = exports.filter = exports.fiberId = exports.exists = exports.every = exports.eventually = exports.either = exports.cond = exports.commitEither = exports.collectSTM = exports.collect = exports.check = exports.catchTags = exports.catchTag = exports.catchSome = exports.bindTo = exports.bind = exports.attempt = exports.asUnit = exports.asSomeError = exports.asSome = exports.as = exports.all = exports.acquireUseRelease = void 0;
var Chunk = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Chunk"));

@@ -14,2 +13,3 @@ var Context = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Context"));

var Option = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Option"));
var predicate = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Predicate"));
var RA = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/ReadonlyArray"));

@@ -92,6 +92,22 @@ var Cause = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/Cause"));

const catchSome = /*#__PURE__*/(0, _Function.dual)(2, (self, pf) => core.catchAll(self, e => Option.getOrElse(pf(e), () => core.fail(e))));
/** @internal */
exports.catchSome = catchSome;
const check = predicate => suspend(() => predicate() ? unit() : core.retry());
const catchTag = /*#__PURE__*/(0, _Function.dual)(3, (self, k, f) => core.catchAll(self, e => {
if ("_tag" in e && e["_tag"] === k) {
return f(e);
}
return core.fail(e);
}));
/** @internal */
exports.catchTag = catchTag;
const catchTags = /*#__PURE__*/(0, _Function.dual)(2, (self, cases) => core.catchAll(self, e => {
const keys = Object.keys(cases);
if ("_tag" in e && keys.includes(e["_tag"])) {
return cases[e["_tag"]](e);
}
return core.fail(e);
}));
/** @internal */
exports.catchTags = catchTags;
const check = predicate => suspend(() => predicate() ? unit : core.retry);
/** @internal */
exports.check = check;

@@ -101,26 +117,8 @@ const collect = /*#__PURE__*/(0, _Function.dual)(2, (self, pf) => collectSTM(self, a => Option.map(pf(a), core.succeed)));

exports.collect = collect;
const collectAll = iterable => forEach(iterable, _Function.identity);
/** @internal */
exports.collectAll = collectAll;
const collectAllDiscard = iterable => forEachDiscard(_Function.identity)(iterable);
/** @internal */
exports.collectAllDiscard = collectAllDiscard;
const collectFirst = /*#__PURE__*/(0, _Function.dual)(2, (iterable, pf) => core.flatMap(iterator => {
const loop = suspend(() => {
const next = iterator.next();
if (next.done) {
return succeedNone();
}
return core.flatMap(Option.match({
onNone: () => loop,
onSome: succeedSome
}))(pf(next.value));
});
return loop;
})(core.sync(() => iterable[Symbol.iterator]())));
/** @internal */
exports.collectFirst = collectFirst;
const collectSTM = /*#__PURE__*/(0, _Function.dual)(2, (self, pf) => core.matchSTM(self, core.fail, a => {
const option = pf(a);
return Option.isSome(option) ? option.value : core.retry();
const collectSTM = /*#__PURE__*/(0, _Function.dual)(2, (self, pf) => core.matchSTM(self, {
onFailure: core.fail,
onSuccess: a => {
const option = pf(a);
return Option.isSome(option) ? option.value : core.retry;
}
}));

@@ -137,6 +135,12 @@ /** @internal */

exports.cond = cond;
const either = self => match(self, Either.left, Either.right);
const either = self => match(self, {
onFailure: Either.left,
onSuccess: Either.right
});
/** @internal */
exports.either = either;
const eventually = self => core.matchSTM(self, () => eventually(self), core.succeed);
const eventually = self => core.matchSTM(self, {
onFailure: () => eventually(self),
onSuccess: core.succeed
});
/** @internal */

@@ -168,3 +172,3 @@ exports.eventually = eventually;

exports.exists = exists;
const fiberId = () => core.effect((_, fiberId) => fiberId);
const fiberId = /*#__PURE__*/core.effect((_, fiberId) => fiberId);
/** @internal */

@@ -190,10 +194,7 @@ exports.fiberId = fiberId;

exports.filterOrDieMessage = filterOrDieMessage;
const filterOrElse = /*#__PURE__*/(0, _Function.dual)(3, (self, predicate, orElse) => filterOrElseWith(self, predicate, orElse));
const filterOrElse = /*#__PURE__*/(0, _Function.dual)(3, (self, predicate, orElse) => core.flatMap(self, a => predicate(a) ? core.succeed(a) : orElse(a)));
/** @internal */
exports.filterOrElse = filterOrElse;
const filterOrElseWith = /*#__PURE__*/(0, _Function.dual)(3, (self, predicate, orElse) => core.flatMap(self, a => predicate(a) ? core.succeed(a) : orElse(a)));
const filterOrFail = /*#__PURE__*/(0, _Function.dual)(3, (self, predicate, orFailWith) => filterOrElse(self, predicate, a => core.failSync(() => orFailWith(a))));
/** @internal */
exports.filterOrElseWith = filterOrElseWith;
const filterOrFail = /*#__PURE__*/(0, _Function.dual)(3, (self, predicate, error) => filterOrElse(self, predicate, () => core.failSync(error)));
/** @internal */
exports.filterOrFail = filterOrFail;

@@ -203,3 +204,6 @@ const flatten = self => core.flatMap(self, _Function.identity);

exports.flatten = flatten;
const flip = self => core.matchSTM(self, core.succeed, core.fail);
const flip = self => core.matchSTM(self, {
onFailure: core.succeed,
onSuccess: core.fail
});
/** @internal */

@@ -210,23 +214,31 @@ exports.flip = flip;

exports.flipWith = flipWith;
const match = /*#__PURE__*/(0, _Function.dual)(3, (self, f, g) => core.matchSTM(self, e => core.succeed(f(e)), a => core.succeed(g(a))));
const match = /*#__PURE__*/(0, _Function.dual)(2, (self, {
onFailure,
onSuccess
}) => core.matchSTM(self, {
onFailure: e => core.succeed(onFailure(e)),
onSuccess: a => core.succeed(onSuccess(a))
}));
/** @internal */
exports.match = match;
const forEach = /*#__PURE__*/(0, _Function.dual)(2, (elements, f) => suspend(() => Array.from(elements).reduce((acc, curr) => core.zipWith(f(curr), (array, elem) => {
array.push(elem);
return array;
})(acc), core.succeed([]))));
const forEach = /*#__PURE__*/(0, _Function.dual)(args => predicate.isIterable(args[0]), (iterable, f, options) => {
if (options?.discard) {
return core.flatMap(iterator => {
const loop = suspend(() => {
const next = iterator.next();
if (next.done) {
return unit;
}
return core.flatMap(() => loop)(f(next.value));
});
return loop;
})(core.sync(() => iterable[Symbol.iterator]()));
}
return suspend(() => RA.fromIterable(iterable).reduce((acc, curr) => core.zipWith(acc, f(curr), (array, elem) => {
array.push(elem);
return array;
}), core.succeed([])));
});
/** @internal */
exports.forEach = forEach;
const forEachDiscard = /*#__PURE__*/(0, _Function.dual)(2, (iterable, f) => core.flatMap(iterator => {
const loop = suspend(() => {
const next = iterator.next();
if (next.done) {
return unit();
}
return core.flatMap(() => loop)(f(next.value));
});
return loop;
})(core.sync(() => iterable[Symbol.iterator]())));
/** @internal */
exports.forEachDiscard = forEachDiscard;
const fromEither = either => {

@@ -279,9 +291,12 @@ switch (either._tag) {

exports.gen = gen;
const head = self => core.matchSTM(e => core.fail(Option.some(e)), a => {
const i = a[Symbol.iterator]();
const res = i.next();
if (res.done) {
return core.fail(Option.none());
} else {
return core.succeed(res.value);
const head = self => core.matchSTM({
onFailure: e => core.fail(Option.some(e)),
onSuccess: a => {
const i = a[Symbol.iterator]();
const res = i.next();
if (res.done) {
return core.fail(Option.none());
} else {
return core.succeed(res.value);
}
}

@@ -291,17 +306,32 @@ })(self);

exports.head = head;
const ifSTM = /*#__PURE__*/(0, _Function.dual)(3, (self, onTrue, onFalse) => core.flatMap(self, bool => bool ? onTrue : onFalse));
const if_ = /*#__PURE__*/(0, _Function.dual)(args => typeof args[0] === "boolean" || core.isSTM(args[0]), (self, {
onFalse,
onTrue
}) => {
if (typeof self === "boolean") {
return self ? onTrue : onFalse;
}
return core.flatMap(self, bool => bool ? onTrue : onFalse);
});
/** @internal */
exports.ifSTM = ifSTM;
const ignore = self => match(self, unit, unit);
exports.if_ = if_;
const ignore = self => match(self, {
onFailure: () => unit,
onSuccess: () => unit
});
/** @internal */
exports.ignore = ignore;
const isFailure = self => match(self, _Function.constTrue, _Function.constFalse);
const isFailure = self => match(self, {
onFailure: _Function.constTrue,
onSuccess: _Function.constFalse
});
/** @internal */
exports.isFailure = isFailure;
const isSuccess = self => match(self, _Function.constFalse, _Function.constTrue);
const isSuccess = self => match(self, {
onFailure: _Function.constFalse,
onSuccess: _Function.constTrue
});
/** @internal */
exports.isSuccess = isSuccess;
const iterate = (initial, cont, body) => {
return iterateLoop(initial, cont, body);
};
const iterate = (initial, options) => iterateLoop(initial, options.while, options.body);
exports.iterate = iterate;

@@ -315,5 +345,3 @@ const iterateLoop = (initial, cont, body) => {

/** @internal */
const loop = (initial, cont, inc, body) => {
return core.map(loopLoop(initial, cont, inc, body), a => Array.from(a));
};
const loop = (initial, options) => options.discard ? loopDiscardLoop(initial, options.while, options.step, options.body) : core.map(loopLoop(initial, options.while, options.step, options.body), a => Array.from(a));
exports.loop = loop;

@@ -326,7 +354,2 @@ const loopLoop = (initial, cont, inc, body) => {

};
/** @internal */
const loopDiscard = (initial, cont, inc, body) => {
return loopDiscardLoop(initial, cont, inc, body);
};
exports.loopDiscard = loopDiscard;
const loopDiscardLoop = (initial, cont, inc, body) => {

@@ -336,15 +359,30 @@ if (cont(initial)) {

}
return unit();
return unit;
};
/** @internal */
const mapAttempt = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => core.matchSTM(self, e => core.fail(e), a => attempt(() => f(a))));
const mapAttempt = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => core.matchSTM(self, {
onFailure: e => core.fail(e),
onSuccess: a => attempt(() => f(a))
}));
/** @internal */
exports.mapAttempt = mapAttempt;
const mapBoth = /*#__PURE__*/(0, _Function.dual)(3, (self, f, g) => core.matchSTM(self, e => core.fail(f(e)), a => core.succeed(g(a))));
const mapBoth = /*#__PURE__*/(0, _Function.dual)(2, (self, {
onFailure,
onSuccess
}) => core.matchSTM(self, {
onFailure: e => core.fail(onFailure(e)),
onSuccess: a => core.succeed(onSuccess(a))
}));
/** @internal */
exports.mapBoth = mapBoth;
const mapError = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => core.matchSTM(self, e => core.fail(f(e)), core.succeed));
const mapError = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => core.matchSTM(self, {
onFailure: e => core.fail(f(e)),
onSuccess: core.succeed
}));
/** @internal */
exports.mapError = mapError;
const merge = self => core.matchSTM(self, e => core.succeed(e), core.succeed);
const merge = self => core.matchSTM(self, {
onFailure: e => core.succeed(e),
onSuccess: core.succeed
});
/** @internal */

@@ -358,9 +396,15 @@ exports.merge = merge;

exports.negate = negate;
const none = self => core.matchSTM(self, e => core.fail(Option.some(e)), Option.match({
onNone: unit,
onSome: () => core.fail(Option.none())
}));
const none = self => core.matchSTM(self, {
onFailure: e => core.fail(Option.some(e)),
onSuccess: Option.match({
onNone: () => unit,
onSome: () => core.fail(Option.none())
})
});
/** @internal */
exports.none = none;
const option = self => match(self, () => Option.none(), Option.some);
const option = self => match(self, {
onFailure: () => Option.none(),
onSuccess: Option.some
});
/** @internal */

@@ -444,12 +488,20 @@ exports.option = option;

exports.replicate = replicate;
const replicateSTM = /*#__PURE__*/(0, _Function.dual)(2, (self, n) => collectAll(replicate(n)(self)));
const replicateSTM = /*#__PURE__*/(0, _Function.dual)(2, (self, n) => all()(replicate(n)(self)));
/** @internal */
exports.replicateSTM = replicateSTM;
const replicateSTMDiscard = /*#__PURE__*/(0, _Function.dual)(2, (self, n) => collectAllDiscard(replicate(n)(self)));
const replicateSTMDiscard = /*#__PURE__*/(0, _Function.dual)(2, (self, n) => all({
discard: true
})(replicate(n)(self)));
/** @internal */
exports.replicateSTMDiscard = replicateSTMDiscard;
const retryUntil = /*#__PURE__*/(0, _Function.dual)(2, (self, predicate) => core.matchSTM(self, core.fail, a => predicate(a) ? core.succeed(a) : core.retry()));
const retryUntil = /*#__PURE__*/(0, _Function.dual)(2, (self, predicate) => core.matchSTM(self, {
onFailure: core.fail,
onSuccess: a => predicate(a) ? core.succeed(a) : core.retry
}));
/** @internal */
exports.retryUntil = retryUntil;
const retryWhile = /*#__PURE__*/(0, _Function.dual)(2, (self, predicate) => core.matchSTM(self, core.fail, a => !predicate(a) ? core.succeed(a) : core.retry()));
const retryWhile = /*#__PURE__*/(0, _Function.dual)(2, (self, predicate) => core.matchSTM(self, {
onFailure: core.fail,
onSuccess: a => !predicate(a) ? core.succeed(a) : core.retry
}));
/** @internal */

@@ -460,39 +512,40 @@ exports.retryWhile = retryWhile;

exports.partition = partition;
const some = self => core.matchSTM(self, e => core.fail(Option.some(e)), Option.match({
onNone: () => core.fail(Option.none()),
onSome: core.succeed
}));
/** @internal */
const some = self => core.matchSTM(self, {
onFailure: e => core.fail(Option.some(e)),
onSuccess: Option.match({
onNone: () => core.fail(Option.none()),
onSome: core.succeed
})
});
exports.some = some;
const someOrElse = /*#__PURE__*/(0, _Function.dual)(2, (self, orElse) => core.map(Option.getOrElse(orElse))(self));
/** @internal */
exports.someOrElse = someOrElse;
const someOrElseSTM = /*#__PURE__*/(0, _Function.dual)(2, (self, orElse) => core.flatMap(self, Option.match({
onNone: () => orElse(),
onSome: core.succeed
})));
const allIsDataFirst = args => {
if (args.length === 0) {
return false;
} else if (args.length > 1) {
return true;
} else if (Symbol.iterator in args[0]) {
return true;
}
const obj = args[0];
return typeof obj.discard === "boolean" === false;
};
/* @internal */
exports.someOrElseSTM = someOrElseSTM;
const all = function () {
if (arguments.length === 1) {
if (core.isSTM(arguments[0])) {
return core.map(arguments[0], x => [x]);
} else if (Symbol.iterator in arguments[0]) {
return collectAll(arguments[0]);
} else {
return core.map(values => {
const res = {};
for (const [k, v] of values) {
;
res[k] = v;
}
return res;
})(forEach(Object.entries(arguments[0]), ([_, e]) => core.map(e, a => [_, a])));
const all = /*#__PURE__*/(0, _Function.dual)(allIsDataFirst, (input, options) => {
if (Symbol.iterator in input) {
return forEach(input, _Function.identity, options);
} else if (options?.discard) {
return forEach(Object.values(input), _Function.identity, options);
}
return core.map(values => {
const res = {};
for (const [k, v] of values) {
;
res[k] = v;
}
}
return collectAll(arguments);
};
return res;
})(forEach(Object.entries(input), ([_, e]) => core.map(e, a => [_, a])));
});
/** @internal */
exports.all = all;
const succeedNone = () => core.succeed(Option.none());
const succeedNone = /*#__PURE__*/core.succeed( /*#__PURE__*/Option.none());
/** @internal */

@@ -512,30 +565,45 @@ exports.succeedNone = succeedNone;

exports.tap = tap;
const tapBoth = /*#__PURE__*/(0, _Function.dual)(3, (self, f, g) => core.matchSTM(self, e => core.zipRight(core.fail(e))(f(e)), a => as(a)(g(a))));
const tapBoth = /*#__PURE__*/(0, _Function.dual)(2, (self, {
onFailure,
onSuccess
}) => core.matchSTM(self, {
onFailure: e => core.zipRight(core.fail(e))(onFailure(e)),
onSuccess: a => as(a)(onSuccess(a))
}));
/** @internal */
exports.tapBoth = tapBoth;
const tapError = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => core.matchSTM(self, e => core.zipRight(f(e), core.fail(e)), core.succeed));
const tapError = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => core.matchSTM(self, {
onFailure: e => core.zipRight(f(e), core.fail(e)),
onSuccess: core.succeed
}));
/** @internal */
exports.tapError = tapError;
const tryCatch = (attempt, onThrow) => suspend(() => {
try {
return core.succeed(attempt());
} catch (error) {
return core.fail(onThrow(error));
}
});
const try_ = arg => {
const evaluate = typeof arg === "function" ? arg : arg.try;
return suspend(() => {
try {
return core.succeed(evaluate());
} catch (error) {
return core.fail("catch" in arg ? arg.catch(error) : error);
}
});
};
/** @internal */
exports.tryCatch = tryCatch;
const unit = () => core.succeed(void 0);
exports.try_ = try_;
const unit = /*#__PURE__*/core.succeed(void 0);
/** @internal */
exports.unit = unit;
const unless = /*#__PURE__*/(0, _Function.dual)(2, (self, predicate) => suspend(() => predicate() ? succeedNone() : asSome(self)));
const unless = /*#__PURE__*/(0, _Function.dual)(2, (self, predicate) => suspend(() => predicate() ? succeedNone : asSome(self)));
/** @internal */
exports.unless = unless;
const unlessSTM = /*#__PURE__*/(0, _Function.dual)(2, (self, predicate) => core.flatMap(predicate, bool => bool ? succeedNone() : asSome(self)));
const unlessSTM = /*#__PURE__*/(0, _Function.dual)(2, (self, predicate) => core.flatMap(predicate, bool => bool ? succeedNone : asSome(self)));
/** @internal */
exports.unlessSTM = unlessSTM;
const unsome = self => core.matchSTM(self, Option.match({
onNone: () => core.succeed(Option.none()),
onSome: core.fail
}), a => core.succeed(Option.some(a)));
const unsome = self => core.matchSTM(self, {
onFailure: Option.match({
onNone: () => core.succeed(Option.none()),
onSome: core.fail
}),
onSuccess: a => core.succeed(Option.some(a))
});
/** @internal */

@@ -549,7 +617,7 @@ exports.unsome = unsome;

exports.validateFirst = validateFirst;
const when = /*#__PURE__*/(0, _Function.dual)(2, (self, predicate) => suspend(() => predicate() ? asSome(self) : succeedNone()));
const when = /*#__PURE__*/(0, _Function.dual)(2, (self, predicate) => suspend(() => predicate() ? asSome(self) : succeedNone));
/** @internal */
exports.when = when;
const whenSTM = /*#__PURE__*/(0, _Function.dual)(2, (self, predicate) => core.flatMap(predicate, bool => bool ? asSome(self) : succeedNone()));
const whenSTM = /*#__PURE__*/(0, _Function.dual)(2, (self, predicate) => core.flatMap(predicate, bool => bool ? asSome(self) : succeedNone));
exports.whenSTM = whenSTM;
//# sourceMappingURL=stm.js.map

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

return Option.match({
onNone: () => stm.succeedNone(),
onNone: () => stm.succeedNone,
onSome: core.map(Option.some)

@@ -90,3 +90,3 @@ })(result);

if (from < 0) {
return stm.succeedNone();
return stm.succeedNone;
}

@@ -113,4 +113,4 @@ return core.effect(journal => {

const findFirstIndexWhereFromSTM = /*#__PURE__*/(0, _Function.dual)(3, (self, predicate, from) => {
const forIndex = index => index < self.chunk.length ? core.flatMap(bool => bool ? core.succeed(Option.some(index)) : forIndex(index + 1))(core.flatMap(predicate)(tRef.get(self.chunk[index]))) : stm.succeedNone();
return from < 0 ? stm.succeedNone() : forIndex(from);
const forIndex = index => index < self.chunk.length ? core.flatMap(bool => bool ? core.succeed(Option.some(index)) : forIndex(index + 1))(core.flatMap(predicate)(tRef.get(self.chunk[index]))) : stm.succeedNone;
return from < 0 ? stm.succeedNone : forIndex(from);
});

@@ -122,5 +122,8 @@ /** @internal */

const cont = state => Option.isNone(state[0]) && state[1] < self.chunk.length - 1;
return core.map(stm.iterate(init, cont, state => {
const index = state[1];
return core.flatMap(value => core.map(predicate(value), bool => [bool ? Option.some(value) : Option.none(), index + 1]))(tRef.get(self.chunk[index]));
return core.map(stm.iterate(init, {
while: cont,
body: state => {
const index = state[1];
return core.flatMap(value => core.map(predicate(value), bool => [bool ? Option.some(value) : Option.none(), index + 1]))(tRef.get(self.chunk[index]));
}
}), state => state[0]);

@@ -149,3 +152,3 @@ });

if (end >= self.chunk.length) {
return stm.succeedNone();
return stm.succeedNone;
}

@@ -171,5 +174,8 @@ return core.effect(journal => {

const cont = state => Option.isNone(state[0]) && state[1] >= 0;
return core.map(stm.iterate(init, cont, state => {
const index = state[1];
return core.flatMap(value => core.map(predicate(value), bool => [bool ? Option.some(value) : Option.none(), index - 1]))(tRef.get(self.chunk[index]));
return core.map(stm.iterate(init, {
while: cont,
body: state => {
const index = state[1];
return core.flatMap(value => core.map(predicate(value), bool => [bool ? Option.some(value) : Option.none(), index - 1]))(tRef.get(self.chunk[index]));
}
}), state => state[0]);

@@ -196,3 +202,3 @@ });

exports.headOption = headOption;
const lastOption = self => self.chunk.length === 0 ? stm.succeedNone() : core.map(tRef.get(self.chunk[self.chunk.length - 1]), Option.some);
const lastOption = self => self.chunk.length === 0 ? stm.succeedNone : core.map(tRef.get(self.chunk[self.chunk.length - 1]), Option.some);
/** @internal */

@@ -199,0 +205,0 @@ exports.lastOption = lastOption;

@@ -44,21 +44,31 @@ "use strict";

this[_b] = tQueue.tEnqueueVariance;
this.isShutdown = core.effect(journal => {
const currentPublisherTail = tRef.unsafeGet(this.publisherTail, journal);
return currentPublisherTail === undefined;
});
this.awaitShutdown = core.flatMap(this.isShutdown, isShutdown => isShutdown ? stm.unit : core.retry);
this.size = core.withSTMRuntime(runtime => {
const currentPublisherTail = tRef.unsafeGet(this.publisherTail, runtime.journal);
if (currentPublisherTail === undefined) {
return core.interruptAs(runtime.fiberId);
}
return core.succeed(tRef.unsafeGet(this.hubSize, runtime.journal));
});
this.isEmpty = core.map(this.size, size => size === 0);
this.isFull = core.map(this.size, size => size === this.capacity());
this.shutdown = core.effect(journal => {
const currentPublisherTail = tRef.unsafeGet(this.publisherTail, journal);
if (currentPublisherTail !== undefined) {
tRef.unsafeSet(this.publisherTail, void 0, journal);
const currentSubscribers = tRef.unsafeGet(this.subscribers, journal);
HashSet.forEach(currentSubscribers, subscriber => {
tRef.unsafeSet(subscriber, void 0, journal);
});
tRef.unsafeSet(this.subscribers, HashSet.empty(), journal);
}
});
}
awaitShutdown() {
return core.flatMap(this.isShutdown(), isShutdown => isShutdown ? stm.unit() : core.retry());
}
capacity() {
return this.requestedCapacity;
}
isEmpty() {
return core.map(this.size(), size => size === 0);
}
isFull() {
return core.map(this.size(), size => size === this.capacity());
}
isShutdown() {
return core.effect(journal => {
const currentPublisherTail = tRef.unsafeGet(this.publisherTail, journal);
return currentPublisherTail === undefined;
});
}
offer(value) {

@@ -86,3 +96,3 @@ return core.withSTMRuntime(runtime => {

{
return core.retry();
return core.retry;
}

@@ -101,3 +111,3 @@ case OpCodes.OP_DROPPING_STRATEGY:

if (node === undefined) {
return core.retry();
return core.retry;
}

@@ -128,24 +138,2 @@ const head = node.head;

}
size() {
return core.withSTMRuntime(runtime => {
const currentPublisherTail = tRef.unsafeGet(this.publisherTail, runtime.journal);
if (currentPublisherTail === undefined) {
return core.interruptAs(runtime.fiberId);
}
return core.succeed(tRef.unsafeGet(this.hubSize, runtime.journal));
});
}
shutdown() {
return core.effect(journal => {
const currentPublisherTail = tRef.unsafeGet(this.publisherTail, journal);
if (currentPublisherTail !== undefined) {
tRef.unsafeSet(this.publisherTail, void 0, journal);
const currentSubscribers = tRef.unsafeGet(this.subscribers, journal);
HashSet.forEach(currentSubscribers, subscriber => {
tRef.unsafeSet(subscriber, void 0, journal);
});
tRef.unsafeSet(this.subscribers, HashSet.empty(), journal);
}
});
}
}

@@ -164,23 +152,8 @@ _a = THubTypeId, _b = tQueue.TEnqueueTypeId;

this[_d] = tQueue.tDequeueVariance;
}
awaitShutdown() {
return core.flatMap(this.isShutdown(), isShutdown => isShutdown ? stm.unit() : core.retry());
}
capacity() {
return this.requestedCapacity;
}
isEmpty() {
return core.map(this.size(), size => size === 0);
}
isFull() {
return core.map(this.size(), size => size === this.capacity());
}
isShutdown() {
return core.effect(journal => {
this.isShutdown = core.effect(journal => {
const currentSubscriberHead = tRef.unsafeGet(this.subscriberHead, journal);
return currentSubscriberHead === undefined;
});
}
peek() {
return core.withSTMRuntime(runtime => {
this.awaitShutdown = core.flatMap(this.isShutdown, isShutdown => isShutdown ? stm.unit : core.retry);
this.size = core.withSTMRuntime(runtime => {
let currentSubscriberHead = tRef.unsafeGet(this.subscriberHead, runtime.journal);

@@ -190,2 +163,29 @@ if (currentSubscriberHead === undefined) {

}
let loop = true;
let size = 0;
while (loop) {
const node = tRef.unsafeGet(currentSubscriberHead, runtime.journal);
if (node === undefined) {
loop = false;
} else {
const head = node.head;
const tail = node.tail;
if (head !== undefined) {
size = size + 1;
if (size >= Number.MAX_SAFE_INTEGER) {
loop = false;
}
}
currentSubscriberHead = tail;
}
}
return core.succeed(size);
});
this.isEmpty = core.map(this.size, size => size === 0);
this.isFull = core.map(this.size, size => size === this.capacity());
this.peek = core.withSTMRuntime(runtime => {
let currentSubscriberHead = tRef.unsafeGet(this.subscriberHead, runtime.journal);
if (currentSubscriberHead === undefined) {
return core.interruptAs(runtime.fiberId);
}
let value = undefined;

@@ -196,3 +196,3 @@ let loop = true;

if (node === undefined) {
return core.retry();
return core.retry;
}

@@ -210,5 +210,3 @@ const head = node.head;

});
}
peekOption() {
return core.withSTMRuntime(runtime => {
this.peekOption = core.withSTMRuntime(runtime => {
let currentSubscriberHead = tRef.unsafeGet(this.subscriberHead, runtime.journal);

@@ -238,32 +236,3 @@ if (currentSubscriberHead === undefined) {

});
}
size() {
return core.withSTMRuntime(runtime => {
let currentSubscriberHead = tRef.unsafeGet(this.subscriberHead, runtime.journal);
if (currentSubscriberHead === undefined) {
return core.interruptAs(runtime.fiberId);
}
let loop = true;
let size = 0;
while (loop) {
const node = tRef.unsafeGet(currentSubscriberHead, runtime.journal);
if (node === undefined) {
loop = false;
} else {
const head = node.head;
const tail = node.tail;
if (head !== undefined) {
size = size + 1;
if (size >= Number.MAX_SAFE_INTEGER) {
loop = false;
}
}
currentSubscriberHead = tail;
}
}
return core.succeed(size);
});
}
shutdown() {
return core.effect(journal => {
this.shutdown = core.effect(journal => {
let currentSubscriberHead = tRef.unsafeGet(this.subscriberHead, journal);

@@ -301,5 +270,3 @@ if (currentSubscriberHead !== undefined) {

});
}
take() {
return core.withSTMRuntime(runtime => {
this.take = core.withSTMRuntime(runtime => {
let currentSubscriberHead = tRef.unsafeGet(this.subscriberHead, runtime.journal);

@@ -314,3 +281,3 @@ if (currentSubscriberHead === undefined) {

if (node === undefined) {
return core.retry();
return core.retry;
}

@@ -340,5 +307,6 @@ const head = node.head;

});
this.takeAll = this.takeUpTo(Number.POSITIVE_INFINITY);
}
takeAll() {
return this.takeUpTo(Number.POSITIVE_INFINITY);
capacity() {
return this.requestedCapacity;
}

@@ -385,6 +353,6 @@ takeUpTo(max) {

/** @internal */
const makeHub = (requestedCapacity, strategy) => core.flatMap(([empty, hubSize]) => core.map(([publisherHead, publisherTail, subscriberCount, subscribers]) => new THubImpl(hubSize, publisherHead, publisherTail, requestedCapacity, strategy, subscriberCount, subscribers))(stm.all(tRef.make(empty), tRef.make(empty), tRef.make(0), tRef.make(HashSet.empty()))))(stm.all(tRef.make(void 0), tRef.make(0)));
const makeSubscription = (hubSize, publisherHead, publisherTail, requestedCapacity, subscriberCount, subscribers) => core.flatMap(currentPublisherTail => core.map(([subscriberHead]) => new THubSubscriptionImpl(hubSize, publisherHead, requestedCapacity, subscriberHead, subscriberCount, subscribers))(stm.tap(([subscriberHead, _, currentSubscribers]) => tRef.set(HashSet.add(subscriberHead)(currentSubscribers))(subscribers))(stm.tap(([_, currentSubscriberCount]) => tRef.set(currentSubscriberCount + 1)(subscriberCount))(stm.all(tRef.make(currentPublisherTail), tRef.get(subscriberCount), tRef.get(subscribers))))))(tRef.get(publisherTail));
const makeHub = (requestedCapacity, strategy) => core.flatMap(([empty, hubSize]) => core.map(([publisherHead, publisherTail, subscriberCount, subscribers]) => new THubImpl(hubSize, publisherHead, publisherTail, requestedCapacity, strategy, subscriberCount, subscribers))(stm.all([tRef.make(empty), tRef.make(empty), tRef.make(0), tRef.make(HashSet.empty())])))(stm.all([tRef.make(void 0), tRef.make(0)]));
const makeSubscription = (hubSize, publisherHead, publisherTail, requestedCapacity, subscriberCount, subscribers) => core.flatMap(currentPublisherTail => core.map(([subscriberHead]) => new THubSubscriptionImpl(hubSize, publisherHead, requestedCapacity, subscriberHead, subscriberCount, subscribers))(stm.tap(([subscriberHead, _, currentSubscribers]) => tRef.set(HashSet.add(subscriberHead)(currentSubscribers))(subscribers))(stm.tap(([_, currentSubscriberCount]) => tRef.set(currentSubscriberCount + 1)(subscriberCount))(stm.all([tRef.make(currentPublisherTail), tRef.get(subscriberCount), tRef.get(subscribers)])))))(tRef.get(publisherTail));
/** @internal */
const awaitShutdown = self => self.awaitShutdown();
const awaitShutdown = self => self.awaitShutdown;
/** @internal */

@@ -401,9 +369,9 @@ exports.awaitShutdown = awaitShutdown;

exports.dropping = dropping;
const isEmpty = self => self.isEmpty();
const isEmpty = self => self.isEmpty;
/** @internal */
exports.isEmpty = isEmpty;
const isFull = self => self.isFull();
const isFull = self => self.isFull;
/** @internal */
exports.isFull = isFull;
const isShutdown = self => self.isShutdown();
const isShutdown = self => self.isShutdown;
/** @internal */

@@ -417,6 +385,6 @@ exports.isShutdown = isShutdown;

exports.publishAll = publishAll;
const size = self => self.size();
const size = self => self.size;
/** @internal */
exports.size = size;
const shutdown = self => self.shutdown();
const shutdown = self => self.shutdown;
/** @internal */

@@ -423,0 +391,0 @@ exports.shutdown = shutdown;

@@ -83,6 +83,9 @@ "use strict";

exports.find = find;
const findSTM = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => reduceWithIndexSTM(self, Option.none(), (acc, value, key) => Option.isNone(acc) ? core.matchSTM(f(key, value), Option.match({
onNone: stm.succeedNone,
onSome: core.fail
}), stm.succeedSome) : STM.succeed(acc)));
const findSTM = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => reduceWithIndexSTM(self, Option.none(), (acc, value, key) => Option.isNone(acc) ? core.matchSTM(f(key, value), {
onFailure: Option.match({
onNone: () => stm.succeedNone,
onSome: core.fail
}),
onSuccess: stm.succeedSome
}) : STM.succeed(acc)));
/** @internal */

@@ -99,6 +102,9 @@ exports.findSTM = findSTM;

exports.findAll = findAll;
const findAllSTM = /*#__PURE__*/(0, _Function.dual)(2, (self, pf) => core.map(reduceWithIndexSTM(self, Chunk.empty(), (acc, value, key) => core.matchSTM(pf(key, value), Option.match({
onNone: () => core.succeed(acc),
onSome: core.fail
}), a => core.succeed(Chunk.append(acc, a)))), a => Array.from(a)));
const findAllSTM = /*#__PURE__*/(0, _Function.dual)(2, (self, pf) => core.map(reduceWithIndexSTM(self, Chunk.empty(), (acc, value, key) => core.matchSTM(pf(key, value), {
onFailure: Option.match({
onNone: () => core.succeed(acc),
onSome: core.fail
}),
onSuccess: a => core.succeed(Chunk.append(acc, a))
})), a => Array.from(a)));
/** @internal */

@@ -312,3 +318,3 @@ exports.findAllSTM = findAllSTM;

onNone: () => set(self, key, value),
onSome: stm.unit
onSome: () => stm.unit
})));

@@ -315,0 +321,0 @@ /** @internal */

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

return Option.match(SortedMap.headOption(map), {
onNone: core.retry,
onNone: () => core.retry,
onSome: elements => core.succeed(elements[0])

@@ -93,3 +93,3 @@ });

return Option.match(SortedMap.headOption(map), {
onNone: core.retry,
onNone: () => core.retry,
onSome: values => {

@@ -96,0 +96,0 @@ const head = values[1][0];

@@ -59,8 +59,3 @@ "use strict";

this[_b] = tEnqueueVariance;
}
capacity() {
return this.requestedCapacity;
}
size() {
return core.withSTMRuntime(runtime => {
this.size = core.withSTMRuntime(runtime => {
const queue = tRef.unsafeGet(this.ref, runtime.journal);

@@ -72,23 +67,54 @@ if (queue === undefined) {

});
}
isFull() {
return core.map(this.size(), size => size === this.requestedCapacity);
}
isEmpty() {
return core.map(this.size(), size => size === 0);
}
shutdown() {
return core.withSTMRuntime(runtime => {
this.isFull = core.map(this.size, size => size === this.requestedCapacity);
this.isEmpty = core.map(this.size, size => size === 0);
this.shutdown = core.withSTMRuntime(runtime => {
tRef.unsafeSet(this.ref, void 0, runtime.journal);
return stm.unit();
return stm.unit;
});
}
isShutdown() {
return core.effect(journal => {
this.isShutdown = core.effect(journal => {
const queue = tRef.unsafeGet(this.ref, journal);
return queue === undefined;
});
this.awaitShutdown = core.flatMap(this.isShutdown, isShutdown => isShutdown ? stm.unit : core.retry);
this.peek = core.withSTMRuntime(runtime => {
const queue = tRef.unsafeGet(this.ref, runtime.journal);
if (queue === undefined) {
return core.interruptAs(runtime.fiberId);
}
const head = queue[0];
if (head === undefined) {
return core.retry;
}
return core.succeed(head);
});
this.peekOption = core.withSTMRuntime(runtime => {
const queue = tRef.unsafeGet(this.ref, runtime.journal);
if (queue === undefined) {
return core.interruptAs(runtime.fiberId);
}
return core.succeed(Option.fromNullable(queue[0]));
});
this.take = core.withSTMRuntime(runtime => {
const queue = tRef.unsafeGet(this.ref, runtime.journal);
if (queue === undefined) {
return core.interruptAs(runtime.fiberId);
}
const dequeued = queue.shift();
if (dequeued === undefined) {
return core.retry;
}
tRef.unsafeSet(this.ref, queue, runtime.journal);
return core.succeed(dequeued);
});
this.takeAll = core.withSTMRuntime(runtime => {
const queue = tRef.unsafeGet(this.ref, runtime.journal);
if (queue === undefined) {
return core.interruptAs(runtime.fiberId);
}
tRef.unsafeSet(this.ref, [], runtime.journal);
return core.succeed(queue);
});
}
awaitShutdown() {
return core.flatMap(this.isShutdown(), isShutdown => isShutdown ? stm.unit() : core.retry());
capacity() {
return this.requestedCapacity;
}

@@ -109,3 +135,3 @@ offer(value) {

{
return core.retry();
return core.retry;
}

@@ -143,3 +169,3 @@ case OpCodes.OP_DROPPING_STRATEGY:

{
return core.retry();
return core.retry;
}

@@ -163,48 +189,2 @@ case OpCodes.OP_DROPPING_STRATEGY:

}
peek() {
return core.withSTMRuntime(runtime => {
const queue = tRef.unsafeGet(this.ref, runtime.journal);
if (queue === undefined) {
return core.interruptAs(runtime.fiberId);
}
const head = queue[0];
if (head === undefined) {
return core.retry();
}
return core.succeed(head);
});
}
peekOption() {
return core.withSTMRuntime(runtime => {
const queue = tRef.unsafeGet(this.ref, runtime.journal);
if (queue === undefined) {
return core.interruptAs(runtime.fiberId);
}
return core.succeed(Option.fromNullable(queue[0]));
});
}
take() {
return core.withSTMRuntime(runtime => {
const queue = tRef.unsafeGet(this.ref, runtime.journal);
if (queue === undefined) {
return core.interruptAs(runtime.fiberId);
}
const dequeued = queue.shift();
if (dequeued === undefined) {
return core.retry();
}
tRef.unsafeSet(this.ref, queue, runtime.journal);
return core.succeed(dequeued);
});
}
takeAll() {
return core.withSTMRuntime(runtime => {
const queue = tRef.unsafeGet(this.ref, runtime.journal);
if (queue === undefined) {
return core.interruptAs(runtime.fiberId);
}
tRef.unsafeSet(this.ref, [], runtime.journal);
return core.succeed(queue);
});
}
takeUpTo(max) {

@@ -239,3 +219,3 @@ return core.withSTMRuntime(runtime => {

exports.isTDequeue = isTDequeue;
const awaitShutdown = self => self.awaitShutdown();
const awaitShutdown = self => self.awaitShutdown;
/** @internal */

@@ -254,9 +234,9 @@ exports.awaitShutdown = awaitShutdown;

exports.dropping = dropping;
const isEmpty = self => self.isEmpty();
const isEmpty = self => self.isEmpty;
/** @internal */
exports.isEmpty = isEmpty;
const isFull = self => self.isFull();
const isFull = self => self.isFull;
/** @internal */
exports.isFull = isFull;
const isShutdown = self => self.isShutdown();
const isShutdown = self => self.isShutdown;
/** @internal */

@@ -270,6 +250,6 @@ exports.isShutdown = isShutdown;

exports.offerAll = offerAll;
const peek = self => self.peek();
const peek = self => self.peek;
/** @internal */
exports.peek = peek;
const peekOption = self => self.peekOption();
const peekOption = self => self.peekOption;
/** @internal */

@@ -282,8 +262,8 @@ exports.peekOption = peekOption;

exports.seek = seek;
const seekLoop = (self, predicate) => core.flatMap(self.take(), a => predicate(a) ? core.succeed(a) : seekLoop(self, predicate));
const seekLoop = (self, predicate) => core.flatMap(self.take, a => predicate(a) ? core.succeed(a) : seekLoop(self, predicate));
/** @internal */
const shutdown = self => self.shutdown();
const shutdown = self => self.shutdown;
/** @internal */
exports.shutdown = shutdown;
const size = self => self.size();
const size = self => self.size;
/** @internal */

@@ -294,6 +274,6 @@ exports.size = size;

exports.sliding = sliding;
const take = self => self.take();
const take = self => self.take;
/** @internal */
exports.take = take;
const takeAll = self => self.takeAll();
const takeAll = self => self.takeAll;
/** @internal */

@@ -309,6 +289,6 @@ exports.takeAll = takeAll;

if (remaining === 1) {
return core.map(a => Chunk.append(a)(Chunk.appendAll(Chunk.unsafeFromArray(taken))(acc)))(self.take());
return core.map(a => Chunk.append(a)(Chunk.appendAll(Chunk.unsafeFromArray(taken))(acc)))(self.take);
}
if (remaining > 1) {
return core.flatMap(a => takeRemainder(remaining - 1, max - taken.length - 1, Chunk.append(a)(Chunk.appendAll(Chunk.unsafeFromArray(taken))(acc))))(self.take());
return core.flatMap(a => takeRemainder(remaining - 1, max - taken.length - 1, Chunk.append(a)(Chunk.appendAll(Chunk.unsafeFromArray(taken))(acc))))(self.take);
}

@@ -315,0 +295,0 @@ return core.succeed(Chunk.appendAll(Chunk.unsafeFromArray(taken))(acc));

@@ -48,3 +48,5 @@ "use strict";

}
return core.zipRight(tArray.toArray(buffer))(stm.forEachDiscard(n => core.flatMap(k => swap(buffer, n - 1, k))(nextIntBounded(n)))(array));
return core.zipRight(tArray.toArray(buffer))(stm.forEach(n => core.flatMap(k => swap(buffer, n - 1, k))(nextIntBounded(n)), {
discard: true
})(array));
})(tArray.fromIterable(iterable));

@@ -59,14 +61,8 @@ };

this[_a] = TRandomTypeId;
this.next = withState(this.state, randomNumber);
this.nextBoolean = core.flatMap(this.next, n => core.succeed(n > 0.5));
this.nextInt = withState(this.state, randomInteger);
}
next() {
return withState(this.state, randomNumber);
}
nextBoolean() {
return core.flatMap(this.next(), n => core.succeed(n > 0.5));
}
nextInt() {
return withState(this.state, randomInteger);
}
nextRange(min, max) {
return core.flatMap(this.next(), n => core.succeed((max - min) * n + min));
return core.flatMap(this.next, n => core.succeed((max - min) * n + min));
}

@@ -82,12 +78,12 @@ nextIntBetween(low, high) {

/** @internal */
const live = () => Layer.effect(Tag, core.commit(core.map(seed => new TRandomImpl(seed))(tRef.make(new Random.PCGRandom(Math.random() * 4294967296 >>> 0).getState()))));
const live = /*#__PURE__*/Layer.effect(Tag, /*#__PURE__*/core.commit( /*#__PURE__*/core.map(seed => new TRandomImpl(seed))( /*#__PURE__*/tRef.make( /*#__PURE__*/new Random.PCGRandom(Math.random() * 4294967296 >>> 0).getState()))));
/** @internal */
exports.live = live;
const next = () => core.flatMap(Tag, random => random.next());
const next = /*#__PURE__*/core.flatMap(Tag, random => random.next);
/** @internal */
exports.next = next;
const nextBoolean = () => core.flatMap(Tag, random => random.nextBoolean());
const nextBoolean = /*#__PURE__*/core.flatMap(Tag, random => random.nextBoolean);
/** @internal */
exports.nextBoolean = nextBoolean;
const nextInt = () => core.flatMap(Tag, random => random.nextInt());
const nextInt = /*#__PURE__*/core.flatMap(Tag, random => random.nextInt);
/** @internal */

@@ -94,0 +90,0 @@ exports.nextInt = nextInt;

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

}
return core.retry();
return core.retry;
});

@@ -157,3 +157,3 @@ /** @internal */

}
return core.retry();
return core.retry;
});

@@ -174,3 +174,3 @@ /** @internal */

exports.locked = locked;
const make = () => core.map(tRef.make(emptyReadLock), readLock => new TReentranLockImpl(readLock));
const make = /*#__PURE__*/core.map( /*#__PURE__*/tRef.make(emptyReadLock), readLock => new TReentranLockImpl(readLock));
/** @internal */

@@ -177,0 +177,0 @@ exports.make = make;

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

if (value < n) {
return STM.retry();
return STM.retry;
} else {

@@ -45,0 +45,0 @@ return STM.succeed(tRef.unsafeSet(self.permits, value - n, driver.journal));

{
"name": "@effect/stm",
"version": "0.14.0",
"version": "0.15.0",
"license": "MIT",

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

@@ -623,7 +623,6 @@ import * as Context from "@effect/data/Context"

>(2, (self, finalizer) =>
matchSTM(
self,
(e) => zipRight(finalizer, fail(e)),
(a) => zipRight(finalizer, succeed(a))
))
matchSTM(self, {
onFailure: (e) => zipRight(finalizer, fail(e)),
onSuccess: (a) => zipRight(finalizer, succeed(a))
}))

@@ -654,14 +653,20 @@ /** @internal */

<E, R1, E1, A1, A, R2, E2, A2>(
onFailure: (e: E) => STM.STM<R1, E1, A1>,
onSuccess: (a: A) => STM.STM<R2, E2, A2>
options: {
readonly onFailure: (e: E) => STM.STM<R1, E1, A1>
readonly onSuccess: (a: A) => STM.STM<R2, E2, A2>
}
) => <R>(self: STM.STM<R, E, A>) => STM.STM<R1 | R2 | R, E1 | E2, A1 | A2>,
<R, E, R1, E1, A1, A, R2, E2, A2>(
self: STM.STM<R, E, A>,
onFailure: (e: E) => STM.STM<R1, E1, A1>,
onSuccess: (a: A) => STM.STM<R2, E2, A2>
options: {
readonly onFailure: (e: E) => STM.STM<R1, E1, A1>
readonly onSuccess: (a: A) => STM.STM<R2, E2, A2>
}
) => STM.STM<R1 | R2 | R, E1 | E2, A1 | A2>
>(3, <R, E, R1, E1, A1, A, R2, E2, A2>(
>(2, <R, E, R1, E1, A1, A, R2, E2, A2>(
self: STM.STM<R, E, A>,
onFailure: (e: E) => STM.STM<R1, E1, A1>,
onSuccess: (a: A) => STM.STM<R2, E2, A2>
{ onFailure, onSuccess }: {
readonly onFailure: (e: E) => STM.STM<R1, E1, A1>
readonly onSuccess: (a: A) => STM.STM<R2, E2, A2>
}
): STM.STM<R1 | R2 | R, E1 | E2, A1 | A2> =>

@@ -685,10 +690,18 @@ pipe(

/** @internal */
export const interrupt = (): STM.STM<never, never, never> =>
withSTMRuntime((_) => {
const stm = new STMPrimitive(OpCodes.OP_INTERRUPT)
stm.i1 = _.fiberId
return stm as any
})
export const withSTMRuntime = <R, E, A>(
f: (runtime: STMDriver<unknown, unknown, unknown>) => STM.STM<R, E, A>
): STM.STM<R, E, A> => {
const stm = new STMPrimitive(OpCodes.OP_WITH_STM_RUNTIME)
stm.i1 = f
return stm
}
/** @internal */
export const interrupt: STM.STM<never, never, never> = withSTMRuntime((_) => {
const stm = new STMPrimitive(OpCodes.OP_INTERRUPT)
stm.i1 = _.fiberId
return stm as any
})
/** @internal */
export const interruptAs = (fiberId: FiberId.FiberId): STM.STM<never, never, never> => {

@@ -725,6 +738,3 @@ const stm = new STMPrimitive(OpCodes.OP_INTERRUPT)

/** @internal */
export const retry = (): STM.STM<never, never, never> => {
const stm = new STMPrimitive(OpCodes.OP_RETRY)
return stm as any
}
export const retry: STM.STM<never, never, never> = new STMPrimitive(OpCodes.OP_RETRY)

@@ -746,11 +756,2 @@ /** @internal */

/** @internal */
export const withSTMRuntime = <R, E, A>(
f: (runtime: STMDriver<unknown, unknown, unknown>) => STM.STM<R, E, A>
): STM.STM<R, E, A> => {
const stm = new STMPrimitive(OpCodes.OP_WITH_STM_RUNTIME)
stm.i1 = f
return stm
}
/** @internal */
export const zip = dual<

@@ -757,0 +758,0 @@ <R1, E1, A1>(

@@ -7,2 +7,3 @@ import * as Chunk from "@effect/data/Chunk"

import * as Option from "@effect/data/Option"
import * as predicate from "@effect/data/Predicate"
import type { Predicate, Refinement } from "@effect/data/Predicate"

@@ -207,5 +208,79 @@ import * as RA from "@effect/data/ReadonlyArray"

export const catchTag = dual<
<K extends E["_tag"] & string, E extends { _tag: string }, R1, E1, A1>(
k: K,
f: (e: Extract<E, { _tag: K }>) => STM.STM<R1, E1, A1>
) => <R, A>(self: STM.STM<R, E, A>) => STM.STM<R | R1, Exclude<E, { _tag: K }> | E1, A | A1>,
<R, E extends { _tag: string }, A, K extends E["_tag"] & string, R1, E1, A1>(
self: STM.STM<R, E, A>,
k: K,
f: (e: Extract<E, { _tag: K }>) => STM.STM<R1, E1, A1>
) => STM.STM<R | R1, Exclude<E, { _tag: K }> | E1, A | A1>
>(3, (self, k, f) =>
core.catchAll(self, (e) => {
if ("_tag" in e && e["_tag"] === k) {
return f(e as any)
}
return core.fail(e as any)
}))
/** @internal */
export const catchTags: {
<
E extends { _tag: string },
Cases extends {
[K in E["_tag"]]+?: (error: Extract<E, { _tag: K }>) => STM.STM<any, any, any>
}
>(
cases: Cases
): <R, A>(self: STM.STM<R, E, A>) => STM.STM<
| R
| {
[K in keyof Cases]: Cases[K] extends ((...args: Array<any>) => STM.STM<infer R, any, any>) ? R : never
}[keyof Cases],
| Exclude<E, { _tag: keyof Cases }>
| {
[K in keyof Cases]: Cases[K] extends ((...args: Array<any>) => STM.STM<any, infer E, any>) ? E : never
}[keyof Cases],
| A
| {
[K in keyof Cases]: Cases[K] extends ((...args: Array<any>) => STM.STM<any, any, infer A>) ? A : never
}[keyof Cases]
>
<
R,
E extends { _tag: string },
A,
Cases extends {
[K in E["_tag"]]+?: (error: Extract<E, { _tag: K }>) => STM.STM<any, any, any>
}
>(
self: STM.STM<R, E, A>,
cases: Cases
): STM.STM<
| R
| {
[K in keyof Cases]: Cases[K] extends ((...args: Array<any>) => STM.STM<infer R, any, any>) ? R : never
}[keyof Cases],
| Exclude<E, { _tag: keyof Cases }>
| {
[K in keyof Cases]: Cases[K] extends ((...args: Array<any>) => STM.STM<any, infer E, any>) ? E : never
}[keyof Cases],
| A
| {
[K in keyof Cases]: Cases[K] extends ((...args: Array<any>) => STM.STM<any, any, infer A>) ? A : never
}[keyof Cases]
>
} = dual(2, (self, cases) =>
core.catchAll(self, (e: any) => {
const keys = Object.keys(cases)
if ("_tag" in e && keys.includes(e["_tag"])) {
return cases[e["_tag"]](e as any)
}
return core.fail(e as any)
}))
/** @internal */
export const check = (predicate: LazyArg<boolean>): STM.STM<never, never, void> =>
suspend(() => predicate() ? unit() : core.retry())
suspend(() => predicate() ? unit : core.retry)

@@ -223,45 +298,2 @@ /** @internal */

/** @internal */
export const collectAll = <R, E, A>(iterable: Iterable<STM.STM<R, E, A>>): STM.STM<R, E, Array<A>> =>
forEach(iterable, identity)
/** @internal */
export const collectAllDiscard = <R, E, A>(iterable: Iterable<STM.STM<R, E, A>>): STM.STM<R, E, void> =>
pipe(iterable, forEachDiscard(identity))
/** @internal */
export const collectFirst = dual<
<A, R, E, A2>(
pf: (a: A) => STM.STM<R, E, Option.Option<A2>>
) => (
iterable: Iterable<A>
) => STM.STM<R, E, Option.Option<A2>>,
<A, R, E, A2>(
iterable: Iterable<A>,
pf: (a: A) => STM.STM<R, E, Option.Option<A2>>
) => STM.STM<R, E, Option.Option<A2>>
>(2, <A, R, E, A2>(
iterable: Iterable<A>,
pf: (a: A) => STM.STM<R, E, Option.Option<A2>>
): STM.STM<R, E, Option.Option<A2>> =>
pipe(
core.sync(() => iterable[Symbol.iterator]()),
core.flatMap((iterator) => {
const loop: STM.STM<R, E, Option.Option<A2>> = suspend(() => {
const next = iterator.next()
if (next.done) {
return succeedNone()
}
return pipe(
pf(next.value),
core.flatMap(Option.match({
onNone: () => loop,
onSome: succeedSome
}))
)
})
return loop
})
))
/** @internal */
export const collectSTM = dual<

@@ -278,5 +310,8 @@ <A, R2, E2, A2>(

>(2, (self, pf) =>
core.matchSTM(self, core.fail, (a) => {
const option = pf(a)
return Option.isSome(option) ? option.value : core.retry()
core.matchSTM(self, {
onFailure: core.fail,
onSuccess: (a) => {
const option = pf(a)
return Option.isSome(option) ? option.value : core.retry
}
}))

@@ -301,7 +336,7 @@

export const either = <R, E, A>(self: STM.STM<R, E, A>): STM.STM<R, never, Either.Either<E, A>> =>
match(self, Either.left, Either.right)
match(self, { onFailure: Either.left, onSuccess: Either.right })
/** @internal */
export const eventually = <R, E, A>(self: STM.STM<R, E, A>): STM.STM<R, E, A> =>
core.matchSTM(self, () => eventually(self), core.succeed)
core.matchSTM(self, { onFailure: () => eventually(self), onSuccess: core.succeed })

@@ -358,4 +393,5 @@ /** @internal */

/** @internal */
export const fiberId = (): STM.STM<never, never, FiberId.FiberId> =>
core.effect<never, FiberId.FiberId>((_, fiberId) => fiberId)
export const fiberId: STM.STM<never, never, FiberId.FiberId> = core.effect<never, FiberId.FiberId>((_, fiberId) =>
fiberId
)

@@ -418,20 +454,2 @@ /** @internal */

predicate: Predicate<A>,
orElse: LazyArg<STM.STM<R2, E2, A2>>
) => <R, E>(
self: STM.STM<R, E, A>
) => STM.STM<R2 | R, E2 | E, A | A2>,
<R, E, A, R2, E2, A2>(
self: STM.STM<R, E, A>,
predicate: Predicate<A>,
orElse: LazyArg<STM.STM<R2, E2, A2>>
) => STM.STM<R2 | R, E2 | E, A | A2>
>(
3,
(self, predicate, orElse) => filterOrElseWith(self, predicate, orElse)
)
/** @internal */
export const filterOrElseWith = dual<
<A, R2, E2, A2>(
predicate: Predicate<A>,
orElse: (a: A) => STM.STM<R2, E2, A2>

@@ -461,9 +479,9 @@ ) => <R, E>(

export const filterOrFail = dual<
<A, E2>(predicate: Predicate<A>, error: LazyArg<E2>) => <R, E>(self: STM.STM<R, E, A>) => STM.STM<R, E2 | E, A>,
<R, E, A, E2>(self: STM.STM<R, E, A>, predicate: Predicate<A>, error: LazyArg<E2>) => STM.STM<R, E2 | E, A>
>(3, (self, predicate, error) =>
<A, E2>(predicate: Predicate<A>, orFailWith: (a: A) => E2) => <R, E>(self: STM.STM<R, E, A>) => STM.STM<R, E2 | E, A>,
<R, E, A, E2>(self: STM.STM<R, E, A>, predicate: Predicate<A>, orFailWith: (a: A) => E2) => STM.STM<R, E2 | E, A>
>(3, (self, predicate, orFailWith) =>
filterOrElse(
self,
predicate,
() => core.failSync(error)
(a) => core.failSync(() => orFailWith(a))
))

@@ -476,3 +494,4 @@

/** @internal */
export const flip = <R, E, A>(self: STM.STM<R, E, A>): STM.STM<R, A, E> => core.matchSTM(self, core.succeed, core.fail)
export const flip = <R, E, A>(self: STM.STM<R, E, A>): STM.STM<R, A, E> =>
core.matchSTM(self, { onFailure: core.succeed, onSuccess: core.fail })

@@ -494,56 +513,69 @@ /** @internal */

export const match = dual<
<E, A2, A, A3>(f: (error: E) => A2, g: (value: A) => A3) => <R>(self: STM.STM<R, E, A>) => STM.STM<R, never, A2 | A3>,
<R, E, A2, A, A3>(self: STM.STM<R, E, A>, f: (error: E) => A2, g: (value: A) => A3) => STM.STM<R, never, A2 | A3>
>(3, (self, f, g) =>
core.matchSTM(
self,
(e) => core.succeed(f(e)),
(a) => core.succeed(g(a))
))
<E, A2, A, A3>(options: {
readonly onFailure: (error: E) => A2
readonly onSuccess: (value: A) => A3
}) => <R>(self: STM.STM<R, E, A>) => STM.STM<R, never, A2 | A3>,
<R, E, A2, A, A3>(self: STM.STM<R, E, A>, options: {
readonly onFailure: (error: E) => A2
readonly onSuccess: (value: A) => A3
}) => STM.STM<R, never, A2 | A3>
>(2, (self, { onFailure, onSuccess }) =>
core.matchSTM(self, {
onFailure: (e) => core.succeed(onFailure(e)),
onSuccess: (a) => core.succeed(onSuccess(a))
}))
/** @internal */
export const forEach = dual<
<A, R, E, A2>(f: (a: A) => STM.STM<R, E, A2>) => (elements: Iterable<A>) => STM.STM<R, E, Array<A2>>,
<A, R, E, A2>(elements: Iterable<A>, f: (a: A) => STM.STM<R, E, A2>) => STM.STM<R, E, Array<A2>>
{
<A, R, E, A2>(f: (a: A) => STM.STM<R, E, A2>, options?: {
readonly discard?: false
}): (elements: Iterable<A>) => STM.STM<R, E, Array<A2>>
<A, R, E, A2>(f: (a: A) => STM.STM<R, E, A2>, options: {
readonly discard: true
}): (elements: Iterable<A>) => STM.STM<R, E, void>
},
{
<A, R, E, A2>(elements: Iterable<A>, f: (a: A) => STM.STM<R, E, A2>, options?: {
readonly discard?: false
}): STM.STM<R, E, Array<A2>>
<A, R, E, A2>(elements: Iterable<A>, f: (a: A) => STM.STM<R, E, A2>, options: {
readonly discard: true
}): STM.STM<R, E, void>
}
>(
2,
<A, R, E, A2>(elements: Iterable<A>, f: (a: A) => STM.STM<R, E, A2>): STM.STM<R, E, Array<A2>> =>
suspend(() =>
Array.from(elements).reduce(
(args) => predicate.isIterable(args[0]),
<A, R, E, A2>(iterable: Iterable<A>, f: (a: A) => STM.STM<R, E, A2>, options?: {
readonly discard?: boolean
}): STM.STM<R, E, any> => {
if (options?.discard) {
return pipe(
core.sync(() => iterable[Symbol.iterator]()),
core.flatMap((iterator) => {
const loop: STM.STM<R, E, void> = suspend(() => {
const next = iterator.next()
if (next.done) {
return unit
}
return pipe(f(next.value), core.flatMap(() => loop))
})
return loop
})
)
}
return suspend(() =>
RA.fromIterable(iterable).reduce(
(acc, curr) =>
pipe(
acc,
core.zipWith(f(curr), (array, elem) => {
array.push(elem)
return array
})
),
core.zipWith(acc, f(curr), (array, elem) => {
array.push(elem)
return array
}),
core.succeed([]) as STM.STM<R, E, Array<A2>>
)
)
}
)
/** @internal */
export const forEachDiscard = dual<
<A, R, E, _>(f: (a: A) => STM.STM<R, E, _>) => (iterable: Iterable<A>) => STM.STM<R, E, void>,
<A, R, E, _>(iterable: Iterable<A>, f: (a: A) => STM.STM<R, E, _>) => STM.STM<R, E, void>
>(
2,
<A, R, E, _>(iterable: Iterable<A>, f: (a: A) => STM.STM<R, E, _>): STM.STM<R, E, void> =>
pipe(
core.sync(() => iterable[Symbol.iterator]()),
core.flatMap((iterator) => {
const loop: STM.STM<R, E, void> = suspend(() => {
const next = iterator.next()
if (next.done) {
return unit()
}
return pipe(f(next.value), core.flatMap(() => loop))
})
return loop
})
)
)
/** @internal */
export const fromEither = <E, A>(either: Either.Either<E, A>): STM.STM<never, E, A> => {

@@ -607,5 +639,5 @@ switch (either._tag) {

self,
core.matchSTM(
(e) => core.fail(Option.some(e)),
(a) => {
core.matchSTM({
onFailure: (e) => core.fail(Option.some(e)),
onSuccess: (a) => {
const i = a[Symbol.iterator]()

@@ -619,38 +651,59 @@ const res = i.next()

}
)
})
)
/** @internal */
export const ifSTM = dual<
export const if_ = dual<
<R1, R2, E1, E2, A, A1>(
onTrue: STM.STM<R1, E1, A>,
onFalse: STM.STM<R2, E2, A1>
) => <R, E>(
self: STM.STM<R, E, boolean>
options: {
readonly onTrue: STM.STM<R1, E1, A>
readonly onFalse: STM.STM<R2, E2, A1>
}
) => <R = never, E = never>(
self: STM.STM<R, E, boolean> | boolean
) => STM.STM<R1 | R2 | R, E1 | E2 | E, A | A1>,
<R, E, R1, R2, E1, E2, A, A1>(
self: STM.STM<R, E, boolean>,
onTrue: STM.STM<R1, E1, A>,
onFalse: STM.STM<R2, E2, A1>
) => STM.STM<R1 | R2 | R, E1 | E2 | E, A | A1>
{
<R, E, R1, R2, E1, E2, A, A1>(
self: boolean,
options: {
readonly onTrue: STM.STM<R1, E1, A>
readonly onFalse: STM.STM<R2, E2, A1>
}
): STM.STM<R1 | R2 | R, E1 | E2 | E, A | A1>
<R, E, R1, R2, E1, E2, A, A1>(
self: STM.STM<R, E, boolean>,
options: {
readonly onTrue: STM.STM<R1, E1, A>
readonly onFalse: STM.STM<R2, E2, A1>
}
): STM.STM<R1 | R2 | R, E1 | E2 | E, A | A1>
}
>(
3,
(args) => typeof args[0] === "boolean" || core.isSTM(args[0]),
<R, E, R1, R2, E1, E2, A, A1>(
self: STM.STM<R, E, boolean>,
onTrue: STM.STM<R1, E1, A>,
onFalse: STM.STM<R2, E2, A1>
): STM.STM<R1 | R2 | R, E1 | E2 | E, A | A1> =>
core.flatMap(self, (bool): STM.STM<R1 | R2, E1 | E2, A | A1> => bool ? onTrue : onFalse)
self: STM.STM<R, E, boolean> | boolean,
{ onFalse, onTrue }: {
readonly onTrue: STM.STM<R1, E1, A>
readonly onFalse: STM.STM<R2, E2, A1>
}
) => {
if (typeof self === "boolean") {
return self ? onTrue : onFalse
}
return core.flatMap(self, (bool): STM.STM<R1 | R2 | R, E1 | E2 | E, A | A1> => bool ? onTrue : onFalse)
}
)
/** @internal */
export const ignore = <R, E, A>(self: STM.STM<R, E, A>): STM.STM<R, never, void> => match(self, unit, unit)
export const ignore = <R, E, A>(self: STM.STM<R, E, A>): STM.STM<R, never, void> =>
match(self, { onFailure: () => unit, onSuccess: () => unit })
/** @internal */
export const isFailure = <R, E, A>(self: STM.STM<R, E, A>): STM.STM<R, never, boolean> =>
match(self, constTrue, constFalse)
match(self, { onFailure: constTrue, onSuccess: constFalse })
/** @internal */
export const isSuccess = <R, E, A>(self: STM.STM<R, E, A>): STM.STM<R, never, boolean> =>
match(self, constFalse, constTrue)
match(self, { onFailure: constFalse, onSuccess: constTrue })

@@ -660,7 +713,7 @@ /** @internal */

initial: Z,
cont: (z: Z) => boolean,
body: (z: Z) => STM.STM<R, E, Z>
): STM.STM<R, E, Z> => {
return iterateLoop(initial, cont, body)
}
options: {
readonly while: (z: Z) => boolean
readonly body: (z: Z) => STM.STM<R, E, Z>
}
): STM.STM<R, E, Z> => iterateLoop(initial, options.while, options.body)

@@ -682,10 +735,33 @@ const iterateLoop = <R, E, Z>(

/** @internal */
export const loop = <Z, R, E, A>(
export const loop: {
<Z, R, E, A>(
initial: Z,
options: {
readonly while: (z: Z) => boolean
readonly step: (z: Z) => Z
readonly body: (z: Z) => STM.STM<R, E, A>
readonly discard?: false
}
): STM.STM<R, E, Array<A>>
<Z, R, E, A>(
initial: Z,
options: {
readonly while: (z: Z) => boolean
readonly step: (z: Z) => Z
readonly body: (z: Z) => STM.STM<R, E, A>
readonly discard: true
}
): STM.STM<R, E, void>
} = <Z, R, E, A>(
initial: Z,
cont: (z: Z) => boolean,
inc: (z: Z) => Z,
body: (z: Z) => STM.STM<R, E, A>
): STM.STM<R, E, Array<A>> => {
return core.map(loopLoop(initial, cont, inc, body), (a) => Array.from(a))
}
options: {
readonly while: (z: Z) => boolean
readonly step: (z: Z) => Z
readonly body: (z: Z) => STM.STM<R, E, A>
readonly discard?: boolean
}
): STM.STM<R, E, any> =>
options.discard ?
loopDiscardLoop(initial, options.while, options.step, options.body) :
core.map(loopLoop(initial, options.while, options.step, options.body), (a) => Array.from(a))

@@ -707,12 +783,2 @@ const loopLoop = <Z, R, E, A>(

/** @internal */
export const loopDiscard = <Z, R, E, X>(
initial: Z,
cont: (z: Z) => boolean,
inc: (z: Z) => Z,
body: (z: Z) => STM.STM<R, E, X>
): STM.STM<R, E, void> => {
return loopDiscardLoop(initial, cont, inc, body)
}
const loopDiscardLoop = <Z, R, E, X>(

@@ -730,3 +796,3 @@ initial: Z,

}
return unit()
return unit
}

@@ -739,18 +805,22 @@

>(2, <R, E, A, B>(self: STM.STM<R, E, A>, f: (a: A) => B): STM.STM<R, unknown, B> =>
core.matchSTM(
self,
(e) => core.fail(e),
(a) => attempt(() => f(a))
))
core.matchSTM(self, {
onFailure: (e) => core.fail(e),
onSuccess: (a) => attempt(() => f(a))
}))
/** @internal */
export const mapBoth = dual<
<E, E2, A, A2>(f: (error: E) => E2, g: (value: A) => A2) => <R>(self: STM.STM<R, E, A>) => STM.STM<R, E2, A2>,
<R, E, E2, A, A2>(self: STM.STM<R, E, A>, f: (error: E) => E2, g: (value: A) => A2) => STM.STM<R, E2, A2>
>(3, (self, f, g) =>
core.matchSTM(
self,
(e) => core.fail(f(e)),
(a) => core.succeed(g(a))
))
<E, E2, A, A2>(options: {
readonly onFailure: (error: E) => E2
readonly onSuccess: (value: A) => A2
}) => <R>(self: STM.STM<R, E, A>) => STM.STM<R, E2, A2>,
<R, E, E2, A, A2>(self: STM.STM<R, E, A>, options: {
readonly onFailure: (error: E) => E2
readonly onSuccess: (value: A) => A2
}) => STM.STM<R, E2, A2>
>(2, (self, { onFailure, onSuccess }) =>
core.matchSTM(self, {
onFailure: (e) => core.fail(onFailure(e)),
onSuccess: (a) => core.succeed(onSuccess(a))
}))

@@ -762,11 +832,10 @@ /** @internal */

>(2, (self, f) =>
core.matchSTM(
self,
(e) => core.fail(f(e)),
core.succeed
))
core.matchSTM(self, {
onFailure: (e) => core.fail(f(e)),
onSuccess: core.succeed
}))
/** @internal */
export const merge = <R, E, A>(self: STM.STM<R, E, A>): STM.STM<R, never, E | A> =>
core.matchSTM(self, (e) => core.succeed(e), core.succeed)
core.matchSTM(self, { onFailure: (e) => core.succeed(e), onSuccess: core.succeed })

@@ -793,14 +862,13 @@ /** @internal */

export const none = <R, E, A>(self: STM.STM<R, E, Option.Option<A>>): STM.STM<R, Option.Option<E>, void> =>
core.matchSTM(
self,
(e) => core.fail(Option.some(e)),
Option.match({
onNone: unit,
core.matchSTM(self, {
onFailure: (e) => core.fail(Option.some(e)),
onSuccess: Option.match({
onNone: () => unit,
onSome: () => core.fail(Option.none())
})
)
})
/** @internal */
export const option = <R, E, A>(self: STM.STM<R, E, A>): STM.STM<R, never, Option.Option<A>> =>
match(self, () => Option.none(), Option.some)
match(self, { onFailure: () => Option.none(), onSuccess: Option.some })

@@ -1107,3 +1175,3 @@ /** @internal */

<R, E, A>(self: STM.STM<R, E, A>, n: number) => STM.STM<R, E, Array<A>>
>(2, (self, n) => pipe(self, replicate(n), collectAll))
>(2, (self, n) => pipe(self, replicate(n), all()))

@@ -1114,3 +1182,3 @@ /** @internal */

<R, E, A>(self: STM.STM<R, E, A>, n: number) => STM.STM<R, E, void>
>(2, (self, n) => pipe(self, replicate(n), collectAllDiscard))
>(2, (self, n) => pipe(self, replicate(n), all({ discard: true })))

@@ -1130,3 +1198,3 @@ /** @internal */

<R, E, A>(self: STM.STM<R, E, A>, predicate: Predicate<A>) =>
core.matchSTM(self, core.fail, (a) => predicate(a) ? core.succeed(a) : core.retry())
core.matchSTM(self, { onFailure: core.fail, onSuccess: (a) => predicate(a) ? core.succeed(a) : core.retry })
)

@@ -1140,3 +1208,4 @@

2,
(self, predicate) => core.matchSTM(self, core.fail, (a) => !predicate(a) ? core.succeed(a) : core.retry())
(self, predicate) =>
core.matchSTM(self, { onFailure: core.fail, onSuccess: (a) => !predicate(a) ? core.succeed(a) : core.retry })
)

@@ -1163,108 +1232,54 @@

export const some = <R, E, A>(self: STM.STM<R, E, Option.Option<A>>): STM.STM<R, Option.Option<E>, A> =>
core.matchSTM(
self,
(e) => core.fail(Option.some(e)),
Option.match({
core.matchSTM(self, {
onFailure: (e) => core.fail(Option.some(e)),
onSuccess: Option.match({
onNone: () => core.fail(Option.none()),
onSome: core.succeed
})
)
})
/** @internal */
export const someOrElse = dual<
<A2>(orElse: LazyArg<A2>) => <R, E, A>(self: STM.STM<R, E, Option.Option<A>>) => STM.STM<R, E, A2 | A>,
<R, E, A, A2>(self: STM.STM<R, E, Option.Option<A>>, orElse: LazyArg<A2>) => STM.STM<R, E, A2 | A>
>(2, (self, orElse) => pipe(self, core.map(Option.getOrElse(orElse))))
const allIsDataFirst = (args: IArguments) => {
if (args.length === 0) {
return false
} else if (args.length > 1) {
return true
} else if (Symbol.iterator in args[0]) {
return true
}
/** @internal */
export const someOrElseSTM = dual<
<R2, E2, A2>(
orElse: LazyArg<STM.STM<R2, E2, A2>>
) => <R, E, A>(
self: STM.STM<R, E, Option.Option<A>>
) => STM.STM<R2 | R, E2 | E, A2 | A>,
<R, E, A, R2, E2, A2>(
self: STM.STM<R, E, Option.Option<A>>,
orElse: LazyArg<STM.STM<R2, E2, A2>>
) => STM.STM<R2 | R, E2 | E, A2 | A>
>(2, <R, E, A, R2, E2, A2>(
self: STM.STM<R, E, Option.Option<A>>,
orElse: LazyArg<STM.STM<R2, E2, A2>>
): STM.STM<R2 | R, E2 | E, A2 | A> =>
core.flatMap(
self,
Option.match({
onNone: (): STM.STM<R | R2, E | E2, A | A2> => orElse(),
onSome: core.succeed
})
))
const obj: STM.All.Options = args[0]
return (
typeof obj.discard === "boolean"
) === false
}
/* @internal */
export const all: {
<R, E, A, T extends ReadonlyArray<STM.STM<any, any, any>>>(
self: STM.STM<R, E, A>,
...args: T
): STM.STM<
R | T["length"] extends 0 ? never
: [T[number]] extends [{ [STM.STMTypeId]: { _R: (_: never) => infer R } }] ? R
: never,
E | T["length"] extends 0 ? never
: [T[number]] extends [{ [STM.STMTypeId]: { _E: (_: never) => infer E } }] ? E
: never,
readonly [
A,
...(T["length"] extends 0 ? []
: Readonly<{ [K in keyof T]: [T[K]] extends [STM.STM<any, any, infer A>] ? A : never }>)
]
>
<T extends ReadonlyArray<STM.STM<any, any, any>>>(
args: [...T]
): STM.STM<
T[number] extends never ? never
: [T[number]] extends [{ [STM.STMTypeId]: { _R: (_: never) => infer R } }] ? R
: never,
T[number] extends never ? never
: [T[number]] extends [{ [STM.STMTypeId]: { _E: (_: never) => infer E } }] ? E
: never,
T[number] extends never ? []
: Readonly<{ [K in keyof T]: [T[K]] extends [STM.STM<any, any, infer A>] ? A : never }>
>
<T extends Readonly<{ [K: string]: STM.STM<any, any, any> }>>(
args: T
): STM.STM<
keyof T extends never ? never
: [T[keyof T]] extends [{ [STM.STMTypeId]: { _R: (_: never) => infer R } }] ? R
: never,
keyof T extends never ? never
: [T[keyof T]] extends [{ [STM.STMTypeId]: { _E: (_: never) => infer E } }] ? E
: never,
Readonly<{ [K in keyof T]: [T[K]] extends [STM.STM<any, any, infer A>] ? A : never }>
>
} = function() {
if (arguments.length === 1) {
if (core.isSTM(arguments[0])) {
return core.map(arguments[0], (x) => [x])
} else if (Symbol.iterator in arguments[0]) {
return collectAll(arguments[0])
} else {
return pipe(
forEach(
Object.entries(arguments[0] as Readonly<{ [K: string]: STM.STM<any, any, any> }>),
([_, e]) => core.map(e, (a) => [_, a] as const)
),
core.map((values) => {
const res = {}
for (const [k, v] of values) {
;(res as any)[k] = v
}
return res
})
) as any
}
export const all = dual<
(options?: STM.All.Options) => (arg: Iterable<STM.All.STMAny> | Record<string, STM.All.STMAny>) => STM.All.STMAny,
(arg: Iterable<STM.All.STMAny> | Record<string, STM.All.STMAny>, options?: STM.All.Options) => STM.All.STMAny
>(allIsDataFirst, (input, options) => {
if (Symbol.iterator in input) {
return forEach(input, identity, options as any)
} else if (options?.discard) {
return forEach(Object.values(input), identity, options as any)
}
return collectAll(arguments)
}
return pipe(
forEach(
Object.entries(input),
([_, e]) => core.map(e, (a) => [_, a] as const)
),
core.map((values) => {
const res = {}
for (const [k, v] of values) {
;(res as any)[k] = v
}
return res
})
)
}) as STM.All.Signature
/** @internal */
export const succeedNone = (): STM.STM<never, never, Option.Option<never>> => core.succeed(Option.none())
export const succeedNone: STM.STM<never, never, Option.Option<never>> = core.succeed(Option.none())

@@ -1307,4 +1322,6 @@ /** @internal */

<E, R2, E2, A2, A, R3, E3, A3>(
f: (error: E) => STM.STM<R2, E2, A2>,
g: (value: A) => STM.STM<R3, E3, A3>
options: {
readonly onFailure: (error: E) => STM.STM<R2, E2, A2>
readonly onSuccess: (value: A) => STM.STM<R3, E3, A3>
}
) => <R>(

@@ -1315,11 +1332,12 @@ self: STM.STM<R, E, A>

self: STM.STM<R, E, A>,
f: (error: E) => STM.STM<R2, E2, A2>,
g: (value: A) => STM.STM<R3, E3, A3>
options: {
readonly onFailure: (error: E) => STM.STM<R2, E2, A2>
readonly onSuccess: (value: A) => STM.STM<R3, E3, A3>
}
) => STM.STM<R2 | R3 | R, E | E2 | E3, A>
>(3, (self, f, g) =>
core.matchSTM(
self,
(e) => pipe(f(e), core.zipRight(core.fail(e))),
(a) => pipe(g(a), as(a))
))
>(2, (self, { onFailure, onSuccess }) =>
core.matchSTM(self, {
onFailure: (e) => pipe(onFailure(e), core.zipRight(core.fail(e))),
onSuccess: (a) => pipe(onSuccess(a), as(a))
}))

@@ -1331,23 +1349,32 @@ /** @internal */

>(2, (self, f) =>
core.matchSTM(
self,
(e) => core.zipRight(f(e), core.fail(e)),
core.succeed
))
core.matchSTM(self, {
onFailure: (e) => core.zipRight(f(e), core.fail(e)),
onSuccess: core.succeed
}))
/** @internal */
export const tryCatch = <E, A>(
attempt: () => A,
onThrow: (u: unknown) => E
): Effect.Effect<never, E, A> =>
suspend(() => {
export const try_: {
<A>(try_: LazyArg<A>): STM.STM<never, unknown, A>
<A, E>(options: {
readonly try: LazyArg<A>
readonly catch: (u: unknown) => E
}): STM.STM<never, E, A>
} = <A, E>(
arg: LazyArg<A> | {
readonly try: LazyArg<A>
readonly catch: (u: unknown) => E
}
) => {
const evaluate = typeof arg === "function" ? arg : arg.try
return suspend(() => {
try {
return core.succeed(attempt())
return core.succeed(evaluate())
} catch (error) {
return core.fail(onThrow(error))
return core.fail("catch" in arg ? arg.catch(error) : error)
}
})
}
/** @internal */
export const unit = (): STM.STM<never, never, void> => core.succeed(void 0)
export const unit: STM.STM<never, never, void> = core.succeed(void 0)

@@ -1360,3 +1387,3 @@ /** @internal */

suspend(
() => predicate() ? succeedNone() : asSome(self)
() => predicate() ? succeedNone : asSome(self)
))

@@ -1378,3 +1405,3 @@

predicate,
(bool) => bool ? succeedNone() : asSome(self)
(bool) => bool ? succeedNone : asSome(self)
))

@@ -1384,10 +1411,9 @@

export const unsome = <R, E, A>(self: STM.STM<R, Option.Option<E>, A>): STM.STM<R, E, Option.Option<A>> =>
core.matchSTM(
self,
Option.match({
core.matchSTM(self, {
onFailure: Option.match({
onNone: () => core.succeed(Option.none()),
onSome: core.fail
}),
(a) => core.succeed(Option.some(a))
)
onSuccess: (a) => core.succeed(Option.some(a))
})

@@ -1426,3 +1452,3 @@ /** @internal */

suspend(
() => predicate() ? asSome(self) : succeedNone()
() => predicate() ? asSome(self) : succeedNone
))

@@ -1444,3 +1470,3 @@

predicate,
(bool) => bool ? asSome(self) : succeedNone()
(bool) => bool ? asSome(self) : succeedNone
))

@@ -68,3 +68,3 @@ import * as Equal from "@effect/data/Equal"

Option.match({
onNone: () => stm.succeedNone(),
onNone: () => stm.succeedNone,
onSome: core.map(Option.some)

@@ -165,3 +165,3 @@ })

if (from < 0) {
return stm.succeedNone()
return stm.succeedNone
}

@@ -221,5 +221,5 @@ return core.effect<never, Option.Option<number>>((journal) => {

)
: stm.succeedNone()
: stm.succeedNone
return from < 0
? stm.succeedNone()
? stm.succeedNone
: forIndex(from)

@@ -244,13 +244,16 @@ })

return core.map(
stm.iterate(init, cont, (state) => {
const index = state[1]
return pipe(
tRef.get(self.chunk[index]),
core.flatMap((value) =>
core.map(
predicate(value),
(bool) => [bool ? Option.some(value) : Option.none(), index + 1] as const
stm.iterate(init, {
while: cont,
body: (state) => {
const index = state[1]
return pipe(
tRef.get(self.chunk[index]),
core.flatMap((value) =>
core.map(
predicate(value),
(bool) => [bool ? Option.some(value) : Option.none(), index + 1] as const
)
)
)
)
}
}),

@@ -291,3 +294,3 @@ (state) => state[0]

if (end >= self.chunk.length) {
return stm.succeedNone()
return stm.succeedNone
}

@@ -322,13 +325,16 @@ return core.effect<never, Option.Option<number>>((journal) => {

return core.map(
stm.iterate(init, cont, (state) => {
const index = state[1]
return pipe(
tRef.get(self.chunk[index]),
core.flatMap((value) =>
core.map(
predicate(value),
(bool) => [bool ? Option.some(value) : Option.none(), index - 1] as const
stm.iterate(init, {
while: cont,
body: (state) => {
const index = state[1]
return pipe(
tRef.get(self.chunk[index]),
core.flatMap((value) =>
core.map(
predicate(value),
(bool) => [bool ? Option.some(value) : Option.none(), index - 1] as const
)
)
)
)
}
}),

@@ -372,3 +378,3 @@ (state) => state[0]

self.chunk.length === 0 ?
stm.succeedNone() :
stm.succeedNone :
core.map(tRef.get(self.chunk[self.chunk.length - 1]), Option.some)

@@ -375,0 +381,0 @@

@@ -55,9 +55,12 @@ import { dual, identity, pipe } from "@effect/data/Function"

awaitShutdown(): STM.STM<never, never, void> {
return core.flatMap(
this.isShutdown(),
(isShutdown) => isShutdown ? stm.unit() : core.retry()
)
}
isShutdown: STM.STM<never, never, boolean> = core.effect<never, boolean>((journal) => {
const currentPublisherTail = tRef.unsafeGet(this.publisherTail, journal)
return currentPublisherTail === undefined
})
awaitShutdown: STM.STM<never, never, void> = core.flatMap(
this.isShutdown,
(isShutdown) => isShutdown ? stm.unit : core.retry
)
capacity(): number {

@@ -67,16 +70,13 @@ return this.requestedCapacity

isEmpty(): STM.STM<never, never, boolean> {
return core.map(this.size(), (size) => size === 0)
}
size: STM.STM<never, never, number> = core.withSTMRuntime((runtime) => {
const currentPublisherTail = tRef.unsafeGet(this.publisherTail, runtime.journal)
if (currentPublisherTail === undefined) {
return core.interruptAs(runtime.fiberId)
}
return core.succeed(tRef.unsafeGet(this.hubSize, runtime.journal))
})
isFull(): STM.STM<never, never, boolean> {
return core.map(this.size(), (size) => size === this.capacity())
}
isEmpty: STM.STM<never, never, boolean> = core.map(this.size, (size) => size === 0)
isShutdown(): STM.STM<never, never, boolean> {
return core.effect<never, boolean>((journal) => {
const currentPublisherTail = tRef.unsafeGet(this.publisherTail, journal)
return currentPublisherTail === undefined
})
}
isFull: STM.STM<never, never, boolean> = core.map(this.size, (size) => size === this.capacity())

@@ -108,3 +108,3 @@ offer(value: A): STM.STM<never, never, boolean> {

case OpCodes.OP_BACKPRESSURE_STRATEGY: {
return core.retry()
return core.retry
}

@@ -124,3 +124,3 @@ case OpCodes.OP_DROPPING_STRATEGY: {

if (node === undefined) {
return core.retry()
return core.retry
}

@@ -160,25 +160,13 @@ const head = node.head

size(): STM.STM<never, never, number> {
return core.withSTMRuntime((runtime) => {
const currentPublisherTail = tRef.unsafeGet(this.publisherTail, runtime.journal)
if (currentPublisherTail === undefined) {
return core.interruptAs(runtime.fiberId)
}
return core.succeed(tRef.unsafeGet(this.hubSize, runtime.journal))
})
}
shutdown(): STM.STM<never, never, void> {
return core.effect<never, void>((journal) => {
const currentPublisherTail = tRef.unsafeGet(this.publisherTail, journal)
if (currentPublisherTail !== undefined) {
tRef.unsafeSet<TRef.TRef<Node<A> | undefined> | undefined>(this.publisherTail, void 0, journal)
const currentSubscribers = tRef.unsafeGet(this.subscribers, journal)
HashSet.forEach(currentSubscribers, (subscriber) => {
tRef.unsafeSet<TRef.TRef<Node<A>> | undefined>(subscriber, void 0, journal)
})
tRef.unsafeSet(this.subscribers, HashSet.empty<TRef.TRef<TRef.TRef<Node<A>> | undefined>>(), journal)
}
})
}
shutdown: STM.STM<never, never, void> = core.effect<never, void>((journal) => {
const currentPublisherTail = tRef.unsafeGet(this.publisherTail, journal)
if (currentPublisherTail !== undefined) {
tRef.unsafeSet<TRef.TRef<Node<A> | undefined> | undefined>(this.publisherTail, void 0, journal)
const currentSubscribers = tRef.unsafeGet(this.subscribers, journal)
HashSet.forEach(currentSubscribers, (subscriber) => {
tRef.unsafeSet<TRef.TRef<Node<A>> | undefined>(subscriber, void 0, journal)
})
tRef.unsafeSet(this.subscribers, HashSet.empty<TRef.TRef<TRef.TRef<Node<A>> | undefined>>(), journal)
}
})
}

@@ -199,45 +187,86 @@

awaitShutdown(): STM.STM<never, never, void> {
return core.flatMap(
this.isShutdown(),
(isShutdown) => isShutdown ? stm.unit() : core.retry()
)
}
isShutdown: STM.STM<never, never, boolean> = core.effect<never, boolean>((journal) => {
const currentSubscriberHead = tRef.unsafeGet(this.subscriberHead, journal)
return currentSubscriberHead === undefined
})
awaitShutdown: STM.STM<never, never, void> = core.flatMap(
this.isShutdown,
(isShutdown) => isShutdown ? stm.unit : core.retry
)
capacity(): number {
return this.requestedCapacity
}
size: STM.STM<never, never, number> = core.withSTMRuntime((runtime) => {
let currentSubscriberHead = tRef.unsafeGet(this.subscriberHead, runtime.journal)
if (currentSubscriberHead === undefined) {
return core.interruptAs(runtime.fiberId)
}
let loop = true
let size = 0
while (loop) {
const node = tRef.unsafeGet(currentSubscriberHead, runtime.journal)
if (node === undefined) {
loop = false
} else {
const head = node.head
const tail: TRef.TRef<Node<A | undefined> | undefined> = node.tail
if (head !== undefined) {
size = size + 1
if (size >= Number.MAX_SAFE_INTEGER) {
loop = false
}
}
currentSubscriberHead = tail
}
}
return core.succeed(size)
})
isEmpty(): STM.STM<never, never, boolean> {
return core.map(this.size(), (size) => size === 0)
}
isEmpty: STM.STM<never, never, boolean> = core.map(this.size, (size) => size === 0)
isFull(): STM.STM<never, never, boolean> {
return core.map(this.size(), (size) => size === this.capacity())
}
isFull: STM.STM<never, never, boolean> = core.map(this.size, (size) => size === this.capacity())
isShutdown(): STM.STM<never, never, boolean> {
return core.effect<never, boolean>((journal) => {
const currentSubscriberHead = tRef.unsafeGet(this.subscriberHead, journal)
return currentSubscriberHead === undefined
})
}
peek: STM.STM<never, never, A> = core.withSTMRuntime((runtime) => {
let currentSubscriberHead = tRef.unsafeGet(this.subscriberHead, runtime.journal)
if (currentSubscriberHead === undefined) {
return core.interruptAs(runtime.fiberId)
}
let value: A | undefined = undefined
let loop = true
while (loop) {
const node = tRef.unsafeGet(currentSubscriberHead, runtime.journal)
if (node === undefined) {
return core.retry
}
const head = node.head
const tail: TRef.TRef<Node<A | undefined> | undefined> = node.tail
if (head !== undefined) {
value = head
loop = false
} else {
currentSubscriberHead = tail
}
}
return core.succeed(value!)
})
peek(): STM.STM<never, never, A> {
return core.withSTMRuntime((runtime) => {
let currentSubscriberHead = tRef.unsafeGet(this.subscriberHead, runtime.journal)
if (currentSubscriberHead === undefined) {
return core.interruptAs(runtime.fiberId)
}
let value: A | undefined = undefined
let loop = true
while (loop) {
const node = tRef.unsafeGet(currentSubscriberHead, runtime.journal)
if (node === undefined) {
return core.retry()
}
peekOption: STM.STM<never, never, Option.Option<A>> = core.withSTMRuntime((runtime) => {
let currentSubscriberHead = tRef.unsafeGet(this.subscriberHead, runtime.journal)
if (currentSubscriberHead === undefined) {
return core.interruptAs(runtime.fiberId)
}
let value: Option.Option<A> = Option.none()
let loop = true
while (loop) {
const node = tRef.unsafeGet(currentSubscriberHead, runtime.journal)
if (node === undefined) {
value = Option.none()
loop = false
} else {
const head = node.head
const tail: TRef.TRef<Node<A | undefined> | undefined> = node.tail
if (head !== undefined) {
value = head
value = Option.some(head)
loop = false

@@ -248,18 +277,14 @@ } else {

}
return core.succeed(value!)
})
}
}
return core.succeed(value)
})
peekOption(): STM.STM<never, never, Option.Option<A>> {
return core.withSTMRuntime((runtime) => {
let currentSubscriberHead = tRef.unsafeGet(this.subscriberHead, runtime.journal)
if (currentSubscriberHead === undefined) {
return core.interruptAs(runtime.fiberId)
}
let value: Option.Option<A> = Option.none()
shutdown: STM.STM<never, never, void> = core.effect<never, void>((journal) => {
let currentSubscriberHead = tRef.unsafeGet(this.subscriberHead, journal)
if (currentSubscriberHead !== undefined) {
tRef.unsafeSet<TRef.TRef<Node<A | undefined> | undefined> | undefined>(this.subscriberHead, void 0, journal)
let loop = true
while (loop) {
const node = tRef.unsafeGet(currentSubscriberHead, runtime.journal)
const node = tRef.unsafeGet(currentSubscriberHead, journal)
if (node === undefined) {
value = Option.none()
loop = false

@@ -270,32 +295,12 @@ } else {

if (head !== undefined) {
value = Option.some(head)
loop = false
} else {
currentSubscriberHead = tail
}
}
}
return core.succeed(value)
})
}
size(): STM.STM<never, never, number> {
return core.withSTMRuntime((runtime) => {
let currentSubscriberHead = tRef.unsafeGet(this.subscriberHead, runtime.journal)
if (currentSubscriberHead === undefined) {
return core.interruptAs(runtime.fiberId)
}
let loop = true
let size = 0
while (loop) {
const node = tRef.unsafeGet(currentSubscriberHead, runtime.journal)
if (node === undefined) {
loop = false
} else {
const head = node.head
const tail: TRef.TRef<Node<A | undefined> | undefined> = node.tail
if (head !== undefined) {
size = size + 1
if (size >= Number.MAX_SAFE_INTEGER) {
loop = false
const subscribers = node.subscribers
if (subscribers === 1) {
const size = tRef.unsafeGet(this.hubSize, journal)
const updatedNode = makeNode(undefined, 0, tail)
tRef.unsafeSet<Node<A | undefined> | undefined>(currentSubscriberHead, updatedNode, journal)
tRef.unsafeSet(this.publisherHead, tail, journal)
tRef.unsafeSet(this.hubSize, size - 1, journal)
} else {
const updatedNode = makeNode(head, subscribers - 1, tail)
tRef.unsafeSet<Node<A | undefined> | undefined>(currentSubscriberHead, updatedNode, journal)
}

@@ -306,94 +311,56 @@ }

}
return core.succeed(size)
})
}
const currentSubscriberCount = tRef.unsafeGet(this.subscriberCount, journal)
tRef.unsafeSet(this.subscriberCount, currentSubscriberCount - 1, journal)
tRef.unsafeSet(
this.subscribers,
HashSet.remove(
tRef.unsafeGet(this.subscribers, journal),
this.subscriberHead
),
journal
)
}
})
shutdown(): STM.STM<never, never, void> {
return core.effect<never, void>((journal) => {
let currentSubscriberHead = tRef.unsafeGet(this.subscriberHead, journal)
if (currentSubscriberHead !== undefined) {
tRef.unsafeSet<TRef.TRef<Node<A | undefined> | undefined> | undefined>(this.subscriberHead, void 0, journal)
let loop = true
while (loop) {
const node = tRef.unsafeGet(currentSubscriberHead, journal)
if (node === undefined) {
loop = false
} else {
const head = node.head
const tail: TRef.TRef<Node<A | undefined> | undefined> = node.tail
if (head !== undefined) {
const subscribers = node.subscribers
if (subscribers === 1) {
const size = tRef.unsafeGet(this.hubSize, journal)
const updatedNode = makeNode(undefined, 0, tail)
tRef.unsafeSet<Node<A | undefined> | undefined>(currentSubscriberHead, updatedNode, journal)
tRef.unsafeSet(this.publisherHead, tail, journal)
tRef.unsafeSet(this.hubSize, size - 1, journal)
} else {
const updatedNode = makeNode(head, subscribers - 1, tail)
tRef.unsafeSet<Node<A | undefined> | undefined>(currentSubscriberHead, updatedNode, journal)
}
}
currentSubscriberHead = tail
}
}
const currentSubscriberCount = tRef.unsafeGet(this.subscriberCount, journal)
tRef.unsafeSet(this.subscriberCount, currentSubscriberCount - 1, journal)
tRef.unsafeSet(
this.subscribers,
HashSet.remove(
tRef.unsafeGet(this.subscribers, journal),
this.subscriberHead
),
journal
)
take: STM.STM<never, never, A> = core.withSTMRuntime((runtime) => {
let currentSubscriberHead = tRef.unsafeGet(this.subscriberHead, runtime.journal)
if (currentSubscriberHead === undefined) {
return core.interruptAs(runtime.fiberId)
}
let value: A | undefined = undefined
let loop = true
while (loop) {
const node = tRef.unsafeGet(currentSubscriberHead, runtime.journal)
if (node === undefined) {
return core.retry
}
})
}
take(): STM.STM<never, never, A> {
return core.withSTMRuntime((runtime) => {
let currentSubscriberHead = tRef.unsafeGet(this.subscriberHead, runtime.journal)
if (currentSubscriberHead === undefined) {
return core.interruptAs(runtime.fiberId)
}
let value: A | undefined = undefined
let loop = true
while (loop) {
const node = tRef.unsafeGet(currentSubscriberHead, runtime.journal)
if (node === undefined) {
return core.retry()
}
const head = node.head
const tail: TRef.TRef<Node<A | undefined> | undefined> = node.tail
if (head !== undefined) {
const subscribers = node.subscribers
if (subscribers === 1) {
const size = tRef.unsafeGet(this.hubSize, runtime.journal)
const updatedNode = makeNode(void 0, 0, tail)
tRef.unsafeSet<Node<A | undefined> | undefined>(currentSubscriberHead, updatedNode, runtime.journal)
tRef.unsafeSet(this.publisherHead, tail, runtime.journal)
tRef.unsafeSet(this.hubSize, size - 1, runtime.journal)
} else {
const updatedNode = makeNode(head, subscribers - 1, tail)
tRef.unsafeSet<Node<A | undefined> | undefined>(currentSubscriberHead, updatedNode, runtime.journal)
}
tRef.unsafeSet<TRef.TRef<Node<A | undefined> | undefined> | undefined>(
this.subscriberHead,
tail,
runtime.journal
)
value = head
loop = false
const head = node.head
const tail: TRef.TRef<Node<A | undefined> | undefined> = node.tail
if (head !== undefined) {
const subscribers = node.subscribers
if (subscribers === 1) {
const size = tRef.unsafeGet(this.hubSize, runtime.journal)
const updatedNode = makeNode(void 0, 0, tail)
tRef.unsafeSet<Node<A | undefined> | undefined>(currentSubscriberHead, updatedNode, runtime.journal)
tRef.unsafeSet(this.publisherHead, tail, runtime.journal)
tRef.unsafeSet(this.hubSize, size - 1, runtime.journal)
} else {
currentSubscriberHead = tail
const updatedNode = makeNode(head, subscribers - 1, tail)
tRef.unsafeSet<Node<A | undefined> | undefined>(currentSubscriberHead, updatedNode, runtime.journal)
}
tRef.unsafeSet<TRef.TRef<Node<A | undefined> | undefined> | undefined>(
this.subscriberHead,
tail,
runtime.journal
)
value = head
loop = false
} else {
currentSubscriberHead = tail
}
return core.succeed(value!)
})
}
}
return core.succeed(value!)
})
takeAll(): STM.STM<never, never, Array<A>> {
return this.takeUpTo(Number.POSITIVE_INFINITY)
}
takeAll: STM.STM<never, never, Array<A>> = this.takeUpTo(Number.POSITIVE_INFINITY)

@@ -449,9 +416,9 @@ takeUpTo(max: number): STM.STM<never, never, Array<A>> {

pipe(
stm.all(
stm.all([
tRef.make<Node<A> | undefined>(void 0),
tRef.make(0)
),
]),
core.flatMap(([empty, hubSize]) =>
pipe(
stm.all(
stm.all([
tRef.make(empty),

@@ -461,3 +428,3 @@ tRef.make(empty),

tRef.make(HashSet.empty())
),
]),
core.map(([publisherHead, publisherTail, subscriberCount, subscribers]) =>

@@ -490,7 +457,7 @@ new THubImpl(

pipe(
stm.all(
stm.all([
tRef.make(currentPublisherTail),
tRef.get(subscriberCount),
tRef.get(subscribers)
),
]),
stm.tap(([_, currentSubscriberCount]) =>

@@ -523,3 +490,3 @@ pipe(

/** @internal */
export const awaitShutdown = <A>(self: THub.THub<A>): STM.STM<never, never, void> => self.awaitShutdown()
export const awaitShutdown = <A>(self: THub.THub<A>): STM.STM<never, never, void> => self.awaitShutdown

@@ -538,9 +505,9 @@ /** @internal */

/** @internal */
export const isEmpty = <A>(self: THub.THub<A>): STM.STM<never, never, boolean> => self.isEmpty()
export const isEmpty = <A>(self: THub.THub<A>): STM.STM<never, never, boolean> => self.isEmpty
/** @internal */
export const isFull = <A>(self: THub.THub<A>): STM.STM<never, never, boolean> => self.isFull()
export const isFull = <A>(self: THub.THub<A>): STM.STM<never, never, boolean> => self.isFull
/** @internal */
export const isShutdown = <A>(self: THub.THub<A>): STM.STM<never, never, boolean> => self.isShutdown()
export const isShutdown = <A>(self: THub.THub<A>): STM.STM<never, never, boolean> => self.isShutdown

@@ -560,6 +527,6 @@ /** @internal */

/** @internal */
export const size = <A>(self: THub.THub<A>): STM.STM<never, never, number> => self.size()
export const size = <A>(self: THub.THub<A>): STM.STM<never, never, number> => self.size
/** @internal */
export const shutdown = <A>(self: THub.THub<A>): STM.STM<never, never, void> => self.shutdown()
export const shutdown = <A>(self: THub.THub<A>): STM.STM<never, never, void> => self.shutdown

@@ -566,0 +533,0 @@ /** @internal */

@@ -126,10 +126,9 @@ import * as Chunk from "@effect/data/Chunk"

Option.isNone(acc) ?
core.matchSTM(
f(key, value),
Option.match({
onNone: stm.succeedNone,
core.matchSTM(f(key, value), {
onFailure: Option.match({
onNone: () => stm.succeedNone,
onSome: core.fail
}),
stm.succeedSome
) :
onSuccess: stm.succeedSome
}) :
STM.succeed(acc)))

@@ -170,10 +169,9 @@

reduceWithIndexSTM(self, Chunk.empty<A>(), (acc, value, key) =>
core.matchSTM(
pf(key, value),
Option.match({
core.matchSTM(pf(key, value), {
onFailure: Option.match({
onNone: () => core.succeed(acc),
onSome: core.fail
}),
(a) => core.succeed(Chunk.append(acc, a))
)),
onSuccess: (a) => core.succeed(Chunk.append(acc, a))
})),
(a) => Array.from(a)

@@ -520,3 +518,3 @@ ))

onNone: () => set(self, key, value),
onSome: stm.unit
onSome: () => stm.unit
})

@@ -523,0 +521,0 @@ ))

@@ -119,3 +119,3 @@ import { dual, pipe } from "@effect/data/Function"

{
onNone: core.retry,
onNone: () => core.retry,
onSome: (elements) => core.succeed(elements[0])

@@ -170,3 +170,3 @@ }

return Option.match(SortedMap.headOption(map), {
onNone: core.retry,
onNone: () => core.retry,
onSome: (values) => {

@@ -173,0 +173,0 @@ const head = values[1][0]

@@ -97,40 +97,28 @@ import * as Chunk from "@effect/data/Chunk"

size(): STM.STM<never, never, number> {
return core.withSTMRuntime((runtime) => {
const queue = tRef.unsafeGet(this.ref, runtime.journal)
if (queue === undefined) {
return STM.interruptAs(runtime.fiberId)
}
return core.succeed(queue.length)
})
}
size: STM.STM<never, never, number> = core.withSTMRuntime((runtime) => {
const queue = tRef.unsafeGet(this.ref, runtime.journal)
if (queue === undefined) {
return STM.interruptAs(runtime.fiberId)
}
return core.succeed(queue.length)
})
isFull(): STM.STM<never, never, boolean> {
return core.map(this.size(), (size) => size === this.requestedCapacity)
}
isFull: STM.STM<never, never, boolean> = core.map(this.size, (size) => size === this.requestedCapacity)
isEmpty(): STM.STM<never, never, boolean> {
return core.map(this.size(), (size) => size === 0)
}
isEmpty: STM.STM<never, never, boolean> = core.map(this.size, (size) => size === 0)
shutdown(): STM.STM<never, never, void> {
return core.withSTMRuntime<never, never, void>((runtime) => {
tRef.unsafeSet(this.ref, void 0, runtime.journal)
return stm.unit()
})
}
shutdown: STM.STM<never, never, void> = core.withSTMRuntime<never, never, void>((runtime) => {
tRef.unsafeSet(this.ref, void 0, runtime.journal)
return stm.unit
})
isShutdown(): STM.STM<never, never, boolean> {
return core.effect<never, boolean>((journal) => {
const queue = tRef.unsafeGet(this.ref, journal)
return queue === undefined
})
}
isShutdown: STM.STM<never, never, boolean> = core.effect<never, boolean>((journal) => {
const queue = tRef.unsafeGet(this.ref, journal)
return queue === undefined
})
awaitShutdown(): STM.STM<never, never, void> {
return core.flatMap(
this.isShutdown(),
(isShutdown) => isShutdown ? stm.unit() : core.retry()
)
}
awaitShutdown: STM.STM<never, never, void> = core.flatMap(
this.isShutdown,
(isShutdown) => isShutdown ? stm.unit : core.retry
)

@@ -150,3 +138,3 @@ offer(value: A): STM.STM<never, never, boolean> {

case OpCodes.OP_BACKPRESSURE_STRATEGY: {
return core.retry()
return core.retry
}

@@ -182,3 +170,3 @@ case OpCodes.OP_DROPPING_STRATEGY: {

case OpCodes.OP_BACKPRESSURE_STRATEGY: {
return core.retry()
return core.retry
}

@@ -201,51 +189,43 @@ case OpCodes.OP_DROPPING_STRATEGY: {

peek(): STM.STM<never, never, A> {
return core.withSTMRuntime((runtime) => {
const queue = tRef.unsafeGet(this.ref, runtime.journal)
if (queue === undefined) {
return core.interruptAs(runtime.fiberId)
}
const head = queue[0]
if (head === undefined) {
return core.retry()
}
return core.succeed(head)
})
}
peek: STM.STM<never, never, A> = core.withSTMRuntime((runtime) => {
const queue = tRef.unsafeGet(this.ref, runtime.journal)
if (queue === undefined) {
return core.interruptAs(runtime.fiberId)
}
const head = queue[0]
if (head === undefined) {
return core.retry
}
return core.succeed(head)
})
peekOption(): STM.STM<never, never, Option.Option<A>> {
return core.withSTMRuntime((runtime) => {
const queue = tRef.unsafeGet(this.ref, runtime.journal)
if (queue === undefined) {
return core.interruptAs(runtime.fiberId)
}
return core.succeed(Option.fromNullable(queue[0]))
})
}
peekOption: STM.STM<never, never, Option.Option<A>> = core.withSTMRuntime((runtime) => {
const queue = tRef.unsafeGet(this.ref, runtime.journal)
if (queue === undefined) {
return core.interruptAs(runtime.fiberId)
}
return core.succeed(Option.fromNullable(queue[0]))
})
take(): STM.STM<never, never, A> {
return core.withSTMRuntime((runtime) => {
const queue = tRef.unsafeGet(this.ref, runtime.journal)
if (queue === undefined) {
return core.interruptAs(runtime.fiberId)
}
const dequeued = queue.shift()
if (dequeued === undefined) {
return core.retry()
}
tRef.unsafeSet(this.ref, queue, runtime.journal)
return core.succeed(dequeued)
})
}
take: STM.STM<never, never, A> = core.withSTMRuntime((runtime) => {
const queue = tRef.unsafeGet(this.ref, runtime.journal)
if (queue === undefined) {
return core.interruptAs(runtime.fiberId)
}
const dequeued = queue.shift()
if (dequeued === undefined) {
return core.retry
}
tRef.unsafeSet(this.ref, queue, runtime.journal)
return core.succeed(dequeued)
})
takeAll(): STM.STM<never, never, Array<A>> {
return core.withSTMRuntime((runtime) => {
const queue = tRef.unsafeGet(this.ref, runtime.journal)
if (queue === undefined) {
return core.interruptAs(runtime.fiberId)
}
tRef.unsafeSet(this.ref, [], runtime.journal)
return core.succeed(queue)
})
}
takeAll: STM.STM<never, never, Array<A>> = core.withSTMRuntime((runtime) => {
const queue = tRef.unsafeGet(this.ref, runtime.journal)
if (queue === undefined) {
return core.interruptAs(runtime.fiberId)
}
tRef.unsafeSet(this.ref, [], runtime.journal)
return core.succeed(queue)
})

@@ -282,3 +262,3 @@ takeUpTo(max: number): STM.STM<never, never, Array<A>> {

export const awaitShutdown = <A>(self: TQueue.TDequeue<A> | TQueue.TEnqueue<A>): STM.STM<never, never, void> =>
self.awaitShutdown()
self.awaitShutdown

@@ -300,11 +280,10 @@ /** @internal */

export const isEmpty = <A>(self: TQueue.TDequeue<A> | TQueue.TEnqueue<A>): STM.STM<never, never, boolean> =>
self.isEmpty()
self.isEmpty
/** @internal */
export const isFull = <A>(self: TQueue.TDequeue<A> | TQueue.TEnqueue<A>): STM.STM<never, never, boolean> =>
self.isFull()
export const isFull = <A>(self: TQueue.TDequeue<A> | TQueue.TEnqueue<A>): STM.STM<never, never, boolean> => self.isFull
/** @internal */
export const isShutdown = <A>(self: TQueue.TDequeue<A> | TQueue.TEnqueue<A>): STM.STM<never, never, boolean> =>
self.isShutdown()
self.isShutdown

@@ -324,6 +303,6 @@ /** @internal */

/** @internal */
export const peek = <A>(self: TQueue.TDequeue<A>): STM.STM<never, never, A> => self.peek()
export const peek = <A>(self: TQueue.TDequeue<A>): STM.STM<never, never, A> => self.peek
/** @internal */
export const peekOption = <A>(self: TQueue.TDequeue<A>): STM.STM<never, never, Option.Option<A>> => self.peekOption()
export const peekOption = <A>(self: TQueue.TDequeue<A>): STM.STM<never, never, Option.Option<A>> => self.peekOption

@@ -342,3 +321,3 @@ /** @internal */

core.flatMap(
self.take(),
self.take,
(a) => predicate(a) ? core.succeed(a) : seekLoop(self, predicate)

@@ -348,7 +327,6 @@ )

/** @internal */
export const shutdown = <A>(self: TQueue.TDequeue<A> | TQueue.TEnqueue<A>): STM.STM<never, never, void> =>
self.shutdown()
export const shutdown = <A>(self: TQueue.TDequeue<A> | TQueue.TEnqueue<A>): STM.STM<never, never, void> => self.shutdown
/** @internal */
export const size = <A>(self: TQueue.TDequeue<A> | TQueue.TEnqueue<A>): STM.STM<never, never, number> => self.size()
export const size = <A>(self: TQueue.TDequeue<A> | TQueue.TEnqueue<A>): STM.STM<never, never, number> => self.size

@@ -360,6 +338,6 @@ /** @internal */

/** @internal */
export const take = <A>(self: TQueue.TDequeue<A>): STM.STM<never, never, A> => self.take()
export const take = <A>(self: TQueue.TDequeue<A>): STM.STM<never, never, A> => self.take
/** @internal */
export const takeAll = <A>(self: TQueue.TDequeue<A>): STM.STM<never, never, Array<A>> => self.takeAll()
export const takeAll = <A>(self: TQueue.TDequeue<A>): STM.STM<never, never, Array<A>> => self.takeAll

@@ -388,3 +366,3 @@ /** @internal */

return pipe(
self.take(),
self.take,
core.map((a) => pipe(acc, Chunk.appendAll(Chunk.unsafeFromArray(taken)), Chunk.append(a)))

@@ -395,3 +373,3 @@ )

return pipe(
self.take(),
self.take,
core.flatMap((a) =>

@@ -398,0 +376,0 @@ takeRemainder(

@@ -78,3 +78,3 @@ import * as Context from "@effect/data/Context"

array,
stm.forEachDiscard((n) => pipe(nextIntBounded(n), core.flatMap((k) => swap(buffer, n - 1, k)))),
stm.forEach((n) => pipe(nextIntBounded(n), core.flatMap((k) => swap(buffer, n - 1, k))), { discard: true }),
core.zipRight(tArray.toArray(buffer))

@@ -92,13 +92,7 @@ )

constructor(readonly state: TRef.TRef<Random.PCGRandomState>) {}
next(): STM.STM<never, never, number> {
return withState(this.state, randomNumber)
}
nextBoolean(): STM.STM<never, never, boolean> {
return core.flatMap(this.next(), (n) => core.succeed(n > 0.5))
}
nextInt(): STM.STM<never, never, number> {
return withState(this.state, randomInteger)
}
next = withState(this.state, randomNumber)
nextBoolean = core.flatMap(this.next, (n) => core.succeed(n > 0.5))
nextInt = withState(this.state, randomInteger)
nextRange(min: number, max: number): STM.STM<never, never, number> {
return core.flatMap(this.next(), (n) => core.succeed((max - min) * n + min))
return core.flatMap(this.next, (n) => core.succeed((max - min) * n + min))
}

@@ -114,21 +108,19 @@ nextIntBetween(low: number, high: number): STM.STM<never, never, number> {

/** @internal */
export const live = (): Layer.Layer<never, never, TRandom.TRandom> =>
Layer.effect(
Tag,
pipe(
tRef.make(new Random.PCGRandom((Math.random() * 4294967296) >>> 0).getState()),
core.map((seed) => new TRandomImpl(seed)),
core.commit
)
export const live: Layer.Layer<never, never, TRandom.TRandom> = Layer.effect(
Tag,
pipe(
tRef.make(new Random.PCGRandom((Math.random() * 4294967296) >>> 0).getState()),
core.map((seed) => new TRandomImpl(seed)),
core.commit
)
)
/** @internal */
export const next = (): STM.STM<TRandom.TRandom, never, number> => core.flatMap(Tag, (random) => random.next())
export const next: STM.STM<TRandom.TRandom, never, number> = core.flatMap(Tag, (random) => random.next)
/** @internal */
export const nextBoolean = (): STM.STM<TRandom.TRandom, never, boolean> =>
core.flatMap(Tag, (random) => random.nextBoolean())
export const nextBoolean: STM.STM<TRandom.TRandom, never, boolean> = core.flatMap(Tag, (random) => random.nextBoolean)
/** @internal */
export const nextInt = (): STM.STM<TRandom.TRandom, never, number> => core.flatMap(Tag, (random) => random.nextInt())
export const nextInt: STM.STM<TRandom.TRandom, never, number> = core.flatMap(Tag, (random) => random.nextInt)

@@ -135,0 +127,0 @@ /** @internal */

@@ -180,3 +180,3 @@ import * as Equal from "@effect/data/Equal"

}
return core.retry()
return core.retry
})

@@ -207,3 +207,3 @@

}
return core.retry()
return core.retry
})

@@ -241,7 +241,6 @@

/** @internal */
export const make = (): STM.STM<never, never, TReentrantLock.TReentrantLock> =>
core.map(
tRef.make(emptyReadLock),
(readLock) => new TReentranLockImpl(readLock)
)
export const make: STM.STM<never, never, TReentrantLock.TReentrantLock> = core.map(
tRef.make(emptyReadLock),
(readLock) => new TReentranLockImpl(readLock)
)

@@ -248,0 +247,0 @@ /** @internal */

@@ -43,3 +43,3 @@ import { dual } from "@effect/data/Function"

if (value < n) {
return STM.retry()
return STM.retry
} else {

@@ -46,0 +46,0 @@ return STM.succeed(tRef.unsafeSet(self.permits, value - n, driver.journal))

@@ -204,3 +204,4 @@ /**

export type STMAny = STM<any, any, any>
export type ReturnArray<T> = [T] extends [ReadonlyArray<STMAny>] ? STM<
export type ReturnTuple<T extends ReadonlyArray<STM<any, any, any>>, Discard extends boolean> = STM<
T[number] extends never ? never

@@ -212,50 +213,53 @@ : [T[number]] extends [{ [STMTypeId]: { _R: (_: never) => infer R } }] ? R

: never,
T[number] extends never ? []
: { [K in keyof T]: [T[K]] extends [STM<any, any, infer A>] ? A : never }
>
: never
export type ReturnTuple<T extends ReadonlyArray<STM<any, any, any>>> = STM<
T[number] extends never ? never
: [T[number]] extends [{ [STMTypeId]: { _R: (_: never) => infer R } }] ? R
: never,
T[number] extends never ? never
: [T[number]] extends [{ [STMTypeId]: { _E: (_: never) => infer E } }] ? E
: never,
T[number] extends never ? []
: { [K in keyof T]: [T[K]] extends [STM<any, any, infer A>] ? A : never }
Discard extends true ? void
: T[number] extends never ? []
: { -readonly [K in keyof T]: [T[K]] extends [STM<infer _R, infer _E, infer A>] ? A : never }
> extends infer X ? X : never
export type ReturnIterable<T> = [T] extends [[Iterable<STMAny>]]
? [T] extends [[ReadonlyArray<STMAny>]] ? ReturnTuple<T[0]>
: STM<
[T[0]] extends [Iterable<{ [STMTypeId]: { _R: (_: never) => infer R } }>] ? R
: never,
[T[0]] extends [Iterable<{ [STMTypeId]: { _E: (_: never) => infer E } }>] ? E
: never,
[T[0]] extends [Iterable<{ [STMTypeId]: { _A: (_: never) => infer A } }>] ? Array<A>
: never
>
: never
export type ReturnObject<T> = [T] extends [[Readonly<{ [K: string]: STM<any, any, any> }>]] ? STM<
keyof T[0] extends never ? never
: [T[0][keyof T[0]]] extends [{ [STMTypeId]: { _R: (_: never) => infer R } }] ? R
export type ReturnIterable<T extends Iterable<STMAny>, Discard extends boolean> = [T] extends
[Iterable<STM.Variance<infer R, infer E, infer A>>] ? STM<R, E, Discard extends true ? void : Array<A>> : never
export type ReturnObject<T extends Record<string, STMAny>, Discard extends boolean> = STM<
keyof T extends never ? never
: [T[keyof T]] extends [{ [STMTypeId]: { _R: (_: never) => infer R } }] ? R
: never,
keyof T[0] extends never ? never
: [T[0][keyof T[0]]] extends [{ [STMTypeId]: { _E: (_: never) => infer E } }] ? E
keyof T extends never ? never
: [T[keyof T]] extends [{ [STMTypeId]: { _E: (_: never) => infer E } }] ? E
: never,
{ [K in keyof T[0]]: [T[0][K]] extends [STM<any, any, infer A>] ? A : never }
Discard extends true ? void
: { -readonly [K in keyof T]: [T[K]] extends [STM.Variance<infer _R, infer _E, infer A>] ? A : never }
>
: never
export type Signature = {
<
Args extends
| ReadonlyArray<STMAny>
| [Iterable<STMAny>]
| [Readonly<{ [K: string]: STM<any, any, any> }>]
>(
...args: [...Args]
): Args["length"] extends 1 ? Args extends [Iterable<STMAny>] ? ReturnIterable<Args>
: Args extends [STMAny] ? ReturnArray<Args>
: ReturnObject<Args>
: ReturnArray<Args>
export type Options = {
readonly discard: boolean
}
type IsDiscard<A> = [Extract<A, { readonly discard: true }>] extends [never] ? false : true
type Narrow<A> = (A extends [] ? [] : never) | A
export interface Signature {
<O extends Options>(
options?: O
): <Arg extends ReadonlyArray<STMAny> | Iterable<STMAny> | Record<string, STMAny>>(
arg: Arg
) => [Arg] extends [ReadonlyArray<STMAny>] ? ReturnTuple<Arg, IsDiscard<O>>
: [Arg] extends [Iterable<STMAny>] ? ReturnIterable<Arg, IsDiscard<O>>
: [Arg] extends [Record<string, STMAny>] ? ReturnObject<Arg, IsDiscard<O>>
: never
<Arg extends ReadonlyArray<STMAny>, O extends Options>(
arg: Narrow<Arg>,
options?: O
): ReturnTuple<Arg, IsDiscard<O>>
<Arg extends Iterable<STMAny>, O extends Options>(
arg: Arg,
options?: O
): ReturnIterable<Arg, IsDiscard<O>>
<Arg extends Record<string, STMAny>, O extends Options>(
arg: Arg,
options?: O
): ReturnObject<Arg, IsDiscard<O>>
}
}

@@ -350,15 +354,61 @@

/**
* Checks the condition, and if it's true, returns unit, otherwise, retries.
* Recovers from the specified tagged error.
*
* @since 1.0.0
* @category constructors
* @category error handling
*/
export const check: (predicate: LazyArg<boolean>) => STM<never, never, void> = stm.check
export const catchTag: {
<K extends E["_tag"] & string, E extends { _tag: string }, R1, E1, A1>(
k: K,
f: (e: Extract<E, { _tag: K }>) => STM<R1, E1, A1>
): <R, A>(self: STM<R, E, A>) => STM<R1 | R, E1 | Exclude<E, { _tag: K }>, A1 | A>
<R, E extends { _tag: string }, A, K extends E["_tag"] & string, R1, E1, A1>(
self: STM<R, E, A>,
k: K,
f: (e: Extract<E, { _tag: K }>) => STM<R1, E1, A1>
): STM<R | R1, E1 | Exclude<E, { _tag: K }>, A | A1>
} = stm.catchTag
/**
* Collects all the transactional effects, returning a single transactional
* effect that produces `Unit`.
* Recovers from multiple tagged errors.
*
* Equivalent to `pipe(icollectAll(iterable), asUnit)`, but without the cost
* of building the list of results.
* @since 1.0.0
* @category error handling
*/
export const catchTags: {
<
E extends { _tag: string },
Cases extends { [K in E["_tag"]]+?: ((error: Extract<E, { _tag: K }>) => STM<any, any, any>) }
>(
cases: Cases
): <R, A>(
self: STM<R, E, A>
) => STM<
| R
| { [K in keyof Cases]: Cases[K] extends (...args: Array<any>) => STM<infer R, any, any> ? R : never }[keyof Cases],
| Exclude<E, { _tag: keyof Cases }>
| { [K in keyof Cases]: Cases[K] extends (...args: Array<any>) => STM<any, infer E, any> ? E : never }[keyof Cases],
| A
| { [K in keyof Cases]: Cases[K] extends (...args: Array<any>) => STM<any, any, infer A> ? A : never }[keyof Cases]
>
<
R,
E extends { _tag: string },
A,
Cases extends { [K in E["_tag"]]+?: ((error: Extract<E, { _tag: K }>) => STM<any, any, any>) }
>(
self: STM<R, E, A>,
cases: Cases
): STM<
| R
| { [K in keyof Cases]: Cases[K] extends (...args: Array<any>) => STM<infer R, any, any> ? R : never }[keyof Cases],
| Exclude<E, { _tag: keyof Cases }>
| { [K in keyof Cases]: Cases[K] extends (...args: Array<any>) => STM<any, infer E, any> ? E : never }[keyof Cases],
| A
| { [K in keyof Cases]: Cases[K] extends (...args: Array<any>) => STM<any, any, infer A> ? A : never }[keyof Cases]
>
} = stm.catchTags
/**
* Checks the condition, and if it's true, returns unit, otherwise, retries.
*

@@ -368,3 +418,3 @@ * @since 1.0.0

*/
export const allDiscard: <R, E, A>(iterable: Iterable<STM<R, E, A>>) => STM<R, E, void> = stm.collectAllDiscard
export const check: (predicate: LazyArg<boolean>) => STM<never, never, void> = stm.check

@@ -394,14 +444,2 @@ /**

/**
* Collects the first element of the `Iterable<A>` for which the effectual
* function `f` returns `Some`.
*
* @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>>
<A, R, E, A2>(iterable: Iterable<A>, pf: (a: A) => STM<R, E, Option.Option<A2>>): STM<R, E, Option.Option<A2>>
} = stm.collectFirst
/**
* Commits this transaction atomically.

@@ -572,3 +610,3 @@ *

*/
export const fiberId: () => STM<never, never, FiberId.FiberId> = stm.fiberId
export const fiberId: STM<never, never, FiberId.FiberId> = stm.fiberId

@@ -630,26 +668,4 @@ /**

predicate: Predicate<A>,
orElse: LazyArg<STM<R2, E2, A2>>
): <R, E>(
self: STM<R, E, A>
) => STM<R2 | R, E2 | E, A | A2>
<R, E, A, R2, E2, A2>(
self: STM<R, E, A>,
predicate: Predicate<A>,
orElse: LazyArg<STM<R2, E2, A2>>
): STM<R | R2, E | E2, A | A2>
} = stm.filterOrElse
/**
* Applies `orElse` if the predicate fails.
*
* @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>
): <R, E>(self: STM<R, E, A>) => STM<R2 | R, E2 | E, A | A2>
<R, E, A, R2, E2, A2>(

@@ -660,3 +676,3 @@ self: STM<R, E, A>,

): STM<R | R2, E | E2, A | A2>
} = stm.filterOrElseWith
} = stm.filterOrElse

@@ -670,4 +686,4 @@ /**

export const filterOrFail: {
<A, E2>(predicate: Predicate<A>, error: LazyArg<E2>): <R, E>(self: STM<R, E, A>) => STM<R, E2 | E, A>
<R, E, A, E2>(self: STM<R, E, A>, predicate: Predicate<A>, error: LazyArg<E2>): STM<R, E | E2, A>
<A, E2>(predicate: Predicate<A>, orFailWith: (a: A) => E2): <R, E>(self: STM<R, E, A>) => STM<R, E2 | E, A>
<R, E, A, E2>(self: STM<R, E, A>, predicate: Predicate<A>, orFailWith: (a: A) => E2): STM<R, E | E2, A>
} = stm.filterOrFail

@@ -725,4 +741,15 @@

export const match: {
<E, A2, A, A3>(f: (error: E) => A2, g: (value: A) => A3): <R>(self: STM<R, E, A>) => STM<R, never, A2 | A3>
<R, E, A2, A, A3>(self: STM<R, E, A>, f: (error: E) => A2, g: (value: A) => A3): STM<R, never, A2 | A3>
<E, A2, A, A3>(
options: {
readonly onFailure: (error: E) => A2
readonly onSuccess: (value: A) => A3
}
): <R>(self: STM<R, E, A>) => STM<R, never, A2 | A3>
<R, E, A2, A, A3>(
self: STM<R, E, A>,
options: {
readonly onFailure: (error: E) => A2
readonly onSuccess: (value: A) => A3
}
): STM<R, never, A2 | A3>
} = stm.match

@@ -738,11 +765,13 @@

<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>
options: {
readonly onFailure: (e: E) => STM<R1, E1, A1>
readonly onSuccess: (a: A) => STM<R2, E2, A2>
}
): <R>(self: STM<R, E, A>) => STM<R1 | R2 | R, E1 | E2, A1 | A2>
<R, E, R1, E1, A1, A, R2, E2, A2>(
self: STM<R, E, A>,
onFailure: (e: E) => STM<R1, E1, A1>,
onSuccess: (a: A) => STM<R2, E2, A2>
options: {
readonly onFailure: (e: E) => STM<R1, E1, A1>
readonly onSuccess: (a: A) => STM<R2, E2, A2>
}
): STM<R | R1 | R2, E1 | E2, A1 | A2>

@@ -759,22 +788,19 @@ } = core.matchSTM

export const forEach: {
<A, R, E, A2>(f: (a: A) => STM<R, E, A2>): (elements: Iterable<A>) => STM<R, E, Array<A2>>
<A, R, E, A2>(elements: Iterable<A>, f: (a: A) => STM<R, E, A2>): STM<R, E, Array<A2>>
<A, R, E, A2>(
f: (a: A) => STM<R, E, A2>,
options?: { readonly discard?: false }
): (elements: Iterable<A>) => STM<R, E, Array<A2>>
<A, R, E, A2>(
f: (a: A) => STM<R, E, A2>,
options: { readonly discard: true }
): (elements: Iterable<A>) => STM<R, E, void>
<A, R, E, A2>(
elements: Iterable<A>,
f: (a: A) => STM<R, E, A2>,
options?: { readonly discard?: false }
): STM<R, E, Array<A2>>
<A, R, E, A2>(elements: Iterable<A>, f: (a: A) => STM<R, E, A2>, options: { readonly discard: true }): STM<R, E, void>
} = 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.
*
* @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>
<A, R, E, _>(iterable: Iterable<A>, f: (a: A) => STM<R, E, _>): STM<R, E, void>
} = stm.forEachDiscard
/**
* Lifts an `Either` into a `STM`.

@@ -1082,22 +1108,35 @@ *

/**
* Runs `onTrue` if the result of `b` is `true` and `onFalse` otherwise.
*
* @since 1.0.0
* @category mutations
*/
export const ifSTM: {
const if_: {
<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>
options: {
readonly onTrue: STM<R1, E1, A>
readonly onFalse: STM<R2, E2, A1>
}
): <R = never, E = never>(self: boolean | STM<R, E, boolean>) => STM<R1 | R2 | R, E1 | E2 | E, A | A1>
<R, E, R1, R2, E1, E2, A, A1>(
self: boolean,
options: {
readonly onTrue: STM<R1, E1, A>
readonly onFalse: STM<R2, E2, A1>
}
): STM<R | R1 | R2, E | E1 | E2, A | A1>
<R, E, R1, R2, E1, E2, A, A1>(
self: STM<R, E, boolean>,
onTrue: STM<R1, E1, A>,
onFalse: STM<R2, E2, A1>
options: {
readonly onTrue: STM<R1, E1, A>
readonly onFalse: STM<R2, E2, A1>
}
): STM<R | R1 | R2, E | E1 | E2, A | A1>
} = stm.ifSTM
} = stm.if_
export {
/**
* Runs `onTrue` if the result of `b` is `true` and `onFalse` otherwise.
*
* @since 1.0.0
* @category mutations
*/
if_ as if
}
/**

@@ -1117,3 +1156,3 @@ * Returns a new effect that ignores the success or failure of this effect.

*/
export const interrupt: () => STM<never, never, never> = core.interrupt
export const interrupt: STM<never, never, never> = core.interrupt

@@ -1161,4 +1200,9 @@ /**

*/
export const iterate: <R, E, Z>(initial: Z, cont: (z: Z) => boolean, body: (z: Z) => STM<R, E, Z>) => STM<R, E, Z> =
stm.iterate
export const iterate: <R, E, Z>(
initial: Z,
options: {
readonly while: (z: Z) => boolean
readonly body: (z: Z) => STM<R, E, Z>
}
) => STM<R, E, Z> = stm.iterate

@@ -1184,33 +1228,24 @@ /**

*/
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, Array<A>> = stm.loop
export const loop: {
<Z, R, E, A>(
initial: Z,
options: {
readonly while: (z: Z) => boolean
readonly step: (z: Z) => Z
readonly body: (z: Z) => STM<R, E, A>
readonly discard?: false
}
): STM<R, E, Array<A>>
<Z, R, E, A>(
initial: Z,
options: {
readonly while: (z: Z) => boolean
readonly step: (z: Z) => Z
readonly body: (z: Z) => STM<R, E, A>
readonly discard: true
}
): STM<R, E, void>
} = 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)
* }
* ```
*
* @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.

@@ -1247,4 +1282,15 @@ *

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>
<R, E, E2, A, A2>(self: STM<R, E, A>, f: (error: E) => E2, g: (value: A) => A2): STM<R, E2, A2>
<E, E2, A, A2>(
options: {
readonly onFailure: (error: E) => E2
readonly onSuccess: (value: A) => A2
}
): <R>(self: STM<R, E, A>) => STM<R, E2, A2>
<R, E, E2, A, A2>(
self: STM<R, E, A>,
options: {
readonly onFailure: (error: E) => E2
readonly onSuccess: (value: A) => A2
}
): STM<R, E2, A2>
} = stm.mapBoth

@@ -1659,3 +1705,3 @@

*/
export const retry: () => STM<never, never, never> = core.retry
export const retry: STM<never, never, never> = core.retry

@@ -1695,31 +1741,2 @@ /**

/**
* Extracts the optional value, or returns the given 'default'.
*
* @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>
<R, E, A, A2>(self: STM<R, E, Option.Option<A>>, orElse: LazyArg<A2>): STM<R, E, A | A2>
} = stm.someOrElse
/**
* Extracts the optional value, or executes the effect 'default'.
*
* @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>
<R, E, A, R2, E2, A2>(
self: STM<R, E, Option.Option<A>>,
orElse: LazyArg<STM<R2, E2, A2>>
): STM<R | R2, E | E2, A | A2>
} = stm.someOrElseSTM
/**
* Returns an `STM` effect that succeeds with the specified value.

@@ -1738,3 +1755,3 @@ *

*/
export const succeedNone: () => STM<never, never, Option.Option<never>> = stm.succeedNone
export const succeedNone: STM<never, never, Option.Option<never>> = stm.succeedNone

@@ -1807,11 +1824,13 @@ /**

<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>
options: {
readonly onFailure: (error: E) => STM<R2, E2, A2>
readonly onSuccess: (value: A) => STM<R3, E3, A3>
}
): <R>(self: STM<R, E, A>) => STM<R2 | R3 | R, E | E2 | E3, A>
<R, E, R2, E2, A2, A, R3, E3, A3>(
self: STM<R, E, A>,
f: (error: E) => STM<R2, E2, A2>,
g: (value: A) => STM<R3, E3, A3>
options: {
readonly onFailure: (error: E) => STM<R2, E2, A2>
readonly onSuccess: (value: A) => STM<R3, E3, A3>
}
): STM<R | R2 | R3, E | E2 | E3, A>

@@ -1831,10 +1850,19 @@ } = stm.tapBoth

/**
* Imports a synchronous side-effect into a pure value, translating any thrown
* exceptions into typed failed effects.
*
* @since 1.0.0
* @category constructors
*/
export const tryCatch: <E, A>(attempt: () => A, onThrow: (u: unknown) => E) => Effect.Effect<never, E, A> = stm.tryCatch
const try_: {
<A>(try_: LazyArg<A>): STM<never, unknown, A>
<A, E>(options: {
readonly try: LazyArg<A>
readonly catch: (u: unknown) => E
}): STM<never, E, A>
} = stm.try_
export {
/**
* Imports a synchronous side-effect into a pure value, translating any thrown
* exceptions into typed failed effects.
*
* @since 1.0.0
* @category constructors
*/
try_ as try
}

@@ -1877,3 +1905,3 @@ /**

*/
export const unit: () => STM<never, never, void> = stm.unit
export const unit: STM<never, never, void> = stm.unit

@@ -1880,0 +1908,0 @@ /**

@@ -76,3 +76,3 @@ /**

*/
peek(): STM.STM<never, never, A>
readonly peek: STM.STM<never, never, A>

@@ -83,3 +83,3 @@ /**

*/
peekOption(): STM.STM<never, never, Option.Option<A>>
readonly peekOption: STM.STM<never, never, Option.Option<A>>

@@ -90,3 +90,3 @@ /**

*/
take(): STM.STM<never, never, A>
readonly take: STM.STM<never, never, A>

@@ -97,3 +97,3 @@ /**

*/
takeAll(): STM.STM<never, never, Array<A>>
readonly takeAll: STM.STM<never, never, Array<A>>

@@ -123,3 +123,3 @@ /**

*/
size(): STM.STM<never, never, number>
readonly size: STM.STM<never, never, number>

@@ -130,3 +130,3 @@ /**

*/
isFull(): STM.STM<never, never, boolean>
readonly isFull: STM.STM<never, never, boolean>

@@ -136,3 +136,3 @@ /**

*/
isEmpty(): STM.STM<never, never, boolean>
readonly isEmpty: STM.STM<never, never, boolean>

@@ -143,3 +143,3 @@ /**

*/
shutdown(): STM.STM<never, never, void>
readonly shutdown: STM.STM<never, never, void>

@@ -149,3 +149,3 @@ /**

*/
isShutdown(): STM.STM<never, never, boolean>
readonly isShutdown: STM.STM<never, never, boolean>

@@ -157,3 +157,3 @@ /**

*/
awaitShutdown(): STM.STM<never, never, void>
readonly awaitShutdown: STM.STM<never, never, void>
}

@@ -160,0 +160,0 @@

@@ -32,11 +32,11 @@ /**

*/
next(): STM.STM<never, never, number>
readonly next: STM.STM<never, never, number>
/**
* Returns the next boolean value from the pseudo-random number generator.
*/
nextBoolean(): STM.STM<never, never, boolean>
readonly nextBoolean: STM.STM<never, never, boolean>
/**
* Returns the next integer value from the pseudo-random number generator.
*/
nextInt(): STM.STM<never, never, number>
readonly nextInt: STM.STM<never, never, number>
/**

@@ -80,3 +80,3 @@ * Returns the next numeric value in the specified range from the

*/
export const live: () => Layer.Layer<never, never, TRandom> = internal.live
export const live: Layer.Layer<never, never, TRandom> = internal.live

@@ -89,3 +89,3 @@ /**

*/
export const next: () => STM.STM<TRandom, never, number> = internal.next
export const next: STM.STM<TRandom, never, number> = internal.next

@@ -98,3 +98,3 @@ /**

*/
export const nextBoolean: () => STM.STM<TRandom, never, boolean> = internal.nextBoolean
export const nextBoolean: STM.STM<TRandom, never, boolean> = internal.nextBoolean

@@ -107,3 +107,3 @@ /**

*/
export const nextInt: () => STM.STM<TRandom, never, number> = internal.nextInt
export const nextInt: STM.STM<TRandom, never, number> = internal.nextInt

@@ -110,0 +110,0 @@ /**

@@ -125,3 +125,3 @@ /**

*/
export const make: () => STM.STM<never, never, TReentrantLock> = internal.make
export const make: STM.STM<never, never, TReentrantLock> = internal.make

@@ -128,0 +128,0 @@ /**

@@ -178,3 +178,3 @@ import type * as Context from "@effect/data/Context";

type STMAny = STM<any, any, any>;
type ReturnArray<T> = [T] extends [ReadonlyArray<STMAny>] ? STM<T[number] extends never ? never : [T[number]] extends [{
type ReturnTuple<T extends ReadonlyArray<STM<any, any, any>>, Discard extends boolean> = STM<T[number] extends never ? never : [T[number]] extends [{
[STMTypeId]: {

@@ -187,53 +187,32 @@ _R: (_: never) => infer R;

};
}] ? E : never, T[number] extends never ? [] : {
[K in keyof T]: [T[K]] extends [STM<any, any, infer A>] ? A : never;
}> : never;
type ReturnTuple<T extends ReadonlyArray<STM<any, any, any>>> = STM<T[number] extends never ? never : [T[number]] extends [{
[STMTypeId]: {
_R: (_: never) => infer R;
};
}] ? R : never, T[number] extends never ? never : [T[number]] extends [{
[STMTypeId]: {
_E: (_: never) => infer E;
};
}] ? E : never, T[number] extends never ? [] : {
[K in keyof T]: [T[K]] extends [STM<any, any, infer A>] ? A : never;
}] ? E : never, Discard extends true ? void : T[number] extends never ? [] : {
-readonly [K in keyof T]: [T[K]] extends [STM<infer _R, infer _E, infer A>] ? A : never;
}> extends infer X ? X : never;
type ReturnIterable<T> = [T] extends [[Iterable<STMAny>]] ? [T] extends [[ReadonlyArray<STMAny>]] ? ReturnTuple<T[0]> : STM<[
T[0]
] extends [Iterable<{
type ReturnIterable<T extends Iterable<STMAny>, Discard extends boolean> = [T] extends [
Iterable<STM.Variance<infer R, infer E, infer A>>
] ? STM<R, E, Discard extends true ? void : Array<A>> : never;
type ReturnObject<T extends Record<string, STMAny>, Discard extends boolean> = STM<keyof T extends never ? never : [T[keyof T]] extends [{
[STMTypeId]: {
_R: (_: never) => infer R;
};
}>] ? R : never, [
T[0]
] extends [Iterable<{
}] ? R : never, keyof T extends never ? never : [T[keyof T]] extends [{
[STMTypeId]: {
_E: (_: never) => infer E;
};
}>] ? E : never, [
T[0]
] extends [Iterable<{
[STMTypeId]: {
_A: (_: never) => infer A;
};
}>] ? Array<A> : never> : never;
type ReturnObject<T> = [T] extends [[Readonly<{
[K: string]: STM<any, any, any>;
}>]] ? STM<keyof T[0] extends never ? never : [T[0][keyof T[0]]] extends [{
[STMTypeId]: {
_R: (_: never) => infer R;
};
}] ? R : never, keyof T[0] extends never ? never : [T[0][keyof T[0]]] extends [{
[STMTypeId]: {
_E: (_: never) => infer E;
};
}] ? E : never, {
[K in keyof T[0]]: [T[0][K]] extends [STM<any, any, infer A>] ? A : never;
}> : never;
type Signature = {
<Args extends ReadonlyArray<STMAny> | [Iterable<STMAny>] | [Readonly<{
[K: string]: STM<any, any, any>;
}>]>(...args: [...Args]): Args["length"] extends 1 ? Args extends [Iterable<STMAny>] ? ReturnIterable<Args> : Args extends [STMAny] ? ReturnArray<Args> : ReturnObject<Args> : ReturnArray<Args>;
}] ? E : never, Discard extends true ? void : {
-readonly [K in keyof T]: [T[K]] extends [STM.Variance<infer _R, infer _E, infer A>] ? A : never;
}>;
type Options = {
readonly discard: boolean;
};
type IsDiscard<A> = [Extract<A, {
readonly discard: true;
}>] extends [never] ? false : true;
type Narrow<A> = (A extends [] ? [] : never) | A;
interface Signature {
<O extends Options>(options?: O): <Arg extends ReadonlyArray<STMAny> | Iterable<STMAny> | Record<string, STMAny>>(arg: Arg) => [Arg] extends [ReadonlyArray<STMAny>] ? ReturnTuple<Arg, IsDiscard<O>> : [Arg] extends [Iterable<STMAny>] ? ReturnIterable<Arg, IsDiscard<O>> : [Arg] extends [Record<string, STMAny>] ? ReturnObject<Arg, IsDiscard<O>> : never;
<Arg extends ReadonlyArray<STMAny>, O extends Options>(arg: Narrow<Arg>, options?: O): ReturnTuple<Arg, IsDiscard<O>>;
<Arg extends Iterable<STMAny>, O extends Options>(arg: Arg, options?: O): ReturnIterable<Arg, IsDiscard<O>>;
<Arg extends Record<string, STMAny>, O extends Options>(arg: Arg, options?: O): ReturnObject<Arg, IsDiscard<O>>;
}
}

@@ -312,14 +291,63 @@ /**

/**
* Checks the condition, and if it's true, returns unit, otherwise, retries.
* Recovers from the specified tagged error.
*
* @since 1.0.0
* @category constructors
* @category error handling
*/
export declare const check: (predicate: LazyArg<boolean>) => STM<never, never, void>;
export declare const catchTag: {
<K extends E["_tag"] & string, E extends {
_tag: string;
}, R1, E1, A1>(k: K, f: (e: Extract<E, {
_tag: K;
}>) => STM<R1, E1, A1>): <R, A>(self: STM<R, E, A>) => STM<R1 | R, E1 | Exclude<E, {
_tag: K;
}>, A1 | A>;
<R, E extends {
_tag: string;
}, A, K extends E["_tag"] & string, R1, E1, A1>(self: STM<R, E, A>, k: K, f: (e: Extract<E, {
_tag: K;
}>) => STM<R1, E1, A1>): STM<R | R1, E1 | Exclude<E, {
_tag: K;
}>, A | A1>;
};
/**
* Collects all the transactional effects, returning a single transactional
* effect that produces `Unit`.
* Recovers from multiple tagged errors.
*
* Equivalent to `pipe(icollectAll(iterable), asUnit)`, but without the cost
* of building the list of results.
* @since 1.0.0
* @category error handling
*/
export declare const catchTags: {
<E extends {
_tag: string;
}, Cases extends {
[K in E["_tag"]]+?: ((error: Extract<E, {
_tag: K;
}>) => STM<any, any, any>);
}>(cases: Cases): <R, A>(self: STM<R, E, A>) => STM<R | {
[K in keyof Cases]: Cases[K] extends (...args: Array<any>) => STM<infer R, any, any> ? R : never;
}[keyof Cases], Exclude<E, {
_tag: keyof Cases;
}> | {
[K in keyof Cases]: Cases[K] extends (...args: Array<any>) => STM<any, infer E, any> ? E : never;
}[keyof Cases], A | {
[K in keyof Cases]: Cases[K] extends (...args: Array<any>) => STM<any, any, infer A> ? A : never;
}[keyof Cases]>;
<R, E extends {
_tag: string;
}, A, Cases extends {
[K in E["_tag"]]+?: ((error: Extract<E, {
_tag: K;
}>) => STM<any, any, any>);
}>(self: STM<R, E, A>, cases: Cases): STM<R | {
[K in keyof Cases]: Cases[K] extends (...args: Array<any>) => STM<infer R, any, any> ? R : never;
}[keyof Cases], Exclude<E, {
_tag: keyof Cases;
}> | {
[K in keyof Cases]: Cases[K] extends (...args: Array<any>) => STM<any, infer E, any> ? E : never;
}[keyof Cases], A | {
[K in keyof Cases]: Cases[K] extends (...args: Array<any>) => STM<any, any, infer A> ? A : never;
}[keyof Cases]>;
};
/**
* Checks the condition, and if it's true, returns unit, otherwise, retries.
*

@@ -329,3 +357,3 @@ * @since 1.0.0

*/
export declare const allDiscard: <R, E, A>(iterable: Iterable<STM<R, E, A>>) => STM<R, E, void>;
export declare const check: (predicate: LazyArg<boolean>) => STM<never, never, void>;
/**

@@ -352,13 +380,2 @@ * Simultaneously filters and maps the value produced by this effect.

/**
* Collects the first element of the `Iterable<A>` for which the effectual
* function `f` returns `Some`.
*
* @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>>;
<A, R, E, A2>(iterable: Iterable<A>, pf: (a: A) => STM<R, E, Option.Option<A2>>): STM<R, E, Option.Option<A2>>;
};
/**
* Commits this transaction atomically.

@@ -509,3 +526,3 @@ *

*/
export declare const fiberId: () => STM<never, never, FiberId.FiberId>;
export declare const fiberId: STM<never, never, FiberId.FiberId>;
/**

@@ -560,12 +577,2 @@ * Filters the collection using the specified effectual predicate.

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>;
<R, E, A, R2, E2, A2>(self: STM<R, E, A>, predicate: Predicate<A>, orElse: LazyArg<STM<R2, E2, A2>>): STM<R | R2, E | E2, A | A2>;
};
/**
* Applies `orElse` if the predicate fails.
*
* @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>;

@@ -581,4 +588,4 @@ <R, E, A, R2, E2, A2>(self: STM<R, E, A>, predicate: Predicate<A>, orElse: (a: A) => STM<R2, E2, A2>): STM<R | R2, E | E2, A | A2>;

export declare const filterOrFail: {
<A, E2>(predicate: Predicate<A>, error: LazyArg<E2>): <R, E>(self: STM<R, E, A>) => STM<R, E2 | E, A>;
<R, E, A, E2>(self: STM<R, E, A>, predicate: Predicate<A>, error: LazyArg<E2>): STM<R, E | E2, A>;
<A, E2>(predicate: Predicate<A>, orFailWith: (a: A) => E2): <R, E>(self: STM<R, E, A>) => STM<R, E2 | E, A>;
<R, E, A, E2>(self: STM<R, E, A>, predicate: Predicate<A>, orFailWith: (a: A) => E2): STM<R, E | E2, A>;
};

@@ -631,4 +638,10 @@ /**

export declare const match: {
<E, A2, A, A3>(f: (error: E) => A2, g: (value: A) => A3): <R>(self: STM<R, E, A>) => STM<R, never, A2 | A3>;
<R, E, A2, A, A3>(self: STM<R, E, A>, f: (error: E) => A2, g: (value: A) => A3): STM<R, never, A2 | A3>;
<E, A2, A, A3>(options: {
readonly onFailure: (error: E) => A2;
readonly onSuccess: (value: A) => A3;
}): <R>(self: STM<R, E, A>) => STM<R, never, A2 | A3>;
<R, E, A2, A, A3>(self: STM<R, E, A>, options: {
readonly onFailure: (error: E) => A2;
readonly onSuccess: (value: A) => A3;
}): STM<R, never, A2 | A3>;
};

@@ -642,4 +655,10 @@ /**

export declare const matchSTM: {
<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>;
<R, E, R1, E1, A1, A, R2, E2, A2>(self: STM<R, E, A>, onFailure: (e: E) => STM<R1, E1, A1>, onSuccess: (a: A) => STM<R2, E2, A2>): STM<R | R1 | R2, E1 | E2, A1 | A2>;
<E, R1, E1, A1, A, R2, E2, A2>(options: {
readonly onFailure: (e: E) => STM<R1, E1, A1>;
readonly onSuccess: (a: A) => STM<R2, E2, A2>;
}): <R>(self: STM<R, E, A>) => STM<R1 | R2 | R, E1 | E2, A1 | A2>;
<R, E, R1, E1, A1, A, R2, E2, A2>(self: STM<R, E, A>, options: {
readonly onFailure: (e: E) => STM<R1, E1, A1>;
readonly onSuccess: (a: A) => STM<R2, E2, A2>;
}): STM<R | R1 | R2, E1 | E2, A1 | A2>;
};

@@ -654,20 +673,16 @@ /**

export declare const forEach: {
<A, R, E, A2>(f: (a: A) => STM<R, E, A2>): (elements: Iterable<A>) => STM<R, E, Array<A2>>;
<A, R, E, A2>(elements: Iterable<A>, f: (a: A) => STM<R, E, A2>): STM<R, E, Array<A2>>;
<A, R, E, A2>(f: (a: A) => STM<R, E, A2>, options?: {
readonly discard?: false;
}): (elements: Iterable<A>) => STM<R, E, Array<A2>>;
<A, R, E, A2>(f: (a: A) => STM<R, E, A2>, options: {
readonly discard: true;
}): (elements: Iterable<A>) => STM<R, E, void>;
<A, R, E, A2>(elements: Iterable<A>, f: (a: A) => STM<R, E, A2>, options?: {
readonly discard?: false;
}): STM<R, E, Array<A2>>;
<A, R, E, A2>(elements: Iterable<A>, f: (a: A) => STM<R, E, A2>, options: {
readonly discard: true;
}): STM<R, E, void>;
};
/**
* 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.
*
* @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>;
<A, R, E, _>(iterable: Iterable<A>, f: (a: A) => STM<R, E, _>): STM<R, E, void>;
};
/**
* Lifts an `Either` into a `STM`.

@@ -730,2 +745,17 @@ *

export declare const head: <R, E, A>(self: STM<R, E, Iterable<A>>) => STM<R, Option.Option<E>, A>;
declare const if_: {
<R1, R2, E1, E2, A, A1>(options: {
readonly onTrue: STM<R1, E1, A>;
readonly onFalse: STM<R2, E2, A1>;
}): <R = never, E = never>(self: boolean | STM<R, E, boolean>) => STM<R1 | R2 | R, E1 | E2 | E, A | A1>;
<R, E, R1, R2, E1, E2, A, A1>(self: boolean, options: {
readonly onTrue: STM<R1, E1, A>;
readonly onFalse: STM<R2, E2, A1>;
}): STM<R | R1 | R2, E | E1 | E2, A | A1>;
<R, E, R1, R2, E1, E2, A, A1>(self: STM<R, E, boolean>, options: {
readonly onTrue: STM<R1, E1, A>;
readonly onFalse: STM<R2, E2, A1>;
}): STM<R | R1 | R2, E | E1 | E2, A | A1>;
};
export {
/**

@@ -737,6 +767,3 @@ * Runs `onTrue` if the result of `b` is `true` and `onFalse` otherwise.

*/
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>;
<R, E, R1, R2, E1, E2, A, A1>(self: STM<R, E, boolean>, onTrue: STM<R1, E1, A>, onFalse: STM<R2, E2, A1>): STM<R | R1 | R2, E | E1 | E2, A | A1>;
};
if_ as if };
/**

@@ -755,3 +782,3 @@ * Returns a new effect that ignores the success or failure of this effect.

*/
export declare const interrupt: () => STM<never, never, never>;
export declare const interrupt: STM<never, never, never>;
/**

@@ -795,3 +822,6 @@ * Interrupts the fiber running the effect with the specified `FiberId`.

*/
export declare const iterate: <R, E, Z>(initial: Z, cont: (z: Z) => boolean, body: (z: Z) => STM<R, E, Z>) => STM<R, E, Z>;
export declare const iterate: <R, E, Z>(initial: Z, options: {
readonly while: (z: Z) => boolean;
readonly body: (z: Z) => STM<R, E, Z>;
}) => STM<R, E, Z>;
/**

@@ -816,21 +846,17 @@ * Loops with the specified transactional function, collecting the results

*/
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, Array<A>>;
export declare const loop: {
<Z, R, E, A>(initial: Z, options: {
readonly while: (z: Z) => boolean;
readonly step: (z: Z) => Z;
readonly body: (z: Z) => STM<R, E, A>;
readonly discard?: false;
}): STM<R, E, Array<A>>;
<Z, R, E, A>(initial: Z, options: {
readonly while: (z: Z) => boolean;
readonly step: (z: Z) => Z;
readonly body: (z: Z) => STM<R, E, A>;
readonly discard: true;
}): STM<R, E, void>;
};
/**
* 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)
* }
* ```
*
* @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.

@@ -865,4 +891,10 @@ *

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>;
<R, E, E2, A, A2>(self: STM<R, E, A>, f: (error: E) => E2, g: (value: A) => A2): STM<R, E2, A2>;
<E, E2, A, A2>(options: {
readonly onFailure: (error: E) => E2;
readonly onSuccess: (value: A) => A2;
}): <R>(self: STM<R, E, A>) => STM<R, E2, A2>;
<R, E, E2, A, A2>(self: STM<R, E, A>, options: {
readonly onFailure: (error: E) => E2;
readonly onSuccess: (value: A) => A2;
}): STM<R, E2, A2>;
};

@@ -1215,3 +1247,3 @@ /**

*/
export declare const retry: () => STM<never, never, never>;
export declare const retry: STM<never, never, never>;
/**

@@ -1247,22 +1279,2 @@ * Filters the value produced by this effect, retrying the transaction until

/**
* Extracts the optional value, or returns the given 'default'.
*
* @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>;
<R, E, A, A2>(self: STM<R, E, Option.Option<A>>, orElse: LazyArg<A2>): STM<R, E, A | A2>;
};
/**
* Extracts the optional value, or executes the effect 'default'.
*
* @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>;
<R, E, A, R2, E2, A2>(self: STM<R, E, Option.Option<A>>, orElse: LazyArg<STM<R2, E2, A2>>): STM<R | R2, E | E2, A | A2>;
};
/**
* Returns an `STM` effect that succeeds with the specified value.

@@ -1280,3 +1292,3 @@ *

*/
export declare const succeedNone: () => STM<never, never, Option.Option<never>>;
export declare const succeedNone: STM<never, never, Option.Option<never>>;
/**

@@ -1333,4 +1345,10 @@ * Returns an effect with the optional value.

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>;
<R, E, R2, E2, A2, A, R3, E3, A3>(self: STM<R, E, A>, f: (error: E) => STM<R2, E2, A2>, g: (value: A) => STM<R3, E3, A3>): STM<R | R2 | R3, E | E2 | E3, A>;
<E, R2, E2, A2, A, R3, E3, A3>(options: {
readonly onFailure: (error: E) => STM<R2, E2, A2>;
readonly onSuccess: (value: A) => STM<R3, E3, A3>;
}): <R>(self: STM<R, E, A>) => STM<R2 | R3 | R, E | E2 | E3, A>;
<R, E, R2, E2, A2, A, R3, E3, A3>(self: STM<R, E, A>, options: {
readonly onFailure: (error: E) => STM<R2, E2, A2>;
readonly onSuccess: (value: A) => STM<R3, E3, A3>;
}): STM<R | R2 | R3, E | E2 | E3, A>;
};

@@ -1347,2 +1365,10 @@ /**

};
declare const try_: {
<A>(try_: LazyArg<A>): STM<never, unknown, A>;
<A, E>(options: {
readonly try: LazyArg<A>;
readonly catch: (u: unknown) => E;
}): STM<never, E, A>;
};
export {
/**

@@ -1355,3 +1381,3 @@ * Imports a synchronous side-effect into a pure value, translating any thrown

*/
export declare const tryCatch: <E, A>(attempt: () => A, onThrow: (u: unknown) => E) => Effect.Effect<never, E, A>;
try_ as try };
/**

@@ -1390,3 +1416,3 @@ * The moral equivalent of `if (!p) exp`

*/
export declare const unit: () => STM<never, never, void>;
export declare const unit: STM<never, never, void>;
/**

@@ -1393,0 +1419,0 @@ * Feeds elements of type `A` to `f` and accumulates all errors in error

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

});
exports.replicateSTM = exports.replicate = exports.repeatWhile = exports.repeatUntil = exports.rejectSTM = exports.reject = exports.refineOrDieWith = exports.refineOrDie = exports.reduceRight = exports.reduceAll = exports.reduce = exports.provideSomeContext = exports.provideServiceSTM = exports.provideService = exports.provideContext = 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.matchSTM = exports.match = exports.mapError = exports.mapBoth = exports.mapAttempt = exports.map = exports.loopDiscard = exports.loop = exports.let = exports.iterate = exports.isSuccess = exports.isSTM = exports.isFailure = exports.interruptAs = exports.interrupt = exports.ignore = exports.ifSTM = exports.head = exports.gen = exports.fromOption = exports.fromEither = exports.forEachDiscard = exports.forEach = exports.flipWith = exports.flip = exports.flatten = exports.flatMap = exports.firstSuccessOf = 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.ensuring = exports.either = exports.dieSync = exports.dieMessage = exports.die = exports.contramapContext = exports.contextWithSTM = exports.contextWith = exports.context = exports.cond = exports.commitEither = exports.commit = exports.collectSTM = exports.collectFirst = exports.collect = exports.check = exports.catchSome = exports.catchAll = exports.bindTo = exports.bind = exports.attempt = exports.asUnit = exports.asSomeError = exports.asSome = exports.as = exports.allDiscard = exports.all = exports.acquireUseRelease = exports.STMTypeId = exports.Do = void 0;
exports.zipWith = exports.zipRight = exports.zipLeft = exports.zip = exports.whenSTM = exports.when = exports.validateFirst = exports.validateAll = exports.unsome = exports.unlessSTM = exports.unless = exports.unit = exports.tryCatch = exports.tapError = exports.tapBoth = exports.tap = exports.sync = exports.suspend = exports.summarized = exports.succeedSome = exports.succeedNone = exports.succeed = exports.someOrElseSTM = exports.someOrElse = exports.some = exports.retryWhile = exports.retryUntil = exports.retry = exports.replicateSTMDiscard = void 0;
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.provideSomeContext = exports.provideServiceSTM = exports.provideService = exports.provideContext = 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.matchSTM = exports.match = exports.mapError = exports.mapBoth = exports.mapAttempt = exports.map = exports.loop = exports.let = exports.iterate = exports.isSuccess = exports.isSTM = exports.isFailure = exports.interruptAs = exports.interrupt = exports.ignore = exports.if = exports.head = exports.gen = exports.fromOption = exports.fromEither = exports.forEach = exports.flipWith = exports.flip = exports.flatten = exports.flatMap = exports.firstSuccessOf = exports.filterOrFail = exports.filterOrElse = exports.filterOrDieMessage = exports.filterOrDie = exports.filterNot = exports.filter = exports.fiberId = exports.failSync = exports.fail = exports.exists = exports.every = exports.eventually = exports.ensuring = exports.either = exports.dieSync = exports.dieMessage = exports.die = exports.contramapContext = exports.contextWithSTM = exports.contextWith = exports.context = exports.cond = exports.commitEither = exports.commit = exports.collectSTM = exports.collect = exports.check = exports.catchTags = exports.catchTag = exports.catchSome = exports.catchAll = exports.bindTo = exports.bind = exports.attempt = exports.asUnit = exports.asSomeError = exports.asSome = exports.as = exports.all = exports.acquireUseRelease = exports.STMTypeId = exports.Do = void 0;
exports.zipWith = exports.zipRight = exports.zipLeft = exports.zip = exports.whenSTM = exports.when = exports.validateFirst = exports.validateAll = exports.unsome = exports.unlessSTM = exports.unless = exports.unit = exports.try = exports.tapError = exports.tapBoth = exports.tap = exports.sync = exports.suspend = exports.summarized = exports.succeedSome = exports.succeedNone = exports.succeed = exports.some = exports.retryWhile = void 0;
var Chunk = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Chunk"));

@@ -114,15 +114,19 @@ var Cause = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/Cause"));

/**
* Checks the condition, and if it's true, returns unit, otherwise, retries.
* Recovers from the specified tagged error.
*
* @since 1.0.0
* @category constructors
* @category error handling
*/
exports.catchSome = catchSome;
const check = stm.check;
const catchTag = stm.catchTag;
/**
* Collects all the transactional effects, returning a single transactional
* effect that produces `Unit`.
* Recovers from multiple tagged errors.
*
* Equivalent to `pipe(icollectAll(iterable), asUnit)`, but without the cost
* of building the list of results.
* @since 1.0.0
* @category error handling
*/
exports.catchTag = catchTag;
const catchTags = stm.catchTags;
/**
* Checks the condition, and if it's true, returns unit, otherwise, retries.
*

@@ -132,4 +136,4 @@ * @since 1.0.0

*/
exports.check = check;
const allDiscard = stm.collectAllDiscard;
exports.catchTags = catchTags;
const check = stm.check;
/**

@@ -141,3 +145,3 @@ * Simultaneously filters and maps the value produced by this effect.

*/
exports.allDiscard = allDiscard;
exports.check = check;
const collect = stm.collect;

@@ -153,11 +157,2 @@ /**

/**
* Collects the first element of the `Iterable<A>` for which the effectual
* function `f` returns `Some`.
*
* @since 1.0.0
* @category constructors
*/
exports.collectSTM = collectSTM;
const collectFirst = stm.collectFirst;
/**
* Commits this transaction atomically.

@@ -168,3 +163,3 @@ *

*/
exports.collectFirst = collectFirst;
exports.collectSTM = collectSTM;
const commit = core.commit;

@@ -359,3 +354,3 @@ /**

/**
* Applies `orElse` if the predicate fails.
* Fails with the specified error if the predicate fails.
*

@@ -366,10 +361,2 @@ * @since 1.0.0

exports.filterOrElse = filterOrElse;
const filterOrElseWith = stm.filterOrElseWith;
/**
* Fails with the specified error if the predicate fails.
*
* @since 1.0.0
* @category filtering
*/
exports.filterOrElseWith = filterOrElseWith;
const filterOrFail = stm.filterOrFail;

@@ -439,14 +426,2 @@ /**

/**
* 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.
*
* @since 1.0.0
* @category traversing
*/
exports.forEach = forEach;
const forEachDiscard = stm.forEachDiscard;
/**
* Lifts an `Either` into a `STM`.

@@ -457,3 +432,3 @@ *

*/
exports.forEachDiscard = forEachDiscard;
exports.forEach = forEach;
const fromEither = stm.fromEither;

@@ -483,10 +458,5 @@ /**

const head = stm.head;
/**
* Runs `onTrue` if the result of `b` is `true` and `onFalse` otherwise.
*
* @since 1.0.0
* @category mutations
*/
exports.head = head;
const ifSTM = stm.ifSTM;
const if_ = stm.if_;
exports.if = if_;
/**

@@ -498,3 +468,2 @@ * Returns a new effect that ignores the success or failure of this effect.

*/
exports.ifSTM = ifSTM;
const ignore = stm.ignore;

@@ -574,20 +543,2 @@ /**

/**
* 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)
* }
* ```
*
* @since 1.0.0
* @category constructors
*/
exports.loop = loop;
const loopDiscard = stm.loopDiscard;
/**
* Maps the value produced by the effect.

@@ -598,3 +549,3 @@ *

*/
exports.loopDiscard = loopDiscard;
exports.loop = loop;
const map = core.map;

@@ -948,18 +899,2 @@ /**

/**
* Extracts the optional value, or returns the given 'default'.
*
* @since 1.0.0
* @category getters
*/
exports.some = some;
const someOrElse = stm.someOrElse;
/**
* Extracts the optional value, or executes the effect 'default'.
*
* @since 1.0.0
* @category getters
*/
exports.someOrElse = someOrElse;
const someOrElseSTM = stm.someOrElseSTM;
/**
* Returns an `STM` effect that succeeds with the specified value.

@@ -970,3 +905,3 @@ *

*/
exports.someOrElseSTM = someOrElseSTM;
exports.some = some;
const succeed = core.succeed;

@@ -1040,11 +975,5 @@ /**

const tapError = stm.tapError;
/**
* Imports a synchronous side-effect into a pure value, translating any thrown
* exceptions into typed failed effects.
*
* @since 1.0.0
* @category constructors
*/
exports.tapError = tapError;
const tryCatch = stm.tryCatch;
const try_ = stm.try_;
exports.try = try_;
/**

@@ -1056,3 +985,2 @@ * The moral equivalent of `if (!p) exp`

*/
exports.tryCatch = tryCatch;
const unless = stm.unless;

@@ -1059,0 +987,0 @@ /**

@@ -68,3 +68,3 @@ /**

*/
peek(): STM.STM<never, never, A>;
readonly peek: STM.STM<never, never, A>;
/**

@@ -74,3 +74,3 @@ * Views the next element in the queue without removing it, returning `None`

*/
peekOption(): STM.STM<never, never, Option.Option<A>>;
readonly peekOption: STM.STM<never, never, Option.Option<A>>;
/**

@@ -80,3 +80,3 @@ * Takes the oldest value in the queue. If the queue is empty, this will return

*/
take(): STM.STM<never, never, A>;
readonly take: STM.STM<never, never, A>;
/**

@@ -86,3 +86,3 @@ * Takes all the values in the queue and returns the values. If the queue is

*/
takeAll(): STM.STM<never, never, Array<A>>;
readonly takeAll: STM.STM<never, never, Array<A>>;
/**

@@ -109,3 +109,3 @@ * Takes up to max number of values from the queue.

*/
size(): STM.STM<never, never, number>;
readonly size: STM.STM<never, never, number>;
/**

@@ -115,7 +115,7 @@ * Returns `true` if the `TQueue` contains at least one element, `false`

*/
isFull(): STM.STM<never, never, boolean>;
readonly isFull: STM.STM<never, never, boolean>;
/**
* Returns `true` if the `TQueue` contains zero elements, `false` otherwise.
*/
isEmpty(): STM.STM<never, never, boolean>;
readonly isEmpty: STM.STM<never, never, boolean>;
/**

@@ -125,7 +125,7 @@ * Interrupts any fibers that are suspended on `offer` or `take`. Future calls

*/
shutdown(): STM.STM<never, never, void>;
readonly shutdown: STM.STM<never, never, void>;
/**
* Returns `true` if `shutdown` has been called, otherwise returns `false`.
*/
isShutdown(): STM.STM<never, never, boolean>;
readonly isShutdown: STM.STM<never, never, boolean>;
/**

@@ -136,3 +136,3 @@ * Waits until the queue is shutdown. The `STM` returned by this method will

*/
awaitShutdown(): STM.STM<never, never, void>;
readonly awaitShutdown: STM.STM<never, never, void>;
}

@@ -139,0 +139,0 @@ /**

@@ -26,11 +26,11 @@ /**

*/
next(): STM.STM<never, never, number>;
readonly next: STM.STM<never, never, number>;
/**
* Returns the next boolean value from the pseudo-random number generator.
*/
nextBoolean(): STM.STM<never, never, boolean>;
readonly nextBoolean: STM.STM<never, never, boolean>;
/**
* Returns the next integer value from the pseudo-random number generator.
*/
nextInt(): STM.STM<never, never, number>;
readonly nextInt: STM.STM<never, never, number>;
/**

@@ -64,3 +64,3 @@ * Returns the next numeric value in the specified range from the

*/
export declare const live: () => Layer.Layer<never, never, TRandom>;
export declare const live: Layer.Layer<never, never, TRandom>;
/**

@@ -72,3 +72,3 @@ * Returns the next number from the pseudo-random number generator.

*/
export declare const next: () => STM.STM<TRandom, never, number>;
export declare const next: STM.STM<TRandom, never, number>;
/**

@@ -80,3 +80,3 @@ * Returns the next boolean value from the pseudo-random number generator.

*/
export declare const nextBoolean: () => STM.STM<TRandom, never, boolean>;
export declare const nextBoolean: STM.STM<TRandom, never, boolean>;
/**

@@ -88,3 +88,3 @@ * Returns the next integer from the pseudo-random number generator.

*/
export declare const nextInt: () => STM.STM<TRandom, never, number>;
export declare const nextInt: STM.STM<TRandom, never, number>;
/**

@@ -91,0 +91,0 @@ * Returns the next integer in the specified range from the pseudo-random number

@@ -105,3 +105,3 @@ /**

*/
export declare const make: () => STM.STM<never, never, TReentrantLock>;
export declare const make: STM.STM<never, never, TReentrantLock>;
/**

@@ -108,0 +108,0 @@ * Obtains a read lock in a scoped context.

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

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

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

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