| /** | |
| * Yields its wrapped value exactly once through an `IterableIterator`. | |
| * | |
| * **When to use** | |
| * | |
| * Use to implement `[Symbol.iterator]()` on Effect-like types so they can be | |
| * `yield*`-ed inside generator functions, such as `Effect.gen` and | |
| * `Option.gen`. | |
| * | |
| * **Details** | |
| * | |
| * The first call to `next()` returns `{ value: self, done: false }`. Every | |
| * subsequent call returns `{ value: a, done: true }` where `a` is the argument | |
| * passed to `next()`. `[Symbol.iterator]()` returns a **new** `SingleShotGen` | |
| * wrapping the same value, so the outer type can be iterated multiple times. | |
| * | |
| * **Example** (Yielding a wrapped value in a generator) | |
| * | |
| * ```ts | |
| * import { Utils } from "effect" | |
| * | |
| * const gen = new Utils.SingleShotGen<string, number>("hello") | |
| * | |
| * // First call yields the wrapped value | |
| * console.log(gen.next(0)) | |
| * // { value: "hello", done: false } | |
| * | |
| * // Second call signals completion with the provided value | |
| * console.log(gen.next(42)) | |
| * // { value: 42, done: true } | |
| * ``` | |
| * | |
| * @see {@link Gen} for the type-level signature that relies on `SingleShotGen` | |
| * @category constructors | |
| * @since 2.0.0 | |
| */ | |
| export class SingleShotGen { | |
| called = false; | |
| self; | |
| constructor(self) { | |
| this.self = self; | |
| } | |
| /** | |
| * Yields the stored value once, then completes with the value sent back in. | |
| * | |
| * **When to use** | |
| * | |
| * Use to advance a `SingleShotGen` through its single yield and completion | |
| * step. | |
| * | |
| * @since 2.0.0 | |
| */ | |
| next(a) { | |
| return this.called ? { | |
| value: a, | |
| done: true | |
| } : (this.called = true, { | |
| value: this.self, | |
| done: false | |
| }); | |
| } | |
| /** | |
| * Creates a fresh single-shot iterator over the stored value. | |
| * | |
| * **When to use** | |
| * | |
| * Use to iterate the wrapped value again without reusing the consumed | |
| * iterator state. | |
| * | |
| * @since 2.0.0 | |
| */ | |
| [Symbol.iterator]() { | |
| return new SingleShotGen(this.self); | |
| } | |
| } | |
| // the probe is wrapped in a single function call (rather than module-level | |
| // statements) so the whole selection is pure-annotated by the build and | |
| // tree-shakable when `internalCall` is unused. | |
| const pickInternalCall = () => { | |
| const InternalTypeId = "~effect/Utils/internal"; | |
| const standard = { | |
| [InternalTypeId]: body => { | |
| return body(); | |
| } | |
| }; | |
| const forced = { | |
| [InternalTypeId]: body => { | |
| try { | |
| return body(); | |
| } finally { | |
| // | |
| } | |
| } | |
| }; | |
| const isNotOptimizedAway = standard[InternalTypeId](() => new Error().stack)?.includes(InternalTypeId) === true; | |
| return isNotOptimizedAway ? standard[InternalTypeId] : forced[InternalTypeId]; | |
| }; | |
| /** @internal */ | |
| export const internalCall = /*#__PURE__*/pickInternalCall(); | |
| //# sourceMappingURL=Utils.js.map |
Xet Storage Details
- Size:
- 2.74 kB
- Xet hash:
- df96d94603dfb31d983eb94c1d0328b1ca43d32cd37311f2f3c5d667777375b0
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.