@effect/language-service 0.7.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +3348 -1096
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Function.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/version.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/GlobalValue.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Predicate.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/errors.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Utils.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Hash.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Equal.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Equivalence.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Inspectable.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Pipeable.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/opCodes/effect.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/effectable.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/option.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Order.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Option.ts","../src/definition.ts","../src/utils/TypeParser.ts","../src/diagnostics/floatingEffect.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/array.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Iterable.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Array.ts","../src/utils/AST.ts","../src/utils/TypeCheckerApi.ts","../src/diagnostics/missingEffectContext.ts","../src/diagnostics/missingEffectError.ts","../src/diagnostics/missingStarInYieldEffectGen.ts","../src/diagnostics/unnecessaryEffectGen.ts","../src/diagnostics.ts","../src/quickinfo.ts","../src/refactors/asyncAwaitToGen.ts","../src/refactors/asyncAwaitToGenTryPromise.ts","../src/refactors/effectGenToFn.ts","../src/refactors/functionToArrow.ts","../src/refactors/pipeableToDatafirst.ts","../src/refactors/removeUnnecessaryEffectGen.ts","../src/refactors/toggleLazyConst.ts","../src/refactors/toggleReturnTypeAnnotation.ts","../src/refactors/toggleTypeAnnotation.ts","../src/refactors/wrapWithPipe.ts","../src/refactors.ts","../src/index.ts"],"sourcesContent":["/**\n * @since 2.0.0\n */\nimport type { TypeLambda } from \"./HKT.js\"\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface FunctionTypeLambda extends TypeLambda {\n readonly type: (a: this[\"In\"]) => this[\"Target\"]\n}\n\n/**\n * Tests if a value is a `function`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isFunction } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isFunction(isFunction), true)\n * assert.deepStrictEqual(isFunction(\"function\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isFunction = (input: unknown): input is Function => typeof input === \"function\"\n\n/**\n * Creates a function that can be used in a data-last (aka `pipe`able) or\n * data-first style.\n *\n * The first parameter to `dual` is either the arity of the uncurried function\n * or a predicate that determines if the function is being used in a data-first\n * or data-last style.\n *\n * Using the arity is the most common use case, but there are some cases where\n * you may want to use a predicate. For example, if you have a function that\n * takes an optional argument, you can use a predicate to determine if the\n * function is being used in a data-first or data-last style.\n *\n * @param arity - Either the arity of the uncurried function or a predicate\n * which determines if the function is being used in a data-first\n * or data-last style.\n * @param body - The definition of the uncurried function.\n *\n * @example\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * // Exampe using arity to determine data-first or data-last style\n * const sum: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual(2, (self: number, that: number): number => self + that)\n *\n * assert.deepStrictEqual(sum(2, 3), 5)\n * assert.deepStrictEqual(pipe(2, sum(3)), 5)\n *\n * // Example using a predicate to determine data-first or data-last style\n * const sum2: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual((args) => args.length === 1, (self: number, that: number): number => self + that)\n *\n * assert.deepStrictEqual(sum(2, 3), 5)\n * assert.deepStrictEqual(pipe(2, sum(3)), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const dual: {\n /**\n * Creates a function that can be used in a data-last (aka `pipe`able) or\n * data-first style.\n *\n * The first parameter to `dual` is either the arity of the uncurried function\n * or a predicate that determines if the function is being used in a data-first\n * or data-last style.\n *\n * Using the arity is the most common use case, but there are some cases where\n * you may want to use a predicate. For example, if you have a function that\n * takes an optional argument, you can use a predicate to determine if the\n * function is being used in a data-first or data-last style.\n *\n * @param arity - Either the arity of the uncurried function or a predicate\n * which determines if the function is being used in a data-first\n * or data-last style.\n * @param body - The definition of the uncurried function.\n *\n * @example\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * // Exampe using arity to determine data-first or data-last style\n * const sum: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual(2, (self: number, that: number): number => self + that)\n *\n * assert.deepStrictEqual(sum(2, 3), 5)\n * assert.deepStrictEqual(pipe(2, sum(3)), 5)\n *\n * // Example using a predicate to determine data-first or data-last style\n * const sum2: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual((args) => args.length === 1, (self: number, that: number): number => self + that)\n *\n * assert.deepStrictEqual(sum(2, 3), 5)\n * assert.deepStrictEqual(pipe(2, sum(3)), 5)\n * ```\n *\n * @since 2.0.0\n */\n <DataLast extends (...args: Array<any>) => any, DataFirst extends (...args: Array<any>) => any>(\n arity: Parameters<DataFirst>[\"length\"],\n body: DataFirst\n ): DataLast & DataFirst\n /**\n * Creates a function that can be used in a data-last (aka `pipe`able) or\n * data-first style.\n *\n * The first parameter to `dual` is either the arity of the uncurried function\n * or a predicate that determines if the function is being used in a data-first\n * or data-last style.\n *\n * Using the arity is the most common use case, but there are some cases where\n * you may want to use a predicate. For example, if you have a function that\n * takes an optional argument, you can use a predicate to determine if the\n * function is being used in a data-first or data-last style.\n *\n * @param arity - Either the arity of the uncurried function or a predicate\n * which determines if the function is being used in a data-first\n * or data-last style.\n * @param body - The definition of the uncurried function.\n *\n * @example\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * // Exampe using arity to determine data-first or data-last style\n * const sum: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual(2, (self: number, that: number): number => self + that)\n *\n * assert.deepStrictEqual(sum(2, 3), 5)\n * assert.deepStrictEqual(pipe(2, sum(3)), 5)\n *\n * // Example using a predicate to determine data-first or data-last style\n * const sum2: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual((args) => args.length === 1, (self: number, that: number): number => self + that)\n *\n * assert.deepStrictEqual(sum(2, 3), 5)\n * assert.deepStrictEqual(pipe(2, sum(3)), 5)\n * ```\n *\n * @since 2.0.0\n */\n <DataLast extends (...args: Array<any>) => any, DataFirst extends (...args: Array<any>) => any>(\n isDataFirst: (args: IArguments) => boolean,\n body: DataFirst\n ): DataLast & DataFirst\n} = function(arity, body) {\n if (typeof arity === \"function\") {\n return function() {\n if (arity(arguments)) {\n // @ts-expect-error\n return body.apply(this, arguments)\n }\n return ((self: any) => body(self, ...arguments)) as any\n }\n }\n\n switch (arity) {\n case 0:\n case 1:\n throw new RangeError(`Invalid arity ${arity}`)\n\n case 2:\n return function(a, b) {\n if (arguments.length >= 2) {\n return body(a, b)\n }\n return function(self: any) {\n return body(self, a)\n }\n }\n\n case 3:\n return function(a, b, c) {\n if (arguments.length >= 3) {\n return body(a, b, c)\n }\n return function(self: any) {\n return body(self, a, b)\n }\n }\n\n case 4:\n return function(a, b, c, d) {\n if (arguments.length >= 4) {\n return body(a, b, c, d)\n }\n return function(self: any) {\n return body(self, a, b, c)\n }\n }\n\n case 5:\n return function(a, b, c, d, e) {\n if (arguments.length >= 5) {\n return body(a, b, c, d, e)\n }\n return function(self: any) {\n return body(self, a, b, c, d)\n }\n }\n\n default:\n return function() {\n if (arguments.length >= arity) {\n // @ts-expect-error\n return body.apply(this, arguments)\n }\n const args = arguments\n return function(self: any) {\n return body(self, ...args)\n }\n }\n }\n}\n/**\n * Apply a function to a given value.\n *\n * @param a - The value that the function will be applied to.\n * @param self - The function to be applied to a value.\n *\n * @example\n * ```ts\n * import { pipe, apply } from \"effect/Function\"\n * import { length } from \"effect/String\"\n *\n * assert.deepStrictEqual(pipe(length, apply(\"hello\")), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const apply = <A>(a: A) => <B>(self: (a: A) => B): B => self(a)\n\n/**\n * A lazy argument.\n *\n * @example\n * ```ts\n * import { LazyArg, constant } from \"effect/Function\"\n *\n * const constNull: LazyArg<null> = constant(null)\n * ```\n *\n * @since 2.0.0\n */\nexport interface LazyArg<A> {\n (): A\n}\n\n/**\n * @example\n * ```ts\n * import { FunctionN } from \"effect/Function\"\n *\n * const sum: FunctionN<[number, number], number> = (a, b) => a + b\n * ```\n *\n * @since 2.0.0\n */\nexport interface FunctionN<A extends ReadonlyArray<unknown>, B> {\n (...args: A): B\n}\n\n/**\n * The identity function, i.e. A function that returns its input argument.\n *\n * @param a - The input argument.\n *\n * @example\n * ```ts\n * import { identity } from \"effect/Function\"\n *\n * assert.deepStrictEqual(identity(5), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const identity = <A>(a: A): A => a\n\n/**\n * A function that ensures that the type of an expression matches some type,\n * without changing the resulting type of that expression.\n *\n * @example\n * ```ts\n * import { satisfies } from \"effect/Function\"\n *\n * const test1 = satisfies<number>()(5 as const)\n * //^? const test: 5\n * // @ts-expect-error\n * const test2 = satisfies<string>()(5)\n * //^? Argument of type 'number' is not assignable to parameter of type 'string'\n *\n * assert.deepStrictEqual(satisfies<number>()(5), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const satisfies = <A>() => <B extends A>(b: B) => b\n\n/**\n * Casts the result to the specified type.\n *\n * @param a - The value to be casted to the target type.\n *\n * @example\n * ```ts\n * import { unsafeCoerce, identity } from \"effect/Function\"\n *\n * assert.deepStrictEqual(unsafeCoerce, identity)\n * ```\n *\n * @since 2.0.0\n */\nexport const unsafeCoerce: <A, B>(a: A) => B = identity as any\n\n/**\n * Creates a constant value that never changes.\n *\n * This is useful when you want to pass a value to a higher-order function (a function that takes another function as its argument)\n * and want that inner function to always use the same value, no matter how many times it is called.\n *\n * @param value - The constant value to be returned.\n *\n * @example\n * ```ts\n * import { constant } from \"effect/Function\"\n *\n * const constNull = constant(null)\n *\n * assert.deepStrictEqual(constNull(), null)\n * assert.deepStrictEqual(constNull(), null)\n * ```\n *\n * @since 2.0.0\n */\nexport const constant = <A>(value: A): LazyArg<A> => () => value\n\n/**\n * A thunk that returns always `true`.\n *\n * @example\n * ```ts\n * import { constTrue } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constTrue(), true)\n * ```\n *\n * @since 2.0.0\n */\nexport const constTrue: LazyArg<boolean> = constant(true)\n\n/**\n * A thunk that returns always `false`.\n *\n * @example\n * ```ts\n * import { constFalse } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constFalse(), false)\n * ```\n *\n * @since 2.0.0\n */\nexport const constFalse: LazyArg<boolean> = constant(false)\n\n/**\n * A thunk that returns always `null`.\n *\n * @example\n * ```ts\n * import { constNull } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constNull(), null)\n * ```\n *\n * @since 2.0.0\n */\nexport const constNull: LazyArg<null> = constant(null)\n\n/**\n * A thunk that returns always `undefined`.\n *\n * @example\n * ```ts\n * import { constUndefined } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constUndefined(), undefined)\n * ```\n *\n * @since 2.0.0\n */\nexport const constUndefined: LazyArg<undefined> = constant(undefined)\n\n/**\n * A thunk that returns always `void`.\n *\n * @example\n * ```ts\n * import { constVoid } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constVoid(), undefined)\n * ```\n *\n * @since 2.0.0\n */\nexport const constVoid: LazyArg<void> = constUndefined\n\n/**\n * Reverses the order of arguments for a curried function.\n *\n * @param f - A curried function that takes multiple arguments.\n *\n * @example\n * ```ts\n * import { flip } from \"effect/Function\"\n *\n * const f = (a: number) => (b: string) => a - b.length\n *\n * assert.deepStrictEqual(flip(f)('aaa')(2), -1)\n * ```\n *\n * @since 2.0.0\n */\nexport const flip = <A extends Array<unknown>, B extends Array<unknown>, C>(\n f: (...a: A) => (...b: B) => C\n): (...b: B) => (...a: A) => C =>\n(...b) =>\n(...a) => f(...a)(...b)\n\n/**\n * Composes two functions, `ab` and `bc` into a single function that takes in an argument `a` of type `A` and returns a result of type `C`.\n * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.\n *\n * @param ab - A function that maps from `A` to `B`.\n * @param bc - A function that maps from `B` to `C`.\n *\n * @example\n * ```ts\n * import { compose } from \"effect/Function\"\n *\n * const increment = (n: number) => n + 1;\n * const square = (n: number) => n * n;\n *\n * assert.strictEqual(compose(increment, square)(2), 9);\n * ```\n *\n * @since 2.0.0\n */\nexport const compose: {\n /**\n * Composes two functions, `ab` and `bc` into a single function that takes in an argument `a` of type `A` and returns a result of type `C`.\n * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.\n *\n * @param ab - A function that maps from `A` to `B`.\n * @param bc - A function that maps from `B` to `C`.\n *\n * @example\n * ```ts\n * import { compose } from \"effect/Function\"\n *\n * const increment = (n: number) => n + 1;\n * const square = (n: number) => n * n;\n *\n * assert.strictEqual(compose(increment, square)(2), 9);\n * ```\n *\n * @since 2.0.0\n */\n <B, C>(bc: (b: B) => C): <A>(self: (a: A) => B) => (a: A) => C\n /**\n * Composes two functions, `ab` and `bc` into a single function that takes in an argument `a` of type `A` and returns a result of type `C`.\n * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.\n *\n * @param ab - A function that maps from `A` to `B`.\n * @param bc - A function that maps from `B` to `C`.\n *\n * @example\n * ```ts\n * import { compose } from \"effect/Function\"\n *\n * const increment = (n: number) => n + 1;\n * const square = (n: number) => n * n;\n *\n * assert.strictEqual(compose(increment, square)(2), 9);\n * ```\n *\n * @since 2.0.0\n */\n <A, B, C>(self: (a: A) => B, bc: (b: B) => C): (a: A) => C\n} = dual(2, <A, B, C>(ab: (a: A) => B, bc: (b: B) => C): (a: A) => C => (a) => bc(ab(a)))\n\n/**\n * The `absurd` function is a stub for cases where a value of type `never` is encountered in your code,\n * meaning that it should be impossible for this code to be executed.\n *\n * This function is particularly useful when it's necessary to specify that certain cases are impossible.\n *\n * @since 2.0.0\n */\nexport const absurd = <A>(_: never): A => {\n throw new Error(\"Called `absurd` function which should be uncallable\")\n}\n\n/**\n * Creates a tupled version of this function: instead of `n` arguments, it accepts a single tuple argument.\n *\n * @example\n * ```ts\n * import { tupled } from \"effect/Function\"\n *\n * const sumTupled = tupled((x: number, y: number): number => x + y)\n *\n * assert.deepStrictEqual(sumTupled([1, 2]), 3)\n * ```\n *\n * @since 2.0.0\n */\nexport const tupled = <A extends ReadonlyArray<unknown>, B>(f: (...a: A) => B): (a: A) => B => (a) => f(...a)\n\n/**\n * Inverse function of `tupled`\n *\n * @example\n * ```ts\n * import { untupled } from \"effect/Function\"\n *\n * const getFirst = untupled(<A, B>(tuple: [A, B]): A => tuple[0])\n *\n * assert.deepStrictEqual(getFirst(1, 2), 1)\n * ```\n *\n * @since 2.0.0\n */\nexport const untupled = <A extends ReadonlyArray<unknown>, B>(f: (a: A) => B): (...a: A) => B => (...a) => f(a)\n\n/**\n * Pipes the value of an expression into a pipeline of functions.\n *\n * **When to Use**\n *\n * This is useful in combination with data-last functions as a simulation of\n * methods:\n *\n * ```ts\n * as.map(f).filter(g)\n * ```\n *\n * becomes:\n *\n * ```ts\n * import { pipe, Array } from \"effect\"\n *\n * pipe(as, Array.map(f), Array.filter(g))\n * ```\n *\n * **Details**\n *\n * The `pipe` function is a utility that allows us to compose functions in a\n * readable and sequential manner. It takes the output of one function and\n * passes it as the input to the next function in the pipeline. This enables us\n * to build complex transformations by chaining multiple functions together.\n *\n * ```ts\n * import { pipe } from \"effect\"\n *\n * const result = pipe(input, func1, func2, ..., funcN)\n * ```\n *\n * In this syntax, `input` is the initial value, and `func1`, `func2`, ...,\n * `funcN` are the functions to be applied in sequence. The result of each\n * function becomes the input for the next function, and the final result is\n * returned.\n *\n * Here's an illustration of how `pipe` works:\n *\n * ```text\n * ┌───────┐ ┌───────┐ ┌───────┐ ┌───────┐ ┌───────┐ ┌────────┐\n * │ input │───►│ func1 │───►│ func2 │───►│ ... │───►│ funcN │───►│ result │\n * └───────┘ └───────┘ └───────┘ └───────┘ └───────┘ └────────┘\n * ```\n *\n * It's important to note that functions passed to `pipe` must have a **single\n * argument** because they are only called with a single argument.\n *\n * @example\n * ```ts\n * // Example: Chaining Arithmetic Operations\n * import { pipe } from \"effect\"\n *\n * // Define simple arithmetic operations\n * const increment = (x: number) => x + 1\n * const double = (x: number) => x * 2\n * const subtractTen = (x: number) => x - 10\n *\n * // Sequentially apply these operations using `pipe`\n * const result = pipe(5, increment, double, subtractTen)\n *\n * console.log(result)\n * // Output: 2\n * ```\n *\n * @since 2.0.0\n */\nexport function pipe<A>(a: A): A\nexport function pipe<A, B = never>(a: A, ab: (a: A) => B): B\nexport function pipe<A, B = never, C = never>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C\n): C\nexport function pipe<A, B = never, C = never, D = never>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D\n): D\nexport function pipe<A, B = never, C = never, D = never, E = never>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E\n): E\nexport function pipe<A, B = never, C = never, D = never, E = never, F = never>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F\n): F\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G\n): G\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H\n): H\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I\n): I\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J\n): J\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K\n): K\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L\n): L\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M\n): M\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N\n): N\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O\n): O\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P\n): P\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q\n): Q\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R\n): R\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => S\n): S\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never,\n T = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => S,\n st: (s: S) => T\n): T\nexport function pipe(\n a: unknown,\n ab?: Function,\n bc?: Function,\n cd?: Function,\n de?: Function,\n ef?: Function,\n fg?: Function,\n gh?: Function,\n hi?: Function\n): unknown {\n switch (arguments.length) {\n case 1:\n return a\n case 2:\n return ab!(a)\n case 3:\n return bc!(ab!(a))\n case 4:\n return cd!(bc!(ab!(a)))\n case 5:\n return de!(cd!(bc!(ab!(a))))\n case 6:\n return ef!(de!(cd!(bc!(ab!(a)))))\n case 7:\n return fg!(ef!(de!(cd!(bc!(ab!(a))))))\n case 8:\n return gh!(fg!(ef!(de!(cd!(bc!(ab!(a)))))))\n case 9:\n return hi!(gh!(fg!(ef!(de!(cd!(bc!(ab!(a))))))))\n default: {\n let ret = arguments[0]\n for (let i = 1; i < arguments.length; i++) {\n ret = arguments[i](ret)\n }\n return ret\n }\n }\n}\n\n/**\n * Performs left-to-right function composition. The first argument may have any arity, the remaining arguments must be unary.\n *\n * See also [`pipe`](#pipe).\n *\n * @example\n * ```ts\n * import { flow } from \"effect/Function\"\n *\n * const len = (s: string): number => s.length\n * const double = (n: number): number => n * 2\n *\n * const f = flow(len, double)\n *\n * assert.strictEqual(f('aaa'), 6)\n * ```\n *\n * @since 2.0.0\n */\nexport function flow<A extends ReadonlyArray<unknown>, B = never>(\n ab: (...a: A) => B\n): (...a: A) => B\nexport function flow<A extends ReadonlyArray<unknown>, B = never, C = never>(\n ab: (...a: A) => B,\n bc: (b: B) => C\n): (...a: A) => C\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never\n>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...a: A) => D\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E\n): (...a: A) => E\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F\n): (...a: A) => F\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G\n): (...a: A) => G\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H\n): (...a: A) => H\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I\n): (...a: A) => I\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J\n): (...a: A) => J\nexport function flow(\n ab: Function,\n bc?: Function,\n cd?: Function,\n de?: Function,\n ef?: Function,\n fg?: Function,\n gh?: Function,\n hi?: Function,\n ij?: Function\n): unknown {\n switch (arguments.length) {\n case 1:\n return ab\n case 2:\n return function(this: unknown) {\n return bc!(ab.apply(this, arguments))\n }\n case 3:\n return function(this: unknown) {\n return cd!(bc!(ab.apply(this, arguments)))\n }\n case 4:\n return function(this: unknown) {\n return de!(cd!(bc!(ab.apply(this, arguments))))\n }\n case 5:\n return function(this: unknown) {\n return ef!(de!(cd!(bc!(ab.apply(this, arguments)))))\n }\n case 6:\n return function(this: unknown) {\n return fg!(ef!(de!(cd!(bc!(ab.apply(this, arguments))))))\n }\n case 7:\n return function(this: unknown) {\n return gh!(fg!(ef!(de!(cd!(bc!(ab.apply(this, arguments)))))))\n }\n case 8:\n return function(this: unknown) {\n return hi!(gh!(fg!(ef!(de!(cd!(bc!(ab.apply(this, arguments))))))))\n }\n case 9:\n return function(this: unknown) {\n return ij!(hi!(gh!(fg!(ef!(de!(cd!(bc!(ab.apply(this, arguments)))))))))\n }\n }\n return\n}\n\n/**\n * Type hole simulation.\n *\n * @since 2.0.0\n */\nexport const hole: <T>() => T = unsafeCoerce(absurd)\n\n/**\n * The SK combinator, also known as the \"S-K combinator\" or \"S-combinator\", is a fundamental combinator in the\n * lambda calculus and the SKI combinator calculus.\n *\n * This function is useful for discarding the first argument passed to it and returning the second argument.\n *\n * @param _ - The first argument to be discarded.\n * @param b - The second argument to be returned.\n *\n * @example\n * ```ts\n * import { SK } from \"effect/Function\";\n *\n * assert.deepStrictEqual(SK(0, \"hello\"), \"hello\")\n * ```\n *\n * @since 2.0.0\n */\nexport const SK = <A, B>(_: A, b: B): B => b\n","let moduleVersion = \"3.12.5\"\n\nexport const getCurrentVersion = () => moduleVersion\n\nexport const setCurrentVersion = (version: string) => {\n moduleVersion = version\n}\n","/**\n * The `GlobalValue` module ensures that a single instance of a value is created globally,\n * even when modules are imported multiple times (e.g., due to mixing CommonJS and ESM builds)\n * or during hot-reloading in development environments like Next.js or Remix.\n *\n * It achieves this by using a versioned global store, identified by a unique `Symbol` tied to\n * the current version of the `effect` library. The store holds values that are keyed by an identifier,\n * allowing the reuse of previously computed instances across imports or reloads.\n *\n * This pattern is particularly useful in scenarios where frequent reloading can cause services or\n * single-instance objects to be recreated unnecessarily, such as in development environments with hot-reloading.\n *\n * @since 2.0.0\n */\nimport * as version from \"./internal/version.js\"\n\nconst globalStoreId = `effect/GlobalValue/globalStoreId/${version.getCurrentVersion()}`\n\nlet globalStore: Map<unknown, any>\n\n/**\n * Retrieves or computes a global value associated with the given `id`. If the value for this `id`\n * has already been computed, it will be returned from the global store. If it does not exist yet,\n * the provided `compute` function will be executed to compute the value, store it, and then return it.\n *\n * This ensures that even in cases where the module is imported multiple times (e.g., in mixed environments\n * like CommonJS and ESM, or during hot-reloading in development), the value is computed only once and reused\n * thereafter.\n *\n * @example\n * ```ts\n * import { globalValue } from \"effect/GlobalValue\"\n *\n * // This cache will persist as long as the module is running,\n * // even if reloaded or imported elsewhere\n * const myCache = globalValue(\n * Symbol.for(\"myCache\"),\n * () => new WeakMap<object, number>()\n * )\n * ```\n *\n * @since 2.0.0\n */\nexport const globalValue = <A>(id: unknown, compute: () => A): A => {\n if (!globalStore) {\n // @ts-expect-error\n globalThis[globalStoreId] ??= new Map()\n // @ts-expect-error\n globalStore = globalThis[globalStoreId] as Map<unknown, any>\n }\n if (!globalStore.has(id)) {\n globalStore.set(id, compute())\n }\n return globalStore.get(id)!\n}\n","/**\n * @since 2.0.0\n */\nimport { dual, isFunction as isFunction_ } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\nimport type { TupleOf, TupleOfAtLeast } from \"./Types.js\"\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Predicate<in A> {\n (a: A): boolean\n}\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface PredicateTypeLambda extends TypeLambda {\n readonly type: Predicate<this[\"Target\"]>\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Refinement<in A, out B extends A> {\n (a: A): a is B\n}\n\n/**\n * @since 3.6.0\n * @category type-level\n */\nexport declare namespace Predicate {\n /**\n * @since 3.6.0\n * @category type-level\n */\n export type In<T extends Any> = [T] extends [Predicate<infer _A>] ? _A : never\n /**\n * @since 3.6.0\n * @category type-level\n */\n export type Any = Predicate<never>\n}\n\n/**\n * @since 3.6.0\n * @category type-level\n */\nexport declare namespace Refinement {\n /**\n * @since 3.6.0\n * @category type-level\n */\n export type In<T extends Any> = [T] extends [Refinement<infer _A, infer _>] ? _A : never\n /**\n * @since 3.6.0\n * @category type-level\n */\n export type Out<T extends Any> = [T] extends [Refinement<infer _, infer _B>] ? _B : never\n /**\n * @since 3.6.0\n * @category type-level\n */\n export type Any = Refinement<any, any>\n}\n\n/**\n * Given a `Predicate<A>` returns a `Predicate<B>`\n *\n * @param self - the `Predicate<A>` to be transformed to `Predicate<B>`.\n * @param f - a function to transform `B` to `A`.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const minLength3 = Predicate.mapInput(Number.greaterThan(2), (s: string) => s.length)\n *\n * assert.deepStrictEqual(minLength3(\"a\"), false)\n * assert.deepStrictEqual(minLength3(\"aa\"), false)\n * assert.deepStrictEqual(minLength3(\"aaa\"), true)\n * assert.deepStrictEqual(minLength3(\"aaaa\"), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const mapInput: {\n /**\n * Given a `Predicate<A>` returns a `Predicate<B>`\n *\n * @param self - the `Predicate<A>` to be transformed to `Predicate<B>`.\n * @param f - a function to transform `B` to `A`.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const minLength3 = Predicate.mapInput(Number.greaterThan(2), (s: string) => s.length)\n *\n * assert.deepStrictEqual(minLength3(\"a\"), false)\n * assert.deepStrictEqual(minLength3(\"aa\"), false)\n * assert.deepStrictEqual(minLength3(\"aaa\"), true)\n * assert.deepStrictEqual(minLength3(\"aaaa\"), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <B, A>(f: (b: B) => A): (self: Predicate<A>) => Predicate<B>\n /**\n * Given a `Predicate<A>` returns a `Predicate<B>`\n *\n * @param self - the `Predicate<A>` to be transformed to `Predicate<B>`.\n * @param f - a function to transform `B` to `A`.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const minLength3 = Predicate.mapInput(Number.greaterThan(2), (s: string) => s.length)\n *\n * assert.deepStrictEqual(minLength3(\"a\"), false)\n * assert.deepStrictEqual(minLength3(\"aa\"), false)\n * assert.deepStrictEqual(minLength3(\"aaa\"), true)\n * assert.deepStrictEqual(minLength3(\"aaaa\"), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A, B>(self: Predicate<A>, f: (b: B) => A): Predicate<B>\n} = dual(2, <A, B>(self: Predicate<A>, f: (b: B) => A): Predicate<B> => (b) => self(f(b)))\n\n/**\n * Determine if an `Array` is a tuple with exactly `N` elements, narrowing down the type to `TupleOf`.\n *\n * An `Array` is considered to be a `TupleOf` if its length is exactly `N`.\n *\n * @param self - The `Array` to check.\n * @param n - The exact number of elements that the `Array` should have to be considered a `TupleOf`.\n *\n * @example\n * ```ts\n * import { isTupleOf } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 3), true);\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 2), false);\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 4), false);\n *\n * const arr: number[] = [1, 2, 3];\n * if (isTupleOf(arr, 3)) {\n * console.log(arr);\n * // ^? [number, number, number]\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\nexport const isTupleOf: {\n /**\n * Determine if an `Array` is a tuple with exactly `N` elements, narrowing down the type to `TupleOf`.\n *\n * An `Array` is considered to be a `TupleOf` if its length is exactly `N`.\n *\n * @param self - The `Array` to check.\n * @param n - The exact number of elements that the `Array` should have to be considered a `TupleOf`.\n *\n * @example\n * ```ts\n * import { isTupleOf } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 3), true);\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 2), false);\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 4), false);\n *\n * const arr: number[] = [1, 2, 3];\n * if (isTupleOf(arr, 3)) {\n * console.log(arr);\n * // ^? [number, number, number]\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\n <N extends number>(n: N): <T>(self: ReadonlyArray<T>) => self is TupleOf<N, T>\n /**\n * Determine if an `Array` is a tuple with exactly `N` elements, narrowing down the type to `TupleOf`.\n *\n * An `Array` is considered to be a `TupleOf` if its length is exactly `N`.\n *\n * @param self - The `Array` to check.\n * @param n - The exact number of elements that the `Array` should have to be considered a `TupleOf`.\n *\n * @example\n * ```ts\n * import { isTupleOf } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 3), true);\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 2), false);\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 4), false);\n *\n * const arr: number[] = [1, 2, 3];\n * if (isTupleOf(arr, 3)) {\n * console.log(arr);\n * // ^? [number, number, number]\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\n <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T>\n} = dual(2, <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T> => self.length === n)\n\n/**\n * Determine if an `Array` is a tuple with at least `N` elements, narrowing down the type to `TupleOfAtLeast`.\n *\n * An `Array` is considered to be a `TupleOfAtLeast` if its length is at least `N`.\n *\n * @param self - The `Array` to check.\n * @param n - The minimum number of elements that the `Array` should have to be considered a `TupleOfAtLeast`.\n *\n * @example\n * ```ts\n * import { isTupleOfAtLeast } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 3), true);\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 2), true);\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 4), false);\n *\n * const arr: number[] = [1, 2, 3, 4];\n * if (isTupleOfAtLeast(arr, 3)) {\n * console.log(arr);\n * // ^? [number, number, number, ...number[]]\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\nexport const isTupleOfAtLeast: {\n /**\n * Determine if an `Array` is a tuple with at least `N` elements, narrowing down the type to `TupleOfAtLeast`.\n *\n * An `Array` is considered to be a `TupleOfAtLeast` if its length is at least `N`.\n *\n * @param self - The `Array` to check.\n * @param n - The minimum number of elements that the `Array` should have to be considered a `TupleOfAtLeast`.\n *\n * @example\n * ```ts\n * import { isTupleOfAtLeast } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 3), true);\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 2), true);\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 4), false);\n *\n * const arr: number[] = [1, 2, 3, 4];\n * if (isTupleOfAtLeast(arr, 3)) {\n * console.log(arr);\n * // ^? [number, number, number, ...number[]]\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\n <N extends number>(n: N): <T>(self: ReadonlyArray<T>) => self is TupleOfAtLeast<N, T>\n /**\n * Determine if an `Array` is a tuple with at least `N` elements, narrowing down the type to `TupleOfAtLeast`.\n *\n * An `Array` is considered to be a `TupleOfAtLeast` if its length is at least `N`.\n *\n * @param self - The `Array` to check.\n * @param n - The minimum number of elements that the `Array` should have to be considered a `TupleOfAtLeast`.\n *\n * @example\n * ```ts\n * import { isTupleOfAtLeast } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 3), true);\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 2), true);\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 4), false);\n *\n * const arr: number[] = [1, 2, 3, 4];\n * if (isTupleOfAtLeast(arr, 3)) {\n * console.log(arr);\n * // ^? [number, number, number, ...number[]]\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\n <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOfAtLeast<N, T>\n} = dual(2, <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOfAtLeast<N, T> => self.length >= n)\n\n/**\n * Tests if a value is `truthy`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isTruthy } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTruthy(1), true)\n * assert.deepStrictEqual(isTruthy(0), false)\n * assert.deepStrictEqual(isTruthy(\"\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isTruthy = (input: unknown) => !!input\n\n/**\n * Tests if a value is a `Set`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isSet } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isSet(new Set([1, 2])), true)\n * assert.deepStrictEqual(isSet(new Set()), true)\n * assert.deepStrictEqual(isSet({}), false)\n * assert.deepStrictEqual(isSet(null), false)\n * assert.deepStrictEqual(isSet(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isSet = (input: unknown): input is Set<unknown> => input instanceof Set\n\n/**\n * Tests if a value is a `Map`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isMap } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isMap(new Map()), true)\n * assert.deepStrictEqual(isMap({}), false)\n * assert.deepStrictEqual(isMap(null), false)\n * assert.deepStrictEqual(isMap(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isMap = (input: unknown): input is Map<unknown, unknown> => input instanceof Map\n\n/**\n * Tests if a value is a `string`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isString } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isString(\"a\"), true)\n *\n * assert.deepStrictEqual(isString(1), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isString = (input: unknown): input is string => typeof input === \"string\"\n\n/**\n * Tests if a value is a `number`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isNumber } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNumber(2), true)\n *\n * assert.deepStrictEqual(isNumber(\"2\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNumber = (input: unknown): input is number => typeof input === \"number\"\n\n/**\n * Tests if a value is a `boolean`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isBoolean } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isBoolean(true), true)\n *\n * assert.deepStrictEqual(isBoolean(\"true\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isBoolean = (input: unknown): input is boolean => typeof input === \"boolean\"\n\n/**\n * Tests if a value is a `bigint`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isBigInt } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isBigInt(1n), true)\n *\n * assert.deepStrictEqual(isBigInt(1), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isBigInt = (input: unknown): input is bigint => typeof input === \"bigint\"\n\n/**\n * Tests if a value is a `symbol`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isSymbol } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isSymbol(Symbol.for(\"a\")), true)\n *\n * assert.deepStrictEqual(isSymbol(\"a\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isSymbol = (input: unknown): input is symbol => typeof input === \"symbol\"\n\n/**\n * Tests if a value is a `function`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isFunction } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isFunction(isFunction), true)\n *\n * assert.deepStrictEqual(isFunction(\"function\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isFunction: (input: unknown) => input is Function = isFunction_\n\n/**\n * Tests if a value is `undefined`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isUndefined } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isUndefined(undefined), true)\n *\n * assert.deepStrictEqual(isUndefined(null), false)\n * assert.deepStrictEqual(isUndefined(\"undefined\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isUndefined = (input: unknown): input is undefined => input === undefined\n\n/**\n * Tests if a value is not `undefined`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isNotUndefined } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNotUndefined(null), true)\n * assert.deepStrictEqual(isNotUndefined(\"undefined\"), true)\n *\n * assert.deepStrictEqual(isNotUndefined(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNotUndefined = <A>(input: A): input is Exclude<A, undefined> => input !== undefined\n\n/**\n * Tests if a value is `null`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isNull } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNull(null), true)\n *\n * assert.deepStrictEqual(isNull(undefined), false)\n * assert.deepStrictEqual(isNull(\"null\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNull = (input: unknown): input is null => input === null\n\n/**\n * Tests if a value is not `null`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isNotNull } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNotNull(undefined), true)\n * assert.deepStrictEqual(isNotNull(\"null\"), true)\n *\n * assert.deepStrictEqual(isNotNull(null), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNotNull = <A>(input: A): input is Exclude<A, null> => input !== null\n\n/**\n * A guard that always fails.\n *\n * @param _ - The value to test.\n *\n * @example\n * ```ts\n * import { isNever } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNever(null), false)\n * assert.deepStrictEqual(isNever(undefined), false)\n * assert.deepStrictEqual(isNever({}), false)\n * assert.deepStrictEqual(isNever([]), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNever: (input: unknown) => input is never = (_: unknown): _ is never => false\n\n/**\n * A guard that always succeeds.\n *\n * @param _ - The value to test.\n *\n * @example\n * ```ts\n * import { isUnknown } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isUnknown(null), true)\n * assert.deepStrictEqual(isUnknown(undefined), true)\n *\n * assert.deepStrictEqual(isUnknown({}), true)\n * assert.deepStrictEqual(isUnknown([]), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isUnknown: (input: unknown) => input is unknown = (_): _ is unknown => true\n\n/** @internal */\nexport const isRecordOrArray = (input: unknown): input is { [x: PropertyKey]: unknown } =>\n typeof input === \"object\" && input !== null\n\n/**\n * Tests if a value is an `object`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isObject } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isObject({}), true)\n * assert.deepStrictEqual(isObject([]), true)\n *\n * assert.deepStrictEqual(isObject(null), false)\n * assert.deepStrictEqual(isObject(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isObject = (input: unknown): input is object => isRecordOrArray(input) || isFunction(input)\n\n/**\n * Checks whether a value is an `object` containing a specified property key.\n *\n * @param property - The field to check within the object.\n * @param self - The value to examine.\n *\n * @category guards\n * @since 2.0.0\n */\nexport const hasProperty: {\n /**\n * Checks whether a value is an `object` containing a specified property key.\n *\n * @param property - The field to check within the object.\n * @param self - The value to examine.\n *\n * @category guards\n * @since 2.0.0\n */\n <P extends PropertyKey>(property: P): (self: unknown) => self is { [K in P]: unknown }\n /**\n * Checks whether a value is an `object` containing a specified property key.\n *\n * @param property - The field to check within the object.\n * @param self - The value to examine.\n *\n * @category guards\n * @since 2.0.0\n */\n <P extends PropertyKey>(self: unknown, property: P): self is { [K in P]: unknown }\n} = dual(\n 2,\n <P extends PropertyKey>(self: unknown, property: P): self is { [K in P]: unknown } =>\n isObject(self) && (property in self)\n)\n\n/**\n * Tests if a value is an `object` with a property `_tag` that matches the given tag.\n *\n * @param input - The value to test.\n * @param tag - The tag to test for.\n *\n * @example\n * ```ts\n * import { isTagged } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTagged(1, \"a\"), false)\n * assert.deepStrictEqual(isTagged(null, \"a\"), false)\n * assert.deepStrictEqual(isTagged({}, \"a\"), false)\n * assert.deepStrictEqual(isTagged({ a: \"a\" }, \"a\"), false)\n * assert.deepStrictEqual(isTagged({ _tag: \"a\" }, \"a\"), true)\n * assert.deepStrictEqual(isTagged(\"a\")({ _tag: \"a\" }), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isTagged: {\n /**\n * Tests if a value is an `object` with a property `_tag` that matches the given tag.\n *\n * @param input - The value to test.\n * @param tag - The tag to test for.\n *\n * @example\n * ```ts\n * import { isTagged } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTagged(1, \"a\"), false)\n * assert.deepStrictEqual(isTagged(null, \"a\"), false)\n * assert.deepStrictEqual(isTagged({}, \"a\"), false)\n * assert.deepStrictEqual(isTagged({ a: \"a\" }, \"a\"), false)\n * assert.deepStrictEqual(isTagged({ _tag: \"a\" }, \"a\"), true)\n * assert.deepStrictEqual(isTagged(\"a\")({ _tag: \"a\" }), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\n <K extends string>(tag: K): (self: unknown) => self is { _tag: K }\n /**\n * Tests if a value is an `object` with a property `_tag` that matches the given tag.\n *\n * @param input - The value to test.\n * @param tag - The tag to test for.\n *\n * @example\n * ```ts\n * import { isTagged } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTagged(1, \"a\"), false)\n * assert.deepStrictEqual(isTagged(null, \"a\"), false)\n * assert.deepStrictEqual(isTagged({}, \"a\"), false)\n * assert.deepStrictEqual(isTagged({ a: \"a\" }, \"a\"), false)\n * assert.deepStrictEqual(isTagged({ _tag: \"a\" }, \"a\"), true)\n * assert.deepStrictEqual(isTagged(\"a\")({ _tag: \"a\" }), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\n <K extends string>(self: unknown, tag: K): self is { _tag: K }\n} = dual(\n 2,\n <K extends string>(self: unknown, tag: K): self is { _tag: K } => hasProperty(self, \"_tag\") && self[\"_tag\"] === tag\n)\n\n/**\n * A guard that succeeds when the input is `null` or `undefined`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isNullable } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNullable(null), true)\n * assert.deepStrictEqual(isNullable(undefined), true)\n *\n * assert.deepStrictEqual(isNullable({}), false)\n * assert.deepStrictEqual(isNullable([]), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNullable = <A>(input: A): input is Extract<A, null | undefined> => input === null || input === undefined\n\n/**\n * A guard that succeeds when the input is not `null` or `undefined`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isNotNullable } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNotNullable({}), true)\n * assert.deepStrictEqual(isNotNullable([]), true)\n *\n * assert.deepStrictEqual(isNotNullable(null), false)\n * assert.deepStrictEqual(isNotNullable(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNotNullable = <A>(input: A): input is NonNullable<A> => input !== null && input !== undefined\n\n/**\n * A guard that succeeds when the input is an `Error`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isError } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isError(new Error()), true)\n *\n * assert.deepStrictEqual(isError(null), false)\n * assert.deepStrictEqual(isError({}), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isError = (input: unknown): input is Error => input instanceof Error\n\n/**\n * A guard that succeeds when the input is a `Uint8Array`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isUint8Array } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isUint8Array(new Uint8Array()), true)\n *\n * assert.deepStrictEqual(isUint8Array(null), false)\n * assert.deepStrictEqual(isUint8Array({}), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isUint8Array = (input: unknown): input is Uint8Array => input instanceof Uint8Array\n\n/**\n * A guard that succeeds when the input is a `Date`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isDate } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isDate(new Date()), true)\n *\n * assert.deepStrictEqual(isDate(null), false)\n * assert.deepStrictEqual(isDate({}), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isDate = (input: unknown): input is Date => input instanceof Date\n\n/**\n * A guard that succeeds when the input is an `Iterable`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isIterable } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isIterable([]), true)\n * assert.deepStrictEqual(isIterable(new Set()), true)\n *\n * assert.deepStrictEqual(isIterable(null), false)\n * assert.deepStrictEqual(isIterable({}), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isIterable = (input: unknown): input is Iterable<unknown> => hasProperty(input, Symbol.iterator)\n\n/**\n * A guard that succeeds when the input is a record.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isRecord } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isRecord({}), true)\n * assert.deepStrictEqual(isRecord({ a: 1 }), true)\n *\n * assert.deepStrictEqual(isRecord([]), false)\n * assert.deepStrictEqual(isRecord([1, 2, 3]), false)\n * assert.deepStrictEqual(isRecord(null), false)\n * assert.deepStrictEqual(isRecord(undefined), false)\n * assert.deepStrictEqual(isRecord(() => null), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isRecord = (input: unknown): input is { [x: string | symbol]: unknown } =>\n isRecordOrArray(input) && !Array.isArray(input)\n\n/**\n * A guard that succeeds when the input is a readonly record.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isReadonlyRecord } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isReadonlyRecord({}), true)\n * assert.deepStrictEqual(isReadonlyRecord({ a: 1 }), true)\n *\n * assert.deepStrictEqual(isReadonlyRecord([]), false)\n * assert.deepStrictEqual(isReadonlyRecord([1, 2, 3]), false)\n * assert.deepStrictEqual(isReadonlyRecord(null), false)\n * assert.deepStrictEqual(isReadonlyRecord(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isReadonlyRecord: (\n input: unknown\n) => input is { readonly [x: string | symbol]: unknown } = isRecord\n\n/**\n * A guard that succeeds when the input is a Promise.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isPromise } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isPromise({}), false)\n * assert.deepStrictEqual(isPromise(Promise.resolve(\"hello\")), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isPromise = (\n input: unknown\n): input is Promise<unknown> =>\n hasProperty(input, \"then\") && \"catch\" in input && isFunction(input.then) && isFunction(input.catch)\n\n/**\n * @category guards\n * @since 2.0.0\n */\nexport const isPromiseLike = (\n input: unknown\n): input is PromiseLike<unknown> => hasProperty(input, \"then\") && isFunction(input.then)\n\n/**\n * Tests if a value is a `RegExp`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * assert.deepStrictEqual(Predicate.isRegExp(/a/), true)\n * assert.deepStrictEqual(Predicate.isRegExp(\"a\"), false)\n * ```\n *\n * @category guards\n * @since 3.9.0\n */\nexport const isRegExp = (input: unknown): input is RegExp => input instanceof RegExp\n\n/**\n * @since 2.0.0\n */\nexport const compose: {\n /**\n * @since 2.0.0\n */\n <A, B extends A, C extends B>(bc: Refinement<B, C>): (ab: Refinement<A, B>) => Refinement<A, C>\n /**\n * @since 2.0.0\n */\n <A, B extends A>(bc: Predicate<NoInfer<B>>): (ab: Refinement<A, B>) => Refinement<A, B>\n /**\n * @since 2.0.0\n */\n <A, B extends A, C extends B>(ab: Refinement<A, B>, bc: Refinement<B, C>): Refinement<A, C>\n /**\n * @since 2.0.0\n */\n <A, B extends A>(ab: Refinement<A, B>, bc: Predicate<NoInfer<B>>): Refinement<A, B>\n} = dual(\n 2,\n <A, B extends A, C extends B>(ab: Refinement<A, B>, bc: Refinement<B, C>): Refinement<A, C> => (a): a is C =>\n ab(a) && bc(a)\n)\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const product =\n <A, B>(self: Predicate<A>, that: Predicate<B>): Predicate<readonly [A, B]> /* readonly because contravariant */ =>\n ([a, b]) => self(a) && that(b)\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const all = <A>(\n collection: Iterable<Predicate<A>>\n): Predicate<ReadonlyArray<A>> => {\n return (as) => {\n let collectionIndex = 0\n for (const p of collection) {\n if (collectionIndex >= as.length) {\n break\n }\n if (p(as[collectionIndex]) === false) {\n return false\n }\n collectionIndex++\n }\n return true\n }\n}\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const productMany = <A>(\n self: Predicate<A>,\n collection: Iterable<Predicate<A>>\n): Predicate<readonly [A, ...Array<A>]> /* readonly because contravariant */ => {\n const rest = all(collection)\n return ([head, ...tail]) => self(head) === false ? false : rest(tail)\n}\n\n/**\n * Similar to `Promise.all` but operates on `Predicate`s.\n *\n * ```\n * [Refinement<A, B>, Refinement<C, D>, ...] -> Refinement<[A, C, ...], [B, D, ...]>\n * [Predicate<A>, Predicate<B>, ...] -> Predicate<[A, B, ...]>\n * [Refinement<A, B>, Predicate<C>, ...] -> Refinement<[A, C, ...], [B, C, ...]>\n * ```\n *\n * @since 2.0.0\n */\nexport const tuple: {\n /**\n * Similar to `Promise.all` but operates on `Predicate`s.\n *\n * ```\n * [Refinement<A, B>, Refinement<C, D>, ...] -> Refinement<[A, C, ...], [B, D, ...]>\n * [Predicate<A>, Predicate<B>, ...] -> Predicate<[A, B, ...]>\n * [Refinement<A, B>, Predicate<C>, ...] -> Refinement<[A, C, ...], [B, C, ...]>\n * ```\n *\n * @since 2.0.0\n */\n <T extends ReadonlyArray<Predicate.Any>>(\n ...elements: T\n ): [Extract<T[number], Refinement.Any>] extends [never] ? Predicate<{ readonly [I in keyof T]: Predicate.In<T[I]> }>\n : Refinement<\n { readonly [I in keyof T]: T[I] extends Refinement.Any ? Refinement.In<T[I]> : Predicate.In<T[I]> },\n { readonly [I in keyof T]: T[I] extends Refinement.Any ? Refinement.Out<T[I]> : Predicate.In<T[I]> }\n >\n} = (...elements: ReadonlyArray<Predicate.Any>) => all(elements) as any\n\n/**\n * ```\n * { ab: Refinement<A, B>; cd: Refinement<C, D>, ... } -> Refinement<{ ab: A; cd: C; ... }, { ab: B; cd: D; ... }>\n * { a: Predicate<A, B>; b: Predicate<B>, ... } -> Predicate<{ a: A; b: B; ... }>\n * { ab: Refinement<A, B>; c: Predicate<C>, ... } -> Refinement<{ ab: A; c: C; ... }, { ab: B; c: С; ... }>\n * ```\n *\n * @since 2.0.0\n */\nexport const struct: {\n /**\n * ```\n * { ab: Refinement<A, B>; cd: Refinement<C, D>, ... } -> Refinement<{ ab: A; cd: C; ... }, { ab: B; cd: D; ... }>\n * { a: Predicate<A, B>; b: Predicate<B>, ... } -> Predicate<{ a: A; b: B; ... }>\n * { ab: Refinement<A, B>; c: Predicate<C>, ... } -> Refinement<{ ab: A; c: C; ... }, { ab: B; c: С; ... }>\n * ```\n *\n * @since 2.0.0\n */\n <R extends Record<string, Predicate.Any>>(\n fields: R\n ): [Extract<R[keyof R], Refinement.Any>] extends [never] ?\n Predicate<{ readonly [K in keyof R]: Predicate.In<R[K]> }> :\n Refinement<\n { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.In<R[K]> : Predicate.In<R[K]> },\n { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.Out<R[K]> : Predicate.In<R[K]> }\n >\n} = (<R extends Record<string, Predicate.Any>>(fields: R) => {\n const keys = Object.keys(fields)\n return (a: Record<string, unknown>) => {\n for (const key of keys) {\n if (!fields[key](a[key] as never)) {\n return false\n }\n }\n return true\n }\n}) as any\n\n/**\n * Negates the result of a given predicate.\n *\n * @param self - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const isPositive = Predicate.not(Number.lessThan(0))\n *\n * assert.deepStrictEqual(isPositive(-1), false)\n * assert.deepStrictEqual(isPositive(0), true)\n * assert.deepStrictEqual(isPositive(1), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const not = <A>(self: Predicate<A>): Predicate<A> => (a) => !self(a)\n\n/**\n * Combines two predicates into a new predicate that returns `true` if at least one of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const nonZero = Predicate.or(Number.lessThan(0), Number.greaterThan(0))\n *\n * assert.deepStrictEqual(nonZero(-1), true)\n * assert.deepStrictEqual(nonZero(0), false)\n * assert.deepStrictEqual(nonZero(1), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const or: {\n /**\n * Combines two predicates into a new predicate that returns `true` if at least one of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const nonZero = Predicate.or(Number.lessThan(0), Number.greaterThan(0))\n *\n * assert.deepStrictEqual(nonZero(-1), true)\n * assert.deepStrictEqual(nonZero(0), false)\n * assert.deepStrictEqual(nonZero(1), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A, C extends A>(that: Refinement<A, C>): <B extends A>(self: Refinement<A, B>) => Refinement<A, B | C>\n /**\n * Combines two predicates into a new predicate that returns `true` if at least one of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const nonZero = Predicate.or(Number.lessThan(0), Number.greaterThan(0))\n *\n * assert.deepStrictEqual(nonZero(-1), true)\n * assert.deepStrictEqual(nonZero(0), false)\n * assert.deepStrictEqual(nonZero(1), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A, B extends A, C extends A>(self: Refinement<A, B>, that: Refinement<A, C>): Refinement<A, B | C>\n /**\n * Combines two predicates into a new predicate that returns `true` if at least one of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const nonZero = Predicate.or(Number.lessThan(0), Number.greaterThan(0))\n *\n * assert.deepStrictEqual(nonZero(-1), true)\n * assert.deepStrictEqual(nonZero(0), false)\n * assert.deepStrictEqual(nonZero(1), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>\n /**\n * Combines two predicates into a new predicate that returns `true` if at least one of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const nonZero = Predicate.or(Number.lessThan(0), Number.greaterThan(0))\n *\n * assert.deepStrictEqual(nonZero(-1), true)\n * assert.deepStrictEqual(nonZero(0), false)\n * assert.deepStrictEqual(nonZero(1), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>\n} = dual(2, <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => self(a) || that(a))\n\n/**\n * Combines two predicates into a new predicate that returns `true` if both of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * const minLength = (n: number) => (s: string) => s.length >= n\n * const maxLength = (n: number) => (s: string) => s.length <= n\n *\n * const length = (n: number) => Predicate.and(minLength(n), maxLength(n))\n *\n * assert.deepStrictEqual(length(2)(\"aa\"), true)\n * assert.deepStrictEqual(length(2)(\"a\"), false)\n * assert.deepStrictEqual(length(2)(\"aaa\"), false)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const and: {\n /**\n * Combines two predicates into a new predicate that returns `true` if both of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * const minLength = (n: number) => (s: string) => s.length >= n\n * const maxLength = (n: number) => (s: string) => s.length <= n\n *\n * const length = (n: number) => Predicate.and(minLength(n), maxLength(n))\n *\n * assert.deepStrictEqual(length(2)(\"aa\"), true)\n * assert.deepStrictEqual(length(2)(\"a\"), false)\n * assert.deepStrictEqual(length(2)(\"aaa\"), false)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A, C extends A>(that: Refinement<A, C>): <B extends A>(self: Refinement<A, B>) => Refinement<A, B & C>\n /**\n * Combines two predicates into a new predicate that returns `true` if both of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * const minLength = (n: number) => (s: string) => s.length >= n\n * const maxLength = (n: number) => (s: string) => s.length <= n\n *\n * const length = (n: number) => Predicate.and(minLength(n), maxLength(n))\n *\n * assert.deepStrictEqual(length(2)(\"aa\"), true)\n * assert.deepStrictEqual(length(2)(\"a\"), false)\n * assert.deepStrictEqual(length(2)(\"aaa\"), false)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A, B extends A, C extends A>(self: Refinement<A, B>, that: Refinement<A, C>): Refinement<A, B & C>\n /**\n * Combines two predicates into a new predicate that returns `true` if both of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * const minLength = (n: number) => (s: string) => s.length >= n\n * const maxLength = (n: number) => (s: string) => s.length <= n\n *\n * const length = (n: number) => Predicate.and(minLength(n), maxLength(n))\n *\n * assert.deepStrictEqual(length(2)(\"aa\"), true)\n * assert.deepStrictEqual(length(2)(\"a\"), false)\n * assert.deepStrictEqual(length(2)(\"aaa\"), false)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>\n /**\n * Combines two predicates into a new predicate that returns `true` if both of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * const minLength = (n: number) => (s: string) => s.length >= n\n * const maxLength = (n: number) => (s: string) => s.length <= n\n *\n * const length = (n: number) => Predicate.and(minLength(n), maxLength(n))\n *\n * assert.deepStrictEqual(length(2)(\"aa\"), true)\n * assert.deepStrictEqual(length(2)(\"a\"), false)\n * assert.deepStrictEqual(length(2)(\"aaa\"), false)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>\n} = dual(2, <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => self(a) && that(a))\n\n/**\n * @category combinators\n * @since 2.0.0\n */\nexport const xor: {\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>\n} = dual(2, <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => self(a) !== that(a))\n\n/**\n * @category combinators\n * @since 2.0.0\n */\nexport const eqv: {\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>\n} = dual(2, <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => self(a) === that(a))\n\n/**\n * Represents the logical implication combinator for predicates. In formal\n * logic, the implication operator `->` denotes that if the first proposition\n * (antecedent) is true, then the second proposition (consequent) must also be\n * true. In simpler terms, `p implies q` can be interpreted as \"if p then q\". If\n * the first predicate holds, then the second predicate must hold\n * for the given context.\n *\n * In practical terms within TypeScript, `p implies q` is equivalent to `!p || (p && q)`.\n *\n * Note that if the antecedent is `false`, the result is `true` by default\n * because the outcome of the consequent cannot be determined.\n *\n * This function is useful in situations where you need to enforce rules or\n * constraints that are contingent on certain conditions.\n * It proves especially helpful in defining property tests.\n *\n * The example below illustrates the transitive property of order using the\n * `implies` function. In simple terms, if `a <= b` and `b <= c`, then `a <= c`\n * must be true.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * type Triple = {\n * readonly a: number\n * readonly b: number\n * readonly c: number\n * }\n *\n * const transitivity = Predicate.implies(\n * // antecedent\n * (input: Triple) => input.a <= input.b && input.b <= input.c,\n * // consequent\n * (input: Triple) => input.a <= input.c\n * )\n *\n * assert.equal(transitivity({ a: 1, b: 2, c: 3 }), true)\n * // antecedent is `false`, so the result is `true`\n * assert.equal(transitivity({ a: 1, b: 0, c: 0 }), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const implies: {\n /**\n * Represents the logical implication combinator for predicates. In formal\n * logic, the implication operator `->` denotes that if the first proposition\n * (antecedent) is true, then the second proposition (consequent) must also be\n * true. In simpler terms, `p implies q` can be interpreted as \"if p then q\". If\n * the first predicate holds, then the second predicate must hold\n * for the given context.\n *\n * In practical terms within TypeScript, `p implies q` is equivalent to `!p || (p && q)`.\n *\n * Note that if the antecedent is `false`, the result is `true` by default\n * because the outcome of the consequent cannot be determined.\n *\n * This function is useful in situations where you need to enforce rules or\n * constraints that are contingent on certain conditions.\n * It proves especially helpful in defining property tests.\n *\n * The example below illustrates the transitive property of order using the\n * `implies` function. In simple terms, if `a <= b` and `b <= c`, then `a <= c`\n * must be true.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * type Triple = {\n * readonly a: number\n * readonly b: number\n * readonly c: number\n * }\n *\n * const transitivity = Predicate.implies(\n * // antecedent\n * (input: Triple) => input.a <= input.b && input.b <= input.c,\n * // consequent\n * (input: Triple) => input.a <= input.c\n * )\n *\n * assert.equal(transitivity({ a: 1, b: 2, c: 3 }), true)\n * // antecedent is `false`, so the result is `true`\n * assert.equal(transitivity({ a: 1, b: 0, c: 0 }), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A>(consequent: Predicate<A>): (antecedent: Predicate<A>) => Predicate<A>\n /**\n * Represents the logical implication combinator for predicates. In formal\n * logic, the implication operator `->` denotes that if the first proposition\n * (antecedent) is true, then the second proposition (consequent) must also be\n * true. In simpler terms, `p implies q` can be interpreted as \"if p then q\". If\n * the first predicate holds, then the second predicate must hold\n * for the given context.\n *\n * In practical terms within TypeScript, `p implies q` is equivalent to `!p || (p && q)`.\n *\n * Note that if the antecedent is `false`, the result is `true` by default\n * because the outcome of the consequent cannot be determined.\n *\n * This function is useful in situations where you need to enforce rules or\n * constraints that are contingent on certain conditions.\n * It proves especially helpful in defining property tests.\n *\n * The example below illustrates the transitive property of order using the\n * `implies` function. In simple terms, if `a <= b` and `b <= c`, then `a <= c`\n * must be true.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * type Triple = {\n * readonly a: number\n * readonly b: number\n * readonly c: number\n * }\n *\n * const transitivity = Predicate.implies(\n * // antecedent\n * (input: Triple) => input.a <= input.b && input.b <= input.c,\n * // consequent\n * (input: Triple) => input.a <= input.c\n * )\n *\n * assert.equal(transitivity({ a: 1, b: 2, c: 3 }), true)\n * // antecedent is `false`, so the result is `true`\n * assert.equal(transitivity({ a: 1, b: 0, c: 0 }), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A>(antecedent: Predicate<A>, consequent: Predicate<A>): Predicate<A>\n} = dual(\n 2,\n <A>(antecedent: Predicate<A>, consequent: Predicate<A>): Predicate<A> => (a) => antecedent(a) ? consequent(a) : true\n)\n\n/**\n * @category combinators\n * @since 2.0.0\n */\nexport const nor: {\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>\n} = dual(\n 2,\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => !(self(a) || that(a))\n)\n\n/**\n * @category combinators\n * @since 2.0.0\n */\nexport const nand: {\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>\n} = dual(\n 2,\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => !(self(a) && that(a))\n)\n\n/**\n * @category elements\n * @since 2.0.0\n */\nexport const every = <A>(collection: Iterable<Predicate<A>>): Predicate<A> => (a: A) => {\n for (const p of collection) {\n if (!p(a)) {\n return false\n }\n }\n return true\n}\n\n/**\n * @category elements\n * @since 2.0.0\n */\nexport const some = <A>(collection: Iterable<Predicate<A>>): Predicate<A> => (a) => {\n for (const p of collection) {\n if (p(a)) {\n return true\n }\n }\n return false\n}\n","/**\n * @since 2.0.0\n */\n\n/** @internal */\nexport const getBugErrorMessage = (message: string) =>\n `BUG: ${message} - please report an issue at https://github.com/Effect-TS/effect/issues`\n","/**\n * @since 2.0.0\n */\nimport { identity } from \"./Function.js\"\nimport { globalValue } from \"./GlobalValue.js\"\nimport type { Kind, TypeLambda } from \"./HKT.js\"\nimport { getBugErrorMessage } from \"./internal/errors.js\"\nimport { isNullable, isObject } from \"./Predicate.js\"\nimport type * as Types from \"./Types.js\"\n\n/*\n * Copyright 2014 Thom Chiovoloni, released under the MIT license.\n *\n * A random number generator based on the basic implementation of the PCG algorithm,\n * as described here: http://www.pcg-random.org/\n *\n * Adapted for TypeScript from Thom's original code at https://github.com/thomcc/pcg-random\n *\n * forked from https://github.com/frptools\n *\n * @since 2.0.0\n */\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport const GenKindTypeId: unique symbol = Symbol.for(\"effect/Gen/GenKind\")\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport type GenKindTypeId = typeof GenKindTypeId\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface GenKind<F extends TypeLambda, R, O, E, A> extends Variance<F, R, O, E> {\n readonly value: Kind<F, R, O, E, A>\n\n [Symbol.iterator](): IterableIterator<GenKind<F, R, O, E, A>, A>\n}\n\n/**\n * @category predicates\n * @since 3.0.6\n */\nexport const isGenKind = (u: unknown): u is GenKind<any, any, any, any, any> => isObject(u) && GenKindTypeId in u\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport class GenKindImpl<F extends TypeLambda, R, O, E, A> implements GenKind<F, R, O, E, A> {\n constructor(\n /**\n * @since 2.0.0\n */\n readonly value: Kind<F, R, O, E, A>\n ) {}\n\n /**\n * @since 2.0.0\n */\n get _F() {\n return identity\n }\n\n /**\n * @since 2.0.0\n */\n get _R() {\n return (_: R) => _\n }\n\n /**\n * @since 2.0.0\n */\n get _O() {\n return (_: never): O => _\n }\n\n /**\n * @since 2.0.0\n */\n get _E() {\n return (_: never): E => _\n }\n\n /**\n * @since 2.0.0\n */\n readonly [GenKindTypeId]: typeof GenKindTypeId = GenKindTypeId;\n\n /**\n * @since 2.0.0\n */\n [Symbol.iterator](): IterableIterator<GenKind<F, R, O, E, A>, A> {\n return new SingleShotGen<GenKind<F, R, O, E, A>, A>(this as any)\n }\n}\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport class SingleShotGen<T, A> implements IterableIterator<T, A> {\n private called = false\n\n constructor(readonly self: T) {}\n\n /**\n * @since 2.0.0\n */\n next(a: A): IteratorResult<T, A> {\n return this.called ?\n ({\n value: a,\n done: true\n }) :\n (this.called = true,\n ({\n value: this.self,\n done: false\n }))\n }\n\n /**\n * @since 2.0.0\n */\n return(a: A): IteratorResult<T, A> {\n return ({\n value: a,\n done: true\n })\n }\n\n /**\n * @since 2.0.0\n */\n throw(e: unknown): IteratorResult<T, A> {\n throw e\n }\n\n /**\n * @since 2.0.0\n */\n [Symbol.iterator](): IterableIterator<T, A> {\n return new SingleShotGen<T, A>(this.self)\n }\n}\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const makeGenKind = <F extends TypeLambda, R, O, E, A>(\n kind: Kind<F, R, O, E, A>\n): GenKind<F, R, O, E, A> => new GenKindImpl(kind)\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Variance<in out F extends TypeLambda, in R, out O, out E> {\n readonly [GenKindTypeId]: GenKindTypeId\n readonly _F: Types.Invariant<F>\n readonly _R: Types.Contravariant<R>\n readonly _O: Types.Covariant<O>\n readonly _E: Types.Covariant<E>\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Gen<F extends TypeLambda, Z> {\n <Self, K extends Variance<F, any, any, any> | YieldWrap<Kind<F, any, any, any, any>>, A>(\n ...args:\n | [\n self: Self,\n body: (this: Self, resume: Z) => Generator<K, A, never>\n ]\n | [\n body: (resume: Z) => Generator<K, A, never>\n ]\n ): Kind<\n F,\n [K] extends [Variance<F, infer R, any, any>] ? R\n : [K] extends [YieldWrap<Kind<F, infer R, any, any, any>>] ? R\n : never,\n [K] extends [Variance<F, any, infer O, any>] ? O\n : [K] extends [YieldWrap<Kind<F, any, infer O, any, any>>] ? O\n : never,\n [K] extends [Variance<F, any, any, infer E>] ? E\n : [K] extends [YieldWrap<Kind<F, any, any, infer E, any>>] ? E\n : never,\n A\n >\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Adapter<Z extends TypeLambda> {\n <_R, _O, _E, _A>(\n self: Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, _R, _O, _E, _A>(a: A, ab: (a: A) => Kind<Z, _R, _O, _E, _A>): GenKind<Z, _R, _O, _E, _A>\n <A, B, _R, _O, _E, _A>(a: A, ab: (a: A) => B, bc: (b: B) => Kind<Z, _R, _O, _E, _A>): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: F) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (g: H) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => S,\n st: (s: S) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => S,\n st: (s: S) => T,\n tu: (s: T) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n}\n\n/**\n * @category adapters\n * @since 2.0.0\n */\nexport const adapter: <F extends TypeLambda>() => Adapter<F> = () => (function() {\n let x = arguments[0]\n for (let i = 1; i < arguments.length; i++) {\n x = arguments[i](x)\n }\n return new GenKindImpl(x) as any\n})\n\nconst defaultIncHi = 0x14057b7e\nconst defaultIncLo = 0xf767814f\nconst MUL_HI = 0x5851f42d >>> 0\nconst MUL_LO = 0x4c957f2d >>> 0\nconst BIT_53 = 9007199254740992.0\nconst BIT_27 = 134217728.0\n\n/**\n * @category model\n * @since 2.0.0\n */\nexport type PCGRandomState = [number, number, number, number]\n\n/**\n * @category model\n * @since 2.0.0\n */\nexport type OptionalNumber = number | null | undefined\n\n/**\n * PCG is a family of simple fast space-efficient statistically good algorithms\n * for random number generation. Unlike many general-purpose RNGs, they are also\n * hard to predict.\n *\n * @category model\n * @since 2.0.0\n */\nexport class PCGRandom {\n private _state!: Int32Array\n\n /**\n * Creates an instance of PCGRandom.\n *\n * @param seed - The low 32 bits of the seed (0 is used for high 32 bits).\n *\n * @memberOf PCGRandom\n */\n constructor(seed?: OptionalNumber)\n /**\n * Creates an instance of PCGRandom.\n *\n * @param seedHi - The high 32 bits of the seed.\n * @param seedLo - The low 32 bits of the seed.\n * @param inc - The low 32 bits of the incrementer (0 is used for high 32 bits).\n *\n * @memberOf PCGRandom\n */\n constructor(seedHi: OptionalNumber, seedLo: OptionalNumber, inc?: OptionalNumber)\n /**\n * Creates an instance of PCGRandom.\n *\n * @param seedHi - The high 32 bits of the seed.\n * @param seedLo - The low 32 bits of the seed.\n * @param incHi - The high 32 bits of the incrementer.\n * @param incLo - The low 32 bits of the incrementer.\n *\n * @memberOf PCGRandom\n */\n constructor(\n seedHi: OptionalNumber,\n seedLo: OptionalNumber,\n incHi: OptionalNumber,\n incLo: OptionalNumber\n )\n constructor(\n seedHi?: OptionalNumber,\n seedLo?: OptionalNumber,\n incHi?: OptionalNumber,\n incLo?: OptionalNumber\n ) {\n if (isNullable(seedLo) && isNullable(seedHi)) {\n seedLo = (Math.random() * 0xffffffff) >>> 0\n seedHi = 0\n } else if (isNullable(seedLo)) {\n seedLo = seedHi\n seedHi = 0\n }\n if (isNullable(incLo) && isNullable(incHi)) {\n incLo = this._state ? this._state[3] : defaultIncLo\n incHi = this._state ? this._state[2] : defaultIncHi\n } else if (isNullable(incLo)) {\n incLo = <number> incHi\n incHi = 0\n }\n\n this._state = new Int32Array([0, 0, (<number> incHi) >>> 0, ((incLo || 0) | 1) >>> 0])\n this._next()\n add64(\n this._state,\n this._state[0]!,\n this._state[1]!,\n (<number> seedHi) >>> 0,\n (<number> seedLo) >>> 0\n )\n this._next()\n return this\n }\n\n /**\n * Returns a copy of the internal state of this random number generator as a\n * JavaScript Array.\n *\n * @category getters\n * @since 2.0.0\n */\n getState(): PCGRandomState {\n return [this._state[0]!, this._state[1]!, this._state[2]!, this._state[3]!]\n }\n\n /**\n * Restore state previously retrieved using `getState()`.\n *\n * @since 2.0.0\n */\n setState(state: PCGRandomState) {\n this._state[0] = state[0]\n this._state[1] = state[1]\n this._state[2] = state[2]\n this._state[3] = state[3] | 1\n }\n\n /**\n * Get a uniformly distributed 32 bit integer between [0, max).\n *\n * @category getter\n * @since 2.0.0\n */\n integer(max: number) {\n return Math.round(this.number() * Number.MAX_SAFE_INTEGER) % max\n }\n\n /**\n * Get a uniformly distributed IEEE-754 double between 0.0 and 1.0, with\n * 53 bits of precision (every bit of the mantissa is randomized).\n *\n * @category getters\n * @since 2.0.0\n */\n number() {\n const hi = (this._next() & 0x03ffffff) * 1.0\n const lo = (this._next() & 0x07ffffff) * 1.0\n return (hi * BIT_27 + lo) / BIT_53\n }\n\n /** @internal */\n private _next() {\n // save current state (what we'll use for this number)\n const oldHi = this._state[0]! >>> 0\n const oldLo = this._state[1]! >>> 0\n\n // churn LCG.\n mul64(this._state, oldHi, oldLo, MUL_HI, MUL_LO)\n add64(this._state, this._state[0]!, this._state[1]!, this._state[2]!, this._state[3]!)\n\n // get least sig. 32 bits of ((oldstate >> 18) ^ oldstate) >> 27\n let xsHi = oldHi >>> 18\n let xsLo = ((oldLo >>> 18) | (oldHi << 14)) >>> 0\n xsHi = (xsHi ^ oldHi) >>> 0\n xsLo = (xsLo ^ oldLo) >>> 0\n const xorshifted = ((xsLo >>> 27) | (xsHi << 5)) >>> 0\n // rotate xorshifted right a random amount, based on the most sig. 5 bits\n // bits of the old state.\n const rot = oldHi >>> 27\n const rot2 = ((-rot >>> 0) & 31) >>> 0\n return ((xorshifted >>> rot) | (xorshifted << rot2)) >>> 0\n }\n}\n\nfunction mul64(\n out: Int32Array,\n aHi: number,\n aLo: number,\n bHi: number,\n bLo: number\n): void {\n let c1 = ((aLo >>> 16) * (bLo & 0xffff)) >>> 0\n let c0 = ((aLo & 0xffff) * (bLo >>> 16)) >>> 0\n\n let lo = ((aLo & 0xffff) * (bLo & 0xffff)) >>> 0\n let hi = ((aLo >>> 16) * (bLo >>> 16) + ((c0 >>> 16) + (c1 >>> 16))) >>> 0\n\n c0 = (c0 << 16) >>> 0\n lo = (lo + c0) >>> 0\n if ((lo >>> 0) < (c0 >>> 0)) {\n hi = (hi + 1) >>> 0\n }\n\n c1 = (c1 << 16) >>> 0\n lo = (lo + c1) >>> 0\n if ((lo >>> 0) < (c1 >>> 0)) {\n hi = (hi + 1) >>> 0\n }\n\n hi = (hi + Math.imul(aLo, bHi)) >>> 0\n hi = (hi + Math.imul(aHi, bLo)) >>> 0\n\n out[0] = hi\n out[1] = lo\n}\n\n// add two 64 bit numbers (given in parts), and store the result in `out`.\nfunction add64(\n out: Int32Array,\n aHi: number,\n aLo: number,\n bHi: number,\n bLo: number\n): void {\n let hi = (aHi + bHi) >>> 0\n const lo = (aLo + bLo) >>> 0\n if ((lo >>> 0) < (aLo >>> 0)) {\n hi = (hi + 1) | 0\n }\n out[0] = hi\n out[1] = lo\n}\n\n/**\n * @since 3.0.6\n */\nexport const YieldWrapTypeId: unique symbol = Symbol.for(\"effect/Utils/YieldWrap\")\n\n/**\n * @since 3.0.6\n */\nexport class YieldWrap<T> {\n /**\n * @since 3.0.6\n */\n readonly #value: T\n constructor(value: T) {\n this.#value = value\n }\n /**\n * @since 3.0.6\n */\n [YieldWrapTypeId](): T {\n return this.#value\n }\n}\n\n/**\n * @since 3.0.6\n */\nexport function yieldWrapGet<T>(self: YieldWrap<T>): T {\n if (typeof self === \"object\" && self !== null && YieldWrapTypeId in self) {\n return self[YieldWrapTypeId]()\n }\n throw new Error(getBugErrorMessage(\"yieldWrapGet\"))\n}\n\n/**\n * Note: this is an experimental feature made available to allow custom matchers in tests, not to be directly used yet in user code\n *\n * @since 3.1.1\n * @status experimental\n * @category modifiers\n */\nexport const structuralRegionState = globalValue(\n \"effect/Utils/isStructuralRegion\",\n (): { enabled: boolean; tester: ((a: unknown, b: unknown) => boolean) | undefined } => ({\n enabled: false,\n tester: undefined\n })\n)\n\n/**\n * Note: this is an experimental feature made available to allow custom matchers in tests, not to be directly used yet in user code\n *\n * @since 3.1.1\n * @status experimental\n * @category modifiers\n */\nexport const structuralRegion = <A>(body: () => A, tester?: (a: unknown, b: unknown) => boolean): A => {\n const current = structuralRegionState.enabled\n const currentTester = structuralRegionState.tester\n structuralRegionState.enabled = true\n if (tester) {\n structuralRegionState.tester = tester\n }\n try {\n return body()\n } finally {\n structuralRegionState.enabled = current\n structuralRegionState.tester = currentTester\n }\n}\n\nconst tracingFunction = (name: string) => {\n const wrap = {\n [name]<A>(body: () => A) {\n return body()\n }\n }\n return function<A>(fn: () => A): A {\n return wrap[name](fn)\n }\n}\n\n/**\n * @since 3.2.2\n * @status experimental\n * @category tracing\n */\nexport const internalCall = tracingFunction(\"effect_internal_function\")\n\nconst genConstructor = (function*() {}).constructor\n\n/**\n * @since 3.11.0\n */\nexport const isGeneratorFunction = (u: unknown): u is (...args: Array<any>) => Generator<any, any, any> =>\n isObject(u) && u.constructor === genConstructor\n","/**\n * @since 2.0.0\n */\nimport { pipe } from \"./Function.js\"\nimport { globalValue } from \"./GlobalValue.js\"\nimport { hasProperty } from \"./Predicate.js\"\nimport { structuralRegionState } from \"./Utils.js\"\n\n/** @internal */\nconst randomHashCache = globalValue(\n Symbol.for(\"effect/Hash/randomHashCache\"),\n () => new WeakMap<object, number>()\n)\n\n/**\n * @since 2.0.0\n * @category symbols\n */\nexport const symbol: unique symbol = Symbol.for(\"effect/Hash\")\n\n/**\n * @since 2.0.0\n * @category models\n */\nexport interface Hash {\n [symbol](): number\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const hash: <A>(self: A) => number = <A>(self: A) => {\n if (structuralRegionState.enabled === true) {\n return 0\n }\n\n switch (typeof self) {\n case \"number\":\n return number(self)\n case \"bigint\":\n return string(self.toString(10))\n case \"boolean\":\n return string(String(self))\n case \"symbol\":\n return string(String(self))\n case \"string\":\n return string(self)\n case \"undefined\":\n return string(\"undefined\")\n case \"function\":\n case \"object\": {\n if (self === null) {\n return string(\"null\")\n } else if (self instanceof Date) {\n return hash(self.toISOString())\n } else if (isHash(self)) {\n return self[symbol]()\n } else {\n return random(self)\n }\n }\n default:\n throw new Error(\n `BUG: unhandled typeof ${typeof self} - please report an issue at https://github.com/Effect-TS/effect/issues`\n )\n }\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const random: <A extends object>(self: A) => number = (self) => {\n if (!randomHashCache.has(self)) {\n randomHashCache.set(self, number(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)))\n }\n return randomHashCache.get(self)!\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const combine: (b: number) => (self: number) => number = (b) => (self) => (self * 53) ^ b\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const optimize = (n: number): number => (n & 0xbfffffff) | ((n >>> 1) & 0x40000000)\n\n/**\n * @since 2.0.0\n * @category guards\n */\nexport const isHash = (u: unknown): u is Hash => hasProperty(u, symbol)\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const number = (n: number) => {\n if (n !== n || n === Infinity) {\n return 0\n }\n let h = n | 0\n if (h !== n) {\n h ^= n * 0xffffffff\n }\n while (n > 0xffffffff) {\n h ^= n /= 0xffffffff\n }\n return optimize(h)\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const string = (str: string) => {\n let h = 5381, i = str.length\n while (i) {\n h = (h * 33) ^ str.charCodeAt(--i)\n }\n return optimize(h)\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const structureKeys = <A extends object>(o: A, keys: ReadonlyArray<keyof A>) => {\n let h = 12289\n for (let i = 0; i < keys.length; i++) {\n h ^= pipe(string(keys[i]! as string), combine(hash((o as any)[keys[i]!])))\n }\n return optimize(h)\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const structure = <A extends object>(o: A) =>\n structureKeys(o, Object.keys(o) as unknown as ReadonlyArray<keyof A>)\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const array = <A>(arr: ReadonlyArray<A>) => {\n let h = 6151\n for (let i = 0; i < arr.length; i++) {\n h = pipe(h, combine(hash(arr[i])))\n }\n return optimize(h)\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const cached: {\n /**\n * @since 2.0.0\n * @category hashing\n */\n (self: object): (hash: number) => number\n /**\n * @since 2.0.0\n * @category hashing\n */\n (self: object, hash: number): number\n} = function() {\n if (arguments.length === 1) {\n const self = arguments[0] as object\n return function(hash: number) {\n Object.defineProperty(self, symbol, {\n value() {\n return hash\n },\n enumerable: false\n })\n return hash\n } as any\n }\n const self = arguments[0] as object\n const hash = arguments[1] as number\n Object.defineProperty(self, symbol, {\n value() {\n return hash\n },\n enumerable: false\n })\n\n return hash\n}\n","/**\n * @since 2.0.0\n */\nimport type { Equivalence } from \"./Equivalence.js\"\nimport * as Hash from \"./Hash.js\"\nimport { hasProperty } from \"./Predicate.js\"\nimport { structuralRegionState } from \"./Utils.js\"\n\n/**\n * @since 2.0.0\n * @category symbols\n */\nexport const symbol: unique symbol = Symbol.for(\"effect/Equal\")\n\n/**\n * @since 2.0.0\n * @category models\n */\nexport interface Equal extends Hash.Hash {\n [symbol](that: Equal): boolean\n}\n\n/**\n * @since 2.0.0\n * @category equality\n */\nexport function equals<B>(that: B): <A>(self: A) => boolean\nexport function equals<A, B>(self: A, that: B): boolean\nexport function equals(): any {\n if (arguments.length === 1) {\n return (self: unknown) => compareBoth(self, arguments[0])\n }\n return compareBoth(arguments[0], arguments[1])\n}\n\nfunction compareBoth(self: unknown, that: unknown): boolean {\n if (self === that) {\n return true\n }\n const selfType = typeof self\n if (selfType !== typeof that) {\n return false\n }\n if (selfType === \"object\" || selfType === \"function\") {\n if (self !== null && that !== null) {\n if (isEqual(self) && isEqual(that)) {\n if (Hash.hash(self) === Hash.hash(that) && self[symbol](that)) {\n return true\n } else {\n return structuralRegionState.enabled && structuralRegionState.tester\n ? structuralRegionState.tester(self, that)\n : false\n }\n } else if (self instanceof Date && that instanceof Date) {\n return self.toISOString() === that.toISOString()\n }\n }\n if (structuralRegionState.enabled) {\n if (Array.isArray(self) && Array.isArray(that)) {\n return self.length === that.length && self.every((v, i) => compareBoth(v, that[i]))\n }\n if (Object.getPrototypeOf(self) === Object.prototype && Object.getPrototypeOf(self) === Object.prototype) {\n const keysSelf = Object.keys(self as any)\n const keysThat = Object.keys(that as any)\n if (keysSelf.length === keysThat.length) {\n for (const key of keysSelf) {\n // @ts-expect-error\n if (!(key in that && compareBoth(self[key], that[key]))) {\n return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false\n }\n }\n return true\n }\n }\n return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false\n }\n }\n\n return structuralRegionState.enabled && structuralRegionState.tester\n ? structuralRegionState.tester(self, that)\n : false\n}\n\n/**\n * @since 2.0.0\n * @category guards\n */\nexport const isEqual = (u: unknown): u is Equal => hasProperty(u, symbol)\n\n/**\n * @since 2.0.0\n * @category instances\n */\nexport const equivalence: <A>() => Equivalence<A> = () => equals\n","/**\n * This module provides an implementation of the `Equivalence` type class, which defines a binary relation\n * that is reflexive, symmetric, and transitive. In other words, it defines a notion of equivalence between values of a certain type.\n * These properties are also known in mathematics as an \"equivalence relation\".\n *\n * @since 2.0.0\n */\nimport { dual } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\n\n/**\n * @category type class\n * @since 2.0.0\n */\nexport interface Equivalence<in A> {\n (self: A, that: A): boolean\n}\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface EquivalenceTypeLambda extends TypeLambda {\n readonly type: Equivalence<this[\"Target\"]>\n}\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const make = <A>(isEquivalent: (self: A, that: A) => boolean): Equivalence<A> => (self: A, that: A): boolean =>\n self === that || isEquivalent(self, that)\n\nconst isStrictEquivalent = (x: unknown, y: unknown) => x === y\n\n/**\n * Return an `Equivalence` that uses strict equality (===) to compare values.\n *\n * @since 2.0.0\n * @category constructors\n */\nexport const strict: <A>() => Equivalence<A> = () => isStrictEquivalent\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const string: Equivalence<string> = strict()\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const number: Equivalence<number> = strict()\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const boolean: Equivalence<boolean> = strict()\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const bigint: Equivalence<bigint> = strict()\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const symbol: Equivalence<symbol> = strict()\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const combine: {\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(that: Equivalence<A>): (self: Equivalence<A>) => Equivalence<A>\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(self: Equivalence<A>, that: Equivalence<A>): Equivalence<A>\n} = dual(2, <A>(self: Equivalence<A>, that: Equivalence<A>): Equivalence<A> => make((x, y) => self(x, y) && that(x, y)))\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const combineMany: {\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(collection: Iterable<Equivalence<A>>): (self: Equivalence<A>) => Equivalence<A>\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(self: Equivalence<A>, collection: Iterable<Equivalence<A>>): Equivalence<A>\n} = dual(2, <A>(self: Equivalence<A>, collection: Iterable<Equivalence<A>>): Equivalence<A> =>\n make((x, y) => {\n if (!self(x, y)) {\n return false\n }\n for (const equivalence of collection) {\n if (!equivalence(x, y)) {\n return false\n }\n }\n return true\n }))\n\nconst isAlwaysEquivalent: Equivalence<unknown> = (_x, _y) => true\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const combineAll = <A>(collection: Iterable<Equivalence<A>>): Equivalence<A> =>\n combineMany(isAlwaysEquivalent, collection)\n\n/**\n * @category mapping\n * @since 2.0.0\n */\nexport const mapInput: {\n /**\n * @category mapping\n * @since 2.0.0\n */\n <B, A>(f: (b: B) => A): (self: Equivalence<A>) => Equivalence<B>\n /**\n * @category mapping\n * @since 2.0.0\n */\n <A, B>(self: Equivalence<A>, f: (b: B) => A): Equivalence<B>\n} = dual(\n 2,\n <A, B>(self: Equivalence<A>, f: (b: B) => A): Equivalence<B> => make((x, y) => self(f(x), f(y)))\n)\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const Date: Equivalence<Date> = mapInput(number, (date) => date.getTime())\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const product: {\n <B>(that: Equivalence<B>): <A>(self: Equivalence<A>) => Equivalence<readonly [A, B]> // readonly because invariant\n <A, B>(self: Equivalence<A>, that: Equivalence<B>): Equivalence<readonly [A, B]> // readonly because invariant\n} = dual(\n 2,\n <A, B>(self: Equivalence<A>, that: Equivalence<B>): Equivalence<readonly [A, B]> =>\n make(([xa, xb], [ya, yb]) => self(xa, ya) && that(xb, yb))\n)\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const all = <A>(collection: Iterable<Equivalence<A>>): Equivalence<ReadonlyArray<A>> => {\n return make((x, y) => {\n const len = Math.min(x.length, y.length)\n\n let collectionLength = 0\n for (const equivalence of collection) {\n if (collectionLength >= len) {\n break\n }\n if (!equivalence(x[collectionLength], y[collectionLength])) {\n return false\n }\n collectionLength++\n }\n return true\n })\n}\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const productMany = <A>(\n self: Equivalence<A>,\n collection: Iterable<Equivalence<A>>\n): Equivalence<readonly [A, ...Array<A>]> /* readonly because invariant */ => {\n const equivalence = all(collection)\n return make((x, y) => !self(x[0], y[0]) ? false : equivalence(x.slice(1), y.slice(1)))\n}\n\n/**\n * Similar to `Promise.all` but operates on `Equivalence`s.\n *\n * ```\n * [Equivalence<A>, Equivalence<B>, ...] -> Equivalence<[A, B, ...]>\n * ```\n *\n * Given a tuple of `Equivalence`s returns a new `Equivalence` that compares values of a tuple\n * by applying each `Equivalence` to the corresponding element of the tuple.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const tuple = <T extends ReadonlyArray<Equivalence<any>>>(\n ...elements: T\n): Equivalence<Readonly<{ [I in keyof T]: [T[I]] extends [Equivalence<infer A>] ? A : never }>> => all(elements) as any\n\n/**\n * Creates a new `Equivalence` for an array of values based on a given `Equivalence` for the elements of the array.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const array = <A>(item: Equivalence<A>): Equivalence<ReadonlyArray<A>> =>\n make((self, that) => {\n if (self.length !== that.length) {\n return false\n }\n\n for (let i = 0; i < self.length; i++) {\n const isEq = item(self[i], that[i])\n if (!isEq) {\n return false\n }\n }\n\n return true\n })\n\n/**\n * Given a struct of `Equivalence`s returns a new `Equivalence` that compares values of a struct\n * by applying each `Equivalence` to the corresponding property of the struct.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const struct = <R extends Record<string, Equivalence<any>>>(\n fields: R\n): Equivalence<{ readonly [K in keyof R]: [R[K]] extends [Equivalence<infer A>] ? A : never }> => {\n const keys = Object.keys(fields)\n return make((self, that) => {\n for (const key of keys) {\n if (!fields[key](self[key], that[key])) {\n return false\n }\n }\n return true\n })\n}\n","/**\n * @since 2.0.0\n */\nimport type * as FiberRefs from \"./FiberRefs.js\"\nimport { globalValue } from \"./GlobalValue.js\"\nimport { hasProperty, isFunction } from \"./Predicate.js\"\n\n/**\n * @since 2.0.0\n * @category symbols\n */\nexport const NodeInspectSymbol = Symbol.for(\"nodejs.util.inspect.custom\")\n\n/**\n * @since 2.0.0\n * @category symbols\n */\nexport type NodeInspectSymbol = typeof NodeInspectSymbol\n\n/**\n * @since 2.0.0\n * @category models\n */\nexport interface Inspectable {\n toString(): string\n toJSON(): unknown\n [NodeInspectSymbol](): unknown\n}\n\n/**\n * @since 2.0.0\n */\nexport const toJSON = (x: unknown): unknown => {\n try {\n if (\n hasProperty(x, \"toJSON\") && isFunction(x[\"toJSON\"]) &&\n x[\"toJSON\"].length === 0\n ) {\n return x.toJSON()\n } else if (Array.isArray(x)) {\n return x.map(toJSON)\n }\n } catch (_) {\n return {}\n }\n return redact(x)\n}\n\n/**\n * @since 2.0.0\n */\nexport const format = (x: unknown): string => JSON.stringify(x, null, 2)\n\n/**\n * @since 2.0.0\n */\nexport const BaseProto: Inspectable = {\n toJSON() {\n return toJSON(this)\n },\n [NodeInspectSymbol]() {\n return this.toJSON()\n },\n toString() {\n return format(this.toJSON())\n }\n}\n\n/**\n * @since 2.0.0\n */\nexport abstract class Class {\n /**\n * @since 2.0.0\n */\n abstract toJSON(): unknown\n /**\n * @since 2.0.0\n */\n [NodeInspectSymbol]() {\n return this.toJSON()\n }\n /**\n * @since 2.0.0\n */\n toString() {\n return format(this.toJSON())\n }\n}\n\n/**\n * @since 2.0.0\n */\nexport const toStringUnknown = (u: unknown, whitespace: number | string | undefined = 2): string => {\n if (typeof u === \"string\") {\n return u\n }\n try {\n return typeof u === \"object\" ? stringifyCircular(u, whitespace) : String(u)\n } catch (_) {\n return String(u)\n }\n}\n\n/**\n * @since 2.0.0\n */\nexport const stringifyCircular = (obj: unknown, whitespace?: number | string | undefined): string => {\n let cache: Array<unknown> = []\n const retVal = JSON.stringify(\n obj,\n (_key, value) =>\n typeof value === \"object\" && value !== null\n ? cache.includes(value)\n ? undefined // circular reference\n : cache.push(value) && (redactableState.fiberRefs !== undefined && isRedactable(value)\n ? value[symbolRedactable](redactableState.fiberRefs)\n : value)\n : value,\n whitespace\n )\n ;(cache as any) = undefined\n return retVal\n}\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport interface Redactable {\n readonly [symbolRedactable]: (fiberRefs: FiberRefs.FiberRefs) => unknown\n}\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport const symbolRedactable: unique symbol = Symbol.for(\"effect/Inspectable/Redactable\")\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport const isRedactable = (u: unknown): u is Redactable =>\n typeof u === \"object\" && u !== null && symbolRedactable in u\n\nconst redactableState = globalValue(\"effect/Inspectable/redactableState\", () => ({\n fiberRefs: undefined as FiberRefs.FiberRefs | undefined\n}))\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport const withRedactableContext = <A>(context: FiberRefs.FiberRefs, f: () => A): A => {\n const prev = redactableState.fiberRefs\n redactableState.fiberRefs = context\n try {\n return f()\n } finally {\n redactableState.fiberRefs = prev\n }\n}\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport const redact = (u: unknown): unknown => {\n if (isRedactable(u) && redactableState.fiberRefs !== undefined) {\n return u[symbolRedactable](redactableState.fiberRefs)\n }\n return u\n}\n","/**\n * @since 2.0.0\n */\n\n/**\n * @since 2.0.0\n * @category models\n */\nexport interface Pipeable {\n pipe<A>(this: A): A\n pipe<A, B = never>(this: A, ab: (_: A) => B): B\n pipe<A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C\n pipe<A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D\n pipe<A, B = never, C = never, D = never, E = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E\n ): E\n pipe<A, B = never, C = never, D = never, E = never, F = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F\n ): F\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G\n ): G\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H\n ): H\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I\n ): I\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J\n ): J\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K\n ): K\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L\n ): L\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M\n ): M\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N\n ): N\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O\n ): O\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P\n ): P\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q\n ): Q\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R\n ): R\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R,\n rs: (_: R) => S\n ): S\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never,\n T = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R,\n rs: (_: R) => S,\n st: (_: S) => T\n ): T\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never,\n T = never,\n U = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R,\n rs: (_: R) => S,\n st: (_: S) => T,\n tu: (_: T) => U\n ): U\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never,\n T = never,\n U = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R,\n rs: (_: R) => S,\n st: (_: S) => T,\n tu: (_: T) => U\n ): U\n}\n\n/**\n * @since 2.0.0\n */\nexport const pipeArguments = <A>(self: A, args: IArguments): unknown => {\n switch (args.length) {\n case 0:\n return self\n case 1:\n return args[0](self)\n case 2:\n return args[1](args[0](self))\n case 3:\n return args[2](args[1](args[0](self)))\n case 4:\n return args[3](args[2](args[1](args[0](self))))\n case 5:\n return args[4](args[3](args[2](args[1](args[0](self)))))\n case 6:\n return args[5](args[4](args[3](args[2](args[1](args[0](self))))))\n case 7:\n return args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))))\n case 8:\n return args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self))))))))\n case 9:\n return args[8](args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))))))\n default: {\n let ret = self\n for (let i = 0, len = args.length; i < len; i++) {\n ret = args[i](ret)\n }\n return ret\n }\n }\n}\n","/** @internal */\nexport type OP_ASYNC = typeof OP_ASYNC\n\n/** @internal */\nexport const OP_ASYNC = \"Async\" as const\n\n/** @internal */\nexport type OP_COMMIT = typeof OP_COMMIT\n\n/** @internal */\nexport const OP_COMMIT = \"Commit\" as const\n\n/** @internal */\nexport type OP_FAILURE = typeof OP_FAILURE\n\n/** @internal */\nexport const OP_FAILURE = \"Failure\" as const\n\n/** @internal */\nexport type OP_ON_FAILURE = typeof OP_ON_FAILURE\n\n/** @internal */\nexport const OP_ON_FAILURE = \"OnFailure\" as const\n\n/** @internal */\nexport type OP_ON_SUCCESS = typeof OP_ON_SUCCESS\n\n/** @internal */\nexport const OP_ON_SUCCESS = \"OnSuccess\" as const\n\n/** @internal */\nexport type OP_ON_SUCCESS_AND_FAILURE = typeof OP_ON_SUCCESS_AND_FAILURE\n\n/** @internal */\nexport const OP_ON_SUCCESS_AND_FAILURE = \"OnSuccessAndFailure\" as const\n\n/** @internal */\nexport type OP_SUCCESS = typeof OP_SUCCESS\n\n/** @internal */\nexport const OP_SUCCESS = \"Success\" as const\n\n/** @internal */\nexport type OP_SYNC = typeof OP_SYNC\n\n/** @internal */\nexport const OP_SYNC = \"Sync\" as const\n\n/** @internal */\nexport const OP_TAG = \"Tag\" as const\n\n/** @internal */\nexport type OP_TAG = typeof OP_TAG\n\n/** @internal */\nexport type OP_UPDATE_RUNTIME_FLAGS = typeof OP_UPDATE_RUNTIME_FLAGS\n\n/** @internal */\nexport const OP_UPDATE_RUNTIME_FLAGS = \"UpdateRuntimeFlags\" as const\n\n/** @internal */\nexport type OP_WHILE = typeof OP_WHILE\n\n/** @internal */\nexport const OP_WHILE = \"While\" as const\n\n/** @internal */\nexport type OP_ITERATOR = typeof OP_ITERATOR\n\n/** @internal */\nexport const OP_ITERATOR = \"Iterator\" as const\n\n/** @internal */\nexport type OP_WITH_RUNTIME = typeof OP_WITH_RUNTIME\n\n/** @internal */\nexport const OP_WITH_RUNTIME = \"WithRuntime\" as const\n\n/** @internal */\nexport type OP_YIELD = typeof OP_YIELD\n\n/** @internal */\nexport const OP_YIELD = \"Yield\" as const\n\n/** @internal */\nexport type OP_REVERT_FLAGS = typeof OP_REVERT_FLAGS\n\n/** @internal */\nexport const OP_REVERT_FLAGS = \"RevertFlags\" as const\n","import type * as Channel from \"../Channel.js\"\nimport type * as Effect from \"../Effect.js\"\nimport type * as Effectable from \"../Effectable.js\"\nimport * as Equal from \"../Equal.js\"\nimport * as Hash from \"../Hash.js\"\nimport { pipeArguments } from \"../Pipeable.js\"\nimport type * as Sink from \"../Sink.js\"\nimport type * as Stream from \"../Stream.js\"\nimport { SingleShotGen, YieldWrap } from \"../Utils.js\"\nimport * as OpCodes from \"./opCodes/effect.js\"\nimport * as version from \"./version.js\"\n\n/** @internal */\nexport const EffectTypeId: Effect.EffectTypeId = Symbol.for(\"effect/Effect\") as Effect.EffectTypeId\n\n/** @internal */\nexport const StreamTypeId: Stream.StreamTypeId = Symbol.for(\"effect/Stream\") as Stream.StreamTypeId\n\n/** @internal */\nexport const SinkTypeId: Sink.SinkTypeId = Symbol.for(\"effect/Sink\") as Sink.SinkTypeId\n\n/** @internal */\nexport const ChannelTypeId: Channel.ChannelTypeId = Symbol.for(\"effect/Channel\") as Channel.ChannelTypeId\n\n/** @internal */\nexport const effectVariance = {\n /* c8 ignore next */\n _R: (_: never) => _,\n /* c8 ignore next */\n _E: (_: never) => _,\n /* c8 ignore next */\n _A: (_: never) => _,\n\n _V: version.getCurrentVersion()\n}\n\nconst sinkVariance = {\n /* c8 ignore next */\n _A: (_: never) => _,\n /* c8 ignore next */\n _In: (_: unknown) => _,\n /* c8 ignore next */\n _L: (_: never) => _,\n /* c8 ignore next */\n _E: (_: never) => _,\n /* c8 ignore next */\n _R: (_: never) => _\n}\n\nconst channelVariance = {\n /* c8 ignore next */\n _Env: (_: never) => _,\n /* c8 ignore next */\n _InErr: (_: unknown) => _,\n /* c8 ignore next */\n _InElem: (_: unknown) => _,\n /* c8 ignore next */\n _InDone: (_: unknown) => _,\n /* c8 ignore next */\n _OutErr: (_: never) => _,\n /* c8 ignore next */\n _OutElem: (_: never) => _,\n /* c8 ignore next */\n _OutDone: (_: never) => _\n}\n\n/** @internal */\nexport const EffectPrototype: Effect.Effect<never> & Equal.Equal = {\n [EffectTypeId]: effectVariance,\n [StreamTypeId]: effectVariance,\n [SinkTypeId]: sinkVariance,\n [ChannelTypeId]: channelVariance,\n [Equal.symbol](that: any) {\n return this === that\n },\n [Hash.symbol]() {\n return Hash.cached(this, Hash.random(this))\n },\n [Symbol.iterator]() {\n return new SingleShotGen(new YieldWrap(this)) as any\n },\n pipe() {\n return pipeArguments(this, arguments)\n }\n}\n\n/** @internal */\nexport const StructuralPrototype: Equal.Equal = {\n [Hash.symbol]() {\n return Hash.cached(this, Hash.structure(this))\n },\n [Equal.symbol](this: Equal.Equal, that: Equal.Equal) {\n const selfKeys = Object.keys(this)\n const thatKeys = Object.keys(that as object)\n if (selfKeys.length !== thatKeys.length) {\n return false\n }\n for (const key of selfKeys) {\n if (!(key in (that as object) && Equal.equals((this as any)[key], (that as any)[key]))) {\n return false\n }\n }\n return true\n }\n}\n\n/** @internal */\nexport const CommitPrototype: Effect.Effect<never> = {\n ...EffectPrototype,\n _op: OpCodes.OP_COMMIT\n} as any\n\n/** @internal */\nexport const StructuralCommitPrototype: Effect.Effect<never> = {\n ...CommitPrototype,\n ...StructuralPrototype\n} as any\n\n/** @internal */\nexport const Base: Effectable.CommitPrimitive = (function() {\n function Base() {}\n Base.prototype = CommitPrototype\n return Base as any\n})()\n\n/** @internal */\nexport const StructuralBase: Effectable.CommitPrimitive = (function() {\n function Base() {}\n Base.prototype = StructuralCommitPrototype\n return Base as any\n})()\n","/**\n * @since 2.0.0\n */\n\nimport * as Equal from \"../Equal.js\"\nimport * as Hash from \"../Hash.js\"\nimport { format, NodeInspectSymbol, toJSON } from \"../Inspectable.js\"\nimport type * as Option from \"../Option.js\"\nimport { hasProperty } from \"../Predicate.js\"\nimport { EffectPrototype } from \"./effectable.js\"\n\nconst TypeId: Option.TypeId = Symbol.for(\"effect/Option\") as Option.TypeId\n\nconst CommonProto = {\n ...EffectPrototype,\n [TypeId]: {\n _A: (_: never) => _\n },\n [NodeInspectSymbol]<A>(this: Option.Option<A>) {\n return this.toJSON()\n },\n toString<A>(this: Option.Option<A>) {\n return format(this.toJSON())\n }\n}\n\nconst SomeProto = Object.assign(Object.create(CommonProto), {\n _tag: \"Some\",\n _op: \"Some\",\n [Equal.symbol]<A>(this: Option.Some<A>, that: unknown): boolean {\n return isOption(that) && isSome(that) && Equal.equals(this.value, that.value)\n },\n [Hash.symbol]<A>(this: Option.Some<A>) {\n return Hash.cached(this, Hash.combine(Hash.hash(this._tag))(Hash.hash(this.value)))\n },\n toJSON<A>(this: Option.Some<A>) {\n return {\n _id: \"Option\",\n _tag: this._tag,\n value: toJSON(this.value)\n }\n }\n})\n\nconst NoneHash = Hash.hash(\"None\")\nconst NoneProto = Object.assign(Object.create(CommonProto), {\n _tag: \"None\",\n _op: \"None\",\n [Equal.symbol]<A>(this: Option.None<A>, that: unknown): boolean {\n return isOption(that) && isNone(that)\n },\n [Hash.symbol]<A>(this: Option.None<A>) {\n return NoneHash\n },\n toJSON<A>(this: Option.None<A>) {\n return {\n _id: \"Option\",\n _tag: this._tag\n }\n }\n})\n\n/** @internal */\nexport const isOption = (input: unknown): input is Option.Option<unknown> => hasProperty(input, TypeId)\n\n/** @internal */\nexport const isNone = <A>(fa: Option.Option<A>): fa is Option.None<A> => fa._tag === \"None\"\n\n/** @internal */\nexport const isSome = <A>(fa: Option.Option<A>): fa is Option.Some<A> => fa._tag === \"Some\"\n\n/** @internal */\nexport const none: Option.Option<never> = Object.create(NoneProto)\n\n/** @internal */\nexport const some = <A>(value: A): Option.Option<A> => {\n const a = Object.create(SomeProto)\n a.value = value\n return a\n}\n","/**\n * This module provides an implementation of the `Order` type class which is used to define a total ordering on some type `A`.\n * An order is defined by a relation `<=`, which obeys the following laws:\n *\n * - either `x <= y` or `y <= x` (totality)\n * - if `x <= y` and `y <= x`, then `x == y` (antisymmetry)\n * - if `x <= y` and `y <= z`, then `x <= z` (transitivity)\n *\n * The truth table for compare is defined as follows:\n *\n * | `x <= y` | `x >= y` | Ordering | |\n * | -------- | -------- | -------- | --------------------- |\n * | `true` | `true` | `0` | corresponds to x == y |\n * | `true` | `false` | `< 0` | corresponds to x < y |\n * | `false` | `true` | `> 0` | corresponds to x > y |\n *\n * @since 2.0.0\n */\nimport { dual } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\n\n/**\n * @category type class\n * @since 2.0.0\n */\nexport interface Order<in A> {\n (self: A, that: A): -1 | 0 | 1\n}\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface OrderTypeLambda extends TypeLambda {\n readonly type: Order<this[\"Target\"]>\n}\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const make = <A>(\n compare: (self: A, that: A) => -1 | 0 | 1\n): Order<A> =>\n(self, that) => self === that ? 0 : compare(self, that)\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const string: Order<string> = make((self, that) => self < that ? -1 : 1)\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const number: Order<number> = make((self, that) => self < that ? -1 : 1)\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const boolean: Order<boolean> = make((self, that) => self < that ? -1 : 1)\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const bigint: Order<bigint> = make((self, that) => self < that ? -1 : 1)\n\n/**\n * @since 2.0.0\n */\nexport const reverse = <A>(O: Order<A>): Order<A> => make((self, that) => O(that, self))\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const combine: {\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(that: Order<A>): (self: Order<A>) => Order<A>\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(self: Order<A>, that: Order<A>): Order<A>\n} = dual(2, <A>(self: Order<A>, that: Order<A>): Order<A> =>\n make((a1, a2) => {\n const out = self(a1, a2)\n if (out !== 0) {\n return out\n }\n return that(a1, a2)\n }))\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const combineMany: {\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(collection: Iterable<Order<A>>): (self: Order<A>) => Order<A>\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(self: Order<A>, collection: Iterable<Order<A>>): Order<A>\n} = dual(2, <A>(self: Order<A>, collection: Iterable<Order<A>>): Order<A> =>\n make((a1, a2) => {\n let out = self(a1, a2)\n if (out !== 0) {\n return out\n }\n for (const O of collection) {\n out = O(a1, a2)\n if (out !== 0) {\n return out\n }\n }\n return out\n }))\n\n/**\n * @since 2.0.0\n */\nexport const empty = <A>(): Order<A> => make(() => 0)\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const combineAll = <A>(collection: Iterable<Order<A>>): Order<A> => combineMany(empty(), collection)\n\n/**\n * @category mapping\n * @since 2.0.0\n */\nexport const mapInput: {\n /**\n * @category mapping\n * @since 2.0.0\n */\n <B, A>(f: (b: B) => A): (self: Order<A>) => Order<B>\n /**\n * @category mapping\n * @since 2.0.0\n */\n <A, B>(self: Order<A>, f: (b: B) => A): Order<B>\n} = dual(\n 2,\n <A, B>(self: Order<A>, f: (b: B) => A): Order<B> => make((b1, b2) => self(f(b1), f(b2)))\n)\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const Date: Order<Date> = mapInput(number, (date) => date.getTime())\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const product: {\n <B>(that: Order<B>): <A>(self: Order<A>) => Order<readonly [A, B]> // readonly because invariant\n <A, B>(self: Order<A>, that: Order<B>): Order<readonly [A, B]> // readonly because invariant\n} = dual(2, <A, B>(self: Order<A>, that: Order<B>): Order<readonly [A, B]> =>\n make(([xa, xb], [ya, yb]) => {\n const o = self(xa, ya)\n return o !== 0 ? o : that(xb, yb)\n }))\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const all = <A>(collection: Iterable<Order<A>>): Order<ReadonlyArray<A>> => {\n return make((x, y) => {\n const len = Math.min(x.length, y.length)\n let collectionLength = 0\n for (const O of collection) {\n if (collectionLength >= len) {\n break\n }\n const o = O(x[collectionLength], y[collectionLength])\n if (o !== 0) {\n return o\n }\n collectionLength++\n }\n return 0\n })\n}\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const productMany: {\n <A>(collection: Iterable<Order<A>>): (self: Order<A>) => Order<readonly [A, ...Array<A>]> // readonly because invariant\n <A>(self: Order<A>, collection: Iterable<Order<A>>): Order<readonly [A, ...Array<A>]> // readonly because invariant\n} = dual(2, <A>(self: Order<A>, collection: Iterable<Order<A>>): Order<readonly [A, ...Array<A>]> => {\n const O = all(collection)\n return make((x, y) => {\n const o = self(x[0], y[0])\n return o !== 0 ? o : O(x.slice(1), y.slice(1))\n })\n})\n\n/**\n * Similar to `Promise.all` but operates on `Order`s.\n *\n * ```\n * [Order<A>, Order<B>, ...] -> Order<[A, B, ...]>\n * ```\n *\n * This function creates and returns a new `Order` for a tuple of values based on the given `Order`s for each element in the tuple.\n * The returned `Order` compares two tuples of the same type by applying the corresponding `Order` to each element in the tuple.\n * It is useful when you need to compare two tuples of the same type and you have a specific way of comparing each element\n * of the tuple.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const tuple = <T extends ReadonlyArray<Order<any>>>(\n ...elements: T\n): Order<Readonly<{ [I in keyof T]: [T[I]] extends [Order<infer A>] ? A : never }>> => all(elements) as any\n\n/**\n * This function creates and returns a new `Order` for an array of values based on a given `Order` for the elements of the array.\n * The returned `Order` compares two arrays by applying the given `Order` to each element in the arrays.\n * If all elements are equal, the arrays are then compared based on their length.\n * It is useful when you need to compare two arrays of the same type and you have a specific way of comparing each element of the array.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const array = <A>(O: Order<A>): Order<ReadonlyArray<A>> =>\n make((self, that) => {\n const aLen = self.length\n const bLen = that.length\n const len = Math.min(aLen, bLen)\n for (let i = 0; i < len; i++) {\n const o = O(self[i], that[i])\n if (o !== 0) {\n return o\n }\n }\n return number(aLen, bLen)\n })\n\n/**\n * This function creates and returns a new `Order` for a struct of values based on the given `Order`s\n * for each property in the struct.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const struct = <R extends { readonly [x: string]: Order<any> }>(\n fields: R\n): Order<{ [K in keyof R]: [R[K]] extends [Order<infer A>] ? A : never }> => {\n const keys = Object.keys(fields)\n return make((self, that) => {\n for (const key of keys) {\n const o = fields[key](self[key], that[key])\n if (o !== 0) {\n return o\n }\n }\n return 0\n })\n}\n\n/**\n * Test whether one value is _strictly less than_ another.\n *\n * @since 2.0.0\n */\nexport const lessThan = <A>(O: Order<A>): {\n (that: A): (self: A) => boolean\n (self: A, that: A): boolean\n} => dual(2, (self: A, that: A) => O(self, that) === -1)\n\n/**\n * Test whether one value is _strictly greater than_ another.\n *\n * @since 2.0.0\n */\nexport const greaterThan = <A>(O: Order<A>): {\n (that: A): (self: A) => boolean\n (self: A, that: A): boolean\n} => dual(2, (self: A, that: A) => O(self, that) === 1)\n\n/**\n * Test whether one value is _non-strictly less than_ another.\n *\n * @since 2.0.0\n */\nexport const lessThanOrEqualTo = <A>(O: Order<A>): {\n (that: A): (self: A) => boolean\n (self: A, that: A): boolean\n} => dual(2, (self: A, that: A) => O(self, that) !== 1)\n\n/**\n * Test whether one value is _non-strictly greater than_ another.\n *\n * @since 2.0.0\n */\nexport const greaterThanOrEqualTo = <A>(O: Order<A>): {\n (that: A): (self: A) => boolean\n (self: A, that: A): boolean\n} => dual(2, (self: A, that: A) => O(self, that) !== -1)\n\n/**\n * Take the minimum of two values. If they are considered equal, the first argument is chosen.\n *\n * @since 2.0.0\n */\nexport const min = <A>(O: Order<A>): {\n (that: A): (self: A) => A\n (self: A, that: A): A\n} => dual(2, (self: A, that: A) => self === that || O(self, that) < 1 ? self : that)\n\n/**\n * Take the maximum of two values. If they are considered equal, the first argument is chosen.\n *\n * @since 2.0.0\n */\nexport const max = <A>(O: Order<A>): {\n (that: A): (self: A) => A\n (self: A, that: A): A\n} => dual(2, (self: A, that: A) => self === that || O(self, that) > -1 ? self : that)\n\n/**\n * Clamp a value between a minimum and a maximum.\n *\n * @example\n * ```ts\n * import { Order, Number } from \"effect\"\n *\n * const clamp = Order.clamp(Number.Order)({ minimum: 1, maximum: 5 })\n *\n * assert.equal(clamp(3), 3)\n * assert.equal(clamp(0), 1)\n * assert.equal(clamp(6), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const clamp = <A>(O: Order<A>): {\n (options: {\n minimum: A\n maximum: A\n }): (self: A) => A\n (self: A, options: {\n minimum: A\n maximum: A\n }): A\n} =>\n dual(\n 2,\n (self: A, options: {\n minimum: A\n maximum: A\n }): A => min(O)(options.maximum, max(O)(options.minimum, self))\n )\n\n/**\n * Test whether a value is between a minimum and a maximum (inclusive).\n *\n * @since 2.0.0\n */\nexport const between = <A>(O: Order<A>): {\n (options: {\n minimum: A\n maximum: A\n }): (self: A) => boolean\n (self: A, options: {\n minimum: A\n maximum: A\n }): boolean\n} =>\n dual(\n 2,\n (self: A, options: {\n minimum: A\n maximum: A\n }): boolean => !lessThan(O)(self, options.minimum) && !greaterThan(O)(self, options.maximum)\n )\n","/**\n * @since 2.0.0\n */\nimport type { Either } from \"./Either.js\"\nimport * as Equal from \"./Equal.js\"\nimport * as Equivalence from \"./Equivalence.js\"\nimport type { LazyArg } from \"./Function.js\"\nimport { constNull, constUndefined, dual, identity, isFunction } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\nimport type { Inspectable } from \"./Inspectable.js\"\nimport * as doNotation from \"./internal/doNotation.js\"\nimport * as either from \"./internal/either.js\"\nimport * as option from \"./internal/option.js\"\nimport type { Order } from \"./Order.js\"\nimport * as order from \"./Order.js\"\nimport type { Pipeable } from \"./Pipeable.js\"\nimport type { Predicate, Refinement } from \"./Predicate.js\"\nimport type { Covariant, NoInfer, NotFunction } from \"./Types.js\"\nimport type * as Unify from \"./Unify.js\"\nimport * as Gen from \"./Utils.js\"\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport type Option<A> = None<A> | Some<A>\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport const TypeId: unique symbol = Symbol.for(\"effect/Option\")\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport type TypeId = typeof TypeId\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface None<out A> extends Pipeable, Inspectable {\n readonly _tag: \"None\"\n readonly _op: \"None\"\n readonly [TypeId]: {\n readonly _A: Covariant<A>\n }\n [Unify.typeSymbol]?: unknown\n [Unify.unifySymbol]?: OptionUnify<this>\n [Unify.ignoreSymbol]?: OptionUnifyIgnore\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Some<out A> extends Pipeable, Inspectable {\n readonly _tag: \"Some\"\n readonly _op: \"Some\"\n readonly value: A\n readonly [TypeId]: {\n readonly _A: Covariant<A>\n }\n [Unify.typeSymbol]?: unknown\n [Unify.unifySymbol]?: OptionUnify<this>\n [Unify.ignoreSymbol]?: OptionUnifyIgnore\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface OptionUnify<A extends { [Unify.typeSymbol]?: any }> {\n Option?: () => A[Unify.typeSymbol] extends Option<infer A0> | infer _ ? Option<A0> : never\n}\n\n/**\n * @since 2.0.0\n */\nexport declare namespace Option {\n /**\n * @since 2.0.0\n * @category type-level\n */\n export type Value<T extends Option<any>> = [T] extends [Option<infer _A>] ? _A : never\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface OptionUnifyIgnore {}\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface OptionTypeLambda extends TypeLambda {\n readonly type: Option<this[\"Target\"]>\n}\n\n/**\n * Creates a new `Option` that represents the absence of a value.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const none = <A = never>(): Option<A> => option.none\n\n/**\n * Creates a new `Option` that wraps the given value.\n *\n * @param value - The value to wrap.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const some: <A>(value: A) => Option<A> = option.some\n\n/**\n * Checks if a given value is an `Option` value.\n *\n * @param input - The value to check.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.isOption(Option.some(1)), true)\n * assert.deepStrictEqual(Option.isOption(Option.none()), true)\n * assert.deepStrictEqual(Option.isOption({}), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isOption: (input: unknown) => input is Option<unknown> = option.isOption\n\n/**\n * Determine if a `Option` is a `None`.\n *\n * @param self - The `Option` to check.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.isNone(Option.some(1)), false)\n * assert.deepStrictEqual(Option.isNone(Option.none()), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNone: <A>(self: Option<A>) => self is None<A> = option.isNone\n\n/**\n * Determine if a `Option` is a `Some`.\n *\n * @param self - The `Option` to check.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.isSome(Option.some(1)), true)\n * assert.deepStrictEqual(Option.isSome(Option.none()), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isSome: <A>(self: Option<A>) => self is Some<A> = option.isSome\n\n/**\n * Matches the given `Option` and returns either the provided `onNone` value or the result of the provided `onSome`\n * function when passed the `Option`'s value.\n *\n * @param self - The `Option` to match\n * @param onNone - The value to be returned if the `Option` is `None`\n * @param onSome - The function to be called if the `Option` is `Some`, it will be passed the `Option`'s value and its result will be returned\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(Option.some(1), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),\n * 'a some containing 1'\n * )\n *\n * assert.deepStrictEqual(\n * pipe(Option.none(), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),\n * 'a none'\n * )\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\nexport const match: {\n /**\n * Matches the given `Option` and returns either the provided `onNone` value or the result of the provided `onSome`\n * function when passed the `Option`'s value.\n *\n * @param self - The `Option` to match\n * @param onNone - The value to be returned if the `Option` is `None`\n * @param onSome - The function to be called if the `Option` is `Some`, it will be passed the `Option`'s value and its result will be returned\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(Option.some(1), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),\n * 'a some containing 1'\n * )\n *\n * assert.deepStrictEqual(\n * pipe(Option.none(), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),\n * 'a none'\n * )\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <B, A, C = B>(\n options: {\n readonly onNone: LazyArg<B>\n readonly onSome: (a: A) => C\n }\n ): (self: Option<A>) => B | C\n /**\n * Matches the given `Option` and returns either the provided `onNone` value or the result of the provided `onSome`\n * function when passed the `Option`'s value.\n *\n * @param self - The `Option` to match\n * @param onNone - The value to be returned if the `Option` is `None`\n * @param onSome - The function to be called if the `Option` is `Some`, it will be passed the `Option`'s value and its result will be returned\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(Option.some(1), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),\n * 'a some containing 1'\n * )\n *\n * assert.deepStrictEqual(\n * pipe(Option.none(), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),\n * 'a none'\n * )\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <A, B, C = B>(\n self: Option<A>,\n options: {\n readonly onNone: LazyArg<B>\n readonly onSome: (a: A) => C\n }\n ): B | C\n} = dual(\n 2,\n <A, B, C = B>(self: Option<A>, { onNone, onSome }: {\n readonly onNone: LazyArg<B>\n readonly onSome: (a: A) => C\n }): B | C => isNone(self) ? onNone() : onSome(self.value)\n)\n\n/**\n * Returns a type guard from a `Option` returning function.\n * This function ensures that a type guard definition is type-safe.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const parsePositive = (n: number): Option.Option<number> =>\n * n > 0 ? Option.some(n) : Option.none()\n *\n * const isPositive = Option.toRefinement(parsePositive)\n *\n * assert.deepStrictEqual(isPositive(1), true)\n * assert.deepStrictEqual(isPositive(-1), false)\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const toRefinement = <A, B extends A>(f: (a: A) => Option<B>): (a: A) => a is B => (a: A): a is B => isSome(f(a))\n\n/**\n * Converts an `Iterable` of values into an `Option`. Returns the first value of the `Iterable` wrapped in a `Some`\n * if the `Iterable` is not empty, otherwise returns `None`.\n *\n * @param collection - The `Iterable` to be converted to an `Option`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.fromIterable([1, 2, 3]), Option.some(1))\n * assert.deepStrictEqual(Option.fromIterable([]), Option.none())\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const fromIterable = <A>(collection: Iterable<A>): Option<A> => {\n for (const a of collection) {\n return some(a)\n }\n return none()\n}\n\n/**\n * Converts a `Either` to an `Option` discarding the error.\n *\n * @example\n * ```ts\n * import { Option, Either } from \"effect\"\n *\n * assert.deepStrictEqual(Option.getRight(Either.right('ok')), Option.some('ok'))\n * assert.deepStrictEqual(Option.getRight(Either.left('err')), Option.none())\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const getRight: <R, L>(self: Either<R, L>) => Option<R> = either.getRight\n\n/**\n * Converts a `Either` to an `Option` discarding the value.\n *\n * @example\n * ```ts\n * import { Option, Either } from \"effect\"\n *\n * assert.deepStrictEqual(Option.getLeft(Either.right(\"ok\")), Option.none())\n * assert.deepStrictEqual(Option.getLeft(Either.left(\"a\")), Option.some(\"a\"))\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const getLeft: <R, L>(self: Either<R, L>) => Option<L> = either.getLeft\n\n/**\n * Returns the value of the `Option` if it is `Some`, otherwise returns `onNone`\n *\n * @param self - The `Option` to get the value of.\n * @param onNone - Function that returns the default value to return if the `Option` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(pipe(Option.some(1), Option.getOrElse(() => 0)), 1)\n * assert.deepStrictEqual(pipe(Option.none(), Option.getOrElse(() => 0)), 0)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrElse: {\n /**\n * Returns the value of the `Option` if it is `Some`, otherwise returns `onNone`\n *\n * @param self - The `Option` to get the value of.\n * @param onNone - Function that returns the default value to return if the `Option` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(pipe(Option.some(1), Option.getOrElse(() => 0)), 1)\n * assert.deepStrictEqual(pipe(Option.none(), Option.getOrElse(() => 0)), 0)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <B>(onNone: LazyArg<B>): <A>(self: Option<A>) => B | A\n /**\n * Returns the value of the `Option` if it is `Some`, otherwise returns `onNone`\n *\n * @param self - The `Option` to get the value of.\n * @param onNone - Function that returns the default value to return if the `Option` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(pipe(Option.some(1), Option.getOrElse(() => 0)), 1)\n * assert.deepStrictEqual(pipe(Option.none(), Option.getOrElse(() => 0)), 0)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, onNone: LazyArg<B>): A | B\n} = dual(\n 2,\n <A, B>(self: Option<A>, onNone: LazyArg<B>): A | B => isNone(self) ? onNone() : self.value\n)\n\n/**\n * Returns the provided `Option` `that` if `self` is `None`, otherwise returns `self`.\n *\n * @param self - The first `Option` to be checked.\n * @param that - The `Option` to return if `self` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElse(() => Option.none())\n * ),\n * Option.none()\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElse(() => Option.none())\n * ),\n * Option.some('a')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElse(() => Option.some('b'))\n * ),\n * Option.some('b')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElse(() => Option.some('b'))\n * ),\n * Option.some('a')\n * )\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\nexport const orElse: {\n /**\n * Returns the provided `Option` `that` if `self` is `None`, otherwise returns `self`.\n *\n * @param self - The first `Option` to be checked.\n * @param that - The `Option` to return if `self` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElse(() => Option.none())\n * ),\n * Option.none()\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElse(() => Option.none())\n * ),\n * Option.some('a')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElse(() => Option.some('b'))\n * ),\n * Option.some('b')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElse(() => Option.some('b'))\n * ),\n * Option.some('a')\n * )\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\n <B>(that: LazyArg<Option<B>>): <A>(self: Option<A>) => Option<B | A>\n /**\n * Returns the provided `Option` `that` if `self` is `None`, otherwise returns `self`.\n *\n * @param self - The first `Option` to be checked.\n * @param that - The `Option` to return if `self` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElse(() => Option.none())\n * ),\n * Option.none()\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElse(() => Option.none())\n * ),\n * Option.some('a')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElse(() => Option.some('b'))\n * ),\n * Option.some('b')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElse(() => Option.some('b'))\n * ),\n * Option.some('a')\n * )\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<A | B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<A | B> => isNone(self) ? that() : self\n)\n\n/**\n * Returns the provided default value as `Some` if `self` is `None`, otherwise returns `self`.\n *\n * @param self - The first `Option` to be checked.\n * @param onNone - Function that returns the default value to return if the `Option` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElseSome(() => 'b')\n * ),\n * Option.some('b')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElseSome(() => 'b')\n * ),\n * Option.some('a')\n * )\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\nexport const orElseSome: {\n /**\n * Returns the provided default value as `Some` if `self` is `None`, otherwise returns `self`.\n *\n * @param self - The first `Option` to be checked.\n * @param onNone - Function that returns the default value to return if the `Option` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElseSome(() => 'b')\n * ),\n * Option.some('b')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElseSome(() => 'b')\n * ),\n * Option.some('a')\n * )\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\n <B>(onNone: LazyArg<B>): <A>(self: Option<A>) => Option<B | A>\n /**\n * Returns the provided default value as `Some` if `self` is `None`, otherwise returns `self`.\n *\n * @param self - The first `Option` to be checked.\n * @param onNone - Function that returns the default value to return if the `Option` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElseSome(() => 'b')\n * ),\n * Option.some('b')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElseSome(() => 'b')\n * ),\n * Option.some('a')\n * )\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, onNone: LazyArg<B>): Option<A | B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, onNone: LazyArg<B>): Option<A | B> => isNone(self) ? some(onNone()) : self\n)\n\n/**\n * Similar to `orElse`, but instead of returning a simple union, it returns an `Either` object,\n * which contains information about which of the two `Option`s has been chosen.\n *\n * This is useful when it's important to know whether the value was retrieved from the first `Option` or the second option.\n *\n * @param self - The first `Option` to be checked.\n * @param that - The second `Option` to be considered if the first `Option` is `None`.\n *\n * @category error handling\n * @since 2.0.0\n */\nexport const orElseEither: {\n /**\n * Similar to `orElse`, but instead of returning a simple union, it returns an `Either` object,\n * which contains information about which of the two `Option`s has been chosen.\n *\n * This is useful when it's important to know whether the value was retrieved from the first `Option` or the second option.\n *\n * @param self - The first `Option` to be checked.\n * @param that - The second `Option` to be considered if the first `Option` is `None`.\n *\n * @category error handling\n * @since 2.0.0\n */\n <B>(that: LazyArg<Option<B>>): <A>(self: Option<A>) => Option<Either<B, A>>\n /**\n * Similar to `orElse`, but instead of returning a simple union, it returns an `Either` object,\n * which contains information about which of the two `Option`s has been chosen.\n *\n * This is useful when it's important to know whether the value was retrieved from the first `Option` or the second option.\n *\n * @param self - The first `Option` to be checked.\n * @param that - The second `Option` to be considered if the first `Option` is `None`.\n *\n * @category error handling\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<Either<B, A>>\n} = dual(\n 2,\n <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<Either<B, A>> =>\n isNone(self) ? map(that(), either.right) : map(self, either.left)\n)\n\n/**\n * Given an `Iterable` collection of `Option`s, returns the first `Some` found in the collection.\n *\n * @param collection - An iterable collection of `Option` to be searched.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.firstSomeOf([Option.none(), Option.some(1), Option.some(2)]), Option.some(1))\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\nexport const firstSomeOf = <T, C extends Iterable<Option<T>> = Iterable<Option<T>>>(\n collection: C\n): [C] extends [Iterable<Option<infer A>>] ? Option<A> : never => {\n let out: Option<unknown> = none()\n for (out of collection) {\n if (isSome(out)) {\n return out as any\n }\n }\n return out as any\n}\n\n/**\n * Constructs a new `Option` from a nullable type. If the value is `null` or `undefined`, returns `None`, otherwise\n * returns the value wrapped in a `Some`.\n *\n * @param nullableValue - The nullable value to be converted to an `Option`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.fromNullable(undefined), Option.none())\n * assert.deepStrictEqual(Option.fromNullable(null), Option.none())\n * assert.deepStrictEqual(Option.fromNullable(1), Option.some(1))\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const fromNullable = <A>(\n nullableValue: A\n): Option<\n NonNullable<A>\n> => (nullableValue == null ? none() : some(nullableValue as NonNullable<A>))\n\n/**\n * This API is useful for lifting a function that returns `null` or `undefined` into the `Option` context.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const parse = (s: string): number | undefined => {\n * const n = parseFloat(s)\n * return isNaN(n) ? undefined : n\n * }\n *\n * const parseOption = Option.liftNullable(parse)\n *\n * assert.deepStrictEqual(parseOption('1'), Option.some(1))\n * assert.deepStrictEqual(parseOption('not a number'), Option.none())\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const liftNullable = <A extends ReadonlyArray<unknown>, B>(\n f: (...a: A) => B | null | undefined\n): (...a: A) => Option<NonNullable<B>> =>\n(...a) => fromNullable(f(...a))\n\n/**\n * Returns the value of the `Option` if it is a `Some`, otherwise returns `null`.\n *\n * @param self - The `Option` to extract the value from.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.getOrNull(Option.some(1)), 1)\n * assert.deepStrictEqual(Option.getOrNull(Option.none()), null)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrNull: <A>(self: Option<A>) => A | null = getOrElse(constNull)\n\n/**\n * Returns the value of the `Option` if it is a `Some`, otherwise returns `undefined`.\n *\n * @param self - The `Option` to extract the value from.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.getOrUndefined(Option.some(1)), 1)\n * assert.deepStrictEqual(Option.getOrUndefined(Option.none()), undefined)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrUndefined: <A>(self: Option<A>) => A | undefined = getOrElse(constUndefined)\n\n/**\n * A utility function that lifts a function that throws exceptions into a function that returns an `Option`.\n *\n * This function is useful for any function that might throw an exception, allowing the developer to handle\n * the exception in a more functional way.\n *\n * @param f - the function that can throw exceptions.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const parse = Option.liftThrowable(JSON.parse)\n *\n * assert.deepStrictEqual(parse(\"1\"), Option.some(1))\n * assert.deepStrictEqual(parse(\"\"), Option.none())\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const liftThrowable = <A extends ReadonlyArray<unknown>, B>(\n f: (...a: A) => B\n): (...a: A) => Option<B> =>\n(...a) => {\n try {\n return some(f(...a))\n } catch (e) {\n return none()\n }\n}\n\n/**\n * Extracts the value of an `Option` or throws if the `Option` is `None`.\n *\n * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.\n *\n * @param self - The `Option` to extract the value from.\n * @param onNone - A function that will be called if the `Option` is `None`. It returns the error to be thrown.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Option.getOrThrowWith(Option.some(1), () => new Error('Unexpected None')),\n * 1\n * )\n * assert.throws(() => Option.getOrThrowWith(Option.none(), () => new Error('Unexpected None')))\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const getOrThrowWith: {\n /**\n * Extracts the value of an `Option` or throws if the `Option` is `None`.\n *\n * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.\n *\n * @param self - The `Option` to extract the value from.\n * @param onNone - A function that will be called if the `Option` is `None`. It returns the error to be thrown.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Option.getOrThrowWith(Option.some(1), () => new Error('Unexpected None')),\n * 1\n * )\n * assert.throws(() => Option.getOrThrowWith(Option.none(), () => new Error('Unexpected None')))\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\n (onNone: () => unknown): <A>(self: Option<A>) => A\n /**\n * Extracts the value of an `Option` or throws if the `Option` is `None`.\n *\n * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.\n *\n * @param self - The `Option` to extract the value from.\n * @param onNone - A function that will be called if the `Option` is `None`. It returns the error to be thrown.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Option.getOrThrowWith(Option.some(1), () => new Error('Unexpected None')),\n * 1\n * )\n * assert.throws(() => Option.getOrThrowWith(Option.none(), () => new Error('Unexpected None')))\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\n <A>(self: Option<A>, onNone: () => unknown): A\n} = dual(2, <A>(self: Option<A>, onNone: () => unknown): A => {\n if (isSome(self)) {\n return self.value\n }\n throw onNone()\n})\n\n/**\n * Extracts the value of an `Option` or throws if the `Option` is `None`.\n *\n * The thrown error is a default error. To configure the error thrown, see {@link getOrThrowWith}.\n *\n * @param self - The `Option` to extract the value from.\n * @throws `Error(\"getOrThrow called on a None\")`\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.getOrThrow(Option.some(1)), 1)\n * assert.throws(() => Option.getOrThrow(Option.none()))\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const getOrThrow: <A>(self: Option<A>) => A = getOrThrowWith(() => new Error(\"getOrThrow called on a None\"))\n\n/**\n * Maps the `Some` side of an `Option` value to a new `Option` value.\n *\n * @param self - An `Option` to map\n * @param f - The function to map over the value of the `Option`\n *\n * @category mapping\n * @since 2.0.0\n */\nexport const map: {\n /**\n * Maps the `Some` side of an `Option` value to a new `Option` value.\n *\n * @param self - An `Option` to map\n * @param f - The function to map over the value of the `Option`\n *\n * @category mapping\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B): (self: Option<A>) => Option<B>\n /**\n * Maps the `Some` side of an `Option` value to a new `Option` value.\n *\n * @param self - An `Option` to map\n * @param f - The function to map over the value of the `Option`\n *\n * @category mapping\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => B): Option<B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => B): Option<B> => isNone(self) ? none() : some(f(self.value))\n)\n\n/**\n * Maps the `Some` value of this `Option` to the specified constant value.\n *\n * @category mapping\n * @since 2.0.0\n */\nexport const as: {\n /**\n * Maps the `Some` value of this `Option` to the specified constant value.\n *\n * @category mapping\n * @since 2.0.0\n */\n <B>(b: B): <X>(self: Option<X>) => Option<B>\n} = dual(2, <X, B>(self: Option<X>, b: B): Option<B> => map(self, () => b))\n\n/**\n * Maps the `Some` value of this `Option` to the `void` constant value.\n *\n * This is useful when the value of the `Option` is not needed, but the presence or absence of the value is important.\n *\n * @category mapping\n * @since 2.0.0\n */\nexport const asVoid: <_>(self: Option<_>) => Option<void> = as(undefined)\n\nconst void_: Option<void> = some(undefined)\nexport {\n /**\n * @since 2.0.0\n */\n void_ as void\n}\n\n/**\n * Applies a function to the value of an `Option` and flattens the result, if the input is `Some`.\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatMap: {\n /**\n * Applies a function to the value of an `Option` and flattens the result, if the input is `Some`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => Option<B>): (self: Option<A>) => Option<B>\n /**\n * Applies a function to the value of an `Option` and flattens the result, if the input is `Some`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B> => isNone(self) ? none() : f(self.value)\n)\n\n/**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const andThen: {\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => Option<B>): (self: Option<A>) => Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <B>(f: Option<B>): <A>(self: Option<A>) => Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B): (self: Option<A>) => Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <B>(f: NotFunction<B>): <A>(self: Option<A>) => Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: Option<B>): Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => B): Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: NotFunction<B>): Option<B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => Option<B> | Option<B>): Option<B> =>\n flatMap(self, (a) => {\n const b = isFunction(f) ? f(a) : f\n return isOption(b) ? b : some(b)\n })\n)\n\n/**\n * This is `flatMap` + `fromNullable`, useful when working with optional values.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * interface Employee {\n * company?: {\n * address?: {\n * street?: {\n * name?: string\n * }\n * }\n * }\n * }\n *\n * const employee1: Employee = { company: { address: { street: { name: 'high street' } } } }\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.some(employee1),\n * Option.flatMapNullable(employee => employee.company?.address?.street?.name),\n * ),\n * Option.some('high street')\n * )\n *\n * const employee2: Employee = { company: { address: { street: {} } } }\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.some(employee2),\n * Option.flatMapNullable(employee => employee.company?.address?.street?.name),\n * ),\n * Option.none()\n * )\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatMapNullable: {\n /**\n * This is `flatMap` + `fromNullable`, useful when working with optional values.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * interface Employee {\n * company?: {\n * address?: {\n * street?: {\n * name?: string\n * }\n * }\n * }\n * }\n *\n * const employee1: Employee = { company: { address: { street: { name: 'high street' } } } }\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.some(employee1),\n * Option.flatMapNullable(employee => employee.company?.address?.street?.name),\n * ),\n * Option.some('high street')\n * )\n *\n * const employee2: Employee = { company: { address: { street: {} } } }\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.some(employee2),\n * Option.flatMapNullable(employee => employee.company?.address?.street?.name),\n * ),\n * Option.none()\n * )\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B | null | undefined): (self: Option<A>) => Option<NonNullable<B>>\n /**\n * This is `flatMap` + `fromNullable`, useful when working with optional values.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * interface Employee {\n * company?: {\n * address?: {\n * street?: {\n * name?: string\n * }\n * }\n * }\n * }\n *\n * const employee1: Employee = { company: { address: { street: { name: 'high street' } } } }\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.some(employee1),\n * Option.flatMapNullable(employee => employee.company?.address?.street?.name),\n * ),\n * Option.some('high street')\n * )\n *\n * const employee2: Employee = { company: { address: { street: {} } } }\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.some(employee2),\n * Option.flatMapNullable(employee => employee.company?.address?.street?.name),\n * ),\n * Option.none()\n * )\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => B | null | undefined): Option<NonNullable<B>>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => B | null | undefined): Option<NonNullable<B>> =>\n isNone(self) ? none() : fromNullable(f(self.value))\n)\n\n/**\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatten: <A>(self: Option<Option<A>>) => Option<A> = flatMap(identity)\n\n/**\n * @category zipping\n * @since 2.0.0\n */\nexport const zipRight: {\n /**\n * @category zipping\n * @since 2.0.0\n */\n <B>(that: Option<B>): <_>(self: Option<_>) => Option<B>\n /**\n * @category zipping\n * @since 2.0.0\n */\n <X, B>(self: Option<X>, that: Option<B>): Option<B>\n} = dual(2, <X, B>(self: Option<X>, that: Option<B>): Option<B> => flatMap(self, () => that))\n\n/**\n * @category sequencing\n * @since 2.0.0\n */\nexport const composeK: {\n /**\n * @category sequencing\n * @since 2.0.0\n */\n <B, C>(bfc: (b: B) => Option<C>): <A>(afb: (a: A) => Option<B>) => (a: A) => Option<C>\n /**\n * @category sequencing\n * @since 2.0.0\n */\n <A, B, C>(afb: (a: A) => Option<B>, bfc: (b: B) => Option<C>): (a: A) => Option<C>\n} = dual(2, <A, B, C>(afb: (a: A) => Option<B>, bfc: (b: B) => Option<C>) => (a: A): Option<C> => flatMap(afb(a), bfc))\n\n/**\n * Sequences the specified `that` `Option` but ignores its value.\n *\n * It is useful when we want to chain multiple operations, but only care about the result of `self`.\n *\n * @param that - The `Option` that will be ignored in the chain and discarded\n * @param self - The `Option` we care about\n *\n * @category zipping\n * @since 2.0.0\n */\nexport const zipLeft: {\n /**\n * Sequences the specified `that` `Option` but ignores its value.\n *\n * It is useful when we want to chain multiple operations, but only care about the result of `self`.\n *\n * @param that - The `Option` that will be ignored in the chain and discarded\n * @param self - The `Option` we care about\n *\n * @category zipping\n * @since 2.0.0\n */\n <_>(that: Option<_>): <A>(self: Option<A>) => Option<A>\n /**\n * Sequences the specified `that` `Option` but ignores its value.\n *\n * It is useful when we want to chain multiple operations, but only care about the result of `self`.\n *\n * @param that - The `Option` that will be ignored in the chain and discarded\n * @param self - The `Option` we care about\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, X>(self: Option<A>, that: Option<X>): Option<A>\n} = dual(2, <A, X>(self: Option<A>, that: Option<X>): Option<A> => tap(self, () => that))\n\n/**\n * Applies the provided function `f` to the value of the `Option` if it is `Some` and returns the original `Option`\n * unless `f` returns `None`, in which case it returns `None`.\n *\n * This function is useful for performing additional computations on the value of the input `Option` without affecting its value.\n *\n * @param f - Function to apply to the value of the `Option` if it is `Some`\n * @param self - The `Option` to apply the function to\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getInteger = (n: number) => Number.isInteger(n) ? Option.some(n) : Option.none()\n *\n * assert.deepStrictEqual(Option.tap(Option.none(), getInteger), Option.none())\n * assert.deepStrictEqual(Option.tap(Option.some(1), getInteger), Option.some(1))\n * assert.deepStrictEqual(Option.tap(Option.some(1.14), getInteger), Option.none())\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const tap: {\n /**\n * Applies the provided function `f` to the value of the `Option` if it is `Some` and returns the original `Option`\n * unless `f` returns `None`, in which case it returns `None`.\n *\n * This function is useful for performing additional computations on the value of the input `Option` without affecting its value.\n *\n * @param f - Function to apply to the value of the `Option` if it is `Some`\n * @param self - The `Option` to apply the function to\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getInteger = (n: number) => Number.isInteger(n) ? Option.some(n) : Option.none()\n *\n * assert.deepStrictEqual(Option.tap(Option.none(), getInteger), Option.none())\n * assert.deepStrictEqual(Option.tap(Option.some(1), getInteger), Option.some(1))\n * assert.deepStrictEqual(Option.tap(Option.some(1.14), getInteger), Option.none())\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, X>(f: (a: A) => Option<X>): (self: Option<A>) => Option<A>\n /**\n * Applies the provided function `f` to the value of the `Option` if it is `Some` and returns the original `Option`\n * unless `f` returns `None`, in which case it returns `None`.\n *\n * This function is useful for performing additional computations on the value of the input `Option` without affecting its value.\n *\n * @param f - Function to apply to the value of the `Option` if it is `Some`\n * @param self - The `Option` to apply the function to\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getInteger = (n: number) => Number.isInteger(n) ? Option.some(n) : Option.none()\n *\n * assert.deepStrictEqual(Option.tap(Option.none(), getInteger), Option.none())\n * assert.deepStrictEqual(Option.tap(Option.some(1), getInteger), Option.some(1))\n * assert.deepStrictEqual(Option.tap(Option.some(1.14), getInteger), Option.none())\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, X>(self: Option<A>, f: (a: A) => Option<X>): Option<A>\n} = dual(2, <A, X>(self: Option<A>, f: (a: A) => Option<X>): Option<A> => flatMap(self, (a) => map(f(a), () => a)))\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const product = <A, B>(self: Option<A>, that: Option<B>): Option<[A, B]> =>\n isSome(self) && isSome(that) ? some([self.value, that.value]) : none()\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const productMany = <A>(\n self: Option<A>,\n collection: Iterable<Option<A>>\n): Option<[A, ...Array<A>]> => {\n if (isNone(self)) {\n return none()\n }\n const out: [A, ...Array<A>] = [self.value]\n for (const o of collection) {\n if (isNone(o)) {\n return none()\n }\n out.push(o.value)\n }\n return some(out)\n}\n\n/**\n * Takes a structure of `Option`s and returns an `Option` of values with the same structure.\n *\n * - If a tuple is supplied, then the returned `Option` will contain a tuple with the same length.\n * - If a struct is supplied, then the returned `Option` will contain a struct with the same keys.\n * - If an iterable is supplied, then the returned `Option` will contain an array.\n *\n * @param fields - the struct of `Option`s to be sequenced.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.all([Option.some(1), Option.some(2)]), Option.some([1, 2]))\n * assert.deepStrictEqual(Option.all({ a: Option.some(1), b: Option.some(\"hello\") }), Option.some({ a: 1, b: \"hello\" }))\n * assert.deepStrictEqual(Option.all({ a: Option.some(1), b: Option.none() }), Option.none())\n * ```\n *\n * @category combining\n * @since 2.0.0\n */\n// @ts-expect-error\nexport const all: <const I extends Iterable<Option<any>> | Record<string, Option<any>>>(\n input: I\n) => [I] extends [ReadonlyArray<Option<any>>] ? Option<\n { -readonly [K in keyof I]: [I[K]] extends [Option<infer A>] ? A : never }\n >\n : [I] extends [Iterable<Option<infer A>>] ? Option<Array<A>>\n : Option<{ -readonly [K in keyof I]: [I[K]] extends [Option<infer A>] ? A : never }> = (\n input: Iterable<Option<any>> | Record<string, Option<any>>\n ): Option<any> => {\n if (Symbol.iterator in input) {\n const out: Array<Option<any>> = []\n for (const o of (input as Iterable<Option<any>>)) {\n if (isNone(o)) {\n return none()\n }\n out.push(o.value)\n }\n return some(out)\n }\n\n const out: Record<string, any> = {}\n for (const key of Object.keys(input)) {\n const o = input[key]\n if (isNone(o)) {\n return none()\n }\n out[key] = o.value\n }\n return some(out)\n }\n\n/**\n * Zips two `Option` values together using a provided function, returning a new `Option` of the result.\n *\n * @param self - The left-hand side of the zip operation\n * @param that - The right-hand side of the zip operation\n * @param f - The function used to combine the values of the two `Option`s\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * type Complex = [real: number, imaginary: number]\n *\n * const complex = (real: number, imaginary: number): Complex => [real, imaginary]\n *\n * assert.deepStrictEqual(Option.zipWith(Option.none(), Option.none(), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.none(), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.none(), Option.some(1), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.some(2), complex), Option.some([1, 2]))\n *\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), complex)(Option.some(2)), Option.some([2, 1]))\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\nexport const zipWith: {\n /**\n * Zips two `Option` values together using a provided function, returning a new `Option` of the result.\n *\n * @param self - The left-hand side of the zip operation\n * @param that - The right-hand side of the zip operation\n * @param f - The function used to combine the values of the two `Option`s\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * type Complex = [real: number, imaginary: number]\n *\n * const complex = (real: number, imaginary: number): Complex => [real, imaginary]\n *\n * assert.deepStrictEqual(Option.zipWith(Option.none(), Option.none(), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.none(), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.none(), Option.some(1), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.some(2), complex), Option.some([1, 2]))\n *\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), complex)(Option.some(2)), Option.some([2, 1]))\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B, A, C>(that: Option<B>, f: (a: A, b: B) => C): (self: Option<A>) => Option<C>\n /**\n * Zips two `Option` values together using a provided function, returning a new `Option` of the result.\n *\n * @param self - The left-hand side of the zip operation\n * @param that - The right-hand side of the zip operation\n * @param f - The function used to combine the values of the two `Option`s\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * type Complex = [real: number, imaginary: number]\n *\n * const complex = (real: number, imaginary: number): Complex => [real, imaginary]\n *\n * assert.deepStrictEqual(Option.zipWith(Option.none(), Option.none(), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.none(), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.none(), Option.some(1), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.some(2), complex), Option.some([1, 2]))\n *\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), complex)(Option.some(2)), Option.some([2, 1]))\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C>\n} = dual(\n 3,\n <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C> =>\n map(product(self, that), ([a, b]) => f(a, b))\n)\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const ap: {\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(that: Option<A>): <B>(self: Option<(a: A) => B>) => Option<B>\n /**\n * @category combining\n * @since 2.0.0\n */\n <A, B>(self: Option<(a: A) => B>, that: Option<A>): Option<B>\n} = dual(2, <A, B>(self: Option<(a: A) => B>, that: Option<A>): Option<B> => zipWith(self, that, (f, a) => f(a)))\n\n/**\n * Reduces an `Iterable` of `Option<A>` to a single value of type `B`, elements that are `None` are ignored.\n *\n * @param self - The Iterable of `Option<A>` to be reduced.\n * @param b - The initial value of the accumulator.\n * @param f - The reducing function that takes the current accumulator value and the unwrapped value of an `Option<A>`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const iterable = [Option.some(1), Option.none(), Option.some(2), Option.none()]\n * assert.deepStrictEqual(pipe(iterable, Option.reduceCompact(0, (b, a) => b + a)), 3)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const reduceCompact: {\n /**\n * Reduces an `Iterable` of `Option<A>` to a single value of type `B`, elements that are `None` are ignored.\n *\n * @param self - The Iterable of `Option<A>` to be reduced.\n * @param b - The initial value of the accumulator.\n * @param f - The reducing function that takes the current accumulator value and the unwrapped value of an `Option<A>`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const iterable = [Option.some(1), Option.none(), Option.some(2), Option.none()]\n * assert.deepStrictEqual(pipe(iterable, Option.reduceCompact(0, (b, a) => b + a)), 3)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A) => B): (self: Iterable<Option<A>>) => B\n /**\n * Reduces an `Iterable` of `Option<A>` to a single value of type `B`, elements that are `None` are ignored.\n *\n * @param self - The Iterable of `Option<A>` to be reduced.\n * @param b - The initial value of the accumulator.\n * @param f - The reducing function that takes the current accumulator value and the unwrapped value of an `Option<A>`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const iterable = [Option.some(1), Option.none(), Option.some(2), Option.none()]\n * assert.deepStrictEqual(pipe(iterable, Option.reduceCompact(0, (b, a) => b + a)), 3)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<Option<A>>, b: B, f: (b: B, a: A) => B): B\n} = dual(\n 3,\n <A, B>(self: Iterable<Option<A>>, b: B, f: (b: B, a: A) => B): B => {\n let out: B = b\n for (const oa of self) {\n if (isSome(oa)) {\n out = f(out, oa.value)\n }\n }\n return out\n }\n)\n\n/**\n * Transforms an `Option` into an `Array`.\n * If the input is `None`, an empty array is returned.\n * If the input is `Some`, the value is wrapped in an array.\n *\n * @param self - The `Option` to convert to an array.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.toArray(Option.some(1)), [1])\n * assert.deepStrictEqual(Option.toArray(Option.none()), [])\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const toArray = <A>(self: Option<A>): Array<A> => isNone(self) ? [] : [self.value]\n\n/**\n * @category filtering\n * @since 2.0.0\n */\nexport const partitionMap: {\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A, B, C>(f: (a: A) => Either<C, B>): (self: Option<A>) => [left: Option<B>, right: Option<C>]\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A, B, C>(self: Option<A>, f: (a: A) => Either<C, B>): [left: Option<B>, right: Option<C>]\n} = dual(2, <A, B, C>(\n self: Option<A>,\n f: (a: A) => Either<C, B>\n): [excluded: Option<B>, satisfying: Option<C>] => {\n if (isNone(self)) {\n return [none(), none()]\n }\n const e = f(self.value)\n return either.isLeft(e) ? [some(e.left), none()] : [none(), some(e.right)]\n})\n\n/**\n * Maps over the value of an `Option` and filters out `None`s.\n *\n * Useful when in addition to filtering you also want to change the type of the `Option`.\n *\n * @param self - The `Option` to map over.\n * @param f - A function to apply to the value of the `Option`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const evenNumber = (n: number) => n % 2 === 0 ? Option.some(n) : Option.none()\n *\n * assert.deepStrictEqual(Option.filterMap(Option.none(), evenNumber), Option.none())\n * assert.deepStrictEqual(Option.filterMap(Option.some(3), evenNumber), Option.none())\n * assert.deepStrictEqual(Option.filterMap(Option.some(2), evenNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const filterMap: {\n /**\n * Maps over the value of an `Option` and filters out `None`s.\n *\n * Useful when in addition to filtering you also want to change the type of the `Option`.\n *\n * @param self - The `Option` to map over.\n * @param f - A function to apply to the value of the `Option`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const evenNumber = (n: number) => n % 2 === 0 ? Option.some(n) : Option.none()\n *\n * assert.deepStrictEqual(Option.filterMap(Option.none(), evenNumber), Option.none())\n * assert.deepStrictEqual(Option.filterMap(Option.some(3), evenNumber), Option.none())\n * assert.deepStrictEqual(Option.filterMap(Option.some(2), evenNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => Option<B>): (self: Option<A>) => Option<B>\n /**\n * Maps over the value of an `Option` and filters out `None`s.\n *\n * Useful when in addition to filtering you also want to change the type of the `Option`.\n *\n * @param self - The `Option` to map over.\n * @param f - A function to apply to the value of the `Option`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const evenNumber = (n: number) => n % 2 === 0 ? Option.some(n) : Option.none()\n *\n * assert.deepStrictEqual(Option.filterMap(Option.none(), evenNumber), Option.none())\n * assert.deepStrictEqual(Option.filterMap(Option.some(3), evenNumber), Option.none())\n * assert.deepStrictEqual(Option.filterMap(Option.some(2), evenNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B> => isNone(self) ? none() : f(self.value)\n)\n\n/**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @param predicate - A predicate function to apply to the `Option` value.\n * @param fb - The `Option` to filter.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // predicate\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(3), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isEven), Option.some(2))\n *\n * // refinement\n * const isNumber = (v: unknown): v is number => typeof v === \"number\"\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some('hello'), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const filter: {\n /**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @param predicate - A predicate function to apply to the `Option` value.\n * @param fb - The `Option` to filter.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // predicate\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(3), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isEven), Option.some(2))\n *\n * // refinement\n * const isNumber = (v: unknown): v is number => typeof v === \"number\"\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some('hello'), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: Option<A>) => Option<B>\n /**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @param predicate - A predicate function to apply to the `Option` value.\n * @param fb - The `Option` to filter.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // predicate\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(3), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isEven), Option.some(2))\n *\n * // refinement\n * const isNumber = (v: unknown): v is number => typeof v === \"number\"\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some('hello'), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A>(predicate: Predicate<NoInfer<A>>): (self: Option<A>) => Option<A>\n /**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @param predicate - A predicate function to apply to the `Option` value.\n * @param fb - The `Option` to filter.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // predicate\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(3), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isEven), Option.some(2))\n *\n * // refinement\n * const isNumber = (v: unknown): v is number => typeof v === \"number\"\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some('hello'), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(self: Option<A>, refinement: Refinement<A, B>): Option<B>\n /**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @param predicate - A predicate function to apply to the `Option` value.\n * @param fb - The `Option` to filter.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // predicate\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(3), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isEven), Option.some(2))\n *\n * // refinement\n * const isNumber = (v: unknown): v is number => typeof v === \"number\"\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some('hello'), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A>(self: Option<A>, predicate: Predicate<A>): Option<A>\n} = dual(\n 2,\n <A>(self: Option<A>, predicate: Predicate<A>): Option<A> =>\n filterMap(self, (b) => (predicate(b) ? option.some(b) : option.none))\n)\n\n/**\n * @example\n * ```ts\n * import { Option, Number } from \"effect\"\n *\n * const isEquivalent = Option.getEquivalence(Number.Equivalence)\n * assert.deepStrictEqual(isEquivalent(Option.none(), Option.none()), true)\n * assert.deepStrictEqual(isEquivalent(Option.none(), Option.some(1)), false)\n * assert.deepStrictEqual(isEquivalent(Option.some(1), Option.none()), false)\n * assert.deepStrictEqual(isEquivalent(Option.some(1), Option.some(2)), false)\n * assert.deepStrictEqual(isEquivalent(Option.some(1), Option.some(1)), true)\n * ```\n *\n * @category equivalence\n * @since 2.0.0\n */\nexport const getEquivalence = <A>(isEquivalent: Equivalence.Equivalence<A>): Equivalence.Equivalence<Option<A>> =>\n Equivalence.make((x, y) => isNone(x) ? isNone(y) : isNone(y) ? false : isEquivalent(x.value, y.value))\n\n/**\n * The `Order` instance allows `Option` values to be compared with\n * `compare`, whenever there is an `Order` instance for\n * the type the `Option` contains.\n *\n * `None` is considered to be less than any `Some` value.\n *\n * @example\n * ```ts\n * import { pipe, Option, Number } from \"effect\"\n *\n * const O = Option.getOrder(Number.Order)\n * assert.deepStrictEqual(O(Option.none(), Option.none()), 0)\n * assert.deepStrictEqual(O(Option.none(), Option.some(1)), -1)\n * assert.deepStrictEqual(O(Option.some(1), Option.none()), 1)\n * assert.deepStrictEqual(O(Option.some(1), Option.some(2)), -1)\n * assert.deepStrictEqual(O(Option.some(1), Option.some(1)), 0)\n * ```\n *\n * @category sorting\n * @since 2.0.0\n */\nexport const getOrder = <A>(O: Order<A>): Order<Option<A>> =>\n order.make((self, that) => isSome(self) ? (isSome(that) ? O(self.value, that.value) : 1) : -1)\n\n/**\n * Lifts a binary function into `Option`.\n *\n * @param f - The function to lift.\n *\n * @category lifting\n * @since 2.0.0\n */\nexport const lift2 = <A, B, C>(f: (a: A, b: B) => C): {\n (that: Option<B>): (self: Option<A>) => Option<C>\n (self: Option<A>, that: Option<B>): Option<C>\n} => dual(2, (self: Option<A>, that: Option<B>): Option<C> => zipWith(self, that, f))\n\n/**\n * Transforms a `Predicate` function into a `Some` of the input value if the predicate returns `true` or `None`\n * if the predicate returns `false`.\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getOption = Option.liftPredicate((n: number) => n >= 0)\n *\n * assert.deepStrictEqual(getOption(-1), Option.none())\n * assert.deepStrictEqual(getOption(1), Option.some(1))\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\nexport const liftPredicate: { // Note: I intentionally avoid using the NoInfer pattern here.\n <A, B extends A>(refinement: Refinement<A, B>): (a: A) => Option<B>\n /**\n * Transforms a `Predicate` function into a `Some` of the input value if the predicate returns `true` or `None`\n * if the predicate returns `false`.\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getOption = Option.liftPredicate((n: number) => n >= 0)\n *\n * assert.deepStrictEqual(getOption(-1), Option.none())\n * assert.deepStrictEqual(getOption(1), Option.some(1))\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\n <B extends A, A = B>(predicate: Predicate<A>): (b: B) => Option<B>\n /**\n * Transforms a `Predicate` function into a `Some` of the input value if the predicate returns `true` or `None`\n * if the predicate returns `false`.\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getOption = Option.liftPredicate((n: number) => n >= 0)\n *\n * assert.deepStrictEqual(getOption(-1), Option.none())\n * assert.deepStrictEqual(getOption(1), Option.some(1))\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\n <A, B extends A>(self: A, refinement: Refinement<A, B>): Option<B>\n /**\n * Transforms a `Predicate` function into a `Some` of the input value if the predicate returns `true` or `None`\n * if the predicate returns `false`.\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getOption = Option.liftPredicate((n: number) => n >= 0)\n *\n * assert.deepStrictEqual(getOption(-1), Option.none())\n * assert.deepStrictEqual(getOption(1), Option.some(1))\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\n <B extends A, A = B>(self: B, predicate: Predicate<A>): Option<B>\n} = dual(\n 2,\n <B extends A, A = B>(b: B, predicate: Predicate<A>): Option<B> => predicate(b) ? some(b) : none()\n)\n\n/**\n * Returns a function that checks if a `Option` contains a given value using a provided `isEquivalent` function.\n *\n * @param equivalent - An `Equivalence` instance to compare values of the `Option`.\n * @param self - The `Option` to apply the comparison to.\n * @param a - The value to compare against the `Option`.\n *\n * @example\n * ```ts\n * import { pipe, Option, Number } from \"effect\"\n *\n * assert.deepStrictEqual(pipe(Option.some(2), Option.containsWith(Number.Equivalence)(2)), true)\n * assert.deepStrictEqual(pipe(Option.some(1), Option.containsWith(Number.Equivalence)(2)), false)\n * assert.deepStrictEqual(pipe(Option.none(), Option.containsWith(Number.Equivalence)(2)), false)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const containsWith = <A>(isEquivalent: (self: A, that: A) => boolean): {\n (a: A): (self: Option<A>) => boolean\n (self: Option<A>, a: A): boolean\n} => dual(2, (self: Option<A>, a: A): boolean => isNone(self) ? false : isEquivalent(self.value, a))\n\nconst _equivalence = Equal.equivalence()\n\n/**\n * Returns a function that checks if an `Option` contains a given value using the default `Equivalence`.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const contains: {\n /**\n * Returns a function that checks if an `Option` contains a given value using the default `Equivalence`.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(a: A): (self: Option<A>) => boolean\n /**\n * Returns a function that checks if an `Option` contains a given value using the default `Equivalence`.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Option<A>, a: A): boolean\n} = containsWith(_equivalence)\n\n/**\n * Check if a value in an `Option` type meets a certain predicate.\n *\n * @param self - The `Option` to check.\n * @param predicate - The condition to check.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(pipe(Option.some(2), Option.exists(isEven)), true)\n * assert.deepStrictEqual(pipe(Option.some(1), Option.exists(isEven)), false)\n * assert.deepStrictEqual(pipe(Option.none(), Option.exists(isEven)), false)\n * ```\n *\n * @since 2.0.0\n */\nexport const exists: {\n /**\n * Check if a value in an `Option` type meets a certain predicate.\n *\n * @param self - The `Option` to check.\n * @param predicate - The condition to check.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(pipe(Option.some(2), Option.exists(isEven)), true)\n * assert.deepStrictEqual(pipe(Option.some(1), Option.exists(isEven)), false)\n * assert.deepStrictEqual(pipe(Option.none(), Option.exists(isEven)), false)\n * ```\n *\n * @since 2.0.0\n */\n <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: Option<A>) => self is Option<B>\n /**\n * Check if a value in an `Option` type meets a certain predicate.\n *\n * @param self - The `Option` to check.\n * @param predicate - The condition to check.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(pipe(Option.some(2), Option.exists(isEven)), true)\n * assert.deepStrictEqual(pipe(Option.some(1), Option.exists(isEven)), false)\n * assert.deepStrictEqual(pipe(Option.none(), Option.exists(isEven)), false)\n * ```\n *\n * @since 2.0.0\n */\n <A>(predicate: Predicate<NoInfer<A>>): (self: Option<A>) => boolean\n /**\n * Check if a value in an `Option` type meets a certain predicate.\n *\n * @param self - The `Option` to check.\n * @param predicate - The condition to check.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(pipe(Option.some(2), Option.exists(isEven)), true)\n * assert.deepStrictEqual(pipe(Option.some(1), Option.exists(isEven)), false)\n * assert.deepStrictEqual(pipe(Option.none(), Option.exists(isEven)), false)\n * ```\n *\n * @since 2.0.0\n */\n <A, B extends A>(self: Option<A>, refinement: Refinement<A, B>): self is Option<B>\n /**\n * Check if a value in an `Option` type meets a certain predicate.\n *\n * @param self - The `Option` to check.\n * @param predicate - The condition to check.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(pipe(Option.some(2), Option.exists(isEven)), true)\n * assert.deepStrictEqual(pipe(Option.some(1), Option.exists(isEven)), false)\n * assert.deepStrictEqual(pipe(Option.none(), Option.exists(isEven)), false)\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Option<A>, predicate: Predicate<A>): boolean\n} = dual(\n 2,\n <A, B extends A>(self: Option<A>, refinement: Refinement<A, B>): self is Option<B> =>\n isNone(self) ? false : refinement(self.value)\n)\n\n// -------------------------------------------------------------------------------------\n// do notation\n// -------------------------------------------------------------------------------------\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\nexport const bindTo: {\n // -------------------------------------------------------------------------------------\n // do notation\n // -------------------------------------------------------------------------------------\n\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <N extends string>(name: N): <A>(self: Option<A>) => Option<{ [K in N]: A }>\n // -------------------------------------------------------------------------------------\n // do notation\n // -------------------------------------------------------------------------------------\n\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <A, N extends string>(self: Option<A>, name: N): Option<{ [K in N]: A }>\n} = doNotation.bindTo<OptionTypeLambda>(map)\n\nconst let_: {\n <N extends string, A extends object, B>(\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): (self: Option<A>) => Option<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n <A extends object, N extends string, B>(\n self: Option<A>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): Option<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n} = doNotation.let_<OptionTypeLambda>(map)\n\nexport {\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link bindTo}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n *\n * ```\n * @category do notation\n * @since 2.0.0\n */\n let_ as let\n}\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\nexport const bind: {\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <N extends string, A extends object, B>(\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => Option<B>\n ): (self: Option<A>) => Option<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <A extends object, N extends string, B>(\n self: Option<A>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => Option<B>\n ): Option<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n} = doNotation.bind<OptionTypeLambda>(map, flatMap)\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\nexport const Do: Option<{}> = some({})\n\nconst adapter = Gen.adapter<OptionTypeLambda>()\n\n/**\n * @category generators\n * @since 2.0.0\n */\nexport const gen: Gen.Gen<OptionTypeLambda, Gen.Adapter<OptionTypeLambda>> = (...args) => {\n let f: any\n if (args.length === 1) {\n f = args[0]\n } else {\n f = args[1].bind(args[0])\n }\n const iterator = f(adapter)\n let state: IteratorYieldResult<any> | IteratorReturnResult<any> = iterator.next()\n if (state.done) {\n return some(state.value)\n } else {\n let current = state.value\n if (Gen.isGenKind(current)) {\n current = current.value\n } else {\n current = Gen.yieldWrapGet(current)\n }\n if (isNone(current)) {\n return current\n }\n while (!state.done) {\n state = iterator.next(current.value as never)\n if (!state.done) {\n current = state.value\n if (Gen.isGenKind(current)) {\n current = current.value\n } else {\n current = Gen.yieldWrapGet(current)\n }\n if (isNone(current)) {\n return current\n }\n }\n }\n return some(state.value)\n }\n}\n","/**\n * @since 1.0.0\n */\nimport type * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport type * as TSAPI from \"./utils/TSAPI.js\"\n\n/**\n * @since 1.0.0\n * @category plugin\n */\nexport interface RefactorDefinition {\n name: string\n description: string\n apply: (ts: TSAPI.TypeScriptApi, program: ts.Program, options: PluginOptions) => (\n sourceFile: ts.SourceFile,\n textRange: ts.TextRange\n ) => Option.Option<ApplicableRefactorDefinition>\n}\n\n/**\n * @since 1.0.0\n * @category plugin\n */\nexport interface ApplicableRefactorDefinition {\n kind: string\n description: string\n apply: (changeTracker: ts.textChanges.ChangeTracker) => void\n}\n\n/**\n * @since 1.0.0\n * @category plugin\n */\nexport function createRefactor(definition: RefactorDefinition) {\n return definition\n}\n\n/**\n * @since 1.0.0\n * @category plugin\n */\nexport interface DiagnosticDefinition {\n code: number\n apply: (ts: TSAPI.TypeScriptApi, program: ts.Program, options: PluginOptions) => (\n sourceFile: ts.SourceFile,\n standardDiagnostic: ReadonlyArray<ts.Diagnostic>\n ) => Array<ApplicableDiagnosticDefinition>\n}\n\n/**\n * @since 1.0.0\n * @category plugin\n */\nexport interface ApplicableDiagnosticDefinition {\n node: ts.Node\n category: ts.DiagnosticCategory\n messageText: string\n}\n\n/**\n * @since 1.0.0\n * @category plugin\n */\nexport function createDiagnostic(definition: DiagnosticDefinition) {\n return definition\n}\n\n/**\n * @since 1.0.0\n * @category plugin\n */\nexport interface PluginOptions {\n diagnostics: boolean\n quickinfo: boolean\n}\n","import * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\n\nexport type TypeScriptApi = typeof ts\n\nexport const covariantTypeArgument = (type: ts.Type) => {\n const signatures = type.getCallSignatures()\n // Covariant<A> has only 1 type signature\n if (signatures.length !== 1) return Option.none()\n // get the return type\n return Option.some(signatures[0].getReturnType())\n}\n\nexport function pipeableType(ts: TypeScriptApi, typeChecker: ts.TypeChecker) {\n return (type: ts.Type, atLocation: ts.Node) => {\n // Pipeable has a pipe property on the type\n const pipeSymbol = typeChecker.getPropertyOfType(type, \"pipe\")\n if (!pipeSymbol) return Option.none()\n // which should be callable with at least one call signature\n const pipeType = typeChecker.getTypeOfSymbolAtLocation(pipeSymbol, atLocation)\n const signatures = pipeType.getCallSignatures()\n if (signatures.length === 0) return Option.none()\n return Option.some(type)\n }\n}\n\nexport function varianceStructCovariantType(\n ts: TypeScriptApi,\n typeChecker: ts.TypeChecker\n) {\n return <A extends string>(type: ts.Type, atLocation: ts.Node, propertyName: A) =>\n Option.gen(function*(_) {\n const propertySymbol = yield* Option.fromNullable(\n typeChecker.getPropertyOfType(type, propertyName)\n )\n const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation)\n return yield* covariantTypeArgument(propertyType)\n })\n}\n\nexport function effectVarianceStruct(ts: TypeScriptApi, typeChecker: ts.TypeChecker) {\n return (type: ts.Type, atLocation: ts.Node) =>\n Option.all({\n A: varianceStructCovariantType(ts, typeChecker)(type, atLocation, \"_A\"),\n E: varianceStructCovariantType(ts, typeChecker)(type, atLocation, \"_E\"),\n R: varianceStructCovariantType(ts, typeChecker)(type, atLocation, \"_R\")\n })\n}\n\nexport function effectType(ts: TypeScriptApi, typeChecker: ts.TypeChecker) {\n return (type: ts.Type, atLocation: ts.Node) =>\n Option.gen(function*(_) {\n // should be pipeable\n yield* pipeableType(ts, typeChecker)(type, atLocation)\n // has a property symbol which is an effect variance struct\n for (const propertySymbol of typeChecker.getPropertiesOfType(type)) {\n const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation)\n const varianceArgs = effectVarianceStruct(ts, typeChecker)(\n propertyType,\n atLocation\n )\n if (Option.isSome(varianceArgs)) {\n return yield* varianceArgs\n }\n }\n return yield* Option.none()\n })\n}\n\nexport function fiberType(ts: TypeScriptApi, typeChecker: ts.TypeChecker) {\n return (type: ts.Type, atLocation: ts.Node) =>\n Option.gen(function*(_) {\n // there is no better way to check if a type is a fiber right not\n // so we just check for the existence of the property \"await\" and \"poll\"\n const awaitSymbol = yield* Option.fromNullable(\n typeChecker.getPropertyOfType(type, \"await\")\n )\n const pollSymbol = yield* Option.fromNullable(\n typeChecker.getPropertyOfType(type, \"poll\")\n )\n if (!awaitSymbol || !pollSymbol) return yield* Option.none()\n // and it is also an effect itself\n return effectType(ts, typeChecker)(type, atLocation)\n })\n}\n\nexport function effectSubtype(ts: TypeScriptApi, typeChecker: ts.TypeChecker) {\n return (type: ts.Type, atLocation: ts.Node) =>\n Option.gen(function*(_) {\n // there is no better way to check if a type is a subtype of effect\n // so we just check for the existence of the property \"_tag\"\n // which is common for Option, Either, and others\n const tagSymbol = yield* Option.fromNullable(\n typeChecker.getPropertyOfType(type, \"_tag\")\n )\n if (!tagSymbol) return yield* Option.none()\n // and it is also an effect itself\n return effectType(ts, typeChecker)(type, atLocation)\n })\n}\n\nexport function importedEffectModule(ts: TypeScriptApi, typeChecker: ts.TypeChecker) {\n return (node: ts.Node) =>\n Option.gen(function*() {\n const type = typeChecker.getTypeAtLocation(node)\n // if the type has a property \"never\"\n const propertySymbol = yield* Option.fromNullable(\n typeChecker.getPropertyOfType(type, \"never\")\n )\n // and the property type is an effect\n const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, node)\n return yield* effectType(ts, typeChecker)(propertyType, node).pipe(\n Option.map(() => node as ts.Expression)\n )\n })\n}\n\nexport function effectGen(ts: TypeScriptApi, typeChecker: ts.TypeChecker) {\n return (node: ts.Node) =>\n Option.gen(function*() {\n // Effect.gen(...)\n if (!ts.isCallExpression(node)) return yield* Option.none()\n // ...\n if (node.arguments.length === 0) return yield* Option.none()\n // firsta argument is a generator function expression\n const generatorFunction = node.arguments[0]\n if (!ts.isFunctionExpression(generatorFunction)) return yield* Option.none()\n if (generatorFunction.asteriskToken === undefined) return yield* Option.none()\n // Effect.gen\n if (!ts.isPropertyAccessExpression(node.expression)) return yield* Option.none()\n const propertyAccess = node.expression\n // gen\n if (propertyAccess.name.text !== \"gen\") return yield* Option.none()\n // check Effect module\n const effectModule = yield* importedEffectModule(ts, typeChecker)(propertyAccess.expression)\n return ({\n node,\n effectModule,\n generatorFunction,\n body: generatorFunction.body,\n functionStar: generatorFunction.getFirstToken()\n })\n })\n}\n\nexport function effectFnUntracedGen(ts: TypeScriptApi, typeChecker: ts.TypeChecker) {\n return (node: ts.Node) =>\n Option.gen(function*() {\n // Effect.gen(...)\n if (!ts.isCallExpression(node)) return yield* Option.none()\n // ...\n if (node.arguments.length === 0) return yield* Option.none()\n // firsta argument is a generator function expression\n const generatorFunction = node.arguments[0]\n if (!ts.isFunctionExpression(generatorFunction)) return yield* Option.none()\n if (generatorFunction.asteriskToken === undefined) return yield* Option.none()\n // Effect.gen\n if (!ts.isPropertyAccessExpression(node.expression)) return yield* Option.none()\n const propertyAccess = node.expression\n // gen\n if (propertyAccess.name.text !== \"fnUntraced\") return yield* Option.none()\n // check Effect module\n const effectModule = yield* importedEffectModule(ts, typeChecker)(propertyAccess.expression)\n return ({\n node,\n effectModule,\n generatorFunction,\n body: generatorFunction.body,\n functionStar: generatorFunction.getFirstToken()\n })\n })\n}\n\nexport function effectFnGen(ts: TypeScriptApi, typeChecker: ts.TypeChecker) {\n return (node: ts.Node) =>\n Option.gen(function*() {\n // Effect.fn(...)\n if (!ts.isCallExpression(node)) return yield* Option.none()\n // ...\n if (node.arguments.length === 0) return yield* Option.none()\n // firsta argument is a generator function expression\n const generatorFunction = node.arguments[0]\n if (!ts.isFunctionExpression(generatorFunction)) return yield* Option.none()\n if (generatorFunction.asteriskToken === undefined) return yield* Option.none()\n // either we are using Effect.fn(\"name\")(generatorFunction) or we are using Effect.fn(generatorFunction)\n const expressionToTest = ts.isCallExpression(node.expression)\n ? node.expression.expression\n : node.expression\n if (!ts.isPropertyAccessExpression(expressionToTest)) return yield* Option.none()\n const propertyAccess = expressionToTest\n // fn\n if (propertyAccess.name.text !== \"fn\") return yield* Option.none()\n // check Effect module\n const effectModule = yield* importedEffectModule(ts, typeChecker)(propertyAccess.expression)\n return ({\n node,\n generatorFunction,\n effectModule,\n body: generatorFunction.body,\n functionStar: generatorFunction.getFirstToken()\n })\n })\n}\n","import { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport type { ApplicableDiagnosticDefinition } from \"../definition.js\"\nimport { createDiagnostic } from \"../definition.js\"\nimport * as TypeParser from \"../utils/TypeParser.js\"\n\nexport const floatingEffect = createDiagnostic({\n code: 3,\n apply: (ts, program) => (sourceFile) => {\n const typeChecker = program.getTypeChecker()\n const effectDiagnostics: Array<ApplicableDiagnosticDefinition> = []\n\n function isFloatingExpression(node: ts.Node): node is ts.ExpressionStatement {\n // should be an expression statement\n if (!ts.isExpressionStatement(node)) return false\n // parent is either block or source file\n if (!(ts.isBlock(node.parent) || ts.isSourceFile(node.parent))) return false\n const expression = node.expression\n // this.variable = Effect.succeed is a valid expression\n if (\n ts.isBinaryExpression(expression) && expression.operatorToken &&\n expression.operatorToken.kind === ts.SyntaxKind.EqualsToken\n ) return false\n return true\n }\n\n const visit = (node: ts.Node) => {\n if (isFloatingExpression(node)) {\n const type = typeChecker.getTypeAtLocation(node.expression)\n // if type is an effect\n const effect = TypeParser.effectType(ts, typeChecker)(type, node.expression)\n if (Option.isSome(effect)) {\n // and not a fiber (we consider that a valid operation)\n const allowedFloatingEffects = pipe(\n TypeParser.fiberType(ts, typeChecker)(type, node.expression),\n Option.orElse(() => TypeParser.effectSubtype(ts, typeChecker)(type, node.expression))\n )\n if (Option.isNone(allowedFloatingEffects)) {\n effectDiagnostics.push({\n node,\n category: ts.DiagnosticCategory.Error,\n messageText: `Effect must be yielded or assigned to a variable.`\n })\n }\n }\n }\n ts.forEachChild(node, visit)\n }\n ts.forEachChild(sourceFile, visit)\n\n return effectDiagnostics\n }\n})\n","/**\n * @since 2.0.0\n */\n\nimport type { NonEmptyArray } from \"../Array.js\"\n\n/** @internal */\nexport const isNonEmptyArray = <A>(self: ReadonlyArray<A>): self is NonEmptyArray<A> => self.length > 0\n","/**\n * This module provides utility functions for working with Iterables in TypeScript.\n *\n * @since 2.0.0\n */\n\nimport type { NonEmptyArray } from \"./Array.js\"\nimport type { Either } from \"./Either.js\"\nimport * as E from \"./Either.js\"\nimport * as Equal from \"./Equal.js\"\nimport { dual, identity } from \"./Function.js\"\nimport type { Option } from \"./Option.js\"\nimport * as O from \"./Option.js\"\nimport { isBoolean } from \"./Predicate.js\"\nimport type * as Record from \"./Record.js\"\nimport * as Tuple from \"./Tuple.js\"\nimport type { NoInfer } from \"./Types.js\"\n\n/**\n * Return a `Iterable` with element `i` initialized with `f(i)`.\n *\n * If the `length` is not specified, the `Iterable` will be infinite.\n *\n * **Note**. `length` is normalized to an integer >= 1.\n *\n * @example\n * ```ts\n * import { makeBy } from \"effect/Iterable\"\n *\n * assert.deepStrictEqual(Array.from(makeBy(n => n * 2, { length: 5 })), [0, 2, 4, 6, 8])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const makeBy = <A>(f: (i: number) => A, options?: {\n readonly length?: number\n}): Iterable<A> => {\n const max = options?.length !== undefined ? Math.max(1, Math.floor(options.length)) : Infinity\n return {\n [Symbol.iterator]() {\n let i = 0\n return {\n next(): IteratorResult<A> {\n if (i < max) {\n return { value: f(i++), done: false }\n }\n return { done: true, value: undefined }\n }\n }\n }\n }\n}\n\n/**\n * Return a `Iterable` containing a range of integers, including both endpoints.\n *\n * If `end` is omitted, the range will not have an upper bound.\n *\n * @example\n * ```ts\n * import { range } from \"effect/Iterable\"\n *\n * assert.deepStrictEqual(Array.from(range(1, 3)), [1, 2, 3])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const range = (start: number, end?: number): Iterable<number> => {\n if (end === undefined) {\n return makeBy((i) => start + i)\n }\n return makeBy((i) => start + i, {\n length: start <= end ? end - start + 1 : 1\n })\n}\n\n/**\n * Return a `Iterable` containing a value repeated the specified number of times.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * @example\n * ```ts\n * import { replicate } from \"effect/Iterable\"\n *\n * assert.deepStrictEqual(Array.from(replicate(\"a\", 3)), [\"a\", \"a\", \"a\"])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const replicate: {\n /**\n * Return a `Iterable` containing a value repeated the specified number of times.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * @example\n * ```ts\n * import { replicate } from \"effect/Iterable\"\n *\n * assert.deepStrictEqual(Array.from(replicate(\"a\", 3)), [\"a\", \"a\", \"a\"])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n (n: number): <A>(a: A) => Iterable<A>\n /**\n * Return a `Iterable` containing a value repeated the specified number of times.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * @example\n * ```ts\n * import { replicate } from \"effect/Iterable\"\n *\n * assert.deepStrictEqual(Array.from(replicate(\"a\", 3)), [\"a\", \"a\", \"a\"])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <A>(a: A, n: number): Iterable<A>\n} = dual(2, <A>(a: A, n: number): Iterable<A> => makeBy(() => a, { length: n }))\n\n/**\n * Takes a record and returns an Iterable of tuples containing its keys and values.\n *\n * @param self - The record to transform.\n *\n * @example\n * ```ts\n * import { fromRecord } from \"effect/Iterable\"\n *\n * const x = { a: 1, b: 2, c: 3 }\n * assert.deepStrictEqual(Array.from(fromRecord(x)), [[\"a\", 1], [\"b\", 2], [\"c\", 3]])\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const fromRecord = <K extends string, A>(self: Readonly<Record<K, A>>): Iterable<[K, A]> => ({\n *[Symbol.iterator]() {\n for (const key in self) {\n if (Object.prototype.hasOwnProperty.call(self, key)) {\n yield [key, self[key]]\n }\n }\n }\n})\n\n/**\n * Prepend an element to the front of an `Iterable`, creating a new `Iterable`.\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const prepend: {\n /**\n * Prepend an element to the front of an `Iterable`, creating a new `Iterable`.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <B>(head: B): <A>(self: Iterable<A>) => Iterable<A | B>\n /**\n * Prepend an element to the front of an `Iterable`, creating a new `Iterable`.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, head: B): Iterable<A | B>\n} = dual(2, <A, B>(self: Iterable<A>, head: B): Iterable<A | B> => prependAll(self, [head]))\n\n/**\n * Prepends the specified prefix iterable to the beginning of the specified iterable.\n *\n * @example\n * ```ts\n * import { Iterable } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Array.from(Iterable.prependAll([1, 2], [\"a\", \"b\"])),\n * [\"a\", \"b\", 1, 2]\n * )\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const prependAll: {\n /**\n * Prepends the specified prefix iterable to the beginning of the specified iterable.\n *\n * @example\n * ```ts\n * import { Iterable } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Array.from(Iterable.prependAll([1, 2], [\"a\", \"b\"])),\n * [\"a\", \"b\", 1, 2]\n * )\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <B>(that: Iterable<B>): <A>(self: Iterable<A>) => Iterable<A | B>\n /**\n * Prepends the specified prefix iterable to the beginning of the specified iterable.\n *\n * @example\n * ```ts\n * import { Iterable } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Array.from(Iterable.prependAll([1, 2], [\"a\", \"b\"])),\n * [\"a\", \"b\", 1, 2]\n * )\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Iterable<A | B>\n} = dual(\n 2,\n <A, B>(self: Iterable<A>, that: Iterable<B>): Iterable<A | B> => appendAll(that, self)\n)\n\n/**\n * Append an element to the end of an `Iterable`, creating a new `Iterable`.\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const append: {\n /**\n * Append an element to the end of an `Iterable`, creating a new `Iterable`.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <B>(last: B): <A>(self: Iterable<A>) => Iterable<A | B>\n /**\n * Append an element to the end of an `Iterable`, creating a new `Iterable`.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, last: B): Iterable<A | B>\n} = dual(2, <A, B>(self: Iterable<A>, last: B): Iterable<A | B> => appendAll(self, [last]))\n\n/**\n * Concatenates two iterables, combining their elements.\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const appendAll: {\n /**\n * Concatenates two iterables, combining their elements.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <B>(that: Iterable<B>): <A>(self: Iterable<A>) => Iterable<A | B>\n /**\n * Concatenates two iterables, combining their elements.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Iterable<A | B>\n} = dual(\n 2,\n <A, B>(self: Iterable<A>, that: Iterable<B>): Iterable<A | B> => ({\n [Symbol.iterator]() {\n const iterA = self[Symbol.iterator]()\n let doneA = false\n let iterB: Iterator<B>\n return {\n next() {\n if (!doneA) {\n const r = iterA.next()\n if (r.done) {\n doneA = true\n iterB = that[Symbol.iterator]()\n return iterB.next()\n }\n return r\n }\n return iterB.next()\n }\n }\n }\n })\n)\n\n/**\n * Reduce an `Iterable` from the left, keeping all intermediate results instead of only the final result.\n *\n * @category folding\n * @since 2.0.0\n */\nexport const scan: {\n /**\n * Reduce an `Iterable` from the left, keeping all intermediate results instead of only the final result.\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A) => B): (self: Iterable<A>) => Iterable<B>\n /**\n * Reduce an `Iterable` from the left, keeping all intermediate results instead of only the final result.\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): Iterable<B>\n} = dual(3, <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): Iterable<B> => ({\n [Symbol.iterator]() {\n let acc = b\n let iterator: Iterator<A> | undefined\n function next() {\n if (iterator === undefined) {\n iterator = self[Symbol.iterator]()\n return { done: false, value: acc }\n }\n const result = iterator.next()\n if (result.done) {\n return result\n }\n acc = f(acc, result.value)\n return { done: false, value: acc }\n }\n return { next }\n }\n}))\n\n/**\n * Determine if an `Iterable` is empty\n *\n * @example\n * ```ts\n * import { isEmpty } from \"effect/Iterable\"\n *\n * assert.deepStrictEqual(isEmpty([]), true);\n * assert.deepStrictEqual(isEmpty([1, 2, 3]), false);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isEmpty = <A>(self: Iterable<A>): self is Iterable<never> => {\n const iterator = self[Symbol.iterator]()\n return iterator.next().done === true\n}\n\n/**\n * Return the number of elements in a `Iterable`.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const size = <A>(self: Iterable<A>): number => {\n const iterator = self[Symbol.iterator]()\n let count = 0\n while (!iterator.next().done) {\n count++\n }\n return count\n}\n\n/**\n * Get the first element of a `Iterable`, or `None` if the `Iterable` is empty.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const head = <A>(self: Iterable<A>): Option<A> => {\n const iterator = self[Symbol.iterator]()\n const result = iterator.next()\n return result.done ? O.none() : O.some(result.value)\n}\n\n/**\n * Get the first element of a `Iterable`, or throw an error if the `Iterable` is empty.\n *\n * @category getters\n * @since 3.3.0\n */\nexport const unsafeHead = <A>(self: Iterable<A>): A => {\n const iterator = self[Symbol.iterator]()\n const result = iterator.next()\n if (result.done) throw new Error(\"unsafeHead: empty iterable\")\n return result.value\n}\n\n/**\n * Keep only a max number of elements from the start of an `Iterable`, creating a new `Iterable`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const take: {\n /**\n * Keep only a max number of elements from the start of an `Iterable`, creating a new `Iterable`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @category getters\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => Iterable<A>\n /**\n * Keep only a max number of elements from the start of an `Iterable`, creating a new `Iterable`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Iterable<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Iterable<A> => ({\n [Symbol.iterator]() {\n let i = 0\n const iterator = self[Symbol.iterator]()\n return {\n next() {\n if (i < n) {\n i++\n return iterator.next()\n }\n return { done: true, value: undefined }\n }\n }\n }\n}))\n\n/**\n * Calculate the longest initial Iterable for which all element satisfy the specified predicate, creating a new `Iterable`.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const takeWhile: {\n /**\n * Calculate the longest initial Iterable for which all element satisfy the specified predicate, creating a new `Iterable`.\n *\n * @category getters\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Iterable<B>\n /**\n * Calculate the longest initial Iterable for which all element satisfy the specified predicate, creating a new `Iterable`.\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Iterable<A>\n /**\n * Calculate the longest initial Iterable for which all element satisfy the specified predicate, creating a new `Iterable`.\n *\n * @category getters\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Iterable<B>\n /**\n * Calculate the longest initial Iterable for which all element satisfy the specified predicate, creating a new `Iterable`.\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Iterable<A>\n} = dual(2, <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Iterable<A> => ({\n [Symbol.iterator]() {\n const iterator = self[Symbol.iterator]()\n let i = 0\n return {\n next() {\n const result = iterator.next()\n if (result.done || !predicate(result.value, i++)) {\n return { done: true, value: undefined }\n }\n return result\n }\n }\n }\n}))\n\n/**\n * Drop a max number of elements from the start of an `Iterable`\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const drop: {\n /**\n * Drop a max number of elements from the start of an `Iterable`\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @category getters\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => Iterable<A>\n /**\n * Drop a max number of elements from the start of an `Iterable`\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Iterable<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Iterable<A> => ({\n [Symbol.iterator]() {\n const iterator = self[Symbol.iterator]()\n let i = 0\n return {\n next() {\n while (i < n) {\n const result = iterator.next()\n if (result.done) {\n return { done: true, value: undefined }\n }\n i++\n }\n return iterator.next()\n }\n }\n }\n}))\n\n/**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findFirst: {\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(f: (a: NoInfer<A>, i: number) => Option<B>): (self: Iterable<A>) => Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option<A>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<A>\n} = dual(\n 2,\n <A>(self: Iterable<A>, f: ((a: A, i: number) => boolean) | ((a: A, i: number) => Option<A>)): Option<A> => {\n let i = 0\n for (const a of self) {\n const o = f(a, i)\n if (isBoolean(o)) {\n if (o) {\n return O.some(a)\n }\n } else {\n if (O.isSome(o)) {\n return o\n }\n }\n i++\n }\n return O.none()\n }\n)\n\n/**\n * Find the last element for which a predicate holds.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findLast: {\n /**\n * Find the last element for which a predicate holds.\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(f: (a: NoInfer<A>, i: number) => Option<B>): (self: Iterable<A>) => Option<B>\n /**\n * Find the last element for which a predicate holds.\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Option<B>\n /**\n * Find the last element for which a predicate holds.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option<A>\n /**\n * Find the last element for which a predicate holds.\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Option<B>\n /**\n * Find the last element for which a predicate holds.\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Option<B>\n /**\n * Find the last element for which a predicate holds.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<A>\n} = dual(\n 2,\n <A>(self: Iterable<A>, f: ((a: A, i: number) => boolean) | ((a: A, i: number) => Option<A>)): Option<A> => {\n let i = 0\n let last: Option<A> = O.none()\n for (const a of self) {\n const o = f(a, i)\n if (isBoolean(o)) {\n if (o) {\n last = O.some(a)\n }\n } else {\n if (O.isSome(o)) {\n last = o\n }\n }\n i++\n }\n return last\n }\n)\n\n/**\n * Takes two `Iterable`s and returns an `Iterable` of corresponding pairs.\n *\n * @category zipping\n * @since 2.0.0\n */\nexport const zip: {\n /**\n * Takes two `Iterable`s and returns an `Iterable` of corresponding pairs.\n *\n * @category zipping\n * @since 2.0.0\n */\n <B>(that: Iterable<B>): <A>(self: Iterable<A>) => Iterable<[A, B]>\n /**\n * Takes two `Iterable`s and returns an `Iterable` of corresponding pairs.\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Iterable<[A, B]>\n} = dual(\n 2,\n <A, B>(self: Iterable<A>, that: Iterable<B>): Iterable<[A, B]> => zipWith(self, that, Tuple.make)\n)\n\n/**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * @category zipping\n * @since 2.0.0\n */\nexport const zipWith: {\n /**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * @category zipping\n * @since 2.0.0\n */\n <B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Iterable<C>\n /**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, B, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Iterable<C>\n} = dual(3, <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Iterable<C> => ({\n [Symbol.iterator]() {\n const selfIterator = self[Symbol.iterator]()\n const thatIterator = that[Symbol.iterator]()\n return {\n next() {\n const selfResult = selfIterator.next()\n const thatResult = thatIterator.next()\n if (selfResult.done || thatResult.done) {\n return { done: true, value: undefined }\n }\n return { done: false, value: f(selfResult.value, thatResult.value) }\n }\n }\n }\n}))\n\n/**\n * Places an element in between members of an `Iterable`.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @since 2.0.0\n */\nexport const intersperse: {\n /**\n * Places an element in between members of an `Iterable`.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @since 2.0.0\n */\n <B>(middle: B): <A>(self: Iterable<A>) => Iterable<A | B>\n /**\n * Places an element in between members of an `Iterable`.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, middle: B): Iterable<A | B>\n} = dual(2, <A, B>(self: Iterable<A>, middle: B): Iterable<A | B> => ({\n [Symbol.iterator]() {\n const iterator = self[Symbol.iterator]()\n let next = iterator.next()\n let emitted = false\n return {\n next() {\n if (next.done) {\n return next\n } else if (emitted) {\n emitted = false\n return { done: false, value: middle }\n }\n emitted = true\n const result = next\n next = iterator.next()\n return result\n }\n }\n }\n}))\n\n/**\n * Returns a function that checks if an `Iterable` contains a given value using a provided `isEquivalent` function.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const containsWith = <A>(isEquivalent: (self: A, that: A) => boolean): {\n (a: A): (self: Iterable<A>) => boolean\n (self: Iterable<A>, a: A): boolean\n} =>\n dual(2, (self: Iterable<A>, a: A): boolean => {\n for (const i of self) {\n if (isEquivalent(a, i)) {\n return true\n }\n }\n return false\n })\n\nconst _equivalence = Equal.equivalence()\n\n/**\n * Returns a function that checks if a `Iterable` contains a given value using the default `Equivalence`.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const contains: {\n /**\n * Returns a function that checks if a `Iterable` contains a given value using the default `Equivalence`.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(a: A): (self: Iterable<A>) => boolean\n /**\n * Returns a function that checks if a `Iterable` contains a given value using the default `Equivalence`.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, a: A): boolean\n} = containsWith(_equivalence)\n\n/**\n * Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of\n * the `Iterable`.\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const chunksOf: {\n /**\n * Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of\n * the `Iterable`.\n *\n * @category splitting\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => Iterable<Array<A>>\n /**\n * Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of\n * the `Iterable`.\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Iterable<Array<A>>\n} = dual(2, <A>(self: Iterable<A>, n: number): Iterable<Array<A>> => {\n const safeN = Math.max(1, Math.floor(n))\n return ({\n [Symbol.iterator]() {\n let iterator: Iterator<A> | undefined = self[Symbol.iterator]()\n return {\n next() {\n if (iterator === undefined) {\n return { done: true, value: undefined }\n }\n\n const chunk: Array<A> = []\n for (let i = 0; i < safeN; i++) {\n const result = iterator.next()\n if (result.done) {\n iterator = undefined\n return chunk.length === 0 ? { done: true, value: undefined } : { done: false, value: chunk }\n }\n chunk.push(result.value)\n }\n\n return { done: false, value: chunk }\n }\n }\n }\n })\n})\n\n/**\n * Group equal, consecutive elements of an `Iterable` into `NonEmptyArray`s using the provided `isEquivalent` function.\n *\n * @category grouping\n * @since 2.0.0\n */\nexport const groupWith: {\n /**\n * Group equal, consecutive elements of an `Iterable` into `NonEmptyArray`s using the provided `isEquivalent` function.\n *\n * @category grouping\n * @since 2.0.0\n */\n <A>(isEquivalent: (self: A, that: A) => boolean): (self: Iterable<A>) => Iterable<NonEmptyArray<A>>\n /**\n * Group equal, consecutive elements of an `Iterable` into `NonEmptyArray`s using the provided `isEquivalent` function.\n *\n * @category grouping\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Iterable<NonEmptyArray<A>>\n} = dual(\n 2,\n <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Iterable<NonEmptyArray<A>> => ({\n [Symbol.iterator]() {\n const iterator = self[Symbol.iterator]()\n let nextResult: IteratorResult<A> | undefined\n return {\n next() {\n let result: IteratorResult<A>\n if (nextResult !== undefined) {\n if (nextResult.done) {\n return { done: true, value: undefined }\n }\n result = nextResult\n nextResult = undefined\n } else {\n result = iterator.next()\n if (result.done) {\n return { done: true, value: undefined }\n }\n }\n const chunk: NonEmptyArray<A> = [result.value]\n\n while (true) {\n const next = iterator.next()\n if (next.done || !isEquivalent(result.value, next.value)) {\n nextResult = next\n return { done: false, value: chunk }\n }\n chunk.push(next.value)\n }\n }\n }\n }\n })\n)\n\n/**\n * Group equal, consecutive elements of an `Iterable` into `NonEmptyArray`s.\n *\n * @category grouping\n * @since 2.0.0\n */\nexport const group: <A>(self: Iterable<A>) => Iterable<NonEmptyArray<A>> = groupWith(\n Equal.equivalence()\n)\n\n/**\n * Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning\n * function on each element, and grouping the results according to values returned\n *\n * @category grouping\n * @since 2.0.0\n */\nexport const groupBy: {\n /**\n * Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning\n * function on each element, and grouping the results according to values returned\n *\n * @category grouping\n * @since 2.0.0\n */\n <A, K extends string | symbol>(\n f: (a: A) => K\n ): (self: Iterable<A>) => Record<Record.ReadonlyRecord.NonLiteralKey<K>, NonEmptyArray<A>>\n /**\n * Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning\n * function on each element, and grouping the results according to values returned\n *\n * @category grouping\n * @since 2.0.0\n */\n <A, K extends string | symbol>(\n self: Iterable<A>,\n f: (a: A) => K\n ): Record<Record.ReadonlyRecord.NonLiteralKey<K>, NonEmptyArray<A>>\n} = dual(2, <A, K extends string | symbol>(\n self: Iterable<A>,\n f: (a: A) => K\n): Record<Record.ReadonlyRecord.NonLiteralKey<K>, NonEmptyArray<A>> => {\n const out: Record<string | symbol, NonEmptyArray<A>> = {}\n for (const a of self) {\n const k = f(a)\n if (Object.prototype.hasOwnProperty.call(out, k)) {\n out[k].push(a)\n } else {\n out[k] = [a]\n }\n }\n return out\n})\n\nconst constEmpty: Iterable<never> = {\n [Symbol.iterator]() {\n return constEmptyIterator\n }\n}\nconst constEmptyIterator: Iterator<never> = {\n next() {\n return { done: true, value: undefined }\n }\n}\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const empty = <A = never>(): Iterable<A> => constEmpty\n\n/**\n * Constructs a new `Iterable<A>` from the specified value.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const of = <A>(a: A): Iterable<A> => [a]\n\n/**\n * @category mapping\n * @since 2.0.0\n */\nexport const map: {\n /**\n * @category mapping\n * @since 2.0.0\n */\n <A, B>(f: (a: NoInfer<A>, i: number) => B): (self: Iterable<A>) => Iterable<B>\n /**\n * @category mapping\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: NoInfer<A>, i: number) => B): Iterable<B>\n} = dual(2, <A, B>(self: Iterable<A>, f: (a: A, i: number) => B): Iterable<B> => ({\n [Symbol.iterator]() {\n const iterator = self[Symbol.iterator]()\n let i = 0\n return {\n next() {\n const result = iterator.next()\n if (result.done) {\n return { done: true, value: undefined }\n }\n return { done: false, value: f(result.value, i++) }\n }\n }\n }\n}))\n\n/**\n * Applies a function to each element in an Iterable and returns a new Iterable containing the concatenated mapped elements.\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatMap: {\n /**\n * Applies a function to each element in an Iterable and returns a new Iterable containing the concatenated mapped elements.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: NoInfer<A>, i: number) => Iterable<B>): (self: Iterable<A>) => Iterable<B>\n /**\n * Applies a function to each element in an Iterable and returns a new Iterable containing the concatenated mapped elements.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: NoInfer<A>, i: number) => Iterable<B>): Iterable<B>\n} = dual(\n 2,\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Iterable<B>): Iterable<B> => flatten(map(self, f))\n)\n\n/**\n * Flattens an Iterable of Iterables into a single Iterable\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatten = <A>(self: Iterable<Iterable<A>>): Iterable<A> => ({\n [Symbol.iterator]() {\n const outerIterator = self[Symbol.iterator]()\n let innerIterator: Iterator<A> | undefined\n function next() {\n if (innerIterator === undefined) {\n const next = outerIterator.next()\n if (next.done) {\n return next\n }\n innerIterator = next.value[Symbol.iterator]()\n }\n const result = innerIterator.next()\n if (result.done) {\n innerIterator = undefined\n return next()\n }\n return result\n }\n return { next }\n }\n})\n\n/**\n * @category filtering\n * @since 2.0.0\n */\nexport const filterMap: {\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(f: (a: A, i: number) => Option<B>): (self: Iterable<A>) => Iterable<B>\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Iterable<B>\n} = dual(\n 2,\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Iterable<B> => ({\n [Symbol.iterator]() {\n const iterator = self[Symbol.iterator]()\n let i = 0\n return {\n next() {\n let result = iterator.next()\n while (!result.done) {\n const b = f(result.value, i++)\n if (O.isSome(b)) {\n return { done: false, value: b.value }\n }\n result = iterator.next()\n }\n return { done: true, value: undefined }\n }\n }\n }\n })\n)\n\n/**\n * Transforms all elements of the `Iterable` for as long as the specified function returns some value\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const filterMapWhile: {\n /**\n * Transforms all elements of the `Iterable` for as long as the specified function returns some value\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(f: (a: A, i: number) => Option<B>): (self: Iterable<A>) => Iterable<B>\n /**\n * Transforms all elements of the `Iterable` for as long as the specified function returns some value\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Iterable<B>\n} = dual(2, <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>) => ({\n [Symbol.iterator]() {\n const iterator = self[Symbol.iterator]()\n let i = 0\n return {\n next() {\n const result = iterator.next()\n if (result.done) {\n return { done: true, value: undefined }\n }\n const b = f(result.value, i++)\n if (O.isSome(b)) {\n return { done: false, value: b.value }\n }\n return { done: true, value: undefined }\n }\n }\n }\n}))\n\n/**\n * Retrieves the `Some` values from an `Iterable` of `Option`s.\n *\n * @example\n * ```ts\n * import { Iterable, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Array.from(Iterable.getSomes([Option.some(1), Option.none(), Option.some(2)])),\n * [1, 2]\n * )\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const getSomes: <A>(self: Iterable<Option<A>>) => Iterable<A> = filterMap(identity)\n\n/**\n * Retrieves the `Left` values from an `Iterable` of `Either`s.\n *\n * @example\n * ```ts\n * import { Iterable, Either } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Array.from(Iterable.getLefts([Either.right(1), Either.left(\"err\"), Either.right(2)])),\n * [\"err\"]\n * )\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const getLefts = <R, L>(self: Iterable<Either<R, L>>): Iterable<L> => filterMap(self, E.getLeft)\n\n/**\n * Retrieves the `Right` values from an `Iterable` of `Either`s.\n *\n * @example\n * ```ts\n * import { Iterable, Either } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Array.from(Iterable.getRights([Either.right(1), Either.left(\"err\"), Either.right(2)])),\n * [1, 2]\n * )\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const getRights = <R, L>(self: Iterable<Either<R, L>>): Iterable<R> => filterMap(self, E.getRight)\n\n/**\n * @category filtering\n * @since 2.0.0\n */\nexport const filter: {\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Iterable<B>\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Iterable<A>\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Iterable<B>\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Iterable<A>\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Iterable<A> => ({\n [Symbol.iterator]() {\n const iterator = self[Symbol.iterator]()\n let i = 0\n return {\n next() {\n let result = iterator.next()\n while (!result.done) {\n if (predicate(result.value, i++)) {\n return { done: false, value: result.value }\n }\n result = iterator.next()\n }\n return { done: true, value: undefined }\n }\n }\n }\n })\n)\n\n/**\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatMapNullable: {\n /**\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B | null | undefined): (self: Iterable<A>) => Iterable<NonNullable<B>>\n /**\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A) => B | null | undefined): Iterable<NonNullable<B>>\n} = dual(\n 2,\n <A, B>(self: Iterable<A>, f: (a: A) => B | null | undefined): Iterable<NonNullable<B>> =>\n filterMap(self, (a) => {\n const b = f(a)\n return b == null ? O.none() : O.some(b)\n })\n)\n\n/**\n * Check if a predicate holds true for some `Iterable` element.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const some: {\n /**\n * Check if a predicate holds true for some `Iterable` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: A, i: number) => boolean): (self: Iterable<A>) => boolean\n /**\n * Check if a predicate holds true for some `Iterable` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): boolean\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): boolean => {\n let i = 0\n for (const a of self) {\n if (predicate(a, i++)) {\n return true\n }\n }\n return false\n }\n)\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const unfold = <B, A>(b: B, f: (b: B) => Option<readonly [A, B]>): Iterable<A> => ({\n [Symbol.iterator]() {\n let next = b\n return {\n next() {\n const o = f(next)\n if (O.isNone(o)) {\n return { done: true, value: undefined }\n }\n const [a, b] = o.value\n next = b\n return { done: false, value: a }\n }\n }\n }\n})\n\n/**\n * Iterate over the `Iterable` applying `f`.\n *\n * @since 2.0.0\n */\nexport const forEach: {\n /**\n * Iterate over the `Iterable` applying `f`.\n *\n * @since 2.0.0\n */\n <A>(f: (a: A, i: number) => void): (self: Iterable<A>) => void\n /**\n * Iterate over the `Iterable` applying `f`.\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, f: (a: A, i: number) => void): void\n} = dual(2, <A>(self: Iterable<A>, f: (a: A, i: number) => void): void => {\n let i = 0\n for (const a of self) {\n f(a, i++)\n }\n})\n\n/**\n * @category folding\n * @since 2.0.0\n */\nexport const reduce: {\n /**\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Iterable<A>) => B\n /**\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B\n} = dual(3, <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B => {\n if (Array.isArray(self)) {\n return self.reduce(f, b)\n }\n let i = 0\n let result = b\n for (const n of self) {\n result = f(result, n, i++)\n }\n return result\n})\n\n/**\n * Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.\n *\n * @since 2.0.0\n */\nexport const dedupeAdjacentWith: {\n /**\n * Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.\n *\n * @since 2.0.0\n */\n <A>(isEquivalent: (self: A, that: A) => boolean): (self: Iterable<A>) => Iterable<A>\n /**\n * Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Iterable<A>\n} = dual(2, <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Iterable<A> => ({\n [Symbol.iterator]() {\n const iterator = self[Symbol.iterator]()\n let first = true\n let last: A\n function next(): IteratorResult<A> {\n const result = iterator.next()\n if (result.done) {\n return { done: true, value: undefined }\n }\n if (first) {\n first = false\n last = result.value\n return result\n }\n const current = result.value\n if (isEquivalent(last, current)) {\n return next()\n }\n last = current\n return result\n }\n return { next }\n }\n}))\n\n/**\n * Deduplicates adjacent elements that are identical.\n *\n * @since 2.0.0\n */\nexport const dedupeAdjacent: <A>(self: Iterable<A>) => Iterable<A> = dedupeAdjacentWith(Equal.equivalence())\n\n/**\n * Zips this Iterable crosswise with the specified Iterable using the specified combiner.\n *\n * @since 2.0.0\n * @category elements\n */\nexport const cartesianWith: {\n /**\n * Zips this Iterable crosswise with the specified Iterable using the specified combiner.\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Iterable<C>\n /**\n * Zips this Iterable crosswise with the specified Iterable using the specified combiner.\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Iterable<C>\n} = dual(\n 3,\n <A, B, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Iterable<C> =>\n flatMap(self, (a) => map(that, (b) => f(a, b)))\n)\n\n/**\n * Zips this Iterable crosswise with the specified Iterable.\n *\n * @since 2.0.0\n * @category elements\n */\nexport const cartesian: {\n /**\n * Zips this Iterable crosswise with the specified Iterable.\n *\n * @since 2.0.0\n * @category elements\n */\n <B>(that: Iterable<B>): <A>(self: Iterable<A>) => Iterable<[A, B]>\n /**\n * Zips this Iterable crosswise with the specified Iterable.\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Iterable<[A, B]>\n} = dual(\n 2,\n <A, B>(self: Iterable<A>, that: Iterable<B>): Iterable<[A, B]> => cartesianWith(self, that, (a, b) => [a, b])\n)\n","/**\n * This module provides utility functions for working with arrays in TypeScript.\n *\n * @since 2.0.0\n */\n\nimport type { Either as array_ } from \"./Either.js\"\nimport * as E from \"./Either.js\"\nimport * as Equal from \"./Equal.js\"\nimport * as Equivalence from \"./Equivalence.js\"\nimport type { LazyArg } from \"./Function.js\"\nimport { dual, identity } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\nimport * as readonlyArray from \"./internal/array.js\"\nimport * as doNotation from \"./internal/doNotation.js\"\nimport * as EffectIterable from \"./Iterable.js\"\nimport type { Option } from \"./Option.js\"\nimport * as O from \"./Option.js\"\nimport * as Order from \"./Order.js\"\nimport type { Predicate, Refinement } from \"./Predicate.js\"\nimport { isBoolean } from \"./Predicate.js\"\nimport * as Record from \"./Record.js\"\nimport * as Tuple from \"./Tuple.js\"\nimport type { NoInfer } from \"./Types.js\"\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface ReadonlyArrayTypeLambda extends TypeLambda {\n readonly type: ReadonlyArray<this[\"Target\"]>\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport type NonEmptyReadonlyArray<A> = readonly [A, ...Array<A>]\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport type NonEmptyArray<A> = [A, ...Array<A>]\n\n/**\n * Builds a `NonEmptyArray` from an non-empty collection of elements.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.make(1, 2, 3)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const make = <Elements extends NonEmptyArray<any>>(\n ...elements: Elements\n): NonEmptyArray<Elements[number]> => elements\n\n/**\n * Creates a new `Array` of the specified length.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.allocate<number>(3)\n * assert.deepStrictEqual(result.length, 3)\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const allocate = <A = never>(n: number): Array<A | undefined> => new Array(n)\n\n/**\n * Return a `NonEmptyArray` of length `n` with element `i` initialized with `f(i)`.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * @example\n * ```ts\n * import { makeBy } from \"effect/Array\"\n *\n * assert.deepStrictEqual(makeBy(5, n => n * 2), [0, 2, 4, 6, 8])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const makeBy = <A>(n: number, f: (i: number) => A): NonEmptyArray<A> => {\n const max = Math.max(1, Math.floor(n))\n const out = new Array(max)\n for (let i = 0; i < max; i++) {\n out[i] = f(i)\n }\n return out as NonEmptyArray<A>\n}\n\n/**\n * Return a `NonEmptyArray` containing a range of integers, including both endpoints.\n *\n * @example\n * ```ts\n * import { range } from \"effect/Array\"\n *\n * assert.deepStrictEqual(range(1, 3), [1, 2, 3])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const range = (start: number, end: number): NonEmptyArray<number> =>\n start <= end ? makeBy(end - start + 1, (i) => start + i) : [start]\n\n/**\n * Return a `NonEmptyArray` containing a value repeated the specified number of times.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * assert.deepStrictEqual(Array.replicate(\"a\", 3), [\"a\", \"a\", \"a\"])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const replicate: {\n /**\n * Return a `NonEmptyArray` containing a value repeated the specified number of times.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * assert.deepStrictEqual(Array.replicate(\"a\", 3), [\"a\", \"a\", \"a\"])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n (n: number): <A>(a: A) => NonEmptyArray<A>\n /**\n * Return a `NonEmptyArray` containing a value repeated the specified number of times.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * assert.deepStrictEqual(Array.replicate(\"a\", 3), [\"a\", \"a\", \"a\"])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <A>(a: A, n: number): NonEmptyArray<A>\n} = dual(2, <A>(a: A, n: number): NonEmptyArray<A> => makeBy(n, () => a))\n\n/**\n * Creates a new `Array` from an iterable collection of values.\n * If the input is already an array, it returns the input as-is.\n * Otherwise, it converts the iterable collection to an array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const set = new Set([1, 2, 3])\n * const result = Array.fromIterable(set)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const fromIterable = <A>(collection: Iterable<A>): Array<A> =>\n Array.isArray(collection) ? collection : Array.from(collection)\n\n/**\n * Creates a new `Array` from a value that might not be an iterable.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * assert.deepStrictEqual(Array.ensure(\"a\"), [\"a\"])\n * assert.deepStrictEqual(Array.ensure([\"a\"]), [\"a\"])\n * assert.deepStrictEqual(Array.ensure([\"a\", \"b\", \"c\"]), [\"a\", \"b\", \"c\"])\n * ```\n *\n * @category constructors\n * @since 3.3.0\n */\nexport const ensure = <A>(self: ReadonlyArray<A> | A): Array<A> => Array.isArray(self) ? self : [self as A]\n\n/**\n * Takes a record and returns an array of tuples containing its keys and values.\n *\n * @param self - The record to transform.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const x = { a: 1, b: 2, c: 3 }\n * assert.deepStrictEqual(Array.fromRecord(x), [[\"a\", 1], [\"b\", 2], [\"c\", 3]])\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const fromRecord: <K extends string, A>(self: Readonly<Record<K, A>>) => Array<[K, A]> = Record.toEntries\n\n/**\n * Converts an `Option` to an array.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Array.fromOption(Option.some(1)), [1])\n * assert.deepStrictEqual(Array.fromOption(Option.none()), [])\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const fromOption: <A>(self: Option<A>) => Array<A> = O.toArray\n\n/**\n * Matches the elements of an array, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const match = Array.match({\n * onEmpty: () => \"empty\",\n * onNonEmpty: ([head, ...tail]) => `head: ${head}, tail: ${tail.length}`\n * })\n * assert.deepStrictEqual(match([]), \"empty\")\n * assert.deepStrictEqual(match([1, 2, 3]), \"head: 1, tail: 2\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\nexport const match: {\n /**\n * Matches the elements of an array, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const match = Array.match({\n * onEmpty: () => \"empty\",\n * onNonEmpty: ([head, ...tail]) => `head: ${head}, tail: ${tail.length}`\n * })\n * assert.deepStrictEqual(match([]), \"empty\")\n * assert.deepStrictEqual(match([1, 2, 3]), \"head: 1, tail: 2\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <B, A, C = B>(\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (self: NonEmptyReadonlyArray<A>) => C\n }\n ): (self: ReadonlyArray<A>) => B | C\n /**\n * Matches the elements of an array, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const match = Array.match({\n * onEmpty: () => \"empty\",\n * onNonEmpty: ([head, ...tail]) => `head: ${head}, tail: ${tail.length}`\n * })\n * assert.deepStrictEqual(match([]), \"empty\")\n * assert.deepStrictEqual(match([1, 2, 3]), \"head: 1, tail: 2\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <A, B, C = B>(\n self: ReadonlyArray<A>,\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (self: NonEmptyReadonlyArray<A>) => C\n }\n ): B | C\n} = dual(2, <A, B, C = B>(\n self: ReadonlyArray<A>,\n { onEmpty, onNonEmpty }: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (self: NonEmptyReadonlyArray<A>) => C\n }\n): B | C => isNonEmptyReadonlyArray(self) ? onNonEmpty(self) : onEmpty())\n\n/**\n * Matches the elements of an array from the left, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchLeft = Array.matchLeft({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (head, tail) => `head: ${head}, tail: ${tail.length}`\n * })\n * assert.deepStrictEqual(matchLeft([]), \"empty\")\n * assert.deepStrictEqual(matchLeft([1, 2, 3]), \"head: 1, tail: 2\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\nexport const matchLeft: {\n /**\n * Matches the elements of an array from the left, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchLeft = Array.matchLeft({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (head, tail) => `head: ${head}, tail: ${tail.length}`\n * })\n * assert.deepStrictEqual(matchLeft([]), \"empty\")\n * assert.deepStrictEqual(matchLeft([1, 2, 3]), \"head: 1, tail: 2\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <B, A, C = B>(\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (head: A, tail: Array<A>) => C\n }\n ): (self: ReadonlyArray<A>) => B | C\n /**\n * Matches the elements of an array from the left, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchLeft = Array.matchLeft({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (head, tail) => `head: ${head}, tail: ${tail.length}`\n * })\n * assert.deepStrictEqual(matchLeft([]), \"empty\")\n * assert.deepStrictEqual(matchLeft([1, 2, 3]), \"head: 1, tail: 2\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <A, B, C = B>(\n self: ReadonlyArray<A>,\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (head: A, tail: Array<A>) => C\n }\n ): B | C\n} = dual(2, <A, B, C = B>(\n self: ReadonlyArray<A>,\n { onEmpty, onNonEmpty }: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (head: A, tail: Array<A>) => C\n }\n): B | C => isNonEmptyReadonlyArray(self) ? onNonEmpty(headNonEmpty(self), tailNonEmpty(self)) : onEmpty())\n\n/**\n * Matches the elements of an array from the right, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchRight = Array.matchRight({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (init, last) => `init: ${init.length}, last: ${last}`\n * })\n * assert.deepStrictEqual(matchRight([]), \"empty\")\n * assert.deepStrictEqual(matchRight([1, 2, 3]), \"init: 2, last: 3\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\nexport const matchRight: {\n /**\n * Matches the elements of an array from the right, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchRight = Array.matchRight({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (init, last) => `init: ${init.length}, last: ${last}`\n * })\n * assert.deepStrictEqual(matchRight([]), \"empty\")\n * assert.deepStrictEqual(matchRight([1, 2, 3]), \"init: 2, last: 3\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <B, A, C = B>(\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (init: Array<A>, last: A) => C\n }\n ): (self: ReadonlyArray<A>) => B | C\n /**\n * Matches the elements of an array from the right, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchRight = Array.matchRight({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (init, last) => `init: ${init.length}, last: ${last}`\n * })\n * assert.deepStrictEqual(matchRight([]), \"empty\")\n * assert.deepStrictEqual(matchRight([1, 2, 3]), \"init: 2, last: 3\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <A, B, C = B>(\n self: ReadonlyArray<A>,\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (init: Array<A>, last: A) => C\n }\n ): B | C\n} = dual(2, <A, B, C = B>(\n self: ReadonlyArray<A>,\n { onEmpty, onNonEmpty }: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (init: Array<A>, last: A) => C\n }\n): B | C =>\n isNonEmptyReadonlyArray(self) ?\n onNonEmpty(initNonEmpty(self), lastNonEmpty(self)) :\n onEmpty())\n\n/**\n * Prepend an element to the front of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const original = [2, 3, 4];\n * const result = Array.prepend(original, 1);\n * assert.deepStrictEqual(result, [1, 2, 3, 4]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const prepend: {\n /**\n * Prepend an element to the front of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const original = [2, 3, 4];\n * const result = Array.prepend(original, 1);\n * assert.deepStrictEqual(result, [1, 2, 3, 4]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <B>(head: B): <A>(self: Iterable<A>) => NonEmptyArray<A | B>\n /**\n * Prepend an element to the front of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const original = [2, 3, 4];\n * const result = Array.prepend(original, 1);\n * assert.deepStrictEqual(result, [1, 2, 3, 4]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, head: B): NonEmptyArray<A | B>\n} = dual(2, <A, B>(self: Iterable<A>, head: B): NonEmptyArray<A | B> => [head, ...self])\n\n/**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const prefix = [0, 1];\n * const array = [2, 3];\n * const result = Array.prependAll(array, prefix);\n * assert.deepStrictEqual(result, [0, 1, 2, 3]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const prependAll: {\n /**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const prefix = [0, 1];\n * const array = [2, 3];\n * const result = Array.prependAll(array, prefix);\n * assert.deepStrictEqual(result, [0, 1, 2, 3]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <S extends Iterable<any>, T extends Iterable<any>>(\n that: T\n ): (self: S) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>\n /**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const prefix = [0, 1];\n * const array = [2, 3];\n * const result = Array.prependAll(array, prefix);\n * assert.deepStrictEqual(result, [0, 1, 2, 3]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<A | B>\n /**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const prefix = [0, 1];\n * const array = [2, 3];\n * const result = Array.prependAll(array, prefix);\n * assert.deepStrictEqual(result, [0, 1, 2, 3]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, that: Iterable<B>): NonEmptyArray<A | B>\n /**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const prefix = [0, 1];\n * const array = [2, 3];\n * const result = Array.prependAll(array, prefix);\n * assert.deepStrictEqual(result, [0, 1, 2, 3]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B>\n} = dual(\n 2,\n <A>(self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(that).concat(fromIterable(self))\n)\n\n/**\n * Append an element to the end of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const original = [1, 2, 3];\n * const result = Array.append(original, 4);\n * assert.deepStrictEqual(result, [1, 2, 3, 4]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const append: {\n /**\n * Append an element to the end of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const original = [1, 2, 3];\n * const result = Array.append(original, 4);\n * assert.deepStrictEqual(result, [1, 2, 3, 4]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <B>(last: B): <A>(self: Iterable<A>) => NonEmptyArray<A | B>\n /**\n * Append an element to the end of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const original = [1, 2, 3];\n * const result = Array.append(original, 4);\n * assert.deepStrictEqual(result, [1, 2, 3, 4]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, last: B): NonEmptyArray<A | B>\n} = dual(2, <A, B>(self: Iterable<A>, last: B): Array<A | B> => [...self, last])\n\n/**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const appendAll: {\n /**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <S extends Iterable<any>, T extends Iterable<any>>(\n that: T\n ): (self: S) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>\n /**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<A | B>\n /**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, that: Iterable<B>): NonEmptyArray<A | B>\n /**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B>\n} = dual(\n 2,\n <A>(self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(self).concat(fromIterable(that))\n)\n\n/**\n * Accumulates values from an `Iterable` starting from the left, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.scan(numbers, 0, (acc, value) => acc + value)\n * assert.deepStrictEqual(result, [0, 1, 3, 6, 10])\n *\n * // Explanation:\n * // This function starts with the initial value (0 in this case)\n * // and adds each element of the array to this accumulator one by one,\n * // keeping track of the cumulative sum after each addition.\n * // Each of these sums is captured in the resulting array.\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const scan: {\n /**\n * Accumulates values from an `Iterable` starting from the left, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.scan(numbers, 0, (acc, value) => acc + value)\n * assert.deepStrictEqual(result, [0, 1, 3, 6, 10])\n *\n * // Explanation:\n * // This function starts with the initial value (0 in this case)\n * // and adds each element of the array to this accumulator one by one,\n * // keeping track of the cumulative sum after each addition.\n * // Each of these sums is captured in the resulting array.\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A) => B): (self: Iterable<A>) => NonEmptyArray<B>\n /**\n * Accumulates values from an `Iterable` starting from the left, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.scan(numbers, 0, (acc, value) => acc + value)\n * assert.deepStrictEqual(result, [0, 1, 3, 6, 10])\n *\n * // Explanation:\n * // This function starts with the initial value (0 in this case)\n * // and adds each element of the array to this accumulator one by one,\n * // keeping track of the cumulative sum after each addition.\n * // Each of these sums is captured in the resulting array.\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B>\n} = dual(3, <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B> => {\n const out: NonEmptyArray<B> = [b]\n let i = 0\n for (const a of self) {\n out[i + 1] = f(out[i], a)\n i++\n }\n return out\n})\n\n/**\n * Accumulates values from an `Iterable` starting from the right, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.scanRight(numbers, 0, (acc, value) => acc + value)\n * assert.deepStrictEqual(result, [10, 9, 7, 4, 0])\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const scanRight: {\n /**\n * Accumulates values from an `Iterable` starting from the right, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.scanRight(numbers, 0, (acc, value) => acc + value)\n * assert.deepStrictEqual(result, [10, 9, 7, 4, 0])\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A) => B): (self: Iterable<A>) => NonEmptyArray<B>\n /**\n * Accumulates values from an `Iterable` starting from the right, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.scanRight(numbers, 0, (acc, value) => acc + value)\n * assert.deepStrictEqual(result, [10, 9, 7, 4, 0])\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B>\n} = dual(3, <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B> => {\n const input = fromIterable(self)\n const out: NonEmptyArray<B> = new Array(input.length + 1) as any\n out[input.length] = b\n for (let i = input.length - 1; i >= 0; i--) {\n out[i] = f(out[i + 1], input[i])\n }\n return out\n})\n\n/**\n * Determine if `unknown` is an Array.\n *\n * @param self - The value to check.\n *\n * @example\n * ```ts\n * import { isArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isArray(null), false);\n * assert.deepStrictEqual(isArray([1, 2, 3]), true);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isArray: {\n /**\n * Determine if `unknown` is an Array.\n *\n * @param self - The value to check.\n *\n * @example\n * ```ts\n * import { isArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isArray(null), false);\n * assert.deepStrictEqual(isArray([1, 2, 3]), true);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\n (self: unknown): self is Array<unknown>\n /**\n * Determine if `unknown` is an Array.\n *\n * @param self - The value to check.\n *\n * @example\n * ```ts\n * import { isArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isArray(null), false);\n * assert.deepStrictEqual(isArray([1, 2, 3]), true);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\n <T>(self: T): self is Extract<T, ReadonlyArray<any>>\n} = Array.isArray\n\n/**\n * Determine if an `Array` is empty narrowing down the type to `[]`.\n *\n * @param self - The `Array` to check.\n *\n * @example\n * ```ts\n * import { isEmptyArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isEmptyArray([]), true);\n * assert.deepStrictEqual(isEmptyArray([1, 2, 3]), false);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isEmptyArray = <A>(self: Array<A>): self is [] => self.length === 0\n\n/**\n * Determine if a `ReadonlyArray` is empty narrowing down the type to `readonly []`.\n *\n * @param self - The `ReadonlyArray` to check.\n *\n * @example\n * ```ts\n * import { isEmptyReadonlyArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isEmptyReadonlyArray([]), true);\n * assert.deepStrictEqual(isEmptyReadonlyArray([1, 2, 3]), false);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isEmptyReadonlyArray: <A>(self: ReadonlyArray<A>) => self is readonly [] = isEmptyArray as any\n\n/**\n * Determine if an `Array` is non empty narrowing down the type to `NonEmptyArray`.\n *\n * An `Array` is considered to be a `NonEmptyArray` if it contains at least one element.\n *\n * @param self - The `Array` to check.\n *\n * @example\n * ```ts\n * import { isNonEmptyArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isNonEmptyArray([]), false);\n * assert.deepStrictEqual(isNonEmptyArray([1, 2, 3]), true);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNonEmptyArray: <A>(self: Array<A>) => self is NonEmptyArray<A> = readonlyArray.isNonEmptyArray\n\n/**\n * Determine if a `ReadonlyArray` is non empty narrowing down the type to `NonEmptyReadonlyArray`.\n *\n * A `ReadonlyArray` is considered to be a `NonEmptyReadonlyArray` if it contains at least one element.\n *\n * @param self - The `ReadonlyArray` to check.\n *\n * @example\n * ```ts\n * import { isNonEmptyReadonlyArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isNonEmptyReadonlyArray([]), false);\n * assert.deepStrictEqual(isNonEmptyReadonlyArray([1, 2, 3]), true);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNonEmptyReadonlyArray: <A>(self: ReadonlyArray<A>) => self is NonEmptyReadonlyArray<A> =\n readonlyArray.isNonEmptyArray\n\n/**\n * Return the number of elements in a `ReadonlyArray`.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const length = <A>(self: ReadonlyArray<A>): number => self.length\n\nconst isOutOfBound = <A>(i: number, as: ReadonlyArray<A>): boolean => i < 0 || i >= as.length\n\nconst clamp = <A>(i: number, as: ReadonlyArray<A>): number => Math.floor(Math.min(Math.max(0, i), as.length))\n\n/**\n * This function provides a safe way to read a value at a particular index from a `ReadonlyArray`.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const get: {\n /**\n * This function provides a safe way to read a value at a particular index from a `ReadonlyArray`.\n *\n * @category getters\n * @since 2.0.0\n */\n (index: number): <A>(self: ReadonlyArray<A>) => Option<A>\n /**\n * This function provides a safe way to read a value at a particular index from a `ReadonlyArray`.\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: ReadonlyArray<A>, index: number): Option<A>\n} = dual(2, <A>(self: ReadonlyArray<A>, index: number): Option<A> => {\n const i = Math.floor(index)\n return isOutOfBound(i, self) ? O.none() : O.some(self[i])\n})\n\n/**\n * Gets an element unsafely, will throw on out of bounds.\n *\n * @since 2.0.0\n * @category unsafe\n */\nexport const unsafeGet: {\n /**\n * Gets an element unsafely, will throw on out of bounds.\n *\n * @since 2.0.0\n * @category unsafe\n */\n (index: number): <A>(self: ReadonlyArray<A>) => A\n /**\n * Gets an element unsafely, will throw on out of bounds.\n *\n * @since 2.0.0\n * @category unsafe\n */\n <A>(self: ReadonlyArray<A>, index: number): A\n} = dual(2, <A>(self: ReadonlyArray<A>, index: number): A => {\n const i = Math.floor(index)\n if (isOutOfBound(i, self)) {\n throw new Error(`Index ${i} out of bounds`)\n }\n return self[i]\n})\n\n/**\n * Return a tuple containing the first element, and a new `Array` of the remaining elements, if any.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.unprepend([1, 2, 3, 4])\n * assert.deepStrictEqual(result, [1, [2, 3, 4]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const unprepend = <A>(\n self: NonEmptyReadonlyArray<A>\n): [firstElement: A, remainingElements: Array<A>] => [headNonEmpty(self), tailNonEmpty(self)]\n\n/**\n * Return a tuple containing a copy of the `NonEmptyReadonlyArray` without its last element, and that last element.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.unappend([1, 2, 3, 4])\n * assert.deepStrictEqual(result, [[1, 2, 3], 4])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const unappend = <A>(\n self: NonEmptyReadonlyArray<A>\n): [arrayWithoutLastElement: Array<A>, lastElement: A] => [initNonEmpty(self), lastNonEmpty(self)]\n\n/**\n * Get the first element of a `ReadonlyArray`, or `None` if the `ReadonlyArray` is empty.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const head: <A>(self: ReadonlyArray<A>) => Option<A> = get(0)\n\n/**\n * Get the first element of a non empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.headNonEmpty([1, 2, 3, 4])\n * assert.deepStrictEqual(result, 1)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const headNonEmpty: <A>(self: NonEmptyReadonlyArray<A>) => A = unsafeGet(0)\n\n/**\n * Get the last element in a `ReadonlyArray`, or `None` if the `ReadonlyArray` is empty.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const last = <A>(self: ReadonlyArray<A>): Option<A> =>\n isNonEmptyReadonlyArray(self) ? O.some(lastNonEmpty(self)) : O.none()\n\n/**\n * Get the last element of a non empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.lastNonEmpty([1, 2, 3, 4])\n * assert.deepStrictEqual(result, 4)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const lastNonEmpty = <A>(self: NonEmptyReadonlyArray<A>): A => self[self.length - 1]\n\n/**\n * Get all but the first element of an `Iterable`, creating a new `Array`, or `None` if the `Iterable` is empty.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const tail = <A>(self: Iterable<A>): Option<Array<A>> => {\n const input = fromIterable(self)\n return isNonEmptyReadonlyArray(input) ? O.some(tailNonEmpty(input)) : O.none()\n}\n\n/**\n * Get all but the first element of a `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.tailNonEmpty([1, 2, 3, 4])\n * assert.deepStrictEqual(result, [2, 3, 4])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const tailNonEmpty = <A>(self: NonEmptyReadonlyArray<A>): Array<A> => self.slice(1)\n\n/**\n * Get all but the last element of an `Iterable`, creating a new `Array`, or `None` if the `Iterable` is empty.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const init = <A>(self: Iterable<A>): Option<Array<A>> => {\n const input = fromIterable(self)\n return isNonEmptyReadonlyArray(input) ? O.some(initNonEmpty(input)) : O.none()\n}\n\n/**\n * Get all but the last element of a non empty array, creating a new array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.initNonEmpty([1, 2, 3, 4])\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const initNonEmpty = <A>(self: NonEmptyReadonlyArray<A>): Array<A> => self.slice(0, -1)\n\n/**\n * Keep only a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.take(numbers, 3)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const take: {\n /**\n * Keep only a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.take(numbers, 3)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Keep only a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.take(numbers, 3)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n return input.slice(0, clamp(n, input))\n})\n\n/**\n * Keep only a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.takeRight(numbers, 3)\n * assert.deepStrictEqual(result, [3, 4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const takeRight: {\n /**\n * Keep only a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.takeRight(numbers, 3)\n * assert.deepStrictEqual(result, [3, 4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Keep only a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.takeRight(numbers, 3)\n * assert.deepStrictEqual(result, [3, 4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n const i = clamp(n, input)\n return i === 0 ? [] : input.slice(-i)\n})\n\n/**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 3, 2, 4, 1, 2]\n * const result = Array.takeWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [1, 3, 2])\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const takeWhile: {\n /**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 3, 2, 4, 1, 2]\n * const result = Array.takeWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [1, 3, 2])\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Array<B>\n /**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 3, 2, 4, 1, 2]\n * const result = Array.takeWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [1, 3, 2])\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Array<A>\n /**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 3, 2, 4, 1, 2]\n * const result = Array.takeWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [1, 3, 2])\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Array<B>\n /**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 3, 2, 4, 1, 2]\n * const result = Array.takeWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [1, 3, 2])\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A>\n} = dual(2, <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A> => {\n let i = 0\n const out: Array<A> = []\n for (const a of self) {\n if (!predicate(a, i)) {\n break\n }\n out.push(a)\n i++\n }\n return out\n})\n\nconst spanIndex = <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): number => {\n let i = 0\n for (const a of self) {\n if (!predicate(a, i)) {\n break\n }\n i++\n }\n return i\n}\n\n/**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const span: {\n /**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\n <A, B extends A>(\n refinement: (a: NoInfer<A>, i: number) => a is B\n ): (self: Iterable<A>) => [init: Array<B>, rest: Array<Exclude<A, B>>]\n /**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => [init: Array<A>, rest: Array<A>]\n /**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\n <A, B extends A>(\n self: Iterable<A>,\n refinement: (a: A, i: number) => a is B\n ): [init: Array<B>, rest: Array<Exclude<A, B>>]\n /**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [init: Array<A>, rest: Array<A>]\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [init: Array<A>, rest: Array<A>] =>\n splitAt(self, spanIndex(self, predicate))\n)\n\n/**\n * Drop a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.drop(numbers, 2)\n * assert.deepStrictEqual(result, [3, 4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const drop: {\n /**\n * Drop a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.drop(numbers, 2)\n * assert.deepStrictEqual(result, [3, 4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Drop a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.drop(numbers, 2)\n * assert.deepStrictEqual(result, [3, 4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n return input.slice(clamp(n, input), input.length)\n})\n\n/**\n * Drop a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.dropRight(numbers, 2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const dropRight: {\n /**\n * Drop a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.dropRight(numbers, 2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Drop a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.dropRight(numbers, 2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n return input.slice(0, input.length - clamp(n, input))\n})\n\n/**\n * Remove the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.dropWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const dropWhile: {\n /**\n * Remove the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.dropWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Array<A>\n /**\n * Remove the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.dropWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A>\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A> =>\n fromIterable(self).slice(spanIndex(self, predicate))\n)\n\n/**\n * Return the first index for which a predicate holds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [5, 3, 8, 9]\n * const result = Array.findFirstIndex(numbers, x => x > 5)\n * assert.deepStrictEqual(result, Option.some(2))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findFirstIndex: {\n /**\n * Return the first index for which a predicate holds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [5, 3, 8, 9]\n * const result = Array.findFirstIndex(numbers, x => x > 5)\n * assert.deepStrictEqual(result, Option.some(2))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option<number>\n /**\n * Return the first index for which a predicate holds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [5, 3, 8, 9]\n * const result = Array.findFirstIndex(numbers, x => x > 5)\n * assert.deepStrictEqual(result, Option.some(2))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<number>\n} = dual(2, <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<number> => {\n let i = 0\n for (const a of self) {\n if (predicate(a, i)) {\n return O.some(i)\n }\n i++\n }\n return O.none()\n})\n\n/**\n * Return the last index for which a predicate holds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 3, 8, 9]\n * const result = Array.findLastIndex(numbers, x => x < 5)\n * assert.deepStrictEqual(result, Option.some(1))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findLastIndex: {\n /**\n * Return the last index for which a predicate holds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 3, 8, 9]\n * const result = Array.findLastIndex(numbers, x => x < 5)\n * assert.deepStrictEqual(result, Option.some(1))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option<number>\n /**\n * Return the last index for which a predicate holds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 3, 8, 9]\n * const result = Array.findLastIndex(numbers, x => x < 5)\n * assert.deepStrictEqual(result, Option.some(1))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<number>\n} = dual(2, <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<number> => {\n const input = fromIterable(self)\n for (let i = input.length - 1; i >= 0; i--) {\n if (predicate(input[i], i)) {\n return O.some(i)\n }\n }\n return O.none()\n})\n\n/**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findFirst: {\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(f: (a: NoInfer<A>, i: number) => Option<B>): (self: Iterable<A>) => Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option<A>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<A>\n} = EffectIterable.findFirst\n\n/**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findLast: {\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(f: (a: NoInfer<A>, i: number) => Option<B>): (self: Iterable<A>) => Option<B>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Option<B>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option<A>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Option<B>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Option<B>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<A>\n} = dual(\n 2,\n <A>(self: Iterable<A>, f: ((a: A, i: number) => boolean) | ((a: A, i: number) => Option<A>)): Option<A> => {\n const input = fromIterable(self)\n for (let i = input.length - 1; i >= 0; i--) {\n const a = input[i]\n const o = f(a, i)\n if (isBoolean(o)) {\n if (o) {\n return O.some(a)\n }\n } else {\n if (O.isSome(o)) {\n return o\n }\n }\n }\n return O.none()\n }\n)\n\n/**\n * Insert an element at the specified index, creating a new `NonEmptyArray`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'e']\n * const result = Array.insertAt(letters, 3, 'd')\n * assert.deepStrictEqual(result, Option.some(['a', 'b', 'c', 'd', 'e']))\n * ```\n *\n * @since 2.0.0\n */\nexport const insertAt: {\n /**\n * Insert an element at the specified index, creating a new `NonEmptyArray`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'e']\n * const result = Array.insertAt(letters, 3, 'd')\n * assert.deepStrictEqual(result, Option.some(['a', 'b', 'c', 'd', 'e']))\n * ```\n *\n * @since 2.0.0\n */\n <B>(i: number, b: B): <A>(self: Iterable<A>) => Option<NonEmptyArray<A | B>>\n /**\n * Insert an element at the specified index, creating a new `NonEmptyArray`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'e']\n * const result = Array.insertAt(letters, 3, 'd')\n * assert.deepStrictEqual(result, Option.some(['a', 'b', 'c', 'd', 'e']))\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, i: number, b: B): Option<NonEmptyArray<A | B>>\n} = dual(3, <A, B>(self: Iterable<A>, i: number, b: B): Option<NonEmptyArray<A | B>> => {\n const out: Array<A | B> = Array.from(self)\n // v--- `= self.length` is ok, it means inserting in last position\n if (i < 0 || i > out.length) {\n return O.none()\n }\n out.splice(i, 0, b)\n return O.some(out) as any\n})\n\n/**\n * Change the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.replace(letters, 1, 'z')\n * assert.deepStrictEqual(result, ['a', 'z', 'c', 'd'])\n * ```\n *\n * @since 2.0.0\n */\nexport const replace: {\n /**\n * Change the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.replace(letters, 1, 'z')\n * assert.deepStrictEqual(result, ['a', 'z', 'c', 'd'])\n * ```\n *\n * @since 2.0.0\n */\n <B>(i: number, b: B): <A, S extends Iterable<A> = Iterable<A>>(\n self: S\n ) => ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n /**\n * Change the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.replace(letters, 1, 'z')\n * assert.deepStrictEqual(result, ['a', 'z', 'c', 'd'])\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(\n self: S,\n i: number,\n b: B\n ): ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n} = dual(3, <A, B>(self: Iterable<A>, i: number, b: B): Array<A | B> => modify(self, i, () => b))\n\n/**\n * Replaces an element in an array with the given value, returning an option of the updated array.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.replaceOption(numbers, 1, 4)\n * assert.deepStrictEqual(result, Option.some([1, 4, 3]))\n * ```\n *\n * @since 2.0.0\n */\nexport const replaceOption: {\n /**\n * Replaces an element in an array with the given value, returning an option of the updated array.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.replaceOption(numbers, 1, 4)\n * assert.deepStrictEqual(result, Option.some([1, 4, 3]))\n * ```\n *\n * @since 2.0.0\n */\n <B>(\n i: number,\n b: B\n ): <A, S extends Iterable<A> = Iterable<A>>(self: S) => Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>\n /**\n * Replaces an element in an array with the given value, returning an option of the updated array.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.replaceOption(numbers, 1, 4)\n * assert.deepStrictEqual(result, Option.some([1, 4, 3]))\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(\n self: S,\n i: number,\n b: B\n ): Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>\n} = dual(\n 3,\n <A, B>(self: Iterable<A>, i: number, b: B): Option<Array<A | B>> => modifyOption(self, i, () => b)\n)\n\n/**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.modify(numbers, 2, (n) => n * 2)\n * assert.deepStrictEqual(result, [1, 2, 6, 4])\n * ```\n *\n * @since 2.0.0\n */\nexport const modify: {\n /**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.modify(numbers, 2, (n) => n * 2)\n * assert.deepStrictEqual(result, [1, 2, 6, 4])\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(\n i: number,\n f: (a: ReadonlyArray.Infer<S>) => B\n ): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n /**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.modify(numbers, 2, (n) => n * 2)\n * assert.deepStrictEqual(result, [1, 2, 6, 4])\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(\n self: S,\n i: number,\n f: (a: ReadonlyArray.Infer<S>) => B\n ): ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n} = dual(\n 3,\n <A, B>(self: Iterable<A>, i: number, f: (a: A) => B): Array<A | B> =>\n O.getOrElse(modifyOption(self, i, f), () => Array.from(self))\n)\n\n/**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.modifyOption(numbers, 2, (n) => n * 2)\n * assert.deepStrictEqual(result, Option.some([1, 2, 6, 4]))\n *\n * const outOfBoundsResult = Array.modifyOption(numbers, 5, (n) => n * 2)\n * assert.deepStrictEqual(outOfBoundsResult, Option.none())\n * ```\n *\n * @since 2.0.0\n */\nexport const modifyOption: {\n /**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.modifyOption(numbers, 2, (n) => n * 2)\n * assert.deepStrictEqual(result, Option.some([1, 2, 6, 4]))\n *\n * const outOfBoundsResult = Array.modifyOption(numbers, 5, (n) => n * 2)\n * assert.deepStrictEqual(outOfBoundsResult, Option.none())\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(\n i: number,\n f: (a: ReadonlyArray.Infer<S>) => B\n ): (self: S) => Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>\n /**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.modifyOption(numbers, 2, (n) => n * 2)\n * assert.deepStrictEqual(result, Option.some([1, 2, 6, 4]))\n *\n * const outOfBoundsResult = Array.modifyOption(numbers, 5, (n) => n * 2)\n * assert.deepStrictEqual(outOfBoundsResult, Option.none())\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(\n self: S,\n i: number,\n f: (a: ReadonlyArray.Infer<S>) => B\n ): Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>\n} = dual(3, <A, B>(self: Iterable<A>, i: number, f: (a: A) => B): Option<Array<A | B>> => {\n const out = Array.from(self)\n if (isOutOfBound(i, out)) {\n return O.none()\n }\n const next = f(out[i])\n // @ts-expect-error\n out[i] = next\n return O.some(out)\n})\n\n/**\n * Delete the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.remove(numbers, 2)\n * assert.deepStrictEqual(result, [1, 2, 4])\n *\n * const outOfBoundsResult = Array.remove(numbers, 5)\n * assert.deepStrictEqual(outOfBoundsResult, [1, 2, 3, 4])\n * ```\n *\n * @since 2.0.0\n */\nexport const remove: {\n /**\n * Delete the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.remove(numbers, 2)\n * assert.deepStrictEqual(result, [1, 2, 4])\n *\n * const outOfBoundsResult = Array.remove(numbers, 5)\n * assert.deepStrictEqual(outOfBoundsResult, [1, 2, 3, 4])\n * ```\n *\n * @since 2.0.0\n */\n (i: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Delete the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.remove(numbers, 2)\n * assert.deepStrictEqual(result, [1, 2, 4])\n *\n * const outOfBoundsResult = Array.remove(numbers, 5)\n * assert.deepStrictEqual(outOfBoundsResult, [1, 2, 3, 4])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, i: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, i: number): Array<A> => {\n const out = Array.from(self)\n if (isOutOfBound(i, out)) {\n return out\n }\n out.splice(i, 1)\n return out\n})\n\n/**\n * Reverse an `Iterable`, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.reverse(numbers)\n * assert.deepStrictEqual(result, [4, 3, 2, 1])\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const reverse = <S extends Iterable<any> | NonEmptyReadonlyArray<any>>(\n self: S\n): S extends NonEmptyReadonlyArray<infer A> ? NonEmptyArray<A> : S extends Iterable<infer A> ? Array<A> : never =>\n Array.from(self).reverse() as any\n\n/**\n * Create a new array with elements sorted in increasing order based on the specified comparator.\n * If the input is a `NonEmptyReadonlyArray`, the output will also be a `NonEmptyReadonlyArray`.\n *\n * @category sorting\n * @since 2.0.0\n */\nexport const sort: {\n /**\n * Create a new array with elements sorted in increasing order based on the specified comparator.\n * If the input is a `NonEmptyReadonlyArray`, the output will also be a `NonEmptyReadonlyArray`.\n *\n * @category sorting\n * @since 2.0.0\n */\n <B>(\n O: Order.Order<B>\n ): <A extends B, S extends ReadonlyArray<A> | Iterable<A>>(self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * Create a new array with elements sorted in increasing order based on the specified comparator.\n * If the input is a `NonEmptyReadonlyArray`, the output will also be a `NonEmptyReadonlyArray`.\n *\n * @category sorting\n * @since 2.0.0\n */\n <A extends B, B>(self: NonEmptyReadonlyArray<A>, O: Order.Order<B>): NonEmptyArray<A>\n /**\n * Create a new array with elements sorted in increasing order based on the specified comparator.\n * If the input is a `NonEmptyReadonlyArray`, the output will also be a `NonEmptyReadonlyArray`.\n *\n * @category sorting\n * @since 2.0.0\n */\n <A extends B, B>(self: Iterable<A>, O: Order.Order<B>): Array<A>\n} = dual(2, <A extends B, B>(self: Iterable<A>, O: Order.Order<B>): Array<A> => {\n const out = Array.from(self)\n out.sort(O)\n return out\n})\n\n/**\n * Sorts an array based on a provided mapping function and order. The mapping\n * function transforms the elements into a value that can be compared, and the\n * order defines how those values should be sorted.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const strings = [\"aaa\", \"b\", \"cc\"]\n * const result = Array.sortWith(strings, (s) => s.length, Order.number)\n * assert.deepStrictEqual(result, [\"b\", \"cc\", \"aaa\"])\n *\n * // Explanation:\n * // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`\n * // converts each string into its length, and the `Order.number` specifies that the lengths should\n * // be sorted in ascending order.\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\nexport const sortWith: {\n /**\n * Sorts an array based on a provided mapping function and order. The mapping\n * function transforms the elements into a value that can be compared, and the\n * order defines how those values should be sorted.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const strings = [\"aaa\", \"b\", \"cc\"]\n * const result = Array.sortWith(strings, (s) => s.length, Order.number)\n * assert.deepStrictEqual(result, [\"b\", \"cc\", \"aaa\"])\n *\n * // Explanation:\n * // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`\n * // converts each string into its length, and the `Order.number` specifies that the lengths should\n * // be sorted in ascending order.\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <S extends Iterable<any> | NonEmptyReadonlyArray<any>, B>(\n f: (a: ReadonlyArray.Infer<S>) => B,\n order: Order.Order<B>\n ): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * Sorts an array based on a provided mapping function and order. The mapping\n * function transforms the elements into a value that can be compared, and the\n * order defines how those values should be sorted.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const strings = [\"aaa\", \"b\", \"cc\"]\n * const result = Array.sortWith(strings, (s) => s.length, Order.number)\n * assert.deepStrictEqual(result, [\"b\", \"cc\", \"aaa\"])\n *\n * // Explanation:\n * // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`\n * // converts each string into its length, and the `Order.number` specifies that the lengths should\n * // be sorted in ascending order.\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B, O: Order.Order<B>): NonEmptyArray<A>\n /**\n * Sorts an array based on a provided mapping function and order. The mapping\n * function transforms the elements into a value that can be compared, and the\n * order defines how those values should be sorted.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const strings = [\"aaa\", \"b\", \"cc\"]\n * const result = Array.sortWith(strings, (s) => s.length, Order.number)\n * assert.deepStrictEqual(result, [\"b\", \"cc\", \"aaa\"])\n *\n * // Explanation:\n * // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`\n * // converts each string into its length, and the `Order.number` specifies that the lengths should\n * // be sorted in ascending order.\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B>(self: Iterable<A>, f: (a: A) => B, order: Order.Order<B>): Array<A>\n} = dual(\n 3,\n <A, B>(self: Iterable<A>, f: (a: A) => B, order: Order.Order<B>): Array<A> =>\n Array.from(self).map((a) => [a, f(a)] as const).sort((a, b) => order(a[1], b[1])).map((x) => x[0])\n)\n\n/**\n * Sorts the elements of an `Iterable` in increasing order based on the provided\n * orders. The elements are compared using the first order in `orders`, then the\n * second order if the first comparison is equal, and so on.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const users = [\n * { name: \"Alice\", age: 30 },\n * { name: \"Bob\", age: 25 },\n * { name: \"Charlie\", age: 30 }\n * ]\n *\n * const result = Array.sortBy(\n * Order.mapInput(Order.number, (user: (typeof users)[number]) => user.age),\n * Order.mapInput(Order.string, (user: (typeof users)[number]) => user.name)\n * )(users)\n *\n * assert.deepStrictEqual(result, [\n * { name: \"Bob\", age: 25 },\n * { name: \"Alice\", age: 30 },\n * { name: \"Charlie\", age: 30 }\n * ])\n *\n * // Explanation:\n * // The array of users is sorted first by age in ascending order. When ages are equal,\n * // the users are further sorted by name in ascending order.\n * ```\n *\n * @category sorting\n * @since 2.0.0\n */\nexport const sortBy = <S extends Iterable<any> | NonEmptyReadonlyArray<any>>(\n ...orders: ReadonlyArray<Order.Order<ReadonlyArray.Infer<S>>>\n) => {\n const sortByAll = sort(Order.combineAll(orders))\n return (\n self: S\n ): S extends NonEmptyReadonlyArray<infer A> ? NonEmptyArray<A> : S extends Iterable<infer A> ? Array<A> : never => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n return sortByAll(input) as any\n }\n return [] as any\n }\n}\n\n/**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = ['a', 'b']\n * const result = Array.zip(array1, array2)\n * assert.deepStrictEqual(result, [[1, 'a'], [2, 'b']])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\nexport const zip: {\n /**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = ['a', 'b']\n * const result = Array.zip(array1, array2)\n * assert.deepStrictEqual(result, [[1, 'a'], [2, 'b']])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B>(that: NonEmptyReadonlyArray<B>): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<[A, B]>\n /**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = ['a', 'b']\n * const result = Array.zip(array1, array2)\n * assert.deepStrictEqual(result, [[1, 'a'], [2, 'b']])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B>(that: Iterable<B>): <A>(self: Iterable<A>) => Array<[A, B]>\n /**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = ['a', 'b']\n * const result = Array.zip(array1, array2)\n * assert.deepStrictEqual(result, [[1, 'a'], [2, 'b']])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<[A, B]>\n /**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = ['a', 'b']\n * const result = Array.zip(array1, array2)\n * assert.deepStrictEqual(result, [[1, 'a'], [2, 'b']])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<[A, B]>\n} = dual(\n 2,\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<[A, B]> => zipWith(self, that, Tuple.make)\n)\n\n/**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [4, 5, 6]\n * const result = Array.zipWith(array1, array2, (a, b) => a + b)\n * assert.deepStrictEqual(result, [5, 7, 9])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\nexport const zipWith: {\n /**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [4, 5, 6]\n * const result = Array.zipWith(array1, array2, (a, b) => a + b)\n * assert.deepStrictEqual(result, [5, 7, 9])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B, A, C>(that: NonEmptyReadonlyArray<B>, f: (a: A, b: B) => C): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<C>\n /**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [4, 5, 6]\n * const result = Array.zipWith(array1, array2, (a, b) => a + b)\n * assert.deepStrictEqual(result, [5, 7, 9])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Array<C>\n /**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [4, 5, 6]\n * const result = Array.zipWith(array1, array2, (a, b) => a + b)\n * assert.deepStrictEqual(result, [5, 7, 9])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, B, C>(\n self: NonEmptyReadonlyArray<A>,\n that: NonEmptyReadonlyArray<B>,\n f: (a: A, b: B) => C\n ): NonEmptyArray<C>\n /**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [4, 5, 6]\n * const result = Array.zipWith(array1, array2, (a, b) => a + b)\n * assert.deepStrictEqual(result, [5, 7, 9])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C>\n} = dual(3, <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C> => {\n const as = fromIterable(self)\n const bs = fromIterable(that)\n if (isNonEmptyReadonlyArray(as) && isNonEmptyReadonlyArray(bs)) {\n const out: NonEmptyArray<C> = [f(headNonEmpty(as), headNonEmpty(bs))]\n const len = Math.min(as.length, bs.length)\n for (let i = 1; i < len; i++) {\n out[i] = f(as[i], bs[i])\n }\n return out\n }\n return []\n})\n\n/**\n * This function is the inverse of `zip`. Takes an `Iterable` of pairs and return two corresponding `Array`s.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.unzip([[1, \"a\"], [2, \"b\"], [3, \"c\"]])\n * assert.deepStrictEqual(result, [[1, 2, 3], ['a', 'b', 'c']])\n * ```\n *\n * @since 2.0.0\n */\nexport const unzip: <S extends Iterable<readonly [any, any]> | NonEmptyReadonlyArray<readonly [any, any]>>(\n self: S\n) => S extends NonEmptyReadonlyArray<readonly [infer A, infer B]> ? [NonEmptyArray<A>, NonEmptyArray<B>]\n : S extends Iterable<readonly [infer A, infer B]> ? [Array<A>, Array<B>]\n : never = (<A, B>(self: Iterable<readonly [A, B]>): [Array<A>, Array<B>] => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const fa: NonEmptyArray<A> = [input[0][0]]\n const fb: NonEmptyArray<B> = [input[0][1]]\n for (let i = 1; i < input.length; i++) {\n fa[i] = input[i][0]\n fb[i] = input[i][1]\n }\n return [fa, fb]\n }\n return [[], []]\n }) as any\n\n/**\n * Places an element in between members of an `Iterable`.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.intersperse(numbers, 0)\n * assert.deepStrictEqual(result, [1, 0, 2, 0, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const intersperse: {\n /**\n * Places an element in between members of an `Iterable`.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.intersperse(numbers, 0)\n * assert.deepStrictEqual(result, [1, 0, 2, 0, 3])\n * ```\n *\n * @since 2.0.0\n */\n <B>(middle: B): <S extends Iterable<any>>(self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n /**\n * Places an element in between members of an `Iterable`.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.intersperse(numbers, 0)\n * assert.deepStrictEqual(result, [1, 0, 2, 0, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, middle: B): NonEmptyArray<A | B>\n /**\n * Places an element in between members of an `Iterable`.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.intersperse(numbers, 0)\n * assert.deepStrictEqual(result, [1, 0, 2, 0, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, middle: B): Array<A | B>\n} = dual(2, <A, B>(self: Iterable<A>, middle: B): Array<A | B> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const out: NonEmptyArray<A | B> = [headNonEmpty(input)]\n const tail = tailNonEmpty(input)\n for (let i = 0; i < tail.length; i++) {\n if (i < tail.length) {\n out.push(middle)\n }\n out.push(tail[i])\n }\n return out\n }\n return []\n})\n\n/**\n * Apply a function to the head, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyHead([1, 2, 3], n => n * 10)\n * assert.deepStrictEqual(result, [10, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const modifyNonEmptyHead: {\n /**\n * Apply a function to the head, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyHead([1, 2, 3], n => n * 10)\n * assert.deepStrictEqual(result, [10, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>\n /**\n * Apply a function to the head, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyHead([1, 2, 3], n => n * 10)\n * assert.deepStrictEqual(result, [10, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B): NonEmptyArray<A | B>\n} = dual(\n 2,\n <A, B>(\n self: NonEmptyReadonlyArray<A>,\n f: (a: A) => B\n ): NonEmptyArray<A | B> => [f(headNonEmpty(self)), ...tailNonEmpty(self)]\n)\n\n/**\n * Change the head, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyHead([1, 2, 3], 10)\n * assert.deepStrictEqual(result, [10, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const setNonEmptyHead: {\n /**\n * Change the head, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyHead([1, 2, 3], 10)\n * assert.deepStrictEqual(result, [10, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <B>(b: B): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>\n /**\n * Change the head, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyHead([1, 2, 3], 10)\n * assert.deepStrictEqual(result, [10, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B>\n} = dual(\n 2,\n <A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B> => modifyNonEmptyHead(self, () => b)\n)\n\n/**\n * Apply a function to the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyLast([1, 2, 3], n => n * 2)\n * assert.deepStrictEqual(result, [1, 2, 6])\n * ```\n *\n * @since 2.0.0\n */\nexport const modifyNonEmptyLast: {\n /**\n * Apply a function to the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyLast([1, 2, 3], n => n * 2)\n * assert.deepStrictEqual(result, [1, 2, 6])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>\n /**\n * Apply a function to the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyLast([1, 2, 3], n => n * 2)\n * assert.deepStrictEqual(result, [1, 2, 6])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B): NonEmptyArray<A | B>\n} = dual(\n 2,\n <A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B): NonEmptyArray<A | B> =>\n append(initNonEmpty(self), f(lastNonEmpty(self)))\n)\n\n/**\n * Change the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyLast([1, 2, 3], 4)\n * assert.deepStrictEqual(result, [1, 2, 4])\n * ```\n *\n * @since 2.0.0\n */\nexport const setNonEmptyLast: {\n /**\n * Change the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyLast([1, 2, 3], 4)\n * assert.deepStrictEqual(result, [1, 2, 4])\n * ```\n *\n * @since 2.0.0\n */\n <B>(b: B): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>\n /**\n * Change the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyLast([1, 2, 3], 4)\n * assert.deepStrictEqual(result, [1, 2, 4])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B>\n} = dual(\n 2,\n <A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B> => modifyNonEmptyLast(self, () => b)\n)\n\n/**\n * Rotate an `Iterable` by `n` steps.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.rotate(letters, 2)\n * assert.deepStrictEqual(result, ['c', 'd', 'a', 'b'])\n * ```\n *\n * @since 2.0.0\n */\nexport const rotate: {\n /**\n * Rotate an `Iterable` by `n` steps.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.rotate(letters, 2)\n * assert.deepStrictEqual(result, ['c', 'd', 'a', 'b'])\n * ```\n *\n * @since 2.0.0\n */\n (n: number): <S extends Iterable<any>>(self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * Rotate an `Iterable` by `n` steps.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.rotate(letters, 2)\n * assert.deepStrictEqual(result, ['c', 'd', 'a', 'b'])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, n: number): NonEmptyArray<A>\n /**\n * Rotate an `Iterable` by `n` steps.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.rotate(letters, 2)\n * assert.deepStrictEqual(result, ['c', 'd', 'a', 'b'])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const len = input.length\n const m = Math.round(n) % len\n if (isOutOfBound(Math.abs(m), input) || m === 0) {\n return copy(input)\n }\n if (m < 0) {\n const [f, s] = splitNonEmptyAt(input, -m)\n return appendAll(s, f)\n } else {\n return rotate(self, m - len)\n }\n }\n return []\n})\n\n/**\n * Returns a function that checks if a `ReadonlyArray` contains a given value using a provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const isEquivalent = (a: number, b: number) => a === b\n * const containsNumber = Array.containsWith(isEquivalent)\n * const result = containsNumber(3)(numbers)\n * assert.deepStrictEqual(result, true)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const containsWith = <A>(isEquivalent: (self: A, that: A) => boolean): {\n (a: A): (self: Iterable<A>) => boolean\n (self: Iterable<A>, a: A): boolean\n} =>\n dual(2, (self: Iterable<A>, a: A): boolean => {\n for (const i of self) {\n if (isEquivalent(a, i)) {\n return true\n }\n }\n return false\n })\n\nconst _equivalence = Equal.equivalence()\n\n/**\n * Returns a function that checks if a `ReadonlyArray` contains a given value using the default `Equivalence`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.contains('c')(letters)\n * assert.deepStrictEqual(result, true)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const contains: {\n /**\n * Returns a function that checks if a `ReadonlyArray` contains a given value using the default `Equivalence`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.contains('c')(letters)\n * assert.deepStrictEqual(result, true)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(a: A): (self: Iterable<A>) => boolean\n /**\n * Returns a function that checks if a `ReadonlyArray` contains a given value using the default `Equivalence`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.contains('c')(letters)\n * assert.deepStrictEqual(result, true)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, a: A): boolean\n} = containsWith(_equivalence)\n\n/**\n * A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for \"chopping\" up the input\n * `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a\n * value and the rest of the `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chop(numbers, (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * assert.deepStrictEqual(result, [2, 4, 6, 8, 10])\n *\n * // Explanation:\n * // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.\n * // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,\n * // resulting in a new array `[2, 4, 6, 8, 10]`.\n * ```\n *\n * @since 2.0.0\n */\nexport const chop: {\n /**\n * A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for \"chopping\" up the input\n * `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a\n * value and the rest of the `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chop(numbers, (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * assert.deepStrictEqual(result, [2, 4, 6, 8, 10])\n *\n * // Explanation:\n * // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.\n * // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,\n * // resulting in a new array `[2, 4, 6, 8, 10]`.\n * ```\n *\n * @since 2.0.0\n */\n <S extends Iterable<any>, B>(\n f: (as: NonEmptyReadonlyArray<ReadonlyArray.Infer<S>>) => readonly [B, ReadonlyArray<ReadonlyArray.Infer<S>>]\n ): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for \"chopping\" up the input\n * `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a\n * value and the rest of the `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chop(numbers, (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * assert.deepStrictEqual(result, [2, 4, 6, 8, 10])\n *\n * // Explanation:\n * // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.\n * // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,\n * // resulting in a new array `[2, 4, 6, 8, 10]`.\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: NonEmptyReadonlyArray<A>,\n f: (as: NonEmptyReadonlyArray<A>) => readonly [B, ReadonlyArray<A>]\n ): NonEmptyArray<B>\n /**\n * A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for \"chopping\" up the input\n * `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a\n * value and the rest of the `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chop(numbers, (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * assert.deepStrictEqual(result, [2, 4, 6, 8, 10])\n *\n * // Explanation:\n * // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.\n * // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,\n * // resulting in a new array `[2, 4, 6, 8, 10]`.\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: Iterable<A>,\n f: (as: NonEmptyReadonlyArray<A>) => readonly [B, ReadonlyArray<A>]\n ): Array<B>\n} = dual(2, <A, B>(\n self: Iterable<A>,\n f: (as: NonEmptyReadonlyArray<A>) => readonly [B, ReadonlyArray<A>]\n): Array<B> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const [b, rest] = f(input)\n const out: NonEmptyArray<B> = [b]\n let next: ReadonlyArray<A> = rest\n while (readonlyArray.isNonEmptyArray(next)) {\n const [b, rest] = f(next)\n out.push(b)\n next = rest\n }\n return out\n }\n return []\n})\n\n/**\n * Splits an `Iterable` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` can be `0`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.splitAt(numbers, 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const splitAt: {\n /**\n * Splits an `Iterable` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` can be `0`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.splitAt(numbers, 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => [beforeIndex: Array<A>, fromIndex: Array<A>]\n /**\n * Splits an `Iterable` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` can be `0`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.splitAt(numbers, 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): [beforeIndex: Array<A>, fromIndex: Array<A>]\n} = dual(2, <A>(self: Iterable<A>, n: number): [Array<A>, Array<A>] => {\n const input = Array.from(self)\n const _n = Math.floor(n)\n if (isNonEmptyReadonlyArray(input)) {\n if (_n >= 1) {\n return splitNonEmptyAt(input, _n)\n }\n return [[], input]\n }\n return [input, []]\n})\n\n/**\n * Splits a `NonEmptyReadonlyArray` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` must be `>= 1`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitNonEmptyAt([\"a\", \"b\", \"c\", \"d\", \"e\"], 3)\n * assert.deepStrictEqual(result, [[\"a\", \"b\", \"c\"], [\"d\", \"e\"]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const splitNonEmptyAt: {\n /**\n * Splits a `NonEmptyReadonlyArray` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` must be `>= 1`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitNonEmptyAt([\"a\", \"b\", \"c\", \"d\", \"e\"], 3)\n * assert.deepStrictEqual(result, [[\"a\", \"b\", \"c\"], [\"d\", \"e\"]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n (n: number): <A>(self: NonEmptyReadonlyArray<A>) => [beforeIndex: NonEmptyArray<A>, fromIndex: Array<A>]\n /**\n * Splits a `NonEmptyReadonlyArray` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` must be `>= 1`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitNonEmptyAt([\"a\", \"b\", \"c\", \"d\", \"e\"], 3)\n * assert.deepStrictEqual(result, [[\"a\", \"b\", \"c\"], [\"d\", \"e\"]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, n: number): [beforeIndex: NonEmptyArray<A>, fromIndex: Array<A>]\n} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, n: number): [NonEmptyArray<A>, Array<A>] => {\n const _n = Math.max(1, Math.floor(n))\n return _n >= self.length ?\n [copy(self), []] :\n [prepend(self.slice(1, _n), headNonEmpty(self)), self.slice(_n)]\n})\n\n/**\n * Splits this iterable into `n` equally sized arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5, 6, 7, 8]\n * const result = Array.split(numbers, 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5, 6], [7, 8]])\n * ```\n *\n * @since 2.0.0\n * @category splitting\n */\nexport const split: {\n /**\n * Splits this iterable into `n` equally sized arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5, 6, 7, 8]\n * const result = Array.split(numbers, 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5, 6], [7, 8]])\n * ```\n *\n * @since 2.0.0\n * @category splitting\n */\n (n: number): <A>(self: Iterable<A>) => Array<Array<A>>\n /**\n * Splits this iterable into `n` equally sized arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5, 6, 7, 8]\n * const result = Array.split(numbers, 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5, 6], [7, 8]])\n * ```\n *\n * @since 2.0.0\n * @category splitting\n */\n <A>(self: Iterable<A>, n: number): Array<Array<A>>\n} = dual(2, <A>(self: Iterable<A>, n: number) => {\n const input = fromIterable(self)\n return chunksOf(input, Math.ceil(input.length / Math.floor(n)))\n})\n\n/**\n * Splits this iterable on the first element that matches this predicate.\n * Returns a tuple containing two arrays: the first one is before the match, and the second one is from the match onward.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.splitWhere(numbers, n => n > 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const splitWhere: {\n /**\n * Splits this iterable on the first element that matches this predicate.\n * Returns a tuple containing two arrays: the first one is before the match, and the second one is from the match onward.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.splitWhere(numbers, n => n > 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(\n predicate: (a: NoInfer<A>, i: number) => boolean\n ): (self: Iterable<A>) => [beforeMatch: Array<A>, fromMatch: Array<A>]\n /**\n * Splits this iterable on the first element that matches this predicate.\n * Returns a tuple containing two arrays: the first one is before the match, and the second one is from the match onward.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.splitWhere(numbers, n => n > 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [beforeMatch: Array<A>, fromMatch: Array<A>]\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [beforeMatch: Array<A>, fromMatch: Array<A>] =>\n span(self, (a: A, i: number) => !predicate(a, i))\n)\n\n/**\n * Copies an array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const copy = Array.copy(numbers)\n * assert.deepStrictEqual(copy, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const copy: {\n /**\n * Copies an array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const copy = Array.copy(numbers)\n * assert.deepStrictEqual(copy, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>): NonEmptyArray<A>\n /**\n * Copies an array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const copy = Array.copy(numbers)\n * assert.deepStrictEqual(copy, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: ReadonlyArray<A>): Array<A>\n} = (<A>(self: ReadonlyArray<A>): Array<A> => self.slice()) as any\n\n/**\n * Pads an array.\n * Returns a new array of length `n` with the elements of `array` followed by `fill` elements if `array` is shorter than `n`.\n * If `array` is longer than `n`, the returned array will be a slice of `array` containing the `n` first elements of `array`.\n * If `n` is less than or equal to 0, the returned array will be an empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const arr = [1, 2, 3]\n * const result = Array.pad(arr, 6, 0)\n * assert.deepStrictEqual(result, [1, 2, 3, 0, 0, 0])\n * ```\n *\n * @since 3.8.4\n */\nexport const pad: {\n /**\n * Pads an array.\n * Returns a new array of length `n` with the elements of `array` followed by `fill` elements if `array` is shorter than `n`.\n * If `array` is longer than `n`, the returned array will be a slice of `array` containing the `n` first elements of `array`.\n * If `n` is less than or equal to 0, the returned array will be an empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const arr = [1, 2, 3]\n * const result = Array.pad(arr, 6, 0)\n * assert.deepStrictEqual(result, [1, 2, 3, 0, 0, 0])\n * ```\n *\n * @since 3.8.4\n */\n <A, T>(n: number, fill: T): (\n self: Array<A>\n ) => Array<A | T>\n /**\n * Pads an array.\n * Returns a new array of length `n` with the elements of `array` followed by `fill` elements if `array` is shorter than `n`.\n * If `array` is longer than `n`, the returned array will be a slice of `array` containing the `n` first elements of `array`.\n * If `n` is less than or equal to 0, the returned array will be an empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const arr = [1, 2, 3]\n * const result = Array.pad(arr, 6, 0)\n * assert.deepStrictEqual(result, [1, 2, 3, 0, 0, 0])\n * ```\n *\n * @since 3.8.4\n */\n <A, T>(self: Array<A>, n: number, fill: T): Array<A | T>\n} = dual(3, <A, T>(self: Array<A>, n: number, fill: T): Array<A | T> => {\n if (self.length >= n) {\n return take(self, n)\n }\n return appendAll(\n self,\n makeBy(n - self.length, () => fill)\n )\n})\n\n/**\n * Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of\n * the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive\n * definition of `chunksOf`; it satisfies the property that\n *\n * ```ts\n * chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))\n * ```\n *\n * whenever `n` evenly divides the length of `self`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chunksOf(numbers, 2)\n * assert.deepStrictEqual(result, [[1, 2], [3, 4], [5]])\n *\n * // Explanation:\n * // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.\n * // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,\n * // the last chunk contains the remaining elements.\n * // The result is `[[1, 2], [3, 4], [5]]`.\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const chunksOf: {\n /**\n * Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of\n * the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive\n * definition of `chunksOf`; it satisfies the property that\n *\n * ```ts\n * chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))\n * ```\n *\n * whenever `n` evenly divides the length of `self`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chunksOf(numbers, 2)\n * assert.deepStrictEqual(result, [[1, 2], [3, 4], [5]])\n *\n * // Explanation:\n * // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.\n * // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,\n * // the last chunk contains the remaining elements.\n * // The result is `[[1, 2], [3, 4], [5]]`.\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n (n: number): <S extends Iterable<any>>(\n self: S\n ) => ReadonlyArray.With<S, NonEmptyArray<ReadonlyArray.Infer<S>>>\n /**\n * Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of\n * the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive\n * definition of `chunksOf`; it satisfies the property that\n *\n * ```ts\n * chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))\n * ```\n *\n * whenever `n` evenly divides the length of `self`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chunksOf(numbers, 2)\n * assert.deepStrictEqual(result, [[1, 2], [3, 4], [5]])\n *\n * // Explanation:\n * // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.\n * // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,\n * // the last chunk contains the remaining elements.\n * // The result is `[[1, 2], [3, 4], [5]]`.\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, n: number): NonEmptyArray<NonEmptyArray<A>>\n /**\n * Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of\n * the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive\n * definition of `chunksOf`; it satisfies the property that\n *\n * ```ts\n * chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))\n * ```\n *\n * whenever `n` evenly divides the length of `self`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chunksOf(numbers, 2)\n * assert.deepStrictEqual(result, [[1, 2], [3, 4], [5]])\n *\n * // Explanation:\n * // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.\n * // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,\n * // the last chunk contains the remaining elements.\n * // The result is `[[1, 2], [3, 4], [5]]`.\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<NonEmptyArray<A>>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<NonEmptyArray<A>> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n return chop(input, splitNonEmptyAt(n))\n }\n return []\n})\n\n/**\n * Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s using the provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.groupWith([\"a\", \"a\", \"b\", \"b\", \"b\", \"c\", \"a\"], (x, y) => x === y)\n * assert.deepStrictEqual(result, [[\"a\", \"a\"], [\"b\", \"b\", \"b\"], [\"c\"], [\"a\"]])\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\nexport const groupWith: {\n /**\n * Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s using the provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.groupWith([\"a\", \"a\", \"b\", \"b\", \"b\", \"c\", \"a\"], (x, y) => x === y)\n * assert.deepStrictEqual(result, [[\"a\", \"a\"], [\"b\", \"b\", \"b\"], [\"c\"], [\"a\"]])\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\n <A>(isEquivalent: (self: A, that: A) => boolean): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<NonEmptyArray<A>>\n /**\n * Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s using the provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.groupWith([\"a\", \"a\", \"b\", \"b\", \"b\", \"c\", \"a\"], (x, y) => x === y)\n * assert.deepStrictEqual(result, [[\"a\", \"a\"], [\"b\", \"b\", \"b\"], [\"c\"], [\"a\"]])\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\n <A>(\n self: NonEmptyReadonlyArray<A>,\n isEquivalent: (self: A, that: A) => boolean\n ): NonEmptyArray<NonEmptyArray<A>>\n} = dual(\n 2,\n <A>(self: NonEmptyReadonlyArray<A>, isEquivalent: (self: A, that: A) => boolean): NonEmptyArray<NonEmptyArray<A>> =>\n chop(self, (as) => {\n const h = headNonEmpty(as)\n const out: NonEmptyArray<A> = [h]\n let i = 1\n for (; i < as.length; i++) {\n const a = as[i]\n if (isEquivalent(a, h)) {\n out.push(a)\n } else {\n break\n }\n }\n return [out, as.slice(i)]\n })\n)\n\n/**\n * Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.group([1, 1, 2, 2, 2, 3, 1])\n * assert.deepStrictEqual(result, [[1, 1], [2, 2, 2], [3], [1]])\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\nexport const group: <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<NonEmptyArray<A>> = groupWith(\n Equal.equivalence()\n)\n\n/**\n * Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning\n * function on each element, and grouping the results according to values returned\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const people = [\n * { name: \"Alice\", group: \"A\" },\n * { name: \"Bob\", group: \"B\" },\n * { name: \"Charlie\", group: \"A\" }\n * ]\n * const result = Array.groupBy(people, person => person.group)\n * assert.deepStrictEqual(result, {\n * A: [{ name: \"Alice\", group: \"A\" }, { name: \"Charlie\", group: \"A\" }],\n * B: [{ name: \"Bob\", group: \"B\" }]\n * })\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\nexport const groupBy: {\n /**\n * Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning\n * function on each element, and grouping the results according to values returned\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const people = [\n * { name: \"Alice\", group: \"A\" },\n * { name: \"Bob\", group: \"B\" },\n * { name: \"Charlie\", group: \"A\" }\n * ]\n * const result = Array.groupBy(people, person => person.group)\n * assert.deepStrictEqual(result, {\n * A: [{ name: \"Alice\", group: \"A\" }, { name: \"Charlie\", group: \"A\" }],\n * B: [{ name: \"Bob\", group: \"B\" }]\n * })\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\n <A, K extends string | symbol>(\n f: (a: A) => K\n ): (self: Iterable<A>) => Record<Record.ReadonlyRecord.NonLiteralKey<K>, NonEmptyArray<A>>\n /**\n * Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning\n * function on each element, and grouping the results according to values returned\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const people = [\n * { name: \"Alice\", group: \"A\" },\n * { name: \"Bob\", group: \"B\" },\n * { name: \"Charlie\", group: \"A\" }\n * ]\n * const result = Array.groupBy(people, person => person.group)\n * assert.deepStrictEqual(result, {\n * A: [{ name: \"Alice\", group: \"A\" }, { name: \"Charlie\", group: \"A\" }],\n * B: [{ name: \"Bob\", group: \"B\" }]\n * })\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\n <A, K extends string | symbol>(\n self: Iterable<A>,\n f: (a: A) => K\n ): Record<Record.ReadonlyRecord.NonLiteralKey<K>, NonEmptyArray<A>>\n} = dual(2, <A, K extends string | symbol>(\n self: Iterable<A>,\n f: (a: A) => K\n): Record<Record.ReadonlyRecord.NonLiteralKey<K>, NonEmptyArray<A>> => {\n const out: Record<string | symbol, NonEmptyArray<A>> = {}\n for (const a of self) {\n const k = f(a)\n if (Object.prototype.hasOwnProperty.call(out, k)) {\n out[k].push(a)\n } else {\n out[k] = [a]\n }\n }\n return out\n})\n\n/**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const union = Array.unionWith(array1, array2, (a, b) => a === b)\n * assert.deepStrictEqual(union, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const unionWith: {\n /**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const union = Array.unionWith(array1, array2, (a, b) => a === b)\n * assert.deepStrictEqual(union, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <S extends Iterable<any>, T extends Iterable<any>>(\n that: T,\n isEquivalent: (self: ReadonlyArray.Infer<S>, that: ReadonlyArray.Infer<T>) => boolean\n ): (self: S) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>\n /**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const union = Array.unionWith(array1, array2, (a, b) => a === b)\n * assert.deepStrictEqual(union, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: NonEmptyReadonlyArray<A>,\n that: Iterable<B>,\n isEquivalent: (self: A, that: B) => boolean\n ): NonEmptyArray<A | B>\n /**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const union = Array.unionWith(array1, array2, (a, b) => a === b)\n * assert.deepStrictEqual(union, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: Iterable<A>,\n that: NonEmptyReadonlyArray<B>,\n isEquivalent: (self: A, that: B) => boolean\n ): NonEmptyArray<A | B>\n /**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const union = Array.unionWith(array1, array2, (a, b) => a === b)\n * assert.deepStrictEqual(union, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: Iterable<A>,\n that: Iterable<B>,\n isEquivalent: (self: A, that: B) => boolean\n ): Array<A | B>\n} = dual(3, <A>(self: Iterable<A>, that: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A> => {\n const a = fromIterable(self)\n const b = fromIterable(that)\n if (isNonEmptyReadonlyArray(a)) {\n if (isNonEmptyReadonlyArray(b)) {\n const dedupe = dedupeWith(isEquivalent)\n return dedupe(appendAll(a, b))\n }\n return a\n }\n return b\n})\n\n/**\n * Creates a union of two arrays, removing duplicates.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const result = Array.union(array1, array2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const union: {\n /**\n * Creates a union of two arrays, removing duplicates.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const result = Array.union(array1, array2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <T extends Iterable<any>>(that: T): <S extends Iterable<any>>(\n self: S\n ) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>\n /**\n * Creates a union of two arrays, removing duplicates.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const result = Array.union(array1, array2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, that: ReadonlyArray<B>): NonEmptyArray<A | B>\n /**\n * Creates a union of two arrays, removing duplicates.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const result = Array.union(array1, array2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: ReadonlyArray<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<A | B>\n /**\n * Creates a union of two arrays, removing duplicates.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const result = Array.union(array1, array2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B>\n} = dual(2, <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B> => unionWith(self, that, _equivalence))\n\n/**\n * Creates an `Array` of unique values that are included in all given `Iterable`s using the provided `isEquivalent` function.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }]\n * const array2 = [{ id: 3 }, { id: 4 }, { id: 1 }]\n * const isEquivalent = (a: { id: number }, b: { id: number }) => a.id === b.id\n * const result = Array.intersectionWith(isEquivalent)(array2)(array1)\n * assert.deepStrictEqual(result, [{ id: 1 }, { id: 3 }])\n * ```\n *\n * @since 2.0.0\n */\nexport const intersectionWith = <A>(isEquivalent: (self: A, that: A) => boolean): {\n (that: Iterable<A>): (self: Iterable<A>) => Array<A>\n (self: Iterable<A>, that: Iterable<A>): Array<A>\n} => {\n const has = containsWith(isEquivalent)\n return dual(\n 2,\n (self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(self).filter((a) => has(that, a))\n )\n}\n\n/**\n * Creates an `Array` of unique values that are included in all given `Iterable`s.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [3, 4, 1]\n * const result = Array.intersection(array1, array2)\n * assert.deepStrictEqual(result, [1, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const intersection: {\n /**\n * Creates an `Array` of unique values that are included in all given `Iterable`s.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [3, 4, 1]\n * const result = Array.intersection(array1, array2)\n * assert.deepStrictEqual(result, [1, 3])\n * ```\n *\n * @since 2.0.0\n */\n <B>(that: Iterable<B>): <A>(self: Iterable<A>) => Array<A & B>\n /**\n * Creates an `Array` of unique values that are included in all given `Iterable`s.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [3, 4, 1]\n * const result = Array.intersection(array1, array2)\n * assert.deepStrictEqual(result, [1, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A & B>\n} = intersectionWith(_equivalence)\n\n/**\n * Creates a `Array` of values not included in the other given `Iterable` using the provided `isEquivalent` function.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [2, 3, 4]\n * const difference = Array.differenceWith<number>((a, b) => a === b)(array1, array2)\n * assert.deepStrictEqual(difference, [1])\n * ```\n *\n * @since 2.0.0\n */\nexport const differenceWith = <A>(isEquivalent: (self: A, that: A) => boolean): {\n (that: Iterable<A>): (self: Iterable<A>) => Array<A>\n (self: Iterable<A>, that: Iterable<A>): Array<A>\n} => {\n const has = containsWith(isEquivalent)\n return dual(\n 2,\n (self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(self).filter((a) => !has(that, a))\n )\n}\n\n/**\n * Creates a `Array` of values not included in the other given `Iterable`.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [2, 3, 4]\n * const difference = Array.difference(array1, array2)\n * assert.deepStrictEqual(difference, [1])\n * ```\n *\n * @since 2.0.0\n */\nexport const difference: {\n /**\n * Creates a `Array` of values not included in the other given `Iterable`.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [2, 3, 4]\n * const difference = Array.difference(array1, array2)\n * assert.deepStrictEqual(difference, [1])\n * ```\n *\n * @since 2.0.0\n */\n <A>(that: Iterable<A>): (self: Iterable<A>) => Array<A>\n /**\n * Creates a `Array` of values not included in the other given `Iterable`.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [2, 3, 4]\n * const difference = Array.difference(array1, array2)\n * assert.deepStrictEqual(difference, [1])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, that: Iterable<A>): Array<A>\n} = differenceWith(_equivalence)\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const empty: <A = never>() => Array<A> = () => []\n\n/**\n * Constructs a new `NonEmptyArray<A>` from the specified value.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const of = <A>(a: A): NonEmptyArray<A> => [a]\n\n/**\n * @since 2.0.0\n */\nexport declare namespace ReadonlyArray {\n /**\n * @since 2.0.0\n */\n export type Infer<S extends Iterable<any>> = S extends ReadonlyArray<infer A> ? A\n : S extends Iterable<infer A> ? A\n : never\n\n /**\n * @since 2.0.0\n */\n export type With<S extends Iterable<any>, A> = S extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>\n : Array<A>\n\n /**\n * @since 2.0.0\n */\n export type OrNonEmpty<\n S extends Iterable<any>,\n T extends Iterable<any>,\n A\n > = S extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>\n : T extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>\n : Array<A>\n\n /**\n * @since 2.0.0\n */\n export type AndNonEmpty<\n S extends Iterable<any>,\n T extends Iterable<any>,\n A\n > = S extends NonEmptyReadonlyArray<any> ? T extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>\n : Array<A>\n : Array<A>\n\n /**\n * @since 2.0.0\n */\n export type Flatten<T extends ReadonlyArray<ReadonlyArray<any>>> = T extends\n NonEmptyReadonlyArray<NonEmptyReadonlyArray<infer A>> ? NonEmptyArray<A>\n : T extends ReadonlyArray<ReadonlyArray<infer A>> ? Array<A>\n : never\n}\n\n/**\n * @category mapping\n * @since 2.0.0\n */\nexport const map: {\n /**\n * @category mapping\n * @since 2.0.0\n */\n <S extends ReadonlyArray<any>, B>(\n f: (a: ReadonlyArray.Infer<S>, i: number) => B\n ): (self: S) => ReadonlyArray.With<S, B>\n /**\n * @category mapping\n * @since 2.0.0\n */\n <S extends ReadonlyArray<any>, B>(self: S, f: (a: ReadonlyArray.Infer<S>, i: number) => B): ReadonlyArray.With<S, B>\n} = dual(2, <A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => B): Array<B> => self.map(f))\n\n/**\n * Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatMap: {\n /**\n * Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <S extends ReadonlyArray<any>, T extends ReadonlyArray<any>>(\n f: (a: ReadonlyArray.Infer<S>, i: number) => T\n ): (self: S) => ReadonlyArray.AndNonEmpty<S, T, ReadonlyArray.Infer<T>>\n /**\n * Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(\n self: NonEmptyReadonlyArray<A>,\n f: (a: A, i: number) => NonEmptyReadonlyArray<B>\n ): NonEmptyArray<B>\n /**\n * Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => ReadonlyArray<B>): Array<B>\n} = dual(\n 2,\n <A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => ReadonlyArray<B>): Array<B> => {\n if (isEmptyReadonlyArray(self)) {\n return []\n }\n const out: Array<B> = []\n for (let i = 0; i < self.length; i++) {\n const inner = f(self[i], i)\n for (let j = 0; j < inner.length; j++) {\n out.push(inner[j])\n }\n }\n return out\n }\n)\n\n/**\n * Combines multiple arrays into a single array by concatenating all elements\n * from each nested array. This function ensures that the structure of nested\n * arrays is collapsed into a single, flat array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const nestedArrays = [[1, 2], [], [3, 4], [], [5, 6]]\n * const result = Array.flatten(nestedArrays)\n *\n * assert.deepStrictEqual(result, [1, 2, 3, 4, 5, 6]);\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatten: <S extends ReadonlyArray<ReadonlyArray<any>>>(self: S) => ReadonlyArray.Flatten<S> = flatMap(\n identity\n) as any\n\n/**\n * Applies a function to each element of the `Iterable` and filters based on the result, keeping the transformed values where the function returns `Some`.\n * This method combines filtering and mapping functionalities, allowing transformations and filtering of elements based on a single function pass.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\";\n *\n * const data = [1, 2, 3, 4, 5];\n * const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();\n * const result = Array.filterMap(data, evenSquares);\n *\n * assert.deepStrictEqual(result, [4, 16]);\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const filterMap: {\n /**\n * Applies a function to each element of the `Iterable` and filters based on the result, keeping the transformed values where the function returns `Some`.\n * This method combines filtering and mapping functionalities, allowing transformations and filtering of elements based on a single function pass.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\";\n *\n * const data = [1, 2, 3, 4, 5];\n * const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();\n * const result = Array.filterMap(data, evenSquares);\n *\n * assert.deepStrictEqual(result, [4, 16]);\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(f: (a: A, i: number) => Option<B>): (self: Iterable<A>) => Array<B>\n /**\n * Applies a function to each element of the `Iterable` and filters based on the result, keeping the transformed values where the function returns `Some`.\n * This method combines filtering and mapping functionalities, allowing transformations and filtering of elements based on a single function pass.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\";\n *\n * const data = [1, 2, 3, 4, 5];\n * const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();\n * const result = Array.filterMap(data, evenSquares);\n *\n * assert.deepStrictEqual(result, [4, 16]);\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Array<B>\n} = dual(\n 2,\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Array<B> => {\n const as = fromIterable(self)\n const out: Array<B> = []\n for (let i = 0; i < as.length; i++) {\n const o = f(as[i], i)\n if (O.isSome(o)) {\n out.push(o.value)\n }\n }\n return out\n }\n)\n\n/**\n * Applies a function to each element of the array and filters based on the result, stopping when a condition is not met.\n * This method combines filtering and mapping in a single pass, and short-circuits, i.e., stops processing, as soon as the function returns `None`.\n * This is useful when you need to transform an array but only up to the point where a certain condition holds true.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\";\n *\n * const data = [2, 4, 5];\n * const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();\n * const result = Array.filterMapWhile(data, toSquareTillOdd);\n *\n * assert.deepStrictEqual(result, [4, 16]);\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const filterMapWhile: {\n /**\n * Applies a function to each element of the array and filters based on the result, stopping when a condition is not met.\n * This method combines filtering and mapping in a single pass, and short-circuits, i.e., stops processing, as soon as the function returns `None`.\n * This is useful when you need to transform an array but only up to the point where a certain condition holds true.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\";\n *\n * const data = [2, 4, 5];\n * const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();\n * const result = Array.filterMapWhile(data, toSquareTillOdd);\n *\n * assert.deepStrictEqual(result, [4, 16]);\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(f: (a: A, i: number) => Option<B>): (self: Iterable<A>) => Array<B>\n /**\n * Applies a function to each element of the array and filters based on the result, stopping when a condition is not met.\n * This method combines filtering and mapping in a single pass, and short-circuits, i.e., stops processing, as soon as the function returns `None`.\n * This is useful when you need to transform an array but only up to the point where a certain condition holds true.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\";\n *\n * const data = [2, 4, 5];\n * const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();\n * const result = Array.filterMapWhile(data, toSquareTillOdd);\n *\n * assert.deepStrictEqual(result, [4, 16]);\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Array<B>\n} = dual(2, <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>) => {\n let i = 0\n const out: Array<B> = []\n for (const a of self) {\n const b = f(a, i)\n if (O.isSome(b)) {\n out.push(b.value)\n } else {\n break\n }\n i++\n }\n return out\n})\n\n/**\n * Applies a function to each element of the `Iterable`, categorizing the results into two separate arrays.\n * This function is particularly useful for operations where each element can result in two possible types,\n * and you want to separate these types into different collections. For instance, separating validation results\n * into successes and failures.\n *\n * @example\n * ```ts\n * import { Array, Either } from \"effect\";\n *\n * const data = [1, 2, 3, 4, 5]\n * const isEven = (x: number) => x % 2 === 0\n * const partitioned = Array.partitionMap(data, x =>\n * isEven(x) ? Either.right(x) : Either.left(x)\n * )\n *\n * assert.deepStrictEqual(partitioned, [\n * [1, 3, 5],\n * [2, 4]\n * ])\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const partitionMap: {\n /**\n * Applies a function to each element of the `Iterable`, categorizing the results into two separate arrays.\n * This function is particularly useful for operations where each element can result in two possible types,\n * and you want to separate these types into different collections. For instance, separating validation results\n * into successes and failures.\n *\n * @example\n * ```ts\n * import { Array, Either } from \"effect\";\n *\n * const data = [1, 2, 3, 4, 5]\n * const isEven = (x: number) => x % 2 === 0\n * const partitioned = Array.partitionMap(data, x =>\n * isEven(x) ? Either.right(x) : Either.left(x)\n * )\n *\n * assert.deepStrictEqual(partitioned, [\n * [1, 3, 5],\n * [2, 4]\n * ])\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B, C>(f: (a: A, i: number) => array_<C, B>): (self: Iterable<A>) => [left: Array<B>, right: Array<C>]\n /**\n * Applies a function to each element of the `Iterable`, categorizing the results into two separate arrays.\n * This function is particularly useful for operations where each element can result in two possible types,\n * and you want to separate these types into different collections. For instance, separating validation results\n * into successes and failures.\n *\n * @example\n * ```ts\n * import { Array, Either } from \"effect\";\n *\n * const data = [1, 2, 3, 4, 5]\n * const isEven = (x: number) => x % 2 === 0\n * const partitioned = Array.partitionMap(data, x =>\n * isEven(x) ? Either.right(x) : Either.left(x)\n * )\n *\n * assert.deepStrictEqual(partitioned, [\n * [1, 3, 5],\n * [2, 4]\n * ])\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B, C>(self: Iterable<A>, f: (a: A, i: number) => array_<C, B>): [left: Array<B>, right: Array<C>]\n} = dual(\n 2,\n <A, B, C>(self: Iterable<A>, f: (a: A, i: number) => array_<C, B>): [left: Array<B>, right: Array<C>] => {\n const left: Array<B> = []\n const right: Array<C> = []\n const as = fromIterable(self)\n for (let i = 0; i < as.length; i++) {\n const e = f(as[i], i)\n if (E.isLeft(e)) {\n left.push(e.left)\n } else {\n right.push(e.right)\n }\n }\n return [left, right]\n }\n)\n\n/**\n * Retrieves the `Some` values from an `Iterable` of `Option`s, collecting them into an array.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Array.getSomes([Option.some(1), Option.none(), Option.some(2)]),\n * [1, 2]\n * )\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n\nexport const getSomes: <T extends Iterable<Option<X>>, X = any>(\n self: T\n) => Array<Option.Value<ReadonlyArray.Infer<T>>> = filterMap(identity as any)\n\n/**\n * Retrieves the `Left` values from an `Iterable` of `Either`s, collecting them into an array.\n *\n * @example\n * ```ts\n * import { Array, Either } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Array.getLefts([Either.right(1), Either.left(\"err\"), Either.right(2)]),\n * [\"err\"]\n * )\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const getLefts = <T extends Iterable<array_<any, any>>>(self: T): Array<array_.Left<ReadonlyArray.Infer<T>>> => {\n const out: Array<any> = []\n for (const a of self) {\n if (E.isLeft(a)) {\n out.push(a.left)\n }\n }\n\n return out\n}\n\n/**\n * Retrieves the `Right` values from an `Iterable` of `Either`s, collecting them into an array.\n *\n * @example\n * ```ts\n * import { Array, Either } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Array.getRights([Either.right(1), Either.left(\"err\"), Either.right(2)]),\n * [1, 2]\n * )\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const getRights = <T extends Iterable<array_<any, any>>>(\n self: T\n): Array<array_.Right<ReadonlyArray.Infer<T>>> => {\n const out: Array<any> = []\n for (const a of self) {\n if (E.isRight(a)) {\n out.push(a.right)\n }\n }\n\n return out\n}\n\n/**\n * @category filtering\n * @since 2.0.0\n */\nexport const filter: {\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Array<B>\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Array<A>\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Array<B>\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A>\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A> => {\n const as = fromIterable(self)\n const out: Array<A> = []\n for (let i = 0; i < as.length; i++) {\n if (predicate(as[i], i)) {\n out.push(as[i])\n }\n }\n return out\n }\n)\n\n/**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const partition: {\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (\n self: Iterable<A>\n ) => [excluded: Array<Exclude<A, B>>, satisfying: Array<B>]\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * @category filtering\n * @since 2.0.0\n */\n <A>(\n predicate: (a: NoInfer<A>, i: number) => boolean\n ): (self: Iterable<A>) => [excluded: Array<A>, satisfying: Array<A>]\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(\n self: Iterable<A>,\n refinement: (a: A, i: number) => a is B\n ): [excluded: Array<Exclude<A, B>>, satisfying: Array<B>]\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * @category filtering\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [excluded: Array<A>, satisfying: Array<A>]\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [excluded: Array<A>, satisfying: Array<A>] => {\n const left: Array<A> = []\n const right: Array<A> = []\n const as = fromIterable(self)\n for (let i = 0; i < as.length; i++) {\n if (predicate(as[i], i)) {\n right.push(as[i])\n } else {\n left.push(as[i])\n }\n }\n return [left, right]\n }\n)\n\n/**\n * Separates an `Iterable` into two arrays based on a predicate.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.partition(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, [[1, 3], [2, 4]])\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const separate: <T extends Iterable<array_<any, any>>>(\n self: T\n) => [Array<array_.Left<ReadonlyArray.Infer<T>>>, Array<array_.Right<ReadonlyArray.Infer<T>>>] = partitionMap(\n identity\n)\n\n/**\n * Reduces an array from the left.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.reduce(numbers, 0, (acc, n) => acc + n)\n * assert.deepStrictEqual(result, 6)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const reduce: {\n /**\n * Reduces an array from the left.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.reduce(numbers, 0, (acc, n) => acc + n)\n * assert.deepStrictEqual(result, 6)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Iterable<A>) => B\n /**\n * Reduces an array from the left.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.reduce(numbers, 0, (acc, n) => acc + n)\n * assert.deepStrictEqual(result, 6)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B\n} = dual(\n 3,\n <B, A>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B =>\n fromIterable(self).reduce((b, a, i) => f(b, a, i), b)\n)\n\n/**\n * Reduces an array from the right.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.reduceRight(numbers, 0, (acc, n) => acc + n)\n * assert.deepStrictEqual(result, 6)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const reduceRight: {\n /**\n * Reduces an array from the right.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.reduceRight(numbers, 0, (acc, n) => acc + n)\n * assert.deepStrictEqual(result, 6)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Iterable<A>) => B\n /**\n * Reduces an array from the right.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.reduceRight(numbers, 0, (acc, n) => acc + n)\n * assert.deepStrictEqual(result, 6)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B\n} = dual(\n 3,\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B =>\n fromIterable(self).reduceRight((b, a, i) => f(b, a, i), b)\n)\n\n/**\n * Lifts a predicate into an array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n * const to = Array.liftPredicate(isEven)\n * assert.deepStrictEqual(to(1), [])\n * assert.deepStrictEqual(to(2), [2])\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\nexport const liftPredicate: { // Note: I intentionally avoid using the NoInfer pattern here.\n <A, B extends A>(refinement: Refinement<A, B>): (a: A) => Array<B>\n /**\n * Lifts a predicate into an array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n * const to = Array.liftPredicate(isEven)\n * assert.deepStrictEqual(to(1), [])\n * assert.deepStrictEqual(to(2), [2])\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\n <A>(predicate: Predicate<A>): <B extends A>(b: B) => Array<B>\n} = <A>(predicate: Predicate<A>) => <B extends A>(b: B): Array<B> => predicate(b) ? [b] : []\n\n/**\n * @category lifting\n * @since 2.0.0\n */\nexport const liftOption = <A extends Array<unknown>, B>(\n f: (...a: A) => Option<B>\n) =>\n(...a: A): Array<B> => fromOption(f(...a))\n\n/**\n * @category conversions\n * @since 2.0.0\n */\nexport const fromNullable = <A>(a: A): Array<NonNullable<A>> => a == null ? empty() : [a as NonNullable<A>]\n\n/**\n * @category lifting\n * @since 2.0.0\n */\nexport const liftNullable = <A extends Array<unknown>, B>(\n f: (...a: A) => B | null | undefined\n): (...a: A) => Array<NonNullable<B>> =>\n(...a) => fromNullable(f(...a))\n\n/**\n * Maps over an array and flattens the result, removing null and undefined values.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.flatMapNullable(numbers, n => (n % 2 === 0 ? null : n))\n * assert.deepStrictEqual(result, [1, 3])\n *\n * // Explanation:\n * // The array of numbers [1, 2, 3] is mapped with a function that returns null for even numbers\n * // and the number itself for odd numbers. The resulting array [1, null, 3] is then flattened\n * // to remove null values, resulting in [1, 3].\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatMapNullable: {\n /**\n * Maps over an array and flattens the result, removing null and undefined values.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.flatMapNullable(numbers, n => (n % 2 === 0 ? null : n))\n * assert.deepStrictEqual(result, [1, 3])\n *\n * // Explanation:\n * // The array of numbers [1, 2, 3] is mapped with a function that returns null for even numbers\n * // and the number itself for odd numbers. The resulting array [1, null, 3] is then flattened\n * // to remove null values, resulting in [1, 3].\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B | null | undefined): (self: ReadonlyArray<A>) => Array<NonNullable<B>>\n /**\n * Maps over an array and flattens the result, removing null and undefined values.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.flatMapNullable(numbers, n => (n % 2 === 0 ? null : n))\n * assert.deepStrictEqual(result, [1, 3])\n *\n * // Explanation:\n * // The array of numbers [1, 2, 3] is mapped with a function that returns null for even numbers\n * // and the number itself for odd numbers. The resulting array [1, null, 3] is then flattened\n * // to remove null values, resulting in [1, 3].\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: ReadonlyArray<A>, f: (a: A) => B | null | undefined): Array<NonNullable<B>>\n} = dual(\n 2,\n <A, B>(self: ReadonlyArray<A>, f: (a: A) => B | null | undefined): Array<NonNullable<B>> =>\n flatMap(self, (a) => fromNullable(f(a)))\n)\n\n/**\n * Lifts a function that returns an `Either` into a function that returns an array.\n * If the `Either` is a left, it returns an empty array.\n * If the `Either` is a right, it returns an array with the right value.\n *\n * @example\n * ```ts\n * import { Array, Either } from \"effect\"\n *\n * const parseNumber = (s: string): Either.Either<number, Error> =>\n * isNaN(Number(s)) ? Either.left(new Error(\"Not a number\")) : Either.right(Number(s))\n *\n * const liftedParseNumber = Array.liftEither(parseNumber)\n *\n * const result1 = liftedParseNumber(\"42\")\n * assert.deepStrictEqual(result1, [42])\n *\n * const result2 = liftedParseNumber(\"not a number\")\n * assert.deepStrictEqual(result2, [])\n *\n * // Explanation:\n * // The function parseNumber is lifted to return an array.\n * // When parsing \"42\", it returns an Either.left with the number 42, resulting in [42].\n * // When parsing \"not a number\", it returns an Either.right with an error, resulting in an empty array [].\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\nexport const liftEither = <A extends Array<unknown>, E, B>(\n f: (...a: A) => array_<B, E>\n) =>\n(...a: A): Array<B> => {\n const e = f(...a)\n return E.isLeft(e) ? [] : [e.right]\n}\n\n/**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const every: {\n /**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(\n refinement: (a: NoInfer<A>, i: number) => a is B\n ): (self: ReadonlyArray<A>) => self is ReadonlyArray<B>\n /**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: ReadonlyArray<A>) => boolean\n /**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(self: ReadonlyArray<A>, refinement: (a: A, i: number) => a is B): self is ReadonlyArray<B>\n /**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): boolean\n} = dual(\n 2,\n <A, B extends A>(self: ReadonlyArray<A>, refinement: (a: A, i: number) => a is B): self is ReadonlyArray<B> =>\n self.every(refinement)\n)\n\n/**\n * Check if a predicate holds true for some `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const some: {\n /**\n * Check if a predicate holds true for some `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: ReadonlyArray<A>) => self is NonEmptyReadonlyArray<A>\n /**\n * Check if a predicate holds true for some `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): self is NonEmptyReadonlyArray<A>\n} = dual(\n 2,\n <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): self is NonEmptyReadonlyArray<A> =>\n self.some(predicate)\n)\n\n/**\n * Extends an array with a function that maps each subarray to a value.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.extend(numbers, as => as.length)\n * assert.deepStrictEqual(result, [3, 2, 1])\n *\n * // Explanation:\n * // The function maps each subarray starting from each element to its length.\n * // The subarrays are: [1, 2, 3], [2, 3], [3].\n * // The lengths are: 3, 2, 1.\n * // Therefore, the result is [3, 2, 1].\n * ```\n *\n * @since 2.0.0\n */\nexport const extend: {\n /**\n * Extends an array with a function that maps each subarray to a value.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.extend(numbers, as => as.length)\n * assert.deepStrictEqual(result, [3, 2, 1])\n *\n * // Explanation:\n * // The function maps each subarray starting from each element to its length.\n * // The subarrays are: [1, 2, 3], [2, 3], [3].\n * // The lengths are: 3, 2, 1.\n * // Therefore, the result is [3, 2, 1].\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(f: (as: ReadonlyArray<A>) => B): (self: ReadonlyArray<A>) => Array<B>\n /**\n * Extends an array with a function that maps each subarray to a value.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.extend(numbers, as => as.length)\n * assert.deepStrictEqual(result, [3, 2, 1])\n *\n * // Explanation:\n * // The function maps each subarray starting from each element to its length.\n * // The subarrays are: [1, 2, 3], [2, 3], [3].\n * // The lengths are: 3, 2, 1.\n * // Therefore, the result is [3, 2, 1].\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: ReadonlyArray<A>, f: (as: ReadonlyArray<A>) => B): Array<B>\n} = dual(\n 2,\n <A, B>(self: ReadonlyArray<A>, f: (as: ReadonlyArray<A>) => B): Array<B> => self.map((_, i, as) => f(as.slice(i)))\n)\n\n/**\n * Finds the minimum element in an array based on a comparator.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const min = Array.min([3, 1, 2], Order.number)\n * assert.deepStrictEqual(min, 1)\n * ```\n *\n * @since 2.0.0\n */\nexport const min: {\n /**\n * Finds the minimum element in an array based on a comparator.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const min = Array.min([3, 1, 2], Order.number)\n * assert.deepStrictEqual(min, 1)\n * ```\n *\n * @since 2.0.0\n */\n <A>(O: Order.Order<A>): (self: NonEmptyReadonlyArray<A>) => A\n /**\n * Finds the minimum element in an array based on a comparator.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const min = Array.min([3, 1, 2], Order.number)\n * assert.deepStrictEqual(min, 1)\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A\n} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A => self.reduce(Order.min(O)))\n\n/**\n * Finds the maximum element in an array based on a comparator.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const max = Array.max([3, 1, 2], Order.number)\n * assert.deepStrictEqual(max, 3)\n * ```\n *\n * @since 2.0.0\n */\nexport const max: {\n /**\n * Finds the maximum element in an array based on a comparator.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const max = Array.max([3, 1, 2], Order.number)\n * assert.deepStrictEqual(max, 3)\n * ```\n *\n * @since 2.0.0\n */\n <A>(O: Order.Order<A>): (self: NonEmptyReadonlyArray<A>) => A\n /**\n * Finds the maximum element in an array based on a comparator.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const max = Array.max([3, 1, 2], Order.number)\n * assert.deepStrictEqual(max, 3)\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A\n} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A => self.reduce(Order.max(O)))\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const unfold = <B, A>(b: B, f: (b: B) => Option<readonly [A, B]>): Array<A> => {\n const out: Array<A> = []\n let next: B = b\n let o: Option<readonly [A, B]>\n while (O.isSome(o = f(next))) {\n const [a, b] = o.value\n out.push(a)\n next = b\n }\n return out\n}\n\n/**\n * This function creates and returns a new `Order` for an array of values based on a given `Order` for the elements of the array.\n * The returned `Order` compares two arrays by applying the given `Order` to each element in the arrays.\n * If all elements are equal, the arrays are then compared based on their length.\n * It is useful when you need to compare two arrays of the same type and you have a specific way of comparing each element of the array.\n *\n * @category instances\n * @since 2.0.0\n */\nexport const getOrder: <A>(O: Order.Order<A>) => Order.Order<ReadonlyArray<A>> = Order.array\n\n/**\n * Creates an equivalence relation for arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers1 = [1, 2, 3]\n * const numbers2 = [1, 2, 3]\n * const eq = Array.getEquivalence<number>((a, b) => a === b)\n * assert.deepStrictEqual(eq(numbers1, numbers2), true)\n * ```\n *\n * @category instances\n * @since 2.0.0\n */\nexport const getEquivalence: <A>(\n isEquivalent: Equivalence.Equivalence<A>\n) => Equivalence.Equivalence<ReadonlyArray<A>> = Equivalence.array\n\n/**\n * Performs a side-effect for each element of the `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * Array.forEach(numbers, n => console.log(n)) // 1, 2, 3\n * ```\n *\n * @since 2.0.0\n */\nexport const forEach: {\n /**\n * Performs a side-effect for each element of the `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * Array.forEach(numbers, n => console.log(n)) // 1, 2, 3\n * ```\n *\n * @since 2.0.0\n */\n <A>(f: (a: A, i: number) => void): (self: Iterable<A>) => void\n /**\n * Performs a side-effect for each element of the `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * Array.forEach(numbers, n => console.log(n)) // 1, 2, 3\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, f: (a: A, i: number) => void): void\n} = dual(2, <A>(self: Iterable<A>, f: (a: A, i: number) => void): void => fromIterable(self).forEach((a, i) => f(a, i)))\n\n/**\n * Remove duplicates from an `Iterable` using the provided `isEquivalent` function,\n * preserving the order of the first occurrence of each element.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 2, 3, 3, 3]\n * const unique = Array.dedupeWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const dedupeWith: {\n /**\n * Remove duplicates from an `Iterable` using the provided `isEquivalent` function,\n * preserving the order of the first occurrence of each element.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 2, 3, 3, 3]\n * const unique = Array.dedupeWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <S extends Iterable<any>>(\n isEquivalent: (self: ReadonlyArray.Infer<S>, that: ReadonlyArray.Infer<S>) => boolean\n ): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * Remove duplicates from an `Iterable` using the provided `isEquivalent` function,\n * preserving the order of the first occurrence of each element.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 2, 3, 3, 3]\n * const unique = Array.dedupeWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A>(\n self: NonEmptyReadonlyArray<A>,\n isEquivalent: (self: A, that: A) => boolean\n ): NonEmptyArray<A>\n /**\n * Remove duplicates from an `Iterable` using the provided `isEquivalent` function,\n * preserving the order of the first occurrence of each element.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 2, 3, 3, 3]\n * const unique = Array.dedupeWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A>\n} = dual(\n 2,\n <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const out: NonEmptyArray<A> = [headNonEmpty(input)]\n const rest = tailNonEmpty(input)\n for (const r of rest) {\n if (out.every((a) => !isEquivalent(r, a))) {\n out.push(r)\n }\n }\n return out\n }\n return []\n }\n)\n\n/**\n * Remove duplicates from an `Iterable`, preserving the order of the first occurrence of each element.\n * The equivalence used to compare elements is provided by `Equal.equivalence()` from the `Equal` module.\n *\n * @since 2.0.0\n */\nexport const dedupe = <S extends Iterable<any> | NonEmptyReadonlyArray<any>>(\n self: S\n): S extends NonEmptyReadonlyArray<infer A> ? NonEmptyArray<A> : S extends Iterable<infer A> ? Array<A> : never =>\n dedupeWith(self, Equal.equivalence()) as any\n\n/**\n * Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 1, 2, 2, 3, 3]\n * const unique = Array.dedupeAdjacentWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const dedupeAdjacentWith: {\n /**\n * Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 1, 2, 2, 3, 3]\n * const unique = Array.dedupeAdjacentWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A>(isEquivalent: (self: A, that: A) => boolean): (self: Iterable<A>) => Array<A>\n /**\n * Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 1, 2, 2, 3, 3]\n * const unique = Array.dedupeAdjacentWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A>\n} = dual(2, <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A> => {\n const out: Array<A> = []\n let lastA: O.Option<A> = O.none()\n for (const a of self) {\n if (O.isNone(lastA) || !isEquivalent(a, lastA.value)) {\n out.push(a)\n lastA = O.some(a)\n }\n }\n return out\n})\n\n/**\n * Deduplicates adjacent elements that are identical.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 1, 2, 2, 3, 3]\n * const unique = Array.dedupeAdjacent(numbers)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const dedupeAdjacent: <A>(self: Iterable<A>) => Array<A> = dedupeAdjacentWith(Equal.equivalence())\n\n/**\n * Joins the elements together with \"sep\" in the middle.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const strings = [\"a\", \"b\", \"c\"]\n * const joined = Array.join(strings, \"-\")\n * assert.deepStrictEqual(joined, \"a-b-c\")\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\nexport const join: {\n /**\n * Joins the elements together with \"sep\" in the middle.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const strings = [\"a\", \"b\", \"c\"]\n * const joined = Array.join(strings, \"-\")\n * assert.deepStrictEqual(joined, \"a-b-c\")\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\n (sep: string): (self: Iterable<string>) => string\n /**\n * Joins the elements together with \"sep\" in the middle.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const strings = [\"a\", \"b\", \"c\"]\n * const joined = Array.join(strings, \"-\")\n * assert.deepStrictEqual(joined, \"a-b-c\")\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\n (self: Iterable<string>, sep: string): string\n} = dual(2, (self: Iterable<string>, sep: string): string => fromIterable(self).join(sep))\n\n/**\n * Statefully maps over the chunk, producing new elements of type `B`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.mapAccum(numbers, 0, (acc, n) => [acc + n, acc + n])\n * assert.deepStrictEqual(result, [6, [1, 3, 6]])\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\nexport const mapAccum: {\n /**\n * Statefully maps over the chunk, producing new elements of type `B`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.mapAccum(numbers, 0, (acc, n) => [acc + n, acc + n])\n * assert.deepStrictEqual(result, [6, [1, 3, 6]])\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\n <S, A, B, I extends Iterable<A> = Iterable<A>>(\n s: S,\n f: (s: S, a: ReadonlyArray.Infer<I>, i: number) => readonly [S, B]\n ): (self: I) => [state: S, mappedArray: ReadonlyArray.With<I, B>]\n /**\n * Statefully maps over the chunk, producing new elements of type `B`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.mapAccum(numbers, 0, (acc, n) => [acc + n, acc + n])\n * assert.deepStrictEqual(result, [6, [1, 3, 6]])\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\n <S, A, B, I extends Iterable<A> = Iterable<A>>(\n self: I,\n s: S,\n f: (s: S, a: ReadonlyArray.Infer<I>, i: number) => readonly [S, B]\n ): [state: S, mappedArray: ReadonlyArray.With<I, B>]\n} = dual(\n 3,\n <S, A, B>(self: Iterable<A>, s: S, f: (s: S, a: A, i: number) => [S, B]): [state: S, mappedArray: Array<B>] => {\n let i = 0\n let s1 = s\n const out: Array<B> = []\n for (const a of self) {\n const r = f(s1, a, i)\n s1 = r[0]\n out.push(r[1])\n i++\n }\n return [s1, out]\n }\n)\n\n/**\n * Zips this chunk crosswise with the specified chunk using the specified combiner.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [\"a\", \"b\"]\n * const product = Array.cartesianWith(array1, array2, (a, b) => `${a}-${b}`)\n * assert.deepStrictEqual(product, [\"1-a\", \"1-b\", \"2-a\", \"2-b\"])\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\nexport const cartesianWith: {\n /**\n * Zips this chunk crosswise with the specified chunk using the specified combiner.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [\"a\", \"b\"]\n * const product = Array.cartesianWith(array1, array2, (a, b) => `${a}-${b}`)\n * assert.deepStrictEqual(product, [\"1-a\", \"1-b\", \"2-a\", \"2-b\"])\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B, C>(that: ReadonlyArray<B>, f: (a: A, b: B) => C): (self: ReadonlyArray<A>) => Array<C>\n /**\n * Zips this chunk crosswise with the specified chunk using the specified combiner.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [\"a\", \"b\"]\n * const product = Array.cartesianWith(array1, array2, (a, b) => `${a}-${b}`)\n * assert.deepStrictEqual(product, [\"1-a\", \"1-b\", \"2-a\", \"2-b\"])\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B, C>(self: ReadonlyArray<A>, that: ReadonlyArray<B>, f: (a: A, b: B) => C): Array<C>\n} = dual(\n 3,\n <A, B, C>(self: ReadonlyArray<A>, that: ReadonlyArray<B>, f: (a: A, b: B) => C): Array<C> =>\n flatMap(self, (a) => map(that, (b) => f(a, b)))\n)\n\n/**\n * Zips this chunk crosswise with the specified chunk.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [\"a\", \"b\"]\n * const product = Array.cartesian(array1, array2)\n * assert.deepStrictEqual(product, [[1, \"a\"], [1, \"b\"], [2, \"a\"], [2, \"b\"]])\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\nexport const cartesian: {\n /**\n * Zips this chunk crosswise with the specified chunk.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [\"a\", \"b\"]\n * const product = Array.cartesian(array1, array2)\n * assert.deepStrictEqual(product, [[1, \"a\"], [1, \"b\"], [2, \"a\"], [2, \"b\"]])\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <B>(that: ReadonlyArray<B>): <A>(self: ReadonlyArray<A>) => Array<[A, B]>\n /**\n * Zips this chunk crosswise with the specified chunk.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [\"a\", \"b\"]\n * const product = Array.cartesian(array1, array2)\n * assert.deepStrictEqual(product, [[1, \"a\"], [1, \"b\"], [2, \"a\"], [2, \"b\"]])\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B>(self: ReadonlyArray<A>, that: ReadonlyArray<B>): Array<[A, B]>\n} = dual(\n 2,\n <A, B>(self: ReadonlyArray<A>, that: ReadonlyArray<B>): Array<[A, B]> => cartesianWith(self, that, (a, b) => [a, b])\n)\n\n// -------------------------------------------------------------------------------------\n// do notation\n// -------------------------------------------------------------------------------------\n\n/**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\nexport const Do: ReadonlyArray<{}> = of({})\n\n/**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\nexport const bind: {\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\n <A extends object, N extends string, B>(tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): (\n self: ReadonlyArray<A>\n ) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\n <A extends object, N extends string, B>(\n self: ReadonlyArray<A>,\n tag: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => ReadonlyArray<B>\n ): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n} = doNotation.bind<ReadonlyArrayTypeLambda>(map, flatMap) as any\n\n/**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\nexport const bindTo: {\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\n <N extends string>(tag: N): <A>(self: ReadonlyArray<A>) => Array<{ [K in N]: A }>\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\n <A, N extends string>(self: ReadonlyArray<A>, tag: N): Array<{ [K in N]: A }>\n} = doNotation.bindTo<ReadonlyArrayTypeLambda>(map) as any\n\nconst let_: {\n <N extends string, B, A extends object>(\n tag: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): (self: ReadonlyArray<A>) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n <N extends string, A extends object, B>(\n self: ReadonlyArray<A>,\n tag: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n} = doNotation.let_<ReadonlyArrayTypeLambda>(map) as any\n\nexport {\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link bind}\n * @see {@link Do}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n *\n * ```\n * @category do notation\n * @since 3.2.0\n */\n let_ as let\n}\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as Order from \"effect/Order\"\nimport type ts from \"typescript\"\nimport * as TypeParser from \"../utils/TypeParser.js\"\nimport type { TypeScriptApi } from \"./TSAPI.js\"\n\n/**\n * Collects the given node and all its ancestor nodes that fully contain the specified TextRange.\n *\n * This function starts from the provided node and traverses up the AST, collecting\n * the node itself and its ancestors that encompass the given range.\n *\n * @param node - The starting AST node.\n * @param textRange - The range of text to use for filtering nodes.\n * @returns An array of nodes, including the starting node and its ancestors, that fully contain the specified range.\n */\nfunction collectSelfAndAncestorNodesInRange(\n node: ts.Node,\n textRange: ts.TextRange\n): Array<ts.Node> {\n let result = ReadonlyArray.empty<ts.Node>()\n let parent = node\n while (parent) {\n if (parent.end >= textRange.end) {\n result = pipe(result, ReadonlyArray.append(parent))\n }\n parent = parent.parent\n }\n return result\n}\n\n/**\n * Collects the node at the given position and all its ancestor nodes\n * that fully contain the specified TextRange.\n *\n * This function starts from the closest token at the given position\n * and traverses up the AST, collecting nodes that encompass the range.\n *\n * @param ts - The TypeScript API.\n * @returns A function that takes a SourceFile and a TextRange, and returns\n * an array of nodes containing the range.\n */\nexport function getAncestorNodesInRange(\n ts: TypeScriptApi\n) {\n return ((sourceFile: ts.SourceFile, textRange: ts.TextRange) => {\n const precedingToken = ts.findPrecedingToken(textRange.pos, sourceFile)\n if (!precedingToken) return ReadonlyArray.empty<ts.Node>()\n return collectSelfAndAncestorNodesInRange(precedingToken, textRange)\n })\n}\n\n/**\n * Finds the deepest AST node at the specified position within the given SourceFile.\n *\n * This function traverses the AST to locate the node that contains the given position.\n * If multiple nodes overlap the position, it returns the most specific (deepest) node.\n *\n * @param sourceFile - The TypeScript SourceFile to search within.\n * @param position - The position in the file to locate the node for.\n * @returns An `Option`:\n * - `Option.some<ts.Node>` if a node is found at the specified position.\n * - `Option.none` if no node is found at the specified position.\n */\nfunction findNodeAtPosition(\n ts: TypeScriptApi,\n sourceFile: ts.SourceFile,\n position: number\n): Option.Option<ts.Node> {\n function find(node: ts.Node): ts.Node | undefined {\n if (position >= node.getStart() && position < node.getEnd()) {\n // If the position is within this node, keep traversing its children\n return ts.forEachChild(node, find) || node\n }\n return undefined\n }\n return Option.fromNullable(find(sourceFile))\n}\n\n/**\n * Collects the node at the given position, its descendants, and all its ancestor nodes\n * that fully contain the specified TextRange.\n *\n * This function starts by locating the node at the given position within the AST,\n * traverses down to include its descendants, and then traverses up to include its ancestors,\n * collecting all nodes that encompass the specified range.\n *\n * @param sourceFile - The TypeScript SourceFile to search within.\n * @param textRange - The range of text to use for filtering nodes.\n * @returns An array of nodes that are either descendants or ancestors of the node\n * at the given position and that fully contain the specified range.\n */\nexport function collectDescendantsAndAncestorsInRange(\n ts: TypeScriptApi,\n sourceFile: ts.SourceFile,\n textRange: ts.TextRange\n) {\n const nodeAtPosition = findNodeAtPosition(ts, sourceFile, textRange.pos)\n if (Option.isNone(nodeAtPosition)) return ReadonlyArray.empty<ts.Node>()\n return collectSelfAndAncestorNodesInRange(nodeAtPosition.value, textRange)\n}\n\n/**\n * Extracts the `Effect` from an `Effect.gen` generator function with a single return statement.\n *\n * This function analyzes the provided node to determine if it represents an `Effect.gen` call.\n * If the generator function body contains exactly one `return` statement, and that statement\n * yields an `Effect`, the function extracts and returns the inner `Effect`.\n *\n * @param typeChecker - The TypeScript type checker, used to analyze the types of nodes.\n * @param node - The AST node to analyze.\n * @returns An `Option`:\n * - `Option.some<ts.Node>` containing the inner `Effect` if the node is an `Effect.gen`\n * with a single return statement yielding an `Effect`.\n * - `Option.none` if the node does not match the criteria.\n */\nexport function getSingleReturnEffectFromEffectGen(\n ts: TypeScriptApi,\n typeChecker: ts.TypeChecker,\n node: ts.Node\n): Option.Option<ts.Node> {\n // is the node an effect gen-like?\n const effectGenLike = TypeParser.effectGen(ts, typeChecker)(node)\n\n if (Option.isSome(effectGenLike)) {\n // if the node is an effect gen-like, we need to check if its body is just a single return statement\n const body = effectGenLike.value.body\n if (\n body.statements.length === 1 &&\n ts.isReturnStatement(body.statements[0]) &&\n body.statements[0].expression &&\n ts.isYieldExpression(body.statements[0].expression) &&\n body.statements[0].expression.expression\n ) {\n // get the type of the node\n const nodeToCheck = body.statements[0].expression.expression\n const type = typeChecker.getTypeAtLocation(nodeToCheck)\n const maybeEffect = TypeParser.effectType(ts, typeChecker)(type, nodeToCheck)\n if (Option.isSome(maybeEffect)) {\n return Option.some(nodeToCheck)\n }\n }\n }\n return Option.none()\n}\n\n/**\n * Ensures value is a text range\n */\nexport function toTextRange(positionOrRange: number | ts.TextRange): ts.TextRange {\n return typeof positionOrRange === \"number\"\n ? { end: positionOrRange, pos: positionOrRange }\n : positionOrRange\n}\n\nexport function isNodeInRange(textRange: ts.TextRange) {\n return (node: ts.Node) => node.pos <= textRange.pos && node.end >= textRange.end\n}\n\nexport function transformAsyncAwaitToEffectGen(\n ts: TypeScriptApi\n) {\n return (\n node: ts.FunctionDeclaration | ts.ArrowFunction | ts.FunctionExpression,\n effectModuleName: string,\n onAwait: (expression: ts.Expression) => ts.Expression\n ) => {\n function visitor(_: ts.Node): ts.Node {\n if (ts.isAwaitExpression(_)) {\n const expression = ts.visitEachChild(_.expression, visitor, ts.nullTransformationContext)\n\n return ts.factory.createYieldExpression(\n ts.factory.createToken(ts.SyntaxKind.AsteriskToken),\n onAwait(expression)\n )\n }\n return ts.visitEachChild(_, visitor, ts.nullTransformationContext)\n }\n const generatorBody = visitor(node.body!)\n\n const generator = ts.factory.createFunctionExpression(\n undefined,\n ts.factory.createToken(ts.SyntaxKind.AsteriskToken),\n undefined,\n [],\n [],\n undefined,\n generatorBody as any // NOTE(mattia): intended, to use same routine for both ConciseBody and Body\n )\n\n const effectGenCallExp = ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectModuleName),\n \"gen\"\n ),\n undefined,\n [generator as any]\n )\n\n let currentFlags = ts.getCombinedModifierFlags(node)\n currentFlags &= ~ts.ModifierFlags.Async\n const newModifiers = ts.factory.createModifiersFromModifierFlags(currentFlags)\n\n if (ts.isArrowFunction(node)) {\n return ts.factory.createArrowFunction(\n newModifiers,\n node.typeParameters,\n node.parameters,\n undefined,\n node.equalsGreaterThanToken,\n effectGenCallExp\n )\n }\n\n const newBody = ts.factory.createBlock([\n ts.factory.createReturnStatement(effectGenCallExp)\n ])\n\n if (ts.isFunctionDeclaration(node)) {\n return ts.factory.createFunctionDeclaration(\n newModifiers,\n node.asteriskToken,\n node.name,\n node.typeParameters,\n node.parameters,\n undefined,\n newBody\n )\n }\n return ts.factory.createFunctionExpression(\n newModifiers,\n node.asteriskToken,\n node.name,\n node.typeParameters,\n node.parameters,\n undefined,\n newBody\n )\n }\n}\n\nexport function addReturnTypeAnnotation(\n ts: TypeScriptApi,\n changes: ts.textChanges.ChangeTracker\n) {\n return (\n sourceFile: ts.SourceFile,\n declaration:\n | ts.FunctionDeclaration\n | ts.FunctionExpression\n | ts.ArrowFunction\n | ts.MethodDeclaration,\n typeNode: ts.TypeNode\n ) => {\n const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile)\n const needParens = ts.isArrowFunction(declaration) && closeParen === undefined\n const endNode = needParens ? declaration.parameters[0] : closeParen\n if (endNode) {\n if (needParens) {\n changes.insertNodeBefore(\n sourceFile,\n endNode,\n ts.factory.createToken(ts.SyntaxKind.OpenParenToken)\n )\n changes.insertNodeAfter(\n sourceFile,\n endNode,\n ts.factory.createToken(ts.SyntaxKind.CloseParenToken)\n )\n }\n changes.insertNodeAt(sourceFile, endNode.end, typeNode, { prefix: \": \" })\n }\n }\n}\n\nexport function removeReturnTypeAnnotation(\n ts: TypeScriptApi,\n changes: ts.textChanges.ChangeTracker\n) {\n return (\n sourceFile: ts.SourceFile,\n declaration:\n | ts.FunctionDeclaration\n | ts.FunctionExpression\n | ts.ArrowFunction\n | ts.MethodDeclaration\n ) => {\n const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile)\n const needParens = ts.isArrowFunction(declaration) && closeParen === undefined\n const endNode = needParens ? declaration.parameters[0] : closeParen\n if (endNode && declaration.type) {\n changes.deleteRange(sourceFile, { pos: endNode.end, end: declaration.type.end })\n }\n }\n}\n\nexport function findImportedModuleIdentifier(ts: TypeScriptApi) {\n return (test: (node: ts.Node) => boolean) =>\n (sourceFile: ts.SourceFile): Option.Option<ts.Identifier> => {\n for (const statement of sourceFile.statements) {\n if (!ts.isImportDeclaration(statement)) continue\n const importClause = statement.importClause\n if (!importClause) continue\n const namedBindings = importClause.namedBindings\n if (!namedBindings) continue\n if (ts.isNamespaceImport(namedBindings)) {\n if (test(namedBindings.name)) return Option.some(namedBindings.name)\n } else if (ts.isNamedImports(namedBindings)) {\n for (const importSpecifier of namedBindings.elements) {\n if (test(importSpecifier.name)) return Option.some(importSpecifier.name)\n }\n }\n }\n return Option.none()\n }\n}\n\nexport function simplifyTypeNode(\n ts: TypeScriptApi\n) {\n function collectCallable(\n typeNode: ts.TypeNode\n ): Option.Option<Array<ts.CallSignatureDeclaration>> {\n // (() => 1) -> skip to inner node\n if (ts.isParenthesizedTypeNode(typeNode)) return collectCallable(typeNode.type)\n // () => 1 -> convert to call signature\n if (ts.isFunctionTypeNode(typeNode)) {\n return Option.some([\n ts.factory.createCallSignature(typeNode.typeParameters, typeNode.parameters, typeNode.type)\n ])\n }\n // { ... } -> if every member is callsignature, return a merge of all of those\n if (ts.isTypeLiteralNode(typeNode)) {\n const allCallSignatures = typeNode.members.every(ts.isCallSignatureDeclaration)\n if (allCallSignatures) {\n return Option.some(typeNode.members as any as Array<ts.CallSignatureDeclaration>)\n }\n }\n // ... & ... -> if both are callable, return merge of both\n if (ts.isIntersectionTypeNode(typeNode)) {\n const members = typeNode.types.map(collectCallable)\n if (members.every(Option.isSome)) {\n return Option.some(members.map((_) => Option.isSome(_) ? _.value : []).flat())\n }\n }\n\n return Option.none()\n }\n\n return (typeNode: ts.TypeNode) => {\n const callSignatures = collectCallable(typeNode)\n if (Option.isSome(callSignatures) && callSignatures.value.length > 1) {\n return ts.factory.createTypeLiteralNode(callSignatures.value)\n }\n return typeNode\n }\n}\n\nexport function isPipeCall(ts: TypeScriptApi) {\n return (node: ts.Node): node is ts.CallExpression => {\n if (!ts.isCallExpression(node)) return false\n const expression = node.expression\n if (!ts.isIdentifier(expression)) return false\n if (expression.text !== \"pipe\") return false\n return true\n }\n}\n\nexport function asDataFirstExpression(ts: TypeScriptApi, checker: ts.TypeChecker) {\n return (node: ts.Node, self: ts.Expression): Option.Option<ts.CallExpression> => {\n if (!ts.isCallExpression(node)) return Option.none()\n const signature = checker.getResolvedSignature(node)\n if (!signature) return Option.none()\n const callSignatures = checker.getTypeAtLocation(node.expression).getCallSignatures()\n for (let i = 0; i < callSignatures.length; i++) {\n const callSignature = callSignatures[i]\n if (callSignature.parameters.length === node.arguments.length + 1) {\n return Option.some(\n ts.factory.createCallExpression(\n node.expression,\n [],\n [self].concat(node.arguments)\n )\n )\n }\n }\n return Option.none()\n }\n}\n\nexport function deterministicTypeOrder(ts: TypeScriptApi, typeChecker: ts.TypeChecker) {\n return Order.make((a: ts.Type, b: ts.Type) => {\n const aName = typeChecker.typeToString(a)\n const bName = typeChecker.typeToString(b)\n if (aName < bName) return -1\n if (aName > bName) return 1\n return 0\n })\n}\n\nexport function tryPreserveDeclarationSemantics(ts: TypeScriptApi) {\n return (nodeToReplace: ts.Node, node: ts.Node) => {\n // new node should be an expression!\n if (!ts.isExpression(node)) return node\n // ok, we need to replace. is that a method or a function?\n if (ts.isFunctionDeclaration(nodeToReplace)) {\n // I need a name!!!\n if (!nodeToReplace.name) return node\n return ts.factory.createVariableStatement(\n nodeToReplace.modifiers,\n ts.factory.createVariableDeclarationList(\n [ts.factory.createVariableDeclaration(\n nodeToReplace.name,\n undefined,\n undefined,\n node\n )],\n ts.NodeFlags.Const\n )\n )\n } else if (ts.isMethodDeclaration(nodeToReplace)) {\n return ts.factory.createPropertyDeclaration(\n nodeToReplace.modifiers,\n nodeToReplace.name,\n undefined,\n undefined,\n node\n )\n }\n // I don't know what else to do!\n return node\n }\n}\n","import * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport type { TypeScriptApi } from \"./TSAPI.js\"\n\nexport function getMissingTypeEntriesInTargetType(ts: TypeScriptApi, typeChecker: ts.TypeChecker) {\n return (realType: ts.Type, expectedType: ts.Type) => {\n const result: Array<ts.Type> = []\n const toTest: Array<ts.Type> = [realType]\n while (toTest.length > 0) {\n const type = toTest.pop()\n if (!type) return result\n if (type.isUnion()) {\n toTest.push(...type.types)\n } else {\n const assignable = typeChecker.isTypeAssignableTo(type, expectedType)\n if (!assignable) {\n result.push(type)\n }\n }\n }\n return result\n }\n}\n\ntype ConvertibleDeclaration =\n | ts.FunctionDeclaration\n | ts.FunctionExpression\n | ts.ArrowFunction\n | ts.MethodDeclaration\n\nexport function getInferredReturnType(ts: TypeScriptApi, typeChecker: ts.TypeChecker) {\n function isConvertibleDeclaration(node: ts.Node): node is ConvertibleDeclaration {\n switch (node.kind) {\n case ts.SyntaxKind.FunctionDeclaration:\n case ts.SyntaxKind.FunctionExpression:\n case ts.SyntaxKind.ArrowFunction:\n case ts.SyntaxKind.MethodDeclaration:\n return true\n default:\n return false\n }\n }\n\n return (node: ts.Node): Option.Option<ts.Type> => {\n let declaration = node\n while (declaration && !isConvertibleDeclaration(declaration)) {\n declaration = declaration.parent\n }\n if (!isConvertibleDeclaration(declaration)) return Option.none()\n\n if (!declaration || !declaration.body) {\n return Option.none()\n }\n\n let returnType: ts.Type | undefined\n\n if (typeChecker.isImplementationOfOverload(declaration)) {\n const signatures = typeChecker.getTypeAtLocation(declaration).getCallSignatures()\n if (signatures.length > 1) {\n returnType = typeChecker.getUnionType(\n signatures.map((s) => s.getReturnType()).filter((_) => !!_)\n )\n }\n }\n if (!returnType) {\n const signature = typeChecker.getSignatureFromDeclaration(declaration)\n if (signature) {\n const typePredicate = typeChecker.getTypePredicateOfSignature(signature)\n if (typePredicate && typePredicate.type) {\n return Option.some(typePredicate.type)\n } else {\n returnType = typeChecker.getReturnTypeOfSignature(signature)\n }\n }\n }\n\n if (!returnType) {\n return Option.none()\n }\n\n return Option.some(returnType)\n }\n}\n\nexport function expectedAndRealType(ts: TypeScriptApi, typeChecker: ts.TypeChecker) {\n return (node: ts.Node): Array<[ts.Node, ts.Type, ts.Node, ts.Type]> => {\n if (ts.isVariableDeclaration(node) && node.initializer) {\n const expectedType = typeChecker.getTypeAtLocation(node.name)\n const realType = typeChecker.getTypeAtLocation(node.initializer)\n return [[node.name, expectedType, node.initializer, realType]]\n }\n if (ts.isCallExpression(node)) {\n const resolvedSignature = typeChecker.getResolvedSignature(node)\n if (resolvedSignature) {\n return resolvedSignature.getParameters().map((parameter, index) => {\n const expectedType = typeChecker.getTypeOfSymbolAtLocation(parameter, node)\n const realType = typeChecker.getTypeAtLocation(node.arguments[index])\n return [node.arguments[index], expectedType, node.arguments[index], realType]\n })\n }\n }\n if (\n ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node) ||\n ts.isNoSubstitutionTemplateLiteral(node)\n ) {\n const parent = node.parent\n if (ts.isObjectLiteralElement(parent)) {\n if (ts.isObjectLiteralExpression(parent.parent) && parent.name === node) {\n const type = typeChecker.getContextualType(parent.parent)\n if (type) {\n const symbol = typeChecker.getPropertyOfType(type, node.text)\n if (symbol) {\n const expectedType = typeChecker.getTypeOfSymbolAtLocation(symbol, node)\n const realType = typeChecker.getTypeAtLocation(node)\n return [[node, expectedType, node, realType]]\n }\n }\n }\n }\n }\n if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken) {\n const expectedType = typeChecker.getTypeAtLocation(node.left)\n const realType = typeChecker.getTypeAtLocation(node.right)\n return [[node.left, expectedType, node.right, realType]]\n }\n if (ts.isReturnStatement(node) && node.expression) {\n const expectedType = Option.getOrUndefined(getInferredReturnType(ts, typeChecker)(node))\n const realType = typeChecker.getTypeAtLocation(node.expression)\n if (expectedType) return [[node, expectedType, node, realType]]\n }\n if (ts.isArrowFunction(node) && ts.isExpression(node.body)) {\n const body = node.body\n const expectedType = typeChecker.getContextualType(body)\n const realType = typeChecker.getTypeAtLocation(body)\n if (expectedType) return [[body, expectedType, body, realType]]\n }\n if (ts.isSatisfiesExpression(node)) {\n const expectedType = typeChecker.getTypeAtLocation(node.type)\n const realType = typeChecker.getTypeAtLocation(node.expression)\n return [[node.expression, expectedType, node.expression, realType]]\n }\n return []\n }\n}\n","import * as ReadonlyArray from \"effect/Array\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport type { ApplicableDiagnosticDefinition } from \"../definition.js\"\nimport { createDiagnostic } from \"../definition.js\"\nimport { deterministicTypeOrder } from \"../utils/AST.js\"\nimport * as TypeCheckerApi from \"../utils/TypeCheckerApi.js\"\nimport * as TypeParser from \"../utils/TypeParser.js\"\n\nexport const missingEffectContext = createDiagnostic({\n code: 1,\n apply: (ts, program) => (sourceFile) => {\n const typeChecker = program.getTypeChecker()\n const effectDiagnostics: Array<ApplicableDiagnosticDefinition> = []\n const sortTypes = ReadonlyArray.sort(deterministicTypeOrder(ts, typeChecker))\n\n const visit = (node: ts.Node) => {\n const entries = TypeCheckerApi.expectedAndRealType(ts, typeChecker)(node)\n for (const [node, expectedType, valueNode, realType] of entries) {\n // the expected type is an effect\n const expectedEffect = TypeParser.effectType(ts, typeChecker)(\n expectedType,\n node\n )\n if (Option.isNone(expectedEffect)) continue\n // the real type is an effect\n const realEffect = TypeParser.effectType(ts, typeChecker)(\n realType,\n valueNode\n )\n if (Option.isNone(realEffect)) continue\n // get the missing context types\n const missingContext = TypeCheckerApi.getMissingTypeEntriesInTargetType(\n ts,\n typeChecker\n )(\n realEffect.value.R,\n expectedEffect.value.R\n )\n if (missingContext.length > 0) {\n effectDiagnostics.push(\n {\n node,\n category: ts.DiagnosticCategory.Error,\n messageText: `Missing '${\n sortTypes(missingContext).map((_) => typeChecker.typeToString(_)).join(\" | \")\n }' in the expected Effect context.`\n }\n )\n }\n }\n ts.forEachChild(node, visit)\n }\n ts.forEachChild(sourceFile, visit)\n\n return effectDiagnostics\n }\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport type { ApplicableDiagnosticDefinition } from \"../definition.js\"\nimport { createDiagnostic } from \"../definition.js\"\nimport { deterministicTypeOrder } from \"../utils/AST.js\"\nimport * as TypeCheckerApi from \"../utils/TypeCheckerApi.js\"\nimport * as TypeParser from \"../utils/TypeParser.js\"\n\nexport const missingEffectError = createDiagnostic({\n code: 2,\n apply: (ts, program) => (sourceFile) => {\n const typeChecker = program.getTypeChecker()\n const effectDiagnostics: Array<ApplicableDiagnosticDefinition> = []\n const sortTypes = ReadonlyArray.sort(deterministicTypeOrder(ts, typeChecker))\n\n const visit = (node: ts.Node) => {\n const entries = TypeCheckerApi.expectedAndRealType(ts, typeChecker)(node)\n for (const [node, expectedType, valueNode, realType] of entries) {\n // the expected type is an effect\n const expectedEffect = TypeParser.effectType(ts, typeChecker)(\n expectedType,\n node\n )\n if (Option.isNone(expectedEffect)) continue\n // the real type is an effect\n const realEffect = TypeParser.effectType(ts, typeChecker)(\n realType,\n valueNode\n )\n if (Option.isNone(realEffect)) continue\n // get the missing error types\n const missingErrorTypes = TypeCheckerApi.getMissingTypeEntriesInTargetType(\n ts,\n typeChecker\n )(\n realEffect.value.E,\n expectedEffect.value.E\n )\n\n if (missingErrorTypes.length > 0) {\n effectDiagnostics.push(\n {\n node,\n category: ts.DiagnosticCategory.Error,\n messageText: `Missing '${\n sortTypes(missingErrorTypes).map((_) => typeChecker.typeToString(_)).join(\" | \")\n }' in the expected Effect errors.`\n }\n )\n }\n }\n ts.forEachChild(node, visit)\n }\n ts.forEachChild(sourceFile, visit)\n\n return effectDiagnostics\n }\n})\n","import { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport type { ApplicableDiagnosticDefinition } from \"../definition.js\"\nimport { createDiagnostic } from \"../definition.js\"\nimport * as TypeParser from \"../utils/TypeParser.js\"\n\nexport const missingStarInYieldEffectGen = createDiagnostic({\n code: 4,\n apply: (ts, program) => (sourceFile) => {\n const typeChecker = program.getTypeChecker()\n const effectDiagnostics: Array<ApplicableDiagnosticDefinition> = []\n const brokenGenerators = new Set<ts.Node>()\n const brokenYields = new Set<ts.Node>()\n\n const visit = (functionStarNode: ts.Node | undefined) => (node: ts.Node) => {\n // error if yield is not followed by *\n if (\n functionStarNode && ts.isYieldExpression(node) && node.expression &&\n node.asteriskToken === undefined\n ) {\n const type = typeChecker.getTypeAtLocation(node.expression)\n const effect = TypeParser.effectType(ts, typeChecker)(type, node.expression)\n if (Option.isSome(effect)) {\n brokenGenerators.add(functionStarNode)\n brokenYields.add(node)\n }\n }\n // continue if we hit effect gen-like\n const effectGenLike = pipe(\n TypeParser.effectGen(ts, typeChecker)(node),\n Option.orElse(() => TypeParser.effectFnUntracedGen(ts, typeChecker)(node)),\n Option.orElse(() => TypeParser.effectFnGen(ts, typeChecker)(node))\n )\n if (Option.isSome(effectGenLike)) {\n ts.forEachChild(effectGenLike.value.body, visit(effectGenLike.value.functionStar))\n } // stop when we hit a generator function\n else if (\n (ts.isFunctionExpression(node) || ts.isMethodDeclaration(node)) &&\n node.asteriskToken !== undefined\n ) {\n // continue with new parent function star node\n ts.forEachChild(node, visit(undefined))\n } else {\n // continue with current parent function star node\n ts.forEachChild(node, visit(functionStarNode))\n }\n }\n ts.forEachChild(sourceFile, visit(undefined))\n\n // emit diagnostics\n brokenGenerators.forEach((node) =>\n effectDiagnostics.push({\n node,\n category: ts.DiagnosticCategory.Error,\n messageText: `Seems like you used yield instead of yield* inside this Effect.gen.`\n })\n )\n brokenYields.forEach((node) =>\n effectDiagnostics.push({\n node,\n category: ts.DiagnosticCategory.Error,\n messageText:\n `When yielding Effects inside Effect.gen, you should use yield* instead of yield.`\n })\n )\n\n return effectDiagnostics\n }\n})\n","import * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport type { ApplicableDiagnosticDefinition } from \"../definition.js\"\nimport { createDiagnostic } from \"../definition.js\"\nimport * as AST from \"../utils/AST.js\"\n\nexport const unnecessaryEffectGen = createDiagnostic({\n code: 5,\n apply: (ts, program) => (sourceFile) => {\n const typeChecker = program.getTypeChecker()\n const effectDiagnostics: Array<ApplicableDiagnosticDefinition> = []\n const brokenGenerators = new Set<ts.Node>()\n\n const visit = (node: ts.Node) => {\n if (Option.isSome(AST.getSingleReturnEffectFromEffectGen(ts, typeChecker, node))) {\n brokenGenerators.add(node)\n }\n ts.forEachChild(node, visit)\n }\n ts.forEachChild(sourceFile, visit)\n\n // emit diagnostics\n brokenGenerators.forEach((node) =>\n effectDiagnostics.push({\n node,\n category: ts.DiagnosticCategory.Suggestion,\n messageText:\n `This Effect.gen is useless here because it only contains a single return statement.`\n })\n )\n\n return effectDiagnostics\n }\n})\n","/**\n * @since 1.0.0\n */\nimport { floatingEffect } from \"./diagnostics/floatingEffect.js\"\nimport { missingEffectContext } from \"./diagnostics/missingEffectContext.js\"\nimport { missingEffectError } from \"./diagnostics/missingEffectError.js\"\nimport { missingStarInYieldEffectGen } from \"./diagnostics/missingStarInYieldEffectGen.js\"\nimport { unnecessaryEffectGen } from \"./diagnostics/unnecessaryEffectGen.js\"\n\n/**\n * @since 1.0.0\n */\nexport const diagnostics = {\n missingEffectContext,\n missingEffectError,\n floatingEffect,\n missingStarInYieldEffectGen,\n unnecessaryEffectGen\n}\n","/**\n * @since 1.0.0\n */\nimport * as ReadonlyArray from \"effect/Array\"\nimport * as Eq from \"effect/Equivalence\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as AST from \"./utils/AST.js\"\nimport type { TypeScriptApi } from \"./utils/TSAPI.js\"\nimport * as TypeParser from \"./utils/TypeParser.js\"\n\nconst SymbolDisplayPartEq = Eq.make<ts.SymbolDisplayPart>((fa, fb) =>\n fa.kind === fb.kind && fa.text === fb.text\n)\n\nconst JSDocTagInfoEq = Eq.make<ts.JSDocTagInfo>((fa, fb) =>\n fa.name === fb.name && typeof fa.text === typeof fb.text &&\n (typeof fa.text !== \"undefined\" ? Eq.array(SymbolDisplayPartEq)(fa.text!, fb.text!) : true)\n)\n\n/**\n * @since 1.0.0\n */\nexport function dedupeJsDocTags(quickInfo: ts.QuickInfo): ts.QuickInfo {\n if (quickInfo.tags) {\n return {\n ...quickInfo,\n tags: ReadonlyArray.dedupeWith(quickInfo.tags, JSDocTagInfoEq)\n }\n }\n return quickInfo\n}\n\nfunction formatTypeForQuickInfo(\n ts: TypeScriptApi,\n typeChecker: ts.TypeChecker\n) {\n return (channelType: ts.Type, channelName: string) => {\n const stringRepresentation = typeChecker.typeToString(\n channelType,\n undefined,\n ts.TypeFormatFlags.NoTruncation\n )\n return `type ${channelName} = ${stringRepresentation}`\n }\n}\n\nexport function prependEffectTypeArguments(ts: TypeScriptApi, program: ts.Program) {\n return (sourceFileName: string, position: number, quickInfo: ts.QuickInfo): ts.QuickInfo => {\n const sourceFile = program.getSourceFile(sourceFileName)\n if (!sourceFile) return quickInfo\n\n const hasTruncationHappened =\n ts.displayPartsToString(quickInfo.displayParts).indexOf(\"...\") > -1\n if (!hasTruncationHappened) return quickInfo\n\n const typeChecker = program.getTypeChecker()\n\n const effectTypeArgsDocumentation = pipe(\n AST.getAncestorNodesInRange(ts)(sourceFile, AST.toTextRange(position)),\n ReadonlyArray.head,\n Option.flatMap((_) =>\n TypeParser.effectType(ts, typeChecker)(typeChecker.getTypeAtLocation(_), _)\n ),\n Option.map((_) => [{\n kind: \"text\",\n text: (\n \"```ts\\n\" +\n \"/* Effect Type Parameters */\\n\" +\n formatTypeForQuickInfo(ts, typeChecker)(_.A, \"Success\") +\n \"\\n\" +\n formatTypeForQuickInfo(ts, typeChecker)(_.E, \"Failure\") +\n \"\\n\" +\n formatTypeForQuickInfo(ts, typeChecker)(_.R, \"Requirements\") +\n \"\\n```\\n\"\n )\n }]),\n Option.getOrElse(() => [] as Array<ts.SymbolDisplayPart>)\n )\n\n if (quickInfo.documentation) {\n return {\n ...quickInfo,\n documentation: effectTypeArgsDocumentation.concat(quickInfo.documentation)\n }\n }\n\n return {\n ...quickInfo,\n documentation: effectTypeArgsDocumentation\n }\n }\n}\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport { createRefactor } from \"../definition.js\"\nimport * as AST from \"../utils/AST.js\"\nimport * as TypeParser from \"../utils/TypeParser.js\"\n\nexport const asyncAwaitToGen = createRefactor({\n name: \"effect/asyncAwaitToGen\",\n description: \"Convert to Effect.gen\",\n apply: (ts, program) => (sourceFile, textRange) =>\n pipe(\n AST.getAncestorNodesInRange(ts)(sourceFile, textRange),\n ReadonlyArray.filter((node) =>\n ts.isFunctionDeclaration(node) || ts.isArrowFunction(node) || ts.isFunctionExpression(node)\n ),\n ReadonlyArray.filter((node) => !!node.body),\n ReadonlyArray.filter((node) =>\n !!(ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Async)\n ),\n ReadonlyArray.head,\n Option.map((node) => ({\n kind: \"refactor.rewrite.effect.asyncAwaitToGen\",\n description: \"Rewrite to Effect.gen\",\n apply: (changeTracker) => {\n const isImportedEffectModule = TypeParser.importedEffectModule(\n ts,\n program.getTypeChecker()\n )\n const effectModuleIdentifierName = pipe(\n AST.findImportedModuleIdentifier(ts)((node) =>\n Option.isSome(isImportedEffectModule(node))\n )(sourceFile),\n Option.map((node) => node.text),\n Option.getOrElse(() => \"Effect\")\n )\n\n const newDeclaration = AST.transformAsyncAwaitToEffectGen(\n ts\n )(\n node,\n effectModuleIdentifierName,\n (expression) =>\n ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectModuleIdentifierName),\n \"promise\"\n ),\n undefined,\n [\n ts.factory.createArrowFunction(\n undefined,\n undefined,\n [],\n undefined,\n undefined,\n expression\n )\n ]\n )\n )\n\n changeTracker.replaceNode(sourceFile, node, newDeclaration)\n }\n }))\n )\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport { createRefactor } from \"../definition.js\"\nimport * as AST from \"../utils/AST.js\"\nimport * as TypeParser from \"../utils/TypeParser.js\"\n\nexport const asyncAwaitToGenTryPromise = createRefactor({\n name: \"effect/asyncAwaitToGenTryPromise\",\n description: \"Convert to Effect.gen with failures\",\n apply: (ts, program) => (sourceFile, textRange) =>\n pipe(\n AST.getAncestorNodesInRange(ts)(sourceFile, textRange),\n ReadonlyArray.filter(\n (node) =>\n ts.isFunctionDeclaration(node) || ts.isArrowFunction(node) ||\n ts.isFunctionExpression(node)\n ),\n ReadonlyArray.filter((node) => !!node.body),\n ReadonlyArray.filter((node) =>\n !!(ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Async)\n ),\n ReadonlyArray.head,\n Option.map((node) => ({\n kind: \"refactor.rewrite.effect.asyncAwaitToGenTryPromise\",\n description: \"Rewrite to Effect.gen with failures\",\n apply: (changeTracker) => {\n const isImportedEffectModule = TypeParser.importedEffectModule(\n ts,\n program.getTypeChecker()\n )\n const effectModuleIdentifierName = pipe(\n AST.findImportedModuleIdentifier(ts)((node) =>\n Option.isSome(isImportedEffectModule(node))\n )(sourceFile),\n Option.map((node) => node.text),\n Option.getOrElse(() => \"Effect\")\n )\n\n let errorCount = 0\n\n function createErrorADT() {\n errorCount++\n return ts.factory.createObjectLiteralExpression([\n ts.factory.createPropertyAssignment(\n \"_tag\",\n ts.factory.createAsExpression(\n ts.factory.createStringLiteral(\"Error\" + errorCount),\n ts.factory.createTypeReferenceNode(\"const\")\n )\n ),\n ts.factory.createShorthandPropertyAssignment(\"error\")\n ])\n }\n\n const newDeclaration = AST.transformAsyncAwaitToEffectGen(\n ts\n )(\n node,\n effectModuleIdentifierName,\n (expression) =>\n ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectModuleIdentifierName),\n \"tryPromise\"\n ),\n undefined,\n [\n ts.factory.createObjectLiteralExpression([\n ts.factory.createPropertyAssignment(\n ts.factory.createIdentifier(\"try\"),\n ts.factory.createArrowFunction(\n undefined,\n undefined,\n [],\n undefined,\n undefined,\n expression\n )\n ),\n ts.factory.createPropertyAssignment(\n ts.factory.createIdentifier(\"catch\"),\n ts.factory.createArrowFunction(\n undefined,\n undefined,\n [ts.factory.createParameterDeclaration(undefined, undefined, \"error\")],\n undefined,\n undefined,\n createErrorADT()\n )\n )\n ])\n ]\n )\n )\n\n changeTracker.replaceNode(sourceFile, node, newDeclaration)\n }\n }))\n )\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport { createRefactor } from \"../definition.js\"\nimport * as AST from \"../utils/AST.js\"\nimport * as TypeParser from \"../utils/TypeParser.js\"\n\nexport const effectGenToFn = createRefactor({\n name: \"effect/effectGenToFn\",\n description: \"Convert to Effect.fn\",\n apply: (ts, program) => (sourceFile, textRange) =>\n pipe(\n AST.getAncestorNodesInRange(ts)(sourceFile, textRange),\n ReadonlyArray.findFirst((node) =>\n Option.gen(function*() {\n // check if the node is a Effect.gen(...)\n const effectGen = yield* TypeParser.effectGen(ts, program.getTypeChecker())(node)\n // if parent is a Effect.gen(...).pipe(...) we then move the pipe tot the new Effect.fn\n let pipeArgs = ts.factory.createNodeArray<ts.Expression>([])\n let nodeToReplace = node.parent\n if (\n ts.isPropertyAccessExpression(node.parent) && node.parent.name.text === \"pipe\" &&\n ts.isCallExpression(node.parent.parent)\n ) {\n pipeArgs = node.parent.parent.arguments\n nodeToReplace = node.parent.parent.parent\n }\n // then we iterate upwards until we find the function declaration\n while (nodeToReplace) {\n // if arrow function, exit\n if (\n ts.isArrowFunction(nodeToReplace) || ts.isFunctionDeclaration(nodeToReplace) ||\n ts.isMethodDeclaration(nodeToReplace)\n ) {\n return ({ ...effectGen, pipeArgs, nodeToReplace })\n }\n // concise body go up\n if (ts.isConciseBody(nodeToReplace) || ts.isReturnStatement(nodeToReplace)) {\n nodeToReplace = nodeToReplace.parent\n continue\n }\n // function body with only one statement, go up\n if (ts.isBlock(nodeToReplace) && nodeToReplace.statements.length === 1) {\n nodeToReplace = nodeToReplace.parent\n continue\n }\n // exit\n break\n }\n\n // nothing, exit\n return yield* Option.none()\n })\n ),\n Option.map(\n ({ effectModule, generatorFunction, nodeToReplace, pipeArgs }) => ({\n kind: \"refactor.rewrite.effect.effectGenToFn\",\n description: \"Convert to Effect.fn\",\n apply: (changeTracker) => {\n // if we have a name in the function declaration,\n // we call Effect.fn with the name\n const effectFn = nodeToReplace.name && ts.isIdentifier(nodeToReplace.name) ?\n ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n effectModule,\n \"fn\"\n ),\n undefined,\n [ts.factory.createStringLiteral(nodeToReplace.name.text)]\n ) :\n ts.factory.createPropertyAccessExpression(\n effectModule,\n \"fn\"\n )\n // append the generator and pipe arguments to the Effect.fn call\n const effectFnCallWithGenerator = ts.factory.createCallExpression(\n effectFn,\n undefined,\n [ts.factory.createFunctionExpression(\n undefined,\n ts.factory.createToken(ts.SyntaxKind.AsteriskToken),\n undefined,\n nodeToReplace.typeParameters,\n nodeToReplace.parameters,\n nodeToReplace.type,\n generatorFunction.body\n ) as ts.Expression].concat(pipeArgs)\n )\n changeTracker.replaceNode(\n sourceFile,\n nodeToReplace,\n AST.tryPreserveDeclarationSemantics(ts)(nodeToReplace, effectFnCallWithGenerator)\n )\n }\n })\n )\n )\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport { createRefactor } from \"../definition.js\"\nimport * as AST from \"../utils/AST.js\"\n\nexport const functionToArrow = createRefactor({\n name: \"effect/functionToArrow\",\n description: \"Convert to arrow\",\n apply: (ts) => (sourceFile, textRange) =>\n pipe(\n pipe(\n AST.getAncestorNodesInRange(ts)(sourceFile, textRange),\n ReadonlyArray.filter(ts.isFunctionDeclaration)\n ),\n ReadonlyArray.appendAll(\n pipe(\n AST.getAncestorNodesInRange(ts)(sourceFile, textRange),\n ReadonlyArray.filter(ts.isMethodDeclaration)\n )\n ),\n ReadonlyArray.filter((node) => !!node.body),\n ReadonlyArray.filter((node) => !!node.name && AST.isNodeInRange(textRange)(node.name)),\n ReadonlyArray.head,\n Option.map(\n (node) => ({\n kind: \"refactor.rewrite.effect.functionToArrow\",\n description: \"Convert to arrow\",\n apply: (changeTracker) => {\n const body = node.body!\n let newBody: ts.ConciseBody = ts.factory.createBlock(body.statements)\n if (body.statements.length === 1) {\n const statement = body.statements[0]\n if (statement && ts.isReturnStatement(statement) && statement.expression) {\n newBody = statement.expression!\n }\n }\n\n let arrowFlags = ts.getCombinedModifierFlags(node)\n arrowFlags &= ~ts.ModifierFlags.Export\n arrowFlags &= ~ts.ModifierFlags.Default\n const arrowModifiers = ts.factory.createModifiersFromModifierFlags(arrowFlags)\n\n const arrowFunction = ts.factory.createArrowFunction(\n arrowModifiers,\n node.typeParameters,\n node.parameters,\n undefined,\n ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),\n newBody\n )\n\n let constFlags = ts.getCombinedModifierFlags(node)\n constFlags &= ~arrowFlags\n const constModifiers = ts.factory.createModifiersFromModifierFlags(constFlags)\n\n let newDeclaration: ts.Node = node\n if (ts.isMethodDeclaration(node)) {\n newDeclaration = ts.factory.createPropertyDeclaration(\n constModifiers,\n node.name!,\n undefined,\n undefined,\n arrowFunction\n )\n } else if (ts.isFunctionDeclaration(node)) {\n newDeclaration = ts.factory.createVariableStatement(\n constModifiers,\n ts.factory.createVariableDeclarationList(\n [\n ts.factory.createVariableDeclaration(\n node.name!,\n undefined,\n undefined,\n arrowFunction\n )\n ],\n ts.NodeFlags.Const\n )\n )\n }\n changeTracker.replaceNode(sourceFile, node, newDeclaration)\n }\n })\n )\n )\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport { createRefactor } from \"../definition.js\"\nimport * as AST from \"../utils/AST.js\"\n\nexport const pipeableToDatafirst = createRefactor({\n name: \"effect/pipeableToDatafirst\",\n description: \"Rewrite to datafirst\",\n apply: (ts, program) => (sourceFile, textRange) =>\n pipe(\n AST.getAncestorNodesInRange(ts)(sourceFile, textRange),\n ReadonlyArray.filter(AST.isPipeCall(ts)),\n ReadonlyArray.filter((node) => AST.isNodeInRange(textRange)(node.expression)),\n ReadonlyArray.filter(\n (node) => node.arguments.length > 0\n ),\n ReadonlyArray.map((node) => {\n let newNode = node.arguments[0]\n let didSomething = false\n for (let i = 1; i < node.arguments.length; i++) {\n const arg = node.arguments[i]\n const a = AST.asDataFirstExpression(ts, program.getTypeChecker())(arg, newNode)\n if (Option.isSome(a)) {\n // use found datafirst\n newNode = a.value\n didSomething = true\n } else {\n if (AST.isPipeCall(ts)(newNode)) {\n // avoid nested pipe(a, pipe(b, c))\n newNode = ts.factory.createCallExpression(\n ts.factory.createIdentifier(\"pipe\"),\n [],\n newNode.arguments.concat([arg])\n )\n } else {\n // no datafirst, keep pipeable\n newNode = ts.factory.createCallExpression(ts.factory.createIdentifier(\"pipe\"), [], [\n newNode,\n arg\n ])\n }\n }\n }\n return didSomething ? Option.some([node, newNode] as const) : Option.none()\n }),\n ReadonlyArray.filter(Option.isSome),\n ReadonlyArray.map((_) => _.value),\n ReadonlyArray.head,\n Option.map(([node, newNode]) => ({\n kind: \"refactor.rewrite.effect.pipeableToDatafirst\",\n description: \"Rewrite to datafirst\",\n apply: (changeTracker) => {\n changeTracker.replaceNode(sourceFile, node, newNode)\n }\n }))\n )\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport { createRefactor } from \"../definition.js\"\nimport * as AST from \"../utils/AST.js\"\n\n/**\n * Refactor to remove unnecessary `Effect.gen` calls.\n *\n * This refactor identifies `Effect.gen` calls that are redundant because they only wrap\n * a single `yield*` statement returning an `Effect`. In such cases, the `Effect.gen` wrapper\n * can be removed, and the inner `Effect` can be returned directly.\n *\n * The function works by analyzing the AST within the specified `textRange` to locate\n * `Effect.gen` calls. It checks if the body of the generator function contains only a single\n * `yield*` statement that directly returns an `Effect`. If such a pattern is found, the\n * `Effect.gen` wrapper is replaced with the inner `Effect`.\n *\n * @example\n * Input:\n * ```ts\n * const result = Effect.gen(function* () {\n * return yield* Effect.succeed(42)\n * })\n * ```\n * Output:\n * ```ts\n * const result = Effect.succeed(42)\n * ```\n *\n * @param ts - The TypeScript API.\n * @param program - The TypeScript program instance, used for type checking.\n * @returns A refactor function that takes a `SourceFile` and a `TextRange`, analyzes the AST,\n * and applies the refactor if applicable.\n */\nexport const removeUnnecessaryEffectGen = createRefactor({\n name: \"effect/removeUnnecessaryEffectGen\",\n description: \"Remove unnecessary Effect.gen\",\n apply: (ts, program) => (sourceFile, textRange) => {\n const typeChecker = program.getTypeChecker()\n return pipe(\n AST.collectDescendantsAndAncestorsInRange(ts, sourceFile, textRange),\n ReadonlyArray.findFirst((node) =>\n Option.gen(function*() {\n const returnedYieldedEffect = yield* AST.getSingleReturnEffectFromEffectGen(\n ts,\n typeChecker,\n node\n )\n return { nodeToReplace: node, returnedYieldedEffect }\n })\n ),\n Option.map((a) => ({\n kind: \"refactor.rewrite.effect.removeUnnecessaryEffectGen\",\n description: \"Remove unnecessary Effect.gen\",\n apply: (changeTracker) => {\n changeTracker.replaceNode(sourceFile, a.nodeToReplace, a.returnedYieldedEffect)\n }\n }))\n )\n }\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport { createRefactor } from \"../definition.js\"\nimport * as AST from \"../utils/AST.js\"\n\nexport const toggleLazyConst = createRefactor({\n name: \"effect/toggleLazyConst\",\n description: \"Toggle type annotation\",\n apply: (ts) => (sourceFile, textRange) =>\n pipe(\n AST.getAncestorNodesInRange(ts)(sourceFile, textRange),\n ReadonlyArray.filter(ts.isVariableDeclaration),\n ReadonlyArray.filter((node) => AST.isNodeInRange(textRange)(node.name)),\n ReadonlyArray.filter((node) =>\n !!node.initializer &&\n !(ts.isArrowFunction(node.initializer) && ts.isBlock(node.initializer.body))\n ),\n ReadonlyArray.head,\n Option.map(\n (node) => ({\n kind: \"refactor.rewrite.effect.toggleLazyConst\",\n description: \"Toggle lazy const\",\n apply: (changeTracker) => {\n const initializer = node.initializer!\n\n if (ts.isArrowFunction(initializer) && initializer.parameters.length === 0) {\n // delete eventual closing bracked\n changeTracker.deleteRange(sourceFile, {\n pos: initializer.body.end,\n end: initializer.end\n })\n // remove () => {\n changeTracker.deleteRange(sourceFile, {\n pos: initializer.pos,\n end: initializer.body.pos\n })\n return\n }\n\n // adds () => before\n changeTracker.insertText(sourceFile, initializer.pos, \" () =>\")\n }\n })\n )\n )\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport { createRefactor } from \"../definition.js\"\nimport * as AST from \"../utils/AST.js\"\nimport * as TypeCheckerApi from \"../utils/TypeCheckerApi.js\"\n\nexport const toggleReturnTypeAnnotation = createRefactor({\n name: \"effect/toggleReturnTypeAnnotation\",\n description: \"Toggle return type annotation\",\n apply: (ts, program) => (sourceFile, textRange) => {\n return Option.gen(function*() {\n const typeChecker = program.getTypeChecker()\n const node = yield* pipe(\n AST.getAncestorNodesInRange(ts)(sourceFile, textRange),\n ReadonlyArray.filter((node) =>\n ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) ||\n ts.isArrowFunction(node) || ts.isMethodDeclaration(node)\n ),\n ReadonlyArray.head\n )\n\n if (node.type) {\n return ({\n kind: \"refactor.rewrite.effect.toggleReturnTypeAnnotation\",\n description: \"Toggle return type annotation\",\n apply: (changeTracker) =>\n AST.removeReturnTypeAnnotation(ts, changeTracker)(sourceFile, node)\n })\n }\n\n const returnType = yield* TypeCheckerApi.getInferredReturnType(ts, typeChecker)(node)\n const returnTypeNode = yield* Option.fromNullable(\n typeChecker.typeToTypeNode(returnType, node, ts.NodeBuilderFlags.NoTruncation)\n )\n\n return ({\n kind: \"refactor.rewrite.effect.toggleReturnTypeAnnotation\",\n description: \"Toggle return type annotation\",\n apply: (changeTracker) => {\n AST.addReturnTypeAnnotation(ts, changeTracker)(\n sourceFile,\n node,\n AST.simplifyTypeNode(ts)(returnTypeNode)\n )\n }\n })\n })\n }\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport { createRefactor } from \"../definition.js\"\nimport * as AST from \"../utils/AST.js\"\n\nexport const toggleTypeAnnotation = createRefactor({\n name: \"effect/toggleTypeAnnotation\",\n description: \"Toggle type annotation\",\n apply: (ts, program) => (sourceFile, textRange) =>\n pipe(\n AST.getAncestorNodesInRange(ts)(sourceFile, textRange),\n ReadonlyArray.filter((node) =>\n ts.isVariableDeclaration(node) || ts.isPropertyDeclaration(node)\n ),\n ReadonlyArray.filter((node) => AST.isNodeInRange(textRange)(node.name)),\n ReadonlyArray.filter((node) => !!node.initializer),\n ReadonlyArray.head,\n Option.map(\n (node) => ({\n kind: \"refactor.rewrite.effect.toggleTypeAnnotation\",\n description: \"Toggle type annotation\",\n apply: (changeTracker) => {\n const typeChecker = program.getTypeChecker()\n\n if (node.type) {\n changeTracker.deleteRange(sourceFile, { pos: node.name.end, end: node.type.end })\n return\n }\n\n const initializer = node.initializer!\n const initializerType = typeChecker.getTypeAtLocation(initializer)\n const initializerTypeNode = Option.fromNullable(typeChecker.typeToTypeNode(\n initializerType,\n node,\n ts.NodeBuilderFlags.NoTruncation\n )).pipe(\n Option.orElse(() =>\n Option.fromNullable(typeChecker.typeToTypeNode(\n initializerType,\n undefined,\n ts.NodeBuilderFlags.NoTruncation\n ))\n ),\n Option.getOrUndefined\n )\n if (initializerTypeNode) {\n changeTracker.insertNodeAt(\n sourceFile,\n node.name.end,\n AST.simplifyTypeNode(ts)(initializerTypeNode),\n {\n prefix: \": \"\n }\n )\n }\n }\n })\n )\n )\n})\n","import * as Option from \"effect/Option\"\nimport { createRefactor } from \"../definition.js\"\n\nexport const wrapWithPipe = createRefactor({\n name: \"effect/wrapWithPipe\",\n description: \"Wrap with pipe\",\n apply: () => (sourceFile, textRange) => {\n if (textRange.end - textRange.pos === 0) return Option.none()\n\n return Option.some({\n kind: \"refactor.rewrite.effect.wrapWithPipe\",\n description: `Wrap with pipe(...)`,\n apply: (changeTracker) => {\n changeTracker.insertText(sourceFile, textRange.pos, \"pipe(\")\n changeTracker.insertText(sourceFile, textRange.end, \")\")\n }\n })\n }\n})\n","/**\n * @since 1.0.0\n */\nimport { asyncAwaitToGen } from \"./refactors/asyncAwaitToGen.js\"\nimport { asyncAwaitToGenTryPromise } from \"./refactors/asyncAwaitToGenTryPromise.js\"\nimport { effectGenToFn } from \"./refactors/effectGenToFn.js\"\nimport { functionToArrow } from \"./refactors/functionToArrow.js\"\nimport { pipeableToDatafirst } from \"./refactors/pipeableToDatafirst.js\"\nimport { removeUnnecessaryEffectGen } from \"./refactors/removeUnnecessaryEffectGen.js\"\nimport { toggleLazyConst } from \"./refactors/toggleLazyConst.js\"\nimport { toggleReturnTypeAnnotation } from \"./refactors/toggleReturnTypeAnnotation.js\"\nimport { toggleTypeAnnotation } from \"./refactors/toggleTypeAnnotation.js\"\nimport { wrapWithPipe } from \"./refactors/wrapWithPipe.js\"\n\n/**\n * @since 1.0.0\n */\nexport const refactors = {\n asyncAwaitToGen,\n asyncAwaitToGenTryPromise,\n functionToArrow,\n pipeableToDatafirst,\n removeUnnecessaryEffectGen,\n toggleLazyConst,\n toggleReturnTypeAnnotation,\n toggleTypeAnnotation,\n wrapWithPipe,\n effectGenToFn\n}\n","/**\n * @since 1.0.0\n */\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport type { PluginOptions } from \"./definition.js\"\nimport { diagnostics } from \"./diagnostics.js\"\nimport { dedupeJsDocTags, prependEffectTypeArguments } from \"./quickinfo.js\"\nimport { refactors } from \"./refactors.js\"\nimport * as AST from \"./utils/AST.js\"\n\nconst init = (\n modules: {\n typescript: typeof ts\n }\n) => {\n const ts = modules.typescript\n\n function create(info: ts.server.PluginCreateInfo) {\n const languageService = info.languageService\n const pluginOptions: PluginOptions = {\n diagnostics:\n info.config && \"diagnostics\" in info.config && typeof info.config.diagnostics === \"boolean\"\n ? info.config.diagnostics\n : true,\n quickinfo:\n info.config && \"quickinfo\" in info.config && typeof info.config.quickinfo === \"boolean\"\n ? info.config.quickinfo\n : true\n }\n\n // create the proxy\n const proxy: ts.LanguageService = Object.create(null)\n for (const k of Object.keys(info.languageService) as Array<keyof ts.LanguageService>) {\n // @ts-expect-error\n proxy[k] = (...args: Array<{}>) => languageService[k]!.apply(languageService, args)\n }\n\n proxy.getSemanticDiagnostics = (fileName, ...args) => {\n const applicableDiagnostics = languageService.getSemanticDiagnostics(fileName, ...args)\n const program = languageService.getProgram()\n\n if (pluginOptions.diagnostics && program) {\n const effectDiagnostics: Array<ts.Diagnostic> = pipe(\n Option.fromNullable(program.getSourceFile(fileName)),\n Option.map((sourceFile) =>\n pipe(\n Object.values(diagnostics).map((diagnostic) =>\n pipe(\n diagnostic.apply(modules.typescript, program, pluginOptions)(\n sourceFile,\n applicableDiagnostics\n ).map((_) => ({\n file: sourceFile,\n start: _.node.getStart(sourceFile),\n length: _.node.getEnd() - _.node.getStart(sourceFile),\n messageText: _.messageText,\n category: _.category,\n code: diagnostic.code,\n source: \"effect\"\n }))\n )\n ),\n (_) =>\n _.reduce(\n (arr, maybeRefactor) => arr.concat(maybeRefactor),\n [] as Array<ts.Diagnostic>\n )\n )\n ),\n Option.getOrElse(() => [])\n )\n\n return effectDiagnostics.concat(applicableDiagnostics)\n }\n\n return applicableDiagnostics\n }\n\n proxy.getApplicableRefactors = (...args) => {\n const applicableRefactors = languageService.getApplicableRefactors(...args)\n const [fileName, positionOrRange] = args\n const program = languageService.getProgram()\n\n if (program) {\n const textRange = AST.toTextRange(positionOrRange)\n const effectRefactors: Array<ts.ApplicableRefactorInfo> = pipe(\n Option.fromNullable(program.getSourceFile(fileName)),\n Option.map((sourceFile) =>\n pipe(\n Object.values(refactors).map((refactor) =>\n pipe(\n refactor.apply(modules.typescript, program, pluginOptions)(\n sourceFile,\n textRange\n ),\n Option.map((_) => ({\n name: refactor.name,\n description: refactor.description,\n actions: [{\n name: refactor.name,\n description: _.description,\n kind: _.kind\n }]\n }))\n )\n ),\n (_) =>\n _.reduce(\n (arr, maybeRefactor) =>\n arr.concat(Option.isSome(maybeRefactor) ? [maybeRefactor.value] : []),\n [] as Array<ts.ApplicableRefactorInfo>\n )\n )\n ),\n Option.getOrElse(() => [])\n )\n\n info.project.projectService.logger.info(\n \"[@effect/language-service] possible refactors are \" + JSON.stringify(effectRefactors)\n )\n\n return applicableRefactors.concat(effectRefactors)\n }\n return applicableRefactors\n }\n\n proxy.getEditsForRefactor = (\n fileName,\n formatOptions,\n positionOrRange,\n refactorName,\n actionName,\n preferences,\n ...args\n ) => {\n const program = languageService.getProgram()\n if (program) {\n for (const refactor of Object.values(refactors)) {\n if (refactor.name === refactorName) {\n const textRange = AST.toTextRange(positionOrRange)\n const possibleRefactor = pipe(\n Option.fromNullable(program.getSourceFile(fileName)),\n Option.flatMap((sourceFile) =>\n refactor.apply(modules.typescript, program, pluginOptions)(\n sourceFile,\n textRange\n )\n )\n )\n\n if (Option.isNone(possibleRefactor)) {\n info.project.projectService.logger.info(\n \"[@effect/language-service] requested refactor \" + refactorName +\n \" is not applicable\"\n )\n return { edits: [] }\n }\n\n const formatContext = ts.formatting.getFormatContext(\n formatOptions,\n info.languageServiceHost\n )\n const edits = ts.textChanges.ChangeTracker.with(\n {\n formatContext,\n host: info.languageServiceHost,\n preferences: preferences || {}\n },\n (changeTracker) => possibleRefactor.value.apply(changeTracker)\n )\n\n return { edits }\n }\n }\n }\n\n return languageService.getEditsForRefactor(\n fileName,\n formatOptions,\n positionOrRange,\n refactorName,\n actionName,\n preferences,\n ...args\n )\n }\n\n proxy.getQuickInfoAtPosition = (fileName, position, ...args) => {\n const quickInfo = languageService.getQuickInfoAtPosition(fileName, position, ...args)\n\n if (pluginOptions.quickinfo && quickInfo) {\n const dedupedTagsQuickInfo = dedupeJsDocTags(quickInfo)\n\n const program = languageService.getProgram()\n if (program) {\n return prependEffectTypeArguments(ts, program)(fileName, position, dedupedTagsQuickInfo)\n }\n\n return dedupedTagsQuickInfo\n }\n\n return quickInfo\n }\n\n return proxy\n }\n\n return { create }\n}\n\nmodule.exports = init\n"],"mappings":";;;AA6BO,IAAMA,aAAcC,WAAsC,OAAOA,UAAU;AA6C3E,IAAMC,OA+FT,SAASC,OAAOC,MAAI;AACtB,MAAI,OAAOD,UAAU,YAAY;AAC/B,WAAO,WAAA;AACL,UAAIA,MAAME,SAAS,GAAG;AAEpB,eAAOD,KAAKE,MAAM,MAAMD,SAAS;MACnC;AACA,aAASE,UAAcH,KAAKG,MAAM,GAAGF,SAAS;IAChD;EACF;AAEA,UAAQF,OAAK;IACX,KAAK;IACL,KAAK;AACH,YAAM,IAAIK,WAAW,iBAAiBL,KAAK,EAAE;IAE/C,KAAK;AACH,aAAO,SAASM,GAAGC,GAAC;AAClB,YAAIL,UAAUM,UAAU,GAAG;AACzB,iBAAOP,KAAKK,GAAGC,CAAC;QAClB;AACA,eAAO,SAASH,MAAS;AACvB,iBAAOH,KAAKG,MAAME,CAAC;QACrB;MACF;IAEF,KAAK;AACH,aAAO,SAASA,GAAGC,GAAGE,GAAC;AACrB,YAAIP,UAAUM,UAAU,GAAG;AACzB,iBAAOP,KAAKK,GAAGC,GAAGE,CAAC;QACrB;AACA,eAAO,SAASL,MAAS;AACvB,iBAAOH,KAAKG,MAAME,GAAGC,CAAC;QACxB;MACF;IAEF,KAAK;AACH,aAAO,SAASD,GAAGC,GAAGE,GAAGC,GAAC;AACxB,YAAIR,UAAUM,UAAU,GAAG;AACzB,iBAAOP,KAAKK,GAAGC,GAAGE,GAAGC,CAAC;QACxB;AACA,eAAO,SAASN,MAAS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,gBACjC,mDAAmD,eACjD;AAAA,cACJ;AACA,qBAAO,EAAE,OAAO,CAAC,EAAE;AAAA,YACrB;AAEA,kBAAM,gBAAgB,GAAG,WAAW;AAAA,cAClC;AAAA,cACA,KAAK;AAAA,YACP;AACA,kBAAM,QAAQ,GAAG,YAAY,cAAc;AAAA,cACzC;AAAA,gBACE;AAAA,gBACA,MAAM,KAAK;AAAA,gBACX,aAAa,eAAe,CAAC;AAAA,cAC/B;AAAA,cACA,CAAC,kBAAkB,iBAAiB,MAAM,MAAM,aAAa;AAAA,YAC/D;AAEA,mBAAO,EAAE,MAAM;AAAA,UACjB;AAAA,QACF;AAAA,MACF;AAEA,aAAO,gBAAgB;AAAA,QACrB;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,GAAG;AAAA,MACL;AAAA,IACF;AAEA,UAAM,yBAAyB,CAAC,UAAU,aAAa,SAAS;AAC9D,YAAM,YAAY,gBAAgB,uBAAuB,UAAU,UAAU,GAAG,IAAI;AAEpF,UAAI,cAAc,aAAa,WAAW;AACxC,cAAM,uBAAuB,gBAAgB,SAAS;AAEtD,cAAM,UAAU,gBAAgB,WAAW;AAC3C,YAAI,SAAS;AACX,iBAAO,2BAA2B,IAAI,OAAO,EAAE,UAAU,UAAU,oBAAoB;AAAA,QACzF;AAEA,eAAO;AAAA,MACT;AAEA,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AAEA,SAAO,EAAE,OAAO;AAClB;AAEA,OAAO,UAAU;","names":["isFunction","input","dual","arity","body","arguments","apply","self","RangeError","a","b","length","c","d","e","args","identity","a","constant","value","constUndefined","constant","undefined","pipe","a","ab","bc","cd","de","ef","fg","gh","hi","arguments","length","ret","i","moduleVersion","getCurrentVersion","globalStoreId","version","getCurrentVersion","globalStore","globalValue","id","compute","globalThis","Map","has","set","get","isBoolean","input","isFunction","isFunction_","isRecordOrArray","input","isObject","isFunction","hasProperty","dual","self","property","getBugErrorMessage","message","GenKindTypeId","Symbol","for","isGenKind","u","isObject","GenKindImpl","value","constructor","_F","identity","_R","_","_O","_E","iterator","SingleShotGen","self","called","next","a","done","return","throw","e","adapter","x","arguments","i","length","GenKindImpl","MUL_HI","MUL_LO","YieldWrapTypeId","Symbol","for","YieldWrap","constructor","value","yieldWrapGet","self","Error","getBugErrorMessage","structuralRegionState","globalValue","enabled","tester","undefined","genConstructor","constructor","randomHashCache","globalValue","Symbol","for","WeakMap","symbol","hash","self","structuralRegionState","enabled","number","string","toString","String","Date","toISOString","isHash","random","Error","has","set","Math","floor","Number","MAX_SAFE_INTEGER","get","combine","b","optimize","n","u","hasProperty","Infinity","h","str","i","length","charCodeAt","structureKeys","o","keys","pipe","structure","Object","cached","arguments","length","self","hash","Object","defineProperty","symbol","value","enumerable","symbol","Symbol","for","equals","arguments","length","self","compareBoth","that","selfType","isEqual","hash","structuralRegionState","enabled","tester","Date","toISOString","Array","isArray","every","v","i","Object","getPrototypeOf","prototype","keysSelf","keys","keysThat","key","u","hasProperty","make","isEquivalent","self","that","array","item","make","self","that","length","i","isEq","NodeInspectSymbol","Symbol","for","toJSON","x","hasProperty","isFunction","length","Array","isArray","map","_","redact","format","JSON","stringify","BaseProto","toString","Class","symbolRedactable","Symbol","for","isRedactable","u","redactableState","globalValue","fiberRefs","undefined","redact","u","isRedactable","redactableState","fiberRefs","undefined","symbolRedactable","pipeArguments","self","args","length","ret","i","len","OP_COMMIT","EffectTypeId","Symbol","for","StreamTypeId","SinkTypeId","ChannelTypeId","effectVariance","_R","_","_E","_A","_V","version","getCurrentVersion","sinkVariance","_In","_L","channelVariance","_Env","_InErr","_InElem","_InDone","_OutErr","_OutElem","_OutDone","EffectPrototype","symbol","that","cached","random","iterator","SingleShotGen","YieldWrap","pipe","pipeArguments","arguments","StructuralPrototype","structure","selfKeys","Object","keys","thatKeys","length","key","equals","CommitPrototype","_op","OP_COMMIT","StructuralCommitPrototype","TypeId","Symbol","for","CommonProto","EffectPrototype","_A","_","NodeInspectSymbol","toJSON","toString","format","SomeProto","Object","assign","create","_tag","_op","symbol","that","isOption","isSome","equals","value","cached","combine","hash","_id","NoneHash","Hash","NoneProto","isNone","input","hasProperty","fa","none","some","a","make","compare","self","that","none","some","isNone","isSome","getOrElse","dual","self","onNone","isNone","value","orElse","that","fromNullable","nullableValue","none","some","getOrUndefined","getOrElse","constUndefined","map","dual","self","f","isNone","none","some","value","flatMap","dual","self","f","isNone","none","value","all","input","Symbol","iterator","out","o","isNone","none","push","value","some","key","Object","keys","adapter","Gen","gen","args","f","length","bind","iterator","state","next","done","some","value","current","isGenKind","yieldWrapGet","isNone","none","some","isSome","isSome","isNone","isNonEmptyArray","self","length","findFirst","dual","self","f","i","a","o","isBoolean","some","isSome","none","fromIterable","collection","Array","isArray","from","append","dual","self","last","appendAll","that","fromIterable","concat","isArray","Array","isNonEmptyReadonlyArray","isNonEmptyArray","isOutOfBound","i","as","length","get","dual","self","index","i","Math","floor","isOutOfBound","none","some","unsafeGet","Error","head","get","headNonEmpty","unsafeGet","tailNonEmpty","self","slice","findFirst","sort","dual","self","O","out","Array","from","empty","map","dual","self","f","filter","dual","self","predicate","as","fromIterable","out","i","length","push","dedupeWith","dual","self","isEquivalent","input","fromIterable","isNonEmptyReadonlyArray","out","headNonEmpty","rest","tailNonEmpty","r","every","a","push","isNone","isSome","some","none","make","none","some","symbol","node","isNone","node","isNone","isSome","isSome","node","isSome","node","isSome","findFirst","effectGen","none","map","isSome","some","none","findFirst","node","none","some","isSome","isNone"]}
|
|
1
|
+
{"version":3,"sources":["../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Function.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Either.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Equivalence.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/doNotation.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/version.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/GlobalValue.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Predicate.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/errors.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Utils.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Hash.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Equal.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Inspectable.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Pipeable.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/opCodes/effect.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/effectable.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/option.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/either.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/array.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Order.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Option.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Array.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Chunk.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/hashMap/config.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/hashMap/bitwise.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/stack.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/hashMap/array.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/hashMap/node.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/hashMap.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/hashSet.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/HashSet.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/opCodes/cause.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/cause.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/singleShotGen.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/core.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Data.ts","../src/core/Nano.ts","../src/core/LSP.ts","../src/utils/TypeScriptApi.ts","../src/utils/TypeCheckerApi.ts","../src/utils/TypeParser.ts","../src/diagnostics/floatingEffect.ts","../src/diagnostics/missingEffectContext.ts","../src/diagnostics/missingEffectError.ts","../src/diagnostics/missingStarInYieldEffectGen.ts","../src/diagnostics/unnecessaryEffectGen.ts","../src/diagnostics.ts","../src/utils/AST.ts","../src/quickinfo.ts","../src/refactors/asyncAwaitToGen.ts","../src/refactors/asyncAwaitToGenTryPromise.ts","../src/refactors/effectGenToFn.ts","../src/refactors/functionToArrow.ts","../src/refactors/pipeableToDatafirst.ts","../src/refactors/removeUnnecessaryEffectGen.ts","../src/refactors/toggleLazyConst.ts","../src/refactors/toggleReturnTypeAnnotation.ts","../src/refactors/toggleTypeAnnotation.ts","../src/refactors/wrapWithPipe.ts","../src/refactors.ts","../src/index.ts"],"sourcesContent":["/**\n * @since 2.0.0\n */\nimport type { TypeLambda } from \"./HKT.js\"\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface FunctionTypeLambda extends TypeLambda {\n readonly type: (a: this[\"In\"]) => this[\"Target\"]\n}\n\n/**\n * Tests if a value is a `function`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isFunction } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isFunction(isFunction), true)\n * assert.deepStrictEqual(isFunction(\"function\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isFunction = (input: unknown): input is Function => typeof input === \"function\"\n\n/**\n * Creates a function that can be used in a data-last (aka `pipe`able) or\n * data-first style.\n *\n * The first parameter to `dual` is either the arity of the uncurried function\n * or a predicate that determines if the function is being used in a data-first\n * or data-last style.\n *\n * Using the arity is the most common use case, but there are some cases where\n * you may want to use a predicate. For example, if you have a function that\n * takes an optional argument, you can use a predicate to determine if the\n * function is being used in a data-first or data-last style.\n *\n * @param arity - Either the arity of the uncurried function or a predicate\n * which determines if the function is being used in a data-first\n * or data-last style.\n * @param body - The definition of the uncurried function.\n *\n * @example\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * // Exampe using arity to determine data-first or data-last style\n * const sum: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual(2, (self: number, that: number): number => self + that)\n *\n * assert.deepStrictEqual(sum(2, 3), 5)\n * assert.deepStrictEqual(pipe(2, sum(3)), 5)\n *\n * // Example using a predicate to determine data-first or data-last style\n * const sum2: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual((args) => args.length === 1, (self: number, that: number): number => self + that)\n *\n * assert.deepStrictEqual(sum(2, 3), 5)\n * assert.deepStrictEqual(pipe(2, sum(3)), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const dual: {\n /**\n * Creates a function that can be used in a data-last (aka `pipe`able) or\n * data-first style.\n *\n * The first parameter to `dual` is either the arity of the uncurried function\n * or a predicate that determines if the function is being used in a data-first\n * or data-last style.\n *\n * Using the arity is the most common use case, but there are some cases where\n * you may want to use a predicate. For example, if you have a function that\n * takes an optional argument, you can use a predicate to determine if the\n * function is being used in a data-first or data-last style.\n *\n * @param arity - Either the arity of the uncurried function or a predicate\n * which determines if the function is being used in a data-first\n * or data-last style.\n * @param body - The definition of the uncurried function.\n *\n * @example\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * // Exampe using arity to determine data-first or data-last style\n * const sum: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual(2, (self: number, that: number): number => self + that)\n *\n * assert.deepStrictEqual(sum(2, 3), 5)\n * assert.deepStrictEqual(pipe(2, sum(3)), 5)\n *\n * // Example using a predicate to determine data-first or data-last style\n * const sum2: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual((args) => args.length === 1, (self: number, that: number): number => self + that)\n *\n * assert.deepStrictEqual(sum(2, 3), 5)\n * assert.deepStrictEqual(pipe(2, sum(3)), 5)\n * ```\n *\n * @since 2.0.0\n */\n <DataLast extends (...args: Array<any>) => any, DataFirst extends (...args: Array<any>) => any>(\n arity: Parameters<DataFirst>[\"length\"],\n body: DataFirst\n ): DataLast & DataFirst\n /**\n * Creates a function that can be used in a data-last (aka `pipe`able) or\n * data-first style.\n *\n * The first parameter to `dual` is either the arity of the uncurried function\n * or a predicate that determines if the function is being used in a data-first\n * or data-last style.\n *\n * Using the arity is the most common use case, but there are some cases where\n * you may want to use a predicate. For example, if you have a function that\n * takes an optional argument, you can use a predicate to determine if the\n * function is being used in a data-first or data-last style.\n *\n * @param arity - Either the arity of the uncurried function or a predicate\n * which determines if the function is being used in a data-first\n * or data-last style.\n * @param body - The definition of the uncurried function.\n *\n * @example\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * // Exampe using arity to determine data-first or data-last style\n * const sum: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual(2, (self: number, that: number): number => self + that)\n *\n * assert.deepStrictEqual(sum(2, 3), 5)\n * assert.deepStrictEqual(pipe(2, sum(3)), 5)\n *\n * // Example using a predicate to determine data-first or data-last style\n * const sum2: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual((args) => args.length === 1, (self: number, that: number): number => self + that)\n *\n * assert.deepStrictEqual(sum(2, 3), 5)\n * assert.deepStrictEqual(pipe(2, sum(3)), 5)\n * ```\n *\n * @since 2.0.0\n */\n <DataLast extends (...args: Array<any>) => any, DataFirst extends (...args: Array<any>) => any>(\n isDataFirst: (args: IArguments) => boolean,\n body: DataFirst\n ): DataLast & DataFirst\n} = function(arity, body) {\n if (typeof arity === \"function\") {\n return function() {\n if (arity(arguments)) {\n // @ts-expect-error\n return body.apply(this, arguments)\n }\n return ((self: any) => body(self, ...arguments)) as any\n }\n }\n\n switch (arity) {\n case 0:\n case 1:\n throw new RangeError(`Invalid arity ${arity}`)\n\n case 2:\n return function(a, b) {\n if (arguments.length >= 2) {\n return body(a, b)\n }\n return function(self: any) {\n return body(self, a)\n }\n }\n\n case 3:\n return function(a, b, c) {\n if (arguments.length >= 3) {\n return body(a, b, c)\n }\n return function(self: any) {\n return body(self, a, b)\n }\n }\n\n case 4:\n return function(a, b, c, d) {\n if (arguments.length >= 4) {\n return body(a, b, c, d)\n }\n return function(self: any) {\n return body(self, a, b, c)\n }\n }\n\n case 5:\n return function(a, b, c, d, e) {\n if (arguments.length >= 5) {\n return body(a, b, c, d, e)\n }\n return function(self: any) {\n return body(self, a, b, c, d)\n }\n }\n\n default:\n return function() {\n if (arguments.length >= arity) {\n // @ts-expect-error\n return body.apply(this, arguments)\n }\n const args = arguments\n return function(self: any) {\n return body(self, ...args)\n }\n }\n }\n}\n/**\n * Apply a function to a given value.\n *\n * @param a - The value that the function will be applied to.\n * @param self - The function to be applied to a value.\n *\n * @example\n * ```ts\n * import { pipe, apply } from \"effect/Function\"\n * import { length } from \"effect/String\"\n *\n * assert.deepStrictEqual(pipe(length, apply(\"hello\")), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const apply = <A>(a: A) => <B>(self: (a: A) => B): B => self(a)\n\n/**\n * A lazy argument.\n *\n * @example\n * ```ts\n * import { LazyArg, constant } from \"effect/Function\"\n *\n * const constNull: LazyArg<null> = constant(null)\n * ```\n *\n * @since 2.0.0\n */\nexport interface LazyArg<A> {\n (): A\n}\n\n/**\n * @example\n * ```ts\n * import { FunctionN } from \"effect/Function\"\n *\n * const sum: FunctionN<[number, number], number> = (a, b) => a + b\n * ```\n *\n * @since 2.0.0\n */\nexport interface FunctionN<A extends ReadonlyArray<unknown>, B> {\n (...args: A): B\n}\n\n/**\n * The identity function, i.e. A function that returns its input argument.\n *\n * @param a - The input argument.\n *\n * @example\n * ```ts\n * import { identity } from \"effect/Function\"\n *\n * assert.deepStrictEqual(identity(5), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const identity = <A>(a: A): A => a\n\n/**\n * A function that ensures that the type of an expression matches some type,\n * without changing the resulting type of that expression.\n *\n * @example\n * ```ts\n * import { satisfies } from \"effect/Function\"\n *\n * const test1 = satisfies<number>()(5 as const)\n * //^? const test: 5\n * // @ts-expect-error\n * const test2 = satisfies<string>()(5)\n * //^? Argument of type 'number' is not assignable to parameter of type 'string'\n *\n * assert.deepStrictEqual(satisfies<number>()(5), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const satisfies = <A>() => <B extends A>(b: B) => b\n\n/**\n * Casts the result to the specified type.\n *\n * @param a - The value to be casted to the target type.\n *\n * @example\n * ```ts\n * import { unsafeCoerce, identity } from \"effect/Function\"\n *\n * assert.deepStrictEqual(unsafeCoerce, identity)\n * ```\n *\n * @since 2.0.0\n */\nexport const unsafeCoerce: <A, B>(a: A) => B = identity as any\n\n/**\n * Creates a constant value that never changes.\n *\n * This is useful when you want to pass a value to a higher-order function (a function that takes another function as its argument)\n * and want that inner function to always use the same value, no matter how many times it is called.\n *\n * @param value - The constant value to be returned.\n *\n * @example\n * ```ts\n * import { constant } from \"effect/Function\"\n *\n * const constNull = constant(null)\n *\n * assert.deepStrictEqual(constNull(), null)\n * assert.deepStrictEqual(constNull(), null)\n * ```\n *\n * @since 2.0.0\n */\nexport const constant = <A>(value: A): LazyArg<A> => () => value\n\n/**\n * A thunk that returns always `true`.\n *\n * @example\n * ```ts\n * import { constTrue } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constTrue(), true)\n * ```\n *\n * @since 2.0.0\n */\nexport const constTrue: LazyArg<boolean> = constant(true)\n\n/**\n * A thunk that returns always `false`.\n *\n * @example\n * ```ts\n * import { constFalse } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constFalse(), false)\n * ```\n *\n * @since 2.0.0\n */\nexport const constFalse: LazyArg<boolean> = constant(false)\n\n/**\n * A thunk that returns always `null`.\n *\n * @example\n * ```ts\n * import { constNull } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constNull(), null)\n * ```\n *\n * @since 2.0.0\n */\nexport const constNull: LazyArg<null> = constant(null)\n\n/**\n * A thunk that returns always `undefined`.\n *\n * @example\n * ```ts\n * import { constUndefined } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constUndefined(), undefined)\n * ```\n *\n * @since 2.0.0\n */\nexport const constUndefined: LazyArg<undefined> = constant(undefined)\n\n/**\n * A thunk that returns always `void`.\n *\n * @example\n * ```ts\n * import { constVoid } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constVoid(), undefined)\n * ```\n *\n * @since 2.0.0\n */\nexport const constVoid: LazyArg<void> = constUndefined\n\n/**\n * Reverses the order of arguments for a curried function.\n *\n * @param f - A curried function that takes multiple arguments.\n *\n * @example\n * ```ts\n * import { flip } from \"effect/Function\"\n *\n * const f = (a: number) => (b: string) => a - b.length\n *\n * assert.deepStrictEqual(flip(f)('aaa')(2), -1)\n * ```\n *\n * @since 2.0.0\n */\nexport const flip = <A extends Array<unknown>, B extends Array<unknown>, C>(\n f: (...a: A) => (...b: B) => C\n): (...b: B) => (...a: A) => C =>\n(...b) =>\n(...a) => f(...a)(...b)\n\n/**\n * Composes two functions, `ab` and `bc` into a single function that takes in an argument `a` of type `A` and returns a result of type `C`.\n * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.\n *\n * @param ab - A function that maps from `A` to `B`.\n * @param bc - A function that maps from `B` to `C`.\n *\n * @example\n * ```ts\n * import { compose } from \"effect/Function\"\n *\n * const increment = (n: number) => n + 1;\n * const square = (n: number) => n * n;\n *\n * assert.strictEqual(compose(increment, square)(2), 9);\n * ```\n *\n * @since 2.0.0\n */\nexport const compose: {\n /**\n * Composes two functions, `ab` and `bc` into a single function that takes in an argument `a` of type `A` and returns a result of type `C`.\n * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.\n *\n * @param ab - A function that maps from `A` to `B`.\n * @param bc - A function that maps from `B` to `C`.\n *\n * @example\n * ```ts\n * import { compose } from \"effect/Function\"\n *\n * const increment = (n: number) => n + 1;\n * const square = (n: number) => n * n;\n *\n * assert.strictEqual(compose(increment, square)(2), 9);\n * ```\n *\n * @since 2.0.0\n */\n <B, C>(bc: (b: B) => C): <A>(self: (a: A) => B) => (a: A) => C\n /**\n * Composes two functions, `ab` and `bc` into a single function that takes in an argument `a` of type `A` and returns a result of type `C`.\n * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.\n *\n * @param ab - A function that maps from `A` to `B`.\n * @param bc - A function that maps from `B` to `C`.\n *\n * @example\n * ```ts\n * import { compose } from \"effect/Function\"\n *\n * const increment = (n: number) => n + 1;\n * const square = (n: number) => n * n;\n *\n * assert.strictEqual(compose(increment, square)(2), 9);\n * ```\n *\n * @since 2.0.0\n */\n <A, B, C>(self: (a: A) => B, bc: (b: B) => C): (a: A) => C\n} = dual(2, <A, B, C>(ab: (a: A) => B, bc: (b: B) => C): (a: A) => C => (a) => bc(ab(a)))\n\n/**\n * The `absurd` function is a stub for cases where a value of type `never` is encountered in your code,\n * meaning that it should be impossible for this code to be executed.\n *\n * This function is particularly useful when it's necessary to specify that certain cases are impossible.\n *\n * @since 2.0.0\n */\nexport const absurd = <A>(_: never): A => {\n throw new Error(\"Called `absurd` function which should be uncallable\")\n}\n\n/**\n * Creates a tupled version of this function: instead of `n` arguments, it accepts a single tuple argument.\n *\n * @example\n * ```ts\n * import { tupled } from \"effect/Function\"\n *\n * const sumTupled = tupled((x: number, y: number): number => x + y)\n *\n * assert.deepStrictEqual(sumTupled([1, 2]), 3)\n * ```\n *\n * @since 2.0.0\n */\nexport const tupled = <A extends ReadonlyArray<unknown>, B>(f: (...a: A) => B): (a: A) => B => (a) => f(...a)\n\n/**\n * Inverse function of `tupled`\n *\n * @example\n * ```ts\n * import { untupled } from \"effect/Function\"\n *\n * const getFirst = untupled(<A, B>(tuple: [A, B]): A => tuple[0])\n *\n * assert.deepStrictEqual(getFirst(1, 2), 1)\n * ```\n *\n * @since 2.0.0\n */\nexport const untupled = <A extends ReadonlyArray<unknown>, B>(f: (a: A) => B): (...a: A) => B => (...a) => f(a)\n\n/**\n * Pipes the value of an expression into a pipeline of functions.\n *\n * **When to Use**\n *\n * This is useful in combination with data-last functions as a simulation of\n * methods:\n *\n * ```ts\n * as.map(f).filter(g)\n * ```\n *\n * becomes:\n *\n * ```ts\n * import { pipe, Array } from \"effect\"\n *\n * pipe(as, Array.map(f), Array.filter(g))\n * ```\n *\n * **Details**\n *\n * The `pipe` function is a utility that allows us to compose functions in a\n * readable and sequential manner. It takes the output of one function and\n * passes it as the input to the next function in the pipeline. This enables us\n * to build complex transformations by chaining multiple functions together.\n *\n * ```ts\n * import { pipe } from \"effect\"\n *\n * const result = pipe(input, func1, func2, ..., funcN)\n * ```\n *\n * In this syntax, `input` is the initial value, and `func1`, `func2`, ...,\n * `funcN` are the functions to be applied in sequence. The result of each\n * function becomes the input for the next function, and the final result is\n * returned.\n *\n * Here's an illustration of how `pipe` works:\n *\n * ```text\n * ┌───────┐ ┌───────┐ ┌───────┐ ┌───────┐ ┌───────┐ ┌────────┐\n * │ input │───►│ func1 │───►│ func2 │───►│ ... │───►│ funcN │───►│ result │\n * └───────┘ └───────┘ └───────┘ └───────┘ └───────┘ └────────┘\n * ```\n *\n * It's important to note that functions passed to `pipe` must have a **single\n * argument** because they are only called with a single argument.\n *\n * @example\n * ```ts\n * // Example: Chaining Arithmetic Operations\n * import { pipe } from \"effect\"\n *\n * // Define simple arithmetic operations\n * const increment = (x: number) => x + 1\n * const double = (x: number) => x * 2\n * const subtractTen = (x: number) => x - 10\n *\n * // Sequentially apply these operations using `pipe`\n * const result = pipe(5, increment, double, subtractTen)\n *\n * console.log(result)\n * // Output: 2\n * ```\n *\n * @since 2.0.0\n */\nexport function pipe<A>(a: A): A\nexport function pipe<A, B = never>(a: A, ab: (a: A) => B): B\nexport function pipe<A, B = never, C = never>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C\n): C\nexport function pipe<A, B = never, C = never, D = never>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D\n): D\nexport function pipe<A, B = never, C = never, D = never, E = never>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E\n): E\nexport function pipe<A, B = never, C = never, D = never, E = never, F = never>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F\n): F\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G\n): G\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H\n): H\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I\n): I\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J\n): J\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K\n): K\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L\n): L\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M\n): M\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N\n): N\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O\n): O\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P\n): P\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q\n): Q\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R\n): R\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => S\n): S\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never,\n T = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => S,\n st: (s: S) => T\n): T\nexport function pipe(\n a: unknown,\n ab?: Function,\n bc?: Function,\n cd?: Function,\n de?: Function,\n ef?: Function,\n fg?: Function,\n gh?: Function,\n hi?: Function\n): unknown {\n switch (arguments.length) {\n case 1:\n return a\n case 2:\n return ab!(a)\n case 3:\n return bc!(ab!(a))\n case 4:\n return cd!(bc!(ab!(a)))\n case 5:\n return de!(cd!(bc!(ab!(a))))\n case 6:\n return ef!(de!(cd!(bc!(ab!(a)))))\n case 7:\n return fg!(ef!(de!(cd!(bc!(ab!(a))))))\n case 8:\n return gh!(fg!(ef!(de!(cd!(bc!(ab!(a)))))))\n case 9:\n return hi!(gh!(fg!(ef!(de!(cd!(bc!(ab!(a))))))))\n default: {\n let ret = arguments[0]\n for (let i = 1; i < arguments.length; i++) {\n ret = arguments[i](ret)\n }\n return ret\n }\n }\n}\n\n/**\n * Performs left-to-right function composition. The first argument may have any arity, the remaining arguments must be unary.\n *\n * See also [`pipe`](#pipe).\n *\n * @example\n * ```ts\n * import { flow } from \"effect/Function\"\n *\n * const len = (s: string): number => s.length\n * const double = (n: number): number => n * 2\n *\n * const f = flow(len, double)\n *\n * assert.strictEqual(f('aaa'), 6)\n * ```\n *\n * @since 2.0.0\n */\nexport function flow<A extends ReadonlyArray<unknown>, B = never>(\n ab: (...a: A) => B\n): (...a: A) => B\nexport function flow<A extends ReadonlyArray<unknown>, B = never, C = never>(\n ab: (...a: A) => B,\n bc: (b: B) => C\n): (...a: A) => C\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never\n>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...a: A) => D\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E\n): (...a: A) => E\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F\n): (...a: A) => F\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G\n): (...a: A) => G\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H\n): (...a: A) => H\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I\n): (...a: A) => I\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J\n): (...a: A) => J\nexport function flow(\n ab: Function,\n bc?: Function,\n cd?: Function,\n de?: Function,\n ef?: Function,\n fg?: Function,\n gh?: Function,\n hi?: Function,\n ij?: Function\n): unknown {\n switch (arguments.length) {\n case 1:\n return ab\n case 2:\n return function(this: unknown) {\n return bc!(ab.apply(this, arguments))\n }\n case 3:\n return function(this: unknown) {\n return cd!(bc!(ab.apply(this, arguments)))\n }\n case 4:\n return function(this: unknown) {\n return de!(cd!(bc!(ab.apply(this, arguments))))\n }\n case 5:\n return function(this: unknown) {\n return ef!(de!(cd!(bc!(ab.apply(this, arguments)))))\n }\n case 6:\n return function(this: unknown) {\n return fg!(ef!(de!(cd!(bc!(ab.apply(this, arguments))))))\n }\n case 7:\n return function(this: unknown) {\n return gh!(fg!(ef!(de!(cd!(bc!(ab.apply(this, arguments)))))))\n }\n case 8:\n return function(this: unknown) {\n return hi!(gh!(fg!(ef!(de!(cd!(bc!(ab.apply(this, arguments))))))))\n }\n case 9:\n return function(this: unknown) {\n return ij!(hi!(gh!(fg!(ef!(de!(cd!(bc!(ab.apply(this, arguments)))))))))\n }\n }\n return\n}\n\n/**\n * Type hole simulation.\n *\n * @since 2.0.0\n */\nexport const hole: <T>() => T = unsafeCoerce(absurd)\n\n/**\n * The SK combinator, also known as the \"S-K combinator\" or \"S-combinator\", is a fundamental combinator in the\n * lambda calculus and the SKI combinator calculus.\n *\n * This function is useful for discarding the first argument passed to it and returning the second argument.\n *\n * @param _ - The first argument to be discarded.\n * @param b - The second argument to be returned.\n *\n * @example\n * ```ts\n * import { SK } from \"effect/Function\";\n *\n * assert.deepStrictEqual(SK(0, \"hello\"), \"hello\")\n * ```\n *\n * @since 2.0.0\n */\nexport const SK = <A, B>(_: A, b: B): B => b\n","/**\n * @since 2.0.0\n */\n\nimport * as Equivalence from \"./Equivalence.js\"\nimport type { LazyArg } from \"./Function.js\"\nimport { constNull, constUndefined, dual, identity } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\nimport type { Inspectable } from \"./Inspectable.js\"\nimport * as doNotation from \"./internal/doNotation.js\"\nimport * as either from \"./internal/either.js\"\nimport type { Option } from \"./Option.js\"\nimport type { Pipeable } from \"./Pipeable.js\"\nimport type { Predicate, Refinement } from \"./Predicate.js\"\nimport { isFunction } from \"./Predicate.js\"\nimport type { Covariant, NoInfer, NotFunction } from \"./Types.js\"\nimport type * as Unify from \"./Unify.js\"\nimport * as Gen from \"./Utils.js\"\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport type Either<R, L = never> = Left<L, R> | Right<L, R>\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport const TypeId: unique symbol = either.TypeId\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport type TypeId = typeof TypeId\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Left<out L, out R> extends Pipeable, Inspectable {\n readonly _tag: \"Left\"\n readonly _op: \"Left\"\n readonly left: L\n readonly [TypeId]: {\n readonly _R: Covariant<R>\n readonly _L: Covariant<L>\n }\n [Unify.typeSymbol]?: unknown\n [Unify.unifySymbol]?: EitherUnify<this>\n [Unify.ignoreSymbol]?: EitherUnifyIgnore\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Right<out L, out R> extends Pipeable, Inspectable {\n readonly _tag: \"Right\"\n readonly _op: \"Right\"\n readonly right: R\n readonly [TypeId]: {\n readonly _R: Covariant<R>\n readonly _L: Covariant<L>\n }\n [Unify.typeSymbol]?: unknown\n [Unify.unifySymbol]?: EitherUnify<this>\n [Unify.ignoreSymbol]?: EitherUnifyIgnore\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface EitherUnify<A extends { [Unify.typeSymbol]?: any }> {\n Either?: () => A[Unify.typeSymbol] extends Either<infer R0, infer L0> | infer _ ? Either<R0, L0> : never\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface EitherUnifyIgnore {}\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface EitherTypeLambda extends TypeLambda {\n readonly type: Either<this[\"Target\"], this[\"Out1\"]>\n}\n\n/**\n * @since 2.0.0\n */\nexport declare namespace Either {\n /**\n * @since 2.0.0\n * @category type-level\n */\n export type Left<T extends Either<any, any>> = [T] extends [Either<infer _A, infer _E>] ? _E : never\n /**\n * @since 2.0.0\n * @category type-level\n */\n export type Right<T extends Either<any, any>> = [T] extends [Either<infer _A, infer _E>] ? _A : never\n}\n\n/**\n * Constructs a new `Either` holding a `Right` value. This usually represents a successful value due to the right bias\n * of this structure.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const right: <R>(right: R) => Either<R> = either.right\n\n/**\n * Constructs a new `Either` holding a `Left` value. This usually represents a failure, due to the right-bias of this\n * structure.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const left: <L>(left: L) => Either<never, L> = either.left\n\n/**\n * Takes a lazy default and a nullable value, if the value is not nully (`null` or `undefined`), turn it into a `Right`, if the value is nully use\n * the provided default as a `Left`.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromNullable(1, () => 'fallback'), Either.right(1))\n * assert.deepStrictEqual(Either.fromNullable(null, () => 'fallback'), Either.left('fallback'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const fromNullable: {\n /**\n * Takes a lazy default and a nullable value, if the value is not nully (`null` or `undefined`), turn it into a `Right`, if the value is nully use\n * the provided default as a `Left`.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromNullable(1, () => 'fallback'), Either.right(1))\n * assert.deepStrictEqual(Either.fromNullable(null, () => 'fallback'), Either.left('fallback'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <R, L>(onNullable: (right: R) => L): (self: R) => Either<NonNullable<R>, L>\n /**\n * Takes a lazy default and a nullable value, if the value is not nully (`null` or `undefined`), turn it into a `Right`, if the value is nully use\n * the provided default as a `Left`.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromNullable(1, () => 'fallback'), Either.right(1))\n * assert.deepStrictEqual(Either.fromNullable(null, () => 'fallback'), Either.left('fallback'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <R, L>(self: R, onNullable: (right: R) => L): Either<NonNullable<R>, L>\n} = dual(\n 2,\n <R, L>(self: R, onNullable: (right: R) => L): Either<NonNullable<R>, L> =>\n self == null ? left(onNullable(self)) : right(self as NonNullable<R>)\n)\n\n/**\n * @example\n * ```ts\n * import { Either, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromOption(Option.some(1), () => 'error'), Either.right(1))\n * assert.deepStrictEqual(Either.fromOption(Option.none(), () => 'error'), Either.left('error'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const fromOption: {\n /**\n * @example\n * ```ts\n * import { Either, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromOption(Option.some(1), () => 'error'), Either.right(1))\n * assert.deepStrictEqual(Either.fromOption(Option.none(), () => 'error'), Either.left('error'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <L>(onNone: () => L): <R>(self: Option<R>) => Either<R, L>\n /**\n * @example\n * ```ts\n * import { Either, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromOption(Option.some(1), () => 'error'), Either.right(1))\n * assert.deepStrictEqual(Either.fromOption(Option.none(), () => 'error'), Either.left('error'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <R, L>(self: Option<R>, onNone: () => L): Either<R, L>\n} = either.fromOption\n\nconst try_: {\n <R, L>(\n options: {\n readonly try: LazyArg<R>\n readonly catch: (error: unknown) => L\n }\n ): Either<R, L>\n <R>(evaluate: LazyArg<R>): Either<R, unknown>\n} = (<R, L>(\n evaluate: LazyArg<R> | {\n readonly try: LazyArg<R>\n readonly catch: (error: unknown) => L\n }\n) => {\n if (isFunction(evaluate)) {\n try {\n return right(evaluate())\n } catch (e) {\n return left(e)\n }\n } else {\n try {\n return right(evaluate.try())\n } catch (e) {\n return left(evaluate.catch(e))\n }\n }\n}) as any\n\nexport {\n /**\n * Imports a synchronous side-effect into a pure `Either` value, translating any\n * thrown exceptions into typed failed eithers creating with `Either.left`.\n *\n * @category constructors\n * @since 2.0.0\n */\n try_ as try\n}\n\n/**\n * Tests if a value is a `Either`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.isEither(Either.right(1)), true)\n * assert.deepStrictEqual(Either.isEither(Either.left(\"a\")), true)\n * assert.deepStrictEqual(Either.isEither({ right: 1 }), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isEither: (input: unknown) => input is Either<unknown, unknown> = either.isEither\n\n/**\n * Determine if a `Either` is a `Left`.\n *\n * @param self - The `Either` to check.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.isLeft(Either.right(1)), false)\n * assert.deepStrictEqual(Either.isLeft(Either.left(\"a\")), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isLeft: <R, L>(self: Either<R, L>) => self is Left<L, R> = either.isLeft\n\n/**\n * Determine if a `Either` is a `Right`.\n *\n * @param self - The `Either` to check.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.isRight(Either.right(1)), true)\n * assert.deepStrictEqual(Either.isRight(Either.left(\"a\")), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isRight: <R, L>(self: Either<R, L>) => self is Right<L, R> = either.isRight\n\n/**\n * Converts a `Either` to an `Option` discarding the `Left`.\n *\n * @example\n * ```ts\n * import { Either, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getRight(Either.right('ok')), Option.some('ok'))\n * assert.deepStrictEqual(Either.getRight(Either.left('err')), Option.none())\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getRight: <R, L>(self: Either<R, L>) => Option<R> = either.getRight\n\n/**\n * Converts a `Either` to an `Option` discarding the value.\n *\n * @example\n * ```ts\n * import { Either, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getLeft(Either.right('ok')), Option.none())\n * assert.deepStrictEqual(Either.getLeft(Either.left('err')), Option.some('err'))\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getLeft: <R, L>(self: Either<R, L>) => Option<L> = either.getLeft\n\n/**\n * @category equivalence\n * @since 2.0.0\n */\nexport const getEquivalence = <R, L>({ left, right }: {\n right: Equivalence.Equivalence<R>\n left: Equivalence.Equivalence<L>\n}): Equivalence.Equivalence<Either<R, L>> =>\n Equivalence.make((x, y) =>\n isLeft(x) ?\n isLeft(y) && left(x.left, y.left) :\n isRight(y) && right(x.right, y.right)\n )\n\n/**\n * @category mapping\n * @since 2.0.0\n */\nexport const mapBoth: {\n /**\n * @category mapping\n * @since 2.0.0\n */\n <L, L2, R, R2>(\n options: {\n readonly onLeft: (left: L) => L2\n readonly onRight: (right: R) => R2\n }\n ): (self: Either<R, L>) => Either<R2, L2>\n /**\n * @category mapping\n * @since 2.0.0\n */\n <L, R, L2, R2>(\n self: Either<R, L>,\n options: {\n readonly onLeft: (left: L) => L2\n readonly onRight: (right: R) => R2\n }\n ): Either<R2, L2>\n} = dual(\n 2,\n <L, R, L2, R2>(self: Either<R, L>, { onLeft, onRight }: {\n readonly onLeft: (left: L) => L2\n readonly onRight: (right: R) => R2\n }): Either<R2, L2> => isLeft(self) ? left(onLeft(self.left)) : right(onRight(self.right))\n)\n\n/**\n * Maps the `Left` side of an `Either` value to a new `Either` value.\n *\n * @param self - The input `Either` value to map.\n * @param f - A transformation function to apply to the `Left` value of the input `Either`.\n *\n * @category mapping\n * @since 2.0.0\n */\nexport const mapLeft: {\n /**\n * Maps the `Left` side of an `Either` value to a new `Either` value.\n *\n * @param self - The input `Either` value to map.\n * @param f - A transformation function to apply to the `Left` value of the input `Either`.\n *\n * @category mapping\n * @since 2.0.0\n */\n <L, L2>(f: (left: L) => L2): <R>(self: Either<R, L>) => Either<R, L2>\n /**\n * Maps the `Left` side of an `Either` value to a new `Either` value.\n *\n * @param self - The input `Either` value to map.\n * @param f - A transformation function to apply to the `Left` value of the input `Either`.\n *\n * @category mapping\n * @since 2.0.0\n */\n <R, L, L2>(self: Either<R, L>, f: (left: L) => L2): Either<R, L2>\n} = dual(\n 2,\n <R, L1, L2>(self: Either<R, L1>, f: (left: L1) => L2): Either<R, L2> =>\n isLeft(self) ? left(f(self.left)) : right(self.right)\n)\n\n/**\n * Maps the `Right` side of an `Either` value to a new `Either` value.\n *\n * @param self - An `Either` to map\n * @param f - The function to map over the value of the `Either`\n *\n * @category mapping\n * @since 2.0.0\n */\nexport const map: {\n /**\n * Maps the `Right` side of an `Either` value to a new `Either` value.\n *\n * @param self - An `Either` to map\n * @param f - The function to map over the value of the `Either`\n *\n * @category mapping\n * @since 2.0.0\n */\n <R, R2>(f: (right: R) => R2): <L>(self: Either<R, L>) => Either<R2, L>\n /**\n * Maps the `Right` side of an `Either` value to a new `Either` value.\n *\n * @param self - An `Either` to map\n * @param f - The function to map over the value of the `Either`\n *\n * @category mapping\n * @since 2.0.0\n */\n <R, L, R2>(self: Either<R, L>, f: (right: R) => R2): Either<R2, L>\n} = dual(\n 2,\n <R1, L, R2>(self: Either<R1, L>, f: (right: R1) => R2): Either<R2, L> =>\n isRight(self) ? right(f(self.right)) : left(self.left)\n)\n\n/**\n * Takes two functions and an `Either` value, if the value is a `Left` the inner value is applied to the `onLeft function,\n * if the value is a `Right` the inner value is applied to the `onRight` function.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const onLeft = (strings: ReadonlyArray<string>): string => `strings: ${strings.join(', ')}`\n *\n * const onRight = (value: number): string => `Ok: ${value}`\n *\n * assert.deepStrictEqual(pipe(Either.right(1), Either.match({ onLeft, onRight })), 'Ok: 1')\n * assert.deepStrictEqual(\n * pipe(Either.left(['string 1', 'string 2']), Either.match({ onLeft, onRight })),\n * 'strings: string 1, string 2'\n * )\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\nexport const match: {\n /**\n * Takes two functions and an `Either` value, if the value is a `Left` the inner value is applied to the `onLeft function,\n * if the value is a `Right` the inner value is applied to the `onRight` function.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const onLeft = (strings: ReadonlyArray<string>): string => `strings: ${strings.join(', ')}`\n *\n * const onRight = (value: number): string => `Ok: ${value}`\n *\n * assert.deepStrictEqual(pipe(Either.right(1), Either.match({ onLeft, onRight })), 'Ok: 1')\n * assert.deepStrictEqual(\n * pipe(Either.left(['string 1', 'string 2']), Either.match({ onLeft, onRight })),\n * 'strings: string 1, string 2'\n * )\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <L, B, R, C = B>(\n options: {\n readonly onLeft: (left: L) => B\n readonly onRight: (right: R) => C\n }\n ): (self: Either<R, L>) => B | C\n /**\n * Takes two functions and an `Either` value, if the value is a `Left` the inner value is applied to the `onLeft function,\n * if the value is a `Right` the inner value is applied to the `onRight` function.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const onLeft = (strings: ReadonlyArray<string>): string => `strings: ${strings.join(', ')}`\n *\n * const onRight = (value: number): string => `Ok: ${value}`\n *\n * assert.deepStrictEqual(pipe(Either.right(1), Either.match({ onLeft, onRight })), 'Ok: 1')\n * assert.deepStrictEqual(\n * pipe(Either.left(['string 1', 'string 2']), Either.match({ onLeft, onRight })),\n * 'strings: string 1, string 2'\n * )\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <R, L, B, C = B>(\n self: Either<R, L>,\n options: {\n readonly onLeft: (left: L) => B\n readonly onRight: (right: R) => C\n }\n ): B | C\n} = dual(\n 2,\n <R, L, B, C = B>(self: Either<R, L>, { onLeft, onRight }: {\n readonly onLeft: (left: L) => B\n readonly onRight: (right: R) => C\n }): B | C => isLeft(self) ? onLeft(self.left) : onRight(self.right)\n)\n\n/**\n * Transforms a `Predicate` function into a `Right` of the input value if the predicate returns `true`\n * or `Left` of the result of the provided function if the predicate returns false\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * 1,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * 0,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @category lifting\n * @since 3.4.0\n */\nexport const liftPredicate: {\n /**\n * Transforms a `Predicate` function into a `Right` of the input value if the predicate returns `true`\n * or `Left` of the result of the provided function if the predicate returns false\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * 1,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * 0,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @category lifting\n * @since 3.4.0\n */\n <A, B extends A, E>(refinement: Refinement<NoInfer<A>, B>, orLeftWith: (a: NoInfer<A>) => E): (a: A) => Either<B, E>\n /**\n * Transforms a `Predicate` function into a `Right` of the input value if the predicate returns `true`\n * or `Left` of the result of the provided function if the predicate returns false\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * 1,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * 0,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @category lifting\n * @since 3.4.0\n */\n <A, E>(predicate: Predicate<NoInfer<A>>, orLeftWith: (a: NoInfer<A>) => E): (a: A) => Either<A, E>\n /**\n * Transforms a `Predicate` function into a `Right` of the input value if the predicate returns `true`\n * or `Left` of the result of the provided function if the predicate returns false\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * 1,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * 0,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @category lifting\n * @since 3.4.0\n */\n <A, E, B extends A>(self: A, refinement: Refinement<A, B>, orLeftWith: (a: A) => E): Either<B, E>\n /**\n * Transforms a `Predicate` function into a `Right` of the input value if the predicate returns `true`\n * or `Left` of the result of the provided function if the predicate returns false\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * 1,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * 0,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @category lifting\n * @since 3.4.0\n */\n <A, E>(\n self: A,\n predicate: Predicate<NoInfer<A>>,\n orLeftWith: (a: NoInfer<A>) => E\n ): Either<A, E>\n} = dual(\n 3,\n <A, E>(a: A, predicate: Predicate<A>, orLeftWith: (a: A) => E): Either<A, E> =>\n predicate(a) ? right(a) : left(orLeftWith(a))\n)\n\n/**\n * Filter the right value with the provided function.\n * If the predicate fails, set the left value with the result of the provided function.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(1),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(0),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @since 2.0.0\n * @category filtering & conditionals\n */\nexport const filterOrLeft: {\n /**\n * Filter the right value with the provided function.\n * If the predicate fails, set the left value with the result of the provided function.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(1),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(0),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @since 2.0.0\n * @category filtering & conditionals\n */\n <R, B extends R, L2>(\n refinement: Refinement<NoInfer<R>, B>,\n orLeftWith: (right: NoInfer<R>) => L2\n ): <L>(self: Either<R, L>) => Either<B, L2 | L>\n /**\n * Filter the right value with the provided function.\n * If the predicate fails, set the left value with the result of the provided function.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(1),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(0),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @since 2.0.0\n * @category filtering & conditionals\n */\n <R, L2>(\n predicate: Predicate<NoInfer<R>>,\n orLeftWith: (right: NoInfer<R>) => L2\n ): <L>(self: Either<R, L>) => Either<R, L2 | L>\n /**\n * Filter the right value with the provided function.\n * If the predicate fails, set the left value with the result of the provided function.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(1),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(0),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @since 2.0.0\n * @category filtering & conditionals\n */\n <R, L, B extends R, L2>(\n self: Either<R, L>,\n refinement: Refinement<R, B>,\n orLeftWith: (right: R) => L2\n ): Either<B, L | L2>\n /**\n * Filter the right value with the provided function.\n * If the predicate fails, set the left value with the result of the provided function.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(1),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(0),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @since 2.0.0\n * @category filtering & conditionals\n */\n <R, L, E2>(self: Either<R, L>, predicate: Predicate<R>, orLeftWith: (right: R) => E2): Either<R, L | E2>\n} = dual(3, <R, L, E2>(\n self: Either<R, L>,\n predicate: Predicate<R>,\n orLeftWith: (right: R) => E2\n): Either<R, L | E2> => flatMap(self, (r) => predicate(r) ? right(r) : left(orLeftWith(r))))\n\n/**\n * @category getters\n * @since 2.0.0\n */\nexport const merge: <R, L>(self: Either<R, L>) => L | R = match({\n onLeft: identity,\n onRight: identity\n})\n\n/**\n * Returns the wrapped value if it's a `Right` or a default value if is a `Left`.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrElse(Either.right(1), (error) => error + \"!\"), 1)\n * assert.deepStrictEqual(Either.getOrElse(Either.left(\"not a number\"), (error) => error + \"!\"), \"not a number!\")\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrElse: {\n /**\n * Returns the wrapped value if it's a `Right` or a default value if is a `Left`.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrElse(Either.right(1), (error) => error + \"!\"), 1)\n * assert.deepStrictEqual(Either.getOrElse(Either.left(\"not a number\"), (error) => error + \"!\"), \"not a number!\")\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <L, R2>(onLeft: (left: L) => R2): <R>(self: Either<R, L>) => R2 | R\n /**\n * Returns the wrapped value if it's a `Right` or a default value if is a `Left`.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrElse(Either.right(1), (error) => error + \"!\"), 1)\n * assert.deepStrictEqual(Either.getOrElse(Either.left(\"not a number\"), (error) => error + \"!\"), \"not a number!\")\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <R, L, R2>(self: Either<R, L>, onLeft: (left: L) => R2): R | R2\n} = dual(\n 2,\n <R, L, B>(self: Either<R, L>, onLeft: (left: L) => B): R | B => isLeft(self) ? onLeft(self.left) : self.right\n)\n\n/**\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrNull(Either.right(1)), 1)\n * assert.deepStrictEqual(Either.getOrNull(Either.left(\"a\")), null)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrNull: <R, L>(self: Either<R, L>) => R | null = getOrElse(constNull)\n\n/**\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrUndefined(Either.right(1)), 1)\n * assert.deepStrictEqual(Either.getOrUndefined(Either.left(\"a\")), undefined)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrUndefined: <R, L>(self: Either<R, L>) => R | undefined = getOrElse(constUndefined)\n\n/**\n * Extracts the value of an `Either` or throws if the `Either` is `Left`.\n *\n * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.\n *\n * @param self - The `Either` to extract the value from.\n * @param onLeft - A function that will be called if the `Either` is `Left`. It returns the error to be thrown.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Either.getOrThrowWith(Either.right(1), () => new Error('Unexpected Left')),\n * 1\n * )\n * assert.throws(() => Either.getOrThrowWith(Either.left(\"error\"), () => new Error('Unexpected Left')))\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrThrowWith: {\n /**\n * Extracts the value of an `Either` or throws if the `Either` is `Left`.\n *\n * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.\n *\n * @param self - The `Either` to extract the value from.\n * @param onLeft - A function that will be called if the `Either` is `Left`. It returns the error to be thrown.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Either.getOrThrowWith(Either.right(1), () => new Error('Unexpected Left')),\n * 1\n * )\n * assert.throws(() => Either.getOrThrowWith(Either.left(\"error\"), () => new Error('Unexpected Left')))\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <L>(onLeft: (left: L) => unknown): <A>(self: Either<A, L>) => A\n /**\n * Extracts the value of an `Either` or throws if the `Either` is `Left`.\n *\n * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.\n *\n * @param self - The `Either` to extract the value from.\n * @param onLeft - A function that will be called if the `Either` is `Left`. It returns the error to be thrown.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Either.getOrThrowWith(Either.right(1), () => new Error('Unexpected Left')),\n * 1\n * )\n * assert.throws(() => Either.getOrThrowWith(Either.left(\"error\"), () => new Error('Unexpected Left')))\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <R, L>(self: Either<R, L>, onLeft: (left: L) => unknown): R\n} = dual(2, <R, L>(self: Either<R, L>, onLeft: (left: L) => unknown): R => {\n if (isRight(self)) {\n return self.right\n }\n throw onLeft(self.left)\n})\n\n/**\n * Extracts the value of an `Either` or throws if the `Either` is `Left`.\n *\n * The thrown error is a default error. To configure the error thrown, see {@link getOrThrowWith}.\n *\n * @param self - The `Either` to extract the value from.\n * @throws `Error(\"getOrThrow called on a Left\")`\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrThrow(Either.right(1)), 1)\n * assert.throws(() => Either.getOrThrow(Either.left(\"error\")))\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrThrow: <R, L>(self: Either<R, L>) => R = getOrThrowWith(() =>\n new Error(\"getOrThrow called on a Left\")\n)\n\n/**\n * Returns `self` if it is a `Right` or `that` otherwise.\n *\n * @param self - The input `Either` value to check and potentially return.\n * @param that - A function that takes the error value from `self` (if it's a `Left`) and returns a new `Either` value.\n *\n * @category error handling\n * @since 2.0.0\n */\nexport const orElse: {\n /**\n * Returns `self` if it is a `Right` or `that` otherwise.\n *\n * @param self - The input `Either` value to check and potentially return.\n * @param that - A function that takes the error value from `self` (if it's a `Left`) and returns a new `Either` value.\n *\n * @category error handling\n * @since 2.0.0\n */\n <L, R2, L2>(that: (left: L) => Either<R2, L2>): <R>(self: Either<R, L>) => Either<R | R2, L2>\n /**\n * Returns `self` if it is a `Right` or `that` otherwise.\n *\n * @param self - The input `Either` value to check and potentially return.\n * @param that - A function that takes the error value from `self` (if it's a `Left`) and returns a new `Either` value.\n *\n * @category error handling\n * @since 2.0.0\n */\n <R, L, R2, L2>(self: Either<R, L>, that: (left: L) => Either<R2, L2>): Either<R | R2, L2>\n} = dual(\n 2,\n <R1, L1, R2, L2>(self: Either<R1, L1>, that: (left: L1) => Either<R2, L2>): Either<R1 | R2, L2> =>\n isLeft(self) ? that(self.left) : right(self.right)\n)\n\n/**\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatMap: {\n /**\n * @category sequencing\n * @since 2.0.0\n */\n <R, R2, L2>(f: (right: R) => Either<R2, L2>): <L>(self: Either<R, L>) => Either<R2, L | L2>\n /**\n * @category sequencing\n * @since 2.0.0\n */\n <R, L, R2, L2>(self: Either<R, L>, f: (right: R) => Either<R2, L2>): Either<R2, L | L2>\n} = dual(\n 2,\n <R1, L1, R2, L2>(self: Either<R1, L1>, f: (right: R1) => Either<R2, L2>): Either<R2, L1 | L2> =>\n isLeft(self) ? left(self.left) : f(self.right)\n)\n\n/**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const andThen: {\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, R2, L2>(f: (right: R) => Either<R2, L2>): <L>(self: Either<R, L>) => Either<R2, L | L2>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R2, L2>(f: Either<R2, L2>): <L, R1>(self: Either<R1, L>) => Either<R2, L | L2>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, R2>(f: (right: R) => R2): <L>(self: Either<R, L>) => Either<R2, L>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R2>(right: NotFunction<R2>): <R1, L>(self: Either<R1, L>) => Either<R2, L>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, L, R2, L2>(self: Either<R, L>, f: (right: R) => Either<R2, L2>): Either<R2, L | L2>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, L, R2, L2>(self: Either<R, L>, f: Either<R2, L2>): Either<R2, L | L2>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, L, R2>(self: Either<R, L>, f: (right: R) => R2): Either<R2, L>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, L, R2>(self: Either<R, L>, f: NotFunction<R2>): Either<R2, L>\n} = dual(\n 2,\n <R, L, R2, L2>(self: Either<R, L>, f: (right: R) => Either<R2, L2> | Either<R2, L2>): Either<R2, L | L2> =>\n flatMap(self, (a) => {\n const b = isFunction(f) ? f(a) : f\n return isEither(b) ? b : right(b)\n })\n)\n\n/**\n * @category zipping\n * @since 2.0.0\n */\nexport const zipWith: {\n /**\n * @category zipping\n * @since 2.0.0\n */\n <R2, L2, R, B>(that: Either<R2, L2>, f: (right: R, right2: R2) => B): <L>(self: Either<R, L>) => Either<B, L2 | L>\n /**\n * @category zipping\n * @since 2.0.0\n */\n <R, L, R2, L2, B>(self: Either<R, L>, that: Either<R2, L2>, f: (right: R, right2: R2) => B): Either<B, L | L2>\n} = dual(\n 3,\n <R, L, R2, L2, B>(self: Either<R, L>, that: Either<R2, L2>, f: (right: R, right2: R2) => B): Either<B, L | L2> =>\n flatMap(self, (r) => map(that, (r2) => f(r, r2)))\n)\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const ap: {\n /**\n * @category combining\n * @since 2.0.0\n */\n <R, L2>(that: Either<R, L2>): <R2, L>(self: Either<(right: R) => R2, L>) => Either<R2, L | L2>\n /**\n * @category combining\n * @since 2.0.0\n */\n <R, R2, L, L2>(self: Either<(right: R) => R2, L>, that: Either<R, L2>): Either<R2, L | L2>\n} = dual(\n 2,\n <R, R2, L, L2>(self: Either<(right: R) => R2, L>, that: Either<R, L2>): Either<R2, L | L2> =>\n zipWith(self, that, (f, a) => f(a))\n)\n\n/**\n * Takes a structure of `Either`s and returns an `Either` of values with the same structure.\n *\n * - If a tuple is supplied, then the returned `Either` will contain a tuple with the same length.\n * - If a struct is supplied, then the returned `Either` will contain a struct with the same keys.\n * - If an iterable is supplied, then the returned `Either` will contain an array.\n *\n * @param fields - the struct of `Either`s to be sequenced.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.all([Either.right(1), Either.right(2)]), Either.right([1, 2]))\n * assert.deepStrictEqual(Either.all({ right: Either.right(1), b: Either.right(\"hello\") }), Either.right({ right: 1, b: \"hello\" }))\n * assert.deepStrictEqual(Either.all({ right: Either.right(1), b: Either.left(\"error\") }), Either.left(\"error\"))\n * ```\n *\n * @category combining\n * @since 2.0.0\n */\n// @ts-expect-error\nexport const all: <const I extends Iterable<Either<any, any>> | Record<string, Either<any, any>>>(\n input: I\n) => [I] extends [ReadonlyArray<Either<any, any>>] ? Either<\n { -readonly [K in keyof I]: [I[K]] extends [Either<infer R, any>] ? R : never },\n I[number] extends never ? never : [I[number]] extends [Either<any, infer L>] ? L : never\n >\n : [I] extends [Iterable<Either<infer R, infer L>>] ? Either<Array<R>, L>\n : Either<\n { -readonly [K in keyof I]: [I[K]] extends [Either<infer R, any>] ? R : never },\n I[keyof I] extends never ? never : [I[keyof I]] extends [Either<any, infer L>] ? L : never\n > = (\n input: Iterable<Either<any, any>> | Record<string, Either<any, any>>\n ): Either<any, any> => {\n if (Symbol.iterator in input) {\n const out: Array<Either<any, any>> = []\n for (const e of (input as Iterable<Either<any, any>>)) {\n if (isLeft(e)) {\n return e\n }\n out.push(e.right)\n }\n return right(out)\n }\n\n const out: Record<string, any> = {}\n for (const key of Object.keys(input)) {\n const e = input[key]\n if (isLeft(e)) {\n return e\n }\n out[key] = e.right\n }\n return right(out)\n }\n\n/**\n * Returns an `Either` that swaps the error/success cases. This allows you to\n * use all methods on the error channel, possibly before flipping back.\n *\n * @since 2.0.0\n * @category mapping\n */\nexport const flip = <R, L>(self: Either<R, L>): Either<L, R> => isLeft(self) ? right(self.left) : left(self.right)\n\nconst adapter = Gen.adapter<EitherTypeLambda>()\n\n/**\n * @category generators\n * @since 2.0.0\n */\nexport const gen: Gen.Gen<EitherTypeLambda, Gen.Adapter<EitherTypeLambda>> = (...args) => {\n const f = (args.length === 1)\n ? args[0]\n : args[1].bind(args[0])\n const iterator = f(adapter)\n let state: IteratorYieldResult<any> | IteratorReturnResult<any> = iterator.next()\n if (state.done) {\n return right(state.value) as any\n } else {\n let current = state.value\n if (Gen.isGenKind(current)) {\n current = current.value\n } else {\n current = Gen.yieldWrapGet(current)\n }\n if (isLeft(current)) {\n return current\n }\n while (!state.done) {\n state = iterator.next(current.right as never)\n if (!state.done) {\n current = state.value\n if (Gen.isGenKind(current)) {\n current = current.value\n } else {\n current = Gen.yieldWrapGet(current)\n }\n if (isLeft(current)) {\n return current\n }\n }\n }\n return right(state.value)\n }\n}\n\n// -------------------------------------------------------------------------------------\n// do notation\n// -------------------------------------------------------------------------------------\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @see {@link bind}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\nexport const Do: Either<{}> = right({})\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\nexport const bind: {\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <N extends string, A extends object, B, L2>(\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => Either<B, L2>\n ): <L1>(self: Either<A, L1>) => Either<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, L1 | L2>\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <A extends object, L1, N extends string, B, L2>(\n self: Either<A, L1>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => Either<B, L2>\n ): Either<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, L1 | L2>\n} = doNotation.bind<EitherTypeLambda>(map, flatMap)\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\nexport const bindTo: {\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <N extends string>(name: N): <R, L>(self: Either<R, L>) => Either<{ [K in N]: R }, L>\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <R, L, N extends string>(self: Either<R, L>, name: N): Either<{ [K in N]: R }, L>\n} = doNotation.bindTo<EitherTypeLambda>(map)\n\nconst let_: {\n <N extends string, R extends object, B>(\n name: Exclude<N, keyof R>,\n f: (r: NoInfer<R>) => B\n ): <L>(self: Either<R, L>) => Either<{ [K in N | keyof R]: K extends keyof R ? R[K] : B }, L>\n <R extends object, L, N extends string, B>(\n self: Either<R, L>,\n name: Exclude<N, keyof R>,\n f: (r: NoInfer<R>) => B\n ): Either<{ [K in N | keyof R]: K extends keyof R ? R[K] : B }, L>\n} = doNotation.let_<EitherTypeLambda>(map)\n\nexport {\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link bind}\n *\n * @example\n * ```ts\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n *\n * ```\n * @category do notation\n * @since 2.0.0\n */\n let_ as let\n}\n","/**\n * This module provides an implementation of the `Equivalence` type class, which defines a binary relation\n * that is reflexive, symmetric, and transitive. In other words, it defines a notion of equivalence between values of a certain type.\n * These properties are also known in mathematics as an \"equivalence relation\".\n *\n * @since 2.0.0\n */\nimport { dual } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\n\n/**\n * @category type class\n * @since 2.0.0\n */\nexport interface Equivalence<in A> {\n (self: A, that: A): boolean\n}\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface EquivalenceTypeLambda extends TypeLambda {\n readonly type: Equivalence<this[\"Target\"]>\n}\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const make = <A>(isEquivalent: (self: A, that: A) => boolean): Equivalence<A> => (self: A, that: A): boolean =>\n self === that || isEquivalent(self, that)\n\nconst isStrictEquivalent = (x: unknown, y: unknown) => x === y\n\n/**\n * Return an `Equivalence` that uses strict equality (===) to compare values.\n *\n * @since 2.0.0\n * @category constructors\n */\nexport const strict: <A>() => Equivalence<A> = () => isStrictEquivalent\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const string: Equivalence<string> = strict()\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const number: Equivalence<number> = strict()\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const boolean: Equivalence<boolean> = strict()\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const bigint: Equivalence<bigint> = strict()\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const symbol: Equivalence<symbol> = strict()\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const combine: {\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(that: Equivalence<A>): (self: Equivalence<A>) => Equivalence<A>\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(self: Equivalence<A>, that: Equivalence<A>): Equivalence<A>\n} = dual(2, <A>(self: Equivalence<A>, that: Equivalence<A>): Equivalence<A> => make((x, y) => self(x, y) && that(x, y)))\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const combineMany: {\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(collection: Iterable<Equivalence<A>>): (self: Equivalence<A>) => Equivalence<A>\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(self: Equivalence<A>, collection: Iterable<Equivalence<A>>): Equivalence<A>\n} = dual(2, <A>(self: Equivalence<A>, collection: Iterable<Equivalence<A>>): Equivalence<A> =>\n make((x, y) => {\n if (!self(x, y)) {\n return false\n }\n for (const equivalence of collection) {\n if (!equivalence(x, y)) {\n return false\n }\n }\n return true\n }))\n\nconst isAlwaysEquivalent: Equivalence<unknown> = (_x, _y) => true\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const combineAll = <A>(collection: Iterable<Equivalence<A>>): Equivalence<A> =>\n combineMany(isAlwaysEquivalent, collection)\n\n/**\n * @category mapping\n * @since 2.0.0\n */\nexport const mapInput: {\n /**\n * @category mapping\n * @since 2.0.0\n */\n <B, A>(f: (b: B) => A): (self: Equivalence<A>) => Equivalence<B>\n /**\n * @category mapping\n * @since 2.0.0\n */\n <A, B>(self: Equivalence<A>, f: (b: B) => A): Equivalence<B>\n} = dual(\n 2,\n <A, B>(self: Equivalence<A>, f: (b: B) => A): Equivalence<B> => make((x, y) => self(f(x), f(y)))\n)\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const Date: Equivalence<Date> = mapInput(number, (date) => date.getTime())\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const product: {\n <B>(that: Equivalence<B>): <A>(self: Equivalence<A>) => Equivalence<readonly [A, B]> // readonly because invariant\n <A, B>(self: Equivalence<A>, that: Equivalence<B>): Equivalence<readonly [A, B]> // readonly because invariant\n} = dual(\n 2,\n <A, B>(self: Equivalence<A>, that: Equivalence<B>): Equivalence<readonly [A, B]> =>\n make(([xa, xb], [ya, yb]) => self(xa, ya) && that(xb, yb))\n)\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const all = <A>(collection: Iterable<Equivalence<A>>): Equivalence<ReadonlyArray<A>> => {\n return make((x, y) => {\n const len = Math.min(x.length, y.length)\n\n let collectionLength = 0\n for (const equivalence of collection) {\n if (collectionLength >= len) {\n break\n }\n if (!equivalence(x[collectionLength], y[collectionLength])) {\n return false\n }\n collectionLength++\n }\n return true\n })\n}\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const productMany = <A>(\n self: Equivalence<A>,\n collection: Iterable<Equivalence<A>>\n): Equivalence<readonly [A, ...Array<A>]> /* readonly because invariant */ => {\n const equivalence = all(collection)\n return make((x, y) => !self(x[0], y[0]) ? false : equivalence(x.slice(1), y.slice(1)))\n}\n\n/**\n * Similar to `Promise.all` but operates on `Equivalence`s.\n *\n * ```\n * [Equivalence<A>, Equivalence<B>, ...] -> Equivalence<[A, B, ...]>\n * ```\n *\n * Given a tuple of `Equivalence`s returns a new `Equivalence` that compares values of a tuple\n * by applying each `Equivalence` to the corresponding element of the tuple.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const tuple = <T extends ReadonlyArray<Equivalence<any>>>(\n ...elements: T\n): Equivalence<Readonly<{ [I in keyof T]: [T[I]] extends [Equivalence<infer A>] ? A : never }>> => all(elements) as any\n\n/**\n * Creates a new `Equivalence` for an array of values based on a given `Equivalence` for the elements of the array.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const array = <A>(item: Equivalence<A>): Equivalence<ReadonlyArray<A>> =>\n make((self, that) => {\n if (self.length !== that.length) {\n return false\n }\n\n for (let i = 0; i < self.length; i++) {\n const isEq = item(self[i], that[i])\n if (!isEq) {\n return false\n }\n }\n\n return true\n })\n\n/**\n * Given a struct of `Equivalence`s returns a new `Equivalence` that compares values of a struct\n * by applying each `Equivalence` to the corresponding property of the struct.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const struct = <R extends Record<string, Equivalence<any>>>(\n fields: R\n): Equivalence<{ readonly [K in keyof R]: [R[K]] extends [Equivalence<infer A>] ? A : never }> => {\n const keys = Object.keys(fields)\n return make((self, that) => {\n for (const key of keys) {\n if (!fields[key](self[key], that[key])) {\n return false\n }\n }\n return true\n })\n}\n","import { dual } from \"../Function.js\"\nimport type { Kind, TypeLambda } from \"../HKT.js\"\nimport type { NoInfer } from \"../Types.js\"\n\ntype Map<F extends TypeLambda> = {\n <A, B>(f: (a: A) => B): <R, O, E>(self: Kind<F, R, O, E, A>) => Kind<F, R, O, E, B>\n <R, O, E, A, B>(self: Kind<F, R, O, E, A>, f: (a: A) => B): Kind<F, R, O, E, B>\n}\n\ntype FlatMap<F extends TypeLambda> = {\n <A, R2, O2, E2, B>(\n f: (a: A) => Kind<F, R2, O2, E2, B>\n ): <R1, O1, E1>(self: Kind<F, R1, O1, E1, A>) => Kind<F, R1 & R2, O1 | O2, E1 | E2, B>\n <R1, O1, E1, A, R2, O2, E2, B>(\n self: Kind<F, R1, O1, E1, A>,\n f: (a: A) => Kind<F, R2, O2, E2, B>\n ): Kind<F, R1 & R2, O1 | O2, E1 | E2, B>\n}\n\n/** @internal */\nexport const let_ = <F extends TypeLambda>(\n map: Map<F>\n): {\n <N extends string, A extends object, B>(\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): <R, O, E>(\n self: Kind<F, R, O, E, A>\n ) => Kind<F, R, O, E, { [K in keyof A | N]: K extends keyof A ? A[K] : B }>\n <R, O, E, A extends object, N extends string, B>(\n self: Kind<F, R, O, E, A>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): Kind<F, R, O, E, { [K in keyof A | N]: K extends keyof A ? A[K] : B }>\n} =>\n dual(3, <R, O, E, A extends object, N extends string, B>(\n self: Kind<F, R, O, E, A>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): Kind<F, R, O, E, { [K in keyof A | N]: K extends keyof A ? A[K] : B }> =>\n map(self, (a) => Object.assign({}, a, { [name]: f(a) }) as any))\n\n/** @internal */\nexport const bindTo = <F extends TypeLambda>(map: Map<F>): {\n <N extends string>(\n name: N\n ): <R, O, E, A>(self: Kind<F, R, O, E, A>) => Kind<F, R, O, E, { [K in N]: A }>\n <R, O, E, A, N extends string>(\n self: Kind<F, R, O, E, A>,\n name: N\n ): Kind<F, R, O, E, { [K in N]: A }>\n} =>\n dual(2, <R, O, E, A, N extends string>(\n self: Kind<F, R, O, E, A>,\n name: N\n ): Kind<F, R, O, E, { [K in N]: A }> => map(self, (a) => ({ [name]: a } as { [K in N]: A })))\n\n/** @internal */\nexport const bind = <F extends TypeLambda>(map: Map<F>, flatMap: FlatMap<F>): {\n <N extends string, A extends object, R2, O2, E2, B>(\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => Kind<F, R2, O2, E2, B>\n ): <R1, O1, E1>(\n self: Kind<F, R1, O1, E1, A>\n ) => Kind<F, R1 & R2, O1 | O2, E1 | E2, { [K in keyof A | N]: K extends keyof A ? A[K] : B }>\n <R1, O1, E1, A extends object, N extends string, R2, O2, E2, B>(\n self: Kind<F, R1, O1, E1, A>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => Kind<F, R2, O2, E2, B>\n ): Kind<F, R1 & R2, O1 | O2, E1 | E2, { [K in keyof A | N]: K extends keyof A ? A[K] : B }>\n} =>\n dual(3, <R1, O1, E1, A, N extends string, R2, O2, E2, B>(\n self: Kind<F, R1, O1, E1, A>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => Kind<F, R2, O2, E2, B>\n ): Kind<F, R1 & R2, O1 | O2, E1 | E2, { [K in keyof A | N]: K extends keyof A ? A[K] : B }> =>\n flatMap(self, (a) =>\n map(f(a), (b) => Object.assign({}, a, { [name]: b }) as { [K in keyof A | N]: K extends keyof A ? A[K] : B })))\n","let moduleVersion = \"3.12.5\"\n\nexport const getCurrentVersion = () => moduleVersion\n\nexport const setCurrentVersion = (version: string) => {\n moduleVersion = version\n}\n","/**\n * The `GlobalValue` module ensures that a single instance of a value is created globally,\n * even when modules are imported multiple times (e.g., due to mixing CommonJS and ESM builds)\n * or during hot-reloading in development environments like Next.js or Remix.\n *\n * It achieves this by using a versioned global store, identified by a unique `Symbol` tied to\n * the current version of the `effect` library. The store holds values that are keyed by an identifier,\n * allowing the reuse of previously computed instances across imports or reloads.\n *\n * This pattern is particularly useful in scenarios where frequent reloading can cause services or\n * single-instance objects to be recreated unnecessarily, such as in development environments with hot-reloading.\n *\n * @since 2.0.0\n */\nimport * as version from \"./internal/version.js\"\n\nconst globalStoreId = `effect/GlobalValue/globalStoreId/${version.getCurrentVersion()}`\n\nlet globalStore: Map<unknown, any>\n\n/**\n * Retrieves or computes a global value associated with the given `id`. If the value for this `id`\n * has already been computed, it will be returned from the global store. If it does not exist yet,\n * the provided `compute` function will be executed to compute the value, store it, and then return it.\n *\n * This ensures that even in cases where the module is imported multiple times (e.g., in mixed environments\n * like CommonJS and ESM, or during hot-reloading in development), the value is computed only once and reused\n * thereafter.\n *\n * @example\n * ```ts\n * import { globalValue } from \"effect/GlobalValue\"\n *\n * // This cache will persist as long as the module is running,\n * // even if reloaded or imported elsewhere\n * const myCache = globalValue(\n * Symbol.for(\"myCache\"),\n * () => new WeakMap<object, number>()\n * )\n * ```\n *\n * @since 2.0.0\n */\nexport const globalValue = <A>(id: unknown, compute: () => A): A => {\n if (!globalStore) {\n // @ts-expect-error\n globalThis[globalStoreId] ??= new Map()\n // @ts-expect-error\n globalStore = globalThis[globalStoreId] as Map<unknown, any>\n }\n if (!globalStore.has(id)) {\n globalStore.set(id, compute())\n }\n return globalStore.get(id)!\n}\n","/**\n * @since 2.0.0\n */\nimport { dual, isFunction as isFunction_ } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\nimport type { TupleOf, TupleOfAtLeast } from \"./Types.js\"\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Predicate<in A> {\n (a: A): boolean\n}\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface PredicateTypeLambda extends TypeLambda {\n readonly type: Predicate<this[\"Target\"]>\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Refinement<in A, out B extends A> {\n (a: A): a is B\n}\n\n/**\n * @since 3.6.0\n * @category type-level\n */\nexport declare namespace Predicate {\n /**\n * @since 3.6.0\n * @category type-level\n */\n export type In<T extends Any> = [T] extends [Predicate<infer _A>] ? _A : never\n /**\n * @since 3.6.0\n * @category type-level\n */\n export type Any = Predicate<never>\n}\n\n/**\n * @since 3.6.0\n * @category type-level\n */\nexport declare namespace Refinement {\n /**\n * @since 3.6.0\n * @category type-level\n */\n export type In<T extends Any> = [T] extends [Refinement<infer _A, infer _>] ? _A : never\n /**\n * @since 3.6.0\n * @category type-level\n */\n export type Out<T extends Any> = [T] extends [Refinement<infer _, infer _B>] ? _B : never\n /**\n * @since 3.6.0\n * @category type-level\n */\n export type Any = Refinement<any, any>\n}\n\n/**\n * Given a `Predicate<A>` returns a `Predicate<B>`\n *\n * @param self - the `Predicate<A>` to be transformed to `Predicate<B>`.\n * @param f - a function to transform `B` to `A`.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const minLength3 = Predicate.mapInput(Number.greaterThan(2), (s: string) => s.length)\n *\n * assert.deepStrictEqual(minLength3(\"a\"), false)\n * assert.deepStrictEqual(minLength3(\"aa\"), false)\n * assert.deepStrictEqual(minLength3(\"aaa\"), true)\n * assert.deepStrictEqual(minLength3(\"aaaa\"), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const mapInput: {\n /**\n * Given a `Predicate<A>` returns a `Predicate<B>`\n *\n * @param self - the `Predicate<A>` to be transformed to `Predicate<B>`.\n * @param f - a function to transform `B` to `A`.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const minLength3 = Predicate.mapInput(Number.greaterThan(2), (s: string) => s.length)\n *\n * assert.deepStrictEqual(minLength3(\"a\"), false)\n * assert.deepStrictEqual(minLength3(\"aa\"), false)\n * assert.deepStrictEqual(minLength3(\"aaa\"), true)\n * assert.deepStrictEqual(minLength3(\"aaaa\"), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <B, A>(f: (b: B) => A): (self: Predicate<A>) => Predicate<B>\n /**\n * Given a `Predicate<A>` returns a `Predicate<B>`\n *\n * @param self - the `Predicate<A>` to be transformed to `Predicate<B>`.\n * @param f - a function to transform `B` to `A`.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const minLength3 = Predicate.mapInput(Number.greaterThan(2), (s: string) => s.length)\n *\n * assert.deepStrictEqual(minLength3(\"a\"), false)\n * assert.deepStrictEqual(minLength3(\"aa\"), false)\n * assert.deepStrictEqual(minLength3(\"aaa\"), true)\n * assert.deepStrictEqual(minLength3(\"aaaa\"), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A, B>(self: Predicate<A>, f: (b: B) => A): Predicate<B>\n} = dual(2, <A, B>(self: Predicate<A>, f: (b: B) => A): Predicate<B> => (b) => self(f(b)))\n\n/**\n * Determine if an `Array` is a tuple with exactly `N` elements, narrowing down the type to `TupleOf`.\n *\n * An `Array` is considered to be a `TupleOf` if its length is exactly `N`.\n *\n * @param self - The `Array` to check.\n * @param n - The exact number of elements that the `Array` should have to be considered a `TupleOf`.\n *\n * @example\n * ```ts\n * import { isTupleOf } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 3), true);\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 2), false);\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 4), false);\n *\n * const arr: number[] = [1, 2, 3];\n * if (isTupleOf(arr, 3)) {\n * console.log(arr);\n * // ^? [number, number, number]\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\nexport const isTupleOf: {\n /**\n * Determine if an `Array` is a tuple with exactly `N` elements, narrowing down the type to `TupleOf`.\n *\n * An `Array` is considered to be a `TupleOf` if its length is exactly `N`.\n *\n * @param self - The `Array` to check.\n * @param n - The exact number of elements that the `Array` should have to be considered a `TupleOf`.\n *\n * @example\n * ```ts\n * import { isTupleOf } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 3), true);\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 2), false);\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 4), false);\n *\n * const arr: number[] = [1, 2, 3];\n * if (isTupleOf(arr, 3)) {\n * console.log(arr);\n * // ^? [number, number, number]\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\n <N extends number>(n: N): <T>(self: ReadonlyArray<T>) => self is TupleOf<N, T>\n /**\n * Determine if an `Array` is a tuple with exactly `N` elements, narrowing down the type to `TupleOf`.\n *\n * An `Array` is considered to be a `TupleOf` if its length is exactly `N`.\n *\n * @param self - The `Array` to check.\n * @param n - The exact number of elements that the `Array` should have to be considered a `TupleOf`.\n *\n * @example\n * ```ts\n * import { isTupleOf } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 3), true);\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 2), false);\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 4), false);\n *\n * const arr: number[] = [1, 2, 3];\n * if (isTupleOf(arr, 3)) {\n * console.log(arr);\n * // ^? [number, number, number]\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\n <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T>\n} = dual(2, <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T> => self.length === n)\n\n/**\n * Determine if an `Array` is a tuple with at least `N` elements, narrowing down the type to `TupleOfAtLeast`.\n *\n * An `Array` is considered to be a `TupleOfAtLeast` if its length is at least `N`.\n *\n * @param self - The `Array` to check.\n * @param n - The minimum number of elements that the `Array` should have to be considered a `TupleOfAtLeast`.\n *\n * @example\n * ```ts\n * import { isTupleOfAtLeast } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 3), true);\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 2), true);\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 4), false);\n *\n * const arr: number[] = [1, 2, 3, 4];\n * if (isTupleOfAtLeast(arr, 3)) {\n * console.log(arr);\n * // ^? [number, number, number, ...number[]]\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\nexport const isTupleOfAtLeast: {\n /**\n * Determine if an `Array` is a tuple with at least `N` elements, narrowing down the type to `TupleOfAtLeast`.\n *\n * An `Array` is considered to be a `TupleOfAtLeast` if its length is at least `N`.\n *\n * @param self - The `Array` to check.\n * @param n - The minimum number of elements that the `Array` should have to be considered a `TupleOfAtLeast`.\n *\n * @example\n * ```ts\n * import { isTupleOfAtLeast } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 3), true);\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 2), true);\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 4), false);\n *\n * const arr: number[] = [1, 2, 3, 4];\n * if (isTupleOfAtLeast(arr, 3)) {\n * console.log(arr);\n * // ^? [number, number, number, ...number[]]\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\n <N extends number>(n: N): <T>(self: ReadonlyArray<T>) => self is TupleOfAtLeast<N, T>\n /**\n * Determine if an `Array` is a tuple with at least `N` elements, narrowing down the type to `TupleOfAtLeast`.\n *\n * An `Array` is considered to be a `TupleOfAtLeast` if its length is at least `N`.\n *\n * @param self - The `Array` to check.\n * @param n - The minimum number of elements that the `Array` should have to be considered a `TupleOfAtLeast`.\n *\n * @example\n * ```ts\n * import { isTupleOfAtLeast } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 3), true);\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 2), true);\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 4), false);\n *\n * const arr: number[] = [1, 2, 3, 4];\n * if (isTupleOfAtLeast(arr, 3)) {\n * console.log(arr);\n * // ^? [number, number, number, ...number[]]\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\n <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOfAtLeast<N, T>\n} = dual(2, <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOfAtLeast<N, T> => self.length >= n)\n\n/**\n * Tests if a value is `truthy`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isTruthy } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTruthy(1), true)\n * assert.deepStrictEqual(isTruthy(0), false)\n * assert.deepStrictEqual(isTruthy(\"\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isTruthy = (input: unknown) => !!input\n\n/**\n * Tests if a value is a `Set`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isSet } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isSet(new Set([1, 2])), true)\n * assert.deepStrictEqual(isSet(new Set()), true)\n * assert.deepStrictEqual(isSet({}), false)\n * assert.deepStrictEqual(isSet(null), false)\n * assert.deepStrictEqual(isSet(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isSet = (input: unknown): input is Set<unknown> => input instanceof Set\n\n/**\n * Tests if a value is a `Map`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isMap } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isMap(new Map()), true)\n * assert.deepStrictEqual(isMap({}), false)\n * assert.deepStrictEqual(isMap(null), false)\n * assert.deepStrictEqual(isMap(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isMap = (input: unknown): input is Map<unknown, unknown> => input instanceof Map\n\n/**\n * Tests if a value is a `string`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isString } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isString(\"a\"), true)\n *\n * assert.deepStrictEqual(isString(1), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isString = (input: unknown): input is string => typeof input === \"string\"\n\n/**\n * Tests if a value is a `number`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isNumber } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNumber(2), true)\n *\n * assert.deepStrictEqual(isNumber(\"2\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNumber = (input: unknown): input is number => typeof input === \"number\"\n\n/**\n * Tests if a value is a `boolean`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isBoolean } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isBoolean(true), true)\n *\n * assert.deepStrictEqual(isBoolean(\"true\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isBoolean = (input: unknown): input is boolean => typeof input === \"boolean\"\n\n/**\n * Tests if a value is a `bigint`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isBigInt } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isBigInt(1n), true)\n *\n * assert.deepStrictEqual(isBigInt(1), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isBigInt = (input: unknown): input is bigint => typeof input === \"bigint\"\n\n/**\n * Tests if a value is a `symbol`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isSymbol } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isSymbol(Symbol.for(\"a\")), true)\n *\n * assert.deepStrictEqual(isSymbol(\"a\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isSymbol = (input: unknown): input is symbol => typeof input === \"symbol\"\n\n/**\n * Tests if a value is a `function`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isFunction } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isFunction(isFunction), true)\n *\n * assert.deepStrictEqual(isFunction(\"function\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isFunction: (input: unknown) => input is Function = isFunction_\n\n/**\n * Tests if a value is `undefined`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isUndefined } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isUndefined(undefined), true)\n *\n * assert.deepStrictEqual(isUndefined(null), false)\n * assert.deepStrictEqual(isUndefined(\"undefined\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isUndefined = (input: unknown): input is undefined => input === undefined\n\n/**\n * Tests if a value is not `undefined`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isNotUndefined } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNotUndefined(null), true)\n * assert.deepStrictEqual(isNotUndefined(\"undefined\"), true)\n *\n * assert.deepStrictEqual(isNotUndefined(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNotUndefined = <A>(input: A): input is Exclude<A, undefined> => input !== undefined\n\n/**\n * Tests if a value is `null`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isNull } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNull(null), true)\n *\n * assert.deepStrictEqual(isNull(undefined), false)\n * assert.deepStrictEqual(isNull(\"null\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNull = (input: unknown): input is null => input === null\n\n/**\n * Tests if a value is not `null`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isNotNull } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNotNull(undefined), true)\n * assert.deepStrictEqual(isNotNull(\"null\"), true)\n *\n * assert.deepStrictEqual(isNotNull(null), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNotNull = <A>(input: A): input is Exclude<A, null> => input !== null\n\n/**\n * A guard that always fails.\n *\n * @param _ - The value to test.\n *\n * @example\n * ```ts\n * import { isNever } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNever(null), false)\n * assert.deepStrictEqual(isNever(undefined), false)\n * assert.deepStrictEqual(isNever({}), false)\n * assert.deepStrictEqual(isNever([]), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNever: (input: unknown) => input is never = (_: unknown): _ is never => false\n\n/**\n * A guard that always succeeds.\n *\n * @param _ - The value to test.\n *\n * @example\n * ```ts\n * import { isUnknown } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isUnknown(null), true)\n * assert.deepStrictEqual(isUnknown(undefined), true)\n *\n * assert.deepStrictEqual(isUnknown({}), true)\n * assert.deepStrictEqual(isUnknown([]), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isUnknown: (input: unknown) => input is unknown = (_): _ is unknown => true\n\n/** @internal */\nexport const isRecordOrArray = (input: unknown): input is { [x: PropertyKey]: unknown } =>\n typeof input === \"object\" && input !== null\n\n/**\n * Tests if a value is an `object`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isObject } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isObject({}), true)\n * assert.deepStrictEqual(isObject([]), true)\n *\n * assert.deepStrictEqual(isObject(null), false)\n * assert.deepStrictEqual(isObject(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isObject = (input: unknown): input is object => isRecordOrArray(input) || isFunction(input)\n\n/**\n * Checks whether a value is an `object` containing a specified property key.\n *\n * @param property - The field to check within the object.\n * @param self - The value to examine.\n *\n * @category guards\n * @since 2.0.0\n */\nexport const hasProperty: {\n /**\n * Checks whether a value is an `object` containing a specified property key.\n *\n * @param property - The field to check within the object.\n * @param self - The value to examine.\n *\n * @category guards\n * @since 2.0.0\n */\n <P extends PropertyKey>(property: P): (self: unknown) => self is { [K in P]: unknown }\n /**\n * Checks whether a value is an `object` containing a specified property key.\n *\n * @param property - The field to check within the object.\n * @param self - The value to examine.\n *\n * @category guards\n * @since 2.0.0\n */\n <P extends PropertyKey>(self: unknown, property: P): self is { [K in P]: unknown }\n} = dual(\n 2,\n <P extends PropertyKey>(self: unknown, property: P): self is { [K in P]: unknown } =>\n isObject(self) && (property in self)\n)\n\n/**\n * Tests if a value is an `object` with a property `_tag` that matches the given tag.\n *\n * @param input - The value to test.\n * @param tag - The tag to test for.\n *\n * @example\n * ```ts\n * import { isTagged } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTagged(1, \"a\"), false)\n * assert.deepStrictEqual(isTagged(null, \"a\"), false)\n * assert.deepStrictEqual(isTagged({}, \"a\"), false)\n * assert.deepStrictEqual(isTagged({ a: \"a\" }, \"a\"), false)\n * assert.deepStrictEqual(isTagged({ _tag: \"a\" }, \"a\"), true)\n * assert.deepStrictEqual(isTagged(\"a\")({ _tag: \"a\" }), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isTagged: {\n /**\n * Tests if a value is an `object` with a property `_tag` that matches the given tag.\n *\n * @param input - The value to test.\n * @param tag - The tag to test for.\n *\n * @example\n * ```ts\n * import { isTagged } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTagged(1, \"a\"), false)\n * assert.deepStrictEqual(isTagged(null, \"a\"), false)\n * assert.deepStrictEqual(isTagged({}, \"a\"), false)\n * assert.deepStrictEqual(isTagged({ a: \"a\" }, \"a\"), false)\n * assert.deepStrictEqual(isTagged({ _tag: \"a\" }, \"a\"), true)\n * assert.deepStrictEqual(isTagged(\"a\")({ _tag: \"a\" }), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\n <K extends string>(tag: K): (self: unknown) => self is { _tag: K }\n /**\n * Tests if a value is an `object` with a property `_tag` that matches the given tag.\n *\n * @param input - The value to test.\n * @param tag - The tag to test for.\n *\n * @example\n * ```ts\n * import { isTagged } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTagged(1, \"a\"), false)\n * assert.deepStrictEqual(isTagged(null, \"a\"), false)\n * assert.deepStrictEqual(isTagged({}, \"a\"), false)\n * assert.deepStrictEqual(isTagged({ a: \"a\" }, \"a\"), false)\n * assert.deepStrictEqual(isTagged({ _tag: \"a\" }, \"a\"), true)\n * assert.deepStrictEqual(isTagged(\"a\")({ _tag: \"a\" }), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\n <K extends string>(self: unknown, tag: K): self is { _tag: K }\n} = dual(\n 2,\n <K extends string>(self: unknown, tag: K): self is { _tag: K } => hasProperty(self, \"_tag\") && self[\"_tag\"] === tag\n)\n\n/**\n * A guard that succeeds when the input is `null` or `undefined`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isNullable } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNullable(null), true)\n * assert.deepStrictEqual(isNullable(undefined), true)\n *\n * assert.deepStrictEqual(isNullable({}), false)\n * assert.deepStrictEqual(isNullable([]), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNullable = <A>(input: A): input is Extract<A, null | undefined> => input === null || input === undefined\n\n/**\n * A guard that succeeds when the input is not `null` or `undefined`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isNotNullable } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNotNullable({}), true)\n * assert.deepStrictEqual(isNotNullable([]), true)\n *\n * assert.deepStrictEqual(isNotNullable(null), false)\n * assert.deepStrictEqual(isNotNullable(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNotNullable = <A>(input: A): input is NonNullable<A> => input !== null && input !== undefined\n\n/**\n * A guard that succeeds when the input is an `Error`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isError } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isError(new Error()), true)\n *\n * assert.deepStrictEqual(isError(null), false)\n * assert.deepStrictEqual(isError({}), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isError = (input: unknown): input is Error => input instanceof Error\n\n/**\n * A guard that succeeds when the input is a `Uint8Array`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isUint8Array } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isUint8Array(new Uint8Array()), true)\n *\n * assert.deepStrictEqual(isUint8Array(null), false)\n * assert.deepStrictEqual(isUint8Array({}), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isUint8Array = (input: unknown): input is Uint8Array => input instanceof Uint8Array\n\n/**\n * A guard that succeeds when the input is a `Date`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isDate } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isDate(new Date()), true)\n *\n * assert.deepStrictEqual(isDate(null), false)\n * assert.deepStrictEqual(isDate({}), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isDate = (input: unknown): input is Date => input instanceof Date\n\n/**\n * A guard that succeeds when the input is an `Iterable`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isIterable } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isIterable([]), true)\n * assert.deepStrictEqual(isIterable(new Set()), true)\n *\n * assert.deepStrictEqual(isIterable(null), false)\n * assert.deepStrictEqual(isIterable({}), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isIterable = (input: unknown): input is Iterable<unknown> => hasProperty(input, Symbol.iterator)\n\n/**\n * A guard that succeeds when the input is a record.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isRecord } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isRecord({}), true)\n * assert.deepStrictEqual(isRecord({ a: 1 }), true)\n *\n * assert.deepStrictEqual(isRecord([]), false)\n * assert.deepStrictEqual(isRecord([1, 2, 3]), false)\n * assert.deepStrictEqual(isRecord(null), false)\n * assert.deepStrictEqual(isRecord(undefined), false)\n * assert.deepStrictEqual(isRecord(() => null), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isRecord = (input: unknown): input is { [x: string | symbol]: unknown } =>\n isRecordOrArray(input) && !Array.isArray(input)\n\n/**\n * A guard that succeeds when the input is a readonly record.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isReadonlyRecord } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isReadonlyRecord({}), true)\n * assert.deepStrictEqual(isReadonlyRecord({ a: 1 }), true)\n *\n * assert.deepStrictEqual(isReadonlyRecord([]), false)\n * assert.deepStrictEqual(isReadonlyRecord([1, 2, 3]), false)\n * assert.deepStrictEqual(isReadonlyRecord(null), false)\n * assert.deepStrictEqual(isReadonlyRecord(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isReadonlyRecord: (\n input: unknown\n) => input is { readonly [x: string | symbol]: unknown } = isRecord\n\n/**\n * A guard that succeeds when the input is a Promise.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isPromise } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isPromise({}), false)\n * assert.deepStrictEqual(isPromise(Promise.resolve(\"hello\")), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isPromise = (\n input: unknown\n): input is Promise<unknown> =>\n hasProperty(input, \"then\") && \"catch\" in input && isFunction(input.then) && isFunction(input.catch)\n\n/**\n * @category guards\n * @since 2.0.0\n */\nexport const isPromiseLike = (\n input: unknown\n): input is PromiseLike<unknown> => hasProperty(input, \"then\") && isFunction(input.then)\n\n/**\n * Tests if a value is a `RegExp`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * assert.deepStrictEqual(Predicate.isRegExp(/a/), true)\n * assert.deepStrictEqual(Predicate.isRegExp(\"a\"), false)\n * ```\n *\n * @category guards\n * @since 3.9.0\n */\nexport const isRegExp = (input: unknown): input is RegExp => input instanceof RegExp\n\n/**\n * @since 2.0.0\n */\nexport const compose: {\n /**\n * @since 2.0.0\n */\n <A, B extends A, C extends B>(bc: Refinement<B, C>): (ab: Refinement<A, B>) => Refinement<A, C>\n /**\n * @since 2.0.0\n */\n <A, B extends A>(bc: Predicate<NoInfer<B>>): (ab: Refinement<A, B>) => Refinement<A, B>\n /**\n * @since 2.0.0\n */\n <A, B extends A, C extends B>(ab: Refinement<A, B>, bc: Refinement<B, C>): Refinement<A, C>\n /**\n * @since 2.0.0\n */\n <A, B extends A>(ab: Refinement<A, B>, bc: Predicate<NoInfer<B>>): Refinement<A, B>\n} = dual(\n 2,\n <A, B extends A, C extends B>(ab: Refinement<A, B>, bc: Refinement<B, C>): Refinement<A, C> => (a): a is C =>\n ab(a) && bc(a)\n)\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const product =\n <A, B>(self: Predicate<A>, that: Predicate<B>): Predicate<readonly [A, B]> /* readonly because contravariant */ =>\n ([a, b]) => self(a) && that(b)\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const all = <A>(\n collection: Iterable<Predicate<A>>\n): Predicate<ReadonlyArray<A>> => {\n return (as) => {\n let collectionIndex = 0\n for (const p of collection) {\n if (collectionIndex >= as.length) {\n break\n }\n if (p(as[collectionIndex]) === false) {\n return false\n }\n collectionIndex++\n }\n return true\n }\n}\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const productMany = <A>(\n self: Predicate<A>,\n collection: Iterable<Predicate<A>>\n): Predicate<readonly [A, ...Array<A>]> /* readonly because contravariant */ => {\n const rest = all(collection)\n return ([head, ...tail]) => self(head) === false ? false : rest(tail)\n}\n\n/**\n * Similar to `Promise.all` but operates on `Predicate`s.\n *\n * ```\n * [Refinement<A, B>, Refinement<C, D>, ...] -> Refinement<[A, C, ...], [B, D, ...]>\n * [Predicate<A>, Predicate<B>, ...] -> Predicate<[A, B, ...]>\n * [Refinement<A, B>, Predicate<C>, ...] -> Refinement<[A, C, ...], [B, C, ...]>\n * ```\n *\n * @since 2.0.0\n */\nexport const tuple: {\n /**\n * Similar to `Promise.all` but operates on `Predicate`s.\n *\n * ```\n * [Refinement<A, B>, Refinement<C, D>, ...] -> Refinement<[A, C, ...], [B, D, ...]>\n * [Predicate<A>, Predicate<B>, ...] -> Predicate<[A, B, ...]>\n * [Refinement<A, B>, Predicate<C>, ...] -> Refinement<[A, C, ...], [B, C, ...]>\n * ```\n *\n * @since 2.0.0\n */\n <T extends ReadonlyArray<Predicate.Any>>(\n ...elements: T\n ): [Extract<T[number], Refinement.Any>] extends [never] ? Predicate<{ readonly [I in keyof T]: Predicate.In<T[I]> }>\n : Refinement<\n { readonly [I in keyof T]: T[I] extends Refinement.Any ? Refinement.In<T[I]> : Predicate.In<T[I]> },\n { readonly [I in keyof T]: T[I] extends Refinement.Any ? Refinement.Out<T[I]> : Predicate.In<T[I]> }\n >\n} = (...elements: ReadonlyArray<Predicate.Any>) => all(elements) as any\n\n/**\n * ```\n * { ab: Refinement<A, B>; cd: Refinement<C, D>, ... } -> Refinement<{ ab: A; cd: C; ... }, { ab: B; cd: D; ... }>\n * { a: Predicate<A, B>; b: Predicate<B>, ... } -> Predicate<{ a: A; b: B; ... }>\n * { ab: Refinement<A, B>; c: Predicate<C>, ... } -> Refinement<{ ab: A; c: C; ... }, { ab: B; c: С; ... }>\n * ```\n *\n * @since 2.0.0\n */\nexport const struct: {\n /**\n * ```\n * { ab: Refinement<A, B>; cd: Refinement<C, D>, ... } -> Refinement<{ ab: A; cd: C; ... }, { ab: B; cd: D; ... }>\n * { a: Predicate<A, B>; b: Predicate<B>, ... } -> Predicate<{ a: A; b: B; ... }>\n * { ab: Refinement<A, B>; c: Predicate<C>, ... } -> Refinement<{ ab: A; c: C; ... }, { ab: B; c: С; ... }>\n * ```\n *\n * @since 2.0.0\n */\n <R extends Record<string, Predicate.Any>>(\n fields: R\n ): [Extract<R[keyof R], Refinement.Any>] extends [never] ?\n Predicate<{ readonly [K in keyof R]: Predicate.In<R[K]> }> :\n Refinement<\n { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.In<R[K]> : Predicate.In<R[K]> },\n { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.Out<R[K]> : Predicate.In<R[K]> }\n >\n} = (<R extends Record<string, Predicate.Any>>(fields: R) => {\n const keys = Object.keys(fields)\n return (a: Record<string, unknown>) => {\n for (const key of keys) {\n if (!fields[key](a[key] as never)) {\n return false\n }\n }\n return true\n }\n}) as any\n\n/**\n * Negates the result of a given predicate.\n *\n * @param self - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const isPositive = Predicate.not(Number.lessThan(0))\n *\n * assert.deepStrictEqual(isPositive(-1), false)\n * assert.deepStrictEqual(isPositive(0), true)\n * assert.deepStrictEqual(isPositive(1), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const not = <A>(self: Predicate<A>): Predicate<A> => (a) => !self(a)\n\n/**\n * Combines two predicates into a new predicate that returns `true` if at least one of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const nonZero = Predicate.or(Number.lessThan(0), Number.greaterThan(0))\n *\n * assert.deepStrictEqual(nonZero(-1), true)\n * assert.deepStrictEqual(nonZero(0), false)\n * assert.deepStrictEqual(nonZero(1), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const or: {\n /**\n * Combines two predicates into a new predicate that returns `true` if at least one of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const nonZero = Predicate.or(Number.lessThan(0), Number.greaterThan(0))\n *\n * assert.deepStrictEqual(nonZero(-1), true)\n * assert.deepStrictEqual(nonZero(0), false)\n * assert.deepStrictEqual(nonZero(1), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A, C extends A>(that: Refinement<A, C>): <B extends A>(self: Refinement<A, B>) => Refinement<A, B | C>\n /**\n * Combines two predicates into a new predicate that returns `true` if at least one of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const nonZero = Predicate.or(Number.lessThan(0), Number.greaterThan(0))\n *\n * assert.deepStrictEqual(nonZero(-1), true)\n * assert.deepStrictEqual(nonZero(0), false)\n * assert.deepStrictEqual(nonZero(1), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A, B extends A, C extends A>(self: Refinement<A, B>, that: Refinement<A, C>): Refinement<A, B | C>\n /**\n * Combines two predicates into a new predicate that returns `true` if at least one of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const nonZero = Predicate.or(Number.lessThan(0), Number.greaterThan(0))\n *\n * assert.deepStrictEqual(nonZero(-1), true)\n * assert.deepStrictEqual(nonZero(0), false)\n * assert.deepStrictEqual(nonZero(1), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>\n /**\n * Combines two predicates into a new predicate that returns `true` if at least one of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const nonZero = Predicate.or(Number.lessThan(0), Number.greaterThan(0))\n *\n * assert.deepStrictEqual(nonZero(-1), true)\n * assert.deepStrictEqual(nonZero(0), false)\n * assert.deepStrictEqual(nonZero(1), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>\n} = dual(2, <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => self(a) || that(a))\n\n/**\n * Combines two predicates into a new predicate that returns `true` if both of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * const minLength = (n: number) => (s: string) => s.length >= n\n * const maxLength = (n: number) => (s: string) => s.length <= n\n *\n * const length = (n: number) => Predicate.and(minLength(n), maxLength(n))\n *\n * assert.deepStrictEqual(length(2)(\"aa\"), true)\n * assert.deepStrictEqual(length(2)(\"a\"), false)\n * assert.deepStrictEqual(length(2)(\"aaa\"), false)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const and: {\n /**\n * Combines two predicates into a new predicate that returns `true` if both of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * const minLength = (n: number) => (s: string) => s.length >= n\n * const maxLength = (n: number) => (s: string) => s.length <= n\n *\n * const length = (n: number) => Predicate.and(minLength(n), maxLength(n))\n *\n * assert.deepStrictEqual(length(2)(\"aa\"), true)\n * assert.deepStrictEqual(length(2)(\"a\"), false)\n * assert.deepStrictEqual(length(2)(\"aaa\"), false)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A, C extends A>(that: Refinement<A, C>): <B extends A>(self: Refinement<A, B>) => Refinement<A, B & C>\n /**\n * Combines two predicates into a new predicate that returns `true` if both of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * const minLength = (n: number) => (s: string) => s.length >= n\n * const maxLength = (n: number) => (s: string) => s.length <= n\n *\n * const length = (n: number) => Predicate.and(minLength(n), maxLength(n))\n *\n * assert.deepStrictEqual(length(2)(\"aa\"), true)\n * assert.deepStrictEqual(length(2)(\"a\"), false)\n * assert.deepStrictEqual(length(2)(\"aaa\"), false)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A, B extends A, C extends A>(self: Refinement<A, B>, that: Refinement<A, C>): Refinement<A, B & C>\n /**\n * Combines two predicates into a new predicate that returns `true` if both of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * const minLength = (n: number) => (s: string) => s.length >= n\n * const maxLength = (n: number) => (s: string) => s.length <= n\n *\n * const length = (n: number) => Predicate.and(minLength(n), maxLength(n))\n *\n * assert.deepStrictEqual(length(2)(\"aa\"), true)\n * assert.deepStrictEqual(length(2)(\"a\"), false)\n * assert.deepStrictEqual(length(2)(\"aaa\"), false)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>\n /**\n * Combines two predicates into a new predicate that returns `true` if both of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * const minLength = (n: number) => (s: string) => s.length >= n\n * const maxLength = (n: number) => (s: string) => s.length <= n\n *\n * const length = (n: number) => Predicate.and(minLength(n), maxLength(n))\n *\n * assert.deepStrictEqual(length(2)(\"aa\"), true)\n * assert.deepStrictEqual(length(2)(\"a\"), false)\n * assert.deepStrictEqual(length(2)(\"aaa\"), false)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>\n} = dual(2, <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => self(a) && that(a))\n\n/**\n * @category combinators\n * @since 2.0.0\n */\nexport const xor: {\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>\n} = dual(2, <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => self(a) !== that(a))\n\n/**\n * @category combinators\n * @since 2.0.0\n */\nexport const eqv: {\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>\n} = dual(2, <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => self(a) === that(a))\n\n/**\n * Represents the logical implication combinator for predicates. In formal\n * logic, the implication operator `->` denotes that if the first proposition\n * (antecedent) is true, then the second proposition (consequent) must also be\n * true. In simpler terms, `p implies q` can be interpreted as \"if p then q\". If\n * the first predicate holds, then the second predicate must hold\n * for the given context.\n *\n * In practical terms within TypeScript, `p implies q` is equivalent to `!p || (p && q)`.\n *\n * Note that if the antecedent is `false`, the result is `true` by default\n * because the outcome of the consequent cannot be determined.\n *\n * This function is useful in situations where you need to enforce rules or\n * constraints that are contingent on certain conditions.\n * It proves especially helpful in defining property tests.\n *\n * The example below illustrates the transitive property of order using the\n * `implies` function. In simple terms, if `a <= b` and `b <= c`, then `a <= c`\n * must be true.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * type Triple = {\n * readonly a: number\n * readonly b: number\n * readonly c: number\n * }\n *\n * const transitivity = Predicate.implies(\n * // antecedent\n * (input: Triple) => input.a <= input.b && input.b <= input.c,\n * // consequent\n * (input: Triple) => input.a <= input.c\n * )\n *\n * assert.equal(transitivity({ a: 1, b: 2, c: 3 }), true)\n * // antecedent is `false`, so the result is `true`\n * assert.equal(transitivity({ a: 1, b: 0, c: 0 }), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const implies: {\n /**\n * Represents the logical implication combinator for predicates. In formal\n * logic, the implication operator `->` denotes that if the first proposition\n * (antecedent) is true, then the second proposition (consequent) must also be\n * true. In simpler terms, `p implies q` can be interpreted as \"if p then q\". If\n * the first predicate holds, then the second predicate must hold\n * for the given context.\n *\n * In practical terms within TypeScript, `p implies q` is equivalent to `!p || (p && q)`.\n *\n * Note that if the antecedent is `false`, the result is `true` by default\n * because the outcome of the consequent cannot be determined.\n *\n * This function is useful in situations where you need to enforce rules or\n * constraints that are contingent on certain conditions.\n * It proves especially helpful in defining property tests.\n *\n * The example below illustrates the transitive property of order using the\n * `implies` function. In simple terms, if `a <= b` and `b <= c`, then `a <= c`\n * must be true.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * type Triple = {\n * readonly a: number\n * readonly b: number\n * readonly c: number\n * }\n *\n * const transitivity = Predicate.implies(\n * // antecedent\n * (input: Triple) => input.a <= input.b && input.b <= input.c,\n * // consequent\n * (input: Triple) => input.a <= input.c\n * )\n *\n * assert.equal(transitivity({ a: 1, b: 2, c: 3 }), true)\n * // antecedent is `false`, so the result is `true`\n * assert.equal(transitivity({ a: 1, b: 0, c: 0 }), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A>(consequent: Predicate<A>): (antecedent: Predicate<A>) => Predicate<A>\n /**\n * Represents the logical implication combinator for predicates. In formal\n * logic, the implication operator `->` denotes that if the first proposition\n * (antecedent) is true, then the second proposition (consequent) must also be\n * true. In simpler terms, `p implies q` can be interpreted as \"if p then q\". If\n * the first predicate holds, then the second predicate must hold\n * for the given context.\n *\n * In practical terms within TypeScript, `p implies q` is equivalent to `!p || (p && q)`.\n *\n * Note that if the antecedent is `false`, the result is `true` by default\n * because the outcome of the consequent cannot be determined.\n *\n * This function is useful in situations where you need to enforce rules or\n * constraints that are contingent on certain conditions.\n * It proves especially helpful in defining property tests.\n *\n * The example below illustrates the transitive property of order using the\n * `implies` function. In simple terms, if `a <= b` and `b <= c`, then `a <= c`\n * must be true.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * type Triple = {\n * readonly a: number\n * readonly b: number\n * readonly c: number\n * }\n *\n * const transitivity = Predicate.implies(\n * // antecedent\n * (input: Triple) => input.a <= input.b && input.b <= input.c,\n * // consequent\n * (input: Triple) => input.a <= input.c\n * )\n *\n * assert.equal(transitivity({ a: 1, b: 2, c: 3 }), true)\n * // antecedent is `false`, so the result is `true`\n * assert.equal(transitivity({ a: 1, b: 0, c: 0 }), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A>(antecedent: Predicate<A>, consequent: Predicate<A>): Predicate<A>\n} = dual(\n 2,\n <A>(antecedent: Predicate<A>, consequent: Predicate<A>): Predicate<A> => (a) => antecedent(a) ? consequent(a) : true\n)\n\n/**\n * @category combinators\n * @since 2.0.0\n */\nexport const nor: {\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>\n} = dual(\n 2,\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => !(self(a) || that(a))\n)\n\n/**\n * @category combinators\n * @since 2.0.0\n */\nexport const nand: {\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>\n} = dual(\n 2,\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => !(self(a) && that(a))\n)\n\n/**\n * @category elements\n * @since 2.0.0\n */\nexport const every = <A>(collection: Iterable<Predicate<A>>): Predicate<A> => (a: A) => {\n for (const p of collection) {\n if (!p(a)) {\n return false\n }\n }\n return true\n}\n\n/**\n * @category elements\n * @since 2.0.0\n */\nexport const some = <A>(collection: Iterable<Predicate<A>>): Predicate<A> => (a) => {\n for (const p of collection) {\n if (p(a)) {\n return true\n }\n }\n return false\n}\n","/**\n * @since 2.0.0\n */\n\n/** @internal */\nexport const getBugErrorMessage = (message: string) =>\n `BUG: ${message} - please report an issue at https://github.com/Effect-TS/effect/issues`\n","/**\n * @since 2.0.0\n */\nimport { identity } from \"./Function.js\"\nimport { globalValue } from \"./GlobalValue.js\"\nimport type { Kind, TypeLambda } from \"./HKT.js\"\nimport { getBugErrorMessage } from \"./internal/errors.js\"\nimport { isNullable, isObject } from \"./Predicate.js\"\nimport type * as Types from \"./Types.js\"\n\n/*\n * Copyright 2014 Thom Chiovoloni, released under the MIT license.\n *\n * A random number generator based on the basic implementation of the PCG algorithm,\n * as described here: http://www.pcg-random.org/\n *\n * Adapted for TypeScript from Thom's original code at https://github.com/thomcc/pcg-random\n *\n * forked from https://github.com/frptools\n *\n * @since 2.0.0\n */\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport const GenKindTypeId: unique symbol = Symbol.for(\"effect/Gen/GenKind\")\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport type GenKindTypeId = typeof GenKindTypeId\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface GenKind<F extends TypeLambda, R, O, E, A> extends Variance<F, R, O, E> {\n readonly value: Kind<F, R, O, E, A>\n\n [Symbol.iterator](): IterableIterator<GenKind<F, R, O, E, A>, A>\n}\n\n/**\n * @category predicates\n * @since 3.0.6\n */\nexport const isGenKind = (u: unknown): u is GenKind<any, any, any, any, any> => isObject(u) && GenKindTypeId in u\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport class GenKindImpl<F extends TypeLambda, R, O, E, A> implements GenKind<F, R, O, E, A> {\n constructor(\n /**\n * @since 2.0.0\n */\n readonly value: Kind<F, R, O, E, A>\n ) {}\n\n /**\n * @since 2.0.0\n */\n get _F() {\n return identity\n }\n\n /**\n * @since 2.0.0\n */\n get _R() {\n return (_: R) => _\n }\n\n /**\n * @since 2.0.0\n */\n get _O() {\n return (_: never): O => _\n }\n\n /**\n * @since 2.0.0\n */\n get _E() {\n return (_: never): E => _\n }\n\n /**\n * @since 2.0.0\n */\n readonly [GenKindTypeId]: typeof GenKindTypeId = GenKindTypeId;\n\n /**\n * @since 2.0.0\n */\n [Symbol.iterator](): IterableIterator<GenKind<F, R, O, E, A>, A> {\n return new SingleShotGen<GenKind<F, R, O, E, A>, A>(this as any)\n }\n}\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport class SingleShotGen<T, A> implements IterableIterator<T, A> {\n private called = false\n\n constructor(readonly self: T) {}\n\n /**\n * @since 2.0.0\n */\n next(a: A): IteratorResult<T, A> {\n return this.called ?\n ({\n value: a,\n done: true\n }) :\n (this.called = true,\n ({\n value: this.self,\n done: false\n }))\n }\n\n /**\n * @since 2.0.0\n */\n return(a: A): IteratorResult<T, A> {\n return ({\n value: a,\n done: true\n })\n }\n\n /**\n * @since 2.0.0\n */\n throw(e: unknown): IteratorResult<T, A> {\n throw e\n }\n\n /**\n * @since 2.0.0\n */\n [Symbol.iterator](): IterableIterator<T, A> {\n return new SingleShotGen<T, A>(this.self)\n }\n}\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const makeGenKind = <F extends TypeLambda, R, O, E, A>(\n kind: Kind<F, R, O, E, A>\n): GenKind<F, R, O, E, A> => new GenKindImpl(kind)\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Variance<in out F extends TypeLambda, in R, out O, out E> {\n readonly [GenKindTypeId]: GenKindTypeId\n readonly _F: Types.Invariant<F>\n readonly _R: Types.Contravariant<R>\n readonly _O: Types.Covariant<O>\n readonly _E: Types.Covariant<E>\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Gen<F extends TypeLambda, Z> {\n <Self, K extends Variance<F, any, any, any> | YieldWrap<Kind<F, any, any, any, any>>, A>(\n ...args:\n | [\n self: Self,\n body: (this: Self, resume: Z) => Generator<K, A, never>\n ]\n | [\n body: (resume: Z) => Generator<K, A, never>\n ]\n ): Kind<\n F,\n [K] extends [Variance<F, infer R, any, any>] ? R\n : [K] extends [YieldWrap<Kind<F, infer R, any, any, any>>] ? R\n : never,\n [K] extends [Variance<F, any, infer O, any>] ? O\n : [K] extends [YieldWrap<Kind<F, any, infer O, any, any>>] ? O\n : never,\n [K] extends [Variance<F, any, any, infer E>] ? E\n : [K] extends [YieldWrap<Kind<F, any, any, infer E, any>>] ? E\n : never,\n A\n >\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Adapter<Z extends TypeLambda> {\n <_R, _O, _E, _A>(\n self: Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, _R, _O, _E, _A>(a: A, ab: (a: A) => Kind<Z, _R, _O, _E, _A>): GenKind<Z, _R, _O, _E, _A>\n <A, B, _R, _O, _E, _A>(a: A, ab: (a: A) => B, bc: (b: B) => Kind<Z, _R, _O, _E, _A>): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: F) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (g: H) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => S,\n st: (s: S) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => S,\n st: (s: S) => T,\n tu: (s: T) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n}\n\n/**\n * @category adapters\n * @since 2.0.0\n */\nexport const adapter: <F extends TypeLambda>() => Adapter<F> = () => (function() {\n let x = arguments[0]\n for (let i = 1; i < arguments.length; i++) {\n x = arguments[i](x)\n }\n return new GenKindImpl(x) as any\n})\n\nconst defaultIncHi = 0x14057b7e\nconst defaultIncLo = 0xf767814f\nconst MUL_HI = 0x5851f42d >>> 0\nconst MUL_LO = 0x4c957f2d >>> 0\nconst BIT_53 = 9007199254740992.0\nconst BIT_27 = 134217728.0\n\n/**\n * @category model\n * @since 2.0.0\n */\nexport type PCGRandomState = [number, number, number, number]\n\n/**\n * @category model\n * @since 2.0.0\n */\nexport type OptionalNumber = number | null | undefined\n\n/**\n * PCG is a family of simple fast space-efficient statistically good algorithms\n * for random number generation. Unlike many general-purpose RNGs, they are also\n * hard to predict.\n *\n * @category model\n * @since 2.0.0\n */\nexport class PCGRandom {\n private _state!: Int32Array\n\n /**\n * Creates an instance of PCGRandom.\n *\n * @param seed - The low 32 bits of the seed (0 is used for high 32 bits).\n *\n * @memberOf PCGRandom\n */\n constructor(seed?: OptionalNumber)\n /**\n * Creates an instance of PCGRandom.\n *\n * @param seedHi - The high 32 bits of the seed.\n * @param seedLo - The low 32 bits of the seed.\n * @param inc - The low 32 bits of the incrementer (0 is used for high 32 bits).\n *\n * @memberOf PCGRandom\n */\n constructor(seedHi: OptionalNumber, seedLo: OptionalNumber, inc?: OptionalNumber)\n /**\n * Creates an instance of PCGRandom.\n *\n * @param seedHi - The high 32 bits of the seed.\n * @param seedLo - The low 32 bits of the seed.\n * @param incHi - The high 32 bits of the incrementer.\n * @param incLo - The low 32 bits of the incrementer.\n *\n * @memberOf PCGRandom\n */\n constructor(\n seedHi: OptionalNumber,\n seedLo: OptionalNumber,\n incHi: OptionalNumber,\n incLo: OptionalNumber\n )\n constructor(\n seedHi?: OptionalNumber,\n seedLo?: OptionalNumber,\n incHi?: OptionalNumber,\n incLo?: OptionalNumber\n ) {\n if (isNullable(seedLo) && isNullable(seedHi)) {\n seedLo = (Math.random() * 0xffffffff) >>> 0\n seedHi = 0\n } else if (isNullable(seedLo)) {\n seedLo = seedHi\n seedHi = 0\n }\n if (isNullable(incLo) && isNullable(incHi)) {\n incLo = this._state ? this._state[3] : defaultIncLo\n incHi = this._state ? this._state[2] : defaultIncHi\n } else if (isNullable(incLo)) {\n incLo = <number> incHi\n incHi = 0\n }\n\n this._state = new Int32Array([0, 0, (<number> incHi) >>> 0, ((incLo || 0) | 1) >>> 0])\n this._next()\n add64(\n this._state,\n this._state[0]!,\n this._state[1]!,\n (<number> seedHi) >>> 0,\n (<number> seedLo) >>> 0\n )\n this._next()\n return this\n }\n\n /**\n * Returns a copy of the internal state of this random number generator as a\n * JavaScript Array.\n *\n * @category getters\n * @since 2.0.0\n */\n getState(): PCGRandomState {\n return [this._state[0]!, this._state[1]!, this._state[2]!, this._state[3]!]\n }\n\n /**\n * Restore state previously retrieved using `getState()`.\n *\n * @since 2.0.0\n */\n setState(state: PCGRandomState) {\n this._state[0] = state[0]\n this._state[1] = state[1]\n this._state[2] = state[2]\n this._state[3] = state[3] | 1\n }\n\n /**\n * Get a uniformly distributed 32 bit integer between [0, max).\n *\n * @category getter\n * @since 2.0.0\n */\n integer(max: number) {\n return Math.round(this.number() * Number.MAX_SAFE_INTEGER) % max\n }\n\n /**\n * Get a uniformly distributed IEEE-754 double between 0.0 and 1.0, with\n * 53 bits of precision (every bit of the mantissa is randomized).\n *\n * @category getters\n * @since 2.0.0\n */\n number() {\n const hi = (this._next() & 0x03ffffff) * 1.0\n const lo = (this._next() & 0x07ffffff) * 1.0\n return (hi * BIT_27 + lo) / BIT_53\n }\n\n /** @internal */\n private _next() {\n // save current state (what we'll use for this number)\n const oldHi = this._state[0]! >>> 0\n const oldLo = this._state[1]! >>> 0\n\n // churn LCG.\n mul64(this._state, oldHi, oldLo, MUL_HI, MUL_LO)\n add64(this._state, this._state[0]!, this._state[1]!, this._state[2]!, this._state[3]!)\n\n // get least sig. 32 bits of ((oldstate >> 18) ^ oldstate) >> 27\n let xsHi = oldHi >>> 18\n let xsLo = ((oldLo >>> 18) | (oldHi << 14)) >>> 0\n xsHi = (xsHi ^ oldHi) >>> 0\n xsLo = (xsLo ^ oldLo) >>> 0\n const xorshifted = ((xsLo >>> 27) | (xsHi << 5)) >>> 0\n // rotate xorshifted right a random amount, based on the most sig. 5 bits\n // bits of the old state.\n const rot = oldHi >>> 27\n const rot2 = ((-rot >>> 0) & 31) >>> 0\n return ((xorshifted >>> rot) | (xorshifted << rot2)) >>> 0\n }\n}\n\nfunction mul64(\n out: Int32Array,\n aHi: number,\n aLo: number,\n bHi: number,\n bLo: number\n): void {\n let c1 = ((aLo >>> 16) * (bLo & 0xffff)) >>> 0\n let c0 = ((aLo & 0xffff) * (bLo >>> 16)) >>> 0\n\n let lo = ((aLo & 0xffff) * (bLo & 0xffff)) >>> 0\n let hi = ((aLo >>> 16) * (bLo >>> 16) + ((c0 >>> 16) + (c1 >>> 16))) >>> 0\n\n c0 = (c0 << 16) >>> 0\n lo = (lo + c0) >>> 0\n if ((lo >>> 0) < (c0 >>> 0)) {\n hi = (hi + 1) >>> 0\n }\n\n c1 = (c1 << 16) >>> 0\n lo = (lo + c1) >>> 0\n if ((lo >>> 0) < (c1 >>> 0)) {\n hi = (hi + 1) >>> 0\n }\n\n hi = (hi + Math.imul(aLo, bHi)) >>> 0\n hi = (hi + Math.imul(aHi, bLo)) >>> 0\n\n out[0] = hi\n out[1] = lo\n}\n\n// add two 64 bit numbers (given in parts), and store the result in `out`.\nfunction add64(\n out: Int32Array,\n aHi: number,\n aLo: number,\n bHi: number,\n bLo: number\n): void {\n let hi = (aHi + bHi) >>> 0\n const lo = (aLo + bLo) >>> 0\n if ((lo >>> 0) < (aLo >>> 0)) {\n hi = (hi + 1) | 0\n }\n out[0] = hi\n out[1] = lo\n}\n\n/**\n * @since 3.0.6\n */\nexport const YieldWrapTypeId: unique symbol = Symbol.for(\"effect/Utils/YieldWrap\")\n\n/**\n * @since 3.0.6\n */\nexport class YieldWrap<T> {\n /**\n * @since 3.0.6\n */\n readonly #value: T\n constructor(value: T) {\n this.#value = value\n }\n /**\n * @since 3.0.6\n */\n [YieldWrapTypeId](): T {\n return this.#value\n }\n}\n\n/**\n * @since 3.0.6\n */\nexport function yieldWrapGet<T>(self: YieldWrap<T>): T {\n if (typeof self === \"object\" && self !== null && YieldWrapTypeId in self) {\n return self[YieldWrapTypeId]()\n }\n throw new Error(getBugErrorMessage(\"yieldWrapGet\"))\n}\n\n/**\n * Note: this is an experimental feature made available to allow custom matchers in tests, not to be directly used yet in user code\n *\n * @since 3.1.1\n * @status experimental\n * @category modifiers\n */\nexport const structuralRegionState = globalValue(\n \"effect/Utils/isStructuralRegion\",\n (): { enabled: boolean; tester: ((a: unknown, b: unknown) => boolean) | undefined } => ({\n enabled: false,\n tester: undefined\n })\n)\n\n/**\n * Note: this is an experimental feature made available to allow custom matchers in tests, not to be directly used yet in user code\n *\n * @since 3.1.1\n * @status experimental\n * @category modifiers\n */\nexport const structuralRegion = <A>(body: () => A, tester?: (a: unknown, b: unknown) => boolean): A => {\n const current = structuralRegionState.enabled\n const currentTester = structuralRegionState.tester\n structuralRegionState.enabled = true\n if (tester) {\n structuralRegionState.tester = tester\n }\n try {\n return body()\n } finally {\n structuralRegionState.enabled = current\n structuralRegionState.tester = currentTester\n }\n}\n\nconst tracingFunction = (name: string) => {\n const wrap = {\n [name]<A>(body: () => A) {\n return body()\n }\n }\n return function<A>(fn: () => A): A {\n return wrap[name](fn)\n }\n}\n\n/**\n * @since 3.2.2\n * @status experimental\n * @category tracing\n */\nexport const internalCall = tracingFunction(\"effect_internal_function\")\n\nconst genConstructor = (function*() {}).constructor\n\n/**\n * @since 3.11.0\n */\nexport const isGeneratorFunction = (u: unknown): u is (...args: Array<any>) => Generator<any, any, any> =>\n isObject(u) && u.constructor === genConstructor\n","/**\n * @since 2.0.0\n */\nimport { pipe } from \"./Function.js\"\nimport { globalValue } from \"./GlobalValue.js\"\nimport { hasProperty } from \"./Predicate.js\"\nimport { structuralRegionState } from \"./Utils.js\"\n\n/** @internal */\nconst randomHashCache = globalValue(\n Symbol.for(\"effect/Hash/randomHashCache\"),\n () => new WeakMap<object, number>()\n)\n\n/**\n * @since 2.0.0\n * @category symbols\n */\nexport const symbol: unique symbol = Symbol.for(\"effect/Hash\")\n\n/**\n * @since 2.0.0\n * @category models\n */\nexport interface Hash {\n [symbol](): number\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const hash: <A>(self: A) => number = <A>(self: A) => {\n if (structuralRegionState.enabled === true) {\n return 0\n }\n\n switch (typeof self) {\n case \"number\":\n return number(self)\n case \"bigint\":\n return string(self.toString(10))\n case \"boolean\":\n return string(String(self))\n case \"symbol\":\n return string(String(self))\n case \"string\":\n return string(self)\n case \"undefined\":\n return string(\"undefined\")\n case \"function\":\n case \"object\": {\n if (self === null) {\n return string(\"null\")\n } else if (self instanceof Date) {\n return hash(self.toISOString())\n } else if (isHash(self)) {\n return self[symbol]()\n } else {\n return random(self)\n }\n }\n default:\n throw new Error(\n `BUG: unhandled typeof ${typeof self} - please report an issue at https://github.com/Effect-TS/effect/issues`\n )\n }\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const random: <A extends object>(self: A) => number = (self) => {\n if (!randomHashCache.has(self)) {\n randomHashCache.set(self, number(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)))\n }\n return randomHashCache.get(self)!\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const combine: (b: number) => (self: number) => number = (b) => (self) => (self * 53) ^ b\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const optimize = (n: number): number => (n & 0xbfffffff) | ((n >>> 1) & 0x40000000)\n\n/**\n * @since 2.0.0\n * @category guards\n */\nexport const isHash = (u: unknown): u is Hash => hasProperty(u, symbol)\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const number = (n: number) => {\n if (n !== n || n === Infinity) {\n return 0\n }\n let h = n | 0\n if (h !== n) {\n h ^= n * 0xffffffff\n }\n while (n > 0xffffffff) {\n h ^= n /= 0xffffffff\n }\n return optimize(h)\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const string = (str: string) => {\n let h = 5381, i = str.length\n while (i) {\n h = (h * 33) ^ str.charCodeAt(--i)\n }\n return optimize(h)\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const structureKeys = <A extends object>(o: A, keys: ReadonlyArray<keyof A>) => {\n let h = 12289\n for (let i = 0; i < keys.length; i++) {\n h ^= pipe(string(keys[i]! as string), combine(hash((o as any)[keys[i]!])))\n }\n return optimize(h)\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const structure = <A extends object>(o: A) =>\n structureKeys(o, Object.keys(o) as unknown as ReadonlyArray<keyof A>)\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const array = <A>(arr: ReadonlyArray<A>) => {\n let h = 6151\n for (let i = 0; i < arr.length; i++) {\n h = pipe(h, combine(hash(arr[i])))\n }\n return optimize(h)\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const cached: {\n /**\n * @since 2.0.0\n * @category hashing\n */\n (self: object): (hash: number) => number\n /**\n * @since 2.0.0\n * @category hashing\n */\n (self: object, hash: number): number\n} = function() {\n if (arguments.length === 1) {\n const self = arguments[0] as object\n return function(hash: number) {\n Object.defineProperty(self, symbol, {\n value() {\n return hash\n },\n enumerable: false\n })\n return hash\n } as any\n }\n const self = arguments[0] as object\n const hash = arguments[1] as number\n Object.defineProperty(self, symbol, {\n value() {\n return hash\n },\n enumerable: false\n })\n\n return hash\n}\n","/**\n * @since 2.0.0\n */\nimport type { Equivalence } from \"./Equivalence.js\"\nimport * as Hash from \"./Hash.js\"\nimport { hasProperty } from \"./Predicate.js\"\nimport { structuralRegionState } from \"./Utils.js\"\n\n/**\n * @since 2.0.0\n * @category symbols\n */\nexport const symbol: unique symbol = Symbol.for(\"effect/Equal\")\n\n/**\n * @since 2.0.0\n * @category models\n */\nexport interface Equal extends Hash.Hash {\n [symbol](that: Equal): boolean\n}\n\n/**\n * @since 2.0.0\n * @category equality\n */\nexport function equals<B>(that: B): <A>(self: A) => boolean\nexport function equals<A, B>(self: A, that: B): boolean\nexport function equals(): any {\n if (arguments.length === 1) {\n return (self: unknown) => compareBoth(self, arguments[0])\n }\n return compareBoth(arguments[0], arguments[1])\n}\n\nfunction compareBoth(self: unknown, that: unknown): boolean {\n if (self === that) {\n return true\n }\n const selfType = typeof self\n if (selfType !== typeof that) {\n return false\n }\n if (selfType === \"object\" || selfType === \"function\") {\n if (self !== null && that !== null) {\n if (isEqual(self) && isEqual(that)) {\n if (Hash.hash(self) === Hash.hash(that) && self[symbol](that)) {\n return true\n } else {\n return structuralRegionState.enabled && structuralRegionState.tester\n ? structuralRegionState.tester(self, that)\n : false\n }\n } else if (self instanceof Date && that instanceof Date) {\n return self.toISOString() === that.toISOString()\n }\n }\n if (structuralRegionState.enabled) {\n if (Array.isArray(self) && Array.isArray(that)) {\n return self.length === that.length && self.every((v, i) => compareBoth(v, that[i]))\n }\n if (Object.getPrototypeOf(self) === Object.prototype && Object.getPrototypeOf(self) === Object.prototype) {\n const keysSelf = Object.keys(self as any)\n const keysThat = Object.keys(that as any)\n if (keysSelf.length === keysThat.length) {\n for (const key of keysSelf) {\n // @ts-expect-error\n if (!(key in that && compareBoth(self[key], that[key]))) {\n return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false\n }\n }\n return true\n }\n }\n return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false\n }\n }\n\n return structuralRegionState.enabled && structuralRegionState.tester\n ? structuralRegionState.tester(self, that)\n : false\n}\n\n/**\n * @since 2.0.0\n * @category guards\n */\nexport const isEqual = (u: unknown): u is Equal => hasProperty(u, symbol)\n\n/**\n * @since 2.0.0\n * @category instances\n */\nexport const equivalence: <A>() => Equivalence<A> = () => equals\n","/**\n * @since 2.0.0\n */\nimport type * as FiberRefs from \"./FiberRefs.js\"\nimport { globalValue } from \"./GlobalValue.js\"\nimport { hasProperty, isFunction } from \"./Predicate.js\"\n\n/**\n * @since 2.0.0\n * @category symbols\n */\nexport const NodeInspectSymbol = Symbol.for(\"nodejs.util.inspect.custom\")\n\n/**\n * @since 2.0.0\n * @category symbols\n */\nexport type NodeInspectSymbol = typeof NodeInspectSymbol\n\n/**\n * @since 2.0.0\n * @category models\n */\nexport interface Inspectable {\n toString(): string\n toJSON(): unknown\n [NodeInspectSymbol](): unknown\n}\n\n/**\n * @since 2.0.0\n */\nexport const toJSON = (x: unknown): unknown => {\n try {\n if (\n hasProperty(x, \"toJSON\") && isFunction(x[\"toJSON\"]) &&\n x[\"toJSON\"].length === 0\n ) {\n return x.toJSON()\n } else if (Array.isArray(x)) {\n return x.map(toJSON)\n }\n } catch (_) {\n return {}\n }\n return redact(x)\n}\n\n/**\n * @since 2.0.0\n */\nexport const format = (x: unknown): string => JSON.stringify(x, null, 2)\n\n/**\n * @since 2.0.0\n */\nexport const BaseProto: Inspectable = {\n toJSON() {\n return toJSON(this)\n },\n [NodeInspectSymbol]() {\n return this.toJSON()\n },\n toString() {\n return format(this.toJSON())\n }\n}\n\n/**\n * @since 2.0.0\n */\nexport abstract class Class {\n /**\n * @since 2.0.0\n */\n abstract toJSON(): unknown\n /**\n * @since 2.0.0\n */\n [NodeInspectSymbol]() {\n return this.toJSON()\n }\n /**\n * @since 2.0.0\n */\n toString() {\n return format(this.toJSON())\n }\n}\n\n/**\n * @since 2.0.0\n */\nexport const toStringUnknown = (u: unknown, whitespace: number | string | undefined = 2): string => {\n if (typeof u === \"string\") {\n return u\n }\n try {\n return typeof u === \"object\" ? stringifyCircular(u, whitespace) : String(u)\n } catch (_) {\n return String(u)\n }\n}\n\n/**\n * @since 2.0.0\n */\nexport const stringifyCircular = (obj: unknown, whitespace?: number | string | undefined): string => {\n let cache: Array<unknown> = []\n const retVal = JSON.stringify(\n obj,\n (_key, value) =>\n typeof value === \"object\" && value !== null\n ? cache.includes(value)\n ? undefined // circular reference\n : cache.push(value) && (redactableState.fiberRefs !== undefined && isRedactable(value)\n ? value[symbolRedactable](redactableState.fiberRefs)\n : value)\n : value,\n whitespace\n )\n ;(cache as any) = undefined\n return retVal\n}\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport interface Redactable {\n readonly [symbolRedactable]: (fiberRefs: FiberRefs.FiberRefs) => unknown\n}\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport const symbolRedactable: unique symbol = Symbol.for(\"effect/Inspectable/Redactable\")\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport const isRedactable = (u: unknown): u is Redactable =>\n typeof u === \"object\" && u !== null && symbolRedactable in u\n\nconst redactableState = globalValue(\"effect/Inspectable/redactableState\", () => ({\n fiberRefs: undefined as FiberRefs.FiberRefs | undefined\n}))\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport const withRedactableContext = <A>(context: FiberRefs.FiberRefs, f: () => A): A => {\n const prev = redactableState.fiberRefs\n redactableState.fiberRefs = context\n try {\n return f()\n } finally {\n redactableState.fiberRefs = prev\n }\n}\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport const redact = (u: unknown): unknown => {\n if (isRedactable(u) && redactableState.fiberRefs !== undefined) {\n return u[symbolRedactable](redactableState.fiberRefs)\n }\n return u\n}\n","/**\n * @since 2.0.0\n */\n\n/**\n * @since 2.0.0\n * @category models\n */\nexport interface Pipeable {\n pipe<A>(this: A): A\n pipe<A, B = never>(this: A, ab: (_: A) => B): B\n pipe<A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C\n pipe<A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D\n pipe<A, B = never, C = never, D = never, E = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E\n ): E\n pipe<A, B = never, C = never, D = never, E = never, F = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F\n ): F\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G\n ): G\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H\n ): H\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I\n ): I\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J\n ): J\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K\n ): K\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L\n ): L\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M\n ): M\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N\n ): N\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O\n ): O\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P\n ): P\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q\n ): Q\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R\n ): R\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R,\n rs: (_: R) => S\n ): S\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never,\n T = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R,\n rs: (_: R) => S,\n st: (_: S) => T\n ): T\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never,\n T = never,\n U = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R,\n rs: (_: R) => S,\n st: (_: S) => T,\n tu: (_: T) => U\n ): U\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never,\n T = never,\n U = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R,\n rs: (_: R) => S,\n st: (_: S) => T,\n tu: (_: T) => U\n ): U\n}\n\n/**\n * @since 2.0.0\n */\nexport const pipeArguments = <A>(self: A, args: IArguments): unknown => {\n switch (args.length) {\n case 0:\n return self\n case 1:\n return args[0](self)\n case 2:\n return args[1](args[0](self))\n case 3:\n return args[2](args[1](args[0](self)))\n case 4:\n return args[3](args[2](args[1](args[0](self))))\n case 5:\n return args[4](args[3](args[2](args[1](args[0](self)))))\n case 6:\n return args[5](args[4](args[3](args[2](args[1](args[0](self))))))\n case 7:\n return args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))))\n case 8:\n return args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self))))))))\n case 9:\n return args[8](args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))))))\n default: {\n let ret = self\n for (let i = 0, len = args.length; i < len; i++) {\n ret = args[i](ret)\n }\n return ret\n }\n }\n}\n","/** @internal */\nexport type OP_ASYNC = typeof OP_ASYNC\n\n/** @internal */\nexport const OP_ASYNC = \"Async\" as const\n\n/** @internal */\nexport type OP_COMMIT = typeof OP_COMMIT\n\n/** @internal */\nexport const OP_COMMIT = \"Commit\" as const\n\n/** @internal */\nexport type OP_FAILURE = typeof OP_FAILURE\n\n/** @internal */\nexport const OP_FAILURE = \"Failure\" as const\n\n/** @internal */\nexport type OP_ON_FAILURE = typeof OP_ON_FAILURE\n\n/** @internal */\nexport const OP_ON_FAILURE = \"OnFailure\" as const\n\n/** @internal */\nexport type OP_ON_SUCCESS = typeof OP_ON_SUCCESS\n\n/** @internal */\nexport const OP_ON_SUCCESS = \"OnSuccess\" as const\n\n/** @internal */\nexport type OP_ON_SUCCESS_AND_FAILURE = typeof OP_ON_SUCCESS_AND_FAILURE\n\n/** @internal */\nexport const OP_ON_SUCCESS_AND_FAILURE = \"OnSuccessAndFailure\" as const\n\n/** @internal */\nexport type OP_SUCCESS = typeof OP_SUCCESS\n\n/** @internal */\nexport const OP_SUCCESS = \"Success\" as const\n\n/** @internal */\nexport type OP_SYNC = typeof OP_SYNC\n\n/** @internal */\nexport const OP_SYNC = \"Sync\" as const\n\n/** @internal */\nexport const OP_TAG = \"Tag\" as const\n\n/** @internal */\nexport type OP_TAG = typeof OP_TAG\n\n/** @internal */\nexport type OP_UPDATE_RUNTIME_FLAGS = typeof OP_UPDATE_RUNTIME_FLAGS\n\n/** @internal */\nexport const OP_UPDATE_RUNTIME_FLAGS = \"UpdateRuntimeFlags\" as const\n\n/** @internal */\nexport type OP_WHILE = typeof OP_WHILE\n\n/** @internal */\nexport const OP_WHILE = \"While\" as const\n\n/** @internal */\nexport type OP_ITERATOR = typeof OP_ITERATOR\n\n/** @internal */\nexport const OP_ITERATOR = \"Iterator\" as const\n\n/** @internal */\nexport type OP_WITH_RUNTIME = typeof OP_WITH_RUNTIME\n\n/** @internal */\nexport const OP_WITH_RUNTIME = \"WithRuntime\" as const\n\n/** @internal */\nexport type OP_YIELD = typeof OP_YIELD\n\n/** @internal */\nexport const OP_YIELD = \"Yield\" as const\n\n/** @internal */\nexport type OP_REVERT_FLAGS = typeof OP_REVERT_FLAGS\n\n/** @internal */\nexport const OP_REVERT_FLAGS = \"RevertFlags\" as const\n","import type * as Channel from \"../Channel.js\"\nimport type * as Effect from \"../Effect.js\"\nimport type * as Effectable from \"../Effectable.js\"\nimport * as Equal from \"../Equal.js\"\nimport * as Hash from \"../Hash.js\"\nimport { pipeArguments } from \"../Pipeable.js\"\nimport type * as Sink from \"../Sink.js\"\nimport type * as Stream from \"../Stream.js\"\nimport { SingleShotGen, YieldWrap } from \"../Utils.js\"\nimport * as OpCodes from \"./opCodes/effect.js\"\nimport * as version from \"./version.js\"\n\n/** @internal */\nexport const EffectTypeId: Effect.EffectTypeId = Symbol.for(\"effect/Effect\") as Effect.EffectTypeId\n\n/** @internal */\nexport const StreamTypeId: Stream.StreamTypeId = Symbol.for(\"effect/Stream\") as Stream.StreamTypeId\n\n/** @internal */\nexport const SinkTypeId: Sink.SinkTypeId = Symbol.for(\"effect/Sink\") as Sink.SinkTypeId\n\n/** @internal */\nexport const ChannelTypeId: Channel.ChannelTypeId = Symbol.for(\"effect/Channel\") as Channel.ChannelTypeId\n\n/** @internal */\nexport const effectVariance = {\n /* c8 ignore next */\n _R: (_: never) => _,\n /* c8 ignore next */\n _E: (_: never) => _,\n /* c8 ignore next */\n _A: (_: never) => _,\n\n _V: version.getCurrentVersion()\n}\n\nconst sinkVariance = {\n /* c8 ignore next */\n _A: (_: never) => _,\n /* c8 ignore next */\n _In: (_: unknown) => _,\n /* c8 ignore next */\n _L: (_: never) => _,\n /* c8 ignore next */\n _E: (_: never) => _,\n /* c8 ignore next */\n _R: (_: never) => _\n}\n\nconst channelVariance = {\n /* c8 ignore next */\n _Env: (_: never) => _,\n /* c8 ignore next */\n _InErr: (_: unknown) => _,\n /* c8 ignore next */\n _InElem: (_: unknown) => _,\n /* c8 ignore next */\n _InDone: (_: unknown) => _,\n /* c8 ignore next */\n _OutErr: (_: never) => _,\n /* c8 ignore next */\n _OutElem: (_: never) => _,\n /* c8 ignore next */\n _OutDone: (_: never) => _\n}\n\n/** @internal */\nexport const EffectPrototype: Effect.Effect<never> & Equal.Equal = {\n [EffectTypeId]: effectVariance,\n [StreamTypeId]: effectVariance,\n [SinkTypeId]: sinkVariance,\n [ChannelTypeId]: channelVariance,\n [Equal.symbol](that: any) {\n return this === that\n },\n [Hash.symbol]() {\n return Hash.cached(this, Hash.random(this))\n },\n [Symbol.iterator]() {\n return new SingleShotGen(new YieldWrap(this)) as any\n },\n pipe() {\n return pipeArguments(this, arguments)\n }\n}\n\n/** @internal */\nexport const StructuralPrototype: Equal.Equal = {\n [Hash.symbol]() {\n return Hash.cached(this, Hash.structure(this))\n },\n [Equal.symbol](this: Equal.Equal, that: Equal.Equal) {\n const selfKeys = Object.keys(this)\n const thatKeys = Object.keys(that as object)\n if (selfKeys.length !== thatKeys.length) {\n return false\n }\n for (const key of selfKeys) {\n if (!(key in (that as object) && Equal.equals((this as any)[key], (that as any)[key]))) {\n return false\n }\n }\n return true\n }\n}\n\n/** @internal */\nexport const CommitPrototype: Effect.Effect<never> = {\n ...EffectPrototype,\n _op: OpCodes.OP_COMMIT\n} as any\n\n/** @internal */\nexport const StructuralCommitPrototype: Effect.Effect<never> = {\n ...CommitPrototype,\n ...StructuralPrototype\n} as any\n\n/** @internal */\nexport const Base: Effectable.CommitPrimitive = (function() {\n function Base() {}\n Base.prototype = CommitPrototype\n return Base as any\n})()\n\n/** @internal */\nexport const StructuralBase: Effectable.CommitPrimitive = (function() {\n function Base() {}\n Base.prototype = StructuralCommitPrototype\n return Base as any\n})()\n","/**\n * @since 2.0.0\n */\n\nimport * as Equal from \"../Equal.js\"\nimport * as Hash from \"../Hash.js\"\nimport { format, NodeInspectSymbol, toJSON } from \"../Inspectable.js\"\nimport type * as Option from \"../Option.js\"\nimport { hasProperty } from \"../Predicate.js\"\nimport { EffectPrototype } from \"./effectable.js\"\n\nconst TypeId: Option.TypeId = Symbol.for(\"effect/Option\") as Option.TypeId\n\nconst CommonProto = {\n ...EffectPrototype,\n [TypeId]: {\n _A: (_: never) => _\n },\n [NodeInspectSymbol]<A>(this: Option.Option<A>) {\n return this.toJSON()\n },\n toString<A>(this: Option.Option<A>) {\n return format(this.toJSON())\n }\n}\n\nconst SomeProto = Object.assign(Object.create(CommonProto), {\n _tag: \"Some\",\n _op: \"Some\",\n [Equal.symbol]<A>(this: Option.Some<A>, that: unknown): boolean {\n return isOption(that) && isSome(that) && Equal.equals(this.value, that.value)\n },\n [Hash.symbol]<A>(this: Option.Some<A>) {\n return Hash.cached(this, Hash.combine(Hash.hash(this._tag))(Hash.hash(this.value)))\n },\n toJSON<A>(this: Option.Some<A>) {\n return {\n _id: \"Option\",\n _tag: this._tag,\n value: toJSON(this.value)\n }\n }\n})\n\nconst NoneHash = Hash.hash(\"None\")\nconst NoneProto = Object.assign(Object.create(CommonProto), {\n _tag: \"None\",\n _op: \"None\",\n [Equal.symbol]<A>(this: Option.None<A>, that: unknown): boolean {\n return isOption(that) && isNone(that)\n },\n [Hash.symbol]<A>(this: Option.None<A>) {\n return NoneHash\n },\n toJSON<A>(this: Option.None<A>) {\n return {\n _id: \"Option\",\n _tag: this._tag\n }\n }\n})\n\n/** @internal */\nexport const isOption = (input: unknown): input is Option.Option<unknown> => hasProperty(input, TypeId)\n\n/** @internal */\nexport const isNone = <A>(fa: Option.Option<A>): fa is Option.None<A> => fa._tag === \"None\"\n\n/** @internal */\nexport const isSome = <A>(fa: Option.Option<A>): fa is Option.Some<A> => fa._tag === \"Some\"\n\n/** @internal */\nexport const none: Option.Option<never> = Object.create(NoneProto)\n\n/** @internal */\nexport const some = <A>(value: A): Option.Option<A> => {\n const a = Object.create(SomeProto)\n a.value = value\n return a\n}\n","/**\n * @since 2.0.0\n */\n\nimport type * as Either from \"../Either.js\"\nimport * as Equal from \"../Equal.js\"\nimport { dual } from \"../Function.js\"\nimport * as Hash from \"../Hash.js\"\nimport { format, NodeInspectSymbol, toJSON } from \"../Inspectable.js\"\nimport type { Option } from \"../Option.js\"\nimport { hasProperty } from \"../Predicate.js\"\nimport { EffectPrototype } from \"./effectable.js\"\nimport * as option from \"./option.js\"\n\n/**\n * @internal\n */\nexport const TypeId: Either.TypeId = Symbol.for(\"effect/Either\") as Either.TypeId\n\nconst CommonProto = {\n ...EffectPrototype,\n [TypeId]: {\n _R: (_: never) => _\n },\n [NodeInspectSymbol]<L, R>(this: Either.Either<R, L>) {\n return this.toJSON()\n },\n toString<L, R>(this: Either.Left<L, R>) {\n return format(this.toJSON())\n }\n}\n\nconst RightProto = Object.assign(Object.create(CommonProto), {\n _tag: \"Right\",\n _op: \"Right\",\n [Equal.symbol]<L, R>(this: Either.Right<L, R>, that: unknown): boolean {\n return isEither(that) && isRight(that) && Equal.equals(this.right, that.right)\n },\n [Hash.symbol]<L, R>(this: Either.Right<L, R>) {\n return Hash.combine(Hash.hash(this._tag))(Hash.hash(this.right))\n },\n toJSON<L, R>(this: Either.Right<L, R>) {\n return {\n _id: \"Either\",\n _tag: this._tag,\n right: toJSON(this.right)\n }\n }\n})\n\nconst LeftProto = Object.assign(Object.create(CommonProto), {\n _tag: \"Left\",\n _op: \"Left\",\n [Equal.symbol]<L, R>(this: Either.Left<L, R>, that: unknown): boolean {\n return isEither(that) && isLeft(that) && Equal.equals(this.left, that.left)\n },\n [Hash.symbol]<L, R>(this: Either.Left<L, R>) {\n return Hash.combine(Hash.hash(this._tag))(Hash.hash(this.left))\n },\n toJSON<E, A>(this: Either.Left<E, A>) {\n return {\n _id: \"Either\",\n _tag: this._tag,\n left: toJSON(this.left)\n }\n }\n})\n\n/** @internal */\nexport const isEither = (input: unknown): input is Either.Either<unknown, unknown> => hasProperty(input, TypeId)\n\n/** @internal */\nexport const isLeft = <R, L>(ma: Either.Either<R, L>): ma is Either.Left<L, R> => ma._tag === \"Left\"\n\n/** @internal */\nexport const isRight = <R, L>(ma: Either.Either<R, L>): ma is Either.Right<L, R> => ma._tag === \"Right\"\n\n/** @internal */\nexport const left = <L>(left: L): Either.Either<never, L> => {\n const a = Object.create(LeftProto)\n a.left = left\n return a\n}\n\n/** @internal */\nexport const right = <R>(right: R): Either.Either<R> => {\n const a = Object.create(RightProto)\n a.right = right\n return a\n}\n\n/** @internal */\nexport const getLeft = <R, L>(\n self: Either.Either<R, L>\n): Option<L> => (isRight(self) ? option.none : option.some(self.left))\n\n/** @internal */\nexport const getRight = <R, L>(\n self: Either.Either<R, L>\n): Option<R> => (isLeft(self) ? option.none : option.some(self.right))\n\n/** @internal */\nexport const fromOption: {\n <L>(onNone: () => L): <R>(self: Option<R>) => Either.Either<R, L>\n <R, L>(self: Option<R>, onNone: () => L): Either.Either<R, L>\n} = dual(\n 2,\n <R, L>(self: Option<R>, onNone: () => L): Either.Either<R, L> =>\n option.isNone(self) ? left(onNone()) : right(self.value)\n)\n","/**\n * @since 2.0.0\n */\n\nimport type { NonEmptyArray } from \"../Array.js\"\n\n/** @internal */\nexport const isNonEmptyArray = <A>(self: ReadonlyArray<A>): self is NonEmptyArray<A> => self.length > 0\n","/**\n * This module provides an implementation of the `Order` type class which is used to define a total ordering on some type `A`.\n * An order is defined by a relation `<=`, which obeys the following laws:\n *\n * - either `x <= y` or `y <= x` (totality)\n * - if `x <= y` and `y <= x`, then `x == y` (antisymmetry)\n * - if `x <= y` and `y <= z`, then `x <= z` (transitivity)\n *\n * The truth table for compare is defined as follows:\n *\n * | `x <= y` | `x >= y` | Ordering | |\n * | -------- | -------- | -------- | --------------------- |\n * | `true` | `true` | `0` | corresponds to x == y |\n * | `true` | `false` | `< 0` | corresponds to x < y |\n * | `false` | `true` | `> 0` | corresponds to x > y |\n *\n * @since 2.0.0\n */\nimport { dual } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\n\n/**\n * @category type class\n * @since 2.0.0\n */\nexport interface Order<in A> {\n (self: A, that: A): -1 | 0 | 1\n}\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface OrderTypeLambda extends TypeLambda {\n readonly type: Order<this[\"Target\"]>\n}\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const make = <A>(\n compare: (self: A, that: A) => -1 | 0 | 1\n): Order<A> =>\n(self, that) => self === that ? 0 : compare(self, that)\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const string: Order<string> = make((self, that) => self < that ? -1 : 1)\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const number: Order<number> = make((self, that) => self < that ? -1 : 1)\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const boolean: Order<boolean> = make((self, that) => self < that ? -1 : 1)\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const bigint: Order<bigint> = make((self, that) => self < that ? -1 : 1)\n\n/**\n * @since 2.0.0\n */\nexport const reverse = <A>(O: Order<A>): Order<A> => make((self, that) => O(that, self))\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const combine: {\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(that: Order<A>): (self: Order<A>) => Order<A>\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(self: Order<A>, that: Order<A>): Order<A>\n} = dual(2, <A>(self: Order<A>, that: Order<A>): Order<A> =>\n make((a1, a2) => {\n const out = self(a1, a2)\n if (out !== 0) {\n return out\n }\n return that(a1, a2)\n }))\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const combineMany: {\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(collection: Iterable<Order<A>>): (self: Order<A>) => Order<A>\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(self: Order<A>, collection: Iterable<Order<A>>): Order<A>\n} = dual(2, <A>(self: Order<A>, collection: Iterable<Order<A>>): Order<A> =>\n make((a1, a2) => {\n let out = self(a1, a2)\n if (out !== 0) {\n return out\n }\n for (const O of collection) {\n out = O(a1, a2)\n if (out !== 0) {\n return out\n }\n }\n return out\n }))\n\n/**\n * @since 2.0.0\n */\nexport const empty = <A>(): Order<A> => make(() => 0)\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const combineAll = <A>(collection: Iterable<Order<A>>): Order<A> => combineMany(empty(), collection)\n\n/**\n * @category mapping\n * @since 2.0.0\n */\nexport const mapInput: {\n /**\n * @category mapping\n * @since 2.0.0\n */\n <B, A>(f: (b: B) => A): (self: Order<A>) => Order<B>\n /**\n * @category mapping\n * @since 2.0.0\n */\n <A, B>(self: Order<A>, f: (b: B) => A): Order<B>\n} = dual(\n 2,\n <A, B>(self: Order<A>, f: (b: B) => A): Order<B> => make((b1, b2) => self(f(b1), f(b2)))\n)\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const Date: Order<Date> = mapInput(number, (date) => date.getTime())\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const product: {\n <B>(that: Order<B>): <A>(self: Order<A>) => Order<readonly [A, B]> // readonly because invariant\n <A, B>(self: Order<A>, that: Order<B>): Order<readonly [A, B]> // readonly because invariant\n} = dual(2, <A, B>(self: Order<A>, that: Order<B>): Order<readonly [A, B]> =>\n make(([xa, xb], [ya, yb]) => {\n const o = self(xa, ya)\n return o !== 0 ? o : that(xb, yb)\n }))\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const all = <A>(collection: Iterable<Order<A>>): Order<ReadonlyArray<A>> => {\n return make((x, y) => {\n const len = Math.min(x.length, y.length)\n let collectionLength = 0\n for (const O of collection) {\n if (collectionLength >= len) {\n break\n }\n const o = O(x[collectionLength], y[collectionLength])\n if (o !== 0) {\n return o\n }\n collectionLength++\n }\n return 0\n })\n}\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const productMany: {\n <A>(collection: Iterable<Order<A>>): (self: Order<A>) => Order<readonly [A, ...Array<A>]> // readonly because invariant\n <A>(self: Order<A>, collection: Iterable<Order<A>>): Order<readonly [A, ...Array<A>]> // readonly because invariant\n} = dual(2, <A>(self: Order<A>, collection: Iterable<Order<A>>): Order<readonly [A, ...Array<A>]> => {\n const O = all(collection)\n return make((x, y) => {\n const o = self(x[0], y[0])\n return o !== 0 ? o : O(x.slice(1), y.slice(1))\n })\n})\n\n/**\n * Similar to `Promise.all` but operates on `Order`s.\n *\n * ```\n * [Order<A>, Order<B>, ...] -> Order<[A, B, ...]>\n * ```\n *\n * This function creates and returns a new `Order` for a tuple of values based on the given `Order`s for each element in the tuple.\n * The returned `Order` compares two tuples of the same type by applying the corresponding `Order` to each element in the tuple.\n * It is useful when you need to compare two tuples of the same type and you have a specific way of comparing each element\n * of the tuple.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const tuple = <T extends ReadonlyArray<Order<any>>>(\n ...elements: T\n): Order<Readonly<{ [I in keyof T]: [T[I]] extends [Order<infer A>] ? A : never }>> => all(elements) as any\n\n/**\n * This function creates and returns a new `Order` for an array of values based on a given `Order` for the elements of the array.\n * The returned `Order` compares two arrays by applying the given `Order` to each element in the arrays.\n * If all elements are equal, the arrays are then compared based on their length.\n * It is useful when you need to compare two arrays of the same type and you have a specific way of comparing each element of the array.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const array = <A>(O: Order<A>): Order<ReadonlyArray<A>> =>\n make((self, that) => {\n const aLen = self.length\n const bLen = that.length\n const len = Math.min(aLen, bLen)\n for (let i = 0; i < len; i++) {\n const o = O(self[i], that[i])\n if (o !== 0) {\n return o\n }\n }\n return number(aLen, bLen)\n })\n\n/**\n * This function creates and returns a new `Order` for a struct of values based on the given `Order`s\n * for each property in the struct.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const struct = <R extends { readonly [x: string]: Order<any> }>(\n fields: R\n): Order<{ [K in keyof R]: [R[K]] extends [Order<infer A>] ? A : never }> => {\n const keys = Object.keys(fields)\n return make((self, that) => {\n for (const key of keys) {\n const o = fields[key](self[key], that[key])\n if (o !== 0) {\n return o\n }\n }\n return 0\n })\n}\n\n/**\n * Test whether one value is _strictly less than_ another.\n *\n * @since 2.0.0\n */\nexport const lessThan = <A>(O: Order<A>): {\n (that: A): (self: A) => boolean\n (self: A, that: A): boolean\n} => dual(2, (self: A, that: A) => O(self, that) === -1)\n\n/**\n * Test whether one value is _strictly greater than_ another.\n *\n * @since 2.0.0\n */\nexport const greaterThan = <A>(O: Order<A>): {\n (that: A): (self: A) => boolean\n (self: A, that: A): boolean\n} => dual(2, (self: A, that: A) => O(self, that) === 1)\n\n/**\n * Test whether one value is _non-strictly less than_ another.\n *\n * @since 2.0.0\n */\nexport const lessThanOrEqualTo = <A>(O: Order<A>): {\n (that: A): (self: A) => boolean\n (self: A, that: A): boolean\n} => dual(2, (self: A, that: A) => O(self, that) !== 1)\n\n/**\n * Test whether one value is _non-strictly greater than_ another.\n *\n * @since 2.0.0\n */\nexport const greaterThanOrEqualTo = <A>(O: Order<A>): {\n (that: A): (self: A) => boolean\n (self: A, that: A): boolean\n} => dual(2, (self: A, that: A) => O(self, that) !== -1)\n\n/**\n * Take the minimum of two values. If they are considered equal, the first argument is chosen.\n *\n * @since 2.0.0\n */\nexport const min = <A>(O: Order<A>): {\n (that: A): (self: A) => A\n (self: A, that: A): A\n} => dual(2, (self: A, that: A) => self === that || O(self, that) < 1 ? self : that)\n\n/**\n * Take the maximum of two values. If they are considered equal, the first argument is chosen.\n *\n * @since 2.0.0\n */\nexport const max = <A>(O: Order<A>): {\n (that: A): (self: A) => A\n (self: A, that: A): A\n} => dual(2, (self: A, that: A) => self === that || O(self, that) > -1 ? self : that)\n\n/**\n * Clamp a value between a minimum and a maximum.\n *\n * @example\n * ```ts\n * import { Order, Number } from \"effect\"\n *\n * const clamp = Order.clamp(Number.Order)({ minimum: 1, maximum: 5 })\n *\n * assert.equal(clamp(3), 3)\n * assert.equal(clamp(0), 1)\n * assert.equal(clamp(6), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const clamp = <A>(O: Order<A>): {\n (options: {\n minimum: A\n maximum: A\n }): (self: A) => A\n (self: A, options: {\n minimum: A\n maximum: A\n }): A\n} =>\n dual(\n 2,\n (self: A, options: {\n minimum: A\n maximum: A\n }): A => min(O)(options.maximum, max(O)(options.minimum, self))\n )\n\n/**\n * Test whether a value is between a minimum and a maximum (inclusive).\n *\n * @since 2.0.0\n */\nexport const between = <A>(O: Order<A>): {\n (options: {\n minimum: A\n maximum: A\n }): (self: A) => boolean\n (self: A, options: {\n minimum: A\n maximum: A\n }): boolean\n} =>\n dual(\n 2,\n (self: A, options: {\n minimum: A\n maximum: A\n }): boolean => !lessThan(O)(self, options.minimum) && !greaterThan(O)(self, options.maximum)\n )\n","/**\n * @since 2.0.0\n */\nimport type { Either } from \"./Either.js\"\nimport * as Equal from \"./Equal.js\"\nimport * as Equivalence from \"./Equivalence.js\"\nimport type { LazyArg } from \"./Function.js\"\nimport { constNull, constUndefined, dual, identity, isFunction } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\nimport type { Inspectable } from \"./Inspectable.js\"\nimport * as doNotation from \"./internal/doNotation.js\"\nimport * as either from \"./internal/either.js\"\nimport * as option from \"./internal/option.js\"\nimport type { Order } from \"./Order.js\"\nimport * as order from \"./Order.js\"\nimport type { Pipeable } from \"./Pipeable.js\"\nimport type { Predicate, Refinement } from \"./Predicate.js\"\nimport type { Covariant, NoInfer, NotFunction } from \"./Types.js\"\nimport type * as Unify from \"./Unify.js\"\nimport * as Gen from \"./Utils.js\"\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport type Option<A> = None<A> | Some<A>\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport const TypeId: unique symbol = Symbol.for(\"effect/Option\")\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport type TypeId = typeof TypeId\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface None<out A> extends Pipeable, Inspectable {\n readonly _tag: \"None\"\n readonly _op: \"None\"\n readonly [TypeId]: {\n readonly _A: Covariant<A>\n }\n [Unify.typeSymbol]?: unknown\n [Unify.unifySymbol]?: OptionUnify<this>\n [Unify.ignoreSymbol]?: OptionUnifyIgnore\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Some<out A> extends Pipeable, Inspectable {\n readonly _tag: \"Some\"\n readonly _op: \"Some\"\n readonly value: A\n readonly [TypeId]: {\n readonly _A: Covariant<A>\n }\n [Unify.typeSymbol]?: unknown\n [Unify.unifySymbol]?: OptionUnify<this>\n [Unify.ignoreSymbol]?: OptionUnifyIgnore\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface OptionUnify<A extends { [Unify.typeSymbol]?: any }> {\n Option?: () => A[Unify.typeSymbol] extends Option<infer A0> | infer _ ? Option<A0> : never\n}\n\n/**\n * @since 2.0.0\n */\nexport declare namespace Option {\n /**\n * @since 2.0.0\n * @category type-level\n */\n export type Value<T extends Option<any>> = [T] extends [Option<infer _A>] ? _A : never\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface OptionUnifyIgnore {}\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface OptionTypeLambda extends TypeLambda {\n readonly type: Option<this[\"Target\"]>\n}\n\n/**\n * Creates a new `Option` that represents the absence of a value.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const none = <A = never>(): Option<A> => option.none\n\n/**\n * Creates a new `Option` that wraps the given value.\n *\n * @param value - The value to wrap.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const some: <A>(value: A) => Option<A> = option.some\n\n/**\n * Checks if a given value is an `Option` value.\n *\n * @param input - The value to check.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.isOption(Option.some(1)), true)\n * assert.deepStrictEqual(Option.isOption(Option.none()), true)\n * assert.deepStrictEqual(Option.isOption({}), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isOption: (input: unknown) => input is Option<unknown> = option.isOption\n\n/**\n * Determine if a `Option` is a `None`.\n *\n * @param self - The `Option` to check.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.isNone(Option.some(1)), false)\n * assert.deepStrictEqual(Option.isNone(Option.none()), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNone: <A>(self: Option<A>) => self is None<A> = option.isNone\n\n/**\n * Determine if a `Option` is a `Some`.\n *\n * @param self - The `Option` to check.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.isSome(Option.some(1)), true)\n * assert.deepStrictEqual(Option.isSome(Option.none()), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isSome: <A>(self: Option<A>) => self is Some<A> = option.isSome\n\n/**\n * Matches the given `Option` and returns either the provided `onNone` value or the result of the provided `onSome`\n * function when passed the `Option`'s value.\n *\n * @param self - The `Option` to match\n * @param onNone - The value to be returned if the `Option` is `None`\n * @param onSome - The function to be called if the `Option` is `Some`, it will be passed the `Option`'s value and its result will be returned\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(Option.some(1), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),\n * 'a some containing 1'\n * )\n *\n * assert.deepStrictEqual(\n * pipe(Option.none(), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),\n * 'a none'\n * )\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\nexport const match: {\n /**\n * Matches the given `Option` and returns either the provided `onNone` value or the result of the provided `onSome`\n * function when passed the `Option`'s value.\n *\n * @param self - The `Option` to match\n * @param onNone - The value to be returned if the `Option` is `None`\n * @param onSome - The function to be called if the `Option` is `Some`, it will be passed the `Option`'s value and its result will be returned\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(Option.some(1), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),\n * 'a some containing 1'\n * )\n *\n * assert.deepStrictEqual(\n * pipe(Option.none(), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),\n * 'a none'\n * )\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <B, A, C = B>(\n options: {\n readonly onNone: LazyArg<B>\n readonly onSome: (a: A) => C\n }\n ): (self: Option<A>) => B | C\n /**\n * Matches the given `Option` and returns either the provided `onNone` value or the result of the provided `onSome`\n * function when passed the `Option`'s value.\n *\n * @param self - The `Option` to match\n * @param onNone - The value to be returned if the `Option` is `None`\n * @param onSome - The function to be called if the `Option` is `Some`, it will be passed the `Option`'s value and its result will be returned\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(Option.some(1), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),\n * 'a some containing 1'\n * )\n *\n * assert.deepStrictEqual(\n * pipe(Option.none(), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),\n * 'a none'\n * )\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <A, B, C = B>(\n self: Option<A>,\n options: {\n readonly onNone: LazyArg<B>\n readonly onSome: (a: A) => C\n }\n ): B | C\n} = dual(\n 2,\n <A, B, C = B>(self: Option<A>, { onNone, onSome }: {\n readonly onNone: LazyArg<B>\n readonly onSome: (a: A) => C\n }): B | C => isNone(self) ? onNone() : onSome(self.value)\n)\n\n/**\n * Returns a type guard from a `Option` returning function.\n * This function ensures that a type guard definition is type-safe.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const parsePositive = (n: number): Option.Option<number> =>\n * n > 0 ? Option.some(n) : Option.none()\n *\n * const isPositive = Option.toRefinement(parsePositive)\n *\n * assert.deepStrictEqual(isPositive(1), true)\n * assert.deepStrictEqual(isPositive(-1), false)\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const toRefinement = <A, B extends A>(f: (a: A) => Option<B>): (a: A) => a is B => (a: A): a is B => isSome(f(a))\n\n/**\n * Converts an `Iterable` of values into an `Option`. Returns the first value of the `Iterable` wrapped in a `Some`\n * if the `Iterable` is not empty, otherwise returns `None`.\n *\n * @param collection - The `Iterable` to be converted to an `Option`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.fromIterable([1, 2, 3]), Option.some(1))\n * assert.deepStrictEqual(Option.fromIterable([]), Option.none())\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const fromIterable = <A>(collection: Iterable<A>): Option<A> => {\n for (const a of collection) {\n return some(a)\n }\n return none()\n}\n\n/**\n * Converts a `Either` to an `Option` discarding the error.\n *\n * @example\n * ```ts\n * import { Option, Either } from \"effect\"\n *\n * assert.deepStrictEqual(Option.getRight(Either.right('ok')), Option.some('ok'))\n * assert.deepStrictEqual(Option.getRight(Either.left('err')), Option.none())\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const getRight: <R, L>(self: Either<R, L>) => Option<R> = either.getRight\n\n/**\n * Converts a `Either` to an `Option` discarding the value.\n *\n * @example\n * ```ts\n * import { Option, Either } from \"effect\"\n *\n * assert.deepStrictEqual(Option.getLeft(Either.right(\"ok\")), Option.none())\n * assert.deepStrictEqual(Option.getLeft(Either.left(\"a\")), Option.some(\"a\"))\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const getLeft: <R, L>(self: Either<R, L>) => Option<L> = either.getLeft\n\n/**\n * Returns the value of the `Option` if it is `Some`, otherwise returns `onNone`\n *\n * @param self - The `Option` to get the value of.\n * @param onNone - Function that returns the default value to return if the `Option` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(pipe(Option.some(1), Option.getOrElse(() => 0)), 1)\n * assert.deepStrictEqual(pipe(Option.none(), Option.getOrElse(() => 0)), 0)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrElse: {\n /**\n * Returns the value of the `Option` if it is `Some`, otherwise returns `onNone`\n *\n * @param self - The `Option` to get the value of.\n * @param onNone - Function that returns the default value to return if the `Option` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(pipe(Option.some(1), Option.getOrElse(() => 0)), 1)\n * assert.deepStrictEqual(pipe(Option.none(), Option.getOrElse(() => 0)), 0)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <B>(onNone: LazyArg<B>): <A>(self: Option<A>) => B | A\n /**\n * Returns the value of the `Option` if it is `Some`, otherwise returns `onNone`\n *\n * @param self - The `Option` to get the value of.\n * @param onNone - Function that returns the default value to return if the `Option` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(pipe(Option.some(1), Option.getOrElse(() => 0)), 1)\n * assert.deepStrictEqual(pipe(Option.none(), Option.getOrElse(() => 0)), 0)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, onNone: LazyArg<B>): A | B\n} = dual(\n 2,\n <A, B>(self: Option<A>, onNone: LazyArg<B>): A | B => isNone(self) ? onNone() : self.value\n)\n\n/**\n * Returns the provided `Option` `that` if `self` is `None`, otherwise returns `self`.\n *\n * @param self - The first `Option` to be checked.\n * @param that - The `Option` to return if `self` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElse(() => Option.none())\n * ),\n * Option.none()\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElse(() => Option.none())\n * ),\n * Option.some('a')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElse(() => Option.some('b'))\n * ),\n * Option.some('b')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElse(() => Option.some('b'))\n * ),\n * Option.some('a')\n * )\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\nexport const orElse: {\n /**\n * Returns the provided `Option` `that` if `self` is `None`, otherwise returns `self`.\n *\n * @param self - The first `Option` to be checked.\n * @param that - The `Option` to return if `self` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElse(() => Option.none())\n * ),\n * Option.none()\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElse(() => Option.none())\n * ),\n * Option.some('a')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElse(() => Option.some('b'))\n * ),\n * Option.some('b')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElse(() => Option.some('b'))\n * ),\n * Option.some('a')\n * )\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\n <B>(that: LazyArg<Option<B>>): <A>(self: Option<A>) => Option<B | A>\n /**\n * Returns the provided `Option` `that` if `self` is `None`, otherwise returns `self`.\n *\n * @param self - The first `Option` to be checked.\n * @param that - The `Option` to return if `self` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElse(() => Option.none())\n * ),\n * Option.none()\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElse(() => Option.none())\n * ),\n * Option.some('a')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElse(() => Option.some('b'))\n * ),\n * Option.some('b')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElse(() => Option.some('b'))\n * ),\n * Option.some('a')\n * )\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<A | B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<A | B> => isNone(self) ? that() : self\n)\n\n/**\n * Returns the provided default value as `Some` if `self` is `None`, otherwise returns `self`.\n *\n * @param self - The first `Option` to be checked.\n * @param onNone - Function that returns the default value to return if the `Option` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElseSome(() => 'b')\n * ),\n * Option.some('b')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElseSome(() => 'b')\n * ),\n * Option.some('a')\n * )\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\nexport const orElseSome: {\n /**\n * Returns the provided default value as `Some` if `self` is `None`, otherwise returns `self`.\n *\n * @param self - The first `Option` to be checked.\n * @param onNone - Function that returns the default value to return if the `Option` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElseSome(() => 'b')\n * ),\n * Option.some('b')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElseSome(() => 'b')\n * ),\n * Option.some('a')\n * )\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\n <B>(onNone: LazyArg<B>): <A>(self: Option<A>) => Option<B | A>\n /**\n * Returns the provided default value as `Some` if `self` is `None`, otherwise returns `self`.\n *\n * @param self - The first `Option` to be checked.\n * @param onNone - Function that returns the default value to return if the `Option` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElseSome(() => 'b')\n * ),\n * Option.some('b')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElseSome(() => 'b')\n * ),\n * Option.some('a')\n * )\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, onNone: LazyArg<B>): Option<A | B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, onNone: LazyArg<B>): Option<A | B> => isNone(self) ? some(onNone()) : self\n)\n\n/**\n * Similar to `orElse`, but instead of returning a simple union, it returns an `Either` object,\n * which contains information about which of the two `Option`s has been chosen.\n *\n * This is useful when it's important to know whether the value was retrieved from the first `Option` or the second option.\n *\n * @param self - The first `Option` to be checked.\n * @param that - The second `Option` to be considered if the first `Option` is `None`.\n *\n * @category error handling\n * @since 2.0.0\n */\nexport const orElseEither: {\n /**\n * Similar to `orElse`, but instead of returning a simple union, it returns an `Either` object,\n * which contains information about which of the two `Option`s has been chosen.\n *\n * This is useful when it's important to know whether the value was retrieved from the first `Option` or the second option.\n *\n * @param self - The first `Option` to be checked.\n * @param that - The second `Option` to be considered if the first `Option` is `None`.\n *\n * @category error handling\n * @since 2.0.0\n */\n <B>(that: LazyArg<Option<B>>): <A>(self: Option<A>) => Option<Either<B, A>>\n /**\n * Similar to `orElse`, but instead of returning a simple union, it returns an `Either` object,\n * which contains information about which of the two `Option`s has been chosen.\n *\n * This is useful when it's important to know whether the value was retrieved from the first `Option` or the second option.\n *\n * @param self - The first `Option` to be checked.\n * @param that - The second `Option` to be considered if the first `Option` is `None`.\n *\n * @category error handling\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<Either<B, A>>\n} = dual(\n 2,\n <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<Either<B, A>> =>\n isNone(self) ? map(that(), either.right) : map(self, either.left)\n)\n\n/**\n * Given an `Iterable` collection of `Option`s, returns the first `Some` found in the collection.\n *\n * @param collection - An iterable collection of `Option` to be searched.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.firstSomeOf([Option.none(), Option.some(1), Option.some(2)]), Option.some(1))\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\nexport const firstSomeOf = <T, C extends Iterable<Option<T>> = Iterable<Option<T>>>(\n collection: C\n): [C] extends [Iterable<Option<infer A>>] ? Option<A> : never => {\n let out: Option<unknown> = none()\n for (out of collection) {\n if (isSome(out)) {\n return out as any\n }\n }\n return out as any\n}\n\n/**\n * Constructs a new `Option` from a nullable type. If the value is `null` or `undefined`, returns `None`, otherwise\n * returns the value wrapped in a `Some`.\n *\n * @param nullableValue - The nullable value to be converted to an `Option`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.fromNullable(undefined), Option.none())\n * assert.deepStrictEqual(Option.fromNullable(null), Option.none())\n * assert.deepStrictEqual(Option.fromNullable(1), Option.some(1))\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const fromNullable = <A>(\n nullableValue: A\n): Option<\n NonNullable<A>\n> => (nullableValue == null ? none() : some(nullableValue as NonNullable<A>))\n\n/**\n * This API is useful for lifting a function that returns `null` or `undefined` into the `Option` context.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const parse = (s: string): number | undefined => {\n * const n = parseFloat(s)\n * return isNaN(n) ? undefined : n\n * }\n *\n * const parseOption = Option.liftNullable(parse)\n *\n * assert.deepStrictEqual(parseOption('1'), Option.some(1))\n * assert.deepStrictEqual(parseOption('not a number'), Option.none())\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const liftNullable = <A extends ReadonlyArray<unknown>, B>(\n f: (...a: A) => B | null | undefined\n): (...a: A) => Option<NonNullable<B>> =>\n(...a) => fromNullable(f(...a))\n\n/**\n * Returns the value of the `Option` if it is a `Some`, otherwise returns `null`.\n *\n * @param self - The `Option` to extract the value from.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.getOrNull(Option.some(1)), 1)\n * assert.deepStrictEqual(Option.getOrNull(Option.none()), null)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrNull: <A>(self: Option<A>) => A | null = getOrElse(constNull)\n\n/**\n * Returns the value of the `Option` if it is a `Some`, otherwise returns `undefined`.\n *\n * @param self - The `Option` to extract the value from.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.getOrUndefined(Option.some(1)), 1)\n * assert.deepStrictEqual(Option.getOrUndefined(Option.none()), undefined)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrUndefined: <A>(self: Option<A>) => A | undefined = getOrElse(constUndefined)\n\n/**\n * A utility function that lifts a function that throws exceptions into a function that returns an `Option`.\n *\n * This function is useful for any function that might throw an exception, allowing the developer to handle\n * the exception in a more functional way.\n *\n * @param f - the function that can throw exceptions.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const parse = Option.liftThrowable(JSON.parse)\n *\n * assert.deepStrictEqual(parse(\"1\"), Option.some(1))\n * assert.deepStrictEqual(parse(\"\"), Option.none())\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const liftThrowable = <A extends ReadonlyArray<unknown>, B>(\n f: (...a: A) => B\n): (...a: A) => Option<B> =>\n(...a) => {\n try {\n return some(f(...a))\n } catch (e) {\n return none()\n }\n}\n\n/**\n * Extracts the value of an `Option` or throws if the `Option` is `None`.\n *\n * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.\n *\n * @param self - The `Option` to extract the value from.\n * @param onNone - A function that will be called if the `Option` is `None`. It returns the error to be thrown.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Option.getOrThrowWith(Option.some(1), () => new Error('Unexpected None')),\n * 1\n * )\n * assert.throws(() => Option.getOrThrowWith(Option.none(), () => new Error('Unexpected None')))\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const getOrThrowWith: {\n /**\n * Extracts the value of an `Option` or throws if the `Option` is `None`.\n *\n * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.\n *\n * @param self - The `Option` to extract the value from.\n * @param onNone - A function that will be called if the `Option` is `None`. It returns the error to be thrown.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Option.getOrThrowWith(Option.some(1), () => new Error('Unexpected None')),\n * 1\n * )\n * assert.throws(() => Option.getOrThrowWith(Option.none(), () => new Error('Unexpected None')))\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\n (onNone: () => unknown): <A>(self: Option<A>) => A\n /**\n * Extracts the value of an `Option` or throws if the `Option` is `None`.\n *\n * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.\n *\n * @param self - The `Option` to extract the value from.\n * @param onNone - A function that will be called if the `Option` is `None`. It returns the error to be thrown.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Option.getOrThrowWith(Option.some(1), () => new Error('Unexpected None')),\n * 1\n * )\n * assert.throws(() => Option.getOrThrowWith(Option.none(), () => new Error('Unexpected None')))\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\n <A>(self: Option<A>, onNone: () => unknown): A\n} = dual(2, <A>(self: Option<A>, onNone: () => unknown): A => {\n if (isSome(self)) {\n return self.value\n }\n throw onNone()\n})\n\n/**\n * Extracts the value of an `Option` or throws if the `Option` is `None`.\n *\n * The thrown error is a default error. To configure the error thrown, see {@link getOrThrowWith}.\n *\n * @param self - The `Option` to extract the value from.\n * @throws `Error(\"getOrThrow called on a None\")`\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.getOrThrow(Option.some(1)), 1)\n * assert.throws(() => Option.getOrThrow(Option.none()))\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const getOrThrow: <A>(self: Option<A>) => A = getOrThrowWith(() => new Error(\"getOrThrow called on a None\"))\n\n/**\n * Maps the `Some` side of an `Option` value to a new `Option` value.\n *\n * @param self - An `Option` to map\n * @param f - The function to map over the value of the `Option`\n *\n * @category mapping\n * @since 2.0.0\n */\nexport const map: {\n /**\n * Maps the `Some` side of an `Option` value to a new `Option` value.\n *\n * @param self - An `Option` to map\n * @param f - The function to map over the value of the `Option`\n *\n * @category mapping\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B): (self: Option<A>) => Option<B>\n /**\n * Maps the `Some` side of an `Option` value to a new `Option` value.\n *\n * @param self - An `Option` to map\n * @param f - The function to map over the value of the `Option`\n *\n * @category mapping\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => B): Option<B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => B): Option<B> => isNone(self) ? none() : some(f(self.value))\n)\n\n/**\n * Maps the `Some` value of this `Option` to the specified constant value.\n *\n * @category mapping\n * @since 2.0.0\n */\nexport const as: {\n /**\n * Maps the `Some` value of this `Option` to the specified constant value.\n *\n * @category mapping\n * @since 2.0.0\n */\n <B>(b: B): <X>(self: Option<X>) => Option<B>\n} = dual(2, <X, B>(self: Option<X>, b: B): Option<B> => map(self, () => b))\n\n/**\n * Maps the `Some` value of this `Option` to the `void` constant value.\n *\n * This is useful when the value of the `Option` is not needed, but the presence or absence of the value is important.\n *\n * @category mapping\n * @since 2.0.0\n */\nexport const asVoid: <_>(self: Option<_>) => Option<void> = as(undefined)\n\nconst void_: Option<void> = some(undefined)\nexport {\n /**\n * @since 2.0.0\n */\n void_ as void\n}\n\n/**\n * Applies a function to the value of an `Option` and flattens the result, if the input is `Some`.\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatMap: {\n /**\n * Applies a function to the value of an `Option` and flattens the result, if the input is `Some`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => Option<B>): (self: Option<A>) => Option<B>\n /**\n * Applies a function to the value of an `Option` and flattens the result, if the input is `Some`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B> => isNone(self) ? none() : f(self.value)\n)\n\n/**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const andThen: {\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => Option<B>): (self: Option<A>) => Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <B>(f: Option<B>): <A>(self: Option<A>) => Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B): (self: Option<A>) => Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <B>(f: NotFunction<B>): <A>(self: Option<A>) => Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: Option<B>): Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => B): Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: NotFunction<B>): Option<B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => Option<B> | Option<B>): Option<B> =>\n flatMap(self, (a) => {\n const b = isFunction(f) ? f(a) : f\n return isOption(b) ? b : some(b)\n })\n)\n\n/**\n * This is `flatMap` + `fromNullable`, useful when working with optional values.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * interface Employee {\n * company?: {\n * address?: {\n * street?: {\n * name?: string\n * }\n * }\n * }\n * }\n *\n * const employee1: Employee = { company: { address: { street: { name: 'high street' } } } }\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.some(employee1),\n * Option.flatMapNullable(employee => employee.company?.address?.street?.name),\n * ),\n * Option.some('high street')\n * )\n *\n * const employee2: Employee = { company: { address: { street: {} } } }\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.some(employee2),\n * Option.flatMapNullable(employee => employee.company?.address?.street?.name),\n * ),\n * Option.none()\n * )\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatMapNullable: {\n /**\n * This is `flatMap` + `fromNullable`, useful when working with optional values.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * interface Employee {\n * company?: {\n * address?: {\n * street?: {\n * name?: string\n * }\n * }\n * }\n * }\n *\n * const employee1: Employee = { company: { address: { street: { name: 'high street' } } } }\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.some(employee1),\n * Option.flatMapNullable(employee => employee.company?.address?.street?.name),\n * ),\n * Option.some('high street')\n * )\n *\n * const employee2: Employee = { company: { address: { street: {} } } }\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.some(employee2),\n * Option.flatMapNullable(employee => employee.company?.address?.street?.name),\n * ),\n * Option.none()\n * )\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B | null | undefined): (self: Option<A>) => Option<NonNullable<B>>\n /**\n * This is `flatMap` + `fromNullable`, useful when working with optional values.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * interface Employee {\n * company?: {\n * address?: {\n * street?: {\n * name?: string\n * }\n * }\n * }\n * }\n *\n * const employee1: Employee = { company: { address: { street: { name: 'high street' } } } }\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.some(employee1),\n * Option.flatMapNullable(employee => employee.company?.address?.street?.name),\n * ),\n * Option.some('high street')\n * )\n *\n * const employee2: Employee = { company: { address: { street: {} } } }\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.some(employee2),\n * Option.flatMapNullable(employee => employee.company?.address?.street?.name),\n * ),\n * Option.none()\n * )\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => B | null | undefined): Option<NonNullable<B>>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => B | null | undefined): Option<NonNullable<B>> =>\n isNone(self) ? none() : fromNullable(f(self.value))\n)\n\n/**\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatten: <A>(self: Option<Option<A>>) => Option<A> = flatMap(identity)\n\n/**\n * @category zipping\n * @since 2.0.0\n */\nexport const zipRight: {\n /**\n * @category zipping\n * @since 2.0.0\n */\n <B>(that: Option<B>): <_>(self: Option<_>) => Option<B>\n /**\n * @category zipping\n * @since 2.0.0\n */\n <X, B>(self: Option<X>, that: Option<B>): Option<B>\n} = dual(2, <X, B>(self: Option<X>, that: Option<B>): Option<B> => flatMap(self, () => that))\n\n/**\n * @category sequencing\n * @since 2.0.0\n */\nexport const composeK: {\n /**\n * @category sequencing\n * @since 2.0.0\n */\n <B, C>(bfc: (b: B) => Option<C>): <A>(afb: (a: A) => Option<B>) => (a: A) => Option<C>\n /**\n * @category sequencing\n * @since 2.0.0\n */\n <A, B, C>(afb: (a: A) => Option<B>, bfc: (b: B) => Option<C>): (a: A) => Option<C>\n} = dual(2, <A, B, C>(afb: (a: A) => Option<B>, bfc: (b: B) => Option<C>) => (a: A): Option<C> => flatMap(afb(a), bfc))\n\n/**\n * Sequences the specified `that` `Option` but ignores its value.\n *\n * It is useful when we want to chain multiple operations, but only care about the result of `self`.\n *\n * @param that - The `Option` that will be ignored in the chain and discarded\n * @param self - The `Option` we care about\n *\n * @category zipping\n * @since 2.0.0\n */\nexport const zipLeft: {\n /**\n * Sequences the specified `that` `Option` but ignores its value.\n *\n * It is useful when we want to chain multiple operations, but only care about the result of `self`.\n *\n * @param that - The `Option` that will be ignored in the chain and discarded\n * @param self - The `Option` we care about\n *\n * @category zipping\n * @since 2.0.0\n */\n <_>(that: Option<_>): <A>(self: Option<A>) => Option<A>\n /**\n * Sequences the specified `that` `Option` but ignores its value.\n *\n * It is useful when we want to chain multiple operations, but only care about the result of `self`.\n *\n * @param that - The `Option` that will be ignored in the chain and discarded\n * @param self - The `Option` we care about\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, X>(self: Option<A>, that: Option<X>): Option<A>\n} = dual(2, <A, X>(self: Option<A>, that: Option<X>): Option<A> => tap(self, () => that))\n\n/**\n * Applies the provided function `f` to the value of the `Option` if it is `Some` and returns the original `Option`\n * unless `f` returns `None`, in which case it returns `None`.\n *\n * This function is useful for performing additional computations on the value of the input `Option` without affecting its value.\n *\n * @param f - Function to apply to the value of the `Option` if it is `Some`\n * @param self - The `Option` to apply the function to\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getInteger = (n: number) => Number.isInteger(n) ? Option.some(n) : Option.none()\n *\n * assert.deepStrictEqual(Option.tap(Option.none(), getInteger), Option.none())\n * assert.deepStrictEqual(Option.tap(Option.some(1), getInteger), Option.some(1))\n * assert.deepStrictEqual(Option.tap(Option.some(1.14), getInteger), Option.none())\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const tap: {\n /**\n * Applies the provided function `f` to the value of the `Option` if it is `Some` and returns the original `Option`\n * unless `f` returns `None`, in which case it returns `None`.\n *\n * This function is useful for performing additional computations on the value of the input `Option` without affecting its value.\n *\n * @param f - Function to apply to the value of the `Option` if it is `Some`\n * @param self - The `Option` to apply the function to\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getInteger = (n: number) => Number.isInteger(n) ? Option.some(n) : Option.none()\n *\n * assert.deepStrictEqual(Option.tap(Option.none(), getInteger), Option.none())\n * assert.deepStrictEqual(Option.tap(Option.some(1), getInteger), Option.some(1))\n * assert.deepStrictEqual(Option.tap(Option.some(1.14), getInteger), Option.none())\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, X>(f: (a: A) => Option<X>): (self: Option<A>) => Option<A>\n /**\n * Applies the provided function `f` to the value of the `Option` if it is `Some` and returns the original `Option`\n * unless `f` returns `None`, in which case it returns `None`.\n *\n * This function is useful for performing additional computations on the value of the input `Option` without affecting its value.\n *\n * @param f - Function to apply to the value of the `Option` if it is `Some`\n * @param self - The `Option` to apply the function to\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getInteger = (n: number) => Number.isInteger(n) ? Option.some(n) : Option.none()\n *\n * assert.deepStrictEqual(Option.tap(Option.none(), getInteger), Option.none())\n * assert.deepStrictEqual(Option.tap(Option.some(1), getInteger), Option.some(1))\n * assert.deepStrictEqual(Option.tap(Option.some(1.14), getInteger), Option.none())\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, X>(self: Option<A>, f: (a: A) => Option<X>): Option<A>\n} = dual(2, <A, X>(self: Option<A>, f: (a: A) => Option<X>): Option<A> => flatMap(self, (a) => map(f(a), () => a)))\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const product = <A, B>(self: Option<A>, that: Option<B>): Option<[A, B]> =>\n isSome(self) && isSome(that) ? some([self.value, that.value]) : none()\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const productMany = <A>(\n self: Option<A>,\n collection: Iterable<Option<A>>\n): Option<[A, ...Array<A>]> => {\n if (isNone(self)) {\n return none()\n }\n const out: [A, ...Array<A>] = [self.value]\n for (const o of collection) {\n if (isNone(o)) {\n return none()\n }\n out.push(o.value)\n }\n return some(out)\n}\n\n/**\n * Takes a structure of `Option`s and returns an `Option` of values with the same structure.\n *\n * - If a tuple is supplied, then the returned `Option` will contain a tuple with the same length.\n * - If a struct is supplied, then the returned `Option` will contain a struct with the same keys.\n * - If an iterable is supplied, then the returned `Option` will contain an array.\n *\n * @param fields - the struct of `Option`s to be sequenced.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.all([Option.some(1), Option.some(2)]), Option.some([1, 2]))\n * assert.deepStrictEqual(Option.all({ a: Option.some(1), b: Option.some(\"hello\") }), Option.some({ a: 1, b: \"hello\" }))\n * assert.deepStrictEqual(Option.all({ a: Option.some(1), b: Option.none() }), Option.none())\n * ```\n *\n * @category combining\n * @since 2.0.0\n */\n// @ts-expect-error\nexport const all: <const I extends Iterable<Option<any>> | Record<string, Option<any>>>(\n input: I\n) => [I] extends [ReadonlyArray<Option<any>>] ? Option<\n { -readonly [K in keyof I]: [I[K]] extends [Option<infer A>] ? A : never }\n >\n : [I] extends [Iterable<Option<infer A>>] ? Option<Array<A>>\n : Option<{ -readonly [K in keyof I]: [I[K]] extends [Option<infer A>] ? A : never }> = (\n input: Iterable<Option<any>> | Record<string, Option<any>>\n ): Option<any> => {\n if (Symbol.iterator in input) {\n const out: Array<Option<any>> = []\n for (const o of (input as Iterable<Option<any>>)) {\n if (isNone(o)) {\n return none()\n }\n out.push(o.value)\n }\n return some(out)\n }\n\n const out: Record<string, any> = {}\n for (const key of Object.keys(input)) {\n const o = input[key]\n if (isNone(o)) {\n return none()\n }\n out[key] = o.value\n }\n return some(out)\n }\n\n/**\n * Zips two `Option` values together using a provided function, returning a new `Option` of the result.\n *\n * @param self - The left-hand side of the zip operation\n * @param that - The right-hand side of the zip operation\n * @param f - The function used to combine the values of the two `Option`s\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * type Complex = [real: number, imaginary: number]\n *\n * const complex = (real: number, imaginary: number): Complex => [real, imaginary]\n *\n * assert.deepStrictEqual(Option.zipWith(Option.none(), Option.none(), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.none(), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.none(), Option.some(1), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.some(2), complex), Option.some([1, 2]))\n *\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), complex)(Option.some(2)), Option.some([2, 1]))\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\nexport const zipWith: {\n /**\n * Zips two `Option` values together using a provided function, returning a new `Option` of the result.\n *\n * @param self - The left-hand side of the zip operation\n * @param that - The right-hand side of the zip operation\n * @param f - The function used to combine the values of the two `Option`s\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * type Complex = [real: number, imaginary: number]\n *\n * const complex = (real: number, imaginary: number): Complex => [real, imaginary]\n *\n * assert.deepStrictEqual(Option.zipWith(Option.none(), Option.none(), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.none(), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.none(), Option.some(1), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.some(2), complex), Option.some([1, 2]))\n *\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), complex)(Option.some(2)), Option.some([2, 1]))\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B, A, C>(that: Option<B>, f: (a: A, b: B) => C): (self: Option<A>) => Option<C>\n /**\n * Zips two `Option` values together using a provided function, returning a new `Option` of the result.\n *\n * @param self - The left-hand side of the zip operation\n * @param that - The right-hand side of the zip operation\n * @param f - The function used to combine the values of the two `Option`s\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * type Complex = [real: number, imaginary: number]\n *\n * const complex = (real: number, imaginary: number): Complex => [real, imaginary]\n *\n * assert.deepStrictEqual(Option.zipWith(Option.none(), Option.none(), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.none(), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.none(), Option.some(1), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.some(2), complex), Option.some([1, 2]))\n *\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), complex)(Option.some(2)), Option.some([2, 1]))\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C>\n} = dual(\n 3,\n <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C> =>\n map(product(self, that), ([a, b]) => f(a, b))\n)\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const ap: {\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(that: Option<A>): <B>(self: Option<(a: A) => B>) => Option<B>\n /**\n * @category combining\n * @since 2.0.0\n */\n <A, B>(self: Option<(a: A) => B>, that: Option<A>): Option<B>\n} = dual(2, <A, B>(self: Option<(a: A) => B>, that: Option<A>): Option<B> => zipWith(self, that, (f, a) => f(a)))\n\n/**\n * Reduces an `Iterable` of `Option<A>` to a single value of type `B`, elements that are `None` are ignored.\n *\n * @param self - The Iterable of `Option<A>` to be reduced.\n * @param b - The initial value of the accumulator.\n * @param f - The reducing function that takes the current accumulator value and the unwrapped value of an `Option<A>`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const iterable = [Option.some(1), Option.none(), Option.some(2), Option.none()]\n * assert.deepStrictEqual(pipe(iterable, Option.reduceCompact(0, (b, a) => b + a)), 3)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const reduceCompact: {\n /**\n * Reduces an `Iterable` of `Option<A>` to a single value of type `B`, elements that are `None` are ignored.\n *\n * @param self - The Iterable of `Option<A>` to be reduced.\n * @param b - The initial value of the accumulator.\n * @param f - The reducing function that takes the current accumulator value and the unwrapped value of an `Option<A>`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const iterable = [Option.some(1), Option.none(), Option.some(2), Option.none()]\n * assert.deepStrictEqual(pipe(iterable, Option.reduceCompact(0, (b, a) => b + a)), 3)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A) => B): (self: Iterable<Option<A>>) => B\n /**\n * Reduces an `Iterable` of `Option<A>` to a single value of type `B`, elements that are `None` are ignored.\n *\n * @param self - The Iterable of `Option<A>` to be reduced.\n * @param b - The initial value of the accumulator.\n * @param f - The reducing function that takes the current accumulator value and the unwrapped value of an `Option<A>`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const iterable = [Option.some(1), Option.none(), Option.some(2), Option.none()]\n * assert.deepStrictEqual(pipe(iterable, Option.reduceCompact(0, (b, a) => b + a)), 3)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<Option<A>>, b: B, f: (b: B, a: A) => B): B\n} = dual(\n 3,\n <A, B>(self: Iterable<Option<A>>, b: B, f: (b: B, a: A) => B): B => {\n let out: B = b\n for (const oa of self) {\n if (isSome(oa)) {\n out = f(out, oa.value)\n }\n }\n return out\n }\n)\n\n/**\n * Transforms an `Option` into an `Array`.\n * If the input is `None`, an empty array is returned.\n * If the input is `Some`, the value is wrapped in an array.\n *\n * @param self - The `Option` to convert to an array.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.toArray(Option.some(1)), [1])\n * assert.deepStrictEqual(Option.toArray(Option.none()), [])\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const toArray = <A>(self: Option<A>): Array<A> => isNone(self) ? [] : [self.value]\n\n/**\n * @category filtering\n * @since 2.0.0\n */\nexport const partitionMap: {\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A, B, C>(f: (a: A) => Either<C, B>): (self: Option<A>) => [left: Option<B>, right: Option<C>]\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A, B, C>(self: Option<A>, f: (a: A) => Either<C, B>): [left: Option<B>, right: Option<C>]\n} = dual(2, <A, B, C>(\n self: Option<A>,\n f: (a: A) => Either<C, B>\n): [excluded: Option<B>, satisfying: Option<C>] => {\n if (isNone(self)) {\n return [none(), none()]\n }\n const e = f(self.value)\n return either.isLeft(e) ? [some(e.left), none()] : [none(), some(e.right)]\n})\n\n/**\n * Maps over the value of an `Option` and filters out `None`s.\n *\n * Useful when in addition to filtering you also want to change the type of the `Option`.\n *\n * @param self - The `Option` to map over.\n * @param f - A function to apply to the value of the `Option`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const evenNumber = (n: number) => n % 2 === 0 ? Option.some(n) : Option.none()\n *\n * assert.deepStrictEqual(Option.filterMap(Option.none(), evenNumber), Option.none())\n * assert.deepStrictEqual(Option.filterMap(Option.some(3), evenNumber), Option.none())\n * assert.deepStrictEqual(Option.filterMap(Option.some(2), evenNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const filterMap: {\n /**\n * Maps over the value of an `Option` and filters out `None`s.\n *\n * Useful when in addition to filtering you also want to change the type of the `Option`.\n *\n * @param self - The `Option` to map over.\n * @param f - A function to apply to the value of the `Option`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const evenNumber = (n: number) => n % 2 === 0 ? Option.some(n) : Option.none()\n *\n * assert.deepStrictEqual(Option.filterMap(Option.none(), evenNumber), Option.none())\n * assert.deepStrictEqual(Option.filterMap(Option.some(3), evenNumber), Option.none())\n * assert.deepStrictEqual(Option.filterMap(Option.some(2), evenNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => Option<B>): (self: Option<A>) => Option<B>\n /**\n * Maps over the value of an `Option` and filters out `None`s.\n *\n * Useful when in addition to filtering you also want to change the type of the `Option`.\n *\n * @param self - The `Option` to map over.\n * @param f - A function to apply to the value of the `Option`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const evenNumber = (n: number) => n % 2 === 0 ? Option.some(n) : Option.none()\n *\n * assert.deepStrictEqual(Option.filterMap(Option.none(), evenNumber), Option.none())\n * assert.deepStrictEqual(Option.filterMap(Option.some(3), evenNumber), Option.none())\n * assert.deepStrictEqual(Option.filterMap(Option.some(2), evenNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B> => isNone(self) ? none() : f(self.value)\n)\n\n/**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @param predicate - A predicate function to apply to the `Option` value.\n * @param fb - The `Option` to filter.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // predicate\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(3), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isEven), Option.some(2))\n *\n * // refinement\n * const isNumber = (v: unknown): v is number => typeof v === \"number\"\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some('hello'), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const filter: {\n /**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @param predicate - A predicate function to apply to the `Option` value.\n * @param fb - The `Option` to filter.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // predicate\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(3), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isEven), Option.some(2))\n *\n * // refinement\n * const isNumber = (v: unknown): v is number => typeof v === \"number\"\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some('hello'), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: Option<A>) => Option<B>\n /**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @param predicate - A predicate function to apply to the `Option` value.\n * @param fb - The `Option` to filter.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // predicate\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(3), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isEven), Option.some(2))\n *\n * // refinement\n * const isNumber = (v: unknown): v is number => typeof v === \"number\"\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some('hello'), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A>(predicate: Predicate<NoInfer<A>>): (self: Option<A>) => Option<A>\n /**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @param predicate - A predicate function to apply to the `Option` value.\n * @param fb - The `Option` to filter.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // predicate\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(3), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isEven), Option.some(2))\n *\n * // refinement\n * const isNumber = (v: unknown): v is number => typeof v === \"number\"\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some('hello'), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(self: Option<A>, refinement: Refinement<A, B>): Option<B>\n /**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @param predicate - A predicate function to apply to the `Option` value.\n * @param fb - The `Option` to filter.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // predicate\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(3), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isEven), Option.some(2))\n *\n * // refinement\n * const isNumber = (v: unknown): v is number => typeof v === \"number\"\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some('hello'), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A>(self: Option<A>, predicate: Predicate<A>): Option<A>\n} = dual(\n 2,\n <A>(self: Option<A>, predicate: Predicate<A>): Option<A> =>\n filterMap(self, (b) => (predicate(b) ? option.some(b) : option.none))\n)\n\n/**\n * @example\n * ```ts\n * import { Option, Number } from \"effect\"\n *\n * const isEquivalent = Option.getEquivalence(Number.Equivalence)\n * assert.deepStrictEqual(isEquivalent(Option.none(), Option.none()), true)\n * assert.deepStrictEqual(isEquivalent(Option.none(), Option.some(1)), false)\n * assert.deepStrictEqual(isEquivalent(Option.some(1), Option.none()), false)\n * assert.deepStrictEqual(isEquivalent(Option.some(1), Option.some(2)), false)\n * assert.deepStrictEqual(isEquivalent(Option.some(1), Option.some(1)), true)\n * ```\n *\n * @category equivalence\n * @since 2.0.0\n */\nexport const getEquivalence = <A>(isEquivalent: Equivalence.Equivalence<A>): Equivalence.Equivalence<Option<A>> =>\n Equivalence.make((x, y) => isNone(x) ? isNone(y) : isNone(y) ? false : isEquivalent(x.value, y.value))\n\n/**\n * The `Order` instance allows `Option` values to be compared with\n * `compare`, whenever there is an `Order` instance for\n * the type the `Option` contains.\n *\n * `None` is considered to be less than any `Some` value.\n *\n * @example\n * ```ts\n * import { pipe, Option, Number } from \"effect\"\n *\n * const O = Option.getOrder(Number.Order)\n * assert.deepStrictEqual(O(Option.none(), Option.none()), 0)\n * assert.deepStrictEqual(O(Option.none(), Option.some(1)), -1)\n * assert.deepStrictEqual(O(Option.some(1), Option.none()), 1)\n * assert.deepStrictEqual(O(Option.some(1), Option.some(2)), -1)\n * assert.deepStrictEqual(O(Option.some(1), Option.some(1)), 0)\n * ```\n *\n * @category sorting\n * @since 2.0.0\n */\nexport const getOrder = <A>(O: Order<A>): Order<Option<A>> =>\n order.make((self, that) => isSome(self) ? (isSome(that) ? O(self.value, that.value) : 1) : -1)\n\n/**\n * Lifts a binary function into `Option`.\n *\n * @param f - The function to lift.\n *\n * @category lifting\n * @since 2.0.0\n */\nexport const lift2 = <A, B, C>(f: (a: A, b: B) => C): {\n (that: Option<B>): (self: Option<A>) => Option<C>\n (self: Option<A>, that: Option<B>): Option<C>\n} => dual(2, (self: Option<A>, that: Option<B>): Option<C> => zipWith(self, that, f))\n\n/**\n * Transforms a `Predicate` function into a `Some` of the input value if the predicate returns `true` or `None`\n * if the predicate returns `false`.\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getOption = Option.liftPredicate((n: number) => n >= 0)\n *\n * assert.deepStrictEqual(getOption(-1), Option.none())\n * assert.deepStrictEqual(getOption(1), Option.some(1))\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\nexport const liftPredicate: { // Note: I intentionally avoid using the NoInfer pattern here.\n <A, B extends A>(refinement: Refinement<A, B>): (a: A) => Option<B>\n /**\n * Transforms a `Predicate` function into a `Some` of the input value if the predicate returns `true` or `None`\n * if the predicate returns `false`.\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getOption = Option.liftPredicate((n: number) => n >= 0)\n *\n * assert.deepStrictEqual(getOption(-1), Option.none())\n * assert.deepStrictEqual(getOption(1), Option.some(1))\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\n <B extends A, A = B>(predicate: Predicate<A>): (b: B) => Option<B>\n /**\n * Transforms a `Predicate` function into a `Some` of the input value if the predicate returns `true` or `None`\n * if the predicate returns `false`.\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getOption = Option.liftPredicate((n: number) => n >= 0)\n *\n * assert.deepStrictEqual(getOption(-1), Option.none())\n * assert.deepStrictEqual(getOption(1), Option.some(1))\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\n <A, B extends A>(self: A, refinement: Refinement<A, B>): Option<B>\n /**\n * Transforms a `Predicate` function into a `Some` of the input value if the predicate returns `true` or `None`\n * if the predicate returns `false`.\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getOption = Option.liftPredicate((n: number) => n >= 0)\n *\n * assert.deepStrictEqual(getOption(-1), Option.none())\n * assert.deepStrictEqual(getOption(1), Option.some(1))\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\n <B extends A, A = B>(self: B, predicate: Predicate<A>): Option<B>\n} = dual(\n 2,\n <B extends A, A = B>(b: B, predicate: Predicate<A>): Option<B> => predicate(b) ? some(b) : none()\n)\n\n/**\n * Returns a function that checks if a `Option` contains a given value using a provided `isEquivalent` function.\n *\n * @param equivalent - An `Equivalence` instance to compare values of the `Option`.\n * @param self - The `Option` to apply the comparison to.\n * @param a - The value to compare against the `Option`.\n *\n * @example\n * ```ts\n * import { pipe, Option, Number } from \"effect\"\n *\n * assert.deepStrictEqual(pipe(Option.some(2), Option.containsWith(Number.Equivalence)(2)), true)\n * assert.deepStrictEqual(pipe(Option.some(1), Option.containsWith(Number.Equivalence)(2)), false)\n * assert.deepStrictEqual(pipe(Option.none(), Option.containsWith(Number.Equivalence)(2)), false)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const containsWith = <A>(isEquivalent: (self: A, that: A) => boolean): {\n (a: A): (self: Option<A>) => boolean\n (self: Option<A>, a: A): boolean\n} => dual(2, (self: Option<A>, a: A): boolean => isNone(self) ? false : isEquivalent(self.value, a))\n\nconst _equivalence = Equal.equivalence()\n\n/**\n * Returns a function that checks if an `Option` contains a given value using the default `Equivalence`.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const contains: {\n /**\n * Returns a function that checks if an `Option` contains a given value using the default `Equivalence`.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(a: A): (self: Option<A>) => boolean\n /**\n * Returns a function that checks if an `Option` contains a given value using the default `Equivalence`.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Option<A>, a: A): boolean\n} = containsWith(_equivalence)\n\n/**\n * Check if a value in an `Option` type meets a certain predicate.\n *\n * @param self - The `Option` to check.\n * @param predicate - The condition to check.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(pipe(Option.some(2), Option.exists(isEven)), true)\n * assert.deepStrictEqual(pipe(Option.some(1), Option.exists(isEven)), false)\n * assert.deepStrictEqual(pipe(Option.none(), Option.exists(isEven)), false)\n * ```\n *\n * @since 2.0.0\n */\nexport const exists: {\n /**\n * Check if a value in an `Option` type meets a certain predicate.\n *\n * @param self - The `Option` to check.\n * @param predicate - The condition to check.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(pipe(Option.some(2), Option.exists(isEven)), true)\n * assert.deepStrictEqual(pipe(Option.some(1), Option.exists(isEven)), false)\n * assert.deepStrictEqual(pipe(Option.none(), Option.exists(isEven)), false)\n * ```\n *\n * @since 2.0.0\n */\n <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: Option<A>) => self is Option<B>\n /**\n * Check if a value in an `Option` type meets a certain predicate.\n *\n * @param self - The `Option` to check.\n * @param predicate - The condition to check.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(pipe(Option.some(2), Option.exists(isEven)), true)\n * assert.deepStrictEqual(pipe(Option.some(1), Option.exists(isEven)), false)\n * assert.deepStrictEqual(pipe(Option.none(), Option.exists(isEven)), false)\n * ```\n *\n * @since 2.0.0\n */\n <A>(predicate: Predicate<NoInfer<A>>): (self: Option<A>) => boolean\n /**\n * Check if a value in an `Option` type meets a certain predicate.\n *\n * @param self - The `Option` to check.\n * @param predicate - The condition to check.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(pipe(Option.some(2), Option.exists(isEven)), true)\n * assert.deepStrictEqual(pipe(Option.some(1), Option.exists(isEven)), false)\n * assert.deepStrictEqual(pipe(Option.none(), Option.exists(isEven)), false)\n * ```\n *\n * @since 2.0.0\n */\n <A, B extends A>(self: Option<A>, refinement: Refinement<A, B>): self is Option<B>\n /**\n * Check if a value in an `Option` type meets a certain predicate.\n *\n * @param self - The `Option` to check.\n * @param predicate - The condition to check.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(pipe(Option.some(2), Option.exists(isEven)), true)\n * assert.deepStrictEqual(pipe(Option.some(1), Option.exists(isEven)), false)\n * assert.deepStrictEqual(pipe(Option.none(), Option.exists(isEven)), false)\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Option<A>, predicate: Predicate<A>): boolean\n} = dual(\n 2,\n <A, B extends A>(self: Option<A>, refinement: Refinement<A, B>): self is Option<B> =>\n isNone(self) ? false : refinement(self.value)\n)\n\n// -------------------------------------------------------------------------------------\n// do notation\n// -------------------------------------------------------------------------------------\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\nexport const bindTo: {\n // -------------------------------------------------------------------------------------\n // do notation\n // -------------------------------------------------------------------------------------\n\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <N extends string>(name: N): <A>(self: Option<A>) => Option<{ [K in N]: A }>\n // -------------------------------------------------------------------------------------\n // do notation\n // -------------------------------------------------------------------------------------\n\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <A, N extends string>(self: Option<A>, name: N): Option<{ [K in N]: A }>\n} = doNotation.bindTo<OptionTypeLambda>(map)\n\nconst let_: {\n <N extends string, A extends object, B>(\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): (self: Option<A>) => Option<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n <A extends object, N extends string, B>(\n self: Option<A>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): Option<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n} = doNotation.let_<OptionTypeLambda>(map)\n\nexport {\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link bindTo}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n *\n * ```\n * @category do notation\n * @since 2.0.0\n */\n let_ as let\n}\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\nexport const bind: {\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <N extends string, A extends object, B>(\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => Option<B>\n ): (self: Option<A>) => Option<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <A extends object, N extends string, B>(\n self: Option<A>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => Option<B>\n ): Option<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n} = doNotation.bind<OptionTypeLambda>(map, flatMap)\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\nexport const Do: Option<{}> = some({})\n\nconst adapter = Gen.adapter<OptionTypeLambda>()\n\n/**\n * @category generators\n * @since 2.0.0\n */\nexport const gen: Gen.Gen<OptionTypeLambda, Gen.Adapter<OptionTypeLambda>> = (...args) => {\n let f: any\n if (args.length === 1) {\n f = args[0]\n } else {\n f = args[1].bind(args[0])\n }\n const iterator = f(adapter)\n let state: IteratorYieldResult<any> | IteratorReturnResult<any> = iterator.next()\n if (state.done) {\n return some(state.value)\n } else {\n let current = state.value\n if (Gen.isGenKind(current)) {\n current = current.value\n } else {\n current = Gen.yieldWrapGet(current)\n }\n if (isNone(current)) {\n return current\n }\n while (!state.done) {\n state = iterator.next(current.value as never)\n if (!state.done) {\n current = state.value\n if (Gen.isGenKind(current)) {\n current = current.value\n } else {\n current = Gen.yieldWrapGet(current)\n }\n if (isNone(current)) {\n return current\n }\n }\n }\n return some(state.value)\n }\n}\n","/**\n * This module provides utility functions for working with arrays in TypeScript.\n *\n * @since 2.0.0\n */\n\nimport type { Either as array_ } from \"./Either.js\"\nimport * as E from \"./Either.js\"\nimport * as Equal from \"./Equal.js\"\nimport * as Equivalence from \"./Equivalence.js\"\nimport type { LazyArg } from \"./Function.js\"\nimport { dual, identity } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\nimport * as readonlyArray from \"./internal/array.js\"\nimport * as doNotation from \"./internal/doNotation.js\"\nimport * as EffectIterable from \"./Iterable.js\"\nimport type { Option } from \"./Option.js\"\nimport * as O from \"./Option.js\"\nimport * as Order from \"./Order.js\"\nimport type { Predicate, Refinement } from \"./Predicate.js\"\nimport { isBoolean } from \"./Predicate.js\"\nimport * as Record from \"./Record.js\"\nimport * as Tuple from \"./Tuple.js\"\nimport type { NoInfer } from \"./Types.js\"\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface ReadonlyArrayTypeLambda extends TypeLambda {\n readonly type: ReadonlyArray<this[\"Target\"]>\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport type NonEmptyReadonlyArray<A> = readonly [A, ...Array<A>]\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport type NonEmptyArray<A> = [A, ...Array<A>]\n\n/**\n * Builds a `NonEmptyArray` from an non-empty collection of elements.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.make(1, 2, 3)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const make = <Elements extends NonEmptyArray<any>>(\n ...elements: Elements\n): NonEmptyArray<Elements[number]> => elements\n\n/**\n * Creates a new `Array` of the specified length.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.allocate<number>(3)\n * assert.deepStrictEqual(result.length, 3)\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const allocate = <A = never>(n: number): Array<A | undefined> => new Array(n)\n\n/**\n * Return a `NonEmptyArray` of length `n` with element `i` initialized with `f(i)`.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * @example\n * ```ts\n * import { makeBy } from \"effect/Array\"\n *\n * assert.deepStrictEqual(makeBy(5, n => n * 2), [0, 2, 4, 6, 8])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const makeBy = <A>(n: number, f: (i: number) => A): NonEmptyArray<A> => {\n const max = Math.max(1, Math.floor(n))\n const out = new Array(max)\n for (let i = 0; i < max; i++) {\n out[i] = f(i)\n }\n return out as NonEmptyArray<A>\n}\n\n/**\n * Return a `NonEmptyArray` containing a range of integers, including both endpoints.\n *\n * @example\n * ```ts\n * import { range } from \"effect/Array\"\n *\n * assert.deepStrictEqual(range(1, 3), [1, 2, 3])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const range = (start: number, end: number): NonEmptyArray<number> =>\n start <= end ? makeBy(end - start + 1, (i) => start + i) : [start]\n\n/**\n * Return a `NonEmptyArray` containing a value repeated the specified number of times.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * assert.deepStrictEqual(Array.replicate(\"a\", 3), [\"a\", \"a\", \"a\"])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const replicate: {\n /**\n * Return a `NonEmptyArray` containing a value repeated the specified number of times.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * assert.deepStrictEqual(Array.replicate(\"a\", 3), [\"a\", \"a\", \"a\"])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n (n: number): <A>(a: A) => NonEmptyArray<A>\n /**\n * Return a `NonEmptyArray` containing a value repeated the specified number of times.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * assert.deepStrictEqual(Array.replicate(\"a\", 3), [\"a\", \"a\", \"a\"])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <A>(a: A, n: number): NonEmptyArray<A>\n} = dual(2, <A>(a: A, n: number): NonEmptyArray<A> => makeBy(n, () => a))\n\n/**\n * Creates a new `Array` from an iterable collection of values.\n * If the input is already an array, it returns the input as-is.\n * Otherwise, it converts the iterable collection to an array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const set = new Set([1, 2, 3])\n * const result = Array.fromIterable(set)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const fromIterable = <A>(collection: Iterable<A>): Array<A> =>\n Array.isArray(collection) ? collection : Array.from(collection)\n\n/**\n * Creates a new `Array` from a value that might not be an iterable.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * assert.deepStrictEqual(Array.ensure(\"a\"), [\"a\"])\n * assert.deepStrictEqual(Array.ensure([\"a\"]), [\"a\"])\n * assert.deepStrictEqual(Array.ensure([\"a\", \"b\", \"c\"]), [\"a\", \"b\", \"c\"])\n * ```\n *\n * @category constructors\n * @since 3.3.0\n */\nexport const ensure = <A>(self: ReadonlyArray<A> | A): Array<A> => Array.isArray(self) ? self : [self as A]\n\n/**\n * Takes a record and returns an array of tuples containing its keys and values.\n *\n * @param self - The record to transform.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const x = { a: 1, b: 2, c: 3 }\n * assert.deepStrictEqual(Array.fromRecord(x), [[\"a\", 1], [\"b\", 2], [\"c\", 3]])\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const fromRecord: <K extends string, A>(self: Readonly<Record<K, A>>) => Array<[K, A]> = Record.toEntries\n\n/**\n * Converts an `Option` to an array.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Array.fromOption(Option.some(1)), [1])\n * assert.deepStrictEqual(Array.fromOption(Option.none()), [])\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const fromOption: <A>(self: Option<A>) => Array<A> = O.toArray\n\n/**\n * Matches the elements of an array, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const match = Array.match({\n * onEmpty: () => \"empty\",\n * onNonEmpty: ([head, ...tail]) => `head: ${head}, tail: ${tail.length}`\n * })\n * assert.deepStrictEqual(match([]), \"empty\")\n * assert.deepStrictEqual(match([1, 2, 3]), \"head: 1, tail: 2\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\nexport const match: {\n /**\n * Matches the elements of an array, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const match = Array.match({\n * onEmpty: () => \"empty\",\n * onNonEmpty: ([head, ...tail]) => `head: ${head}, tail: ${tail.length}`\n * })\n * assert.deepStrictEqual(match([]), \"empty\")\n * assert.deepStrictEqual(match([1, 2, 3]), \"head: 1, tail: 2\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <B, A, C = B>(\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (self: NonEmptyReadonlyArray<A>) => C\n }\n ): (self: ReadonlyArray<A>) => B | C\n /**\n * Matches the elements of an array, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const match = Array.match({\n * onEmpty: () => \"empty\",\n * onNonEmpty: ([head, ...tail]) => `head: ${head}, tail: ${tail.length}`\n * })\n * assert.deepStrictEqual(match([]), \"empty\")\n * assert.deepStrictEqual(match([1, 2, 3]), \"head: 1, tail: 2\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <A, B, C = B>(\n self: ReadonlyArray<A>,\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (self: NonEmptyReadonlyArray<A>) => C\n }\n ): B | C\n} = dual(2, <A, B, C = B>(\n self: ReadonlyArray<A>,\n { onEmpty, onNonEmpty }: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (self: NonEmptyReadonlyArray<A>) => C\n }\n): B | C => isNonEmptyReadonlyArray(self) ? onNonEmpty(self) : onEmpty())\n\n/**\n * Matches the elements of an array from the left, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchLeft = Array.matchLeft({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (head, tail) => `head: ${head}, tail: ${tail.length}`\n * })\n * assert.deepStrictEqual(matchLeft([]), \"empty\")\n * assert.deepStrictEqual(matchLeft([1, 2, 3]), \"head: 1, tail: 2\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\nexport const matchLeft: {\n /**\n * Matches the elements of an array from the left, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchLeft = Array.matchLeft({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (head, tail) => `head: ${head}, tail: ${tail.length}`\n * })\n * assert.deepStrictEqual(matchLeft([]), \"empty\")\n * assert.deepStrictEqual(matchLeft([1, 2, 3]), \"head: 1, tail: 2\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <B, A, C = B>(\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (head: A, tail: Array<A>) => C\n }\n ): (self: ReadonlyArray<A>) => B | C\n /**\n * Matches the elements of an array from the left, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchLeft = Array.matchLeft({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (head, tail) => `head: ${head}, tail: ${tail.length}`\n * })\n * assert.deepStrictEqual(matchLeft([]), \"empty\")\n * assert.deepStrictEqual(matchLeft([1, 2, 3]), \"head: 1, tail: 2\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <A, B, C = B>(\n self: ReadonlyArray<A>,\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (head: A, tail: Array<A>) => C\n }\n ): B | C\n} = dual(2, <A, B, C = B>(\n self: ReadonlyArray<A>,\n { onEmpty, onNonEmpty }: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (head: A, tail: Array<A>) => C\n }\n): B | C => isNonEmptyReadonlyArray(self) ? onNonEmpty(headNonEmpty(self), tailNonEmpty(self)) : onEmpty())\n\n/**\n * Matches the elements of an array from the right, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchRight = Array.matchRight({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (init, last) => `init: ${init.length}, last: ${last}`\n * })\n * assert.deepStrictEqual(matchRight([]), \"empty\")\n * assert.deepStrictEqual(matchRight([1, 2, 3]), \"init: 2, last: 3\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\nexport const matchRight: {\n /**\n * Matches the elements of an array from the right, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchRight = Array.matchRight({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (init, last) => `init: ${init.length}, last: ${last}`\n * })\n * assert.deepStrictEqual(matchRight([]), \"empty\")\n * assert.deepStrictEqual(matchRight([1, 2, 3]), \"init: 2, last: 3\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <B, A, C = B>(\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (init: Array<A>, last: A) => C\n }\n ): (self: ReadonlyArray<A>) => B | C\n /**\n * Matches the elements of an array from the right, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchRight = Array.matchRight({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (init, last) => `init: ${init.length}, last: ${last}`\n * })\n * assert.deepStrictEqual(matchRight([]), \"empty\")\n * assert.deepStrictEqual(matchRight([1, 2, 3]), \"init: 2, last: 3\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <A, B, C = B>(\n self: ReadonlyArray<A>,\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (init: Array<A>, last: A) => C\n }\n ): B | C\n} = dual(2, <A, B, C = B>(\n self: ReadonlyArray<A>,\n { onEmpty, onNonEmpty }: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (init: Array<A>, last: A) => C\n }\n): B | C =>\n isNonEmptyReadonlyArray(self) ?\n onNonEmpty(initNonEmpty(self), lastNonEmpty(self)) :\n onEmpty())\n\n/**\n * Prepend an element to the front of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const original = [2, 3, 4];\n * const result = Array.prepend(original, 1);\n * assert.deepStrictEqual(result, [1, 2, 3, 4]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const prepend: {\n /**\n * Prepend an element to the front of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const original = [2, 3, 4];\n * const result = Array.prepend(original, 1);\n * assert.deepStrictEqual(result, [1, 2, 3, 4]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <B>(head: B): <A>(self: Iterable<A>) => NonEmptyArray<A | B>\n /**\n * Prepend an element to the front of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const original = [2, 3, 4];\n * const result = Array.prepend(original, 1);\n * assert.deepStrictEqual(result, [1, 2, 3, 4]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, head: B): NonEmptyArray<A | B>\n} = dual(2, <A, B>(self: Iterable<A>, head: B): NonEmptyArray<A | B> => [head, ...self])\n\n/**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const prefix = [0, 1];\n * const array = [2, 3];\n * const result = Array.prependAll(array, prefix);\n * assert.deepStrictEqual(result, [0, 1, 2, 3]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const prependAll: {\n /**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const prefix = [0, 1];\n * const array = [2, 3];\n * const result = Array.prependAll(array, prefix);\n * assert.deepStrictEqual(result, [0, 1, 2, 3]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <S extends Iterable<any>, T extends Iterable<any>>(\n that: T\n ): (self: S) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>\n /**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const prefix = [0, 1];\n * const array = [2, 3];\n * const result = Array.prependAll(array, prefix);\n * assert.deepStrictEqual(result, [0, 1, 2, 3]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<A | B>\n /**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const prefix = [0, 1];\n * const array = [2, 3];\n * const result = Array.prependAll(array, prefix);\n * assert.deepStrictEqual(result, [0, 1, 2, 3]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, that: Iterable<B>): NonEmptyArray<A | B>\n /**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const prefix = [0, 1];\n * const array = [2, 3];\n * const result = Array.prependAll(array, prefix);\n * assert.deepStrictEqual(result, [0, 1, 2, 3]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B>\n} = dual(\n 2,\n <A>(self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(that).concat(fromIterable(self))\n)\n\n/**\n * Append an element to the end of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const original = [1, 2, 3];\n * const result = Array.append(original, 4);\n * assert.deepStrictEqual(result, [1, 2, 3, 4]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const append: {\n /**\n * Append an element to the end of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const original = [1, 2, 3];\n * const result = Array.append(original, 4);\n * assert.deepStrictEqual(result, [1, 2, 3, 4]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <B>(last: B): <A>(self: Iterable<A>) => NonEmptyArray<A | B>\n /**\n * Append an element to the end of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const original = [1, 2, 3];\n * const result = Array.append(original, 4);\n * assert.deepStrictEqual(result, [1, 2, 3, 4]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, last: B): NonEmptyArray<A | B>\n} = dual(2, <A, B>(self: Iterable<A>, last: B): Array<A | B> => [...self, last])\n\n/**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const appendAll: {\n /**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <S extends Iterable<any>, T extends Iterable<any>>(\n that: T\n ): (self: S) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>\n /**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<A | B>\n /**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, that: Iterable<B>): NonEmptyArray<A | B>\n /**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B>\n} = dual(\n 2,\n <A>(self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(self).concat(fromIterable(that))\n)\n\n/**\n * Accumulates values from an `Iterable` starting from the left, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.scan(numbers, 0, (acc, value) => acc + value)\n * assert.deepStrictEqual(result, [0, 1, 3, 6, 10])\n *\n * // Explanation:\n * // This function starts with the initial value (0 in this case)\n * // and adds each element of the array to this accumulator one by one,\n * // keeping track of the cumulative sum after each addition.\n * // Each of these sums is captured in the resulting array.\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const scan: {\n /**\n * Accumulates values from an `Iterable` starting from the left, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.scan(numbers, 0, (acc, value) => acc + value)\n * assert.deepStrictEqual(result, [0, 1, 3, 6, 10])\n *\n * // Explanation:\n * // This function starts with the initial value (0 in this case)\n * // and adds each element of the array to this accumulator one by one,\n * // keeping track of the cumulative sum after each addition.\n * // Each of these sums is captured in the resulting array.\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A) => B): (self: Iterable<A>) => NonEmptyArray<B>\n /**\n * Accumulates values from an `Iterable` starting from the left, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.scan(numbers, 0, (acc, value) => acc + value)\n * assert.deepStrictEqual(result, [0, 1, 3, 6, 10])\n *\n * // Explanation:\n * // This function starts with the initial value (0 in this case)\n * // and adds each element of the array to this accumulator one by one,\n * // keeping track of the cumulative sum after each addition.\n * // Each of these sums is captured in the resulting array.\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B>\n} = dual(3, <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B> => {\n const out: NonEmptyArray<B> = [b]\n let i = 0\n for (const a of self) {\n out[i + 1] = f(out[i], a)\n i++\n }\n return out\n})\n\n/**\n * Accumulates values from an `Iterable` starting from the right, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.scanRight(numbers, 0, (acc, value) => acc + value)\n * assert.deepStrictEqual(result, [10, 9, 7, 4, 0])\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const scanRight: {\n /**\n * Accumulates values from an `Iterable` starting from the right, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.scanRight(numbers, 0, (acc, value) => acc + value)\n * assert.deepStrictEqual(result, [10, 9, 7, 4, 0])\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A) => B): (self: Iterable<A>) => NonEmptyArray<B>\n /**\n * Accumulates values from an `Iterable` starting from the right, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.scanRight(numbers, 0, (acc, value) => acc + value)\n * assert.deepStrictEqual(result, [10, 9, 7, 4, 0])\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B>\n} = dual(3, <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B> => {\n const input = fromIterable(self)\n const out: NonEmptyArray<B> = new Array(input.length + 1) as any\n out[input.length] = b\n for (let i = input.length - 1; i >= 0; i--) {\n out[i] = f(out[i + 1], input[i])\n }\n return out\n})\n\n/**\n * Determine if `unknown` is an Array.\n *\n * @param self - The value to check.\n *\n * @example\n * ```ts\n * import { isArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isArray(null), false);\n * assert.deepStrictEqual(isArray([1, 2, 3]), true);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isArray: {\n /**\n * Determine if `unknown` is an Array.\n *\n * @param self - The value to check.\n *\n * @example\n * ```ts\n * import { isArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isArray(null), false);\n * assert.deepStrictEqual(isArray([1, 2, 3]), true);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\n (self: unknown): self is Array<unknown>\n /**\n * Determine if `unknown` is an Array.\n *\n * @param self - The value to check.\n *\n * @example\n * ```ts\n * import { isArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isArray(null), false);\n * assert.deepStrictEqual(isArray([1, 2, 3]), true);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\n <T>(self: T): self is Extract<T, ReadonlyArray<any>>\n} = Array.isArray\n\n/**\n * Determine if an `Array` is empty narrowing down the type to `[]`.\n *\n * @param self - The `Array` to check.\n *\n * @example\n * ```ts\n * import { isEmptyArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isEmptyArray([]), true);\n * assert.deepStrictEqual(isEmptyArray([1, 2, 3]), false);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isEmptyArray = <A>(self: Array<A>): self is [] => self.length === 0\n\n/**\n * Determine if a `ReadonlyArray` is empty narrowing down the type to `readonly []`.\n *\n * @param self - The `ReadonlyArray` to check.\n *\n * @example\n * ```ts\n * import { isEmptyReadonlyArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isEmptyReadonlyArray([]), true);\n * assert.deepStrictEqual(isEmptyReadonlyArray([1, 2, 3]), false);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isEmptyReadonlyArray: <A>(self: ReadonlyArray<A>) => self is readonly [] = isEmptyArray as any\n\n/**\n * Determine if an `Array` is non empty narrowing down the type to `NonEmptyArray`.\n *\n * An `Array` is considered to be a `NonEmptyArray` if it contains at least one element.\n *\n * @param self - The `Array` to check.\n *\n * @example\n * ```ts\n * import { isNonEmptyArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isNonEmptyArray([]), false);\n * assert.deepStrictEqual(isNonEmptyArray([1, 2, 3]), true);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNonEmptyArray: <A>(self: Array<A>) => self is NonEmptyArray<A> = readonlyArray.isNonEmptyArray\n\n/**\n * Determine if a `ReadonlyArray` is non empty narrowing down the type to `NonEmptyReadonlyArray`.\n *\n * A `ReadonlyArray` is considered to be a `NonEmptyReadonlyArray` if it contains at least one element.\n *\n * @param self - The `ReadonlyArray` to check.\n *\n * @example\n * ```ts\n * import { isNonEmptyReadonlyArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isNonEmptyReadonlyArray([]), false);\n * assert.deepStrictEqual(isNonEmptyReadonlyArray([1, 2, 3]), true);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNonEmptyReadonlyArray: <A>(self: ReadonlyArray<A>) => self is NonEmptyReadonlyArray<A> =\n readonlyArray.isNonEmptyArray\n\n/**\n * Return the number of elements in a `ReadonlyArray`.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const length = <A>(self: ReadonlyArray<A>): number => self.length\n\nconst isOutOfBound = <A>(i: number, as: ReadonlyArray<A>): boolean => i < 0 || i >= as.length\n\nconst clamp = <A>(i: number, as: ReadonlyArray<A>): number => Math.floor(Math.min(Math.max(0, i), as.length))\n\n/**\n * This function provides a safe way to read a value at a particular index from a `ReadonlyArray`.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const get: {\n /**\n * This function provides a safe way to read a value at a particular index from a `ReadonlyArray`.\n *\n * @category getters\n * @since 2.0.0\n */\n (index: number): <A>(self: ReadonlyArray<A>) => Option<A>\n /**\n * This function provides a safe way to read a value at a particular index from a `ReadonlyArray`.\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: ReadonlyArray<A>, index: number): Option<A>\n} = dual(2, <A>(self: ReadonlyArray<A>, index: number): Option<A> => {\n const i = Math.floor(index)\n return isOutOfBound(i, self) ? O.none() : O.some(self[i])\n})\n\n/**\n * Gets an element unsafely, will throw on out of bounds.\n *\n * @since 2.0.0\n * @category unsafe\n */\nexport const unsafeGet: {\n /**\n * Gets an element unsafely, will throw on out of bounds.\n *\n * @since 2.0.0\n * @category unsafe\n */\n (index: number): <A>(self: ReadonlyArray<A>) => A\n /**\n * Gets an element unsafely, will throw on out of bounds.\n *\n * @since 2.0.0\n * @category unsafe\n */\n <A>(self: ReadonlyArray<A>, index: number): A\n} = dual(2, <A>(self: ReadonlyArray<A>, index: number): A => {\n const i = Math.floor(index)\n if (isOutOfBound(i, self)) {\n throw new Error(`Index ${i} out of bounds`)\n }\n return self[i]\n})\n\n/**\n * Return a tuple containing the first element, and a new `Array` of the remaining elements, if any.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.unprepend([1, 2, 3, 4])\n * assert.deepStrictEqual(result, [1, [2, 3, 4]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const unprepend = <A>(\n self: NonEmptyReadonlyArray<A>\n): [firstElement: A, remainingElements: Array<A>] => [headNonEmpty(self), tailNonEmpty(self)]\n\n/**\n * Return a tuple containing a copy of the `NonEmptyReadonlyArray` without its last element, and that last element.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.unappend([1, 2, 3, 4])\n * assert.deepStrictEqual(result, [[1, 2, 3], 4])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const unappend = <A>(\n self: NonEmptyReadonlyArray<A>\n): [arrayWithoutLastElement: Array<A>, lastElement: A] => [initNonEmpty(self), lastNonEmpty(self)]\n\n/**\n * Get the first element of a `ReadonlyArray`, or `None` if the `ReadonlyArray` is empty.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const head: <A>(self: ReadonlyArray<A>) => Option<A> = get(0)\n\n/**\n * Get the first element of a non empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.headNonEmpty([1, 2, 3, 4])\n * assert.deepStrictEqual(result, 1)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const headNonEmpty: <A>(self: NonEmptyReadonlyArray<A>) => A = unsafeGet(0)\n\n/**\n * Get the last element in a `ReadonlyArray`, or `None` if the `ReadonlyArray` is empty.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const last = <A>(self: ReadonlyArray<A>): Option<A> =>\n isNonEmptyReadonlyArray(self) ? O.some(lastNonEmpty(self)) : O.none()\n\n/**\n * Get the last element of a non empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.lastNonEmpty([1, 2, 3, 4])\n * assert.deepStrictEqual(result, 4)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const lastNonEmpty = <A>(self: NonEmptyReadonlyArray<A>): A => self[self.length - 1]\n\n/**\n * Get all but the first element of an `Iterable`, creating a new `Array`, or `None` if the `Iterable` is empty.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const tail = <A>(self: Iterable<A>): Option<Array<A>> => {\n const input = fromIterable(self)\n return isNonEmptyReadonlyArray(input) ? O.some(tailNonEmpty(input)) : O.none()\n}\n\n/**\n * Get all but the first element of a `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.tailNonEmpty([1, 2, 3, 4])\n * assert.deepStrictEqual(result, [2, 3, 4])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const tailNonEmpty = <A>(self: NonEmptyReadonlyArray<A>): Array<A> => self.slice(1)\n\n/**\n * Get all but the last element of an `Iterable`, creating a new `Array`, or `None` if the `Iterable` is empty.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const init = <A>(self: Iterable<A>): Option<Array<A>> => {\n const input = fromIterable(self)\n return isNonEmptyReadonlyArray(input) ? O.some(initNonEmpty(input)) : O.none()\n}\n\n/**\n * Get all but the last element of a non empty array, creating a new array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.initNonEmpty([1, 2, 3, 4])\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const initNonEmpty = <A>(self: NonEmptyReadonlyArray<A>): Array<A> => self.slice(0, -1)\n\n/**\n * Keep only a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.take(numbers, 3)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const take: {\n /**\n * Keep only a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.take(numbers, 3)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Keep only a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.take(numbers, 3)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n return input.slice(0, clamp(n, input))\n})\n\n/**\n * Keep only a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.takeRight(numbers, 3)\n * assert.deepStrictEqual(result, [3, 4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const takeRight: {\n /**\n * Keep only a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.takeRight(numbers, 3)\n * assert.deepStrictEqual(result, [3, 4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Keep only a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.takeRight(numbers, 3)\n * assert.deepStrictEqual(result, [3, 4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n const i = clamp(n, input)\n return i === 0 ? [] : input.slice(-i)\n})\n\n/**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 3, 2, 4, 1, 2]\n * const result = Array.takeWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [1, 3, 2])\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const takeWhile: {\n /**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 3, 2, 4, 1, 2]\n * const result = Array.takeWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [1, 3, 2])\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Array<B>\n /**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 3, 2, 4, 1, 2]\n * const result = Array.takeWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [1, 3, 2])\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Array<A>\n /**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 3, 2, 4, 1, 2]\n * const result = Array.takeWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [1, 3, 2])\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Array<B>\n /**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 3, 2, 4, 1, 2]\n * const result = Array.takeWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [1, 3, 2])\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A>\n} = dual(2, <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A> => {\n let i = 0\n const out: Array<A> = []\n for (const a of self) {\n if (!predicate(a, i)) {\n break\n }\n out.push(a)\n i++\n }\n return out\n})\n\nconst spanIndex = <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): number => {\n let i = 0\n for (const a of self) {\n if (!predicate(a, i)) {\n break\n }\n i++\n }\n return i\n}\n\n/**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const span: {\n /**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\n <A, B extends A>(\n refinement: (a: NoInfer<A>, i: number) => a is B\n ): (self: Iterable<A>) => [init: Array<B>, rest: Array<Exclude<A, B>>]\n /**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => [init: Array<A>, rest: Array<A>]\n /**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\n <A, B extends A>(\n self: Iterable<A>,\n refinement: (a: A, i: number) => a is B\n ): [init: Array<B>, rest: Array<Exclude<A, B>>]\n /**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [init: Array<A>, rest: Array<A>]\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [init: Array<A>, rest: Array<A>] =>\n splitAt(self, spanIndex(self, predicate))\n)\n\n/**\n * Drop a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.drop(numbers, 2)\n * assert.deepStrictEqual(result, [3, 4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const drop: {\n /**\n * Drop a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.drop(numbers, 2)\n * assert.deepStrictEqual(result, [3, 4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Drop a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.drop(numbers, 2)\n * assert.deepStrictEqual(result, [3, 4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n return input.slice(clamp(n, input), input.length)\n})\n\n/**\n * Drop a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.dropRight(numbers, 2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const dropRight: {\n /**\n * Drop a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.dropRight(numbers, 2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Drop a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.dropRight(numbers, 2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n return input.slice(0, input.length - clamp(n, input))\n})\n\n/**\n * Remove the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.dropWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const dropWhile: {\n /**\n * Remove the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.dropWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Array<A>\n /**\n * Remove the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.dropWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A>\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A> =>\n fromIterable(self).slice(spanIndex(self, predicate))\n)\n\n/**\n * Return the first index for which a predicate holds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [5, 3, 8, 9]\n * const result = Array.findFirstIndex(numbers, x => x > 5)\n * assert.deepStrictEqual(result, Option.some(2))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findFirstIndex: {\n /**\n * Return the first index for which a predicate holds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [5, 3, 8, 9]\n * const result = Array.findFirstIndex(numbers, x => x > 5)\n * assert.deepStrictEqual(result, Option.some(2))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option<number>\n /**\n * Return the first index for which a predicate holds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [5, 3, 8, 9]\n * const result = Array.findFirstIndex(numbers, x => x > 5)\n * assert.deepStrictEqual(result, Option.some(2))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<number>\n} = dual(2, <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<number> => {\n let i = 0\n for (const a of self) {\n if (predicate(a, i)) {\n return O.some(i)\n }\n i++\n }\n return O.none()\n})\n\n/**\n * Return the last index for which a predicate holds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 3, 8, 9]\n * const result = Array.findLastIndex(numbers, x => x < 5)\n * assert.deepStrictEqual(result, Option.some(1))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findLastIndex: {\n /**\n * Return the last index for which a predicate holds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 3, 8, 9]\n * const result = Array.findLastIndex(numbers, x => x < 5)\n * assert.deepStrictEqual(result, Option.some(1))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option<number>\n /**\n * Return the last index for which a predicate holds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 3, 8, 9]\n * const result = Array.findLastIndex(numbers, x => x < 5)\n * assert.deepStrictEqual(result, Option.some(1))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<number>\n} = dual(2, <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<number> => {\n const input = fromIterable(self)\n for (let i = input.length - 1; i >= 0; i--) {\n if (predicate(input[i], i)) {\n return O.some(i)\n }\n }\n return O.none()\n})\n\n/**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findFirst: {\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(f: (a: NoInfer<A>, i: number) => Option<B>): (self: Iterable<A>) => Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option<A>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<A>\n} = EffectIterable.findFirst\n\n/**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findLast: {\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(f: (a: NoInfer<A>, i: number) => Option<B>): (self: Iterable<A>) => Option<B>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Option<B>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option<A>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Option<B>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Option<B>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<A>\n} = dual(\n 2,\n <A>(self: Iterable<A>, f: ((a: A, i: number) => boolean) | ((a: A, i: number) => Option<A>)): Option<A> => {\n const input = fromIterable(self)\n for (let i = input.length - 1; i >= 0; i--) {\n const a = input[i]\n const o = f(a, i)\n if (isBoolean(o)) {\n if (o) {\n return O.some(a)\n }\n } else {\n if (O.isSome(o)) {\n return o\n }\n }\n }\n return O.none()\n }\n)\n\n/**\n * Insert an element at the specified index, creating a new `NonEmptyArray`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'e']\n * const result = Array.insertAt(letters, 3, 'd')\n * assert.deepStrictEqual(result, Option.some(['a', 'b', 'c', 'd', 'e']))\n * ```\n *\n * @since 2.0.0\n */\nexport const insertAt: {\n /**\n * Insert an element at the specified index, creating a new `NonEmptyArray`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'e']\n * const result = Array.insertAt(letters, 3, 'd')\n * assert.deepStrictEqual(result, Option.some(['a', 'b', 'c', 'd', 'e']))\n * ```\n *\n * @since 2.0.0\n */\n <B>(i: number, b: B): <A>(self: Iterable<A>) => Option<NonEmptyArray<A | B>>\n /**\n * Insert an element at the specified index, creating a new `NonEmptyArray`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'e']\n * const result = Array.insertAt(letters, 3, 'd')\n * assert.deepStrictEqual(result, Option.some(['a', 'b', 'c', 'd', 'e']))\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, i: number, b: B): Option<NonEmptyArray<A | B>>\n} = dual(3, <A, B>(self: Iterable<A>, i: number, b: B): Option<NonEmptyArray<A | B>> => {\n const out: Array<A | B> = Array.from(self)\n // v--- `= self.length` is ok, it means inserting in last position\n if (i < 0 || i > out.length) {\n return O.none()\n }\n out.splice(i, 0, b)\n return O.some(out) as any\n})\n\n/**\n * Change the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.replace(letters, 1, 'z')\n * assert.deepStrictEqual(result, ['a', 'z', 'c', 'd'])\n * ```\n *\n * @since 2.0.0\n */\nexport const replace: {\n /**\n * Change the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.replace(letters, 1, 'z')\n * assert.deepStrictEqual(result, ['a', 'z', 'c', 'd'])\n * ```\n *\n * @since 2.0.0\n */\n <B>(i: number, b: B): <A, S extends Iterable<A> = Iterable<A>>(\n self: S\n ) => ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n /**\n * Change the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.replace(letters, 1, 'z')\n * assert.deepStrictEqual(result, ['a', 'z', 'c', 'd'])\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(\n self: S,\n i: number,\n b: B\n ): ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n} = dual(3, <A, B>(self: Iterable<A>, i: number, b: B): Array<A | B> => modify(self, i, () => b))\n\n/**\n * Replaces an element in an array with the given value, returning an option of the updated array.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.replaceOption(numbers, 1, 4)\n * assert.deepStrictEqual(result, Option.some([1, 4, 3]))\n * ```\n *\n * @since 2.0.0\n */\nexport const replaceOption: {\n /**\n * Replaces an element in an array with the given value, returning an option of the updated array.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.replaceOption(numbers, 1, 4)\n * assert.deepStrictEqual(result, Option.some([1, 4, 3]))\n * ```\n *\n * @since 2.0.0\n */\n <B>(\n i: number,\n b: B\n ): <A, S extends Iterable<A> = Iterable<A>>(self: S) => Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>\n /**\n * Replaces an element in an array with the given value, returning an option of the updated array.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.replaceOption(numbers, 1, 4)\n * assert.deepStrictEqual(result, Option.some([1, 4, 3]))\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(\n self: S,\n i: number,\n b: B\n ): Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>\n} = dual(\n 3,\n <A, B>(self: Iterable<A>, i: number, b: B): Option<Array<A | B>> => modifyOption(self, i, () => b)\n)\n\n/**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.modify(numbers, 2, (n) => n * 2)\n * assert.deepStrictEqual(result, [1, 2, 6, 4])\n * ```\n *\n * @since 2.0.0\n */\nexport const modify: {\n /**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.modify(numbers, 2, (n) => n * 2)\n * assert.deepStrictEqual(result, [1, 2, 6, 4])\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(\n i: number,\n f: (a: ReadonlyArray.Infer<S>) => B\n ): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n /**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.modify(numbers, 2, (n) => n * 2)\n * assert.deepStrictEqual(result, [1, 2, 6, 4])\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(\n self: S,\n i: number,\n f: (a: ReadonlyArray.Infer<S>) => B\n ): ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n} = dual(\n 3,\n <A, B>(self: Iterable<A>, i: number, f: (a: A) => B): Array<A | B> =>\n O.getOrElse(modifyOption(self, i, f), () => Array.from(self))\n)\n\n/**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.modifyOption(numbers, 2, (n) => n * 2)\n * assert.deepStrictEqual(result, Option.some([1, 2, 6, 4]))\n *\n * const outOfBoundsResult = Array.modifyOption(numbers, 5, (n) => n * 2)\n * assert.deepStrictEqual(outOfBoundsResult, Option.none())\n * ```\n *\n * @since 2.0.0\n */\nexport const modifyOption: {\n /**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.modifyOption(numbers, 2, (n) => n * 2)\n * assert.deepStrictEqual(result, Option.some([1, 2, 6, 4]))\n *\n * const outOfBoundsResult = Array.modifyOption(numbers, 5, (n) => n * 2)\n * assert.deepStrictEqual(outOfBoundsResult, Option.none())\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(\n i: number,\n f: (a: ReadonlyArray.Infer<S>) => B\n ): (self: S) => Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>\n /**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.modifyOption(numbers, 2, (n) => n * 2)\n * assert.deepStrictEqual(result, Option.some([1, 2, 6, 4]))\n *\n * const outOfBoundsResult = Array.modifyOption(numbers, 5, (n) => n * 2)\n * assert.deepStrictEqual(outOfBoundsResult, Option.none())\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(\n self: S,\n i: number,\n f: (a: ReadonlyArray.Infer<S>) => B\n ): Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>\n} = dual(3, <A, B>(self: Iterable<A>, i: number, f: (a: A) => B): Option<Array<A | B>> => {\n const out = Array.from(self)\n if (isOutOfBound(i, out)) {\n return O.none()\n }\n const next = f(out[i])\n // @ts-expect-error\n out[i] = next\n return O.some(out)\n})\n\n/**\n * Delete the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.remove(numbers, 2)\n * assert.deepStrictEqual(result, [1, 2, 4])\n *\n * const outOfBoundsResult = Array.remove(numbers, 5)\n * assert.deepStrictEqual(outOfBoundsResult, [1, 2, 3, 4])\n * ```\n *\n * @since 2.0.0\n */\nexport const remove: {\n /**\n * Delete the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.remove(numbers, 2)\n * assert.deepStrictEqual(result, [1, 2, 4])\n *\n * const outOfBoundsResult = Array.remove(numbers, 5)\n * assert.deepStrictEqual(outOfBoundsResult, [1, 2, 3, 4])\n * ```\n *\n * @since 2.0.0\n */\n (i: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Delete the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.remove(numbers, 2)\n * assert.deepStrictEqual(result, [1, 2, 4])\n *\n * const outOfBoundsResult = Array.remove(numbers, 5)\n * assert.deepStrictEqual(outOfBoundsResult, [1, 2, 3, 4])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, i: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, i: number): Array<A> => {\n const out = Array.from(self)\n if (isOutOfBound(i, out)) {\n return out\n }\n out.splice(i, 1)\n return out\n})\n\n/**\n * Reverse an `Iterable`, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.reverse(numbers)\n * assert.deepStrictEqual(result, [4, 3, 2, 1])\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const reverse = <S extends Iterable<any> | NonEmptyReadonlyArray<any>>(\n self: S\n): S extends NonEmptyReadonlyArray<infer A> ? NonEmptyArray<A> : S extends Iterable<infer A> ? Array<A> : never =>\n Array.from(self).reverse() as any\n\n/**\n * Create a new array with elements sorted in increasing order based on the specified comparator.\n * If the input is a `NonEmptyReadonlyArray`, the output will also be a `NonEmptyReadonlyArray`.\n *\n * @category sorting\n * @since 2.0.0\n */\nexport const sort: {\n /**\n * Create a new array with elements sorted in increasing order based on the specified comparator.\n * If the input is a `NonEmptyReadonlyArray`, the output will also be a `NonEmptyReadonlyArray`.\n *\n * @category sorting\n * @since 2.0.0\n */\n <B>(\n O: Order.Order<B>\n ): <A extends B, S extends ReadonlyArray<A> | Iterable<A>>(self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * Create a new array with elements sorted in increasing order based on the specified comparator.\n * If the input is a `NonEmptyReadonlyArray`, the output will also be a `NonEmptyReadonlyArray`.\n *\n * @category sorting\n * @since 2.0.0\n */\n <A extends B, B>(self: NonEmptyReadonlyArray<A>, O: Order.Order<B>): NonEmptyArray<A>\n /**\n * Create a new array with elements sorted in increasing order based on the specified comparator.\n * If the input is a `NonEmptyReadonlyArray`, the output will also be a `NonEmptyReadonlyArray`.\n *\n * @category sorting\n * @since 2.0.0\n */\n <A extends B, B>(self: Iterable<A>, O: Order.Order<B>): Array<A>\n} = dual(2, <A extends B, B>(self: Iterable<A>, O: Order.Order<B>): Array<A> => {\n const out = Array.from(self)\n out.sort(O)\n return out\n})\n\n/**\n * Sorts an array based on a provided mapping function and order. The mapping\n * function transforms the elements into a value that can be compared, and the\n * order defines how those values should be sorted.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const strings = [\"aaa\", \"b\", \"cc\"]\n * const result = Array.sortWith(strings, (s) => s.length, Order.number)\n * assert.deepStrictEqual(result, [\"b\", \"cc\", \"aaa\"])\n *\n * // Explanation:\n * // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`\n * // converts each string into its length, and the `Order.number` specifies that the lengths should\n * // be sorted in ascending order.\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\nexport const sortWith: {\n /**\n * Sorts an array based on a provided mapping function and order. The mapping\n * function transforms the elements into a value that can be compared, and the\n * order defines how those values should be sorted.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const strings = [\"aaa\", \"b\", \"cc\"]\n * const result = Array.sortWith(strings, (s) => s.length, Order.number)\n * assert.deepStrictEqual(result, [\"b\", \"cc\", \"aaa\"])\n *\n * // Explanation:\n * // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`\n * // converts each string into its length, and the `Order.number` specifies that the lengths should\n * // be sorted in ascending order.\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <S extends Iterable<any> | NonEmptyReadonlyArray<any>, B>(\n f: (a: ReadonlyArray.Infer<S>) => B,\n order: Order.Order<B>\n ): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * Sorts an array based on a provided mapping function and order. The mapping\n * function transforms the elements into a value that can be compared, and the\n * order defines how those values should be sorted.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const strings = [\"aaa\", \"b\", \"cc\"]\n * const result = Array.sortWith(strings, (s) => s.length, Order.number)\n * assert.deepStrictEqual(result, [\"b\", \"cc\", \"aaa\"])\n *\n * // Explanation:\n * // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`\n * // converts each string into its length, and the `Order.number` specifies that the lengths should\n * // be sorted in ascending order.\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B, O: Order.Order<B>): NonEmptyArray<A>\n /**\n * Sorts an array based on a provided mapping function and order. The mapping\n * function transforms the elements into a value that can be compared, and the\n * order defines how those values should be sorted.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const strings = [\"aaa\", \"b\", \"cc\"]\n * const result = Array.sortWith(strings, (s) => s.length, Order.number)\n * assert.deepStrictEqual(result, [\"b\", \"cc\", \"aaa\"])\n *\n * // Explanation:\n * // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`\n * // converts each string into its length, and the `Order.number` specifies that the lengths should\n * // be sorted in ascending order.\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B>(self: Iterable<A>, f: (a: A) => B, order: Order.Order<B>): Array<A>\n} = dual(\n 3,\n <A, B>(self: Iterable<A>, f: (a: A) => B, order: Order.Order<B>): Array<A> =>\n Array.from(self).map((a) => [a, f(a)] as const).sort((a, b) => order(a[1], b[1])).map((x) => x[0])\n)\n\n/**\n * Sorts the elements of an `Iterable` in increasing order based on the provided\n * orders. The elements are compared using the first order in `orders`, then the\n * second order if the first comparison is equal, and so on.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const users = [\n * { name: \"Alice\", age: 30 },\n * { name: \"Bob\", age: 25 },\n * { name: \"Charlie\", age: 30 }\n * ]\n *\n * const result = Array.sortBy(\n * Order.mapInput(Order.number, (user: (typeof users)[number]) => user.age),\n * Order.mapInput(Order.string, (user: (typeof users)[number]) => user.name)\n * )(users)\n *\n * assert.deepStrictEqual(result, [\n * { name: \"Bob\", age: 25 },\n * { name: \"Alice\", age: 30 },\n * { name: \"Charlie\", age: 30 }\n * ])\n *\n * // Explanation:\n * // The array of users is sorted first by age in ascending order. When ages are equal,\n * // the users are further sorted by name in ascending order.\n * ```\n *\n * @category sorting\n * @since 2.0.0\n */\nexport const sortBy = <S extends Iterable<any> | NonEmptyReadonlyArray<any>>(\n ...orders: ReadonlyArray<Order.Order<ReadonlyArray.Infer<S>>>\n) => {\n const sortByAll = sort(Order.combineAll(orders))\n return (\n self: S\n ): S extends NonEmptyReadonlyArray<infer A> ? NonEmptyArray<A> : S extends Iterable<infer A> ? Array<A> : never => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n return sortByAll(input) as any\n }\n return [] as any\n }\n}\n\n/**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = ['a', 'b']\n * const result = Array.zip(array1, array2)\n * assert.deepStrictEqual(result, [[1, 'a'], [2, 'b']])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\nexport const zip: {\n /**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = ['a', 'b']\n * const result = Array.zip(array1, array2)\n * assert.deepStrictEqual(result, [[1, 'a'], [2, 'b']])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B>(that: NonEmptyReadonlyArray<B>): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<[A, B]>\n /**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = ['a', 'b']\n * const result = Array.zip(array1, array2)\n * assert.deepStrictEqual(result, [[1, 'a'], [2, 'b']])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B>(that: Iterable<B>): <A>(self: Iterable<A>) => Array<[A, B]>\n /**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = ['a', 'b']\n * const result = Array.zip(array1, array2)\n * assert.deepStrictEqual(result, [[1, 'a'], [2, 'b']])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<[A, B]>\n /**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = ['a', 'b']\n * const result = Array.zip(array1, array2)\n * assert.deepStrictEqual(result, [[1, 'a'], [2, 'b']])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<[A, B]>\n} = dual(\n 2,\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<[A, B]> => zipWith(self, that, Tuple.make)\n)\n\n/**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [4, 5, 6]\n * const result = Array.zipWith(array1, array2, (a, b) => a + b)\n * assert.deepStrictEqual(result, [5, 7, 9])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\nexport const zipWith: {\n /**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [4, 5, 6]\n * const result = Array.zipWith(array1, array2, (a, b) => a + b)\n * assert.deepStrictEqual(result, [5, 7, 9])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B, A, C>(that: NonEmptyReadonlyArray<B>, f: (a: A, b: B) => C): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<C>\n /**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [4, 5, 6]\n * const result = Array.zipWith(array1, array2, (a, b) => a + b)\n * assert.deepStrictEqual(result, [5, 7, 9])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Array<C>\n /**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [4, 5, 6]\n * const result = Array.zipWith(array1, array2, (a, b) => a + b)\n * assert.deepStrictEqual(result, [5, 7, 9])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, B, C>(\n self: NonEmptyReadonlyArray<A>,\n that: NonEmptyReadonlyArray<B>,\n f: (a: A, b: B) => C\n ): NonEmptyArray<C>\n /**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [4, 5, 6]\n * const result = Array.zipWith(array1, array2, (a, b) => a + b)\n * assert.deepStrictEqual(result, [5, 7, 9])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C>\n} = dual(3, <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C> => {\n const as = fromIterable(self)\n const bs = fromIterable(that)\n if (isNonEmptyReadonlyArray(as) && isNonEmptyReadonlyArray(bs)) {\n const out: NonEmptyArray<C> = [f(headNonEmpty(as), headNonEmpty(bs))]\n const len = Math.min(as.length, bs.length)\n for (let i = 1; i < len; i++) {\n out[i] = f(as[i], bs[i])\n }\n return out\n }\n return []\n})\n\n/**\n * This function is the inverse of `zip`. Takes an `Iterable` of pairs and return two corresponding `Array`s.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.unzip([[1, \"a\"], [2, \"b\"], [3, \"c\"]])\n * assert.deepStrictEqual(result, [[1, 2, 3], ['a', 'b', 'c']])\n * ```\n *\n * @since 2.0.0\n */\nexport const unzip: <S extends Iterable<readonly [any, any]> | NonEmptyReadonlyArray<readonly [any, any]>>(\n self: S\n) => S extends NonEmptyReadonlyArray<readonly [infer A, infer B]> ? [NonEmptyArray<A>, NonEmptyArray<B>]\n : S extends Iterable<readonly [infer A, infer B]> ? [Array<A>, Array<B>]\n : never = (<A, B>(self: Iterable<readonly [A, B]>): [Array<A>, Array<B>] => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const fa: NonEmptyArray<A> = [input[0][0]]\n const fb: NonEmptyArray<B> = [input[0][1]]\n for (let i = 1; i < input.length; i++) {\n fa[i] = input[i][0]\n fb[i] = input[i][1]\n }\n return [fa, fb]\n }\n return [[], []]\n }) as any\n\n/**\n * Places an element in between members of an `Iterable`.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.intersperse(numbers, 0)\n * assert.deepStrictEqual(result, [1, 0, 2, 0, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const intersperse: {\n /**\n * Places an element in between members of an `Iterable`.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.intersperse(numbers, 0)\n * assert.deepStrictEqual(result, [1, 0, 2, 0, 3])\n * ```\n *\n * @since 2.0.0\n */\n <B>(middle: B): <S extends Iterable<any>>(self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n /**\n * Places an element in between members of an `Iterable`.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.intersperse(numbers, 0)\n * assert.deepStrictEqual(result, [1, 0, 2, 0, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, middle: B): NonEmptyArray<A | B>\n /**\n * Places an element in between members of an `Iterable`.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.intersperse(numbers, 0)\n * assert.deepStrictEqual(result, [1, 0, 2, 0, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, middle: B): Array<A | B>\n} = dual(2, <A, B>(self: Iterable<A>, middle: B): Array<A | B> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const out: NonEmptyArray<A | B> = [headNonEmpty(input)]\n const tail = tailNonEmpty(input)\n for (let i = 0; i < tail.length; i++) {\n if (i < tail.length) {\n out.push(middle)\n }\n out.push(tail[i])\n }\n return out\n }\n return []\n})\n\n/**\n * Apply a function to the head, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyHead([1, 2, 3], n => n * 10)\n * assert.deepStrictEqual(result, [10, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const modifyNonEmptyHead: {\n /**\n * Apply a function to the head, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyHead([1, 2, 3], n => n * 10)\n * assert.deepStrictEqual(result, [10, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>\n /**\n * Apply a function to the head, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyHead([1, 2, 3], n => n * 10)\n * assert.deepStrictEqual(result, [10, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B): NonEmptyArray<A | B>\n} = dual(\n 2,\n <A, B>(\n self: NonEmptyReadonlyArray<A>,\n f: (a: A) => B\n ): NonEmptyArray<A | B> => [f(headNonEmpty(self)), ...tailNonEmpty(self)]\n)\n\n/**\n * Change the head, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyHead([1, 2, 3], 10)\n * assert.deepStrictEqual(result, [10, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const setNonEmptyHead: {\n /**\n * Change the head, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyHead([1, 2, 3], 10)\n * assert.deepStrictEqual(result, [10, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <B>(b: B): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>\n /**\n * Change the head, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyHead([1, 2, 3], 10)\n * assert.deepStrictEqual(result, [10, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B>\n} = dual(\n 2,\n <A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B> => modifyNonEmptyHead(self, () => b)\n)\n\n/**\n * Apply a function to the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyLast([1, 2, 3], n => n * 2)\n * assert.deepStrictEqual(result, [1, 2, 6])\n * ```\n *\n * @since 2.0.0\n */\nexport const modifyNonEmptyLast: {\n /**\n * Apply a function to the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyLast([1, 2, 3], n => n * 2)\n * assert.deepStrictEqual(result, [1, 2, 6])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>\n /**\n * Apply a function to the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyLast([1, 2, 3], n => n * 2)\n * assert.deepStrictEqual(result, [1, 2, 6])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B): NonEmptyArray<A | B>\n} = dual(\n 2,\n <A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B): NonEmptyArray<A | B> =>\n append(initNonEmpty(self), f(lastNonEmpty(self)))\n)\n\n/**\n * Change the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyLast([1, 2, 3], 4)\n * assert.deepStrictEqual(result, [1, 2, 4])\n * ```\n *\n * @since 2.0.0\n */\nexport const setNonEmptyLast: {\n /**\n * Change the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyLast([1, 2, 3], 4)\n * assert.deepStrictEqual(result, [1, 2, 4])\n * ```\n *\n * @since 2.0.0\n */\n <B>(b: B): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>\n /**\n * Change the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyLast([1, 2, 3], 4)\n * assert.deepStrictEqual(result, [1, 2, 4])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B>\n} = dual(\n 2,\n <A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B> => modifyNonEmptyLast(self, () => b)\n)\n\n/**\n * Rotate an `Iterable` by `n` steps.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.rotate(letters, 2)\n * assert.deepStrictEqual(result, ['c', 'd', 'a', 'b'])\n * ```\n *\n * @since 2.0.0\n */\nexport const rotate: {\n /**\n * Rotate an `Iterable` by `n` steps.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.rotate(letters, 2)\n * assert.deepStrictEqual(result, ['c', 'd', 'a', 'b'])\n * ```\n *\n * @since 2.0.0\n */\n (n: number): <S extends Iterable<any>>(self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * Rotate an `Iterable` by `n` steps.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.rotate(letters, 2)\n * assert.deepStrictEqual(result, ['c', 'd', 'a', 'b'])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, n: number): NonEmptyArray<A>\n /**\n * Rotate an `Iterable` by `n` steps.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.rotate(letters, 2)\n * assert.deepStrictEqual(result, ['c', 'd', 'a', 'b'])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const len = input.length\n const m = Math.round(n) % len\n if (isOutOfBound(Math.abs(m), input) || m === 0) {\n return copy(input)\n }\n if (m < 0) {\n const [f, s] = splitNonEmptyAt(input, -m)\n return appendAll(s, f)\n } else {\n return rotate(self, m - len)\n }\n }\n return []\n})\n\n/**\n * Returns a function that checks if a `ReadonlyArray` contains a given value using a provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const isEquivalent = (a: number, b: number) => a === b\n * const containsNumber = Array.containsWith(isEquivalent)\n * const result = containsNumber(3)(numbers)\n * assert.deepStrictEqual(result, true)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const containsWith = <A>(isEquivalent: (self: A, that: A) => boolean): {\n (a: A): (self: Iterable<A>) => boolean\n (self: Iterable<A>, a: A): boolean\n} =>\n dual(2, (self: Iterable<A>, a: A): boolean => {\n for (const i of self) {\n if (isEquivalent(a, i)) {\n return true\n }\n }\n return false\n })\n\nconst _equivalence = Equal.equivalence()\n\n/**\n * Returns a function that checks if a `ReadonlyArray` contains a given value using the default `Equivalence`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.contains('c')(letters)\n * assert.deepStrictEqual(result, true)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const contains: {\n /**\n * Returns a function that checks if a `ReadonlyArray` contains a given value using the default `Equivalence`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.contains('c')(letters)\n * assert.deepStrictEqual(result, true)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(a: A): (self: Iterable<A>) => boolean\n /**\n * Returns a function that checks if a `ReadonlyArray` contains a given value using the default `Equivalence`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.contains('c')(letters)\n * assert.deepStrictEqual(result, true)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, a: A): boolean\n} = containsWith(_equivalence)\n\n/**\n * A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for \"chopping\" up the input\n * `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a\n * value and the rest of the `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chop(numbers, (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * assert.deepStrictEqual(result, [2, 4, 6, 8, 10])\n *\n * // Explanation:\n * // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.\n * // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,\n * // resulting in a new array `[2, 4, 6, 8, 10]`.\n * ```\n *\n * @since 2.0.0\n */\nexport const chop: {\n /**\n * A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for \"chopping\" up the input\n * `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a\n * value and the rest of the `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chop(numbers, (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * assert.deepStrictEqual(result, [2, 4, 6, 8, 10])\n *\n * // Explanation:\n * // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.\n * // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,\n * // resulting in a new array `[2, 4, 6, 8, 10]`.\n * ```\n *\n * @since 2.0.0\n */\n <S extends Iterable<any>, B>(\n f: (as: NonEmptyReadonlyArray<ReadonlyArray.Infer<S>>) => readonly [B, ReadonlyArray<ReadonlyArray.Infer<S>>]\n ): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for \"chopping\" up the input\n * `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a\n * value and the rest of the `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chop(numbers, (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * assert.deepStrictEqual(result, [2, 4, 6, 8, 10])\n *\n * // Explanation:\n * // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.\n * // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,\n * // resulting in a new array `[2, 4, 6, 8, 10]`.\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: NonEmptyReadonlyArray<A>,\n f: (as: NonEmptyReadonlyArray<A>) => readonly [B, ReadonlyArray<A>]\n ): NonEmptyArray<B>\n /**\n * A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for \"chopping\" up the input\n * `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a\n * value and the rest of the `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chop(numbers, (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * assert.deepStrictEqual(result, [2, 4, 6, 8, 10])\n *\n * // Explanation:\n * // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.\n * // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,\n * // resulting in a new array `[2, 4, 6, 8, 10]`.\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: Iterable<A>,\n f: (as: NonEmptyReadonlyArray<A>) => readonly [B, ReadonlyArray<A>]\n ): Array<B>\n} = dual(2, <A, B>(\n self: Iterable<A>,\n f: (as: NonEmptyReadonlyArray<A>) => readonly [B, ReadonlyArray<A>]\n): Array<B> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const [b, rest] = f(input)\n const out: NonEmptyArray<B> = [b]\n let next: ReadonlyArray<A> = rest\n while (readonlyArray.isNonEmptyArray(next)) {\n const [b, rest] = f(next)\n out.push(b)\n next = rest\n }\n return out\n }\n return []\n})\n\n/**\n * Splits an `Iterable` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` can be `0`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.splitAt(numbers, 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const splitAt: {\n /**\n * Splits an `Iterable` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` can be `0`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.splitAt(numbers, 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => [beforeIndex: Array<A>, fromIndex: Array<A>]\n /**\n * Splits an `Iterable` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` can be `0`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.splitAt(numbers, 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): [beforeIndex: Array<A>, fromIndex: Array<A>]\n} = dual(2, <A>(self: Iterable<A>, n: number): [Array<A>, Array<A>] => {\n const input = Array.from(self)\n const _n = Math.floor(n)\n if (isNonEmptyReadonlyArray(input)) {\n if (_n >= 1) {\n return splitNonEmptyAt(input, _n)\n }\n return [[], input]\n }\n return [input, []]\n})\n\n/**\n * Splits a `NonEmptyReadonlyArray` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` must be `>= 1`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitNonEmptyAt([\"a\", \"b\", \"c\", \"d\", \"e\"], 3)\n * assert.deepStrictEqual(result, [[\"a\", \"b\", \"c\"], [\"d\", \"e\"]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const splitNonEmptyAt: {\n /**\n * Splits a `NonEmptyReadonlyArray` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` must be `>= 1`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitNonEmptyAt([\"a\", \"b\", \"c\", \"d\", \"e\"], 3)\n * assert.deepStrictEqual(result, [[\"a\", \"b\", \"c\"], [\"d\", \"e\"]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n (n: number): <A>(self: NonEmptyReadonlyArray<A>) => [beforeIndex: NonEmptyArray<A>, fromIndex: Array<A>]\n /**\n * Splits a `NonEmptyReadonlyArray` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` must be `>= 1`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitNonEmptyAt([\"a\", \"b\", \"c\", \"d\", \"e\"], 3)\n * assert.deepStrictEqual(result, [[\"a\", \"b\", \"c\"], [\"d\", \"e\"]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, n: number): [beforeIndex: NonEmptyArray<A>, fromIndex: Array<A>]\n} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, n: number): [NonEmptyArray<A>, Array<A>] => {\n const _n = Math.max(1, Math.floor(n))\n return _n >= self.length ?\n [copy(self), []] :\n [prepend(self.slice(1, _n), headNonEmpty(self)), self.slice(_n)]\n})\n\n/**\n * Splits this iterable into `n` equally sized arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5, 6, 7, 8]\n * const result = Array.split(numbers, 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5, 6], [7, 8]])\n * ```\n *\n * @since 2.0.0\n * @category splitting\n */\nexport const split: {\n /**\n * Splits this iterable into `n` equally sized arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5, 6, 7, 8]\n * const result = Array.split(numbers, 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5, 6], [7, 8]])\n * ```\n *\n * @since 2.0.0\n * @category splitting\n */\n (n: number): <A>(self: Iterable<A>) => Array<Array<A>>\n /**\n * Splits this iterable into `n` equally sized arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5, 6, 7, 8]\n * const result = Array.split(numbers, 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5, 6], [7, 8]])\n * ```\n *\n * @since 2.0.0\n * @category splitting\n */\n <A>(self: Iterable<A>, n: number): Array<Array<A>>\n} = dual(2, <A>(self: Iterable<A>, n: number) => {\n const input = fromIterable(self)\n return chunksOf(input, Math.ceil(input.length / Math.floor(n)))\n})\n\n/**\n * Splits this iterable on the first element that matches this predicate.\n * Returns a tuple containing two arrays: the first one is before the match, and the second one is from the match onward.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.splitWhere(numbers, n => n > 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const splitWhere: {\n /**\n * Splits this iterable on the first element that matches this predicate.\n * Returns a tuple containing two arrays: the first one is before the match, and the second one is from the match onward.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.splitWhere(numbers, n => n > 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(\n predicate: (a: NoInfer<A>, i: number) => boolean\n ): (self: Iterable<A>) => [beforeMatch: Array<A>, fromMatch: Array<A>]\n /**\n * Splits this iterable on the first element that matches this predicate.\n * Returns a tuple containing two arrays: the first one is before the match, and the second one is from the match onward.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.splitWhere(numbers, n => n > 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [beforeMatch: Array<A>, fromMatch: Array<A>]\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [beforeMatch: Array<A>, fromMatch: Array<A>] =>\n span(self, (a: A, i: number) => !predicate(a, i))\n)\n\n/**\n * Copies an array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const copy = Array.copy(numbers)\n * assert.deepStrictEqual(copy, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const copy: {\n /**\n * Copies an array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const copy = Array.copy(numbers)\n * assert.deepStrictEqual(copy, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>): NonEmptyArray<A>\n /**\n * Copies an array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const copy = Array.copy(numbers)\n * assert.deepStrictEqual(copy, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: ReadonlyArray<A>): Array<A>\n} = (<A>(self: ReadonlyArray<A>): Array<A> => self.slice()) as any\n\n/**\n * Pads an array.\n * Returns a new array of length `n` with the elements of `array` followed by `fill` elements if `array` is shorter than `n`.\n * If `array` is longer than `n`, the returned array will be a slice of `array` containing the `n` first elements of `array`.\n * If `n` is less than or equal to 0, the returned array will be an empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const arr = [1, 2, 3]\n * const result = Array.pad(arr, 6, 0)\n * assert.deepStrictEqual(result, [1, 2, 3, 0, 0, 0])\n * ```\n *\n * @since 3.8.4\n */\nexport const pad: {\n /**\n * Pads an array.\n * Returns a new array of length `n` with the elements of `array` followed by `fill` elements if `array` is shorter than `n`.\n * If `array` is longer than `n`, the returned array will be a slice of `array` containing the `n` first elements of `array`.\n * If `n` is less than or equal to 0, the returned array will be an empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const arr = [1, 2, 3]\n * const result = Array.pad(arr, 6, 0)\n * assert.deepStrictEqual(result, [1, 2, 3, 0, 0, 0])\n * ```\n *\n * @since 3.8.4\n */\n <A, T>(n: number, fill: T): (\n self: Array<A>\n ) => Array<A | T>\n /**\n * Pads an array.\n * Returns a new array of length `n` with the elements of `array` followed by `fill` elements if `array` is shorter than `n`.\n * If `array` is longer than `n`, the returned array will be a slice of `array` containing the `n` first elements of `array`.\n * If `n` is less than or equal to 0, the returned array will be an empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const arr = [1, 2, 3]\n * const result = Array.pad(arr, 6, 0)\n * assert.deepStrictEqual(result, [1, 2, 3, 0, 0, 0])\n * ```\n *\n * @since 3.8.4\n */\n <A, T>(self: Array<A>, n: number, fill: T): Array<A | T>\n} = dual(3, <A, T>(self: Array<A>, n: number, fill: T): Array<A | T> => {\n if (self.length >= n) {\n return take(self, n)\n }\n return appendAll(\n self,\n makeBy(n - self.length, () => fill)\n )\n})\n\n/**\n * Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of\n * the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive\n * definition of `chunksOf`; it satisfies the property that\n *\n * ```ts\n * chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))\n * ```\n *\n * whenever `n` evenly divides the length of `self`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chunksOf(numbers, 2)\n * assert.deepStrictEqual(result, [[1, 2], [3, 4], [5]])\n *\n * // Explanation:\n * // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.\n * // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,\n * // the last chunk contains the remaining elements.\n * // The result is `[[1, 2], [3, 4], [5]]`.\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const chunksOf: {\n /**\n * Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of\n * the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive\n * definition of `chunksOf`; it satisfies the property that\n *\n * ```ts\n * chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))\n * ```\n *\n * whenever `n` evenly divides the length of `self`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chunksOf(numbers, 2)\n * assert.deepStrictEqual(result, [[1, 2], [3, 4], [5]])\n *\n * // Explanation:\n * // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.\n * // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,\n * // the last chunk contains the remaining elements.\n * // The result is `[[1, 2], [3, 4], [5]]`.\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n (n: number): <S extends Iterable<any>>(\n self: S\n ) => ReadonlyArray.With<S, NonEmptyArray<ReadonlyArray.Infer<S>>>\n /**\n * Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of\n * the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive\n * definition of `chunksOf`; it satisfies the property that\n *\n * ```ts\n * chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))\n * ```\n *\n * whenever `n` evenly divides the length of `self`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chunksOf(numbers, 2)\n * assert.deepStrictEqual(result, [[1, 2], [3, 4], [5]])\n *\n * // Explanation:\n * // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.\n * // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,\n * // the last chunk contains the remaining elements.\n * // The result is `[[1, 2], [3, 4], [5]]`.\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, n: number): NonEmptyArray<NonEmptyArray<A>>\n /**\n * Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of\n * the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive\n * definition of `chunksOf`; it satisfies the property that\n *\n * ```ts\n * chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))\n * ```\n *\n * whenever `n` evenly divides the length of `self`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chunksOf(numbers, 2)\n * assert.deepStrictEqual(result, [[1, 2], [3, 4], [5]])\n *\n * // Explanation:\n * // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.\n * // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,\n * // the last chunk contains the remaining elements.\n * // The result is `[[1, 2], [3, 4], [5]]`.\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<NonEmptyArray<A>>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<NonEmptyArray<A>> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n return chop(input, splitNonEmptyAt(n))\n }\n return []\n})\n\n/**\n * Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s using the provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.groupWith([\"a\", \"a\", \"b\", \"b\", \"b\", \"c\", \"a\"], (x, y) => x === y)\n * assert.deepStrictEqual(result, [[\"a\", \"a\"], [\"b\", \"b\", \"b\"], [\"c\"], [\"a\"]])\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\nexport const groupWith: {\n /**\n * Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s using the provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.groupWith([\"a\", \"a\", \"b\", \"b\", \"b\", \"c\", \"a\"], (x, y) => x === y)\n * assert.deepStrictEqual(result, [[\"a\", \"a\"], [\"b\", \"b\", \"b\"], [\"c\"], [\"a\"]])\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\n <A>(isEquivalent: (self: A, that: A) => boolean): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<NonEmptyArray<A>>\n /**\n * Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s using the provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.groupWith([\"a\", \"a\", \"b\", \"b\", \"b\", \"c\", \"a\"], (x, y) => x === y)\n * assert.deepStrictEqual(result, [[\"a\", \"a\"], [\"b\", \"b\", \"b\"], [\"c\"], [\"a\"]])\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\n <A>(\n self: NonEmptyReadonlyArray<A>,\n isEquivalent: (self: A, that: A) => boolean\n ): NonEmptyArray<NonEmptyArray<A>>\n} = dual(\n 2,\n <A>(self: NonEmptyReadonlyArray<A>, isEquivalent: (self: A, that: A) => boolean): NonEmptyArray<NonEmptyArray<A>> =>\n chop(self, (as) => {\n const h = headNonEmpty(as)\n const out: NonEmptyArray<A> = [h]\n let i = 1\n for (; i < as.length; i++) {\n const a = as[i]\n if (isEquivalent(a, h)) {\n out.push(a)\n } else {\n break\n }\n }\n return [out, as.slice(i)]\n })\n)\n\n/**\n * Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.group([1, 1, 2, 2, 2, 3, 1])\n * assert.deepStrictEqual(result, [[1, 1], [2, 2, 2], [3], [1]])\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\nexport const group: <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<NonEmptyArray<A>> = groupWith(\n Equal.equivalence()\n)\n\n/**\n * Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning\n * function on each element, and grouping the results according to values returned\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const people = [\n * { name: \"Alice\", group: \"A\" },\n * { name: \"Bob\", group: \"B\" },\n * { name: \"Charlie\", group: \"A\" }\n * ]\n * const result = Array.groupBy(people, person => person.group)\n * assert.deepStrictEqual(result, {\n * A: [{ name: \"Alice\", group: \"A\" }, { name: \"Charlie\", group: \"A\" }],\n * B: [{ name: \"Bob\", group: \"B\" }]\n * })\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\nexport const groupBy: {\n /**\n * Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning\n * function on each element, and grouping the results according to values returned\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const people = [\n * { name: \"Alice\", group: \"A\" },\n * { name: \"Bob\", group: \"B\" },\n * { name: \"Charlie\", group: \"A\" }\n * ]\n * const result = Array.groupBy(people, person => person.group)\n * assert.deepStrictEqual(result, {\n * A: [{ name: \"Alice\", group: \"A\" }, { name: \"Charlie\", group: \"A\" }],\n * B: [{ name: \"Bob\", group: \"B\" }]\n * })\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\n <A, K extends string | symbol>(\n f: (a: A) => K\n ): (self: Iterable<A>) => Record<Record.ReadonlyRecord.NonLiteralKey<K>, NonEmptyArray<A>>\n /**\n * Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning\n * function on each element, and grouping the results according to values returned\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const people = [\n * { name: \"Alice\", group: \"A\" },\n * { name: \"Bob\", group: \"B\" },\n * { name: \"Charlie\", group: \"A\" }\n * ]\n * const result = Array.groupBy(people, person => person.group)\n * assert.deepStrictEqual(result, {\n * A: [{ name: \"Alice\", group: \"A\" }, { name: \"Charlie\", group: \"A\" }],\n * B: [{ name: \"Bob\", group: \"B\" }]\n * })\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\n <A, K extends string | symbol>(\n self: Iterable<A>,\n f: (a: A) => K\n ): Record<Record.ReadonlyRecord.NonLiteralKey<K>, NonEmptyArray<A>>\n} = dual(2, <A, K extends string | symbol>(\n self: Iterable<A>,\n f: (a: A) => K\n): Record<Record.ReadonlyRecord.NonLiteralKey<K>, NonEmptyArray<A>> => {\n const out: Record<string | symbol, NonEmptyArray<A>> = {}\n for (const a of self) {\n const k = f(a)\n if (Object.prototype.hasOwnProperty.call(out, k)) {\n out[k].push(a)\n } else {\n out[k] = [a]\n }\n }\n return out\n})\n\n/**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const union = Array.unionWith(array1, array2, (a, b) => a === b)\n * assert.deepStrictEqual(union, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const unionWith: {\n /**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const union = Array.unionWith(array1, array2, (a, b) => a === b)\n * assert.deepStrictEqual(union, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <S extends Iterable<any>, T extends Iterable<any>>(\n that: T,\n isEquivalent: (self: ReadonlyArray.Infer<S>, that: ReadonlyArray.Infer<T>) => boolean\n ): (self: S) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>\n /**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const union = Array.unionWith(array1, array2, (a, b) => a === b)\n * assert.deepStrictEqual(union, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: NonEmptyReadonlyArray<A>,\n that: Iterable<B>,\n isEquivalent: (self: A, that: B) => boolean\n ): NonEmptyArray<A | B>\n /**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const union = Array.unionWith(array1, array2, (a, b) => a === b)\n * assert.deepStrictEqual(union, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: Iterable<A>,\n that: NonEmptyReadonlyArray<B>,\n isEquivalent: (self: A, that: B) => boolean\n ): NonEmptyArray<A | B>\n /**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const union = Array.unionWith(array1, array2, (a, b) => a === b)\n * assert.deepStrictEqual(union, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: Iterable<A>,\n that: Iterable<B>,\n isEquivalent: (self: A, that: B) => boolean\n ): Array<A | B>\n} = dual(3, <A>(self: Iterable<A>, that: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A> => {\n const a = fromIterable(self)\n const b = fromIterable(that)\n if (isNonEmptyReadonlyArray(a)) {\n if (isNonEmptyReadonlyArray(b)) {\n const dedupe = dedupeWith(isEquivalent)\n return dedupe(appendAll(a, b))\n }\n return a\n }\n return b\n})\n\n/**\n * Creates a union of two arrays, removing duplicates.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const result = Array.union(array1, array2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const union: {\n /**\n * Creates a union of two arrays, removing duplicates.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const result = Array.union(array1, array2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <T extends Iterable<any>>(that: T): <S extends Iterable<any>>(\n self: S\n ) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>\n /**\n * Creates a union of two arrays, removing duplicates.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const result = Array.union(array1, array2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, that: ReadonlyArray<B>): NonEmptyArray<A | B>\n /**\n * Creates a union of two arrays, removing duplicates.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const result = Array.union(array1, array2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: ReadonlyArray<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<A | B>\n /**\n * Creates a union of two arrays, removing duplicates.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const result = Array.union(array1, array2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B>\n} = dual(2, <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B> => unionWith(self, that, _equivalence))\n\n/**\n * Creates an `Array` of unique values that are included in all given `Iterable`s using the provided `isEquivalent` function.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }]\n * const array2 = [{ id: 3 }, { id: 4 }, { id: 1 }]\n * const isEquivalent = (a: { id: number }, b: { id: number }) => a.id === b.id\n * const result = Array.intersectionWith(isEquivalent)(array2)(array1)\n * assert.deepStrictEqual(result, [{ id: 1 }, { id: 3 }])\n * ```\n *\n * @since 2.0.0\n */\nexport const intersectionWith = <A>(isEquivalent: (self: A, that: A) => boolean): {\n (that: Iterable<A>): (self: Iterable<A>) => Array<A>\n (self: Iterable<A>, that: Iterable<A>): Array<A>\n} => {\n const has = containsWith(isEquivalent)\n return dual(\n 2,\n (self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(self).filter((a) => has(that, a))\n )\n}\n\n/**\n * Creates an `Array` of unique values that are included in all given `Iterable`s.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [3, 4, 1]\n * const result = Array.intersection(array1, array2)\n * assert.deepStrictEqual(result, [1, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const intersection: {\n /**\n * Creates an `Array` of unique values that are included in all given `Iterable`s.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [3, 4, 1]\n * const result = Array.intersection(array1, array2)\n * assert.deepStrictEqual(result, [1, 3])\n * ```\n *\n * @since 2.0.0\n */\n <B>(that: Iterable<B>): <A>(self: Iterable<A>) => Array<A & B>\n /**\n * Creates an `Array` of unique values that are included in all given `Iterable`s.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [3, 4, 1]\n * const result = Array.intersection(array1, array2)\n * assert.deepStrictEqual(result, [1, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A & B>\n} = intersectionWith(_equivalence)\n\n/**\n * Creates a `Array` of values not included in the other given `Iterable` using the provided `isEquivalent` function.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [2, 3, 4]\n * const difference = Array.differenceWith<number>((a, b) => a === b)(array1, array2)\n * assert.deepStrictEqual(difference, [1])\n * ```\n *\n * @since 2.0.0\n */\nexport const differenceWith = <A>(isEquivalent: (self: A, that: A) => boolean): {\n (that: Iterable<A>): (self: Iterable<A>) => Array<A>\n (self: Iterable<A>, that: Iterable<A>): Array<A>\n} => {\n const has = containsWith(isEquivalent)\n return dual(\n 2,\n (self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(self).filter((a) => !has(that, a))\n )\n}\n\n/**\n * Creates a `Array` of values not included in the other given `Iterable`.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [2, 3, 4]\n * const difference = Array.difference(array1, array2)\n * assert.deepStrictEqual(difference, [1])\n * ```\n *\n * @since 2.0.0\n */\nexport const difference: {\n /**\n * Creates a `Array` of values not included in the other given `Iterable`.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [2, 3, 4]\n * const difference = Array.difference(array1, array2)\n * assert.deepStrictEqual(difference, [1])\n * ```\n *\n * @since 2.0.0\n */\n <A>(that: Iterable<A>): (self: Iterable<A>) => Array<A>\n /**\n * Creates a `Array` of values not included in the other given `Iterable`.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [2, 3, 4]\n * const difference = Array.difference(array1, array2)\n * assert.deepStrictEqual(difference, [1])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, that: Iterable<A>): Array<A>\n} = differenceWith(_equivalence)\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const empty: <A = never>() => Array<A> = () => []\n\n/**\n * Constructs a new `NonEmptyArray<A>` from the specified value.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const of = <A>(a: A): NonEmptyArray<A> => [a]\n\n/**\n * @since 2.0.0\n */\nexport declare namespace ReadonlyArray {\n /**\n * @since 2.0.0\n */\n export type Infer<S extends Iterable<any>> = S extends ReadonlyArray<infer A> ? A\n : S extends Iterable<infer A> ? A\n : never\n\n /**\n * @since 2.0.0\n */\n export type With<S extends Iterable<any>, A> = S extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>\n : Array<A>\n\n /**\n * @since 2.0.0\n */\n export type OrNonEmpty<\n S extends Iterable<any>,\n T extends Iterable<any>,\n A\n > = S extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>\n : T extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>\n : Array<A>\n\n /**\n * @since 2.0.0\n */\n export type AndNonEmpty<\n S extends Iterable<any>,\n T extends Iterable<any>,\n A\n > = S extends NonEmptyReadonlyArray<any> ? T extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>\n : Array<A>\n : Array<A>\n\n /**\n * @since 2.0.0\n */\n export type Flatten<T extends ReadonlyArray<ReadonlyArray<any>>> = T extends\n NonEmptyReadonlyArray<NonEmptyReadonlyArray<infer A>> ? NonEmptyArray<A>\n : T extends ReadonlyArray<ReadonlyArray<infer A>> ? Array<A>\n : never\n}\n\n/**\n * @category mapping\n * @since 2.0.0\n */\nexport const map: {\n /**\n * @category mapping\n * @since 2.0.0\n */\n <S extends ReadonlyArray<any>, B>(\n f: (a: ReadonlyArray.Infer<S>, i: number) => B\n ): (self: S) => ReadonlyArray.With<S, B>\n /**\n * @category mapping\n * @since 2.0.0\n */\n <S extends ReadonlyArray<any>, B>(self: S, f: (a: ReadonlyArray.Infer<S>, i: number) => B): ReadonlyArray.With<S, B>\n} = dual(2, <A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => B): Array<B> => self.map(f))\n\n/**\n * Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatMap: {\n /**\n * Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <S extends ReadonlyArray<any>, T extends ReadonlyArray<any>>(\n f: (a: ReadonlyArray.Infer<S>, i: number) => T\n ): (self: S) => ReadonlyArray.AndNonEmpty<S, T, ReadonlyArray.Infer<T>>\n /**\n * Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(\n self: NonEmptyReadonlyArray<A>,\n f: (a: A, i: number) => NonEmptyReadonlyArray<B>\n ): NonEmptyArray<B>\n /**\n * Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => ReadonlyArray<B>): Array<B>\n} = dual(\n 2,\n <A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => ReadonlyArray<B>): Array<B> => {\n if (isEmptyReadonlyArray(self)) {\n return []\n }\n const out: Array<B> = []\n for (let i = 0; i < self.length; i++) {\n const inner = f(self[i], i)\n for (let j = 0; j < inner.length; j++) {\n out.push(inner[j])\n }\n }\n return out\n }\n)\n\n/**\n * Combines multiple arrays into a single array by concatenating all elements\n * from each nested array. This function ensures that the structure of nested\n * arrays is collapsed into a single, flat array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const nestedArrays = [[1, 2], [], [3, 4], [], [5, 6]]\n * const result = Array.flatten(nestedArrays)\n *\n * assert.deepStrictEqual(result, [1, 2, 3, 4, 5, 6]);\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatten: <S extends ReadonlyArray<ReadonlyArray<any>>>(self: S) => ReadonlyArray.Flatten<S> = flatMap(\n identity\n) as any\n\n/**\n * Applies a function to each element of the `Iterable` and filters based on the result, keeping the transformed values where the function returns `Some`.\n * This method combines filtering and mapping functionalities, allowing transformations and filtering of elements based on a single function pass.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\";\n *\n * const data = [1, 2, 3, 4, 5];\n * const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();\n * const result = Array.filterMap(data, evenSquares);\n *\n * assert.deepStrictEqual(result, [4, 16]);\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const filterMap: {\n /**\n * Applies a function to each element of the `Iterable` and filters based on the result, keeping the transformed values where the function returns `Some`.\n * This method combines filtering and mapping functionalities, allowing transformations and filtering of elements based on a single function pass.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\";\n *\n * const data = [1, 2, 3, 4, 5];\n * const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();\n * const result = Array.filterMap(data, evenSquares);\n *\n * assert.deepStrictEqual(result, [4, 16]);\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(f: (a: A, i: number) => Option<B>): (self: Iterable<A>) => Array<B>\n /**\n * Applies a function to each element of the `Iterable` and filters based on the result, keeping the transformed values where the function returns `Some`.\n * This method combines filtering and mapping functionalities, allowing transformations and filtering of elements based on a single function pass.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\";\n *\n * const data = [1, 2, 3, 4, 5];\n * const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();\n * const result = Array.filterMap(data, evenSquares);\n *\n * assert.deepStrictEqual(result, [4, 16]);\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Array<B>\n} = dual(\n 2,\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Array<B> => {\n const as = fromIterable(self)\n const out: Array<B> = []\n for (let i = 0; i < as.length; i++) {\n const o = f(as[i], i)\n if (O.isSome(o)) {\n out.push(o.value)\n }\n }\n return out\n }\n)\n\n/**\n * Applies a function to each element of the array and filters based on the result, stopping when a condition is not met.\n * This method combines filtering and mapping in a single pass, and short-circuits, i.e., stops processing, as soon as the function returns `None`.\n * This is useful when you need to transform an array but only up to the point where a certain condition holds true.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\";\n *\n * const data = [2, 4, 5];\n * const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();\n * const result = Array.filterMapWhile(data, toSquareTillOdd);\n *\n * assert.deepStrictEqual(result, [4, 16]);\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const filterMapWhile: {\n /**\n * Applies a function to each element of the array and filters based on the result, stopping when a condition is not met.\n * This method combines filtering and mapping in a single pass, and short-circuits, i.e., stops processing, as soon as the function returns `None`.\n * This is useful when you need to transform an array but only up to the point where a certain condition holds true.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\";\n *\n * const data = [2, 4, 5];\n * const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();\n * const result = Array.filterMapWhile(data, toSquareTillOdd);\n *\n * assert.deepStrictEqual(result, [4, 16]);\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(f: (a: A, i: number) => Option<B>): (self: Iterable<A>) => Array<B>\n /**\n * Applies a function to each element of the array and filters based on the result, stopping when a condition is not met.\n * This method combines filtering and mapping in a single pass, and short-circuits, i.e., stops processing, as soon as the function returns `None`.\n * This is useful when you need to transform an array but only up to the point where a certain condition holds true.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\";\n *\n * const data = [2, 4, 5];\n * const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();\n * const result = Array.filterMapWhile(data, toSquareTillOdd);\n *\n * assert.deepStrictEqual(result, [4, 16]);\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Array<B>\n} = dual(2, <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>) => {\n let i = 0\n const out: Array<B> = []\n for (const a of self) {\n const b = f(a, i)\n if (O.isSome(b)) {\n out.push(b.value)\n } else {\n break\n }\n i++\n }\n return out\n})\n\n/**\n * Applies a function to each element of the `Iterable`, categorizing the results into two separate arrays.\n * This function is particularly useful for operations where each element can result in two possible types,\n * and you want to separate these types into different collections. For instance, separating validation results\n * into successes and failures.\n *\n * @example\n * ```ts\n * import { Array, Either } from \"effect\";\n *\n * const data = [1, 2, 3, 4, 5]\n * const isEven = (x: number) => x % 2 === 0\n * const partitioned = Array.partitionMap(data, x =>\n * isEven(x) ? Either.right(x) : Either.left(x)\n * )\n *\n * assert.deepStrictEqual(partitioned, [\n * [1, 3, 5],\n * [2, 4]\n * ])\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const partitionMap: {\n /**\n * Applies a function to each element of the `Iterable`, categorizing the results into two separate arrays.\n * This function is particularly useful for operations where each element can result in two possible types,\n * and you want to separate these types into different collections. For instance, separating validation results\n * into successes and failures.\n *\n * @example\n * ```ts\n * import { Array, Either } from \"effect\";\n *\n * const data = [1, 2, 3, 4, 5]\n * const isEven = (x: number) => x % 2 === 0\n * const partitioned = Array.partitionMap(data, x =>\n * isEven(x) ? Either.right(x) : Either.left(x)\n * )\n *\n * assert.deepStrictEqual(partitioned, [\n * [1, 3, 5],\n * [2, 4]\n * ])\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B, C>(f: (a: A, i: number) => array_<C, B>): (self: Iterable<A>) => [left: Array<B>, right: Array<C>]\n /**\n * Applies a function to each element of the `Iterable`, categorizing the results into two separate arrays.\n * This function is particularly useful for operations where each element can result in two possible types,\n * and you want to separate these types into different collections. For instance, separating validation results\n * into successes and failures.\n *\n * @example\n * ```ts\n * import { Array, Either } from \"effect\";\n *\n * const data = [1, 2, 3, 4, 5]\n * const isEven = (x: number) => x % 2 === 0\n * const partitioned = Array.partitionMap(data, x =>\n * isEven(x) ? Either.right(x) : Either.left(x)\n * )\n *\n * assert.deepStrictEqual(partitioned, [\n * [1, 3, 5],\n * [2, 4]\n * ])\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B, C>(self: Iterable<A>, f: (a: A, i: number) => array_<C, B>): [left: Array<B>, right: Array<C>]\n} = dual(\n 2,\n <A, B, C>(self: Iterable<A>, f: (a: A, i: number) => array_<C, B>): [left: Array<B>, right: Array<C>] => {\n const left: Array<B> = []\n const right: Array<C> = []\n const as = fromIterable(self)\n for (let i = 0; i < as.length; i++) {\n const e = f(as[i], i)\n if (E.isLeft(e)) {\n left.push(e.left)\n } else {\n right.push(e.right)\n }\n }\n return [left, right]\n }\n)\n\n/**\n * Retrieves the `Some` values from an `Iterable` of `Option`s, collecting them into an array.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Array.getSomes([Option.some(1), Option.none(), Option.some(2)]),\n * [1, 2]\n * )\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n\nexport const getSomes: <T extends Iterable<Option<X>>, X = any>(\n self: T\n) => Array<Option.Value<ReadonlyArray.Infer<T>>> = filterMap(identity as any)\n\n/**\n * Retrieves the `Left` values from an `Iterable` of `Either`s, collecting them into an array.\n *\n * @example\n * ```ts\n * import { Array, Either } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Array.getLefts([Either.right(1), Either.left(\"err\"), Either.right(2)]),\n * [\"err\"]\n * )\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const getLefts = <T extends Iterable<array_<any, any>>>(self: T): Array<array_.Left<ReadonlyArray.Infer<T>>> => {\n const out: Array<any> = []\n for (const a of self) {\n if (E.isLeft(a)) {\n out.push(a.left)\n }\n }\n\n return out\n}\n\n/**\n * Retrieves the `Right` values from an `Iterable` of `Either`s, collecting them into an array.\n *\n * @example\n * ```ts\n * import { Array, Either } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Array.getRights([Either.right(1), Either.left(\"err\"), Either.right(2)]),\n * [1, 2]\n * )\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const getRights = <T extends Iterable<array_<any, any>>>(\n self: T\n): Array<array_.Right<ReadonlyArray.Infer<T>>> => {\n const out: Array<any> = []\n for (const a of self) {\n if (E.isRight(a)) {\n out.push(a.right)\n }\n }\n\n return out\n}\n\n/**\n * @category filtering\n * @since 2.0.0\n */\nexport const filter: {\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Array<B>\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Array<A>\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Array<B>\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A>\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A> => {\n const as = fromIterable(self)\n const out: Array<A> = []\n for (let i = 0; i < as.length; i++) {\n if (predicate(as[i], i)) {\n out.push(as[i])\n }\n }\n return out\n }\n)\n\n/**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const partition: {\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (\n self: Iterable<A>\n ) => [excluded: Array<Exclude<A, B>>, satisfying: Array<B>]\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * @category filtering\n * @since 2.0.0\n */\n <A>(\n predicate: (a: NoInfer<A>, i: number) => boolean\n ): (self: Iterable<A>) => [excluded: Array<A>, satisfying: Array<A>]\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(\n self: Iterable<A>,\n refinement: (a: A, i: number) => a is B\n ): [excluded: Array<Exclude<A, B>>, satisfying: Array<B>]\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * @category filtering\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [excluded: Array<A>, satisfying: Array<A>]\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [excluded: Array<A>, satisfying: Array<A>] => {\n const left: Array<A> = []\n const right: Array<A> = []\n const as = fromIterable(self)\n for (let i = 0; i < as.length; i++) {\n if (predicate(as[i], i)) {\n right.push(as[i])\n } else {\n left.push(as[i])\n }\n }\n return [left, right]\n }\n)\n\n/**\n * Separates an `Iterable` into two arrays based on a predicate.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.partition(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, [[1, 3], [2, 4]])\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const separate: <T extends Iterable<array_<any, any>>>(\n self: T\n) => [Array<array_.Left<ReadonlyArray.Infer<T>>>, Array<array_.Right<ReadonlyArray.Infer<T>>>] = partitionMap(\n identity\n)\n\n/**\n * Reduces an array from the left.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.reduce(numbers, 0, (acc, n) => acc + n)\n * assert.deepStrictEqual(result, 6)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const reduce: {\n /**\n * Reduces an array from the left.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.reduce(numbers, 0, (acc, n) => acc + n)\n * assert.deepStrictEqual(result, 6)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Iterable<A>) => B\n /**\n * Reduces an array from the left.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.reduce(numbers, 0, (acc, n) => acc + n)\n * assert.deepStrictEqual(result, 6)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B\n} = dual(\n 3,\n <B, A>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B =>\n fromIterable(self).reduce((b, a, i) => f(b, a, i), b)\n)\n\n/**\n * Reduces an array from the right.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.reduceRight(numbers, 0, (acc, n) => acc + n)\n * assert.deepStrictEqual(result, 6)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const reduceRight: {\n /**\n * Reduces an array from the right.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.reduceRight(numbers, 0, (acc, n) => acc + n)\n * assert.deepStrictEqual(result, 6)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Iterable<A>) => B\n /**\n * Reduces an array from the right.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.reduceRight(numbers, 0, (acc, n) => acc + n)\n * assert.deepStrictEqual(result, 6)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B\n} = dual(\n 3,\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B =>\n fromIterable(self).reduceRight((b, a, i) => f(b, a, i), b)\n)\n\n/**\n * Lifts a predicate into an array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n * const to = Array.liftPredicate(isEven)\n * assert.deepStrictEqual(to(1), [])\n * assert.deepStrictEqual(to(2), [2])\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\nexport const liftPredicate: { // Note: I intentionally avoid using the NoInfer pattern here.\n <A, B extends A>(refinement: Refinement<A, B>): (a: A) => Array<B>\n /**\n * Lifts a predicate into an array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n * const to = Array.liftPredicate(isEven)\n * assert.deepStrictEqual(to(1), [])\n * assert.deepStrictEqual(to(2), [2])\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\n <A>(predicate: Predicate<A>): <B extends A>(b: B) => Array<B>\n} = <A>(predicate: Predicate<A>) => <B extends A>(b: B): Array<B> => predicate(b) ? [b] : []\n\n/**\n * @category lifting\n * @since 2.0.0\n */\nexport const liftOption = <A extends Array<unknown>, B>(\n f: (...a: A) => Option<B>\n) =>\n(...a: A): Array<B> => fromOption(f(...a))\n\n/**\n * @category conversions\n * @since 2.0.0\n */\nexport const fromNullable = <A>(a: A): Array<NonNullable<A>> => a == null ? empty() : [a as NonNullable<A>]\n\n/**\n * @category lifting\n * @since 2.0.0\n */\nexport const liftNullable = <A extends Array<unknown>, B>(\n f: (...a: A) => B | null | undefined\n): (...a: A) => Array<NonNullable<B>> =>\n(...a) => fromNullable(f(...a))\n\n/**\n * Maps over an array and flattens the result, removing null and undefined values.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.flatMapNullable(numbers, n => (n % 2 === 0 ? null : n))\n * assert.deepStrictEqual(result, [1, 3])\n *\n * // Explanation:\n * // The array of numbers [1, 2, 3] is mapped with a function that returns null for even numbers\n * // and the number itself for odd numbers. The resulting array [1, null, 3] is then flattened\n * // to remove null values, resulting in [1, 3].\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatMapNullable: {\n /**\n * Maps over an array and flattens the result, removing null and undefined values.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.flatMapNullable(numbers, n => (n % 2 === 0 ? null : n))\n * assert.deepStrictEqual(result, [1, 3])\n *\n * // Explanation:\n * // The array of numbers [1, 2, 3] is mapped with a function that returns null for even numbers\n * // and the number itself for odd numbers. The resulting array [1, null, 3] is then flattened\n * // to remove null values, resulting in [1, 3].\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B | null | undefined): (self: ReadonlyArray<A>) => Array<NonNullable<B>>\n /**\n * Maps over an array and flattens the result, removing null and undefined values.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.flatMapNullable(numbers, n => (n % 2 === 0 ? null : n))\n * assert.deepStrictEqual(result, [1, 3])\n *\n * // Explanation:\n * // The array of numbers [1, 2, 3] is mapped with a function that returns null for even numbers\n * // and the number itself for odd numbers. The resulting array [1, null, 3] is then flattened\n * // to remove null values, resulting in [1, 3].\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: ReadonlyArray<A>, f: (a: A) => B | null | undefined): Array<NonNullable<B>>\n} = dual(\n 2,\n <A, B>(self: ReadonlyArray<A>, f: (a: A) => B | null | undefined): Array<NonNullable<B>> =>\n flatMap(self, (a) => fromNullable(f(a)))\n)\n\n/**\n * Lifts a function that returns an `Either` into a function that returns an array.\n * If the `Either` is a left, it returns an empty array.\n * If the `Either` is a right, it returns an array with the right value.\n *\n * @example\n * ```ts\n * import { Array, Either } from \"effect\"\n *\n * const parseNumber = (s: string): Either.Either<number, Error> =>\n * isNaN(Number(s)) ? Either.left(new Error(\"Not a number\")) : Either.right(Number(s))\n *\n * const liftedParseNumber = Array.liftEither(parseNumber)\n *\n * const result1 = liftedParseNumber(\"42\")\n * assert.deepStrictEqual(result1, [42])\n *\n * const result2 = liftedParseNumber(\"not a number\")\n * assert.deepStrictEqual(result2, [])\n *\n * // Explanation:\n * // The function parseNumber is lifted to return an array.\n * // When parsing \"42\", it returns an Either.left with the number 42, resulting in [42].\n * // When parsing \"not a number\", it returns an Either.right with an error, resulting in an empty array [].\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\nexport const liftEither = <A extends Array<unknown>, E, B>(\n f: (...a: A) => array_<B, E>\n) =>\n(...a: A): Array<B> => {\n const e = f(...a)\n return E.isLeft(e) ? [] : [e.right]\n}\n\n/**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const every: {\n /**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(\n refinement: (a: NoInfer<A>, i: number) => a is B\n ): (self: ReadonlyArray<A>) => self is ReadonlyArray<B>\n /**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: ReadonlyArray<A>) => boolean\n /**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(self: ReadonlyArray<A>, refinement: (a: A, i: number) => a is B): self is ReadonlyArray<B>\n /**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): boolean\n} = dual(\n 2,\n <A, B extends A>(self: ReadonlyArray<A>, refinement: (a: A, i: number) => a is B): self is ReadonlyArray<B> =>\n self.every(refinement)\n)\n\n/**\n * Check if a predicate holds true for some `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const some: {\n /**\n * Check if a predicate holds true for some `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: ReadonlyArray<A>) => self is NonEmptyReadonlyArray<A>\n /**\n * Check if a predicate holds true for some `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): self is NonEmptyReadonlyArray<A>\n} = dual(\n 2,\n <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): self is NonEmptyReadonlyArray<A> =>\n self.some(predicate)\n)\n\n/**\n * Extends an array with a function that maps each subarray to a value.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.extend(numbers, as => as.length)\n * assert.deepStrictEqual(result, [3, 2, 1])\n *\n * // Explanation:\n * // The function maps each subarray starting from each element to its length.\n * // The subarrays are: [1, 2, 3], [2, 3], [3].\n * // The lengths are: 3, 2, 1.\n * // Therefore, the result is [3, 2, 1].\n * ```\n *\n * @since 2.0.0\n */\nexport const extend: {\n /**\n * Extends an array with a function that maps each subarray to a value.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.extend(numbers, as => as.length)\n * assert.deepStrictEqual(result, [3, 2, 1])\n *\n * // Explanation:\n * // The function maps each subarray starting from each element to its length.\n * // The subarrays are: [1, 2, 3], [2, 3], [3].\n * // The lengths are: 3, 2, 1.\n * // Therefore, the result is [3, 2, 1].\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(f: (as: ReadonlyArray<A>) => B): (self: ReadonlyArray<A>) => Array<B>\n /**\n * Extends an array with a function that maps each subarray to a value.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.extend(numbers, as => as.length)\n * assert.deepStrictEqual(result, [3, 2, 1])\n *\n * // Explanation:\n * // The function maps each subarray starting from each element to its length.\n * // The subarrays are: [1, 2, 3], [2, 3], [3].\n * // The lengths are: 3, 2, 1.\n * // Therefore, the result is [3, 2, 1].\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: ReadonlyArray<A>, f: (as: ReadonlyArray<A>) => B): Array<B>\n} = dual(\n 2,\n <A, B>(self: ReadonlyArray<A>, f: (as: ReadonlyArray<A>) => B): Array<B> => self.map((_, i, as) => f(as.slice(i)))\n)\n\n/**\n * Finds the minimum element in an array based on a comparator.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const min = Array.min([3, 1, 2], Order.number)\n * assert.deepStrictEqual(min, 1)\n * ```\n *\n * @since 2.0.0\n */\nexport const min: {\n /**\n * Finds the minimum element in an array based on a comparator.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const min = Array.min([3, 1, 2], Order.number)\n * assert.deepStrictEqual(min, 1)\n * ```\n *\n * @since 2.0.0\n */\n <A>(O: Order.Order<A>): (self: NonEmptyReadonlyArray<A>) => A\n /**\n * Finds the minimum element in an array based on a comparator.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const min = Array.min([3, 1, 2], Order.number)\n * assert.deepStrictEqual(min, 1)\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A\n} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A => self.reduce(Order.min(O)))\n\n/**\n * Finds the maximum element in an array based on a comparator.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const max = Array.max([3, 1, 2], Order.number)\n * assert.deepStrictEqual(max, 3)\n * ```\n *\n * @since 2.0.0\n */\nexport const max: {\n /**\n * Finds the maximum element in an array based on a comparator.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const max = Array.max([3, 1, 2], Order.number)\n * assert.deepStrictEqual(max, 3)\n * ```\n *\n * @since 2.0.0\n */\n <A>(O: Order.Order<A>): (self: NonEmptyReadonlyArray<A>) => A\n /**\n * Finds the maximum element in an array based on a comparator.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const max = Array.max([3, 1, 2], Order.number)\n * assert.deepStrictEqual(max, 3)\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A\n} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A => self.reduce(Order.max(O)))\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const unfold = <B, A>(b: B, f: (b: B) => Option<readonly [A, B]>): Array<A> => {\n const out: Array<A> = []\n let next: B = b\n let o: Option<readonly [A, B]>\n while (O.isSome(o = f(next))) {\n const [a, b] = o.value\n out.push(a)\n next = b\n }\n return out\n}\n\n/**\n * This function creates and returns a new `Order` for an array of values based on a given `Order` for the elements of the array.\n * The returned `Order` compares two arrays by applying the given `Order` to each element in the arrays.\n * If all elements are equal, the arrays are then compared based on their length.\n * It is useful when you need to compare two arrays of the same type and you have a specific way of comparing each element of the array.\n *\n * @category instances\n * @since 2.0.0\n */\nexport const getOrder: <A>(O: Order.Order<A>) => Order.Order<ReadonlyArray<A>> = Order.array\n\n/**\n * Creates an equivalence relation for arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers1 = [1, 2, 3]\n * const numbers2 = [1, 2, 3]\n * const eq = Array.getEquivalence<number>((a, b) => a === b)\n * assert.deepStrictEqual(eq(numbers1, numbers2), true)\n * ```\n *\n * @category instances\n * @since 2.0.0\n */\nexport const getEquivalence: <A>(\n isEquivalent: Equivalence.Equivalence<A>\n) => Equivalence.Equivalence<ReadonlyArray<A>> = Equivalence.array\n\n/**\n * Performs a side-effect for each element of the `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * Array.forEach(numbers, n => console.log(n)) // 1, 2, 3\n * ```\n *\n * @since 2.0.0\n */\nexport const forEach: {\n /**\n * Performs a side-effect for each element of the `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * Array.forEach(numbers, n => console.log(n)) // 1, 2, 3\n * ```\n *\n * @since 2.0.0\n */\n <A>(f: (a: A, i: number) => void): (self: Iterable<A>) => void\n /**\n * Performs a side-effect for each element of the `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * Array.forEach(numbers, n => console.log(n)) // 1, 2, 3\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, f: (a: A, i: number) => void): void\n} = dual(2, <A>(self: Iterable<A>, f: (a: A, i: number) => void): void => fromIterable(self).forEach((a, i) => f(a, i)))\n\n/**\n * Remove duplicates from an `Iterable` using the provided `isEquivalent` function,\n * preserving the order of the first occurrence of each element.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 2, 3, 3, 3]\n * const unique = Array.dedupeWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const dedupeWith: {\n /**\n * Remove duplicates from an `Iterable` using the provided `isEquivalent` function,\n * preserving the order of the first occurrence of each element.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 2, 3, 3, 3]\n * const unique = Array.dedupeWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <S extends Iterable<any>>(\n isEquivalent: (self: ReadonlyArray.Infer<S>, that: ReadonlyArray.Infer<S>) => boolean\n ): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * Remove duplicates from an `Iterable` using the provided `isEquivalent` function,\n * preserving the order of the first occurrence of each element.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 2, 3, 3, 3]\n * const unique = Array.dedupeWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A>(\n self: NonEmptyReadonlyArray<A>,\n isEquivalent: (self: A, that: A) => boolean\n ): NonEmptyArray<A>\n /**\n * Remove duplicates from an `Iterable` using the provided `isEquivalent` function,\n * preserving the order of the first occurrence of each element.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 2, 3, 3, 3]\n * const unique = Array.dedupeWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A>\n} = dual(\n 2,\n <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const out: NonEmptyArray<A> = [headNonEmpty(input)]\n const rest = tailNonEmpty(input)\n for (const r of rest) {\n if (out.every((a) => !isEquivalent(r, a))) {\n out.push(r)\n }\n }\n return out\n }\n return []\n }\n)\n\n/**\n * Remove duplicates from an `Iterable`, preserving the order of the first occurrence of each element.\n * The equivalence used to compare elements is provided by `Equal.equivalence()` from the `Equal` module.\n *\n * @since 2.0.0\n */\nexport const dedupe = <S extends Iterable<any> | NonEmptyReadonlyArray<any>>(\n self: S\n): S extends NonEmptyReadonlyArray<infer A> ? NonEmptyArray<A> : S extends Iterable<infer A> ? Array<A> : never =>\n dedupeWith(self, Equal.equivalence()) as any\n\n/**\n * Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 1, 2, 2, 3, 3]\n * const unique = Array.dedupeAdjacentWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const dedupeAdjacentWith: {\n /**\n * Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 1, 2, 2, 3, 3]\n * const unique = Array.dedupeAdjacentWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A>(isEquivalent: (self: A, that: A) => boolean): (self: Iterable<A>) => Array<A>\n /**\n * Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 1, 2, 2, 3, 3]\n * const unique = Array.dedupeAdjacentWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A>\n} = dual(2, <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A> => {\n const out: Array<A> = []\n let lastA: O.Option<A> = O.none()\n for (const a of self) {\n if (O.isNone(lastA) || !isEquivalent(a, lastA.value)) {\n out.push(a)\n lastA = O.some(a)\n }\n }\n return out\n})\n\n/**\n * Deduplicates adjacent elements that are identical.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 1, 2, 2, 3, 3]\n * const unique = Array.dedupeAdjacent(numbers)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const dedupeAdjacent: <A>(self: Iterable<A>) => Array<A> = dedupeAdjacentWith(Equal.equivalence())\n\n/**\n * Joins the elements together with \"sep\" in the middle.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const strings = [\"a\", \"b\", \"c\"]\n * const joined = Array.join(strings, \"-\")\n * assert.deepStrictEqual(joined, \"a-b-c\")\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\nexport const join: {\n /**\n * Joins the elements together with \"sep\" in the middle.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const strings = [\"a\", \"b\", \"c\"]\n * const joined = Array.join(strings, \"-\")\n * assert.deepStrictEqual(joined, \"a-b-c\")\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\n (sep: string): (self: Iterable<string>) => string\n /**\n * Joins the elements together with \"sep\" in the middle.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const strings = [\"a\", \"b\", \"c\"]\n * const joined = Array.join(strings, \"-\")\n * assert.deepStrictEqual(joined, \"a-b-c\")\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\n (self: Iterable<string>, sep: string): string\n} = dual(2, (self: Iterable<string>, sep: string): string => fromIterable(self).join(sep))\n\n/**\n * Statefully maps over the chunk, producing new elements of type `B`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.mapAccum(numbers, 0, (acc, n) => [acc + n, acc + n])\n * assert.deepStrictEqual(result, [6, [1, 3, 6]])\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\nexport const mapAccum: {\n /**\n * Statefully maps over the chunk, producing new elements of type `B`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.mapAccum(numbers, 0, (acc, n) => [acc + n, acc + n])\n * assert.deepStrictEqual(result, [6, [1, 3, 6]])\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\n <S, A, B, I extends Iterable<A> = Iterable<A>>(\n s: S,\n f: (s: S, a: ReadonlyArray.Infer<I>, i: number) => readonly [S, B]\n ): (self: I) => [state: S, mappedArray: ReadonlyArray.With<I, B>]\n /**\n * Statefully maps over the chunk, producing new elements of type `B`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.mapAccum(numbers, 0, (acc, n) => [acc + n, acc + n])\n * assert.deepStrictEqual(result, [6, [1, 3, 6]])\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\n <S, A, B, I extends Iterable<A> = Iterable<A>>(\n self: I,\n s: S,\n f: (s: S, a: ReadonlyArray.Infer<I>, i: number) => readonly [S, B]\n ): [state: S, mappedArray: ReadonlyArray.With<I, B>]\n} = dual(\n 3,\n <S, A, B>(self: Iterable<A>, s: S, f: (s: S, a: A, i: number) => [S, B]): [state: S, mappedArray: Array<B>] => {\n let i = 0\n let s1 = s\n const out: Array<B> = []\n for (const a of self) {\n const r = f(s1, a, i)\n s1 = r[0]\n out.push(r[1])\n i++\n }\n return [s1, out]\n }\n)\n\n/**\n * Zips this chunk crosswise with the specified chunk using the specified combiner.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [\"a\", \"b\"]\n * const product = Array.cartesianWith(array1, array2, (a, b) => `${a}-${b}`)\n * assert.deepStrictEqual(product, [\"1-a\", \"1-b\", \"2-a\", \"2-b\"])\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\nexport const cartesianWith: {\n /**\n * Zips this chunk crosswise with the specified chunk using the specified combiner.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [\"a\", \"b\"]\n * const product = Array.cartesianWith(array1, array2, (a, b) => `${a}-${b}`)\n * assert.deepStrictEqual(product, [\"1-a\", \"1-b\", \"2-a\", \"2-b\"])\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B, C>(that: ReadonlyArray<B>, f: (a: A, b: B) => C): (self: ReadonlyArray<A>) => Array<C>\n /**\n * Zips this chunk crosswise with the specified chunk using the specified combiner.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [\"a\", \"b\"]\n * const product = Array.cartesianWith(array1, array2, (a, b) => `${a}-${b}`)\n * assert.deepStrictEqual(product, [\"1-a\", \"1-b\", \"2-a\", \"2-b\"])\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B, C>(self: ReadonlyArray<A>, that: ReadonlyArray<B>, f: (a: A, b: B) => C): Array<C>\n} = dual(\n 3,\n <A, B, C>(self: ReadonlyArray<A>, that: ReadonlyArray<B>, f: (a: A, b: B) => C): Array<C> =>\n flatMap(self, (a) => map(that, (b) => f(a, b)))\n)\n\n/**\n * Zips this chunk crosswise with the specified chunk.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [\"a\", \"b\"]\n * const product = Array.cartesian(array1, array2)\n * assert.deepStrictEqual(product, [[1, \"a\"], [1, \"b\"], [2, \"a\"], [2, \"b\"]])\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\nexport const cartesian: {\n /**\n * Zips this chunk crosswise with the specified chunk.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [\"a\", \"b\"]\n * const product = Array.cartesian(array1, array2)\n * assert.deepStrictEqual(product, [[1, \"a\"], [1, \"b\"], [2, \"a\"], [2, \"b\"]])\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <B>(that: ReadonlyArray<B>): <A>(self: ReadonlyArray<A>) => Array<[A, B]>\n /**\n * Zips this chunk crosswise with the specified chunk.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [\"a\", \"b\"]\n * const product = Array.cartesian(array1, array2)\n * assert.deepStrictEqual(product, [[1, \"a\"], [1, \"b\"], [2, \"a\"], [2, \"b\"]])\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B>(self: ReadonlyArray<A>, that: ReadonlyArray<B>): Array<[A, B]>\n} = dual(\n 2,\n <A, B>(self: ReadonlyArray<A>, that: ReadonlyArray<B>): Array<[A, B]> => cartesianWith(self, that, (a, b) => [a, b])\n)\n\n// -------------------------------------------------------------------------------------\n// do notation\n// -------------------------------------------------------------------------------------\n\n/**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\nexport const Do: ReadonlyArray<{}> = of({})\n\n/**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\nexport const bind: {\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\n <A extends object, N extends string, B>(tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): (\n self: ReadonlyArray<A>\n ) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\n <A extends object, N extends string, B>(\n self: ReadonlyArray<A>,\n tag: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => ReadonlyArray<B>\n ): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n} = doNotation.bind<ReadonlyArrayTypeLambda>(map, flatMap) as any\n\n/**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\nexport const bindTo: {\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\n <N extends string>(tag: N): <A>(self: ReadonlyArray<A>) => Array<{ [K in N]: A }>\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\n <A, N extends string>(self: ReadonlyArray<A>, tag: N): Array<{ [K in N]: A }>\n} = doNotation.bindTo<ReadonlyArrayTypeLambda>(map) as any\n\nconst let_: {\n <N extends string, B, A extends object>(\n tag: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): (self: ReadonlyArray<A>) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n <N extends string, A extends object, B>(\n self: ReadonlyArray<A>,\n tag: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n} = doNotation.let_<ReadonlyArrayTypeLambda>(map) as any\n\nexport {\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link bind}\n * @see {@link Do}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n *\n * ```\n * @category do notation\n * @since 3.2.0\n */\n let_ as let\n}\n","/**\n * @since 2.0.0\n */\nimport * as RA from \"./Array.js\"\nimport type { NonEmptyReadonlyArray } from \"./Array.js\"\nimport type { Either } from \"./Either.js\"\nimport * as Equal from \"./Equal.js\"\nimport * as Equivalence from \"./Equivalence.js\"\nimport { dual, identity, pipe } from \"./Function.js\"\nimport * as Hash from \"./Hash.js\"\nimport type { TypeLambda } from \"./HKT.js\"\nimport { format, type Inspectable, NodeInspectSymbol, toJSON } from \"./Inspectable.js\"\nimport type { NonEmptyIterable } from \"./NonEmptyIterable.js\"\nimport type { Option } from \"./Option.js\"\nimport * as O from \"./Option.js\"\nimport * as Order from \"./Order.js\"\nimport type { Pipeable } from \"./Pipeable.js\"\nimport { pipeArguments } from \"./Pipeable.js\"\nimport { hasProperty, type Predicate, type Refinement } from \"./Predicate.js\"\nimport type { Covariant, NoInfer } from \"./Types.js\"\n\nconst TypeId: unique symbol = Symbol.for(\"effect/Chunk\") as TypeId\n\n/**\n * @category symbol\n * @since 2.0.0\n */\nexport type TypeId = typeof TypeId\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Chunk<out A> extends Iterable<A>, Equal.Equal, Pipeable, Inspectable {\n readonly [TypeId]: {\n readonly _A: Covariant<A>\n }\n readonly length: number\n /** @internal */\n right: Chunk<A>\n /** @internal */\n left: Chunk<A>\n /** @internal */\n backing: Backing<A>\n /** @internal */\n depth: number\n}\n\n/**\n * @category model\n * @since 2.0.0\n */\nexport interface NonEmptyChunk<out A> extends Chunk<A>, NonEmptyIterable<A> {}\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface ChunkTypeLambda extends TypeLambda {\n readonly type: Chunk<this[\"Target\"]>\n}\n\ntype Backing<A> =\n | IArray<A>\n | IConcat<A>\n | ISingleton<A>\n | IEmpty\n | ISlice<A>\n\ninterface IArray<A> {\n readonly _tag: \"IArray\"\n readonly array: ReadonlyArray<A>\n}\n\ninterface IConcat<A> {\n readonly _tag: \"IConcat\"\n readonly left: Chunk<A>\n readonly right: Chunk<A>\n}\n\ninterface ISingleton<A> {\n readonly _tag: \"ISingleton\"\n readonly a: A\n}\n\ninterface IEmpty {\n readonly _tag: \"IEmpty\"\n}\n\ninterface ISlice<A> {\n readonly _tag: \"ISlice\"\n readonly chunk: Chunk<A>\n readonly offset: number\n readonly length: number\n}\n\nfunction copy<A>(\n src: ReadonlyArray<A>,\n srcPos: number,\n dest: Array<A>,\n destPos: number,\n len: number\n) {\n for (let i = srcPos; i < Math.min(src.length, srcPos + len); i++) {\n dest[destPos + i - srcPos] = src[i]!\n }\n return dest\n}\n\nconst emptyArray: ReadonlyArray<never> = []\n\n/**\n * Compares the two chunks of equal length using the specified function\n *\n * @category equivalence\n * @since 2.0.0\n */\nexport const getEquivalence = <A>(isEquivalent: Equivalence.Equivalence<A>): Equivalence.Equivalence<Chunk<A>> =>\n Equivalence.make((self, that) =>\n self.length === that.length && toReadonlyArray(self).every((value, i) => isEquivalent(value, unsafeGet(that, i)))\n )\n\nconst _equivalence = getEquivalence(Equal.equals)\n\nconst ChunkProto: Omit<Chunk<unknown>, \"backing\" | \"depth\" | \"left\" | \"length\" | \"right\"> = {\n [TypeId]: {\n _A: (_: never) => _\n },\n toString<A>(this: Chunk<A>) {\n return format(this.toJSON())\n },\n toJSON<A>(this: Chunk<A>) {\n return {\n _id: \"Chunk\",\n values: toReadonlyArray(this).map(toJSON)\n }\n },\n [NodeInspectSymbol]<A>(this: Chunk<A>) {\n return this.toJSON()\n },\n [Equal.symbol]<A>(this: Chunk<A>, that: unknown): boolean {\n return isChunk(that) && _equivalence(this, that)\n },\n [Hash.symbol]<A>(this: Chunk<A>): number {\n return Hash.cached(this, Hash.array(toReadonlyArray(this)))\n },\n [Symbol.iterator]<A>(this: Chunk<A>): Iterator<A> {\n switch (this.backing._tag) {\n case \"IArray\": {\n return this.backing.array[Symbol.iterator]()\n }\n case \"IEmpty\": {\n return emptyArray[Symbol.iterator]()\n }\n default: {\n return toReadonlyArray(this)[Symbol.iterator]()\n }\n }\n },\n pipe<A>(this: Chunk<A>) {\n return pipeArguments(this, arguments)\n }\n}\n\nconst makeChunk = <A>(backing: Backing<A>): Chunk<A> => {\n const chunk = Object.create(ChunkProto)\n chunk.backing = backing\n switch (backing._tag) {\n case \"IEmpty\": {\n chunk.length = 0\n chunk.depth = 0\n chunk.left = chunk\n chunk.right = chunk\n break\n }\n case \"IConcat\": {\n chunk.length = backing.left.length + backing.right.length\n chunk.depth = 1 + Math.max(backing.left.depth, backing.right.depth)\n chunk.left = backing.left\n chunk.right = backing.right\n break\n }\n case \"IArray\": {\n chunk.length = backing.array.length\n chunk.depth = 0\n chunk.left = _empty\n chunk.right = _empty\n break\n }\n case \"ISingleton\": {\n chunk.length = 1\n chunk.depth = 0\n chunk.left = _empty\n chunk.right = _empty\n break\n }\n case \"ISlice\": {\n chunk.length = backing.length\n chunk.depth = backing.chunk.depth + 1\n chunk.left = _empty\n chunk.right = _empty\n break\n }\n }\n return chunk\n}\n\n/**\n * Checks if `u` is a `Chunk<unknown>`\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const isChunk: {\n /**\n * Checks if `u` is a `Chunk<unknown>`\n *\n * @category constructors\n * @since 2.0.0\n */\n <A>(u: Iterable<A>): u is Chunk<A>\n /**\n * Checks if `u` is a `Chunk<unknown>`\n *\n * @category constructors\n * @since 2.0.0\n */\n (u: unknown): u is Chunk<unknown>\n} = (u: unknown): u is Chunk<unknown> => hasProperty(u, TypeId)\n\nconst _empty = makeChunk<never>({ _tag: \"IEmpty\" })\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const empty: <A = never>() => Chunk<A> = () => _empty\n\n/**\n * Builds a `NonEmptyChunk` from an non-empty collection of elements.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const make = <As extends readonly [any, ...ReadonlyArray<any>]>(\n ...as: As\n): NonEmptyChunk<As[number]> => as.length === 1 ? of(as[0]) : unsafeFromNonEmptyArray(as)\n\n/**\n * Builds a `NonEmptyChunk` from a single element.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const of = <A>(a: A): NonEmptyChunk<A> => makeChunk({ _tag: \"ISingleton\", a }) as any\n\n/**\n * Creates a new `Chunk` from an iterable collection of values.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const fromIterable = <A>(self: Iterable<A>): Chunk<A> =>\n isChunk(self) ? self : makeChunk({ _tag: \"IArray\", array: RA.fromIterable(self) })\n\nconst copyToArray = <A>(self: Chunk<A>, array: Array<any>, initial: number): void => {\n switch (self.backing._tag) {\n case \"IArray\": {\n copy(self.backing.array, 0, array, initial, self.length)\n break\n }\n case \"IConcat\": {\n copyToArray(self.left, array, initial)\n copyToArray(self.right, array, initial + self.left.length)\n break\n }\n case \"ISingleton\": {\n array[initial] = self.backing.a\n break\n }\n case \"ISlice\": {\n let i = 0\n let j = initial\n while (i < self.length) {\n array[j] = unsafeGet(self, i)\n i += 1\n j += 1\n }\n break\n }\n }\n}\n\nconst toArray_ = <A>(self: Chunk<A>): Array<A> => toReadonlyArray(self).slice()\n\n/**\n * Converts a `Chunk` into an `Array`. If the provided `Chunk` is non-empty\n * (`NonEmptyChunk`), the function will return a `NonEmptyArray`, ensuring the\n * non-empty property is preserved.\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const toArray: <S extends Chunk<any>>(\n self: S\n) => S extends NonEmptyChunk<any> ? RA.NonEmptyArray<Chunk.Infer<S>> : Array<Chunk.Infer<S>> = toArray_ as any\n\nconst toReadonlyArray_ = <A>(self: Chunk<A>): ReadonlyArray<A> => {\n switch (self.backing._tag) {\n case \"IEmpty\": {\n return emptyArray\n }\n case \"IArray\": {\n return self.backing.array\n }\n default: {\n const arr = new Array<A>(self.length)\n copyToArray(self, arr, 0)\n self.backing = {\n _tag: \"IArray\",\n array: arr\n }\n self.left = _empty\n self.right = _empty\n self.depth = 0\n return arr\n }\n }\n}\n\n/**\n * Converts a `Chunk` into a `ReadonlyArray`. If the provided `Chunk` is\n * non-empty (`NonEmptyChunk`), the function will return a\n * `NonEmptyReadonlyArray`, ensuring the non-empty property is preserved.\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const toReadonlyArray: <S extends Chunk<any>>(\n self: S\n) => S extends NonEmptyChunk<any> ? RA.NonEmptyReadonlyArray<Chunk.Infer<S>> : ReadonlyArray<Chunk.Infer<S>> =\n toReadonlyArray_ as any\n\nconst reverseChunk = <A>(self: Chunk<A>): Chunk<A> => {\n switch (self.backing._tag) {\n case \"IEmpty\":\n case \"ISingleton\":\n return self\n case \"IArray\": {\n return makeChunk({ _tag: \"IArray\", array: RA.reverse(self.backing.array) })\n }\n case \"IConcat\": {\n return makeChunk({ _tag: \"IConcat\", left: reverse(self.backing.right), right: reverse(self.backing.left) })\n }\n case \"ISlice\":\n return unsafeFromArray(RA.reverse(toReadonlyArray(self)))\n }\n}\n\n/**\n * Reverses the order of elements in a `Chunk`.\n * Importantly, if the input chunk is a `NonEmptyChunk`, the reversed chunk will also be a `NonEmptyChunk`.\n *\n * @example\n * ```ts\n * import { Chunk } from \"effect\"\n *\n * const numbers = Chunk.make(1, 2, 3)\n * const reversedNumbers = Chunk.reverse(numbers)\n * assert.deepStrictEqual(reversedNumbers, Chunk.make(3, 2, 1))\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\nexport const reverse: <S extends Chunk<any>>(self: S) => Chunk.With<S, Chunk.Infer<S>> = reverseChunk as any\n\n/**\n * This function provides a safe way to read a value at a particular index from a `Chunk`.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const get: {\n /**\n * This function provides a safe way to read a value at a particular index from a `Chunk`.\n *\n * @category elements\n * @since 2.0.0\n */\n (index: number): <A>(self: Chunk<A>) => Option<A>\n /**\n * This function provides a safe way to read a value at a particular index from a `Chunk`.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Chunk<A>, index: number): Option<A>\n} = dual(\n 2,\n <A>(self: Chunk<A>, index: number): Option<A> =>\n index < 0 || index >= self.length ? O.none() : O.some(unsafeGet(self, index))\n)\n\n/**\n * Wraps an array into a chunk without copying, unsafe on mutable arrays\n *\n * @since 2.0.0\n * @category unsafe\n */\nexport const unsafeFromArray = <A>(self: ReadonlyArray<A>): Chunk<A> => makeChunk({ _tag: \"IArray\", array: self })\n\n/**\n * Wraps an array into a chunk without copying, unsafe on mutable arrays\n *\n * @since 2.0.0\n * @category unsafe\n */\nexport const unsafeFromNonEmptyArray = <A>(self: NonEmptyReadonlyArray<A>): NonEmptyChunk<A> =>\n unsafeFromArray(self) as any\n\n/**\n * Gets an element unsafely, will throw on out of bounds\n *\n * @since 2.0.0\n * @category unsafe\n */\nexport const unsafeGet: {\n /**\n * Gets an element unsafely, will throw on out of bounds\n *\n * @since 2.0.0\n * @category unsafe\n */\n (index: number): <A>(self: Chunk<A>) => A\n /**\n * Gets an element unsafely, will throw on out of bounds\n *\n * @since 2.0.0\n * @category unsafe\n */\n <A>(self: Chunk<A>, index: number): A\n} = dual(2, <A>(self: Chunk<A>, index: number): A => {\n switch (self.backing._tag) {\n case \"IEmpty\": {\n throw new Error(`Index out of bounds`)\n }\n case \"ISingleton\": {\n if (index !== 0) {\n throw new Error(`Index out of bounds`)\n }\n return self.backing.a\n }\n case \"IArray\": {\n if (index >= self.length || index < 0) {\n throw new Error(`Index out of bounds`)\n }\n return self.backing.array[index]!\n }\n case \"IConcat\": {\n return index < self.left.length\n ? unsafeGet(self.left, index)\n : unsafeGet(self.right, index - self.left.length)\n }\n case \"ISlice\": {\n return unsafeGet(self.backing.chunk, index + self.backing.offset)\n }\n }\n})\n\n/**\n * Appends the specified element to the end of the `Chunk`.\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const append: {\n /**\n * Appends the specified element to the end of the `Chunk`.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A2>(a: A2): <A>(self: Chunk<A>) => NonEmptyChunk<A2 | A>\n /**\n * Appends the specified element to the end of the `Chunk`.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, A2>(self: Chunk<A>, a: A2): NonEmptyChunk<A | A2>\n} = dual(2, <A, A2>(self: Chunk<A>, a: A2): NonEmptyChunk<A | A2> => appendAll(self, of(a)))\n\n/**\n * Prepend an element to the front of a `Chunk`, creating a new `NonEmptyChunk`.\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const prepend: {\n /**\n * Prepend an element to the front of a `Chunk`, creating a new `NonEmptyChunk`.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <B>(elem: B): <A>(self: Chunk<A>) => NonEmptyChunk<B | A>\n /**\n * Prepend an element to the front of a `Chunk`, creating a new `NonEmptyChunk`.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Chunk<A>, elem: B): NonEmptyChunk<A | B>\n} = dual(2, <A, B>(self: Chunk<A>, elem: B): NonEmptyChunk<A | B> => appendAll(of(elem), self))\n\n/**\n * Takes the first up to `n` elements from the chunk\n *\n * @since 2.0.0\n */\nexport const take: {\n /**\n * Takes the first up to `n` elements from the chunk\n *\n * @since 2.0.0\n */\n (n: number): <A>(self: Chunk<A>) => Chunk<A>\n /**\n * Takes the first up to `n` elements from the chunk\n *\n * @since 2.0.0\n */\n <A>(self: Chunk<A>, n: number): Chunk<A>\n} = dual(2, <A>(self: Chunk<A>, n: number): Chunk<A> => {\n if (n <= 0) {\n return _empty\n } else if (n >= self.length) {\n return self\n } else {\n switch (self.backing._tag) {\n case \"ISlice\": {\n return makeChunk({\n _tag: \"ISlice\",\n chunk: self.backing.chunk,\n length: n,\n offset: self.backing.offset\n })\n }\n case \"IConcat\": {\n if (n > self.left.length) {\n return makeChunk({\n _tag: \"IConcat\",\n left: self.left,\n right: take(self.right, n - self.left.length)\n })\n }\n\n return take(self.left, n)\n }\n default: {\n return makeChunk({\n _tag: \"ISlice\",\n chunk: self,\n offset: 0,\n length: n\n })\n }\n }\n }\n})\n\n/**\n * Drops the first up to `n` elements from the chunk\n *\n * @since 2.0.0\n */\nexport const drop: {\n /**\n * Drops the first up to `n` elements from the chunk\n *\n * @since 2.0.0\n */\n (n: number): <A>(self: Chunk<A>) => Chunk<A>\n /**\n * Drops the first up to `n` elements from the chunk\n *\n * @since 2.0.0\n */\n <A>(self: Chunk<A>, n: number): Chunk<A>\n} = dual(2, <A>(self: Chunk<A>, n: number): Chunk<A> => {\n if (n <= 0) {\n return self\n } else if (n >= self.length) {\n return _empty\n } else {\n switch (self.backing._tag) {\n case \"ISlice\": {\n return makeChunk({\n _tag: \"ISlice\",\n chunk: self.backing.chunk,\n offset: self.backing.offset + n,\n length: self.backing.length - n\n })\n }\n case \"IConcat\": {\n if (n > self.left.length) {\n return drop(self.right, n - self.left.length)\n }\n return makeChunk({\n _tag: \"IConcat\",\n left: drop(self.left, n),\n right: self.right\n })\n }\n default: {\n return makeChunk({\n _tag: \"ISlice\",\n chunk: self,\n offset: n,\n length: self.length - n\n })\n }\n }\n }\n})\n\n/**\n * Drops the last `n` elements.\n *\n * @since 2.0.0\n */\nexport const dropRight: {\n /**\n * Drops the last `n` elements.\n *\n * @since 2.0.0\n */\n (n: number): <A>(self: Chunk<A>) => Chunk<A>\n /**\n * Drops the last `n` elements.\n *\n * @since 2.0.0\n */\n <A>(self: Chunk<A>, n: number): Chunk<A>\n} = dual(2, <A>(self: Chunk<A>, n: number): Chunk<A> => take(self, Math.max(0, self.length - n)))\n\n/**\n * Drops all elements so long as the predicate returns true.\n *\n * @since 2.0.0\n */\nexport const dropWhile: {\n /**\n * Drops all elements so long as the predicate returns true.\n *\n * @since 2.0.0\n */\n <A>(predicate: Predicate<NoInfer<A>>): (self: Chunk<A>) => Chunk<A>\n /**\n * Drops all elements so long as the predicate returns true.\n *\n * @since 2.0.0\n */\n <A>(self: Chunk<A>, predicate: Predicate<A>): Chunk<A>\n} = dual(2, <A>(self: Chunk<A>, predicate: Predicate<A>): Chunk<A> => {\n const arr = toReadonlyArray(self)\n const len = arr.length\n let i = 0\n while (i < len && predicate(arr[i]!)) {\n i++\n }\n return drop(self, i)\n})\n\n/**\n * Prepends the specified prefix chunk to the beginning of the specified chunk.\n * If either chunk is non-empty, the result is also a non-empty chunk.\n *\n * @example\n * ```ts\n * import { Chunk } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Chunk.make(1, 2).pipe(Chunk.prependAll(Chunk.make(\"a\", \"b\")), Chunk.toArray),\n * [\"a\", \"b\", 1, 2]\n * )\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const prependAll: {\n /**\n * Prepends the specified prefix chunk to the beginning of the specified chunk.\n * If either chunk is non-empty, the result is also a non-empty chunk.\n *\n * @example\n * ```ts\n * import { Chunk } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Chunk.make(1, 2).pipe(Chunk.prependAll(Chunk.make(\"a\", \"b\")), Chunk.toArray),\n * [\"a\", \"b\", 1, 2]\n * )\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <S extends Chunk<any>, T extends Chunk<any>>(\n that: T\n ): (self: S) => Chunk.OrNonEmpty<S, T, Chunk.Infer<S> | Chunk.Infer<T>>\n /**\n * Prepends the specified prefix chunk to the beginning of the specified chunk.\n * If either chunk is non-empty, the result is also a non-empty chunk.\n *\n * @example\n * ```ts\n * import { Chunk } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Chunk.make(1, 2).pipe(Chunk.prependAll(Chunk.make(\"a\", \"b\")), Chunk.toArray),\n * [\"a\", \"b\", 1, 2]\n * )\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Chunk<A>, that: NonEmptyChunk<B>): NonEmptyChunk<A | B>\n /**\n * Prepends the specified prefix chunk to the beginning of the specified chunk.\n * If either chunk is non-empty, the result is also a non-empty chunk.\n *\n * @example\n * ```ts\n * import { Chunk } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Chunk.make(1, 2).pipe(Chunk.prependAll(Chunk.make(\"a\", \"b\")), Chunk.toArray),\n * [\"a\", \"b\", 1, 2]\n * )\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyChunk<A>, that: Chunk<B>): NonEmptyChunk<A | B>\n /**\n * Prepends the specified prefix chunk to the beginning of the specified chunk.\n * If either chunk is non-empty, the result is also a non-empty chunk.\n *\n * @example\n * ```ts\n * import { Chunk } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Chunk.make(1, 2).pipe(Chunk.prependAll(Chunk.make(\"a\", \"b\")), Chunk.toArray),\n * [\"a\", \"b\", 1, 2]\n * )\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Chunk<A>, that: Chunk<B>): Chunk<A | B>\n} = dual(2, <A, B>(self: NonEmptyChunk<A>, that: Chunk<B>): Chunk<A | B> => appendAll(that, self))\n\n/**\n * Concatenates two chunks, combining their elements.\n * If either chunk is non-empty, the result is also a non-empty chunk.\n *\n * @example\n * ```ts\n * import { Chunk } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Chunk.make(1, 2).pipe(Chunk.appendAll(Chunk.make(\"a\", \"b\")), Chunk.toArray),\n * [1, 2, \"a\", \"b\"]\n * )\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const appendAll: {\n /**\n * Concatenates two chunks, combining their elements.\n * If either chunk is non-empty, the result is also a non-empty chunk.\n *\n * @example\n * ```ts\n * import { Chunk } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Chunk.make(1, 2).pipe(Chunk.appendAll(Chunk.make(\"a\", \"b\")), Chunk.toArray),\n * [1, 2, \"a\", \"b\"]\n * )\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <S extends Chunk<any>, T extends Chunk<any>>(\n that: T\n ): (self: S) => Chunk.OrNonEmpty<S, T, Chunk.Infer<S> | Chunk.Infer<T>>\n /**\n * Concatenates two chunks, combining their elements.\n * If either chunk is non-empty, the result is also a non-empty chunk.\n *\n * @example\n * ```ts\n * import { Chunk } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Chunk.make(1, 2).pipe(Chunk.appendAll(Chunk.make(\"a\", \"b\")), Chunk.toArray),\n * [1, 2, \"a\", \"b\"]\n * )\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Chunk<A>, that: NonEmptyChunk<B>): NonEmptyChunk<A | B>\n /**\n * Concatenates two chunks, combining their elements.\n * If either chunk is non-empty, the result is also a non-empty chunk.\n *\n * @example\n * ```ts\n * import { Chunk } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Chunk.make(1, 2).pipe(Chunk.appendAll(Chunk.make(\"a\", \"b\")), Chunk.toArray),\n * [1, 2, \"a\", \"b\"]\n * )\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyChunk<A>, that: Chunk<B>): NonEmptyChunk<A | B>\n /**\n * Concatenates two chunks, combining their elements.\n * If either chunk is non-empty, the result is also a non-empty chunk.\n *\n * @example\n * ```ts\n * import { Chunk } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Chunk.make(1, 2).pipe(Chunk.appendAll(Chunk.make(\"a\", \"b\")), Chunk.toArray),\n * [1, 2, \"a\", \"b\"]\n * )\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Chunk<A>, that: Chunk<B>): Chunk<A | B>\n} = dual(2, <A, B>(self: Chunk<A>, that: Chunk<B>): Chunk<A | B> => {\n if (self.backing._tag === \"IEmpty\") {\n return that\n }\n if (that.backing._tag === \"IEmpty\") {\n return self\n }\n const diff = that.depth - self.depth\n if (Math.abs(diff) <= 1) {\n return makeChunk<\n /**\n * Concatenates two chunks, combining their elements.\n * If either chunk is non-empty, the result is also a non-empty chunk.\n *\n * @example\n * ```ts\n * import { Chunk } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Chunk.make(1, 2).pipe(Chunk.appendAll(Chunk.make(\"a\", \"b\")), Chunk.toArray),\n * [1, 2, \"a\", \"b\"]\n * )\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n A | B\n >({ _tag: \"IConcat\", left: self, right: that })\n } else if (diff < -1) {\n if (self.left.depth >= self.right.depth) {\n const nr = appendAll(self.right, that)\n return makeChunk({ _tag: \"IConcat\", left: self.left, right: nr })\n } else {\n const nrr = appendAll(self.right.right, that)\n if (nrr.depth === self.depth - 3) {\n const nr = makeChunk({ _tag: \"IConcat\", left: self.right.left, right: nrr })\n return makeChunk({ _tag: \"IConcat\", left: self.left, right: nr })\n } else {\n const nl = makeChunk({ _tag: \"IConcat\", left: self.left, right: self.right.left })\n return makeChunk({ _tag: \"IConcat\", left: nl, right: nrr })\n }\n }\n } else {\n if (that.right.depth >= that.left.depth) {\n const nl = appendAll(self, that.left)\n return makeChunk({ _tag: \"IConcat\", left: nl, right: that.right })\n } else {\n const nll = appendAll(self, that.left.left)\n if (nll.depth === that.depth - 3) {\n const nl = makeChunk({ _tag: \"IConcat\", left: nll, right: that.left.right })\n return makeChunk({ _tag: \"IConcat\", left: nl, right: that.right })\n } else {\n const nr = makeChunk({ _tag: \"IConcat\", left: that.left.right, right: that.right })\n return makeChunk({ _tag: \"IConcat\", left: nll, right: nr })\n }\n }\n }\n})\n\n/**\n * Returns a filtered and mapped subset of the elements.\n *\n * @since 2.0.0\n * @category filtering\n */\nexport const filterMap: {\n /**\n * Returns a filtered and mapped subset of the elements.\n *\n * @since 2.0.0\n * @category filtering\n */\n <A, B>(f: (a: A, i: number) => Option<B>): (self: Chunk<A>) => Chunk<B>\n /**\n * Returns a filtered and mapped subset of the elements.\n *\n * @since 2.0.0\n * @category filtering\n */\n <A, B>(self: Chunk<A>, f: (a: A, i: number) => Option<B>): Chunk<B>\n} = dual(\n 2,\n <A, B>(self: Chunk<A>, f: (a: A, i: number) => Option<B>): Chunk<B> => unsafeFromArray(RA.filterMap(self, f))\n)\n\n/**\n * Returns a filtered and mapped subset of the elements.\n *\n * @since 2.0.0\n * @category filtering\n */\nexport const filter: {\n /**\n * Returns a filtered and mapped subset of the elements.\n *\n * @since 2.0.0\n * @category filtering\n */\n <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: Chunk<A>) => Chunk<B>\n /**\n * Returns a filtered and mapped subset of the elements.\n *\n * @since 2.0.0\n * @category filtering\n */\n <A>(predicate: Predicate<NoInfer<A>>): (self: Chunk<A>) => Chunk<A>\n /**\n * Returns a filtered and mapped subset of the elements.\n *\n * @since 2.0.0\n * @category filtering\n */\n <A, B extends A>(self: Chunk<A>, refinement: Refinement<A, B>): Chunk<B>\n /**\n * Returns a filtered and mapped subset of the elements.\n *\n * @since 2.0.0\n * @category filtering\n */\n <A>(self: Chunk<A>, predicate: Predicate<A>): Chunk<A>\n} = dual(\n 2,\n <A>(self: Chunk<A>, predicate: Predicate<A>): Chunk<A> => unsafeFromArray(RA.filter(self, predicate))\n)\n\n/**\n * Transforms all elements of the chunk for as long as the specified function returns some value\n *\n * @since 2.0.0\n * @category filtering\n */\nexport const filterMapWhile: {\n /**\n * Transforms all elements of the chunk for as long as the specified function returns some value\n *\n * @since 2.0.0\n * @category filtering\n */\n <A, B>(f: (a: A) => Option<B>): (self: Chunk<A>) => Chunk<B>\n /**\n * Transforms all elements of the chunk for as long as the specified function returns some value\n *\n * @since 2.0.0\n * @category filtering\n */\n <A, B>(self: Chunk<A>, f: (a: A) => Option<B>): Chunk<B>\n} = dual(2, <A, B>(self: Chunk<A>, f: (a: A) => Option<B>) => unsafeFromArray(RA.filterMapWhile(self, f)))\n\n/**\n * Filter out optional values\n *\n * @since 2.0.0\n * @category filtering\n */\nexport const compact = <A>(self: Chunk<Option<A>>): Chunk<A> => filterMap(self, identity)\n\n/**\n * Applies a function to each element in a chunk and returns a new chunk containing the concatenated mapped elements.\n *\n * @since 2.0.0\n * @category sequencing\n */\nexport const flatMap: {\n /**\n * Applies a function to each element in a chunk and returns a new chunk containing the concatenated mapped elements.\n *\n * @since 2.0.0\n * @category sequencing\n */\n <S extends Chunk<any>, T extends Chunk<any>>(\n f: (a: Chunk.Infer<S>, i: number) => T\n ): (self: S) => Chunk.AndNonEmpty<S, T, Chunk.Infer<T>>\n /**\n * Applies a function to each element in a chunk and returns a new chunk containing the concatenated mapped elements.\n *\n * @since 2.0.0\n * @category sequencing\n */\n <A, B>(self: NonEmptyChunk<A>, f: (a: A, i: number) => NonEmptyChunk<B>): NonEmptyChunk<B>\n /**\n * Applies a function to each element in a chunk and returns a new chunk containing the concatenated mapped elements.\n *\n * @since 2.0.0\n * @category sequencing\n */\n <A, B>(self: Chunk<A>, f: (a: A, i: number) => Chunk<B>): Chunk<B>\n} = dual(2, <A, B>(self: Chunk<A>, f: (a: A, i: number) => Chunk<B>) => {\n if (self.backing._tag === \"ISingleton\") {\n return f(self.backing.a, 0)\n }\n let out: Chunk<B> = _empty\n let i = 0\n for (const k of self) {\n out = appendAll(out, f(k, i++))\n }\n return out\n})\n\n/**\n * Applies the specified function to each element of the `List`.\n *\n * @since 2.0.0\n * @category combinators\n */\nexport const forEach: {\n /**\n * Applies the specified function to each element of the `List`.\n *\n * @since 2.0.0\n * @category combinators\n */\n <A, B>(f: (a: A) => B): (self: Chunk<A>) => void\n /**\n * Applies the specified function to each element of the `List`.\n *\n * @since 2.0.0\n * @category combinators\n */\n <A, B>(self: Chunk<A>, f: (a: A) => B): void\n} = dual(2, <A, B>(self: Chunk<A>, f: (a: A) => B): void => toReadonlyArray(self).forEach(f))\n\n/**\n * Flattens a chunk of chunks into a single chunk by concatenating all chunks.\n *\n * @since 2.0.0\n * @category sequencing\n */\nexport const flatten: <S extends Chunk<Chunk<any>>>(self: S) => Chunk.Flatten<S> = flatMap(identity) as any\n\n/**\n * Groups elements in chunks of up to `n` elements.\n *\n * @since 2.0.0\n * @category elements\n */\nexport const chunksOf: {\n /**\n * Groups elements in chunks of up to `n` elements.\n *\n * @since 2.0.0\n * @category elements\n */\n (n: number): <A>(self: Chunk<A>) => Chunk<Chunk<A>>\n /**\n * Groups elements in chunks of up to `n` elements.\n *\n * @since 2.0.0\n * @category elements\n */\n <A>(self: Chunk<A>, n: number): Chunk<Chunk<A>>\n} = dual(2, <A>(self: Chunk<A>, n: number) => {\n const gr: Array<Chunk<A>> = []\n let current: Array<A> = []\n toReadonlyArray(self).forEach((a) => {\n current.push(a)\n if (current.length >= n) {\n gr.push(unsafeFromArray(current))\n current = []\n }\n })\n if (current.length > 0) {\n gr.push(unsafeFromArray(current))\n }\n return unsafeFromArray(gr)\n})\n\n/**\n * Creates a Chunk of unique values that are included in all given Chunks.\n *\n * The order and references of result values are determined by the Chunk.\n *\n * @since 2.0.0\n * @category elements\n */\nexport const intersection: {\n /**\n * Creates a Chunk of unique values that are included in all given Chunks.\n *\n * The order and references of result values are determined by the Chunk.\n *\n * @since 2.0.0\n * @category elements\n */\n <A>(that: Chunk<A>): <B>(self: Chunk<B>) => Chunk<A & B>\n /**\n * Creates a Chunk of unique values that are included in all given Chunks.\n *\n * The order and references of result values are determined by the Chunk.\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B>(self: Chunk<A>, that: Chunk<B>): Chunk<A & B>\n} = dual(\n 2,\n <A, B>(self: Chunk<A>, that: Chunk<B>): Chunk<A & B> =>\n unsafeFromArray(RA.intersection(toReadonlyArray(self), toReadonlyArray(that)))\n)\n\n/**\n * Determines if the chunk is empty.\n *\n * @since 2.0.0\n * @category elements\n */\nexport const isEmpty = <A>(self: Chunk<A>): boolean => self.length === 0\n\n/**\n * Determines if the chunk is not empty.\n *\n * @since 2.0.0\n * @category elements\n */\nexport const isNonEmpty = <A>(self: Chunk<A>): self is NonEmptyChunk<A> => self.length > 0\n\n/**\n * Returns the first element of this chunk if it exists.\n *\n * @since 2.0.0\n * @category elements\n */\nexport const head: <A>(self: Chunk<A>) => Option<A> = get(0)\n\n/**\n * Returns the first element of this chunk.\n *\n * It will throw an error if the chunk is empty.\n *\n * @since 2.0.0\n * @category unsafe\n */\nexport const unsafeHead = <A>(self: Chunk<A>): A => unsafeGet(self, 0)\n\n/**\n * Returns the first element of this non empty chunk.\n *\n * @since 2.0.0\n * @category elements\n */\nexport const headNonEmpty: <A>(self: NonEmptyChunk<A>) => A = unsafeHead\n\n/**\n * Returns the last element of this chunk if it exists.\n *\n * @since 2.0.0\n * @category elements\n */\nexport const last = <A>(self: Chunk<A>): Option<A> => get(self, self.length - 1)\n\n/**\n * Returns the last element of this chunk.\n *\n * It will throw an error if the chunk is empty.\n *\n * @since 2.0.0\n * @category unsafe\n */\nexport const unsafeLast = <A>(self: Chunk<A>): A => unsafeGet(self, self.length - 1)\n\n/**\n * Returns the last element of this non empty chunk.\n *\n * @since 3.4.0\n * @category elements\n */\nexport const lastNonEmpty: <A>(self: NonEmptyChunk<A>) => A = unsafeLast\n\n/**\n * @since 2.0.0\n */\nexport declare namespace Chunk {\n /**\n * @since 2.0.0\n */\n export type Infer<S extends Chunk<any>> = S extends Chunk<infer A> ? A : never\n\n /**\n * @since 2.0.0\n */\n export type With<S extends Chunk<any>, A> = S extends NonEmptyChunk<any> ? NonEmptyChunk<A> : Chunk<A>\n\n /**\n * @since 2.0.0\n */\n export type OrNonEmpty<S extends Chunk<any>, T extends Chunk<any>, A> = S extends NonEmptyChunk<any> ?\n NonEmptyChunk<A>\n : T extends NonEmptyChunk<any> ? NonEmptyChunk<A>\n : Chunk<A>\n\n /**\n * @since 2.0.0\n */\n export type AndNonEmpty<S extends Chunk<any>, T extends Chunk<any>, A> = S extends NonEmptyChunk<any> ?\n T extends NonEmptyChunk<any> ? NonEmptyChunk<A>\n : Chunk<A> :\n Chunk<A>\n\n /**\n * @since 2.0.0\n */\n export type Flatten<T extends Chunk<Chunk<any>>> = T extends NonEmptyChunk<NonEmptyChunk<infer A>> ? NonEmptyChunk<A>\n : T extends Chunk<Chunk<infer A>> ? Chunk<A>\n : never\n}\n\n/**\n * Transforms the elements of a chunk using the specified mapping function.\n * If the input chunk is non-empty, the resulting chunk will also be non-empty.\n *\n * @example\n * ```ts\n * import { Chunk } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Chunk.map(Chunk.make(1, 2), (n) => n + 1),\n * Chunk.make(2, 3)\n * )\n * ```\n *\n * @since 2.0.0\n * @category mapping\n */\nexport const map: {\n /**\n * Transforms the elements of a chunk using the specified mapping function.\n * If the input chunk is non-empty, the resulting chunk will also be non-empty.\n *\n * @example\n * ```ts\n * import { Chunk } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Chunk.map(Chunk.make(1, 2), (n) => n + 1),\n * Chunk.make(2, 3)\n * )\n * ```\n *\n * @since 2.0.0\n * @category mapping\n */\n <S extends Chunk<any>, B>(f: (a: Chunk.Infer<S>, i: number) => B): (self: S) => Chunk.With<S, B>\n /**\n * Transforms the elements of a chunk using the specified mapping function.\n * If the input chunk is non-empty, the resulting chunk will also be non-empty.\n *\n * @example\n * ```ts\n * import { Chunk } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Chunk.map(Chunk.make(1, 2), (n) => n + 1),\n * Chunk.make(2, 3)\n * )\n * ```\n *\n * @since 2.0.0\n * @category mapping\n */\n <A, B>(self: NonEmptyChunk<A>, f: (a: A, i: number) => B): NonEmptyChunk<B>\n /**\n * Transforms the elements of a chunk using the specified mapping function.\n * If the input chunk is non-empty, the resulting chunk will also be non-empty.\n *\n * @example\n * ```ts\n * import { Chunk } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Chunk.map(Chunk.make(1, 2), (n) => n + 1),\n * Chunk.make(2, 3)\n * )\n * ```\n *\n * @since 2.0.0\n * @category mapping\n */\n <A, B>(self: Chunk<A>, f: (a: A, i: number) => B): Chunk<B>\n} = dual(2, <A, B>(self: Chunk<A>, f: (a: A, i: number) => B): Chunk<B> =>\n self.backing._tag === \"ISingleton\" ?\n of(f(self.backing.a, 0)) :\n unsafeFromArray(pipe(toReadonlyArray(self), RA.map((a, i) => f(a, i)))))\n\n/**\n * Statefully maps over the chunk, producing new elements of type `B`.\n *\n * @since 2.0.0\n * @category folding\n */\nexport const mapAccum: {\n /**\n * Statefully maps over the chunk, producing new elements of type `B`.\n *\n * @since 2.0.0\n * @category folding\n */\n <S, A, B>(s: S, f: (s: S, a: A) => readonly [S, B]): (self: Chunk<A>) => [S, Chunk<B>]\n /**\n * Statefully maps over the chunk, producing new elements of type `B`.\n *\n * @since 2.0.0\n * @category folding\n */\n <S, A, B>(self: Chunk<A>, s: S, f: (s: S, a: A) => readonly [S, B]): [S, Chunk<B>]\n} = dual(3, <S, A, B>(self: Chunk<A>, s: S, f: (s: S, a: A) => readonly [S, B]): [S, Chunk<B>] => {\n const [s1, as] = RA.mapAccum(self, s, f)\n return [s1, unsafeFromArray(as)]\n})\n\n/**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const partition: {\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(\n refinement: (a: NoInfer<A>, i: number) => a is B\n ): (self: Chunk<A>) => [excluded: Chunk<Exclude<A, B>>, satisfying: Chunk<B>]\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * @category filtering\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Chunk<A>) => [excluded: Chunk<A>, satisfying: Chunk<A>]\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(\n self: Chunk<A>,\n refinement: (a: A, i: number) => a is B\n ): [excluded: Chunk<Exclude<A, B>>, satisfying: Chunk<B>]\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * @category filtering\n * @since 2.0.0\n */\n <A>(self: Chunk<A>, predicate: (a: A, i: number) => boolean): [excluded: Chunk<A>, satisfying: Chunk<A>]\n} = dual(\n 2,\n <A>(self: Chunk<A>, predicate: (a: A, i: number) => boolean): [excluded: Chunk<A>, satisfying: Chunk<A>] =>\n pipe(\n RA.partition(toReadonlyArray(self), predicate),\n ([l, r]) => [unsafeFromArray(l), unsafeFromArray(r)]\n )\n)\n\n/**\n * Partitions the elements of this chunk into two chunks using f.\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const partitionMap: {\n /**\n * Partitions the elements of this chunk into two chunks using f.\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B, C>(f: (a: A) => Either<C, B>): (self: Chunk<A>) => [left: Chunk<B>, right: Chunk<C>]\n /**\n * Partitions the elements of this chunk into two chunks using f.\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B, C>(self: Chunk<A>, f: (a: A) => Either<C, B>): [left: Chunk<B>, right: Chunk<C>]\n} = dual(2, <A, B, C>(self: Chunk<A>, f: (a: A) => Either<C, B>): [left: Chunk<B>, right: Chunk<C>] =>\n pipe(\n RA.partitionMap(toReadonlyArray(self), f),\n ([l, r]) => [unsafeFromArray(l), unsafeFromArray(r)]\n ))\n\n/**\n * Partitions the elements of this chunk into two chunks.\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const separate = <A, B>(self: Chunk<Either<B, A>>): [Chunk<A>, Chunk<B>] =>\n pipe(\n RA.separate(toReadonlyArray(self)),\n ([l, r]) => [unsafeFromArray(l), unsafeFromArray(r)]\n )\n\n/**\n * Retireves the size of the chunk\n *\n * @since 2.0.0\n * @category elements\n */\nexport const size = <A>(self: Chunk<A>): number => self.length\n\n/**\n * Sort the elements of a Chunk in increasing order, creating a new Chunk.\n *\n * @since 2.0.0\n * @category sorting\n */\nexport const sort: {\n /**\n * Sort the elements of a Chunk in increasing order, creating a new Chunk.\n *\n * @since 2.0.0\n * @category sorting\n */\n <B>(O: Order.Order<B>): <A extends B>(self: Chunk<A>) => Chunk<A>\n /**\n * Sort the elements of a Chunk in increasing order, creating a new Chunk.\n *\n * @since 2.0.0\n * @category sorting\n */\n <A extends B, B>(self: Chunk<A>, O: Order.Order<B>): Chunk<A>\n} = dual(\n 2,\n <A extends B, B>(self: Chunk<A>, O: Order.Order<B>): Chunk<A> => unsafeFromArray(RA.sort(toReadonlyArray(self), O))\n)\n\n/**\n * @since 2.0.0\n * @category sorting\n */\nexport const sortWith: {\n /**\n * @since 2.0.0\n * @category sorting\n */\n <A, B>(f: (a: A) => B, order: Order.Order<B>): (self: Chunk<A>) => Chunk<A>\n /**\n * @since 2.0.0\n * @category sorting\n */\n <A, B>(self: Chunk<A>, f: (a: A) => B, order: Order.Order<B>): Chunk<A>\n} = dual(\n 3,\n <A, B>(self: Chunk<A>, f: (a: A) => B, order: Order.Order<B>): Chunk<A> => sort(self, Order.mapInput(order, f))\n)\n\n/**\n * Returns two splits of this chunk at the specified index.\n *\n * @since 2.0.0\n * @category splitting\n */\nexport const splitAt: {\n /**\n * Returns two splits of this chunk at the specified index.\n *\n * @since 2.0.0\n * @category splitting\n */\n (n: number): <A>(self: Chunk<A>) => [beforeIndex: Chunk<A>, fromIndex: Chunk<A>]\n /**\n * Returns two splits of this chunk at the specified index.\n *\n * @since 2.0.0\n * @category splitting\n */\n <A>(self: Chunk<A>, n: number): [beforeIndex: Chunk<A>, fromIndex: Chunk<A>]\n} = dual(2, <A>(self: Chunk<A>, n: number): [Chunk<A>, Chunk<A>] => [take(self, n), drop(self, n)])\n\n/**\n * Splits a `NonEmptyChunk` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` must be `>= 1`.\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const splitNonEmptyAt: {\n /**\n * Splits a `NonEmptyChunk` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` must be `>= 1`.\n *\n * @category splitting\n * @since 2.0.0\n */\n (n: number): <A>(self: NonEmptyChunk<A>) => [beforeIndex: NonEmptyChunk<A>, fromIndex: Chunk<A>]\n /**\n * Splits a `NonEmptyChunk` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` must be `>= 1`.\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: NonEmptyChunk<A>, n: number): [beforeIndex: NonEmptyChunk<A>, fromIndex: Chunk<A>]\n} = dual(2, <A>(self: NonEmptyChunk<A>, n: number): [Chunk<A>, Chunk<A>] => {\n const _n = Math.max(1, Math.floor(n))\n return _n >= self.length ?\n [self, empty()] :\n [take(self, _n), drop(self, _n)]\n})\n\n/**\n * Splits this chunk into `n` equally sized chunks.\n *\n * @since 2.0.0\n * @category splitting\n */\nexport const split: {\n /**\n * Splits this chunk into `n` equally sized chunks.\n *\n * @since 2.0.0\n * @category splitting\n */\n (n: number): <A>(self: Chunk<A>) => Chunk<Chunk<A>>\n /**\n * Splits this chunk into `n` equally sized chunks.\n *\n * @since 2.0.0\n * @category splitting\n */\n <A>(self: Chunk<A>, n: number): Chunk<Chunk<A>>\n} = dual(2, <A>(self: Chunk<A>, n: number) => chunksOf(self, Math.ceil(self.length / Math.floor(n))))\n\n/**\n * Splits this chunk on the first element that matches this predicate.\n * Returns a tuple containing two chunks: the first one is before the match, and the second one is from the match onward.\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const splitWhere: {\n /**\n * Splits this chunk on the first element that matches this predicate.\n * Returns a tuple containing two chunks: the first one is before the match, and the second one is from the match onward.\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(predicate: Predicate<NoInfer<A>>): (self: Chunk<A>) => [beforeMatch: Chunk<A>, fromMatch: Chunk<A>]\n /**\n * Splits this chunk on the first element that matches this predicate.\n * Returns a tuple containing two chunks: the first one is before the match, and the second one is from the match onward.\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: Chunk<A>, predicate: Predicate<A>): [beforeMatch: Chunk<A>, fromMatch: Chunk<A>]\n} = dual(2, <A>(self: Chunk<A>, predicate: Predicate<A>): [beforeMatch: Chunk<A>, fromMatch: Chunk<A>] => {\n let i = 0\n for (const a of toReadonlyArray(self)) {\n if (predicate(a)) {\n break\n } else {\n i++\n }\n }\n return splitAt(self, i)\n})\n\n/**\n * Returns every elements after the first.\n *\n * @since 2.0.0\n * @category elements\n */\nexport const tail = <A>(self: Chunk<A>): Option<Chunk<A>> => self.length > 0 ? O.some(drop(self, 1)) : O.none()\n\n/**\n * Returns every elements after the first.\n *\n * @since 2.0.0\n * @category elements\n */\nexport const tailNonEmpty = <A>(self: NonEmptyChunk<A>): Chunk<A> => drop(self, 1)\n\n/**\n * Takes the last `n` elements.\n *\n * @since 2.0.0\n * @category elements\n */\nexport const takeRight: {\n /**\n * Takes the last `n` elements.\n *\n * @since 2.0.0\n * @category elements\n */\n (n: number): <A>(self: Chunk<A>) => Chunk<A>\n /**\n * Takes the last `n` elements.\n *\n * @since 2.0.0\n * @category elements\n */\n <A>(self: Chunk<A>, n: number): Chunk<A>\n} = dual(2, <A>(self: Chunk<A>, n: number): Chunk<A> => drop(self, self.length - n))\n\n/**\n * Takes all elements so long as the predicate returns true.\n *\n * @since 2.0.0\n * @category elements\n */\nexport const takeWhile: {\n /**\n * Takes all elements so long as the predicate returns true.\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: Chunk<A>) => Chunk<B>\n /**\n * Takes all elements so long as the predicate returns true.\n *\n * @since 2.0.0\n * @category elements\n */\n <A>(predicate: Predicate<NoInfer<A>>): (self: Chunk<A>) => Chunk<A>\n /**\n * Takes all elements so long as the predicate returns true.\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B extends A>(self: Chunk<A>, refinement: Refinement<A, B>): Chunk<B>\n /**\n * Takes all elements so long as the predicate returns true.\n *\n * @since 2.0.0\n * @category elements\n */\n <A>(self: Chunk<A>, predicate: Predicate<A>): Chunk<A>\n} = dual(2, <A>(self: Chunk<A>, predicate: Predicate<A>): Chunk<A> => {\n const out: Array<A> = []\n for (const a of toReadonlyArray(self)) {\n if (predicate(a)) {\n out.push(a)\n } else {\n break\n }\n }\n return unsafeFromArray(out)\n})\n\n/**\n * Creates a Chunks of unique values, in order, from all given Chunks.\n *\n * @since 2.0.0\n * @category elements\n */\nexport const union: {\n /**\n * Creates a Chunks of unique values, in order, from all given Chunks.\n *\n * @since 2.0.0\n * @category elements\n */\n <A>(that: Chunk<A>): <B>(self: Chunk<B>) => Chunk<A | B>\n /**\n * Creates a Chunks of unique values, in order, from all given Chunks.\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B>(self: Chunk<A>, that: Chunk<B>): Chunk<A | B>\n} = dual(\n 2,\n <A, B>(self: Chunk<A>, that: Chunk<B>) => unsafeFromArray(RA.union(toReadonlyArray(self), toReadonlyArray(that)))\n)\n\n/**\n * Remove duplicates from an array, keeping the first occurrence of an element.\n *\n * @since 2.0.0\n * @category elements\n */\nexport const dedupe = <A>(self: Chunk<A>): Chunk<A> => unsafeFromArray(RA.dedupe(toReadonlyArray(self)))\n\n/**\n * Deduplicates adjacent elements that are identical.\n *\n * @since 2.0.0\n * @category filtering\n */\nexport const dedupeAdjacent = <A>(self: Chunk<A>): Chunk<A> => unsafeFromArray(RA.dedupeAdjacent(self))\n\n/**\n * Takes a `Chunk` of pairs and return two corresponding `Chunk`s.\n *\n * Note: The function is reverse of `zip`.\n *\n * @since 2.0.0\n * @category elements\n */\nexport const unzip = <A, B>(self: Chunk<readonly [A, B]>): [Chunk<A>, Chunk<B>] => {\n const [left, right] = RA.unzip(self)\n return [unsafeFromArray(left), unsafeFromArray(right)]\n}\n\n/**\n * Zips this chunk pointwise with the specified chunk using the specified combiner.\n *\n * @since 2.0.0\n * @category zipping\n */\nexport const zipWith: {\n /**\n * Zips this chunk pointwise with the specified chunk using the specified combiner.\n *\n * @since 2.0.0\n * @category zipping\n */\n <A, B, C>(that: Chunk<B>, f: (a: A, b: B) => C): (self: Chunk<A>) => Chunk<C>\n /**\n * Zips this chunk pointwise with the specified chunk using the specified combiner.\n *\n * @since 2.0.0\n * @category zipping\n */\n <A, B, C>(self: Chunk<A>, that: Chunk<B>, f: (a: A, b: B) => C): Chunk<C>\n} = dual(\n 3,\n <A, B, C>(self: Chunk<A>, that: Chunk<B>, f: (a: A, b: B) => C): Chunk<C> =>\n unsafeFromArray(RA.zipWith(self, that, f))\n)\n\n/**\n * Zips this chunk pointwise with the specified chunk.\n *\n * @since 2.0.0\n * @category zipping\n */\nexport const zip: {\n /**\n * Zips this chunk pointwise with the specified chunk.\n *\n * @since 2.0.0\n * @category zipping\n */\n <B>(that: Chunk<B>): <A>(self: Chunk<A>) => Chunk<[A, B]>\n /**\n * Zips this chunk pointwise with the specified chunk.\n *\n * @since 2.0.0\n * @category zipping\n */\n <A, B>(self: Chunk<A>, that: Chunk<B>): Chunk<[A, B]>\n} = dual(\n 2,\n <A, B>(self: Chunk<A>, that: Chunk<B>): Chunk<[A, B]> => zipWith(self, that, (a, b) => [a, b])\n)\n\n/**\n * Delete the element at the specified index, creating a new `Chunk`,\n * or returning the input if the index is out of bounds.\n *\n * @since 2.0.0\n */\nexport const remove: {\n /**\n * Delete the element at the specified index, creating a new `Chunk`,\n * or returning the input if the index is out of bounds.\n *\n * @since 2.0.0\n */\n (i: number): <A>(self: Chunk<A>) => Chunk<A>\n /**\n * Delete the element at the specified index, creating a new `Chunk`,\n * or returning the input if the index is out of bounds.\n *\n * @since 2.0.0\n */\n <A>(self: Chunk<A>, i: number): Chunk<A>\n} = dual(\n 2,\n <A>(self: Chunk<A>, i: number): Chunk<A> => unsafeFromArray(RA.remove(toReadonlyArray(self), i))\n)\n\n/**\n * @since 2.0.0\n */\nexport const modifyOption: {\n /**\n * @since 2.0.0\n */\n <A, B>(i: number, f: (a: A) => B): (self: Chunk<A>) => Option<Chunk<A | B>>\n /**\n * @since 2.0.0\n */\n <A, B>(self: Chunk<A>, i: number, f: (a: A) => B): Option<Chunk<A | B>>\n} = dual(\n 3,\n <A, B>(self: Chunk<A>, i: number, f: (a: A) => B): Option<Chunk<A | B>> =>\n O.map(RA.modifyOption(toReadonlyArray(self), i, f), unsafeFromArray)\n)\n\n/**\n * Apply a function to the element at the specified index, creating a new `Chunk`,\n * or returning the input if the index is out of bounds.\n *\n * @since 2.0.0\n */\nexport const modify: {\n /**\n * Apply a function to the element at the specified index, creating a new `Chunk`,\n * or returning the input if the index is out of bounds.\n *\n * @since 2.0.0\n */\n <A, B>(i: number, f: (a: A) => B): (self: Chunk<A>) => Chunk<A | B>\n /**\n * Apply a function to the element at the specified index, creating a new `Chunk`,\n * or returning the input if the index is out of bounds.\n *\n * @since 2.0.0\n */\n <A, B>(self: Chunk<A>, i: number, f: (a: A) => B): Chunk<A | B>\n} = dual(\n 3,\n <A, B>(self: Chunk<A>, i: number, f: (a: A) => B): Chunk<A | B> => O.getOrElse(modifyOption(self, i, f), () => self)\n)\n\n/**\n * Change the element at the specified index, creating a new `Chunk`,\n * or returning the input if the index is out of bounds.\n *\n * @since 2.0.0\n */\nexport const replace: {\n /**\n * Change the element at the specified index, creating a new `Chunk`,\n * or returning the input if the index is out of bounds.\n *\n * @since 2.0.0\n */\n <B>(i: number, b: B): <A>(self: Chunk<A>) => Chunk<B | A>\n /**\n * Change the element at the specified index, creating a new `Chunk`,\n * or returning the input if the index is out of bounds.\n *\n * @since 2.0.0\n */\n <A, B>(self: Chunk<A>, i: number, b: B): Chunk<B | A>\n} = dual(3, <A, B>(self: Chunk<A>, i: number, b: B): Chunk<B | A> => modify(self, i, () => b))\n\n/**\n * @since 2.0.0\n */\nexport const replaceOption: {\n /**\n * @since 2.0.0\n */\n <B>(i: number, b: B): <A>(self: Chunk<A>) => Option<Chunk<B | A>>\n /**\n * @since 2.0.0\n */\n <A, B>(self: Chunk<A>, i: number, b: B): Option<Chunk<B | A>>\n} = dual(3, <A, B>(self: Chunk<A>, i: number, b: B): Option<Chunk<B | A>> => modifyOption(self, i, () => b))\n\n/**\n * Return a Chunk of length n with element i initialized with f(i).\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const makeBy: {\n /**\n * Return a Chunk of length n with element i initialized with f(i).\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * @category constructors\n * @since 2.0.0\n */\n <A>(f: (i: number) => A): (n: number) => NonEmptyChunk<A>\n /**\n * Return a Chunk of length n with element i initialized with f(i).\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * @category constructors\n * @since 2.0.0\n */\n <A>(n: number, f: (i: number) => A): NonEmptyChunk<A>\n} = dual(2, (n, f) => fromIterable(RA.makeBy(n, f)))\n\n/**\n * Create a non empty `Chunk` containing a range of integers, including both endpoints.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const range = (start: number, end: number): NonEmptyChunk<number> =>\n start <= end ? makeBy(end - start + 1, (i) => start + i) : of(start)\n\n// -------------------------------------------------------------------------------------\n// re-exports from ReadonlyArray\n// -------------------------------------------------------------------------------------\n\n/**\n * Returns a function that checks if a `Chunk` contains a given value using the default `Equivalence`.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const contains: {\n // -------------------------------------------------------------------------------------\n // re-exports from ReadonlyArray\n // -------------------------------------------------------------------------------------\n\n /**\n * Returns a function that checks if a `Chunk` contains a given value using the default `Equivalence`.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(a: A): (self: Chunk<A>) => boolean\n // -------------------------------------------------------------------------------------\n // re-exports from ReadonlyArray\n // -------------------------------------------------------------------------------------\n\n /**\n * Returns a function that checks if a `Chunk` contains a given value using the default `Equivalence`.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Chunk<A>, a: A): boolean\n} = RA.contains\n\n/**\n * Returns a function that checks if a `Chunk` contains a given value using a provided `isEquivalent` function.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const containsWith: <A>(\n isEquivalent: (self: A, that: A) => boolean\n) => {\n (a: A): (self: Chunk<A>) => boolean\n (self: Chunk<A>, a: A): boolean\n} = RA.containsWith\n\n/**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findFirst: {\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: Chunk<A>) => Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: Predicate<NoInfer<A>>): (self: Chunk<A>) => Option<A>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(self: Chunk<A>, refinement: Refinement<A, B>): Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Chunk<A>, predicate: Predicate<A>): Option<A>\n} = RA.findFirst\n\n/**\n * Return the first index for which a predicate holds.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findFirstIndex: {\n /**\n * Return the first index for which a predicate holds.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: Predicate<A>): (self: Chunk<A>) => Option<number>\n /**\n * Return the first index for which a predicate holds.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Chunk<A>, predicate: Predicate<A>): Option<number>\n} = RA.findFirstIndex\n\n/**\n * Find the last element for which a predicate holds.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findLast: {\n /**\n * Find the last element for which a predicate holds.\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: Chunk<A>) => Option<B>\n /**\n * Find the last element for which a predicate holds.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: Predicate<NoInfer<A>>): (self: Chunk<A>) => Option<A>\n /**\n * Find the last element for which a predicate holds.\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(self: Chunk<A>, refinement: Refinement<A, B>): Option<B>\n /**\n * Find the last element for which a predicate holds.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Chunk<A>, predicate: Predicate<A>): Option<A>\n} = RA.findLast\n\n/**\n * Return the last index for which a predicate holds.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findLastIndex: {\n /**\n * Return the last index for which a predicate holds.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: Predicate<A>): (self: Chunk<A>) => Option<number>\n /**\n * Return the last index for which a predicate holds.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Chunk<A>, predicate: Predicate<A>): Option<number>\n} = RA.findLastIndex\n\n/**\n * Check if a predicate holds true for every `Chunk` element.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const every: {\n /**\n * Check if a predicate holds true for every `Chunk` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: Chunk<A>) => self is Chunk<B>\n /**\n * Check if a predicate holds true for every `Chunk` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: Predicate<A>): (self: Chunk<A>) => boolean\n /**\n * Check if a predicate holds true for every `Chunk` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(self: Chunk<A>, refinement: Refinement<A, B>): self is Chunk<B>\n /**\n * Check if a predicate holds true for every `Chunk` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Chunk<A>, predicate: Predicate<A>): boolean\n} = dual(\n 2,\n <A, B extends A>(self: Chunk<A>, refinement: Refinement<A, B>): self is Chunk<B> =>\n RA.fromIterable(self).every(refinement)\n)\n\n/**\n * Check if a predicate holds true for some `Chunk` element.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const some: {\n /**\n * Check if a predicate holds true for some `Chunk` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: Predicate<NoInfer<A>>): (self: Chunk<A>) => self is NonEmptyChunk<A>\n /**\n * Check if a predicate holds true for some `Chunk` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Chunk<A>, predicate: Predicate<A>): self is NonEmptyChunk<A>\n} = dual(\n 2,\n <A>(self: Chunk<A>, predicate: Predicate<A>): self is NonEmptyChunk<A> => RA.fromIterable(self).some(predicate)\n)\n\n/**\n * Joins the elements together with \"sep\" in the middle.\n *\n * @category folding\n * @since 2.0.0\n */\nexport const join: {\n /**\n * Joins the elements together with \"sep\" in the middle.\n *\n * @category folding\n * @since 2.0.0\n */\n (sep: string): (self: Chunk<string>) => string\n /**\n * Joins the elements together with \"sep\" in the middle.\n *\n * @category folding\n * @since 2.0.0\n */\n (self: Chunk<string>, sep: string): string\n} = RA.join\n\n/**\n * @category folding\n * @since 2.0.0\n */\nexport const reduce: {\n /**\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Chunk<A>) => B\n /**\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Chunk<A>, b: B, f: (b: B, a: A, i: number) => B): B\n} = RA.reduce\n\n/**\n * @category folding\n * @since 2.0.0\n */\nexport const reduceRight: {\n /**\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Chunk<A>) => B\n /**\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Chunk<A>, b: B, f: (b: B, a: A, i: number) => B): B\n} = RA.reduceRight\n\n/**\n * Creates a `Chunk` of values not included in the other given `Chunk` using the provided `isEquivalent` function.\n * The order and references of result values are determined by the first `Chunk`.\n *\n * @since 3.2.0\n */\nexport const differenceWith = <A>(isEquivalent: (self: A, that: A) => boolean): {\n (that: Chunk<A>): (self: Chunk<A>) => Chunk<A>\n (self: Chunk<A>, that: Chunk<A>): Chunk<A>\n} => {\n return dual(\n 2,\n (self: Chunk<A>, that: Chunk<A>): Chunk<A> => unsafeFromArray(RA.differenceWith(isEquivalent)(that, self))\n )\n}\n\n/**\n * Creates a `Chunk` of values not included in the other given `Chunk`.\n * The order and references of result values are determined by the first `Chunk`.\n *\n * @since 3.2.0\n */\nexport const difference: {\n /**\n * Creates a `Chunk` of values not included in the other given `Chunk`.\n * The order and references of result values are determined by the first `Chunk`.\n *\n * @since 3.2.0\n */\n <A>(that: Chunk<A>): (self: Chunk<A>) => Chunk<A>\n /**\n * Creates a `Chunk` of values not included in the other given `Chunk`.\n * The order and references of result values are determined by the first `Chunk`.\n *\n * @since 3.2.0\n */\n <A>(self: Chunk<A>, that: Chunk<A>): Chunk<A>\n} = dual(\n 2,\n <A>(self: Chunk<A>, that: Chunk<A>): Chunk<A> => unsafeFromArray(RA.difference(that, self))\n)\n","/** @internal */\nexport const SIZE = 5\n\n/** @internal */\nexport const BUCKET_SIZE = Math.pow(2, SIZE)\n\n/** @internal */\nexport const MASK = BUCKET_SIZE - 1\n\n/** @internal */\nexport const MAX_INDEX_NODE = BUCKET_SIZE / 2\n\n/** @internal */\nexport const MIN_ARRAY_NODE = BUCKET_SIZE / 4\n","import { MASK } from \"./config.js\"\n\n/**\n * Hamming weight.\n *\n * Taken from: http://jsperf.com/hamming-weight\n *\n * @internal\n */\nexport function popcount(x: number) {\n x -= (x >> 1) & 0x55555555\n x = (x & 0x33333333) + ((x >> 2) & 0x33333333)\n x = (x + (x >> 4)) & 0x0f0f0f0f\n x += x >> 8\n x += x >> 16\n return x & 0x7f\n}\n\n/** @internal */\nexport function hashFragment(shift: number, h: number) {\n return (h >>> shift) & MASK\n}\n\n/** @internal */\nexport function toBitmap(x: number) {\n return 1 << x\n}\n\n/** @internal */\nexport function fromBitmap(bitmap: number, bit: number) {\n return popcount(bitmap & (bit - 1))\n}\n","/** @internal */\nexport interface Stack<out A> {\n readonly value: A\n readonly previous: Stack<A> | undefined\n}\n\nexport const make = <A>(value: A, previous?: Stack<A>): Stack<A> => ({\n value,\n previous\n})\n","/** @internal */\nexport function arrayUpdate<A>(mutate: boolean, at: number, v: A, arr: Array<A>) {\n let out = arr\n if (!mutate) {\n const len = arr.length\n out = new Array(len)\n for (let i = 0; i < len; ++i) out[i] = arr[i]!\n }\n out[at] = v\n return out\n}\n\n/** @internal */\nexport function arraySpliceOut<A>(mutate: boolean, at: number, arr: Array<A>) {\n const newLen = arr.length - 1\n let i = 0\n let g = 0\n let out = arr\n if (mutate) {\n i = g = at\n } else {\n out = new Array(newLen)\n while (i < at) out[g++] = arr[i++]!\n }\n ;++i\n while (i <= newLen) out[g++] = arr[i++]!\n if (mutate) {\n out.length = newLen\n }\n return out\n}\n\n/** @internal */\nexport function arraySpliceIn<A>(mutate: boolean, at: number, v: A, arr: Array<A>) {\n const len = arr.length\n if (mutate) {\n let i = len\n while (i >= at) arr[i--] = arr[i]!\n arr[at] = v\n return arr\n }\n let i = 0,\n g = 0\n const out = new Array<A>(len + 1)\n while (i < at) out[g++] = arr[i++]!\n out[at] = v\n while (i < len) out[++g] = arr[i++]!\n return out\n}\n","import { equals } from \"../../Equal.js\"\nimport type { HashMap } from \"../../HashMap.js\"\nimport * as O from \"../../Option.js\"\nimport { isTagged } from \"../../Predicate.js\"\nimport * as Stack from \"../stack.js\"\nimport { arraySpliceIn, arraySpliceOut, arrayUpdate } from \"./array.js\"\nimport { fromBitmap, hashFragment, toBitmap } from \"./bitwise.js\"\nimport { MAX_INDEX_NODE, MIN_ARRAY_NODE, SIZE } from \"./config.js\"\n\n/** @internal */\nexport type Node<K, V> =\n | EmptyNode<K, V>\n | LeafNode<K, V>\n | CollisionNode<K, V>\n | IndexedNode<K, V>\n | ArrayNode<K, V>\n\n/** @internal */\nexport interface SizeRef {\n value: number // mutable by design\n}\n\n/** @internal */\nexport class EmptyNode<out K, out V> {\n readonly _tag = \"EmptyNode\"\n\n modify(\n edit: number,\n _shift: number,\n f: HashMap.UpdateFn<V>,\n hash: number,\n key: K,\n size: SizeRef\n ): Node<K, V> {\n const v = f(O.none())\n if (O.isNone(v)) return new EmptyNode()\n ;++size.value\n return new LeafNode(edit, hash, key, v)\n }\n}\n\n/** @internal */\nexport function isEmptyNode(a: unknown): a is EmptyNode<unknown, unknown> {\n return isTagged(a, \"EmptyNode\")\n}\n\n/** @internal */\nexport function isLeafNode<K, V>(\n node: Node<K, V>\n): node is EmptyNode<K, V> | LeafNode<K, V> | CollisionNode<K, V> {\n return isEmptyNode(node) || node._tag === \"LeafNode\" || node._tag === \"CollisionNode\"\n}\n\n/** @internal */\nexport function canEditNode<K, V>(node: Node<K, V>, edit: number): boolean {\n return isEmptyNode(node) ? false : edit === node.edit\n}\n\n/** @internal */\nexport class LeafNode<out K, out V> {\n readonly _tag = \"LeafNode\"\n\n constructor(\n readonly edit: number,\n readonly hash: number,\n readonly key: K,\n public value: O.Option<V>\n ) {}\n\n modify(\n edit: number,\n shift: number,\n f: HashMap.UpdateFn<V>,\n hash: number,\n key: K,\n size: SizeRef\n ): Node<K, V> {\n if (equals(key, this.key)) {\n const v = f(this.value)\n if (v === this.value) return this\n else if (O.isNone(v)) {\n ;--size.value\n return new EmptyNode()\n }\n if (canEditNode(this, edit)) {\n this.value = v\n return this\n }\n return new LeafNode(edit, hash, key, v)\n }\n const v = f(O.none())\n if (O.isNone(v)) return this\n ;++size.value\n return mergeLeaves(\n edit,\n shift,\n this.hash,\n this,\n hash,\n new LeafNode(edit, hash, key, v)\n )\n }\n}\n\n/** @internal */\nexport class CollisionNode<out K, out V> {\n readonly _tag = \"CollisionNode\"\n\n constructor(\n readonly edit: number,\n readonly hash: number,\n readonly children: Array<Node<K, V>>\n ) {}\n\n modify(\n edit: number,\n shift: number,\n f: HashMap.UpdateFn<V>,\n hash: number,\n key: K,\n size: SizeRef\n ): Node<K, V> {\n if (hash === this.hash) {\n const canEdit = canEditNode(this, edit)\n const list = this.updateCollisionList(\n canEdit,\n edit,\n this.hash,\n this.children,\n f,\n key,\n size\n )\n if (list === this.children) return this\n\n return list.length > 1 ? new CollisionNode(edit, this.hash, list) : list[0]! // collapse single element collision list\n }\n const v = f(O.none())\n if (O.isNone(v)) return this\n ;++size.value\n return mergeLeaves(\n edit,\n shift,\n this.hash,\n this,\n hash,\n new LeafNode(edit, hash, key, v)\n )\n }\n\n updateCollisionList(\n mutate: boolean,\n edit: number,\n hash: number,\n list: Array<Node<K, V>>,\n f: HashMap.UpdateFn<V>,\n key: K,\n size: SizeRef\n ) {\n const len = list.length\n for (let i = 0; i < len; ++i) {\n const child = list[i]!\n if (\"key\" in child && equals(key, child.key)) {\n const value = child.value\n const newValue = f(value)\n if (newValue === value) return list\n if (O.isNone(newValue)) {\n ;--size.value\n return arraySpliceOut(mutate, i, list)\n }\n return arrayUpdate(mutate, i, new LeafNode(edit, hash, key, newValue), list)\n }\n }\n\n const newValue = f(O.none())\n if (O.isNone(newValue)) return list\n ;++size.value\n return arrayUpdate(mutate, len, new LeafNode(edit, hash, key, newValue), list)\n }\n}\n\n/** @internal */\nexport class IndexedNode<out K, out V> {\n readonly _tag = \"IndexedNode\"\n\n constructor(\n readonly edit: number,\n public mask: number,\n public children: Array<Node<K, V>>\n ) {}\n\n modify(\n edit: number,\n shift: number,\n f: HashMap.UpdateFn<V>,\n hash: number,\n key: K,\n size: SizeRef\n ): Node<K, V> {\n const mask = this.mask\n const children = this.children\n const frag = hashFragment(shift, hash)\n const bit = toBitmap(frag)\n const indx = fromBitmap(mask, bit)\n const exists = mask & bit\n const canEdit = canEditNode(this, edit)\n\n if (!exists) {\n const _newChild = new EmptyNode<K, V>().modify(edit, shift + SIZE, f, hash, key, size)\n if (!_newChild) return this\n return children.length >= MAX_INDEX_NODE ?\n expand(edit, frag, _newChild, mask, children) :\n new IndexedNode(edit, mask | bit, arraySpliceIn(canEdit, indx, _newChild, children))\n }\n\n const current = children[indx]!\n const child = current.modify(edit, shift + SIZE, f, hash, key, size)\n\n if (current === child) return this\n let bitmap = mask\n let newChildren\n if (isEmptyNode(child)) {\n // remove\n bitmap &= ~bit\n if (!bitmap) return new EmptyNode()\n if (children.length <= 2 && isLeafNode(children[indx ^ 1]!)) {\n return children[indx ^ 1]! // collapse\n }\n\n newChildren = arraySpliceOut(canEdit, indx, children)\n } else {\n // modify\n newChildren = arrayUpdate(canEdit, indx, child, children)\n }\n\n if (canEdit) {\n this.mask = bitmap\n this.children = newChildren\n return this\n }\n\n return new IndexedNode(edit, bitmap, newChildren)\n }\n}\n\n/** @internal */\nexport class ArrayNode<out K, out V> {\n readonly _tag = \"ArrayNode\"\n\n constructor(\n readonly edit: number,\n public size: number,\n public children: Array<Node<K, V>>\n ) {}\n\n modify(\n edit: number,\n shift: number,\n f: HashMap.UpdateFn<V>,\n hash: number,\n key: K,\n size: SizeRef\n ): Node<K, V> {\n let count = this.size\n const children = this.children\n const frag = hashFragment(shift, hash)\n const child = children[frag]\n const newChild = (child || new EmptyNode<K, V>()).modify(\n edit,\n shift + SIZE,\n f,\n hash,\n key,\n size\n )\n\n if (child === newChild) return this\n\n const canEdit = canEditNode(this, edit)\n let newChildren\n if (isEmptyNode(child) && !isEmptyNode(newChild)) {\n // add\n ;++count\n newChildren = arrayUpdate(canEdit, frag, newChild, children)\n } else if (!isEmptyNode(child) && isEmptyNode(newChild)) {\n // remove\n ;--count\n if (count <= MIN_ARRAY_NODE) {\n return pack(edit, count, frag, children)\n }\n newChildren = arrayUpdate(canEdit, frag, new EmptyNode<K, V>(), children)\n } else {\n // modify\n newChildren = arrayUpdate(canEdit, frag, newChild, children)\n }\n\n if (canEdit) {\n this.size = count\n this.children = newChildren\n return this\n }\n return new ArrayNode(edit, count, newChildren)\n }\n}\n\nfunction pack<K, V>(\n edit: number,\n count: number,\n removed: number,\n elements: Array<Node<K, V>>\n) {\n const children = new Array<Node<K, V>>(count - 1)\n let g = 0\n let bitmap = 0\n for (let i = 0, len = elements.length; i < len; ++i) {\n if (i !== removed) {\n const elem = elements[i]\n if (elem && !isEmptyNode(elem)) {\n children[g++] = elem\n bitmap |= 1 << i\n }\n }\n }\n return new IndexedNode(edit, bitmap, children)\n}\n\nfunction expand<K, V>(\n edit: number,\n frag: number,\n child: Node<K, V>,\n bitmap: number,\n subNodes: Array<Node<K, V>>\n) {\n const arr = []\n let bit = bitmap\n let count = 0\n for (let i = 0; bit; ++i) {\n if (bit & 1) arr[i] = subNodes[count++]!\n bit >>>= 1\n }\n arr[frag] = child\n return new ArrayNode(edit, count + 1, arr)\n}\n\nfunction mergeLeavesInner<K, V>(\n edit: number,\n shift: number,\n h1: number,\n n1: Node<K, V>,\n h2: number,\n n2: Node<K, V>\n): Node<K, V> | ((child: Node<K, V>) => Node<K, V>) {\n if (h1 === h2) return new CollisionNode(edit, h1, [n2, n1])\n const subH1 = hashFragment(shift, h1)\n const subH2 = hashFragment(shift, h2)\n\n if (subH1 === subH2) {\n return (child) => new IndexedNode(edit, toBitmap(subH1) | toBitmap(subH2), [child])\n } else {\n const children = subH1 < subH2 ? [n1, n2] : [n2, n1]\n return new IndexedNode(edit, toBitmap(subH1) | toBitmap(subH2), children)\n }\n}\n\nfunction mergeLeaves<K, V>(\n edit: number,\n shift: number,\n h1: number,\n n1: Node<K, V>,\n h2: number,\n n2: Node<K, V>\n): Node<K, V> {\n let stack: Stack.Stack<(node: Node<K, V>) => Node<K, V>> | undefined = undefined\n let currentShift = shift\n\n while (true) {\n const res = mergeLeavesInner(edit, currentShift, h1, n1, h2, n2)\n\n if (typeof res === \"function\") {\n stack = Stack.make(res, stack)\n currentShift = currentShift + SIZE\n } else {\n let final = res\n while (stack != null) {\n final = stack.value(final)\n stack = stack.previous\n }\n return final\n }\n }\n}\n","import * as Equal from \"../Equal.js\"\nimport * as Dual from \"../Function.js\"\nimport { identity, pipe } from \"../Function.js\"\nimport * as Hash from \"../Hash.js\"\nimport type * as HM from \"../HashMap.js\"\nimport { format, NodeInspectSymbol, toJSON } from \"../Inspectable.js\"\nimport * as Option from \"../Option.js\"\nimport { pipeArguments } from \"../Pipeable.js\"\nimport { hasProperty } from \"../Predicate.js\"\nimport type { NoInfer } from \"../Types.js\"\nimport { fromBitmap, hashFragment, toBitmap } from \"./hashMap/bitwise.js\"\nimport { SIZE } from \"./hashMap/config.js\"\nimport * as Node from \"./hashMap/node.js\"\n\nconst HashMapSymbolKey = \"effect/HashMap\"\n\n/** @internal */\nexport const HashMapTypeId: HM.TypeId = Symbol.for(HashMapSymbolKey) as HM.TypeId\n\ntype TraversalFn<K, V, A> = (k: K, v: V) => A\n\ntype Cont<K, V, A> =\n | [\n len: number,\n children: Array<Node.Node<K, V>>,\n i: number,\n f: TraversalFn<K, V, A>,\n cont: Cont<K, V, A>\n ]\n | undefined\n\ninterface VisitResult<K, V, A> {\n value: A\n cont: Cont<K, V, A>\n}\n\n/** @internal */\nexport interface HashMapImpl<out K, out V> extends HM.HashMap<K, V> {\n _editable: boolean // mutable by design\n _edit: number // mutable by design\n _root: Node.Node<K, V> // mutable by design\n _size: number // mutable by design\n}\n\nconst HashMapProto: HM.HashMap<unknown, unknown> = {\n [HashMapTypeId]: HashMapTypeId,\n [Symbol.iterator]<K, V>(this: HashMapImpl<K, V>): Iterator<[K, V]> {\n return new HashMapIterator(this, (k, v) => [k, v])\n },\n [Hash.symbol](this: HM.HashMap<unknown, unknown>): number {\n let hash = Hash.hash(HashMapSymbolKey)\n for (const item of this) {\n hash ^= pipe(Hash.hash(item[0]), Hash.combine(Hash.hash(item[1])))\n }\n return Hash.cached(this, hash)\n },\n [Equal.symbol]<K, V>(this: HashMapImpl<K, V>, that: unknown): boolean {\n if (isHashMap(that)) {\n if ((that as HashMapImpl<K, V>)._size !== this._size) {\n return false\n }\n for (const item of this) {\n const elem = pipe(\n that as HM.HashMap<K, V>,\n getHash(item[0], Hash.hash(item[0]))\n )\n if (Option.isNone(elem)) {\n return false\n } else {\n if (!Equal.equals(item[1], elem.value)) {\n return false\n }\n }\n }\n return true\n }\n return false\n },\n toString<K, V>(this: HashMapImpl<K, V>) {\n return format(this.toJSON())\n },\n toJSON() {\n return {\n _id: \"HashMap\",\n values: Array.from(this).map(toJSON)\n }\n },\n [NodeInspectSymbol]() {\n return this.toJSON()\n },\n pipe() {\n return pipeArguments(this, arguments)\n }\n}\n\nconst makeImpl = <K, V>(\n editable: boolean,\n edit: number,\n root: Node.Node<K, V>,\n size: number\n): HashMapImpl<K, V> => {\n const map = Object.create(HashMapProto)\n map._editable = editable\n map._edit = edit\n map._root = root\n map._size = size\n return map\n}\n\nclass HashMapIterator<in out K, in out V, out T> implements IterableIterator<T> {\n v: Option.Option<VisitResult<K, V, T>>\n\n constructor(readonly map: HashMapImpl<K, V>, readonly f: TraversalFn<K, V, T>) {\n this.v = visitLazy(this.map._root, this.f, undefined)\n }\n\n next(): IteratorResult<T> {\n if (Option.isNone(this.v)) {\n return { done: true, value: undefined }\n }\n const v0 = this.v.value\n this.v = applyCont(v0.cont)\n return { done: false, value: v0.value }\n }\n\n [Symbol.iterator](): IterableIterator<T> {\n return new HashMapIterator(this.map, this.f)\n }\n}\n\nconst applyCont = <K, V, A>(cont: Cont<K, V, A>): Option.Option<VisitResult<K, V, A>> =>\n cont\n ? visitLazyChildren(cont[0], cont[1], cont[2], cont[3], cont[4])\n : Option.none()\n\nconst visitLazy = <K, V, A>(\n node: Node.Node<K, V>,\n f: TraversalFn<K, V, A>,\n cont: Cont<K, V, A> = undefined\n): Option.Option<VisitResult<K, V, A>> => {\n switch (node._tag) {\n case \"LeafNode\": {\n if (Option.isSome(node.value)) {\n return Option.some({\n value: f(node.key, node.value.value),\n cont\n })\n }\n return applyCont(cont)\n }\n case \"CollisionNode\":\n case \"ArrayNode\":\n case \"IndexedNode\": {\n const children = node.children\n return visitLazyChildren(children.length, children, 0, f, cont)\n }\n default: {\n return applyCont(cont)\n }\n }\n}\n\nconst visitLazyChildren = <K, V, A>(\n len: number,\n children: Array<Node.Node<K, V>>,\n i: number,\n f: TraversalFn<K, V, A>,\n cont: Cont<K, V, A>\n): Option.Option<VisitResult<K, V, A>> => {\n while (i < len) {\n const child = children[i++]\n if (child && !Node.isEmptyNode(child)) {\n return visitLazy(child, f, [len, children, i, f, cont])\n }\n }\n return applyCont(cont)\n}\n\nconst _empty = makeImpl<never, never>(false, 0, new Node.EmptyNode(), 0)\n\n/** @internal */\nexport const empty = <K = never, V = never>(): HM.HashMap<K, V> => _empty\n\n/** @internal */\nexport const make = <Entries extends ReadonlyArray<readonly [any, any]>>(\n ...entries: Entries\n): HM.HashMap<\n Entries[number] extends readonly [infer K, any] ? K : never,\n Entries[number] extends readonly [any, infer V] ? V : never\n> => fromIterable(entries)\n\n/** @internal */\nexport const fromIterable = <K, V>(entries: Iterable<readonly [K, V]>): HM.HashMap<K, V> => {\n const map = beginMutation(empty<K, V>())\n for (const entry of entries) {\n set(map, entry[0], entry[1])\n }\n return endMutation(map)\n}\n\n/** @internal */\nexport const isHashMap: {\n <K, V>(u: Iterable<readonly [K, V]>): u is HM.HashMap<K, V>\n (u: unknown): u is HM.HashMap<unknown, unknown>\n} = (u: unknown): u is HM.HashMap<unknown, unknown> => hasProperty(u, HashMapTypeId)\n\n/** @internal */\nexport const isEmpty = <K, V>(self: HM.HashMap<K, V>): boolean =>\n self && Node.isEmptyNode((self as HashMapImpl<K, V>)._root)\n\n/** @internal */\nexport const get = Dual.dual<\n <K1>(key: K1) => <K, V>(self: HM.HashMap<K, V>) => Option.Option<V>,\n <K, V, K1>(self: HM.HashMap<K, V>, key: K1) => Option.Option<V>\n>(2, (self, key) => getHash(self, key, Hash.hash(key)))\n\n/** @internal */\nexport const getHash = Dual.dual<\n <K1>(key: K1, hash: number) => <K, V>(self: HM.HashMap<K, V>) => Option.Option<V>,\n <K, V, K1>(self: HM.HashMap<K, V>, key: K1, hash: number) => Option.Option<V>\n>(3, <K, V, K1>(self: HM.HashMap<K, V>, key: K1, hash: number) => {\n let node = (self as HashMapImpl<K, V>)._root\n let shift = 0\n\n while (true) {\n switch (node._tag) {\n case \"LeafNode\": {\n return Equal.equals(key, node.key) ? node.value : Option.none()\n }\n case \"CollisionNode\": {\n if (hash === node.hash) {\n const children = node.children\n for (let i = 0, len = children.length; i < len; ++i) {\n const child = children[i]!\n if (\"key\" in child && Equal.equals(key, child.key)) {\n return child.value\n }\n }\n }\n return Option.none()\n }\n case \"IndexedNode\": {\n const frag = hashFragment(shift, hash)\n const bit = toBitmap(frag)\n if (node.mask & bit) {\n node = node.children[fromBitmap(node.mask, bit)]!\n shift += SIZE\n break\n }\n return Option.none()\n }\n case \"ArrayNode\": {\n node = node.children[hashFragment(shift, hash)]!\n if (node) {\n shift += SIZE\n break\n }\n return Option.none()\n }\n default:\n return Option.none()\n }\n }\n})\n\n/** @internal */\nexport const unsafeGet = Dual.dual<\n <K1>(key: K1) => <K, V>(self: HM.HashMap<K, V>) => V,\n <K, V, K1>(self: HM.HashMap<K, V>, key: K1) => V\n>(2, (self, key) => {\n const element = getHash(self, key, Hash.hash(key))\n if (Option.isNone(element)) {\n throw new Error(\"Expected map to contain key\")\n }\n return element.value\n})\n\n/** @internal */\nexport const has = Dual.dual<\n <K1>(key: K1) => <K, V>(self: HM.HashMap<K, V>) => boolean,\n <K, V, K1>(self: HM.HashMap<K, V>, key: K1) => boolean\n>(2, (self, key) => Option.isSome(getHash(self, key, Hash.hash(key))))\n\n/** @internal */\nexport const hasHash = Dual.dual<\n <K1>(key: K1, hash: number) => <K, V>(self: HM.HashMap<K, V>) => boolean,\n <K, V, K1>(self: HM.HashMap<K, V>, key: K1, hash: number) => boolean\n>(3, (self, key, hash) => Option.isSome(getHash(self, key, hash)))\n\n/** @internal */\nexport const set = Dual.dual<\n <K, V>(key: K, value: V) => (self: HM.HashMap<K, V>) => HM.HashMap<K, V>,\n <K, V>(self: HM.HashMap<K, V>, key: K, value: V) => HM.HashMap<K, V>\n>(3, (self, key, value) => modifyAt(self, key, () => Option.some(value)))\n\n/** @internal */\nexport const setTree = Dual.dual<\n <K, V>(newRoot: Node.Node<K, V>, newSize: number) => (self: HM.HashMap<K, V>) => HM.HashMap<K, V>,\n <K, V>(self: HM.HashMap<K, V>, newRoot: Node.Node<K, V>, newSize: number) => HM.HashMap<K, V>\n>(3, <K, V>(self: HM.HashMap<K, V>, newRoot: Node.Node<K, V>, newSize: number) => {\n if ((self as HashMapImpl<K, V>)._editable) {\n ;(self as HashMapImpl<K, V>)._root = newRoot\n ;(self as HashMapImpl<K, V>)._size = newSize\n return self\n }\n return newRoot === (self as HashMapImpl<K, V>)._root\n ? self\n : makeImpl(\n (self as HashMapImpl<K, V>)._editable,\n (self as HashMapImpl<K, V>)._edit,\n newRoot,\n newSize\n )\n})\n\n/** @internal */\nexport const keys = <K, V>(self: HM.HashMap<K, V>): IterableIterator<K> =>\n new HashMapIterator(self as HashMapImpl<K, V>, (key) => key)\n\n/** @internal */\nexport const values = <K, V>(self: HM.HashMap<K, V>): IterableIterator<V> =>\n new HashMapIterator(self as HashMapImpl<K, V>, (_, value) => value)\n\n/** @internal */\nexport const entries = <K, V>(self: HM.HashMap<K, V>): IterableIterator<[K, V]> =>\n new HashMapIterator(self as HashMapImpl<K, V>, (key, value) => [key, value])\n\n/** @internal */\nexport const size = <K, V>(self: HM.HashMap<K, V>): number => (self as HashMapImpl<K, V>)._size\n\n/** @internal */\nexport const beginMutation = <K, V>(self: HM.HashMap<K, V>): HM.HashMap<K, V> =>\n makeImpl(\n true,\n (self as HashMapImpl<K, V>)._edit + 1,\n (self as HashMapImpl<K, V>)._root,\n (self as HashMapImpl<K, V>)._size\n )\n\n/** @internal */\nexport const endMutation = <K, V>(self: HM.HashMap<K, V>): HM.HashMap<K, V> => {\n ;(self as HashMapImpl<K, V>)._editable = false\n return self\n}\n\n/** @internal */\nexport const mutate = Dual.dual<\n <K, V>(f: (self: HM.HashMap<K, V>) => void) => (self: HM.HashMap<K, V>) => HM.HashMap<K, V>,\n <K, V>(self: HM.HashMap<K, V>, f: (self: HM.HashMap<K, V>) => void) => HM.HashMap<K, V>\n>(2, (self, f) => {\n const transient = beginMutation(self)\n f(transient)\n return endMutation(transient)\n})\n\n/** @internal */\nexport const modifyAt = Dual.dual<\n <K, V>(key: K, f: HM.HashMap.UpdateFn<V>) => (self: HM.HashMap<K, V>) => HM.HashMap<K, V>,\n <K, V>(self: HM.HashMap<K, V>, key: K, f: HM.HashMap.UpdateFn<V>) => HM.HashMap<K, V>\n>(3, (self, key, f) => modifyHash(self, key, Hash.hash(key), f))\n\n/** @internal */\nexport const modifyHash = Dual.dual<\n <K, V>(key: K, hash: number, f: HM.HashMap.UpdateFn<V>) => (self: HM.HashMap<K, V>) => HM.HashMap<K, V>,\n <K, V>(self: HM.HashMap<K, V>, key: K, hash: number, f: HM.HashMap.UpdateFn<V>) => HM.HashMap<K, V>\n>(4, <K, V>(self: HM.HashMap<K, V>, key: K, hash: number, f: HM.HashMap.UpdateFn<V>) => {\n const size = { value: (self as HashMapImpl<K, V>)._size }\n const newRoot = (self as HashMapImpl<K, V>)._root.modify(\n (self as HashMapImpl<K, V>)._editable ?\n (self as HashMapImpl<K, V>)._edit :\n NaN,\n 0,\n f,\n hash,\n key,\n size\n )\n return pipe(self, setTree(newRoot, size.value))\n})\n\n/** @internal */\nexport const modify = Dual.dual<\n <K, V>(key: K, f: (v: V) => V) => (self: HM.HashMap<K, V>) => HM.HashMap<K, V>,\n <K, V>(self: HM.HashMap<K, V>, key: K, f: (v: V) => V) => HM.HashMap<K, V>\n>(3, (self, key, f) => modifyAt(self, key, Option.map(f)))\n\n/** @internal */\nexport const union = Dual.dual<\n <K1, V1>(\n that: HM.HashMap<K1, V1>\n ) => <K0, V0>(self: HM.HashMap<K0, V0>) => HM.HashMap<K0 | K1, V0 | V1>,\n <K0, V0, K1, V1>(\n self: HM.HashMap<K0, V0>,\n that: HM.HashMap<K1, V1>\n ) => HM.HashMap<K0 | K1, V0 | V1>\n>(2, <K0, V0, K1, V1>(self: HM.HashMap<K0, V0>, that: HM.HashMap<K1, V1>) => {\n const result: HM.HashMap<K0 | K1, V0 | V1> = beginMutation(self)\n forEach(that, (v, k) => set(result, k, v))\n return endMutation(result)\n})\n\n/** @internal */\nexport const remove = Dual.dual<\n <K>(key: K) => <V>(self: HM.HashMap<K, V>) => HM.HashMap<K, V>,\n <K, V>(self: HM.HashMap<K, V>, key: K) => HM.HashMap<K, V>\n>(2, (self, key) => modifyAt(self, key, Option.none))\n\n/** @internal */\nexport const removeMany = Dual.dual<\n <K>(keys: Iterable<K>) => <V>(self: HM.HashMap<K, V>) => HM.HashMap<K, V>,\n <K, V>(self: HM.HashMap<K, V>, keys: Iterable<K>) => HM.HashMap<K, V>\n>(2, (self, keys) =>\n mutate(self, (map) => {\n for (const key of keys) {\n remove(key)(map)\n }\n }))\n\n/**\n * Maps over the entries of the `HashMap` using the specified function.\n *\n * @since 2.0.0\n * @category mapping\n */\nexport const map = Dual.dual<\n <A, V, K>(f: (value: V, key: K) => A) => (self: HM.HashMap<K, V>) => HM.HashMap<K, A>,\n <K, V, A>(self: HM.HashMap<K, V>, f: (value: V, key: K) => A) => HM.HashMap<K, A>\n>(2, (self, f) =>\n reduce(\n self,\n empty(),\n (map, value, key) => set(map, key, f(value, key))\n ))\n\n/** @internal */\nexport const flatMap = Dual.dual<\n <A, K, B>(\n f: (value: A, key: K) => HM.HashMap<K, B>\n ) => (self: HM.HashMap<K, A>) => HM.HashMap<K, B>,\n <K, A, B>(self: HM.HashMap<K, A>, f: (value: A, key: K) => HM.HashMap<K, B>) => HM.HashMap<K, B>\n>(\n 2,\n (self, f) =>\n reduce(self, empty(), (zero, value, key) =>\n mutate(\n zero,\n (map) => forEach(f(value, key), (value, key) => set(map, key, value))\n ))\n)\n\n/** @internal */\nexport const forEach = Dual.dual<\n <V, K>(f: (value: V, key: K) => void) => (self: HM.HashMap<K, V>) => void,\n <V, K>(self: HM.HashMap<K, V>, f: (value: V, key: K) => void) => void\n>(2, (self, f) => reduce(self, void 0 as void, (_, value, key) => f(value, key)))\n\n/** @internal */\nexport const reduce = Dual.dual<\n <Z, V, K>(zero: Z, f: (accumulator: Z, value: V, key: K) => Z) => (self: HM.HashMap<K, V>) => Z,\n <Z, V, K>(self: HM.HashMap<K, V>, zero: Z, f: (accumulator: Z, value: V, key: K) => Z) => Z\n>(3, <Z, V, K>(self: HM.HashMap<K, V>, zero: Z, f: (accumulator: Z, value: V, key: K) => Z) => {\n const root = (self as HashMapImpl<K, V>)._root\n if (root._tag === \"LeafNode\") {\n return Option.isSome(root.value) ? f(zero, root.value.value, root.key) : zero\n }\n if (root._tag === \"EmptyNode\") {\n return zero\n }\n const toVisit = [root.children]\n let children\n while ((children = toVisit.pop())) {\n for (let i = 0, len = children.length; i < len;) {\n const child = children[i++]\n if (child && !Node.isEmptyNode(child)) {\n if (child._tag === \"LeafNode\") {\n if (Option.isSome(child.value)) {\n zero = f(zero, child.value.value, child.key)\n }\n } else {\n toVisit.push(child.children)\n }\n }\n }\n }\n return zero\n})\n\n/** @internal */\nexport const filter: {\n <K, A, B extends A>(f: (a: NoInfer<A>, k: K) => a is B): (self: HM.HashMap<K, A>) => HM.HashMap<K, B>\n <K, A>(f: (a: NoInfer<A>, k: K) => boolean): (self: HM.HashMap<K, A>) => HM.HashMap<K, A>\n <K, A, B extends A>(self: HM.HashMap<K, A>, f: (a: A, k: K) => a is B): HM.HashMap<K, B>\n <K, A>(self: HM.HashMap<K, A>, f: (a: A, k: K) => boolean): HM.HashMap<K, A>\n} = Dual.dual(\n 2,\n <K, A>(self: HM.HashMap<K, A>, f: (a: A, k: K) => boolean): HM.HashMap<K, A> =>\n mutate(empty(), (map) => {\n for (const [k, a] of self) {\n if (f(a, k)) {\n set(map, k, a)\n }\n }\n })\n)\n\n/** @internal */\nexport const compact = <K, A>(self: HM.HashMap<K, Option.Option<A>>) => filterMap(self, identity)\n\n/** @internal */\nexport const filterMap = Dual.dual<\n <A, K, B>(\n f: (value: A, key: K) => Option.Option<B>\n ) => (self: HM.HashMap<K, A>) => HM.HashMap<K, B>,\n <K, A, B>(self: HM.HashMap<K, A>, f: (value: A, key: K) => Option.Option<B>) => HM.HashMap<K, B>\n>(2, (self, f) =>\n mutate(empty(), (map) => {\n for (const [k, a] of self) {\n const option = f(a, k)\n if (Option.isSome(option)) {\n set(map, k, option.value)\n }\n }\n }))\n\n/** @internal */\nexport const findFirst: {\n <K, A, B extends A>(predicate: (a: NoInfer<A>, k: K) => a is B): (self: HM.HashMap<K, A>) => Option.Option<[K, B]>\n <K, A>(predicate: (a: NoInfer<A>, k: K) => boolean): (self: HM.HashMap<K, A>) => Option.Option<[K, A]>\n <K, A, B extends A>(self: HM.HashMap<K, A>, predicate: (a: A, k: K) => a is B): Option.Option<[K, B]>\n <K, A>(self: HM.HashMap<K, A>, predicate: (a: A, k: K) => boolean): Option.Option<[K, A]>\n} = Dual.dual(\n 2,\n <K, A>(self: HM.HashMap<K, A>, predicate: (a: A, k: K) => boolean): Option.Option<[K, A]> => {\n for (const ka of self) {\n if (predicate(ka[1], ka[0])) {\n return Option.some(ka)\n }\n }\n return Option.none()\n }\n)\n","import * as Equal from \"../Equal.js\"\nimport { dual } from \"../Function.js\"\nimport * as Hash from \"../Hash.js\"\nimport type { HashMap } from \"../HashMap.js\"\nimport type * as HS from \"../HashSet.js\"\nimport { format, NodeInspectSymbol, toJSON } from \"../Inspectable.js\"\nimport { pipeArguments } from \"../Pipeable.js\"\nimport type { Predicate, Refinement } from \"../Predicate.js\"\nimport { hasProperty } from \"../Predicate.js\"\nimport type { NoInfer } from \"../Types.js\"\nimport * as HM from \"./hashMap.js\"\n\nconst HashSetSymbolKey = \"effect/HashSet\"\n\n/** @internal */\nexport const HashSetTypeId: HS.TypeId = Symbol.for(HashSetSymbolKey) as HS.TypeId\n\n/** @internal */\nexport interface HashSetImpl<out A> extends HS.HashSet<A> {\n readonly _keyMap: HashMap<A, unknown>\n}\n\nconst HashSetProto: Omit<HashSetImpl<unknown>, \"_keyMap\"> = {\n [HashSetTypeId]: HashSetTypeId,\n [Symbol.iterator]<A>(this: HashSetImpl<A>): Iterator<A> {\n return HM.keys(this._keyMap)\n },\n [Hash.symbol]<A>(this: HashSetImpl<A>): number {\n return Hash.cached(\n this,\n Hash.combine(Hash.hash(this._keyMap))(Hash.hash(HashSetSymbolKey))\n )\n },\n [Equal.symbol]<A>(this: HashSetImpl<A>, that: unknown): boolean {\n if (isHashSet(that)) {\n return (\n HM.size(this._keyMap) === HM.size((that as HashSetImpl<A>)._keyMap) &&\n Equal.equals(this._keyMap, (that as HashSetImpl<A>)._keyMap)\n )\n }\n return false\n },\n toString() {\n return format(this.toJSON())\n },\n toJSON() {\n return {\n _id: \"HashSet\",\n values: Array.from(this).map(toJSON)\n }\n },\n [NodeInspectSymbol]() {\n return this.toJSON()\n },\n pipe() {\n return pipeArguments(this, arguments)\n }\n}\n\n/** @internal */\nexport const makeImpl = <A>(keyMap: HashMap<A, unknown>): HashSetImpl<A> => {\n const set = Object.create(HashSetProto)\n set._keyMap = keyMap\n return set\n}\n\n/** @internal */\nexport const isHashSet: {\n <A>(u: Iterable<A>): u is HS.HashSet<A>\n (u: unknown): u is HS.HashSet<unknown>\n} = (u: unknown): u is HS.HashSet<unknown> => hasProperty(u, HashSetTypeId)\n\nconst _empty = makeImpl<never>(HM.empty())\n\n/** @internal */\nexport const empty = <A = never>(): HS.HashSet<A> => _empty\n\n/** @internal */\nexport const fromIterable = <A>(elements: Iterable<A>): HS.HashSet<A> => {\n const set = beginMutation(empty<A>())\n for (const value of elements) {\n add(set, value)\n }\n return endMutation(set)\n}\n\n/** @internal */\nexport const make = <As extends ReadonlyArray<any>>(...elements: As): HS.HashSet<As[number]> => {\n const set = beginMutation(empty<As[number]>())\n for (const value of elements) {\n add(set, value)\n }\n return endMutation(set)\n}\n\n/** @internal */\nexport const has = dual<\n <A>(value: A) => (self: HS.HashSet<A>) => boolean,\n <A>(self: HS.HashSet<A>, value: A) => boolean\n>(2, <A>(self: HS.HashSet<A>, value: A) => HM.has((self as HashSetImpl<A>)._keyMap, value))\n\n/** @internal */\nexport const some = dual<\n <A>(f: Predicate<A>) => (self: HS.HashSet<A>) => boolean,\n <A>(self: HS.HashSet<A>, f: Predicate<A>) => boolean\n>(2, (self, f) => {\n let found = false\n for (const value of self) {\n found = f(value)\n if (found) {\n break\n }\n }\n return found\n})\n\n/** @internal */\nexport const every: {\n <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: HS.HashSet<A>) => self is HS.HashSet<B>\n <A>(predicate: Predicate<A>): (self: HS.HashSet<A>) => boolean\n <A, B extends A>(self: HS.HashSet<A>, refinement: Refinement<A, B>): self is HS.HashSet<B>\n <A>(self: HS.HashSet<A>, predicate: Predicate<A>): boolean\n} = dual(\n 2,\n <A, B extends A>(self: HS.HashSet<A>, refinement: Refinement<A, B>): self is HS.HashSet<B> =>\n !some(self, (a) => !refinement(a))\n)\n\n/** @internal */\nexport const isSubset = dual<\n <A>(that: HS.HashSet<A>) => (self: HS.HashSet<A>) => boolean,\n <A>(self: HS.HashSet<A>, that: HS.HashSet<A>) => boolean\n>(2, (self, that) => every(self, (value) => has(that, value)))\n\n/** @internal */\nexport const values = <A>(self: HS.HashSet<A>): IterableIterator<A> => HM.keys((self as HashSetImpl<A>)._keyMap)\n\n/** @internal */\nexport const size = <A>(self: HS.HashSet<A>): number => HM.size((self as HashSetImpl<A>)._keyMap)\n\n/** @internal */\nexport const beginMutation = <A>(self: HS.HashSet<A>): HS.HashSet<A> =>\n makeImpl(HM.beginMutation((self as HashSetImpl<A>)._keyMap))\n\n/** @internal */\nexport const endMutation = <A>(self: HS.HashSet<A>): HS.HashSet<A> => {\n ;((self as HashSetImpl<A>)._keyMap as HM.HashMapImpl<A, unknown>)._editable = false\n return self\n}\n\n/** @internal */\nexport const mutate = dual<\n <A>(f: (set: HS.HashSet<A>) => void) => (self: HS.HashSet<A>) => HS.HashSet<A>,\n <A>(self: HS.HashSet<A>, f: (set: HS.HashSet<A>) => void) => HS.HashSet<A>\n>(2, (self, f) => {\n const transient = beginMutation(self)\n f(transient)\n return endMutation(transient)\n})\n\n/** @internal */\nexport const add = dual<\n <A>(value: A) => (self: HS.HashSet<A>) => HS.HashSet<A>,\n <A>(self: HS.HashSet<A>, value: A) => HS.HashSet<A>\n>(\n 2,\n <A>(self: HS.HashSet<A>, value: A) =>\n ((self as HashSetImpl<A>)._keyMap as HM.HashMapImpl<A, unknown>)._editable\n ? (HM.set(value as A, true as unknown)((self as HashSetImpl<A>)._keyMap), self)\n : makeImpl(HM.set(value as A, true as unknown)((self as HashSetImpl<A>)._keyMap))\n)\n\n/** @internal */\nexport const remove = dual<\n <A>(value: A) => (self: HS.HashSet<A>) => HS.HashSet<A>,\n <A>(self: HS.HashSet<A>, value: A) => HS.HashSet<A>\n>(\n 2,\n <A>(self: HS.HashSet<A>, value: A) =>\n (((self as HashSetImpl<A>)._keyMap) as HM.HashMapImpl<A, unknown>)._editable\n ? (HM.remove(value)((self as HashSetImpl<A>)._keyMap), self)\n : makeImpl(HM.remove(value)((self as HashSetImpl<A>)._keyMap))\n)\n\n/** @internal */\nexport const difference = dual<\n <A>(that: Iterable<A>) => (self: HS.HashSet<A>) => HS.HashSet<A>,\n <A>(self: HS.HashSet<A>, that: Iterable<A>) => HS.HashSet<A>\n>(2, (self, that) =>\n mutate(self, (set) => {\n for (const value of that) {\n remove(set, value)\n }\n }))\n\n/** @internal */\nexport const intersection = dual<\n <A>(that: Iterable<A>) => (self: HS.HashSet<A>) => HS.HashSet<A>,\n <A>(self: HS.HashSet<A>, that: Iterable<A>) => HS.HashSet<A>\n>(2, (self, that) =>\n mutate(empty(), (set) => {\n for (const value of that) {\n if (has(value)(self)) {\n add(value)(set)\n }\n }\n }))\n\n/** @internal */\nexport const union = dual<\n <A>(that: Iterable<A>) => (self: HS.HashSet<A>) => HS.HashSet<A>,\n <A>(self: HS.HashSet<A>, that: Iterable<A>) => HS.HashSet<A>\n>(2, (self, that) =>\n mutate(empty(), (set) => {\n forEach(self, (value) => add(set, value))\n for (const value of that) {\n add(set, value)\n }\n }))\n\n/** @internal */\nexport const toggle = dual<\n <A>(value: A) => (self: HS.HashSet<A>) => HS.HashSet<A>,\n <A>(self: HS.HashSet<A>, value: A) => HS.HashSet<A>\n>(2, (self, value) => has(self, value) ? remove(self, value) : add(self, value))\n\n/** @internal */\nexport const map = dual<\n <A, B>(f: (a: A) => B) => (self: HS.HashSet<A>) => HS.HashSet<B>,\n <A, B>(self: HS.HashSet<A>, f: (a: A) => B) => HS.HashSet<B>\n>(2, (self, f) =>\n mutate(empty(), (set) => {\n forEach(self, (a) => {\n const b = f(a)\n if (!has(set, b)) {\n add(set, b)\n }\n })\n }))\n\n/** @internal */\nexport const flatMap = dual<\n <A, B>(f: (a: A) => Iterable<B>) => (self: HS.HashSet<A>) => HS.HashSet<B>,\n <A, B>(self: HS.HashSet<A>, f: (a: A) => Iterable<B>) => HS.HashSet<B>\n>(2, (self, f) =>\n mutate(empty(), (set) => {\n forEach(self, (a) => {\n for (const b of f(a)) {\n if (!has(set, b)) {\n add(set, b)\n }\n }\n })\n }))\n\n/** @internal */\nexport const forEach = dual<\n <A>(f: (value: A) => void) => (self: HS.HashSet<A>) => void,\n <A>(self: HS.HashSet<A>, f: (value: A) => void) => void\n>(2, <A>(self: HS.HashSet<A>, f: (value: A) => void) =>\n HM.forEach(\n (self as HashSetImpl<A>)._keyMap,\n (_, k) => f(k)\n ))\n\n/** @internal */\nexport const reduce = dual<\n <A, Z>(zero: Z, f: (accumulator: Z, value: A) => Z) => (self: HS.HashSet<A>) => Z,\n <A, Z>(self: HS.HashSet<A>, zero: Z, f: (accumulator: Z, value: A) => Z) => Z\n>(3, <A, Z>(self: HS.HashSet<A>, zero: Z, f: (accumulator: Z, value: A) => Z) =>\n HM.reduce(\n (self as HashSetImpl<A>)._keyMap,\n zero,\n (z, _, a) => f(z, a)\n ))\n\n/** @internal */\nexport const filter: {\n <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: HS.HashSet<A>) => HS.HashSet<B>\n <A>(predicate: Predicate<NoInfer<A>>): (self: HS.HashSet<A>) => HS.HashSet<A>\n <A, B extends A>(self: HS.HashSet<A>, refinement: Refinement<A, B>): HS.HashSet<B>\n <A>(self: HS.HashSet<A>, predicate: Predicate<A>): HS.HashSet<A>\n} = dual(2, <A>(self: HS.HashSet<A>, f: Predicate<A>) => {\n return mutate(empty(), (set) => {\n const iterator = values(self)\n let next: IteratorResult<A, any>\n while (!(next = iterator.next()).done) {\n const value = next.value\n if (f(value)) {\n add(set, value)\n }\n }\n })\n})\n\n/** @internal */\nexport const partition: {\n <A, B extends A>(\n refinement: Refinement<NoInfer<A>, B>\n ): (self: HS.HashSet<A>) => [excluded: HS.HashSet<Exclude<A, B>>, satisfying: HS.HashSet<B>]\n <A>(\n predicate: Predicate<NoInfer<A>>\n ): (self: HS.HashSet<A>) => [excluded: HS.HashSet<A>, satisfying: HS.HashSet<A>]\n <A, B extends A>(\n self: HS.HashSet<A>,\n refinement: Refinement<A, B>\n ): [excluded: HS.HashSet<Exclude<A, B>>, satisfying: HS.HashSet<B>]\n <A>(self: HS.HashSet<A>, predicate: Predicate<A>): [excluded: HS.HashSet<A>, satisfying: HS.HashSet<A>]\n} = dual(2, <A>(self: HS.HashSet<A>, predicate: Predicate<A>): [excluded: HS.HashSet<A>, satisfying: HS.HashSet<A>] => {\n const iterator = values(self)\n let next: IteratorResult<A, any>\n const right = beginMutation(empty<A>())\n const left = beginMutation(empty<A>())\n while (!(next = iterator.next()).done) {\n const value = next.value\n if (predicate(value)) {\n add(right, value)\n } else {\n add(left, value)\n }\n }\n return [endMutation(left), endMutation(right)]\n})\n","/**\n * @since 2.0.0\n */\n\nimport type { Equal } from \"./Equal.js\"\nimport type { Inspectable } from \"./Inspectable.js\"\nimport * as HS from \"./internal/hashSet.js\"\nimport type { Pipeable } from \"./Pipeable.js\"\nimport type { Predicate, Refinement } from \"./Predicate.js\"\nimport type { NoInfer } from \"./Types.js\"\n\nconst TypeId: unique symbol = HS.HashSetTypeId as TypeId\n\n/**\n * @since 2.0.0\n * @category symbol\n */\nexport type TypeId = typeof TypeId\n\n/**\n * @since 2.0.0\n * @category models\n */\nexport interface HashSet<out A> extends Iterable<A>, Equal, Pipeable, Inspectable {\n readonly [TypeId]: TypeId\n}\n\n/**\n * @since 2.0.0\n * @category refinements\n */\nexport const isHashSet: {\n /**\n * @since 2.0.0\n * @category refinements\n */\n <A>(u: Iterable<A>): u is HashSet<A>\n /**\n * @since 2.0.0\n * @category refinements\n */\n (u: unknown): u is HashSet<unknown>\n} = HS.isHashSet\n\n/**\n * Creates an empty `HashSet`.\n *\n * @since 2.0.0\n * @category constructors\n */\nexport const empty: <A = never>() => HashSet<A> = HS.empty\n\n/**\n * Creates a new `HashSet` from an iterable collection of values.\n *\n * @since 2.0.0\n * @category constructors\n */\nexport const fromIterable: <A>(elements: Iterable<A>) => HashSet<A> = HS.fromIterable\n\n/**\n * Construct a new `HashSet` from a variable number of values.\n *\n * @since 2.0.0\n * @category constructors\n */\nexport const make: <As extends ReadonlyArray<any>>(...elements: As) => HashSet<As[number]> = HS.make\n\n/**\n * Checks if the specified value exists in the `HashSet`.\n *\n * @since 2.0.0\n * @category elements\n */\nexport const has: {\n /**\n * Checks if the specified value exists in the `HashSet`.\n *\n * @since 2.0.0\n * @category elements\n */\n <A>(value: A): (self: HashSet<A>) => boolean\n /**\n * Checks if the specified value exists in the `HashSet`.\n *\n * @since 2.0.0\n * @category elements\n */\n <A>(self: HashSet<A>, value: A): boolean\n} = HS.has\n\n/**\n * Check if a predicate holds true for some `HashSet` element.\n *\n * @since 2.0.0\n * @category elements\n */\nexport const some: {\n /**\n * Check if a predicate holds true for some `HashSet` element.\n *\n * @since 2.0.0\n * @category elements\n */\n <A>(f: Predicate<A>): (self: HashSet<A>) => boolean\n /**\n * Check if a predicate holds true for some `HashSet` element.\n *\n * @since 2.0.0\n * @category elements\n */\n <A>(self: HashSet<A>, f: Predicate<A>): boolean\n} = HS.some\n\n/**\n * Check if a predicate holds true for every `HashSet` element.\n *\n * @since 2.0.0\n * @category elements\n */\nexport const every: {\n /**\n * Check if a predicate holds true for every `HashSet` element.\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: HashSet<A>) => self is HashSet<B>\n /**\n * Check if a predicate holds true for every `HashSet` element.\n *\n * @since 2.0.0\n * @category elements\n */\n <A>(predicate: Predicate<A>): (self: HashSet<A>) => boolean\n /**\n * Check if a predicate holds true for every `HashSet` element.\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B extends A>(self: HashSet<A>, refinement: Refinement<A, B>): self is HashSet<B>\n /**\n * Check if a predicate holds true for every `HashSet` element.\n *\n * @since 2.0.0\n * @category elements\n */\n <A>(self: HashSet<A>, predicate: Predicate<A>): boolean\n} = HS.every\n\n/**\n * Returns `true` if and only if every element in the this `HashSet` is an\n * element of the second set,\n *\n * **NOTE**: the hash and equal of both sets must be the same.\n *\n * @since 2.0.0\n * @category elements\n */\nexport const isSubset: {\n /**\n * Returns `true` if and only if every element in the this `HashSet` is an\n * element of the second set,\n *\n * **NOTE**: the hash and equal of both sets must be the same.\n *\n * @since 2.0.0\n * @category elements\n */\n <A>(that: HashSet<A>): (self: HashSet<A>) => boolean\n /**\n * Returns `true` if and only if every element in the this `HashSet` is an\n * element of the second set,\n *\n * **NOTE**: the hash and equal of both sets must be the same.\n *\n * @since 2.0.0\n * @category elements\n */\n <A>(self: HashSet<A>, that: HashSet<A>): boolean\n} = HS.isSubset\n\n/**\n * Returns an `IterableIterator` of the values in the `HashSet`.\n *\n * @since 2.0.0\n * @category getters\n */\nexport const values: <A>(self: HashSet<A>) => IterableIterator<A> = HS.values\n\n/**\n * Calculates the number of values in the `HashSet`.\n *\n * @since 2.0.0\n * @category getters\n */\nexport const size: <A>(self: HashSet<A>) => number = HS.size\n\n/**\n * Marks the `HashSet` as mutable.\n *\n * @since 2.0.0\n */\nexport const beginMutation: <A>(self: HashSet<A>) => HashSet<A> = HS.beginMutation\n\n/**\n * Marks the `HashSet` as immutable.\n *\n * @since 2.0.0\n */\nexport const endMutation: <A>(self: HashSet<A>) => HashSet<A> = HS.endMutation\n\n/**\n * Mutates the `HashSet` within the context of the provided function.\n *\n * @since 2.0.0\n */\nexport const mutate: {\n /**\n * Mutates the `HashSet` within the context of the provided function.\n *\n * @since 2.0.0\n */\n <A>(f: (set: HashSet<A>) => void): (self: HashSet<A>) => HashSet<A>\n /**\n * Mutates the `HashSet` within the context of the provided function.\n *\n * @since 2.0.0\n */\n <A>(self: HashSet<A>, f: (set: HashSet<A>) => void): HashSet<A>\n} = HS.mutate\n\n/**\n * Adds a value to the `HashSet`.\n *\n * @since 2.0.0\n */\nexport const add: {\n /**\n * Adds a value to the `HashSet`.\n *\n * @since 2.0.0\n */\n <A>(value: A): (self: HashSet<A>) => HashSet<A>\n /**\n * Adds a value to the `HashSet`.\n *\n * @since 2.0.0\n */\n <A>(self: HashSet<A>, value: A): HashSet<A>\n} = HS.add\n\n/**\n * Removes a value from the `HashSet`.\n *\n * @since 2.0.0\n */\nexport const remove: {\n /**\n * Removes a value from the `HashSet`.\n *\n * @since 2.0.0\n */\n <A>(value: A): (self: HashSet<A>) => HashSet<A>\n /**\n * Removes a value from the `HashSet`.\n *\n * @since 2.0.0\n */\n <A>(self: HashSet<A>, value: A): HashSet<A>\n} = HS.remove\n\n/**\n * Computes the set difference between this `HashSet` and the specified\n * `Iterable<A>`.\n *\n * **NOTE**: the hash and equal of the values in both the set and the iterable\n * must be the same.\n *\n * @since 2.0.0\n */\nexport const difference: {\n /**\n * Computes the set difference between this `HashSet` and the specified\n * `Iterable<A>`.\n *\n * **NOTE**: the hash and equal of the values in both the set and the iterable\n * must be the same.\n *\n * @since 2.0.0\n */\n <A>(that: Iterable<A>): (self: HashSet<A>) => HashSet<A>\n /**\n * Computes the set difference between this `HashSet` and the specified\n * `Iterable<A>`.\n *\n * **NOTE**: the hash and equal of the values in both the set and the iterable\n * must be the same.\n *\n * @since 2.0.0\n */\n <A>(self: HashSet<A>, that: Iterable<A>): HashSet<A>\n} = HS.difference\n\n/**\n * Returns a `HashSet` of values which are present in both this set and that\n * `Iterable<A>`.\n *\n * **NOTE**: the hash and equal of the values in both the set and the iterable\n * must be the same.\n *\n * @since 2.0.0\n */\nexport const intersection: {\n /**\n * Returns a `HashSet` of values which are present in both this set and that\n * `Iterable<A>`.\n *\n * **NOTE**: the hash and equal of the values in both the set and the iterable\n * must be the same.\n *\n * @since 2.0.0\n */\n <A>(that: Iterable<A>): (self: HashSet<A>) => HashSet<A>\n /**\n * Returns a `HashSet` of values which are present in both this set and that\n * `Iterable<A>`.\n *\n * **NOTE**: the hash and equal of the values in both the set and the iterable\n * must be the same.\n *\n * @since 2.0.0\n */\n <A>(self: HashSet<A>, that: Iterable<A>): HashSet<A>\n} = HS.intersection\n\n/**\n * Computes the set union `(`self` + `that`)` between this `HashSet` and the\n * specified `Iterable<A>`.\n *\n * **NOTE**: the hash and equal of the values in both the set and the iterable\n * must be the same.\n *\n * @since 2.0.0\n */\nexport const union: {\n /**\n * Computes the set union `(`self` + `that`)` between this `HashSet` and the\n * specified `Iterable<A>`.\n *\n * **NOTE**: the hash and equal of the values in both the set and the iterable\n * must be the same.\n *\n * @since 2.0.0\n */\n <A>(that: Iterable<A>): (self: HashSet<A>) => HashSet<A>\n /**\n * Computes the set union `(`self` + `that`)` between this `HashSet` and the\n * specified `Iterable<A>`.\n *\n * **NOTE**: the hash and equal of the values in both the set and the iterable\n * must be the same.\n *\n * @since 2.0.0\n */\n <A>(self: HashSet<A>, that: Iterable<A>): HashSet<A>\n} = HS.union\n\n/**\n * Checks if a value is present in the `HashSet`. If it is present, the value\n * will be removed from the `HashSet`, otherwise the value will be added to the\n * `HashSet`.\n *\n * @since 2.0.0\n */\nexport const toggle: {\n /**\n * Checks if a value is present in the `HashSet`. If it is present, the value\n * will be removed from the `HashSet`, otherwise the value will be added to the\n * `HashSet`.\n *\n * @since 2.0.0\n */\n <A>(value: A): (self: HashSet<A>) => HashSet<A>\n /**\n * Checks if a value is present in the `HashSet`. If it is present, the value\n * will be removed from the `HashSet`, otherwise the value will be added to the\n * `HashSet`.\n *\n * @since 2.0.0\n */\n <A>(self: HashSet<A>, value: A): HashSet<A>\n} = HS.toggle\n\n/**\n * Maps over the values of the `HashSet` using the specified function.\n *\n * @since 2.0.0\n * @category mapping\n */\nexport const map: {\n /**\n * Maps over the values of the `HashSet` using the specified function.\n *\n * @since 2.0.0\n * @category mapping\n */\n <A, B>(f: (a: A) => B): (self: HashSet<A>) => HashSet<B>\n /**\n * Maps over the values of the `HashSet` using the specified function.\n *\n * @since 2.0.0\n * @category mapping\n */\n <A, B>(self: HashSet<A>, f: (a: A) => B): HashSet<B>\n} = HS.map\n\n/**\n * Chains over the values of the `HashSet` using the specified function.\n *\n * @since 2.0.0\n * @category sequencing\n */\nexport const flatMap: {\n /**\n * Chains over the values of the `HashSet` using the specified function.\n *\n * @since 2.0.0\n * @category sequencing\n */\n <A, B>(f: (a: A) => Iterable<B>): (self: HashSet<A>) => HashSet<B>\n /**\n * Chains over the values of the `HashSet` using the specified function.\n *\n * @since 2.0.0\n * @category sequencing\n */\n <A, B>(self: HashSet<A>, f: (a: A) => Iterable<B>): HashSet<B>\n} = HS.flatMap\n\n/**\n * Applies the specified function to the values of the `HashSet`.\n *\n * @since 2.0.0\n * @category traversing\n */\nexport const forEach: {\n /**\n * Applies the specified function to the values of the `HashSet`.\n *\n * @since 2.0.0\n * @category traversing\n */\n <A>(f: (value: A) => void): (self: HashSet<A>) => void\n /**\n * Applies the specified function to the values of the `HashSet`.\n *\n * @since 2.0.0\n * @category traversing\n */\n <A>(self: HashSet<A>, f: (value: A) => void): void\n} = HS.forEach\n\n/**\n * Reduces the specified state over the values of the `HashSet`.\n *\n * @since 2.0.0\n * @category folding\n */\nexport const reduce: {\n /**\n * Reduces the specified state over the values of the `HashSet`.\n *\n * @since 2.0.0\n * @category folding\n */\n <A, Z>(zero: Z, f: (accumulator: Z, value: A) => Z): (self: HashSet<A>) => Z\n /**\n * Reduces the specified state over the values of the `HashSet`.\n *\n * @since 2.0.0\n * @category folding\n */\n <A, Z>(self: HashSet<A>, zero: Z, f: (accumulator: Z, value: A) => Z): Z\n} = HS.reduce\n\n/**\n * Filters values out of a `HashSet` using the specified predicate.\n *\n * @since 2.0.0\n * @category filtering\n */\nexport const filter: {\n /**\n * Filters values out of a `HashSet` using the specified predicate.\n *\n * @since 2.0.0\n * @category filtering\n */\n <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: HashSet<A>) => HashSet<B>\n /**\n * Filters values out of a `HashSet` using the specified predicate.\n *\n * @since 2.0.0\n * @category filtering\n */\n <A>(predicate: Predicate<NoInfer<A>>): (self: HashSet<A>) => HashSet<A>\n /**\n * Filters values out of a `HashSet` using the specified predicate.\n *\n * @since 2.0.0\n * @category filtering\n */\n <A, B extends A>(self: HashSet<A>, refinement: Refinement<A, B>): HashSet<B>\n /**\n * Filters values out of a `HashSet` using the specified predicate.\n *\n * @since 2.0.0\n * @category filtering\n */\n <A>(self: HashSet<A>, predicate: Predicate<A>): HashSet<A>\n} = HS.filter\n\n/**\n * Partition the values of a `HashSet` using the specified predicate.\n *\n * If a value matches the predicate, it will be placed into the `HashSet` on the\n * right side of the resulting `Tuple`, otherwise the value will be placed into\n * the left side.\n *\n * @since 2.0.0\n * @category partitioning\n */\nexport const partition: {\n /**\n * Partition the values of a `HashSet` using the specified predicate.\n *\n * If a value matches the predicate, it will be placed into the `HashSet` on the\n * right side of the resulting `Tuple`, otherwise the value will be placed into\n * the left side.\n *\n * @since 2.0.0\n * @category partitioning\n */\n <A, B extends A>(\n refinement: Refinement<NoInfer<A>, B>\n ): (self: HashSet<A>) => [excluded: HashSet<Exclude<A, B>>, satisfying: HashSet<B>]\n /**\n * Partition the values of a `HashSet` using the specified predicate.\n *\n * If a value matches the predicate, it will be placed into the `HashSet` on the\n * right side of the resulting `Tuple`, otherwise the value will be placed into\n * the left side.\n *\n * @since 2.0.0\n * @category partitioning\n */\n <A>(predicate: Predicate<NoInfer<A>>): (self: HashSet<A>) => [excluded: HashSet<A>, satisfying: HashSet<A>]\n /**\n * Partition the values of a `HashSet` using the specified predicate.\n *\n * If a value matches the predicate, it will be placed into the `HashSet` on the\n * right side of the resulting `Tuple`, otherwise the value will be placed into\n * the left side.\n *\n * @since 2.0.0\n * @category partitioning\n */\n <A, B extends A>(\n self: HashSet<A>,\n refinement: Refinement<A, B>\n ): [excluded: HashSet<Exclude<A, B>>, satisfying: HashSet<B>]\n /**\n * Partition the values of a `HashSet` using the specified predicate.\n *\n * If a value matches the predicate, it will be placed into the `HashSet` on the\n * right side of the resulting `Tuple`, otherwise the value will be placed into\n * the left side.\n *\n * @since 2.0.0\n * @category partitioning\n */\n <A>(self: HashSet<A>, predicate: Predicate<A>): [excluded: HashSet<A>, satisfying: HashSet<A>]\n} = HS.partition\n","/** @internal */\nexport const OP_DIE = \"Die\" as const\n\n/** @internal */\nexport type OP_DIE = typeof OP_DIE\n\n/** @internal */\nexport const OP_EMPTY = \"Empty\" as const\n\n/** @internal */\nexport type OP_EMPTY = typeof OP_EMPTY\n\n/** @internal */\nexport const OP_FAIL = \"Fail\" as const\n\n/** @internal */\nexport type OP_FAIL = typeof OP_FAIL\n\n/** @internal */\nexport const OP_INTERRUPT = \"Interrupt\" as const\n\n/** @internal */\nexport type OP_INTERRUPT = typeof OP_INTERRUPT\n\n/** @internal */\nexport const OP_PARALLEL = \"Parallel\" as const\n\n/** @internal */\nexport type OP_PARALLEL = typeof OP_PARALLEL\n\n/** @internal */\nexport const OP_SEQUENTIAL = \"Sequential\" as const\n\n/** @internal */\nexport type OP_SEQUENTIAL = typeof OP_SEQUENTIAL\n","import * as Arr from \"../Array.js\"\nimport type * as Cause from \"../Cause.js\"\nimport * as Chunk from \"../Chunk.js\"\nimport * as Either from \"../Either.js\"\nimport * as Equal from \"../Equal.js\"\nimport type * as FiberId from \"../FiberId.js\"\nimport { constFalse, constTrue, dual, identity, pipe } from \"../Function.js\"\nimport { globalValue } from \"../GlobalValue.js\"\nimport * as Hash from \"../Hash.js\"\nimport * as HashSet from \"../HashSet.js\"\nimport { NodeInspectSymbol, stringifyCircular, toJSON } from \"../Inspectable.js\"\nimport * as Option from \"../Option.js\"\nimport { pipeArguments } from \"../Pipeable.js\"\nimport type { Predicate, Refinement } from \"../Predicate.js\"\nimport { hasProperty, isFunction } from \"../Predicate.js\"\nimport type { AnySpan, Span } from \"../Tracer.js\"\nimport type { NoInfer } from \"../Types.js\"\nimport { getBugErrorMessage } from \"./errors.js\"\nimport * as OpCodes from \"./opCodes/cause.js\"\n\n// -----------------------------------------------------------------------------\n// Models\n// -----------------------------------------------------------------------------\n\n/** @internal */\nconst CauseSymbolKey = \"effect/Cause\"\n\n/** @internal */\nexport const CauseTypeId: Cause.CauseTypeId = Symbol.for(\n CauseSymbolKey\n) as Cause.CauseTypeId\n\nconst variance = {\n /* c8 ignore next */\n _E: (_: never) => _\n}\n\n/** @internal */\nconst proto = {\n [CauseTypeId]: variance,\n [Hash.symbol](this: Cause.Cause<any>): number {\n return pipe(\n Hash.hash(CauseSymbolKey),\n Hash.combine(Hash.hash(flattenCause(this))),\n Hash.cached(this)\n )\n },\n [Equal.symbol](this: Cause.Cause<any>, that: unknown): boolean {\n return isCause(that) && causeEquals(this, that)\n },\n pipe() {\n return pipeArguments(this, arguments)\n },\n toJSON<E>(this: Cause.Cause<E>) {\n switch (this._tag) {\n case \"Empty\":\n return { _id: \"Cause\", _tag: this._tag }\n case \"Die\":\n return { _id: \"Cause\", _tag: this._tag, defect: toJSON(this.defect) }\n case \"Interrupt\":\n return { _id: \"Cause\", _tag: this._tag, fiberId: this.fiberId.toJSON() }\n case \"Fail\":\n return { _id: \"Cause\", _tag: this._tag, failure: toJSON(this.error) }\n case \"Sequential\":\n case \"Parallel\":\n return { _id: \"Cause\", _tag: this._tag, left: toJSON(this.left), right: toJSON(this.right) }\n }\n },\n toString<E>(this: Cause.Cause<E>) {\n return pretty(this)\n },\n [NodeInspectSymbol]<E>(this: Cause.Cause<E>) {\n return this.toJSON()\n }\n}\n\n// -----------------------------------------------------------------------------\n// Constructors\n// -----------------------------------------------------------------------------\n\n/** @internal */\nexport const empty: Cause.Cause<never> = (() => {\n const o = Object.create(proto)\n o._tag = OpCodes.OP_EMPTY\n return o\n})()\n\n/** @internal */\nexport const fail = <E>(error: E): Cause.Cause<E> => {\n const o = Object.create(proto)\n o._tag = OpCodes.OP_FAIL\n o.error = error\n return o\n}\n\n/** @internal */\nexport const die = (defect: unknown): Cause.Cause<never> => {\n const o = Object.create(proto)\n o._tag = OpCodes.OP_DIE\n o.defect = defect\n return o\n}\n\n/** @internal */\nexport const interrupt = (fiberId: FiberId.FiberId): Cause.Cause<never> => {\n const o = Object.create(proto)\n o._tag = OpCodes.OP_INTERRUPT\n o.fiberId = fiberId\n return o\n}\n\n/** @internal */\nexport const parallel = <E, E2>(left: Cause.Cause<E>, right: Cause.Cause<E2>): Cause.Cause<E | E2> => {\n const o = Object.create(proto)\n o._tag = OpCodes.OP_PARALLEL\n o.left = left\n o.right = right\n return o\n}\n\n/** @internal */\nexport const sequential = <E, E2>(left: Cause.Cause<E>, right: Cause.Cause<E2>): Cause.Cause<E | E2> => {\n const o = Object.create(proto)\n o._tag = OpCodes.OP_SEQUENTIAL\n o.left = left\n o.right = right\n return o\n}\n\n// -----------------------------------------------------------------------------\n// Refinements\n// -----------------------------------------------------------------------------\n\n/** @internal */\nexport const isCause = (u: unknown): u is Cause.Cause<never> => hasProperty(u, CauseTypeId)\n\n/** @internal */\nexport const isEmptyType = <E>(self: Cause.Cause<E>): self is Cause.Empty => self._tag === OpCodes.OP_EMPTY\n\n/** @internal */\nexport const isFailType = <E>(self: Cause.Cause<E>): self is Cause.Fail<E> => self._tag === OpCodes.OP_FAIL\n\n/** @internal */\nexport const isDieType = <E>(self: Cause.Cause<E>): self is Cause.Die => self._tag === OpCodes.OP_DIE\n\n/** @internal */\nexport const isInterruptType = <E>(self: Cause.Cause<E>): self is Cause.Interrupt => self._tag === OpCodes.OP_INTERRUPT\n\n/** @internal */\nexport const isSequentialType = <E>(self: Cause.Cause<E>): self is Cause.Sequential<E> =>\n self._tag === OpCodes.OP_SEQUENTIAL\n\n/** @internal */\nexport const isParallelType = <E>(self: Cause.Cause<E>): self is Cause.Parallel<E> => self._tag === OpCodes.OP_PARALLEL\n\n// -----------------------------------------------------------------------------\n// Getters\n// -----------------------------------------------------------------------------\n\n/** @internal */\nexport const size = <E>(self: Cause.Cause<E>): number => reduceWithContext(self, void 0, SizeCauseReducer)\n\n/** @internal */\nexport const isEmpty = <E>(self: Cause.Cause<E>): boolean => {\n if (self._tag === OpCodes.OP_EMPTY) {\n return true\n }\n return reduce(self, true, (acc, cause) => {\n switch (cause._tag) {\n case OpCodes.OP_EMPTY: {\n return Option.some(acc)\n }\n case OpCodes.OP_DIE:\n case OpCodes.OP_FAIL:\n case OpCodes.OP_INTERRUPT: {\n return Option.some(false)\n }\n default: {\n return Option.none()\n }\n }\n })\n}\n\n/** @internal */\nexport const isFailure = <E>(self: Cause.Cause<E>): boolean => Option.isSome(failureOption(self))\n\n/** @internal */\nexport const isDie = <E>(self: Cause.Cause<E>): boolean => Option.isSome(dieOption(self))\n\n/** @internal */\nexport const isInterrupted = <E>(self: Cause.Cause<E>): boolean => Option.isSome(interruptOption(self))\n\n/** @internal */\nexport const isInterruptedOnly = <E>(self: Cause.Cause<E>): boolean =>\n reduceWithContext(undefined, IsInterruptedOnlyCauseReducer)(self)\n\n/** @internal */\nexport const failures = <E>(self: Cause.Cause<E>): Chunk.Chunk<E> =>\n Chunk.reverse(\n reduce<Chunk.Chunk<E>, E>(\n self,\n Chunk.empty<E>(),\n (list, cause) =>\n cause._tag === OpCodes.OP_FAIL ?\n Option.some(pipe(list, Chunk.prepend(cause.error))) :\n Option.none()\n )\n )\n\n/** @internal */\nexport const defects = <E>(self: Cause.Cause<E>): Chunk.Chunk<unknown> =>\n Chunk.reverse(\n reduce<Chunk.Chunk<unknown>, E>(\n self,\n Chunk.empty<unknown>(),\n (list, cause) =>\n cause._tag === OpCodes.OP_DIE ?\n Option.some(pipe(list, Chunk.prepend(cause.defect))) :\n Option.none()\n )\n )\n\n/** @internal */\nexport const interruptors = <E>(self: Cause.Cause<E>): HashSet.HashSet<FiberId.FiberId> =>\n reduce(self, HashSet.empty<FiberId.FiberId>(), (set, cause) =>\n cause._tag === OpCodes.OP_INTERRUPT ?\n Option.some(pipe(set, HashSet.add(cause.fiberId))) :\n Option.none())\n\n/** @internal */\nexport const failureOption = <E>(self: Cause.Cause<E>): Option.Option<E> =>\n find<E, E>(self, (cause) =>\n cause._tag === OpCodes.OP_FAIL ?\n Option.some(cause.error) :\n Option.none())\n\n/** @internal */\nexport const failureOrCause = <E>(self: Cause.Cause<E>): Either.Either<Cause.Cause<never>, E> => {\n const option = failureOption(self)\n switch (option._tag) {\n case \"None\": {\n // no `E` inside this `Cause`, so it can be safely cast to `never`\n return Either.right(self as Cause.Cause<never>)\n }\n case \"Some\": {\n return Either.left(option.value)\n }\n }\n}\n\n/** @internal */\nexport const dieOption = <E>(self: Cause.Cause<E>): Option.Option<unknown> =>\n find(self, (cause) =>\n cause._tag === OpCodes.OP_DIE ?\n Option.some(cause.defect) :\n Option.none())\n\n/** @internal */\nexport const flipCauseOption = <E>(self: Cause.Cause<Option.Option<E>>): Option.Option<Cause.Cause<E>> =>\n match(self, {\n onEmpty: Option.some(empty),\n onFail: (failureOption) => pipe(failureOption, Option.map(fail)),\n onDie: (defect) => Option.some(die(defect)),\n onInterrupt: (fiberId) => Option.some(interrupt(fiberId)),\n onSequential: (left, right) => {\n if (Option.isSome(left) && Option.isSome(right)) {\n return Option.some(sequential(left.value, right.value))\n }\n if (Option.isNone(left) && Option.isSome(right)) {\n return Option.some(right.value)\n }\n if (Option.isSome(left) && Option.isNone(right)) {\n return Option.some(left.value)\n }\n return Option.none()\n },\n onParallel: (left, right) => {\n if (Option.isSome(left) && Option.isSome(right)) {\n return Option.some(parallel(left.value, right.value))\n }\n if (Option.isNone(left) && Option.isSome(right)) {\n return Option.some(right.value)\n }\n if (Option.isSome(left) && Option.isNone(right)) {\n return Option.some(left.value)\n }\n return Option.none()\n }\n })\n\n/** @internal */\nexport const interruptOption = <E>(self: Cause.Cause<E>): Option.Option<FiberId.FiberId> =>\n find(self, (cause) =>\n cause._tag === OpCodes.OP_INTERRUPT ?\n Option.some(cause.fiberId) :\n Option.none())\n\n/** @internal */\nexport const keepDefects = <E>(self: Cause.Cause<E>): Option.Option<Cause.Cause<never>> =>\n match<Option.Option<Cause.Cause<never>>, E>(self, {\n onEmpty: Option.none(),\n onFail: () => Option.none(),\n onDie: (defect) => Option.some(die(defect)),\n onInterrupt: () => Option.none(),\n onSequential: (left, right) => {\n if (Option.isSome(left) && Option.isSome(right)) {\n return Option.some(sequential(left.value, right.value))\n }\n if (Option.isSome(left) && Option.isNone(right)) {\n return Option.some(left.value)\n }\n if (Option.isNone(left) && Option.isSome(right)) {\n return Option.some(right.value)\n }\n return Option.none()\n },\n onParallel: (left, right) => {\n if (Option.isSome(left) && Option.isSome(right)) {\n return Option.some(parallel(left.value, right.value))\n }\n if (Option.isSome(left) && Option.isNone(right)) {\n return Option.some(left.value)\n }\n if (Option.isNone(left) && Option.isSome(right)) {\n return Option.some(right.value)\n }\n return Option.none()\n }\n })\n\n/** @internal */\nexport const keepDefectsAndElectFailures = <E>(self: Cause.Cause<E>): Option.Option<Cause.Cause<never>> =>\n match<Option.Option<Cause.Cause<never>>, E>(self, {\n onEmpty: Option.none(),\n onFail: (failure) => Option.some(die(failure)),\n onDie: (defect) => Option.some(die(defect)),\n onInterrupt: () => Option.none(),\n onSequential: (left, right) => {\n if (Option.isSome(left) && Option.isSome(right)) {\n return Option.some(sequential(left.value, right.value))\n }\n if (Option.isSome(left) && Option.isNone(right)) {\n return Option.some(left.value)\n }\n if (Option.isNone(left) && Option.isSome(right)) {\n return Option.some(right.value)\n }\n return Option.none()\n },\n onParallel: (left, right) => {\n if (Option.isSome(left) && Option.isSome(right)) {\n return Option.some(parallel(left.value, right.value))\n }\n if (Option.isSome(left) && Option.isNone(right)) {\n return Option.some(left.value)\n }\n if (Option.isNone(left) && Option.isSome(right)) {\n return Option.some(right.value)\n }\n return Option.none()\n }\n })\n\n/** @internal */\nexport const linearize = <E>(self: Cause.Cause<E>): HashSet.HashSet<Cause.Cause<E>> =>\n match(self, {\n onEmpty: HashSet.empty(),\n onFail: (error) => HashSet.make(fail(error)),\n onDie: (defect) => HashSet.make(die(defect)),\n onInterrupt: (fiberId) => HashSet.make(interrupt(fiberId)),\n onSequential: (leftSet, rightSet) =>\n pipe(\n leftSet,\n HashSet.flatMap((leftCause) =>\n pipe(\n rightSet,\n HashSet.map((rightCause) => sequential(leftCause, rightCause))\n )\n )\n ),\n onParallel: (leftSet, rightSet) =>\n pipe(\n leftSet,\n HashSet.flatMap((leftCause) =>\n pipe(\n rightSet,\n HashSet.map((rightCause) => parallel(leftCause, rightCause))\n )\n )\n )\n })\n\n/** @internal */\nexport const stripFailures = <E>(self: Cause.Cause<E>): Cause.Cause<never> =>\n match(self, {\n onEmpty: empty,\n onFail: () => empty,\n onDie: (defect) => die(defect),\n onInterrupt: (fiberId) => interrupt(fiberId),\n onSequential: sequential,\n onParallel: parallel\n })\n\n/** @internal */\nexport const electFailures = <E>(self: Cause.Cause<E>): Cause.Cause<never> =>\n match(self, {\n onEmpty: empty,\n onFail: (failure) => die(failure),\n onDie: (defect) => die(defect),\n onInterrupt: (fiberId) => interrupt(fiberId),\n onSequential: (left, right) => sequential(left, right),\n onParallel: (left, right) => parallel(left, right)\n })\n\n/** @internal */\nexport const stripSomeDefects = dual<\n (pf: (defect: unknown) => Option.Option<unknown>) => <E>(self: Cause.Cause<E>) => Option.Option<Cause.Cause<E>>,\n <E>(self: Cause.Cause<E>, pf: (defect: unknown) => Option.Option<unknown>) => Option.Option<Cause.Cause<E>>\n>(2, <E>(self: Cause.Cause<E>, pf: (defect: unknown) => Option.Option<unknown>) =>\n match(self, {\n onEmpty: Option.some(empty),\n onFail: (error) => Option.some(fail(error)),\n onDie: (defect) => {\n const option = pf(defect)\n return Option.isSome(option) ? Option.none() : Option.some(die(defect))\n },\n onInterrupt: (fiberId) => Option.some(interrupt(fiberId)),\n onSequential: (left, right) => {\n if (Option.isSome(left) && Option.isSome(right)) {\n return Option.some(sequential(left.value, right.value))\n }\n if (Option.isSome(left) && Option.isNone(right)) {\n return Option.some(left.value)\n }\n if (Option.isNone(left) && Option.isSome(right)) {\n return Option.some(right.value)\n }\n return Option.none()\n },\n onParallel: (left, right) => {\n if (Option.isSome(left) && Option.isSome(right)) {\n return Option.some(parallel(left.value, right.value))\n }\n if (Option.isSome(left) && Option.isNone(right)) {\n return Option.some(left.value)\n }\n if (Option.isNone(left) && Option.isSome(right)) {\n return Option.some(right.value)\n }\n return Option.none()\n }\n }))\n\n// -----------------------------------------------------------------------------\n// Mapping\n// -----------------------------------------------------------------------------\n\n/** @internal */\nexport const as = dual<\n <E2>(error: E2) => <E>(self: Cause.Cause<E>) => Cause.Cause<E2>,\n <E, E2>(self: Cause.Cause<E>, error: E2) => Cause.Cause<E2>\n>(2, (self, error) => map(self, () => error))\n\n/** @internal */\nexport const map = dual<\n <E, E2>(f: (e: E) => E2) => (self: Cause.Cause<E>) => Cause.Cause<E2>,\n <E, E2>(self: Cause.Cause<E>, f: (e: E) => E2) => Cause.Cause<E2>\n>(2, (self, f) => flatMap(self, (e) => fail(f(e))))\n\n// -----------------------------------------------------------------------------\n// Sequencing\n// -----------------------------------------------------------------------------\n\n/** @internal */\nexport const flatMap = dual<\n <E, E2>(f: (e: E) => Cause.Cause<E2>) => (self: Cause.Cause<E>) => Cause.Cause<E2>,\n <E, E2>(self: Cause.Cause<E>, f: (e: E) => Cause.Cause<E2>) => Cause.Cause<E2>\n>(2, (self, f) =>\n match(self, {\n onEmpty: empty,\n onFail: (error) => f(error),\n onDie: (defect) => die(defect),\n onInterrupt: (fiberId) => interrupt(fiberId),\n onSequential: (left, right) => sequential(left, right),\n onParallel: (left, right) => parallel(left, right)\n }))\n\n/** @internal */\nexport const flatten = <E>(self: Cause.Cause<Cause.Cause<E>>): Cause.Cause<E> => flatMap(self, identity)\n\n/** @internal */\nexport const andThen: {\n <E, E2>(f: (e: E) => Cause.Cause<E2>): (self: Cause.Cause<E>) => Cause.Cause<E2>\n <E2>(f: Cause.Cause<E2>): <E>(self: Cause.Cause<E>) => Cause.Cause<E2>\n <E, E2>(self: Cause.Cause<E>, f: (e: E) => Cause.Cause<E2>): Cause.Cause<E2>\n <E, E2>(self: Cause.Cause<E>, f: Cause.Cause<E2>): Cause.Cause<E2>\n} = dual(\n 2,\n <E, E2>(self: Cause.Cause<E>, f: ((e: E) => Cause.Cause<E2>) | Cause.Cause<E2>): Cause.Cause<E2> =>\n isFunction(f) ? flatMap(self, f) : flatMap(self, () => f)\n)\n\n// -----------------------------------------------------------------------------\n// Equality\n// -----------------------------------------------------------------------------\n\n/** @internal */\nexport const contains = dual<\n <E2>(that: Cause.Cause<E2>) => <E>(self: Cause.Cause<E>) => boolean,\n <E, E2>(self: Cause.Cause<E>, that: Cause.Cause<E2>) => boolean\n>(2, (self, that) => {\n if (that._tag === OpCodes.OP_EMPTY || self === that) {\n return true\n }\n return reduce(self, false, (accumulator, cause) => {\n return Option.some(accumulator || causeEquals(cause, that))\n })\n})\n\n/** @internal */\nconst causeEquals = (left: Cause.Cause<unknown>, right: Cause.Cause<unknown>): boolean => {\n let leftStack: Chunk.Chunk<Cause.Cause<unknown>> = Chunk.of(left)\n let rightStack: Chunk.Chunk<Cause.Cause<unknown>> = Chunk.of(right)\n while (Chunk.isNonEmpty(leftStack) && Chunk.isNonEmpty(rightStack)) {\n const [leftParallel, leftSequential] = pipe(\n Chunk.headNonEmpty(leftStack),\n reduce(\n [HashSet.empty<unknown>(), Chunk.empty<Cause.Cause<unknown>>()] as const,\n ([parallel, sequential], cause) => {\n const [par, seq] = evaluateCause(cause)\n return Option.some(\n [\n pipe(parallel, HashSet.union(par)),\n pipe(sequential, Chunk.appendAll(seq))\n ] as const\n )\n }\n )\n )\n const [rightParallel, rightSequential] = pipe(\n Chunk.headNonEmpty(rightStack),\n reduce(\n [HashSet.empty<unknown>(), Chunk.empty<Cause.Cause<unknown>>()] as const,\n ([parallel, sequential], cause) => {\n const [par, seq] = evaluateCause(cause)\n return Option.some(\n [\n pipe(parallel, HashSet.union(par)),\n pipe(sequential, Chunk.appendAll(seq))\n ] as const\n )\n }\n )\n )\n if (!Equal.equals(leftParallel, rightParallel)) {\n return false\n }\n leftStack = leftSequential\n rightStack = rightSequential\n }\n return true\n}\n\n// -----------------------------------------------------------------------------\n// Flattening\n// -----------------------------------------------------------------------------\n\n/**\n * Flattens a cause to a sequence of sets of causes, where each set represents\n * causes that fail in parallel and sequential sets represent causes that fail\n * after each other.\n *\n * @internal\n */\nconst flattenCause = (cause: Cause.Cause<unknown>): Chunk.Chunk<HashSet.HashSet<unknown>> => {\n return flattenCauseLoop(Chunk.of(cause), Chunk.empty())\n}\n\n/** @internal */\nconst flattenCauseLoop = (\n causes: Chunk.Chunk<Cause.Cause<unknown>>,\n flattened: Chunk.Chunk<HashSet.HashSet<unknown>>\n): Chunk.Chunk<HashSet.HashSet<unknown>> => {\n // eslint-disable-next-line no-constant-condition\n while (1) {\n const [parallel, sequential] = pipe(\n causes,\n Arr.reduce(\n [HashSet.empty<unknown>(), Chunk.empty<Cause.Cause<unknown>>()] as const,\n ([parallel, sequential], cause) => {\n const [par, seq] = evaluateCause(cause)\n return [\n pipe(parallel, HashSet.union(par)),\n pipe(sequential, Chunk.appendAll(seq))\n ]\n }\n )\n )\n const updated = HashSet.size(parallel) > 0 ?\n pipe(flattened, Chunk.prepend(parallel)) :\n flattened\n if (Chunk.isEmpty(sequential)) {\n return Chunk.reverse(updated)\n }\n causes = sequential\n flattened = updated\n }\n throw new Error(getBugErrorMessage(\"Cause.flattenCauseLoop\"))\n}\n\n// -----------------------------------------------------------------------------\n// Finding\n// -----------------------------------------------------------------------------\n\n/** @internal */\nexport const find = dual<\n <E, Z>(pf: (cause: Cause.Cause<E>) => Option.Option<Z>) => (self: Cause.Cause<E>) => Option.Option<Z>,\n <E, Z>(self: Cause.Cause<E>, pf: (cause: Cause.Cause<E>) => Option.Option<Z>) => Option.Option<Z>\n>(2, <E, Z>(self: Cause.Cause<E>, pf: (cause: Cause.Cause<E>) => Option.Option<Z>) => {\n const stack: Array<Cause.Cause<E>> = [self]\n while (stack.length > 0) {\n const item = stack.pop()!\n const option = pf(item)\n switch (option._tag) {\n case \"None\": {\n switch (item._tag) {\n case OpCodes.OP_SEQUENTIAL:\n case OpCodes.OP_PARALLEL: {\n stack.push(item.right)\n stack.push(item.left)\n break\n }\n }\n break\n }\n case \"Some\": {\n return option\n }\n }\n }\n return Option.none()\n})\n\n// -----------------------------------------------------------------------------\n// Filtering\n// -----------------------------------------------------------------------------\n\n/** @internal */\nexport const filter: {\n <E, EB extends E>(\n refinement: Refinement<Cause.Cause<NoInfer<E>>, Cause.Cause<EB>>\n ): (self: Cause.Cause<E>) => Cause.Cause<EB>\n <E>(predicate: Predicate<Cause.Cause<NoInfer<E>>>): (self: Cause.Cause<E>) => Cause.Cause<E>\n <E, EB extends E>(self: Cause.Cause<E>, refinement: Refinement<Cause.Cause<E>, Cause.Cause<EB>>): Cause.Cause<EB>\n <E>(self: Cause.Cause<E>, predicate: Predicate<Cause.Cause<E>>): Cause.Cause<E>\n} = dual(\n 2,\n <E>(self: Cause.Cause<E>, predicate: Predicate<Cause.Cause<E>>): Cause.Cause<E> =>\n reduceWithContext(self, void 0, FilterCauseReducer(predicate))\n)\n\n// -----------------------------------------------------------------------------\n// Evaluation\n// -----------------------------------------------------------------------------\n\n/**\n * Takes one step in evaluating a cause, returning a set of causes that fail\n * in parallel and a list of causes that fail sequentially after those causes.\n *\n * @internal\n */\nconst evaluateCause = (\n self: Cause.Cause<unknown>\n): [HashSet.HashSet<unknown>, Chunk.Chunk<Cause.Cause<unknown>>] => {\n let cause: Cause.Cause<unknown> | undefined = self\n const stack: Array<Cause.Cause<unknown>> = []\n let _parallel = HashSet.empty<unknown>()\n let _sequential = Chunk.empty<Cause.Cause<unknown>>()\n while (cause !== undefined) {\n switch (cause._tag) {\n case OpCodes.OP_EMPTY: {\n if (stack.length === 0) {\n return [_parallel, _sequential]\n }\n cause = stack.pop()\n break\n }\n case OpCodes.OP_FAIL: {\n _parallel = HashSet.add(_parallel, Chunk.make(cause._tag, cause.error))\n if (stack.length === 0) {\n return [_parallel, _sequential]\n }\n cause = stack.pop()\n break\n }\n case OpCodes.OP_DIE: {\n _parallel = HashSet.add(_parallel, Chunk.make(cause._tag, cause.defect))\n if (stack.length === 0) {\n return [_parallel, _sequential]\n }\n cause = stack.pop()\n break\n }\n case OpCodes.OP_INTERRUPT: {\n _parallel = HashSet.add(_parallel, Chunk.make(cause._tag, cause.fiberId as unknown))\n if (stack.length === 0) {\n return [_parallel, _sequential]\n }\n cause = stack.pop()\n break\n }\n case OpCodes.OP_SEQUENTIAL: {\n switch (cause.left._tag) {\n case OpCodes.OP_EMPTY: {\n cause = cause.right\n break\n }\n case OpCodes.OP_SEQUENTIAL: {\n cause = sequential(cause.left.left, sequential(cause.left.right, cause.right))\n break\n }\n case OpCodes.OP_PARALLEL: {\n cause = parallel(\n sequential(cause.left.left, cause.right),\n sequential(cause.left.right, cause.right)\n )\n break\n }\n default: {\n _sequential = Chunk.prepend(_sequential, cause.right)\n cause = cause.left\n break\n }\n }\n break\n }\n case OpCodes.OP_PARALLEL: {\n stack.push(cause.right)\n cause = cause.left\n break\n }\n }\n }\n throw new Error(getBugErrorMessage(\"Cause.evaluateCauseLoop\"))\n}\n\n// -----------------------------------------------------------------------------\n// Reducing\n// -----------------------------------------------------------------------------\n\n/** @internal */\nconst SizeCauseReducer: Cause.CauseReducer<unknown, unknown, number> = {\n emptyCase: () => 0,\n failCase: () => 1,\n dieCase: () => 1,\n interruptCase: () => 1,\n sequentialCase: (_, left, right) => left + right,\n parallelCase: (_, left, right) => left + right\n}\n\n/** @internal */\nconst IsInterruptedOnlyCauseReducer: Cause.CauseReducer<unknown, unknown, boolean> = {\n emptyCase: constTrue,\n failCase: constFalse,\n dieCase: constFalse,\n interruptCase: constTrue,\n sequentialCase: (_, left, right) => left && right,\n parallelCase: (_, left, right) => left && right\n}\n\n/** @internal */\nconst FilterCauseReducer = <E>(\n predicate: Predicate<Cause.Cause<E>>\n): Cause.CauseReducer<unknown, E, Cause.Cause<E>> => ({\n emptyCase: () => empty,\n failCase: (_, error) => fail(error),\n dieCase: (_, defect) => die(defect),\n interruptCase: (_, fiberId) => interrupt(fiberId),\n sequentialCase: (_, left, right) => {\n if (predicate(left)) {\n if (predicate(right)) {\n return sequential(left, right)\n }\n return left\n }\n if (predicate(right)) {\n return right\n }\n return empty\n },\n parallelCase: (_, left, right) => {\n if (predicate(left)) {\n if (predicate(right)) {\n return parallel(left, right)\n }\n return left\n }\n if (predicate(right)) {\n return right\n }\n return empty\n }\n})\n\n/** @internal */\ntype CauseCase = SequentialCase | ParallelCase\n\nconst OP_SEQUENTIAL_CASE = \"SequentialCase\"\n\nconst OP_PARALLEL_CASE = \"ParallelCase\"\n\n/** @internal */\ninterface SequentialCase {\n readonly _tag: typeof OP_SEQUENTIAL_CASE\n}\n\n/** @internal */\ninterface ParallelCase {\n readonly _tag: typeof OP_PARALLEL_CASE\n}\n\n/** @internal */\nexport const match = dual<\n <Z, E>(\n options: {\n readonly onEmpty: Z\n readonly onFail: (error: E) => Z\n readonly onDie: (defect: unknown) => Z\n readonly onInterrupt: (fiberId: FiberId.FiberId) => Z\n readonly onSequential: (left: Z, right: Z) => Z\n readonly onParallel: (left: Z, right: Z) => Z\n }\n ) => (self: Cause.Cause<E>) => Z,\n <Z, E>(\n self: Cause.Cause<E>,\n options: {\n readonly onEmpty: Z\n readonly onFail: (error: E) => Z\n readonly onDie: (defect: unknown) => Z\n readonly onInterrupt: (fiberId: FiberId.FiberId) => Z\n readonly onSequential: (left: Z, right: Z) => Z\n readonly onParallel: (left: Z, right: Z) => Z\n }\n ) => Z\n>(2, (self, { onDie, onEmpty, onFail, onInterrupt, onParallel, onSequential }) => {\n return reduceWithContext(self, void 0, {\n emptyCase: () => onEmpty,\n failCase: (_, error) => onFail(error),\n dieCase: (_, defect) => onDie(defect),\n interruptCase: (_, fiberId) => onInterrupt(fiberId),\n sequentialCase: (_, left, right) => onSequential(left, right),\n parallelCase: (_, left, right) => onParallel(left, right)\n })\n})\n\n/** @internal */\nexport const reduce = dual<\n <Z, E>(zero: Z, pf: (accumulator: Z, cause: Cause.Cause<E>) => Option.Option<Z>) => (self: Cause.Cause<E>) => Z,\n <Z, E>(self: Cause.Cause<E>, zero: Z, pf: (accumulator: Z, cause: Cause.Cause<E>) => Option.Option<Z>) => Z\n>(3, <Z, E>(self: Cause.Cause<E>, zero: Z, pf: (accumulator: Z, cause: Cause.Cause<E>) => Option.Option<Z>) => {\n let accumulator: Z = zero\n let cause: Cause.Cause<E> | undefined = self\n const causes: Array<Cause.Cause<E>> = []\n while (cause !== undefined) {\n const option = pf(accumulator, cause)\n accumulator = Option.isSome(option) ? option.value : accumulator\n switch (cause._tag) {\n case OpCodes.OP_SEQUENTIAL: {\n causes.push(cause.right)\n cause = cause.left\n break\n }\n case OpCodes.OP_PARALLEL: {\n causes.push(cause.right)\n cause = cause.left\n break\n }\n default: {\n cause = undefined\n break\n }\n }\n if (cause === undefined && causes.length > 0) {\n cause = causes.pop()!\n }\n }\n return accumulator\n})\n\n/** @internal */\nexport const reduceWithContext = dual<\n <C, E, Z>(context: C, reducer: Cause.CauseReducer<C, E, Z>) => (self: Cause.Cause<E>) => Z,\n <C, E, Z>(self: Cause.Cause<E>, context: C, reducer: Cause.CauseReducer<C, E, Z>) => Z\n>(3, <C, E, Z>(self: Cause.Cause<E>, context: C, reducer: Cause.CauseReducer<C, E, Z>) => {\n const input: Array<Cause.Cause<E>> = [self]\n const output: Array<Either.Either<Z, CauseCase>> = []\n while (input.length > 0) {\n const cause = input.pop()!\n switch (cause._tag) {\n case OpCodes.OP_EMPTY: {\n output.push(Either.right(reducer.emptyCase(context)))\n break\n }\n case OpCodes.OP_FAIL: {\n output.push(Either.right(reducer.failCase(context, cause.error)))\n break\n }\n case OpCodes.OP_DIE: {\n output.push(Either.right(reducer.dieCase(context, cause.defect)))\n break\n }\n case OpCodes.OP_INTERRUPT: {\n output.push(Either.right(reducer.interruptCase(context, cause.fiberId)))\n break\n }\n case OpCodes.OP_SEQUENTIAL: {\n input.push(cause.right)\n input.push(cause.left)\n output.push(Either.left({ _tag: OP_SEQUENTIAL_CASE }))\n break\n }\n case OpCodes.OP_PARALLEL: {\n input.push(cause.right)\n input.push(cause.left)\n output.push(Either.left({ _tag: OP_PARALLEL_CASE }))\n break\n }\n }\n }\n const accumulator: Array<Z> = []\n while (output.length > 0) {\n const either = output.pop()!\n switch (either._tag) {\n case \"Left\": {\n switch (either.left._tag) {\n case OP_SEQUENTIAL_CASE: {\n const left = accumulator.pop()!\n const right = accumulator.pop()!\n const value = reducer.sequentialCase(context, left, right)\n accumulator.push(value)\n break\n }\n case OP_PARALLEL_CASE: {\n const left = accumulator.pop()!\n const right = accumulator.pop()!\n const value = reducer.parallelCase(context, left, right)\n accumulator.push(value)\n break\n }\n }\n break\n }\n case \"Right\": {\n accumulator.push(either.right)\n break\n }\n }\n }\n if (accumulator.length === 0) {\n throw new Error(\n \"BUG: Cause.reduceWithContext - please report an issue at https://github.com/Effect-TS/effect/issues\"\n )\n }\n return accumulator.pop()!\n})\n\n// -----------------------------------------------------------------------------\n// Pretty Printing\n// -----------------------------------------------------------------------------\n\n/** @internal */\nexport const pretty = <E>(cause: Cause.Cause<E>, options?: {\n readonly renderErrorCause?: boolean | undefined\n}): string => {\n if (isInterruptedOnly(cause)) {\n return \"All fibers interrupted without errors.\"\n }\n return prettyErrors<E>(cause).map(function(e) {\n if (options?.renderErrorCause !== true || e.cause === undefined) {\n return e.stack\n }\n return `${e.stack} {\\n${renderErrorCause(e.cause as PrettyError, \" \")}\\n}`\n }).join(\"\\n\")\n}\n\nconst renderErrorCause = (cause: PrettyError, prefix: string) => {\n const lines = cause.stack!.split(\"\\n\")\n let stack = `${prefix}[cause]: ${lines[0]}`\n for (let i = 1, len = lines.length; i < len; i++) {\n stack += `\\n${prefix}${lines[i]}`\n }\n if (cause.cause) {\n stack += ` {\\n${renderErrorCause(cause.cause as PrettyError, `${prefix} `)}\\n${prefix}}`\n }\n return stack\n}\n\nclass PrettyError extends globalThis.Error implements Cause.PrettyError {\n span: undefined | Span = undefined\n constructor(originalError: unknown) {\n const originalErrorIsObject = typeof originalError === \"object\" && originalError !== null\n const prevLimit = Error.stackTraceLimit\n Error.stackTraceLimit = 1\n super(\n prettyErrorMessage(originalError),\n originalErrorIsObject && \"cause\" in originalError && typeof originalError.cause !== \"undefined\"\n ? { cause: new PrettyError(originalError.cause) }\n : undefined\n )\n if (this.message === \"\") {\n this.message = \"An error has occurred\"\n }\n Error.stackTraceLimit = prevLimit\n this.name = originalError instanceof Error ? originalError.name : \"Error\"\n if (originalErrorIsObject) {\n if (spanSymbol in originalError) {\n this.span = originalError[spanSymbol] as Span\n }\n Object.keys(originalError).forEach((key) => {\n if (!(key in this)) {\n // @ts-expect-error\n this[key] = originalError[key]\n }\n })\n }\n this.stack = prettyErrorStack(\n `${this.name}: ${this.message}`,\n originalError instanceof Error && originalError.stack\n ? originalError.stack\n : \"\",\n this.span\n )\n }\n}\n\n/**\n * A utility function for generating human-readable error messages from a generic error of type `unknown`.\n *\n * Rules:\n *\n * 1) If the input `u` is already a string, it's considered a message.\n * 2) If `u` is an Error instance with a message defined, it uses the message.\n * 3) If `u` has a user-defined `toString()` method, it uses that method.\n * 4) Otherwise, it uses `Inspectable.stringifyCircular` to produce a string representation and uses it as the error message,\n * with \"Error\" added as a prefix.\n *\n * @internal\n */\nexport const prettyErrorMessage = (u: unknown): string => {\n // 1)\n if (typeof u === \"string\") {\n return u\n }\n // 2)\n if (typeof u === \"object\" && u !== null && u instanceof Error) {\n return u.message\n }\n // 3)\n try {\n if (\n hasProperty(u, \"toString\") &&\n isFunction(u[\"toString\"]) &&\n u[\"toString\"] !== Object.prototype.toString &&\n u[\"toString\"] !== globalThis.Array.prototype.toString\n ) {\n return u[\"toString\"]()\n }\n } catch {\n // something's off, rollback to json\n }\n // 4)\n return stringifyCircular(u)\n}\n\nconst locationRegex = /\\((.*)\\)/g\n\n/** @internal */\nexport const spanToTrace = globalValue(\"effect/Tracer/spanToTrace\", () => new WeakMap())\n\nconst prettyErrorStack = (message: string, stack: string, span?: Span | undefined): string => {\n const out: Array<string> = [message]\n const lines = stack.startsWith(message) ? stack.slice(message.length).split(\"\\n\") : stack.split(\"\\n\")\n\n for (let i = 1; i < lines.length; i++) {\n if (lines[i].includes(\"Generator.next\")) {\n break\n }\n if (lines[i].includes(\"effect_internal_function\")) {\n out.pop()\n break\n }\n out.push(\n lines[i]\n .replace(/at .*effect_instruction_i.*\\((.*)\\)/, \"at $1\")\n .replace(/EffectPrimitive\\.\\w+/, \"<anonymous>\")\n )\n }\n\n if (span) {\n let current: Span | AnySpan | undefined = span\n let i = 0\n while (current && current._tag === \"Span\" && i < 10) {\n const stackFn = spanToTrace.get(current)\n if (typeof stackFn === \"function\") {\n const stack = stackFn()\n if (typeof stack === \"string\") {\n const locationMatchAll = stack.matchAll(locationRegex)\n let match = false\n for (const [, location] of locationMatchAll) {\n match = true\n out.push(` at ${current.name} (${location})`)\n }\n if (!match) {\n out.push(` at ${current.name} (${stack.replace(/^at /, \"\")})`)\n }\n } else {\n out.push(` at ${current.name}`)\n }\n } else {\n out.push(` at ${current.name}`)\n }\n current = Option.getOrUndefined(current.parent)\n i++\n }\n }\n\n return out.join(\"\\n\")\n}\n\nconst spanSymbol = Symbol.for(\"effect/SpanAnnotation\")\n\n/** @internal */\nexport const prettyErrors = <E>(cause: Cause.Cause<E>): Array<PrettyError> =>\n reduceWithContext(cause, void 0, {\n emptyCase: (): Array<PrettyError> => [],\n dieCase: (_, unknownError) => {\n return [new PrettyError(unknownError)]\n },\n failCase: (_, error) => {\n return [new PrettyError(error)]\n },\n interruptCase: () => [],\n parallelCase: (_, l, r) => [...l, ...r],\n sequentialCase: (_, l, r) => [...l, ...r]\n })\n","/** @internal */\nexport class SingleShotGen<T, A> implements Generator<T, A> {\n called = false\n\n constructor(readonly self: T) {\n }\n\n next(a: A): IteratorResult<T, A> {\n return this.called ?\n ({\n value: a,\n done: true\n }) :\n (this.called = true,\n ({\n value: this.self,\n done: false\n }))\n }\n\n return(a: A): IteratorResult<T, A> {\n return ({\n value: a,\n done: true\n })\n }\n\n throw(e: unknown): IteratorResult<T, A> {\n throw e\n }\n\n [Symbol.iterator](): Generator<T, A> {\n return new SingleShotGen<T, A>(this.self)\n }\n}\n","import * as Arr from \"../Array.js\"\nimport type * as Cause from \"../Cause.js\"\nimport * as Chunk from \"../Chunk.js\"\nimport * as Context from \"../Context.js\"\nimport type * as Deferred from \"../Deferred.js\"\nimport type * as Differ from \"../Differ.js\"\nimport * as Duration from \"../Duration.js\"\nimport type * as Effect from \"../Effect.js\"\nimport * as Either from \"../Either.js\"\nimport * as Equal from \"../Equal.js\"\nimport type * as ExecutionStrategy from \"../ExecutionStrategy.js\"\nimport type * as Exit from \"../Exit.js\"\nimport type * as Fiber from \"../Fiber.js\"\nimport * as FiberId from \"../FiberId.js\"\nimport type * as FiberRef from \"../FiberRef.js\"\nimport type * as FiberStatus from \"../FiberStatus.js\"\nimport type { LazyArg } from \"../Function.js\"\nimport { dual, identity, pipe } from \"../Function.js\"\nimport { globalValue } from \"../GlobalValue.js\"\nimport * as Hash from \"../Hash.js\"\nimport * as HashMap from \"../HashMap.js\"\nimport type * as HashSet from \"../HashSet.js\"\nimport { format, NodeInspectSymbol, toJSON } from \"../Inspectable.js\"\nimport * as List from \"../List.js\"\nimport type * as LogLevel from \"../LogLevel.js\"\nimport type * as LogSpan from \"../LogSpan.js\"\nimport type * as MetricLabel from \"../MetricLabel.js\"\nimport * as MutableRef from \"../MutableRef.js\"\nimport * as Option from \"../Option.js\"\nimport { pipeArguments } from \"../Pipeable.js\"\nimport { hasProperty, isObject, isPromiseLike, type Predicate, type Refinement } from \"../Predicate.js\"\nimport type * as Request from \"../Request.js\"\nimport type * as BlockedRequests from \"../RequestBlock.js\"\nimport type * as RequestResolver from \"../RequestResolver.js\"\nimport type * as RuntimeFlags from \"../RuntimeFlags.js\"\nimport * as RuntimeFlagsPatch from \"../RuntimeFlagsPatch.js\"\nimport type * as Scope from \"../Scope.js\"\nimport type * as Tracer from \"../Tracer.js\"\nimport type { NoInfer, NotFunction } from \"../Types.js\"\nimport { internalCall, YieldWrap } from \"../Utils.js\"\nimport * as blockedRequests_ from \"./blockedRequests.js\"\nimport * as internalCause from \"./cause.js\"\nimport * as deferred from \"./deferred.js\"\nimport * as internalDiffer from \"./differ.js\"\nimport { CommitPrototype, effectVariance, StructuralCommitPrototype } from \"./effectable.js\"\nimport { getBugErrorMessage } from \"./errors.js\"\nimport type * as FiberRuntime from \"./fiberRuntime.js\"\nimport type * as fiberScope from \"./fiberScope.js\"\nimport * as DeferredOpCodes from \"./opCodes/deferred.js\"\nimport * as OpCodes from \"./opCodes/effect.js\"\nimport * as runtimeFlags_ from \"./runtimeFlags.js\"\nimport { SingleShotGen } from \"./singleShotGen.js\"\n\n// -----------------------------------------------------------------------------\n// Effect\n// -----------------------------------------------------------------------------\n\n/**\n * @internal\n */\nexport const blocked = <A, E>(\n blockedRequests: BlockedRequests.RequestBlock,\n _continue: Effect.Effect<A, E>\n): Effect.Blocked<A, E> => {\n const effect = new EffectPrimitive(\"Blocked\") as any\n effect.effect_instruction_i0 = blockedRequests\n effect.effect_instruction_i1 = _continue\n return effect\n}\n\n/**\n * @internal\n */\nexport const runRequestBlock = (\n blockedRequests: BlockedRequests.RequestBlock\n): Effect.Effect<void> => {\n const effect = new EffectPrimitive(\"RunBlocked\") as any\n effect.effect_instruction_i0 = blockedRequests\n return effect\n}\n\n/** @internal */\nexport const EffectTypeId: Effect.EffectTypeId = Symbol.for(\"effect/Effect\") as Effect.EffectTypeId\n\n/** @internal */\nexport type Primitive =\n | Async\n | Commit\n | Failure\n | OnFailure\n | OnSuccess\n | OnStep\n | OnSuccessAndFailure\n | Success\n | Sync\n | UpdateRuntimeFlags\n | While\n | FromIterator\n | WithRuntime\n | Yield\n | OpTag\n | Blocked\n | RunBlocked\n | Either.Either<any, any>\n | Option.Option<any>\n\n/** @internal */\nexport type Continuation =\n | OnSuccess\n | OnStep\n | OnSuccessAndFailure\n | OnFailure\n | While\n | FromIterator\n | RevertFlags\n\n/** @internal */\nexport class RevertFlags {\n readonly _op = OpCodes.OP_REVERT_FLAGS\n constructor(\n readonly patch: RuntimeFlagsPatch.RuntimeFlagsPatch,\n readonly op: Primitive & { _op: OpCodes.OP_UPDATE_RUNTIME_FLAGS }\n ) {\n }\n}\n\nclass EffectPrimitive {\n public effect_instruction_i0 = undefined\n public effect_instruction_i1 = undefined\n public effect_instruction_i2 = undefined\n public trace = undefined;\n [EffectTypeId] = effectVariance\n constructor(readonly _op: Primitive[\"_op\"]) {}\n [Equal.symbol](this: {}, that: unknown) {\n return this === that\n }\n [Hash.symbol](this: {}) {\n return Hash.cached(this, Hash.random(this))\n }\n pipe() {\n return pipeArguments(this, arguments)\n }\n toJSON() {\n return {\n _id: \"Effect\",\n _op: this._op,\n effect_instruction_i0: toJSON(this.effect_instruction_i0),\n effect_instruction_i1: toJSON(this.effect_instruction_i1),\n effect_instruction_i2: toJSON(this.effect_instruction_i2)\n }\n }\n toString() {\n return format(this.toJSON())\n }\n [NodeInspectSymbol]() {\n return this.toJSON()\n }\n [Symbol.iterator]() {\n return new SingleShotGen(new YieldWrap(this))\n }\n}\n\n/** @internal */\nclass EffectPrimitiveFailure {\n public effect_instruction_i0 = undefined\n public effect_instruction_i1 = undefined\n public effect_instruction_i2 = undefined\n public trace = undefined;\n [EffectTypeId] = effectVariance\n constructor(readonly _op: Primitive[\"_op\"]) {\n // @ts-expect-error\n this._tag = _op\n }\n [Equal.symbol](this: {}, that: unknown) {\n return exitIsExit(that) && that._op === \"Failure\" &&\n // @ts-expect-error\n Equal.equals(this.effect_instruction_i0, that.effect_instruction_i0)\n }\n [Hash.symbol](this: {}) {\n return pipe(\n // @ts-expect-error\n Hash.string(this._tag),\n // @ts-expect-error\n Hash.combine(Hash.hash(this.effect_instruction_i0)),\n Hash.cached(this)\n )\n }\n get cause() {\n return this.effect_instruction_i0\n }\n pipe() {\n return pipeArguments(this, arguments)\n }\n toJSON() {\n return {\n _id: \"Exit\",\n _tag: this._op,\n cause: (this.cause as any).toJSON()\n }\n }\n toString() {\n return format(this.toJSON())\n }\n [NodeInspectSymbol]() {\n return this.toJSON()\n }\n [Symbol.iterator]() {\n return new SingleShotGen(new YieldWrap(this))\n }\n}\n\n/** @internal */\nclass EffectPrimitiveSuccess {\n public effect_instruction_i0 = undefined\n public effect_instruction_i1 = undefined\n public effect_instruction_i2 = undefined\n public trace = undefined;\n [EffectTypeId] = effectVariance\n constructor(readonly _op: Primitive[\"_op\"]) {\n // @ts-expect-error\n this._tag = _op\n }\n [Equal.symbol](this: {}, that: unknown) {\n return exitIsExit(that) && that._op === \"Success\" &&\n // @ts-expect-error\n Equal.equals(this.effect_instruction_i0, that.effect_instruction_i0)\n }\n [Hash.symbol](this: {}) {\n return pipe(\n // @ts-expect-error\n Hash.string(this._tag),\n // @ts-expect-error\n Hash.combine(Hash.hash(this.effect_instruction_i0)),\n Hash.cached(this)\n )\n }\n get value() {\n return this.effect_instruction_i0\n }\n pipe() {\n return pipeArguments(this, arguments)\n }\n toJSON() {\n return {\n _id: \"Exit\",\n _tag: this._op,\n value: toJSON(this.value)\n }\n }\n toString() {\n return format(this.toJSON())\n }\n [NodeInspectSymbol]() {\n return this.toJSON()\n }\n [Symbol.iterator]() {\n return new SingleShotGen(new YieldWrap(this))\n }\n}\n\n/** @internal */\nexport type Op<Tag extends string, Body = {}> = Effect.Effect<never> & Body & {\n readonly _op: Tag\n}\n\n/** @internal */\nexport interface Async extends\n Op<OpCodes.OP_ASYNC, {\n effect_instruction_i0(resume: (effect: Primitive) => void): void\n readonly effect_instruction_i1: FiberId.FiberId\n }>\n{}\n\n/** @internal */\nexport interface Blocked<out E = any, out A = any> extends\n Op<\"Blocked\", {\n readonly effect_instruction_i0: BlockedRequests.RequestBlock\n readonly effect_instruction_i1: Effect.Effect<A, E>\n }>\n{}\n\n/** @internal */\nexport interface RunBlocked extends\n Op<\"RunBlocked\", {\n readonly effect_instruction_i0: BlockedRequests.RequestBlock\n }>\n{}\n\n/** @internal */\nexport interface Failure extends\n Op<OpCodes.OP_FAILURE, {\n readonly effect_instruction_i0: Cause.Cause<unknown>\n }>\n{}\n\n/** @internal */\nexport interface OpTag extends Op<OpCodes.OP_TAG, {}> {}\n\n/** @internal */\nexport interface Commit extends\n Op<OpCodes.OP_COMMIT, {\n commit(): Effect.Effect<unknown, unknown, unknown>\n }>\n{}\n\n/** @internal */\nexport interface OnFailure extends\n Op<OpCodes.OP_ON_FAILURE, {\n readonly effect_instruction_i0: Primitive\n effect_instruction_i1(a: Cause.Cause<unknown>): Primitive\n }>\n{}\n\n/** @internal */\nexport interface OnSuccess extends\n Op<OpCodes.OP_ON_SUCCESS, {\n readonly effect_instruction_i0: Primitive\n effect_instruction_i1(a: unknown): Primitive\n }>\n{}\n\n/** @internal */\nexport interface OnStep extends Op<\"OnStep\", { readonly effect_instruction_i0: Primitive }> {}\n\n/** @internal */\nexport interface OnSuccessAndFailure extends\n Op<OpCodes.OP_ON_SUCCESS_AND_FAILURE, {\n readonly effect_instruction_i0: Primitive\n effect_instruction_i1(a: Cause.Cause<unknown>): Primitive\n effect_instruction_i2(a: unknown): Primitive\n }>\n{}\n\n/** @internal */\nexport interface Success extends\n Op<OpCodes.OP_SUCCESS, {\n readonly effect_instruction_i0: unknown\n }>\n{}\n\n/** @internal */\nexport interface Sync extends\n Op<OpCodes.OP_SYNC, {\n effect_instruction_i0(): unknown\n }>\n{}\n\n/** @internal */\nexport interface UpdateRuntimeFlags extends\n Op<OpCodes.OP_UPDATE_RUNTIME_FLAGS, {\n readonly effect_instruction_i0: RuntimeFlagsPatch.RuntimeFlagsPatch\n readonly effect_instruction_i1?: (oldRuntimeFlags: RuntimeFlags.RuntimeFlags) => Primitive\n }>\n{}\n\n/** @internal */\nexport interface While extends\n Op<OpCodes.OP_WHILE, {\n effect_instruction_i0(): boolean\n effect_instruction_i1(): Primitive\n effect_instruction_i2(a: unknown): void\n }>\n{}\n\n/** @internal */\nexport interface FromIterator extends\n Op<OpCodes.OP_ITERATOR, {\n effect_instruction_i0: Iterator<YieldWrap<Primitive>, any>\n }>\n{}\n\n/** @internal */\nexport interface WithRuntime extends\n Op<OpCodes.OP_WITH_RUNTIME, {\n effect_instruction_i0(fiber: FiberRuntime.FiberRuntime<unknown, unknown>, status: FiberStatus.Running): Primitive\n }>\n{}\n\n/** @internal */\nexport interface Yield extends Op<OpCodes.OP_YIELD> {}\n\n/** @internal */\nexport const isEffect = (u: unknown): u is Effect.Effect<unknown, unknown, unknown> => hasProperty(u, EffectTypeId)\n\n/* @internal */\nexport const withFiberRuntime = <A, E = never, R = never>(\n withRuntime: (fiber: FiberRuntime.FiberRuntime<A, E>, status: FiberStatus.Running) => Effect.Effect<A, E, R>\n): Effect.Effect<A, E, R> => {\n const effect = new EffectPrimitive(OpCodes.OP_WITH_RUNTIME) as any\n effect.effect_instruction_i0 = withRuntime\n return effect\n}\n\n/* @internal */\nexport const acquireUseRelease: {\n <A2, E2, R2, A, X, R3>(\n use: (a: A) => Effect.Effect<A2, E2, R2>,\n release: (a: A, exit: Exit.Exit<A2, E2>) => Effect.Effect<X, never, R3>\n ): <E, R>(acquire: Effect.Effect<A, E, R>) => Effect.Effect<A2, E2 | E, R2 | R3 | R>\n <A, E, R, A2, E2, R2, X, R3>(\n acquire: Effect.Effect<A, E, R>,\n use: (a: A) => Effect.Effect<A2, E2, R2>,\n release: (a: A, exit: Exit.Exit<A2, E2>) => Effect.Effect<X, never, R3>\n ): Effect.Effect<A2, E | E2, R | R2 | R3>\n} = dual(3, <A, E, R, A2, E2, R2, X, R3>(\n acquire: Effect.Effect<A, E, R>,\n use: (a: A) => Effect.Effect<A2, E2, R2>,\n release: (a: A, exit: Exit.Exit<A2, E2>) => Effect.Effect<X, never, R3>\n): Effect.Effect<A2, E | E2, R | R2 | R3> =>\n uninterruptibleMask((restore) =>\n flatMap(\n acquire,\n (a) =>\n flatMap(exit(suspend(() => restore(use(a)))), (exit): Effect.Effect<A2, E | E2, R | R2 | R3> => {\n return suspend(() => release(a, exit)).pipe(\n matchCauseEffect({\n onFailure: (cause) => {\n switch (exit._tag) {\n case OpCodes.OP_FAILURE:\n return failCause(internalCause.sequential(exit.effect_instruction_i0, cause))\n case OpCodes.OP_SUCCESS:\n return failCause(cause)\n }\n },\n onSuccess: () => exit\n })\n )\n })\n )\n ))\n\n/* @internal */\nexport const as: {\n <B>(value: B): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B, E, R>\n <A, E, R, B>(self: Effect.Effect<A, E, R>, value: B): Effect.Effect<B, E, R>\n} = dual(\n 2,\n <A, E, R, B>(self: Effect.Effect<A, E, R>, value: B): Effect.Effect<B, E, R> => flatMap(self, () => succeed(value))\n)\n\n/* @internal */\nexport const asVoid = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<void, E, R> => as(self, void 0)\n\n/* @internal */\nexport const custom: {\n <X, A, E, R>(i0: X, body: (this: { effect_instruction_i0: X }) => Effect.Effect<A, E, R>): Effect.Effect<A, E, R>\n <X, Y, A, E, R>(\n i0: X,\n i1: Y,\n body: (this: { effect_instruction_i0: X; effect_instruction_i1: Y }) => Effect.Effect<A, E, R>\n ): Effect.Effect<A, E, R>\n <X, Y, Z, A, E, R>(\n i0: X,\n i1: Y,\n i2: Z,\n body: (\n this: { effect_instruction_i0: X; effect_instruction_i1: Y; effect_instruction_i2: Z }\n ) => Effect.Effect<A, E, R>\n ): Effect.Effect<A, E, R>\n} = function() {\n const wrapper = new EffectPrimitive(OpCodes.OP_COMMIT) as any\n switch (arguments.length) {\n case 2: {\n wrapper.effect_instruction_i0 = arguments[0]\n wrapper.commit = arguments[1]\n break\n }\n case 3: {\n wrapper.effect_instruction_i0 = arguments[0]\n wrapper.effect_instruction_i1 = arguments[1]\n wrapper.commit = arguments[2]\n break\n }\n case 4: {\n wrapper.effect_instruction_i0 = arguments[0]\n wrapper.effect_instruction_i1 = arguments[1]\n wrapper.effect_instruction_i2 = arguments[2]\n wrapper.commit = arguments[3]\n break\n }\n default: {\n throw new Error(getBugErrorMessage(\"you're not supposed to end up here\"))\n }\n }\n return wrapper\n}\n\n/* @internal */\nexport const unsafeAsync = <A, E = never, R = never>(\n register: (\n callback: (_: Effect.Effect<A, E, R>) => void\n ) => void | Effect.Effect<void, never, R>,\n blockingOn: FiberId.FiberId = FiberId.none\n): Effect.Effect<A, E, R> => {\n const effect = new EffectPrimitive(OpCodes.OP_ASYNC) as any\n let cancelerRef: Effect.Effect<void, never, R> | void = undefined\n effect.effect_instruction_i0 = (resume: (_: Effect.Effect<A, E, R>) => void) => {\n cancelerRef = register(resume)\n }\n effect.effect_instruction_i1 = blockingOn\n return onInterrupt(effect, (_) => isEffect(cancelerRef) ? cancelerRef : void_)\n}\n\n/* @internal */\nexport const asyncInterrupt = <A, E = never, R = never>(\n register: (\n callback: (_: Effect.Effect<A, E, R>) => void\n ) => void | Effect.Effect<void, never, R>,\n blockingOn: FiberId.FiberId = FiberId.none\n): Effect.Effect<A, E, R> => suspend(() => unsafeAsync(register, blockingOn))\n\nconst async_ = <A, E = never, R = never>(\n resume: (\n callback: (_: Effect.Effect<A, E, R>) => void,\n signal: AbortSignal\n ) => void | Effect.Effect<void, never, R>,\n blockingOn: FiberId.FiberId = FiberId.none\n): Effect.Effect<A, E, R> => {\n return custom(resume, function() {\n let backingResume: ((_: Effect.Effect<A, E, R>) => void) | undefined = undefined\n let pendingEffect: Effect.Effect<A, E, R> | undefined = undefined\n function proxyResume(effect: Effect.Effect<A, E, R>) {\n if (backingResume) {\n backingResume(effect)\n } else if (pendingEffect === undefined) {\n pendingEffect = effect\n }\n }\n const effect = new EffectPrimitive(OpCodes.OP_ASYNC) as any\n effect.effect_instruction_i0 = (resume: (_: Effect.Effect<A, E, R>) => void) => {\n backingResume = resume\n if (pendingEffect) {\n resume(pendingEffect)\n }\n }\n effect.effect_instruction_i1 = blockingOn\n let cancelerRef: Effect.Effect<void, never, R> | void = undefined\n let controllerRef: AbortController | void = undefined\n if (this.effect_instruction_i0.length !== 1) {\n controllerRef = new AbortController()\n cancelerRef = internalCall(() => this.effect_instruction_i0(proxyResume, controllerRef!.signal))\n } else {\n cancelerRef = internalCall(() => (this.effect_instruction_i0 as any)(proxyResume))\n }\n return (cancelerRef || controllerRef) ?\n onInterrupt(effect, (_) => {\n if (controllerRef) {\n controllerRef.abort()\n }\n return cancelerRef ?? void_\n }) :\n effect\n })\n}\nexport {\n /** @internal */\n async_ as async\n}\n\n/* @internal */\nexport const catchAllCause = dual<\n <E, A2, E2, R2>(\n f: (cause: Cause.Cause<E>) => Effect.Effect<A2, E2, R2>\n ) => <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A2 | A, E2, R2 | R>,\n <A, E, R, A2, E2, R2>(\n self: Effect.Effect<A, E, R>,\n f: (cause: Cause.Cause<E>) => Effect.Effect<A2, E2, R2>\n ) => Effect.Effect<A2 | A, E2, R2 | R>\n>(2, (self, f) => {\n const effect = new EffectPrimitive(OpCodes.OP_ON_FAILURE) as any\n effect.effect_instruction_i0 = self\n effect.effect_instruction_i1 = f\n return effect\n})\n\n/* @internal */\nexport const catchAll: {\n <E, A2, E2, R2>(\n f: (e: E) => Effect.Effect<A2, E2, R2>\n ): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A2 | A, E2, R2 | R>\n <A, E, R, A2, E2, R2>(\n self: Effect.Effect<A, E, R>,\n f: (e: E) => Effect.Effect<A2, E2, R2>\n ): Effect.Effect<A2 | A, E2, R2 | R>\n} = dual(\n 2,\n <A, E, R, A2, E2, R2>(\n self: Effect.Effect<A, E, R>,\n f: (e: E) => Effect.Effect<A2, E2, R2>\n ): Effect.Effect<A2 | A, E2, R2 | R> => matchEffect(self, { onFailure: f, onSuccess: succeed })\n)\n\n/* @internal */\nexport const catchIf: {\n <E, EB extends E, A2, E2, R2>(\n refinement: Refinement<NoInfer<E>, EB>,\n f: (e: EB) => Effect.Effect<A2, E2, R2>\n ): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A2 | A, E2 | Exclude<E, EB>, R2 | R>\n <E, A2, E2, R2>(\n predicate: Predicate<NoInfer<E>>,\n f: (e: NoInfer<E>) => Effect.Effect<A2, E2, R2>\n ): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A2 | A, E | E2, R2 | R>\n <A, E, R, EB extends E, A2, E2, R2>(\n self: Effect.Effect<A, E, R>,\n refinement: Refinement<E, EB>,\n f: (e: EB) => Effect.Effect<A2, E2, R2>\n ): Effect.Effect<A2 | A, E2 | Exclude<E, EB>, R2 | R>\n <A, E, R, A2, E2, R2>(\n self: Effect.Effect<A, E, R>,\n predicate: Predicate<E>,\n f: (e: E) => Effect.Effect<A2, E2, R2>\n ): Effect.Effect<A | A2, E | E2, R | R2>\n} = dual(3, <A, E, R, A2, E2, R2>(\n self: Effect.Effect<A, E, R>,\n predicate: Predicate<E>,\n f: (e: E) => Effect.Effect<A2, E2, R2>\n): Effect.Effect<A | A2, E | E2, R | R2> =>\n catchAllCause(self, (cause): Effect.Effect<A | A2, E | E2, R | R2> => {\n const either = internalCause.failureOrCause(cause)\n switch (either._tag) {\n case \"Left\":\n return predicate(either.left) ? f(either.left) : failCause(cause)\n case \"Right\":\n return failCause(either.right)\n }\n }))\n\n/* @internal */\nexport const catchSome = dual<\n <E, A2, E2, R2>(\n pf: (e: NoInfer<E>) => Option.Option<Effect.Effect<A2, E2, R2>>\n ) => <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A2 | A, E | E2, R2 | R>,\n <A, E, R, A2, E2, R2>(\n self: Effect.Effect<A, E, R>,\n pf: (e: NoInfer<E>) => Option.Option<Effect.Effect<A2, E2, R2>>\n ) => Effect.Effect<A2 | A, E | E2, R2 | R>\n>(2, <A, E, R, A2, E2, R2>(\n self: Effect.Effect<A, E, R>,\n pf: (e: NoInfer<E>) => Option.Option<Effect.Effect<A2, E2, R2>>\n) =>\n catchAllCause(self, (cause): Effect.Effect<A2 | A, E | E2, R2 | R> => {\n const either = internalCause.failureOrCause(cause)\n switch (either._tag) {\n case \"Left\":\n return pipe(pf(either.left), Option.getOrElse(() => failCause(cause)))\n case \"Right\":\n return failCause(either.right)\n }\n }))\n\n/* @internal */\nexport const checkInterruptible = <A, E, R>(\n f: (isInterruptible: boolean) => Effect.Effect<A, E, R>\n): Effect.Effect<A, E, R> => withFiberRuntime((_, status) => f(runtimeFlags_.interruption(status.runtimeFlags)))\n\nconst spanSymbol = Symbol.for(\"effect/SpanAnnotation\")\nconst originalSymbol = Symbol.for(\"effect/OriginalAnnotation\")\n\n/* @internal */\nexport const originalInstance = <E>(obj: E): E => {\n if (hasProperty(obj, originalSymbol)) {\n // @ts-expect-error\n return obj[originalSymbol]\n }\n return obj\n}\n\n/* @internal */\nexport const capture = <E>(obj: E & object, span: Option.Option<Tracer.Span>): E => {\n if (Option.isSome(span)) {\n return new Proxy(obj, {\n has(target, p) {\n return p === spanSymbol || p === originalSymbol || p in target\n },\n get(target, p) {\n if (p === spanSymbol) {\n return span.value\n }\n if (p === originalSymbol) {\n return obj\n }\n // @ts-expect-error\n return target[p]\n }\n })\n }\n return obj\n}\n\n/* @internal */\nexport const die = (defect: unknown): Effect.Effect<never> =>\n isObject(defect) && !(spanSymbol in defect) ?\n withFiberRuntime((fiber) => failCause(internalCause.die(capture(defect, currentSpanFromFiber(fiber)))))\n : failCause(internalCause.die(defect))\n\n/* @internal */\nexport const dieMessage = (message: string): Effect.Effect<never> =>\n failCauseSync(() => internalCause.die(new RuntimeException(message)))\n\n/* @internal */\nexport const dieSync = (evaluate: LazyArg<unknown>): Effect.Effect<never> => flatMap(sync(evaluate), die)\n\n/* @internal */\nexport const either = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<Either.Either<A, E>, never, R> =>\n matchEffect(self, {\n onFailure: (e) => succeed(Either.left(e)),\n onSuccess: (a) => succeed(Either.right(a))\n })\n\n/* @internal */\nexport const exit = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<Exit.Exit<A, E>, never, R> =>\n matchCause(self, {\n onFailure: exitFailCause,\n onSuccess: exitSucceed\n })\n\n/* @internal */\nexport const fail = <E>(error: E): Effect.Effect<never, E> =>\n isObject(error) && !(spanSymbol in error) ?\n withFiberRuntime((fiber) => failCause(internalCause.fail(capture(error, currentSpanFromFiber(fiber)))))\n : failCause(internalCause.fail(error))\n\n/* @internal */\nexport const failSync = <E>(evaluate: LazyArg<E>): Effect.Effect<never, E> => flatMap(sync(evaluate), fail)\n\n/* @internal */\nexport const failCause = <E>(cause: Cause.Cause<E>): Effect.Effect<never, E> => {\n const effect = new EffectPrimitiveFailure(OpCodes.OP_FAILURE) as any\n effect.effect_instruction_i0 = cause\n return effect\n}\n\n/* @internal */\nexport const failCauseSync = <E>(\n evaluate: LazyArg<Cause.Cause<E>>\n): Effect.Effect<never, E> => flatMap(sync(evaluate), failCause)\n\n/* @internal */\nexport const fiberId: Effect.Effect<FiberId.FiberId> = withFiberRuntime((state) => succeed(state.id()))\n\n/* @internal */\nexport const fiberIdWith = <A, E, R>(\n f: (descriptor: FiberId.Runtime) => Effect.Effect<A, E, R>\n): Effect.Effect<A, E, R> => withFiberRuntime((state) => f(state.id()))\n\n/* @internal */\nexport const flatMap = dual<\n <A, B, E1, R1>(\n f: (a: A) => Effect.Effect<B, E1, R1>\n ) => <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B, E1 | E, R1 | R>,\n <A, E, R, B, E1, R1>(\n self: Effect.Effect<A, E, R>,\n f: (a: A) => Effect.Effect<B, E1, R1>\n ) => Effect.Effect<B, E | E1, R | R1>\n>(\n 2,\n (self, f) => {\n const effect = new EffectPrimitive(OpCodes.OP_ON_SUCCESS) as any\n effect.effect_instruction_i0 = self\n effect.effect_instruction_i1 = f\n return effect\n }\n)\n\n/* @internal */\nexport const andThen: {\n <A, X>(\n f: (a: NoInfer<A>) => X\n ): <E, R>(\n self: Effect.Effect<A, E, R>\n ) => [X] extends [Effect.Effect<infer A1, infer E1, infer R1>] ? Effect.Effect<A1, E | E1, R | R1>\n : [X] extends [PromiseLike<infer A1>] ? Effect.Effect<A1, E | Cause.UnknownException, R>\n : Effect.Effect<X, E, R>\n <X>(\n f: NotFunction<X>\n ): <A, E, R>(\n self: Effect.Effect<A, E, R>\n ) => [X] extends [Effect.Effect<infer A1, infer E1, infer R1>] ? Effect.Effect<A1, E | E1, R | R1>\n : [X] extends [PromiseLike<infer A1>] ? Effect.Effect<A1, E | Cause.UnknownException, R>\n : Effect.Effect<X, E, R>\n <A, E, R, X>(\n self: Effect.Effect<A, E, R>,\n f: (a: NoInfer<A>) => X\n ): [X] extends [Effect.Effect<infer A1, infer E1, infer R1>] ? Effect.Effect<A1, E | E1, R | R1>\n : [X] extends [PromiseLike<infer A1>] ? Effect.Effect<A1, E | Cause.UnknownException, R>\n : Effect.Effect<X, E, R>\n <A, E, R, X>(\n self: Effect.Effect<A, E, R>,\n f: NotFunction<X>\n ): [X] extends [Effect.Effect<infer A1, infer E1, infer R1>] ? Effect.Effect<A1, E | E1, R | R1>\n : [X] extends [PromiseLike<infer A1>] ? Effect.Effect<A1, E | Cause.UnknownException, R>\n : Effect.Effect<X, E, R>\n} = dual(2, (self, f) =>\n flatMap(self, (a) => {\n const b = typeof f === \"function\" ? (f as any)(a) : f\n if (isEffect(b)) {\n return b\n } else if (isPromiseLike(b)) {\n return unsafeAsync<any, Cause.UnknownException>((resume) => {\n b.then((a) => resume(succeed(a)), (e) => resume(fail(new UnknownException(e))))\n })\n }\n return succeed(b)\n }))\n\n/* @internal */\nexport const step = <A, E, R>(\n self: Effect.Effect<A, E, R>\n): Effect.Effect<Exit.Exit<A, E> | Effect.Blocked<A, E>, never, R> => {\n const effect = new EffectPrimitive(\"OnStep\") as any\n effect.effect_instruction_i0 = self\n return effect\n}\n\n/* @internal */\nexport const flatten = <A, E1, R1, E, R>(\n self: Effect.Effect<Effect.Effect<A, E1, R1>, E, R>\n): Effect.Effect<A, E | E1, R | R1> => flatMap(self, identity)\n\n/* @internal */\nexport const flip = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<E, A, R> =>\n matchEffect(self, { onFailure: succeed, onSuccess: fail })\n\n/* @internal */\nexport const matchCause: {\n <E, A2, A, A3>(\n options: {\n readonly onFailure: (cause: Cause.Cause<E>) => A2\n readonly onSuccess: (a: A) => A3\n }\n ): <R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A2 | A3, never, R>\n <A, E, R, A2, A3>(\n self: Effect.Effect<A, E, R>,\n options: {\n readonly onFailure: (cause: Cause.Cause<E>) => A2\n readonly onSuccess: (a: A) => A3\n }\n ): Effect.Effect<A2 | A3, never, R>\n} = dual(2, <A, E, R, A2, A3>(\n self: Effect.Effect<A, E, R>,\n options: {\n readonly onFailure: (cause: Cause.Cause<E>) => A2\n readonly onSuccess: (a: A) => A3\n }\n): Effect.Effect<A2 | A3, never, R> =>\n matchCauseEffect(self, {\n onFailure: (cause) => succeed(options.onFailure(cause)),\n onSuccess: (a) => succeed(options.onSuccess(a))\n }))\n\n/* @internal */\nexport const matchCauseEffect: {\n <E, A2, E2, R2, A, A3, E3, R3>(\n options: {\n readonly onFailure: (cause: Cause.Cause<E>) => Effect.Effect<A2, E2, R2>\n readonly onSuccess: (a: A) => Effect.Effect<A3, E3, R3>\n }\n ): <R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A2 | A3, E2 | E3, R2 | R3 | R>\n <A, E, R, A2, E2, R2, A3, E3, R3>(\n self: Effect.Effect<A, E, R>,\n options: {\n readonly onFailure: (cause: Cause.Cause<E>) => Effect.Effect<A2, E2, R2>\n readonly onSuccess: (a: A) => Effect.Effect<A3, E3, R3>\n }\n ): Effect.Effect<A2 | A3, E2 | E3, R2 | R3 | R>\n} = dual(2, <A, E, R, A2, E2, R2, A3, E3, R3>(\n self: Effect.Effect<A, E, R>,\n options: {\n readonly onFailure: (cause: Cause.Cause<E>) => Effect.Effect<A2, E2, R2>\n readonly onSuccess: (a: A) => Effect.Effect<A3, E3, R3>\n }\n): Effect.Effect<A2 | A3, E2 | E3, R2 | R3 | R> => {\n const effect = new EffectPrimitive(OpCodes.OP_ON_SUCCESS_AND_FAILURE) as any\n effect.effect_instruction_i0 = self\n effect.effect_instruction_i1 = options.onFailure\n effect.effect_instruction_i2 = options.onSuccess\n return effect\n})\n\n/* @internal */\nexport const matchEffect: {\n <E, A2, E2, R2, A, A3, E3, R3>(\n options: {\n readonly onFailure: (e: E) => Effect.Effect<A2, E2, R2>\n readonly onSuccess: (a: A) => Effect.Effect<A3, E3, R3>\n }\n ): <R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A2 | A3, E2 | E3, R2 | R3 | R>\n <A, E, R, A2, E2, R2, A3, E3, R3>(\n self: Effect.Effect<A, E, R>,\n options: {\n readonly onFailure: (e: E) => Effect.Effect<A2, E2, R2>\n readonly onSuccess: (a: A) => Effect.Effect<A3, E3, R3>\n }\n ): Effect.Effect<A2 | A3, E2 | E3, R2 | R3 | R>\n} = dual(2, <A, E, R, A2, E2, R2, A3, E3, R3>(\n self: Effect.Effect<A, E, R>,\n options: {\n readonly onFailure: (e: E) => Effect.Effect<A2, E2, R2>\n readonly onSuccess: (a: A) => Effect.Effect<A3, E3, R3>\n }\n): Effect.Effect<A2 | A3, E2 | E3, R2 | R3 | R> =>\n matchCauseEffect(self, {\n onFailure: (cause) => {\n const defects = internalCause.defects(cause)\n if (defects.length > 0) {\n return failCause(internalCause.electFailures(cause))\n }\n const failures = internalCause.failures(cause)\n if (failures.length > 0) {\n return options.onFailure(Chunk.unsafeHead(failures))\n }\n return failCause(cause as Cause.Cause<never>)\n },\n onSuccess: options.onSuccess\n }))\n\n/* @internal */\nexport const forEachSequential: {\n <A, B, E, R>(f: (a: A, i: number) => Effect.Effect<B, E, R>): (self: Iterable<A>) => Effect.Effect<Array<B>, E, R>\n <A, B, E, R>(self: Iterable<A>, f: (a: A, i: number) => Effect.Effect<B, E, R>): Effect.Effect<Array<B>, E, R>\n} = dual(\n 2,\n <A, B, E, R>(self: Iterable<A>, f: (a: A, i: number) => Effect.Effect<B, E, R>): Effect.Effect<Array<B>, E, R> =>\n suspend(() => {\n const arr = Arr.fromIterable(self)\n const ret = Arr.allocate<B>(arr.length)\n let i = 0\n return as(\n whileLoop({\n while: () => i < arr.length,\n body: () => f(arr[i], i),\n step: (b) => {\n ret[i++] = b\n }\n }),\n ret as Array<B>\n )\n })\n)\n\n/* @internal */\nexport const forEachSequentialDiscard: {\n <A, B, E, R>(f: (a: A, i: number) => Effect.Effect<B, E, R>): (self: Iterable<A>) => Effect.Effect<void, E, R>\n <A, B, E, R>(self: Iterable<A>, f: (a: A, i: number) => Effect.Effect<B, E, R>): Effect.Effect<void, E, R>\n} = dual(\n 2,\n <A, B, E, R>(self: Iterable<A>, f: (a: A, i: number) => Effect.Effect<B, E, R>): Effect.Effect<void, E, R> =>\n suspend(() => {\n const arr = Arr.fromIterable(self)\n let i = 0\n return whileLoop({\n while: () => i < arr.length,\n body: () => f(arr[i], i),\n step: () => {\n i++\n }\n })\n })\n)\n\n/* @internal */\nexport const if_ = dual<\n <A1, E1, R1, A2, E2, R2>(\n options: {\n readonly onTrue: LazyArg<Effect.Effect<A1, E1, R1>>\n readonly onFalse: LazyArg<Effect.Effect<A2, E2, R2>>\n }\n ) => <E = never, R = never>(\n self: Effect.Effect<boolean, E, R> | boolean\n ) => Effect.Effect<A1 | A2, E | E1 | E2, R | R1 | R2>,\n <A1, E1, R1, A2, E2, R2, E = never, R = never>(\n self: Effect.Effect<boolean, E, R> | boolean,\n options: {\n readonly onTrue: LazyArg<Effect.Effect<A1, E1, R1>>\n readonly onFalse: LazyArg<Effect.Effect<A2, E2, R2>>\n }\n ) => Effect.Effect<A1 | A2, E1 | E2 | E, R1 | R2 | R>\n>(\n (args) => typeof args[0] === \"boolean\" || isEffect(args[0]),\n <A1, E1, R1, A2, E2, R2, E = never, R = never>(\n self: Effect.Effect<boolean, E, R> | boolean,\n options: {\n readonly onTrue: LazyArg<Effect.Effect<A1, E1, R1>>\n readonly onFalse: LazyArg<Effect.Effect<A2, E2, R2>>\n }\n ): Effect.Effect<A1 | A2, E1 | E2 | E, R1 | R2 | R> =>\n isEffect(self)\n ? flatMap(self, (b): Effect.Effect<A1 | A2, E1 | E2, R1 | R2> => (b ? options.onTrue() : options.onFalse()))\n : self\n ? options.onTrue()\n : options.onFalse()\n)\n\n/* @internal */\nexport const interrupt: Effect.Effect<never> = flatMap(fiberId, (fiberId) => interruptWith(fiberId))\n\n/* @internal */\nexport const interruptWith = (fiberId: FiberId.FiberId): Effect.Effect<never> =>\n failCause(internalCause.interrupt(fiberId))\n\n/* @internal */\nexport const interruptible = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> => {\n const effect = new EffectPrimitive(OpCodes.OP_UPDATE_RUNTIME_FLAGS) as any\n effect.effect_instruction_i0 = RuntimeFlagsPatch.enable(runtimeFlags_.Interruption)\n effect.effect_instruction_i1 = () => self\n return effect\n}\n\n/* @internal */\nexport const interruptibleMask = <A, E, R>(\n f: (restore: <AX, EX, RX>(effect: Effect.Effect<AX, EX, RX>) => Effect.Effect<AX, EX, RX>) => Effect.Effect<A, E, R>\n): Effect.Effect<A, E, R> =>\n custom(f, function() {\n const effect = new EffectPrimitive(OpCodes.OP_UPDATE_RUNTIME_FLAGS) as any\n effect.effect_instruction_i0 = RuntimeFlagsPatch.enable(runtimeFlags_.Interruption)\n effect.effect_instruction_i1 = (oldFlags: RuntimeFlags.RuntimeFlags) =>\n runtimeFlags_.interruption(oldFlags)\n ? internalCall(() => this.effect_instruction_i0(interruptible))\n : internalCall(() => this.effect_instruction_i0(uninterruptible))\n return effect\n })\n\n/* @internal */\nexport const intoDeferred: {\n <A, E>(deferred: Deferred.Deferred<A, E>): <R>(self: Effect.Effect<A, E, R>) => Effect.Effect<boolean, never, R>\n <A, E, R>(self: Effect.Effect<A, E, R>, deferred: Deferred.Deferred<A, E>): Effect.Effect<boolean, never, R>\n} = dual(\n 2,\n <A, E, R>(self: Effect.Effect<A, E, R>, deferred: Deferred.Deferred<A, E>): Effect.Effect<boolean, never, R> =>\n uninterruptibleMask((restore) =>\n flatMap(\n exit(restore(self)),\n (exit) => deferredDone(deferred, exit)\n )\n )\n)\n\n/* @internal */\nexport const map: {\n <A, B>(f: (a: A) => B): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B, E, R>\n <A, E, R, B>(self: Effect.Effect<A, E, R>, f: (a: A) => B): Effect.Effect<B, E, R>\n} = dual(\n 2,\n <A, E, R, B>(self: Effect.Effect<A, E, R>, f: (a: A) => B): Effect.Effect<B, E, R> =>\n flatMap(self, (a) => sync(() => f(a)))\n)\n\n/* @internal */\nexport const mapBoth: {\n <E, E2, A, A2>(\n options: { readonly onFailure: (e: E) => E2; readonly onSuccess: (a: A) => A2 }\n ): <R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A2, E2, R>\n <A, E, R, E2, A2>(\n self: Effect.Effect<A, E, R>,\n options: { readonly onFailure: (e: E) => E2; readonly onSuccess: (a: A) => A2 }\n ): Effect.Effect<A2, E2, R>\n} = dual(2, <A, E, R, E2, A2>(\n self: Effect.Effect<A, E, R>,\n options: { readonly onFailure: (e: E) => E2; readonly onSuccess: (a: A) => A2 }\n): Effect.Effect<A2, E2, R> =>\n matchEffect(self, {\n onFailure: (e) => failSync(() => options.onFailure(e)),\n onSuccess: (a) => sync(() => options.onSuccess(a))\n }))\n\n/* @internal */\nexport const mapError: {\n <E, E2>(f: (e: E) => E2): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E2, R>\n <A, E, R, E2>(self: Effect.Effect<A, E, R>, f: (e: E) => E2): Effect.Effect<A, E2, R>\n} = dual(\n 2,\n <A, E, R, E2>(self: Effect.Effect<A, E, R>, f: (e: E) => E2): Effect.Effect<A, E2, R> =>\n matchCauseEffect(self, {\n onFailure: (cause) => {\n const either = internalCause.failureOrCause(cause)\n switch (either._tag) {\n case \"Left\": {\n return failSync(() => f(either.left))\n }\n case \"Right\": {\n return failCause(either.right)\n }\n }\n },\n onSuccess: succeed\n })\n)\n\n/* @internal */\nexport const onError: {\n <E, X, R2>(\n cleanup: (cause: Cause.Cause<E>) => Effect.Effect<X, never, R2>\n ): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R2 | R>\n <A, E, R, X, R2>(\n self: Effect.Effect<A, E, R>,\n cleanup: (cause: Cause.Cause<E>) => Effect.Effect<X, never, R2>\n ): Effect.Effect<A, E, R2 | R>\n} = dual(2, <A, E, R, X, R2>(\n self: Effect.Effect<A, E, R>,\n cleanup: (cause: Cause.Cause<E>) => Effect.Effect<X, never, R2>\n): Effect.Effect<A, E, R2 | R> =>\n onExit(self, (exit) => exitIsSuccess(exit) ? void_ : cleanup(exit.effect_instruction_i0)))\n\n/* @internal */\nexport const onExit: {\n <A, E, X, R2>(\n cleanup: (exit: Exit.Exit<A, E>) => Effect.Effect<X, never, R2>\n ): <R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R2 | R>\n <A, E, R, X, R2>(\n self: Effect.Effect<A, E, R>,\n cleanup: (exit: Exit.Exit<A, E>) => Effect.Effect<X, never, R2>\n ): Effect.Effect<A, E, R2 | R>\n} = dual(2, <A, E, R, X, R2>(\n self: Effect.Effect<A, E, R>,\n cleanup: (exit: Exit.Exit<A, E>) => Effect.Effect<X, never, R2>\n): Effect.Effect<A, E, R2 | R> =>\n uninterruptibleMask((restore) =>\n matchCauseEffect(restore(self), {\n onFailure: (cause1) => {\n const result = exitFailCause(cause1)\n return matchCauseEffect(cleanup(result), {\n onFailure: (cause2) => exitFailCause(internalCause.sequential(cause1, cause2)),\n onSuccess: () => result\n })\n },\n onSuccess: (success) => {\n const result = exitSucceed(success)\n return zipRight(cleanup(result), result)\n }\n })\n ))\n\n/* @internal */\nexport const onInterrupt: {\n <X, R2>(\n cleanup: (interruptors: HashSet.HashSet<FiberId.FiberId>) => Effect.Effect<X, never, R2>\n ): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R2 | R>\n <A, E, R, X, R2>(\n self: Effect.Effect<A, E, R>,\n cleanup: (interruptors: HashSet.HashSet<FiberId.FiberId>) => Effect.Effect<X, never, R2>\n ): Effect.Effect<A, E, R2 | R>\n} = dual(2, <A, E, R, X, R2>(\n self: Effect.Effect<A, E, R>,\n cleanup: (interruptors: HashSet.HashSet<FiberId.FiberId>) => Effect.Effect<X, never, R2>\n): Effect.Effect<A, E, R2 | R> =>\n onExit(\n self,\n exitMatch({\n onFailure: (cause) =>\n internalCause.isInterruptedOnly(cause)\n ? asVoid(cleanup(internalCause.interruptors(cause)))\n : void_,\n onSuccess: () => void_\n })\n ))\n\n/* @internal */\nexport const orElse: {\n <A2, E2, R2>(\n that: LazyArg<Effect.Effect<A2, E2, R2>>\n ): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A2 | A, E2, R2 | R>\n <A, E, R, A2, E2, R2>(\n self: Effect.Effect<A, E, R>,\n that: LazyArg<Effect.Effect<A2, E2, R2>>\n ): Effect.Effect<A2 | A, E2, R2 | R>\n} = dual(\n 2,\n <A, E, R, A2, E2, R2>(\n self: Effect.Effect<A, E, R>,\n that: LazyArg<Effect.Effect<A2, E2, R2>>\n ): Effect.Effect<A2 | A, E2, R2 | R> => attemptOrElse(self, that, succeed)\n)\n\n/* @internal */\nexport const orDie = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, never, R> => orDieWith(self, identity)\n\n/* @internal */\nexport const orDieWith: {\n <E>(f: (error: E) => unknown): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, never, R>\n <A, E, R>(self: Effect.Effect<A, E, R>, f: (error: E) => unknown): Effect.Effect<A, never, R>\n} = dual(\n 2,\n <A, E, R>(self: Effect.Effect<A, E, R>, f: (error: E) => unknown): Effect.Effect<A, never, R> =>\n matchEffect(self, {\n onFailure: (e) => die(f(e)),\n onSuccess: succeed\n })\n)\n\n/* @internal */\nexport const partitionMap: <A, A1, A2>(\n elements: Iterable<A>,\n f: (a: A) => Either.Either<A2, A1>\n) => [left: Array<A1>, right: Array<A2>] = Arr.partitionMap\n/* @internal */\nexport const runtimeFlags: Effect.Effect<RuntimeFlags.RuntimeFlags> = withFiberRuntime((_, status) =>\n succeed(status.runtimeFlags)\n)\n\n/* @internal */\nexport const succeed = <A>(value: A): Effect.Effect<A> => {\n const effect = new EffectPrimitiveSuccess(OpCodes.OP_SUCCESS) as any\n effect.effect_instruction_i0 = value\n return effect\n}\n\n/* @internal */\nexport const suspend = <A, E, R>(evaluate: LazyArg<Effect.Effect<A, E, R>>): Effect.Effect<A, E, R> => {\n const effect = new EffectPrimitive(OpCodes.OP_COMMIT) as any\n effect.commit = evaluate\n return effect\n}\n\n/* @internal */\nexport const sync = <A>(thunk: LazyArg<A>): Effect.Effect<A> => {\n const effect = new EffectPrimitive(OpCodes.OP_SYNC) as any\n effect.effect_instruction_i0 = thunk\n return effect\n}\n\n/* @internal */\nexport const tap = dual<\n {\n <A, X>(\n f: (a: NoInfer<A>) => X\n ): <E, R>(\n self: Effect.Effect<A, E, R>\n ) => [X] extends [Effect.Effect<infer _A1, infer E1, infer R1>] ? Effect.Effect<A, E | E1, R | R1>\n : [X] extends [PromiseLike<infer _A1>] ? Effect.Effect<A, E | Cause.UnknownException, R>\n : Effect.Effect<A, E, R>\n <A, X, E1, R1>(\n f: (a: NoInfer<A>) => Effect.Effect<X, E1, R1>,\n options: { onlyEffect: true }\n ): <E, R>(\n self: Effect.Effect<A, E, R>\n ) => Effect.Effect<A, E | E1, R | R1>\n <X>(\n f: NotFunction<X>\n ): <A, E, R>(\n self: Effect.Effect<A, E, R>\n ) => [X] extends [Effect.Effect<infer _A1, infer E1, infer R1>] ? Effect.Effect<A, E | E1, R | R1>\n : [X] extends [PromiseLike<infer _A1>] ? Effect.Effect<A, E | Cause.UnknownException, R>\n : Effect.Effect<A, E, R>\n <X, E1, R1>(\n f: Effect.Effect<X, E1, R1>,\n options: { onlyEffect: true }\n ): <A, E, R>(\n self: Effect.Effect<A, E, R>\n ) => Effect.Effect<A, E | E1, R | R1>\n },\n {\n <A, E, R, X>(\n self: Effect.Effect<A, E, R>,\n f: (a: NoInfer<A>) => X\n ): [X] extends [Effect.Effect<infer _A1, infer E1, infer R1>] ? Effect.Effect<A, E | E1, R | R1>\n : [X] extends [PromiseLike<infer _A1>] ? Effect.Effect<A, E | Cause.UnknownException, R>\n : Effect.Effect<A, E, R>\n <A, E, R, X, E1, R1>(\n self: Effect.Effect<A, E, R>,\n f: (a: NoInfer<A>) => Effect.Effect<X, E1, R1>,\n options: { onlyEffect: true }\n ): Effect.Effect<A, E | E1, R | R1>\n <A, E, R, X>(\n self: Effect.Effect<A, E, R>,\n f: NotFunction<X>\n ): [X] extends [Effect.Effect<infer _A1, infer E1, infer R1>] ? Effect.Effect<A, E | E1, R | R1>\n : [X] extends [PromiseLike<infer _A1>] ? Effect.Effect<A, E | Cause.UnknownException, R>\n : Effect.Effect<A, E, R>\n <A, E, R, X, E1, R1>(\n self: Effect.Effect<A, E, R>,\n f: Effect.Effect<X, E1, R1>,\n options: { onlyEffect: true }\n ): Effect.Effect<A, E | E1, R | R1>\n }\n>(\n (args) => args.length === 3 || args.length === 2 && !(isObject(args[1]) && \"onlyEffect\" in args[1]),\n <A, E, R, X>(self: Effect.Effect<A, E, R>, f: X) =>\n flatMap(self, (a) => {\n const b = typeof f === \"function\" ? (f as any)(a) : f\n if (isEffect(b)) {\n return as(b, a)\n } else if (isPromiseLike(b)) {\n return unsafeAsync<any, Cause.UnknownException>((resume) => {\n b.then((_) => resume(succeed(a)), (e) => resume(fail(new UnknownException(e))))\n })\n }\n return succeed(a)\n })\n)\n\n/* @internal */\nexport const transplant = <A, E, R>(\n f: (grafter: <A2, E2, R2>(effect: Effect.Effect<A2, E2, R2>) => Effect.Effect<A2, E2, R2>) => Effect.Effect<A, E, R>\n): Effect.Effect<A, E, R> =>\n withFiberRuntime<A, E, R>((state) => {\n const scopeOverride = state.getFiberRef(currentForkScopeOverride)\n const scope = pipe(scopeOverride, Option.getOrElse(() => state.scope()))\n return f(fiberRefLocally(currentForkScopeOverride, Option.some(scope)))\n })\n\n/* @internal */\nexport const attemptOrElse: {\n <A2, E2, R2, A, A3, E3, R3>(\n that: LazyArg<Effect.Effect<A2, E2, R2>>,\n onSuccess: (a: A) => Effect.Effect<A3, E3, R3>\n ): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A2 | A3, E2 | E3, R | R2 | R3>\n <A, E, R, A2, E2, R2, A3, E3, R3>(\n self: Effect.Effect<A, E, R>,\n that: LazyArg<Effect.Effect<A2, E2, R2>>,\n onSuccess: (a: A) => Effect.Effect<A3, E3, R3>\n ): Effect.Effect<A2 | A3, E2 | E3, R | R2 | R3>\n} = dual(3, <A, E, R, A2, E2, R2, A3, E3, R3>(\n self: Effect.Effect<A, E, R>,\n that: LazyArg<Effect.Effect<A2, E2, R2>>,\n onSuccess: (a: A) => Effect.Effect<A3, E3, R3>\n): Effect.Effect<A2 | A3, E2 | E3, R | R2 | R3> =>\n matchCauseEffect(self, {\n onFailure: (cause) => {\n const defects = internalCause.defects(cause)\n if (defects.length > 0) {\n return failCause(Option.getOrThrow(internalCause.keepDefectsAndElectFailures(cause)))\n }\n return that()\n },\n onSuccess\n }))\n\n/* @internal */\nexport const uninterruptible: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R> = <A, E, R>(\n self: Effect.Effect<A, E, R>\n): Effect.Effect<A, E, R> => {\n const effect = new EffectPrimitive(OpCodes.OP_UPDATE_RUNTIME_FLAGS) as any\n effect.effect_instruction_i0 = RuntimeFlagsPatch.disable(runtimeFlags_.Interruption)\n effect.effect_instruction_i1 = () => self\n return effect\n}\n\n/* @internal */\nexport const uninterruptibleMask = <A, E, R>(\n f: (restore: <AX, EX, RX>(effect: Effect.Effect<AX, EX, RX>) => Effect.Effect<AX, EX, RX>) => Effect.Effect<A, E, R>\n): Effect.Effect<A, E, R> =>\n custom(f, function() {\n const effect = new EffectPrimitive(OpCodes.OP_UPDATE_RUNTIME_FLAGS) as any\n effect.effect_instruction_i0 = RuntimeFlagsPatch.disable(runtimeFlags_.Interruption)\n effect.effect_instruction_i1 = (oldFlags: RuntimeFlags.RuntimeFlags) =>\n runtimeFlags_.interruption(oldFlags)\n ? internalCall(() => this.effect_instruction_i0(interruptible))\n : internalCall(() => this.effect_instruction_i0(uninterruptible))\n return effect\n })\n\nconst void_: Effect.Effect<void> = succeed(void 0)\nexport {\n /* @internal */\n void_ as void\n}\n\n/* @internal */\nexport const updateRuntimeFlags = (patch: RuntimeFlagsPatch.RuntimeFlagsPatch): Effect.Effect<void> => {\n const effect = new EffectPrimitive(OpCodes.OP_UPDATE_RUNTIME_FLAGS) as any\n effect.effect_instruction_i0 = patch\n effect.effect_instruction_i1 = void 0\n return effect\n}\n\n/* @internal */\nexport const whenEffect: {\n <E, R>(\n condition: Effect.Effect<boolean, E, R>\n ): <A, E2, R2>(\n effect: Effect.Effect<A, E2, R2>\n ) => Effect.Effect<Option.Option<A>, E | E2, R | R2>\n <A, E2, R2, E, R>(\n self: Effect.Effect<A, E2, R2>,\n condition: Effect.Effect<boolean, E, R>\n ): Effect.Effect<Option.Option<A>, E | E2, R | R2>\n} = dual(2, <A, E2, R2, E, R>(\n self: Effect.Effect<A, E2, R2>,\n condition: Effect.Effect<boolean, E, R>\n): Effect.Effect<Option.Option<A>, E | E2, R | R2> =>\n flatMap(condition, (b) => {\n if (b) {\n return pipe(self, map(Option.some))\n }\n return succeed(Option.none())\n }))\n\n/* @internal */\nexport const whileLoop = <A, E, R>(\n options: {\n readonly while: LazyArg<boolean>\n readonly body: LazyArg<Effect.Effect<A, E, R>>\n readonly step: (a: A) => void\n }\n): Effect.Effect<void, E, R> => {\n const effect = new EffectPrimitive(OpCodes.OP_WHILE) as any\n effect.effect_instruction_i0 = options.while\n effect.effect_instruction_i1 = options.body\n effect.effect_instruction_i2 = options.step\n return effect\n}\n\n/* @internal */\nexport const fromIterator = <Eff extends YieldWrap<Effect.Effect<any, any, any>>, AEff>(\n iterator: LazyArg<Iterator<Eff, AEff, never>>\n): Effect.Effect<\n AEff,\n [Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E : never,\n [Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R : never\n> =>\n suspend(() => {\n const effect = new EffectPrimitive(OpCodes.OP_ITERATOR) as any\n effect.effect_instruction_i0 = iterator()\n return effect\n })\n\n/* @internal */\nexport const gen: typeof Effect.gen = function() {\n const f = arguments.length === 1 ? arguments[0] : arguments[1].bind(arguments[0])\n return fromIterator(() => f(pipe))\n}\n\n/* @internal */\nexport const withConcurrency = dual<\n (concurrency: number | \"unbounded\") => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,\n <A, E, R>(self: Effect.Effect<A, E, R>, concurrency: number | \"unbounded\") => Effect.Effect<A, E, R>\n>(2, (self, concurrency) => fiberRefLocally(self, currentConcurrency, concurrency))\n\n/* @internal */\nexport const withRequestBatching = dual<\n (requestBatching: boolean) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,\n <A, E, R>(self: Effect.Effect<A, E, R>, requestBatching: boolean) => Effect.Effect<A, E, R>\n>(2, (self, requestBatching) => fiberRefLocally(self, currentRequestBatching, requestBatching))\n\n/* @internal */\nexport const withRuntimeFlags = dual<\n (update: RuntimeFlagsPatch.RuntimeFlagsPatch) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,\n <A, E, R>(self: Effect.Effect<A, E, R>, update: RuntimeFlagsPatch.RuntimeFlagsPatch) => Effect.Effect<A, E, R>\n>(2, (self, update) => {\n const effect = new EffectPrimitive(OpCodes.OP_UPDATE_RUNTIME_FLAGS) as any\n effect.effect_instruction_i0 = update\n effect.effect_instruction_i1 = () => self\n return effect\n})\n\n/** @internal */\nexport const withTracerEnabled = dual<\n (enabled: boolean) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,\n <A, E, R>(effect: Effect.Effect<A, E, R>, enabled: boolean) => Effect.Effect<A, E, R>\n>(2, (effect, enabled) =>\n fiberRefLocally(\n effect,\n currentTracerEnabled,\n enabled\n ))\n\n/** @internal */\nexport const withTracerTiming = dual<\n (enabled: boolean) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,\n <A, E, R>(effect: Effect.Effect<A, E, R>, enabled: boolean) => Effect.Effect<A, E, R>\n>(2, (effect, enabled) =>\n fiberRefLocally(\n effect,\n currentTracerTimingEnabled,\n enabled\n ))\n\n/* @internal */\nexport const yieldNow = (options?: {\n readonly priority?: number | undefined\n}): Effect.Effect<void> => {\n const effect = new EffectPrimitive(OpCodes.OP_YIELD) as any\n return typeof options?.priority !== \"undefined\" ?\n withSchedulingPriority(effect, options.priority) :\n effect\n}\n\n/* @internal */\nexport const zip = dual<\n <A2, E2, R2>(\n that: Effect.Effect<A2, E2, R2>\n ) => <A, E, R>(\n self: Effect.Effect<A, E, R>\n ) => Effect.Effect<[A, A2], E | E2, R | R2>,\n <A, E, R, A2, E2, R2>(\n self: Effect.Effect<A, E, R>,\n that: Effect.Effect<A2, E2, R2>\n ) => Effect.Effect<[A, A2], E | E2, R | R2>\n>(2, <A, E, R, A2, E2, R2>(\n self: Effect.Effect<A, E, R>,\n that: Effect.Effect<A2, E2, R2>\n): Effect.Effect<[A, A2], E | E2, R | R2> => flatMap(self, (a) => map(that, (b) => [a, b])))\n\n/* @internal */\nexport const zipFlatten: {\n <A2, E2, R2>(\n that: Effect.Effect<A2, E2, R2>\n ): <A extends ReadonlyArray<any>, E, R>(\n self: Effect.Effect<A, E, R>\n ) => Effect.Effect<[...A, A2], E | E2, R | R2>\n <A extends ReadonlyArray<any>, E, R, A2, E2, R2>(\n self: Effect.Effect<A, E, R>,\n that: Effect.Effect<A2, E2, R2>\n ): Effect.Effect<[...A, A2], E | E2, R | R2>\n} = dual(2, <A extends ReadonlyArray<any>, E, R, A2, E2, R2>(\n self: Effect.Effect<A, E, R>,\n that: Effect.Effect<A2, E2, R2>\n): Effect.Effect<[...A, A2], E | E2, R | R2> => flatMap(self, (a) => map(that, (b) => [...a, b])))\n\n/* @internal */\nexport const zipLeft: {\n <A2, E2, R2>(\n that: Effect.Effect<A2, E2, R2>\n ): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E | E2, R | R2>\n <A, E, R, A2, E2, R2>(\n self: Effect.Effect<A, E, R>,\n that: Effect.Effect<A2, E2, R2>\n ): Effect.Effect<A, E | E2, R | R2>\n} = dual(2, <A, E, R, A2, E2, R2>(\n self: Effect.Effect<A, E, R>,\n that: Effect.Effect<A2, E2, R2>\n): Effect.Effect<A, E | E2, R | R2> => flatMap(self, (a) => as(that, a)))\n\n/* @internal */\nexport const zipRight: {\n <A2, E2, R2>(\n that: Effect.Effect<A2, E2, R2>\n ): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A2, E | E2, R | R2>\n <A, E, R, A2, E2, R2>(\n self: Effect.Effect<A, E, R>,\n that: Effect.Effect<A2, E2, R2>\n ): Effect.Effect<A2, E | E2, R | R2>\n} = dual(2, <A, E, R, A2, E2, R2>(\n self: Effect.Effect<A, E, R>,\n that: Effect.Effect<A2, E2, R2>\n): Effect.Effect<A2, E | E2, R | R2> => flatMap(self, () => that))\n\n/* @internal */\nexport const zipWith: {\n <A2, E2, R2, A, B>(\n that: Effect.Effect<A2, E2, R2>,\n f: (a: A, b: A2) => B\n ): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B, E | E2, R | R2>\n <A, E, R, A2, E2, R2, B>(\n self: Effect.Effect<A, E, R>,\n that: Effect.Effect<A2, E2, R2>,\n f: (a: A, b: A2) => B\n ): Effect.Effect<B, E | E2, R | R2>\n} = dual(3, <A, E, R, A2, E2, R2, B>(\n self: Effect.Effect<A, E, R>,\n that: Effect.Effect<A2, E2, R2>,\n f: (a: A, b: A2) => B\n): Effect.Effect<B, E | E2, R | R2> => flatMap(self, (a) => map(that, (b) => f(a, b))))\n\n/* @internal */\nexport const never: Effect.Effect<never> = asyncInterrupt<never>(() => {\n const interval = setInterval(() => {\n //\n }, 2 ** 31 - 1)\n return sync(() => clearInterval(interval))\n})\n\n// -----------------------------------------------------------------------------\n// Fiber\n// -----------------------------------------------------------------------------\n\n/* @internal */\nexport const interruptFiber = <A, E>(self: Fiber.Fiber<A, E>): Effect.Effect<Exit.Exit<A, E>> =>\n flatMap(fiberId, (fiberId) => pipe(self, interruptAsFiber(fiberId)))\n\n/* @internal */\nexport const interruptAsFiber = dual<\n (fiberId: FiberId.FiberId) => <A, E>(self: Fiber.Fiber<A, E>) => Effect.Effect<Exit.Exit<A, E>>,\n <A, E>(self: Fiber.Fiber<A, E>, fiberId: FiberId.FiberId) => Effect.Effect<Exit.Exit<A, E>>\n>(2, (self, fiberId) => flatMap(self.interruptAsFork(fiberId), () => self.await))\n\n// -----------------------------------------------------------------------------\n// LogLevel\n// -----------------------------------------------------------------------------\n\n/** @internal */\nexport const logLevelAll: LogLevel.LogLevel = {\n _tag: \"All\",\n syslog: 0,\n label: \"ALL\",\n ordinal: Number.MIN_SAFE_INTEGER,\n pipe() {\n return pipeArguments(this, arguments)\n }\n}\n\n/** @internal */\nexport const logLevelFatal: LogLevel.LogLevel = {\n _tag: \"Fatal\",\n syslog: 2,\n label: \"FATAL\",\n ordinal: 50000,\n pipe() {\n return pipeArguments(this, arguments)\n }\n}\n\n/** @internal */\nexport const logLevelError: LogLevel.LogLevel = {\n _tag: \"Error\",\n syslog: 3,\n label: \"ERROR\",\n ordinal: 40000,\n pipe() {\n return pipeArguments(this, arguments)\n }\n}\n\n/** @internal */\nexport const logLevelWarning: LogLevel.LogLevel = {\n _tag: \"Warning\",\n syslog: 4,\n label: \"WARN\",\n ordinal: 30000,\n pipe() {\n return pipeArguments(this, arguments)\n }\n}\n\n/** @internal */\nexport const logLevelInfo: LogLevel.LogLevel = {\n _tag: \"Info\",\n syslog: 6,\n label: \"INFO\",\n ordinal: 20000,\n pipe() {\n return pipeArguments(this, arguments)\n }\n}\n\n/** @internal */\nexport const logLevelDebug: LogLevel.LogLevel = {\n _tag: \"Debug\",\n syslog: 7,\n label: \"DEBUG\",\n ordinal: 10000,\n pipe() {\n return pipeArguments(this, arguments)\n }\n}\n\n/** @internal */\nexport const logLevelTrace: LogLevel.LogLevel = {\n _tag: \"Trace\",\n syslog: 7,\n label: \"TRACE\",\n ordinal: 0,\n pipe() {\n return pipeArguments(this, arguments)\n }\n}\n\n/** @internal */\nexport const logLevelNone: LogLevel.LogLevel = {\n _tag: \"None\",\n syslog: 7,\n label: \"OFF\",\n ordinal: Number.MAX_SAFE_INTEGER,\n pipe() {\n return pipeArguments(this, arguments)\n }\n}\n\n/** @internal */\nexport const allLogLevels: ReadonlyArray<LogLevel.LogLevel> = [\n logLevelAll,\n logLevelTrace,\n logLevelDebug,\n logLevelInfo,\n logLevelWarning,\n logLevelError,\n logLevelFatal,\n logLevelNone\n]\n\n// -----------------------------------------------------------------------------\n// FiberRef\n// -----------------------------------------------------------------------------\n\n/** @internal */\nconst FiberRefSymbolKey = \"effect/FiberRef\"\n\n/** @internal */\nexport const FiberRefTypeId: FiberRef.FiberRefTypeId = Symbol.for(\n FiberRefSymbolKey\n) as FiberRef.FiberRefTypeId\n\nconst fiberRefVariance = {\n /* c8 ignore next */\n _A: (_: any) => _\n}\n\n/* @internal */\nexport const fiberRefGet = <A>(self: FiberRef.FiberRef<A>): Effect.Effect<A> =>\n withFiberRuntime((fiber) => exitSucceed(fiber.getFiberRef(self)))\n\n/* @internal */\nexport const fiberRefGetAndSet = dual<\n <A>(value: A) => (self: FiberRef.FiberRef<A>) => Effect.Effect<A>,\n <A>(self: FiberRef.FiberRef<A>, value: A) => Effect.Effect<A>\n>(2, (self, value) => fiberRefModify(self, (v) => [v, value] as const))\n\n/* @internal */\nexport const fiberRefGetAndUpdate = dual<\n <A>(f: (a: A) => A) => (self: FiberRef.FiberRef<A>) => Effect.Effect<A>,\n <A>(self: FiberRef.FiberRef<A>, f: (a: A) => A) => Effect.Effect<A>\n>(2, (self, f) => fiberRefModify(self, (v) => [v, f(v)] as const))\n\n/* @internal */\nexport const fiberRefGetAndUpdateSome = dual<\n <A>(\n pf: (a: A) => Option.Option<A>\n ) => (self: FiberRef.FiberRef<A>) => Effect.Effect<A>,\n <A>(\n self: FiberRef.FiberRef<A>,\n pf: (a: A) => Option.Option<A>\n ) => Effect.Effect<A>\n>(2, (self, pf) => fiberRefModify(self, (v) => [v, Option.getOrElse(pf(v), () => v)] as const))\n\n/* @internal */\nexport const fiberRefGetWith = dual<\n <B, E, R, A>(f: (a: A) => Effect.Effect<B, E, R>) => (self: FiberRef.FiberRef<A>) => Effect.Effect<B, E, R>,\n <A, B, E, R>(self: FiberRef.FiberRef<A>, f: (a: A) => Effect.Effect<B, E, R>) => Effect.Effect<B, E, R>\n>(2, (self, f) => flatMap(fiberRefGet(self), f))\n\n/* @internal */\nexport const fiberRefSet = dual<\n <A>(value: A) => (self: FiberRef.FiberRef<A>) => Effect.Effect<void>,\n <A>(self: FiberRef.FiberRef<A>, value: A) => Effect.Effect<void>\n>(2, (self, value) => fiberRefModify(self, () => [void 0, value] as const))\n\n/* @internal */\nexport const fiberRefDelete = <A>(self: FiberRef.FiberRef<A>): Effect.Effect<void> =>\n withFiberRuntime((state) => {\n state.unsafeDeleteFiberRef(self)\n return void_\n })\n\n/* @internal */\nexport const fiberRefReset = <A>(self: FiberRef.FiberRef<A>): Effect.Effect<void> => fiberRefSet(self, self.initial)\n\n/* @internal */\nexport const fiberRefModify = dual<\n <A, B>(f: (a: A) => readonly [B, A]) => (self: FiberRef.FiberRef<A>) => Effect.Effect<B>,\n <A, B>(self: FiberRef.FiberRef<A>, f: (a: A) => readonly [B, A]) => Effect.Effect<B>\n>(2, <A, B>(\n self: FiberRef.FiberRef<A>,\n f: (a: A) => readonly [B, A]\n): Effect.Effect<B> =>\n withFiberRuntime((state) => {\n const [b, a] = f(state.getFiberRef(self) as A)\n state.setFiberRef(self, a)\n return succeed(b)\n }))\n\n/* @internal */\nexport const fiberRefModifySome = <A, B>(\n self: FiberRef.FiberRef<A>,\n def: B,\n f: (a: A) => Option.Option<readonly [B, A]>\n): Effect.Effect<B> => fiberRefModify(self, (v) => Option.getOrElse(f(v), () => [def, v] as const))\n\n/* @internal */\nexport const fiberRefUpdate = dual<\n <A>(f: (a: A) => A) => (self: FiberRef.FiberRef<A>) => Effect.Effect<void>,\n <A>(self: FiberRef.FiberRef<A>, f: (a: A) => A) => Effect.Effect<void>\n>(2, (self, f) => fiberRefModify(self, (v) => [void 0, f(v)] as const))\n\n/* @internal */\nexport const fiberRefUpdateSome = dual<\n <A>(pf: (a: A) => Option.Option<A>) => (self: FiberRef.FiberRef<A>) => Effect.Effect<void>,\n <A>(self: FiberRef.FiberRef<A>, pf: (a: A) => Option.Option<A>) => Effect.Effect<void>\n>(2, (self, pf) => fiberRefModify(self, (v) => [void 0, Option.getOrElse(pf(v), () => v)] as const))\n\n/* @internal */\nexport const fiberRefUpdateAndGet = dual<\n <A>(f: (a: A) => A) => (self: FiberRef.FiberRef<A>) => Effect.Effect<A>,\n <A>(self: FiberRef.FiberRef<A>, f: (a: A) => A) => Effect.Effect<A>\n>(2, (self, f) =>\n fiberRefModify(self, (v) => {\n const result = f(v)\n return [result, result] as const\n }))\n\n/* @internal */\nexport const fiberRefUpdateSomeAndGet = dual<\n <A>(pf: (a: A) => Option.Option<A>) => (self: FiberRef.FiberRef<A>) => Effect.Effect<A>,\n <A>(self: FiberRef.FiberRef<A>, pf: (a: A) => Option.Option<A>) => Effect.Effect<A>\n>(2, (self, pf) =>\n fiberRefModify(self, (v) => {\n const result = Option.getOrElse(pf(v), () => v)\n return [result, result] as const\n }))\n\n// circular\n/** @internal */\nconst RequestResolverSymbolKey = \"effect/RequestResolver\"\n\n/** @internal */\nexport const RequestResolverTypeId: RequestResolver.RequestResolverTypeId = Symbol.for(\n RequestResolverSymbolKey\n) as RequestResolver.RequestResolverTypeId\n\nconst requestResolverVariance = {\n /* c8 ignore next */\n _A: (_: unknown) => _,\n /* c8 ignore next */\n _R: (_: never) => _\n}\n\n/** @internal */\nexport class RequestResolverImpl<in A, out R> implements RequestResolver.RequestResolver<A, R> {\n readonly [RequestResolverTypeId] = requestResolverVariance\n constructor(\n readonly runAll: (\n requests: Array<Array<Request.Entry<A>>>\n ) => Effect.Effect<void, never, R>,\n readonly target?: unknown\n ) {\n }\n [Hash.symbol](): number {\n return Hash.cached(this, this.target ? Hash.hash(this.target) : Hash.random(this))\n }\n [Equal.symbol](that: unknown): boolean {\n return this.target ?\n isRequestResolver(that) && Equal.equals(this.target, (that as RequestResolverImpl<any, any>).target) :\n this === that\n }\n identified(...ids: Array<unknown>): RequestResolver.RequestResolver<A, R> {\n return new RequestResolverImpl(this.runAll, Chunk.fromIterable(ids))\n }\n pipe() {\n return pipeArguments(this, arguments)\n }\n}\n\n/** @internal */\nexport const isRequestResolver = (u: unknown): u is RequestResolver.RequestResolver<unknown, unknown> =>\n hasProperty(u, RequestResolverTypeId)\n\n// end\n\n/** @internal */\nexport const resolverLocally = dual<\n <A>(\n self: FiberRef.FiberRef<A>,\n value: A\n ) => <R, B extends Request.Request<any, any>>(\n use: RequestResolver.RequestResolver<B, R>\n ) => RequestResolver.RequestResolver<B, R>,\n <R, B extends Request.Request<any, any>, A>(\n use: RequestResolver.RequestResolver<B, R>,\n self: FiberRef.FiberRef<A>,\n value: A\n ) => RequestResolver.RequestResolver<B, R>\n>(3, <R, B extends Request.Request<any, any>, A>(\n use: RequestResolver.RequestResolver<B, R>,\n self: FiberRef.FiberRef<A>,\n value: A\n): RequestResolver.RequestResolver<B, R> =>\n new RequestResolverImpl<B, R>(\n (requests) =>\n fiberRefLocally(\n use.runAll(requests),\n self,\n value\n ),\n Chunk.make(\"Locally\", use, self, value)\n ))\n\n/** @internal */\nexport const requestBlockLocally = <A>(\n self: BlockedRequests.RequestBlock,\n ref: FiberRef.FiberRef<A>,\n value: A\n): BlockedRequests.RequestBlock => blockedRequests_.reduce(self, LocallyReducer(ref, value))\n\nconst LocallyReducer = <A>(\n ref: FiberRef.FiberRef<A>,\n value: A\n): BlockedRequests.RequestBlock.Reducer<BlockedRequests.RequestBlock> => ({\n emptyCase: () => blockedRequests_.empty,\n parCase: (left, right) => blockedRequests_.par(left, right),\n seqCase: (left, right) => blockedRequests_.seq(left, right),\n singleCase: (dataSource, blockedRequest) =>\n blockedRequests_.single(\n resolverLocally(dataSource, ref, value),\n blockedRequest as any\n )\n})\n\n/* @internal */\nexport const fiberRefLocally: {\n <A>(self: FiberRef.FiberRef<A>, value: A): <B, E, R>(use: Effect.Effect<B, E, R>) => Effect.Effect<B, E, R>\n <B, E, R, A>(use: Effect.Effect<B, E, R>, self: FiberRef.FiberRef<A>, value: A): Effect.Effect<B, E, R>\n} = dual(\n 3,\n <B, E, R, A>(use: Effect.Effect<B, E, R>, self: FiberRef.FiberRef<A>, value: A): Effect.Effect<B, E, R> =>\n acquireUseRelease(\n zipLeft(fiberRefGet(self), fiberRefSet(self, value)),\n () => use,\n (oldValue) => fiberRefSet(self, oldValue)\n )\n)\n\n/* @internal */\nexport const fiberRefLocallyWith = dual<\n <A>(self: FiberRef.FiberRef<A>, f: (a: A) => A) => <B, E, R>(use: Effect.Effect<B, E, R>) => Effect.Effect<B, E, R>,\n <B, E, R, A>(use: Effect.Effect<B, E, R>, self: FiberRef.FiberRef<A>, f: (a: A) => A) => Effect.Effect<B, E, R>\n>(3, (use, self, f) => fiberRefGetWith(self, (a) => fiberRefLocally(use, self, f(a))))\n\n/** @internal */\nexport const fiberRefUnsafeMake = <Value>(\n initial: Value,\n options?: {\n readonly fork?: ((a: Value) => Value) | undefined\n readonly join?: ((left: Value, right: Value) => Value) | undefined\n }\n): FiberRef.FiberRef<Value> =>\n fiberRefUnsafeMakePatch(initial, {\n differ: internalDiffer.update(),\n fork: options?.fork ?? identity,\n join: options?.join\n })\n\n/** @internal */\nexport const fiberRefUnsafeMakeHashSet = <A>(\n initial: HashSet.HashSet<A>\n): FiberRef.FiberRef<HashSet.HashSet<A>> => {\n const differ = internalDiffer.hashSet<A>()\n return fiberRefUnsafeMakePatch(initial, {\n differ,\n fork: differ.empty\n })\n}\n\n/** @internal */\nexport const fiberRefUnsafeMakeReadonlyArray = <A>(\n initial: ReadonlyArray<A>\n): FiberRef.FiberRef<ReadonlyArray<A>> => {\n const differ = internalDiffer.readonlyArray(internalDiffer.update<A>())\n return fiberRefUnsafeMakePatch(initial, {\n differ,\n fork: differ.empty\n })\n}\n\n/** @internal */\nexport const fiberRefUnsafeMakeContext = <A>(\n initial: Context.Context<A>\n): FiberRef.FiberRef<Context.Context<A>> => {\n const differ = internalDiffer.environment<A>()\n return fiberRefUnsafeMakePatch(initial, {\n differ,\n fork: differ.empty\n })\n}\n\n/** @internal */\nexport const fiberRefUnsafeMakePatch = <Value, Patch>(\n initial: Value,\n options: {\n readonly differ: Differ.Differ<Value, Patch>\n readonly fork: Patch\n readonly join?: ((oldV: Value, newV: Value) => Value) | undefined\n }\n): FiberRef.FiberRef<Value> => {\n const _fiberRef = {\n ...CommitPrototype,\n [FiberRefTypeId]: fiberRefVariance,\n initial,\n commit() {\n return fiberRefGet(this)\n },\n diff: (oldValue: Value, newValue: Value) => options.differ.diff(oldValue, newValue),\n combine: (first: Patch, second: Patch) => options.differ.combine(first, second),\n patch: (patch: Patch) => (oldValue: Value) => options.differ.patch(patch, oldValue),\n fork: options.fork,\n join: options.join ?? ((_, n) => n)\n }\n return _fiberRef\n}\n\n/** @internal */\nexport const fiberRefUnsafeMakeRuntimeFlags = (\n initial: RuntimeFlags.RuntimeFlags\n): FiberRef.FiberRef<RuntimeFlags.RuntimeFlags> =>\n fiberRefUnsafeMakePatch(initial, {\n differ: runtimeFlags_.differ,\n fork: runtimeFlags_.differ.empty\n })\n\n/** @internal */\nexport const currentContext: FiberRef.FiberRef<Context.Context<never>> = globalValue(\n Symbol.for(\"effect/FiberRef/currentContext\"),\n () => fiberRefUnsafeMakeContext(Context.empty())\n)\n\n/** @internal */\nexport const currentSchedulingPriority: FiberRef.FiberRef<number> = globalValue(\n Symbol.for(\"effect/FiberRef/currentSchedulingPriority\"),\n () => fiberRefUnsafeMake(0)\n)\n\n/** @internal */\nexport const currentMaxOpsBeforeYield: FiberRef.FiberRef<number> = globalValue(\n Symbol.for(\"effect/FiberRef/currentMaxOpsBeforeYield\"),\n () => fiberRefUnsafeMake(2048)\n)\n\n/** @internal */\nexport const currentLogAnnotations: FiberRef.FiberRef<HashMap.HashMap<string, unknown>> = globalValue(\n Symbol.for(\"effect/FiberRef/currentLogAnnotation\"),\n () => fiberRefUnsafeMake(HashMap.empty())\n)\n\n/** @internal */\nexport const currentLogLevel: FiberRef.FiberRef<LogLevel.LogLevel> = globalValue(\n Symbol.for(\"effect/FiberRef/currentLogLevel\"),\n () => fiberRefUnsafeMake<LogLevel.LogLevel>(logLevelInfo)\n)\n\n/** @internal */\nexport const currentLogSpan: FiberRef.FiberRef<List.List<LogSpan.LogSpan>> = globalValue(\n Symbol.for(\"effect/FiberRef/currentLogSpan\"),\n () => fiberRefUnsafeMake(List.empty<LogSpan.LogSpan>())\n)\n\n/** @internal */\nexport const withSchedulingPriority = dual<\n (priority: number) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,\n <A, E, R>(self: Effect.Effect<A, E, R>, priority: number) => Effect.Effect<A, E, R>\n>(2, (self, scheduler) => fiberRefLocally(self, currentSchedulingPriority, scheduler))\n\n/** @internal */\nexport const withMaxOpsBeforeYield = dual<\n (priority: number) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,\n <A, E, R>(self: Effect.Effect<A, E, R>, priority: number) => Effect.Effect<A, E, R>\n>(2, (self, scheduler) => fiberRefLocally(self, currentMaxOpsBeforeYield, scheduler))\n\n/** @internal */\nexport const currentConcurrency: FiberRef.FiberRef<\"unbounded\" | number> = globalValue(\n Symbol.for(\"effect/FiberRef/currentConcurrency\"),\n () => fiberRefUnsafeMake<\"unbounded\" | number>(\"unbounded\")\n)\n\n/**\n * @internal\n */\nexport const currentRequestBatching = globalValue(\n Symbol.for(\"effect/FiberRef/currentRequestBatching\"),\n () => fiberRefUnsafeMake(true)\n)\n\n/** @internal */\nexport const currentUnhandledErrorLogLevel: FiberRef.FiberRef<Option.Option<LogLevel.LogLevel>> = globalValue(\n Symbol.for(\"effect/FiberRef/currentUnhandledErrorLogLevel\"),\n () => fiberRefUnsafeMake(Option.some<LogLevel.LogLevel>(logLevelDebug))\n)\n\n/** @internal */\nexport const withUnhandledErrorLogLevel = dual<\n (level: Option.Option<LogLevel.LogLevel>) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,\n <A, E, R>(self: Effect.Effect<A, E, R>, level: Option.Option<LogLevel.LogLevel>) => Effect.Effect<A, E, R>\n>(2, (self, level) => fiberRefLocally(self, currentUnhandledErrorLogLevel, level))\n\n/** @internal */\nexport const currentMetricLabels: FiberRef.FiberRef<ReadonlyArray<MetricLabel.MetricLabel>> = globalValue(\n Symbol.for(\"effect/FiberRef/currentMetricLabels\"),\n () => fiberRefUnsafeMakeReadonlyArray(Arr.empty())\n)\n\n/* @internal */\nexport const metricLabels: Effect.Effect<ReadonlyArray<MetricLabel.MetricLabel>> = fiberRefGet(\n currentMetricLabels\n)\n\n/** @internal */\nexport const currentForkScopeOverride: FiberRef.FiberRef<Option.Option<fiberScope.FiberScope>> = globalValue(\n Symbol.for(\"effect/FiberRef/currentForkScopeOverride\"),\n () =>\n fiberRefUnsafeMake(Option.none(), {\n fork: () => Option.none() as Option.Option<fiberScope.FiberScope>,\n join: (parent, _) => parent\n })\n)\n\n/** @internal */\nexport const currentInterruptedCause: FiberRef.FiberRef<Cause.Cause<never>> = globalValue(\n Symbol.for(\"effect/FiberRef/currentInterruptedCause\"),\n () =>\n fiberRefUnsafeMake(internalCause.empty, {\n fork: () => internalCause.empty,\n join: (parent, _) => parent\n })\n)\n\n/** @internal */\nexport const currentTracerEnabled: FiberRef.FiberRef<boolean> = globalValue(\n Symbol.for(\"effect/FiberRef/currentTracerEnabled\"),\n () => fiberRefUnsafeMake(true)\n)\n\n/** @internal */\nexport const currentTracerTimingEnabled: FiberRef.FiberRef<boolean> = globalValue(\n Symbol.for(\"effect/FiberRef/currentTracerTiming\"),\n () => fiberRefUnsafeMake(true)\n)\n\n/** @internal */\nexport const currentTracerSpanAnnotations: FiberRef.FiberRef<HashMap.HashMap<string, unknown>> = globalValue(\n Symbol.for(\"effect/FiberRef/currentTracerSpanAnnotations\"),\n () => fiberRefUnsafeMake(HashMap.empty())\n)\n\n/** @internal */\nexport const currentTracerSpanLinks: FiberRef.FiberRef<Chunk.Chunk<Tracer.SpanLink>> = globalValue(\n Symbol.for(\"effect/FiberRef/currentTracerSpanLinks\"),\n () => fiberRefUnsafeMake(Chunk.empty())\n)\n\n// -----------------------------------------------------------------------------\n// Scope\n// -----------------------------------------------------------------------------\n\n/** @internal */\nexport const ScopeTypeId: Scope.ScopeTypeId = Symbol.for(\"effect/Scope\") as Scope.ScopeTypeId\n\n/** @internal */\nexport const CloseableScopeTypeId: Scope.CloseableScopeTypeId = Symbol.for(\n \"effect/CloseableScope\"\n) as Scope.CloseableScopeTypeId\n\n/* @internal */\nexport const scopeAddFinalizer = (\n self: Scope.Scope,\n finalizer: Effect.Effect<unknown>\n): Effect.Effect<void> => self.addFinalizer(() => asVoid(finalizer))\n\n/* @internal */\nexport const scopeAddFinalizerExit = (\n self: Scope.Scope,\n finalizer: Scope.Scope.Finalizer\n): Effect.Effect<void> => self.addFinalizer(finalizer)\n\n/* @internal */\nexport const scopeClose = (\n self: Scope.Scope.Closeable,\n exit: Exit.Exit<unknown, unknown>\n): Effect.Effect<void> => self.close(exit)\n\n/* @internal */\nexport const scopeFork = (\n self: Scope.Scope,\n strategy: ExecutionStrategy.ExecutionStrategy\n): Effect.Effect<Scope.Scope.Closeable> => self.fork(strategy)\n\n// -----------------------------------------------------------------------------\n// Cause\n// -----------------------------------------------------------------------------\n\n/** @internal */\nexport const causeSquash = <E>(self: Cause.Cause<E>): unknown => {\n return causeSquashWith(identity)(self)\n}\n\n/** @internal */\nexport const causeSquashWith = dual<\n <E>(f: (error: E) => unknown) => (self: Cause.Cause<E>) => unknown,\n <E>(self: Cause.Cause<E>, f: (error: E) => unknown) => unknown\n>(2, (self, f) => {\n const option = pipe(self, internalCause.failureOption, Option.map(f))\n switch (option._tag) {\n case \"None\": {\n return pipe(\n internalCause.defects(self),\n Chunk.head,\n Option.match({\n onNone: () => {\n const interrupts = Arr.fromIterable(internalCause.interruptors(self)).flatMap((fiberId) =>\n Arr.fromIterable(FiberId.ids(fiberId)).map((id) => `#${id}`)\n )\n return new InterruptedException(interrupts ? `Interrupted by fibers: ${interrupts.join(\", \")}` : void 0)\n },\n onSome: identity\n })\n )\n }\n case \"Some\": {\n return option.value\n }\n }\n})\n\n// -----------------------------------------------------------------------------\n// Errors\n// -----------------------------------------------------------------------------\n\n/** @internal */\nexport const YieldableError: new(message?: string, options?: ErrorOptions) => Cause.YieldableError = (function() {\n class YieldableError extends globalThis.Error {\n commit() {\n return fail(this)\n }\n toJSON() {\n return { ...this }\n }\n [NodeInspectSymbol]() {\n if (this.toString !== globalThis.Error.prototype.toString) {\n return this.stack ? `${this.toString()}\\n${this.stack.split(\"\\n\").slice(1).join(\"\\n\")}` : this.toString()\n } else if (\"Bun\" in globalThis) {\n return internalCause.pretty(internalCause.fail(this), { renderErrorCause: true })\n }\n return this\n }\n }\n Object.assign(YieldableError.prototype, StructuralCommitPrototype)\n return YieldableError as any\n})()\n\nconst makeException = <T extends { _tag: string; message?: string }>(\n proto: Omit<T, keyof Cause.YieldableError | \"_tag\">,\n tag: T[\"_tag\"]\n): new(message?: string | undefined) => T => {\n class Base extends YieldableError {\n readonly _tag = tag\n }\n Object.assign(Base.prototype, proto)\n ;(Base.prototype as any).name = tag\n return Base as any\n}\n\n/** @internal */\nexport const RuntimeExceptionTypeId: Cause.RuntimeExceptionTypeId = Symbol.for(\n \"effect/Cause/errors/RuntimeException\"\n) as Cause.RuntimeExceptionTypeId\n\n/** @internal */\nexport const RuntimeException = makeException<Cause.RuntimeException>({\n [RuntimeExceptionTypeId]: RuntimeExceptionTypeId\n}, \"RuntimeException\")\n\n/** @internal */\nexport const isRuntimeException = (u: unknown): u is Cause.RuntimeException => hasProperty(u, RuntimeExceptionTypeId)\n\n/** @internal */\nexport const InterruptedExceptionTypeId: Cause.InterruptedExceptionTypeId = Symbol.for(\n \"effect/Cause/errors/InterruptedException\"\n) as Cause.InterruptedExceptionTypeId\n\n/** @internal */\nexport const InterruptedException = makeException<Cause.InterruptedException>({\n [InterruptedExceptionTypeId]: InterruptedExceptionTypeId\n}, \"InterruptedException\")\n\n/** @internal */\nexport const isInterruptedException = (u: unknown): u is Cause.InterruptedException =>\n hasProperty(u, InterruptedExceptionTypeId)\n\n/** @internal */\nexport const IllegalArgumentExceptionTypeId: Cause.IllegalArgumentExceptionTypeId = Symbol.for(\n \"effect/Cause/errors/IllegalArgument\"\n) as Cause.IllegalArgumentExceptionTypeId\n\n/** @internal */\nexport const IllegalArgumentException = makeException<Cause.IllegalArgumentException>({\n [IllegalArgumentExceptionTypeId]: IllegalArgumentExceptionTypeId\n}, \"IllegalArgumentException\")\n\n/** @internal */\nexport const isIllegalArgumentException = (u: unknown): u is Cause.IllegalArgumentException =>\n hasProperty(u, IllegalArgumentExceptionTypeId)\n\n/** @internal */\nexport const NoSuchElementExceptionTypeId: Cause.NoSuchElementExceptionTypeId = Symbol.for(\n \"effect/Cause/errors/NoSuchElement\"\n) as Cause.NoSuchElementExceptionTypeId\n\n/** @internal */\nexport const NoSuchElementException = makeException<Cause.NoSuchElementException>({\n [NoSuchElementExceptionTypeId]: NoSuchElementExceptionTypeId\n}, \"NoSuchElementException\")\n\n/** @internal */\nexport const isNoSuchElementException = (u: unknown): u is Cause.NoSuchElementException =>\n hasProperty(u, NoSuchElementExceptionTypeId)\n\n/** @internal */\nexport const InvalidPubSubCapacityExceptionTypeId: Cause.InvalidPubSubCapacityExceptionTypeId = Symbol.for(\n \"effect/Cause/errors/InvalidPubSubCapacityException\"\n) as Cause.InvalidPubSubCapacityExceptionTypeId\n\n/** @internal */\nexport const InvalidPubSubCapacityException = makeException<Cause.InvalidPubSubCapacityException>({\n [InvalidPubSubCapacityExceptionTypeId]: InvalidPubSubCapacityExceptionTypeId\n}, \"InvalidPubSubCapacityException\")\n\n/** @internal */\nexport const ExceededCapacityExceptionTypeId: Cause.ExceededCapacityExceptionTypeId = Symbol.for(\n \"effect/Cause/errors/ExceededCapacityException\"\n) as Cause.ExceededCapacityExceptionTypeId\n\n/** @internal */\nexport const ExceededCapacityException = makeException<Cause.ExceededCapacityException>({\n [ExceededCapacityExceptionTypeId]: ExceededCapacityExceptionTypeId\n}, \"ExceededCapacityException\")\n\n/** @internal */\nexport const isExceededCapacityException = (u: unknown): u is Cause.ExceededCapacityException =>\n hasProperty(u, ExceededCapacityExceptionTypeId)\n\n/** @internal */\nexport const isInvalidCapacityError = (u: unknown): u is Cause.InvalidPubSubCapacityException =>\n hasProperty(u, InvalidPubSubCapacityExceptionTypeId)\n\n/** @internal */\nexport const TimeoutExceptionTypeId: Cause.TimeoutExceptionTypeId = Symbol.for(\n \"effect/Cause/errors/Timeout\"\n) as Cause.TimeoutExceptionTypeId\n\n/** @internal */\nexport const TimeoutException = makeException<Cause.TimeoutException>({\n [TimeoutExceptionTypeId]: TimeoutExceptionTypeId\n}, \"TimeoutException\")\n/** @internal */\nexport const timeoutExceptionFromDuration = (duration: Duration.DurationInput): Cause.TimeoutException =>\n new TimeoutException(`Operation timed out before the specified duration of '${Duration.format(duration)}' elapsed`)\n\n/** @internal */\nexport const isTimeoutException = (u: unknown): u is Cause.TimeoutException => hasProperty(u, TimeoutExceptionTypeId)\n\n/** @internal */\nexport const UnknownExceptionTypeId: Cause.UnknownExceptionTypeId = Symbol.for(\n \"effect/Cause/errors/UnknownException\"\n) as Cause.UnknownExceptionTypeId\n\n/** @internal */\nexport const UnknownException: new(cause: unknown, message?: string | undefined) => Cause.UnknownException =\n (function() {\n class UnknownException extends YieldableError {\n readonly _tag = \"UnknownException\"\n readonly error: unknown\n constructor(readonly cause: unknown, message?: string) {\n super(message ?? \"An unknown error occurred\", { cause })\n this.error = cause\n }\n }\n Object.assign(UnknownException.prototype, {\n [UnknownExceptionTypeId]: UnknownExceptionTypeId,\n name: \"UnknownException\"\n })\n return UnknownException as any\n })()\n\n/** @internal */\nexport const isUnknownException = (u: unknown): u is Cause.UnknownException => hasProperty(u, UnknownExceptionTypeId)\n\n// -----------------------------------------------------------------------------\n// Exit\n// -----------------------------------------------------------------------------\n\n/** @internal */\nexport const exitIsExit = (u: unknown): u is Exit.Exit<unknown, unknown> =>\n isEffect(u) && \"_tag\" in u && (u._tag === \"Success\" || u._tag === \"Failure\")\n\n/** @internal */\nexport const exitIsFailure = <A, E>(self: Exit.Exit<A, E>): self is Exit.Failure<A, E> => self._tag === \"Failure\"\n\n/** @internal */\nexport const exitIsSuccess = <A, E>(self: Exit.Exit<A, E>): self is Exit.Success<A, E> => self._tag === \"Success\"\n\n/** @internal */\nexport const exitIsInterrupted = <A, E>(self: Exit.Exit<A, E>): boolean => {\n switch (self._tag) {\n case OpCodes.OP_FAILURE:\n return internalCause.isInterrupted(self.effect_instruction_i0)\n case OpCodes.OP_SUCCESS:\n return false\n }\n}\n\n/** @internal */\nexport const exitAs = dual<\n <A2>(value: A2) => <A, E>(self: Exit.Exit<A, E>) => Exit.Exit<A2, E>,\n <A, E, A2>(self: Exit.Exit<A, E>, value: A2) => Exit.Exit<A2, E>\n>(2, <A, E, A2>(self: Exit.Exit<A, E>, value: A2): Exit.Exit<A2, E> => {\n switch (self._tag) {\n case OpCodes.OP_FAILURE: {\n return exitFailCause(self.effect_instruction_i0)\n }\n case OpCodes.OP_SUCCESS: {\n return exitSucceed(value) as Exit.Exit<A2, E>\n }\n }\n})\n\n/** @internal */\nexport const exitAsVoid = <A, E>(self: Exit.Exit<A, E>): Exit.Exit<void, E> => exitAs(self, void 0)\n\n/** @internal */\nexport const exitCauseOption = <A, E>(self: Exit.Exit<A, E>): Option.Option<Cause.Cause<E>> => {\n switch (self._tag) {\n case OpCodes.OP_FAILURE:\n return Option.some(self.effect_instruction_i0)\n case OpCodes.OP_SUCCESS:\n return Option.none()\n }\n}\n\n/** @internal */\nexport const exitCollectAll = <A, E>(\n exits: Iterable<Exit.Exit<A, E>>,\n options?: {\n readonly parallel?: boolean | undefined\n }\n): Option.Option<Exit.Exit<Array<A>, E>> =>\n exitCollectAllInternal(exits, options?.parallel ? internalCause.parallel : internalCause.sequential)\n\n/** @internal */\nexport const exitDie = (defect: unknown): Exit.Exit<never> =>\n exitFailCause(internalCause.die(defect)) as Exit.Exit<never>\n\n/** @internal */\nexport const exitExists: {\n <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): <E>(self: Exit.Exit<A, E>) => self is Exit.Exit<B>\n <A>(predicate: Predicate<NoInfer<A>>): <E>(self: Exit.Exit<A, E>) => boolean\n <A, E, B extends A>(self: Exit.Exit<A, E>, refinement: Refinement<A, B>): self is Exit.Exit<B>\n <A, E>(self: Exit.Exit<A, E>, predicate: Predicate<A>): boolean\n} = dual(2, <A, E, B extends A>(self: Exit.Exit<A, E>, refinement: Refinement<A, B>): self is Exit.Exit<B> => {\n switch (self._tag) {\n case OpCodes.OP_FAILURE:\n return false\n case OpCodes.OP_SUCCESS:\n return refinement(self.effect_instruction_i0)\n }\n})\n\n/** @internal */\nexport const exitFail = <E>(error: E): Exit.Exit<never, E> =>\n exitFailCause(internalCause.fail(error)) as Exit.Exit<never, E>\n\n/** @internal */\nexport const exitFailCause = <E>(cause: Cause.Cause<E>): Exit.Exit<never, E> => {\n const effect = new EffectPrimitiveFailure(OpCodes.OP_FAILURE) as any\n effect.effect_instruction_i0 = cause\n return effect\n}\n\n/** @internal */\nexport const exitFlatMap = dual<\n <A, A2, E2>(f: (a: A) => Exit.Exit<A2, E2>) => <E>(self: Exit.Exit<A, E>) => Exit.Exit<A2, E | E2>,\n <A, E, E2, A2>(self: Exit.Exit<A, E>, f: (a: A) => Exit.Exit<A2, E2>) => Exit.Exit<A2, E | E2>\n>(2, <A, E, E2, A2>(self: Exit.Exit<A, E>, f: (a: A) => Exit.Exit<A2, E2>): Exit.Exit<A2, E | E2> => {\n switch (self._tag) {\n case OpCodes.OP_FAILURE: {\n return exitFailCause(self.effect_instruction_i0)\n }\n case OpCodes.OP_SUCCESS: {\n return f(self.effect_instruction_i0)\n }\n }\n})\n\n/** @internal */\nexport const exitFlatMapEffect: {\n <A, E, A2, E2, R>(\n f: (a: A) => Effect.Effect<Exit.Exit<A2, E>, E2, R>\n ): (self: Exit.Exit<A, E>) => Effect.Effect<Exit.Exit<A2, E>, E2, R>\n <A, E, A2, E2, R>(\n self: Exit.Exit<A, E>,\n f: (a: A) => Effect.Effect<Exit.Exit<A2, E>, E2, R>\n ): Effect.Effect<Exit.Exit<A2, E>, E2, R>\n} = dual(2, <A, E, A2, E2, R>(\n self: Exit.Exit<A, E>,\n f: (a: A) => Effect.Effect<Exit.Exit<A2, E>, E2, R>\n): Effect.Effect<Exit.Exit<A2, E>, E2, R> => {\n switch (self._tag) {\n case OpCodes.OP_FAILURE: {\n return succeed(exitFailCause(self.effect_instruction_i0))\n }\n case OpCodes.OP_SUCCESS: {\n return f(self.effect_instruction_i0)\n }\n }\n})\n\n/** @internal */\nexport const exitFlatten = <A, E, E2>(\n self: Exit.Exit<Exit.Exit<A, E>, E2>\n): Exit.Exit<A, E | E2> => pipe(self, exitFlatMap(identity))\n\n/** @internal */\nexport const exitForEachEffect: {\n <A, B, E2, R>(\n f: (a: A) => Effect.Effect<B, E2, R>\n ): <E>(self: Exit.Exit<A, E>) => Effect.Effect<Exit.Exit<B, E | E2>, never, R>\n <A, E, B, E2, R>(\n self: Exit.Exit<A, E>,\n f: (a: A) => Effect.Effect<B, E2, R>\n ): Effect.Effect<Exit.Exit<B, E | E2>, never, R>\n} = dual(2, <A, E, B, E2, R>(\n self: Exit.Exit<A, E>,\n f: (a: A) => Effect.Effect<B, E2, R>\n): Effect.Effect<Exit.Exit<B, E | E2>, never, R> => {\n switch (self._tag) {\n case OpCodes.OP_FAILURE: {\n return succeed(exitFailCause(self.effect_instruction_i0))\n }\n case OpCodes.OP_SUCCESS: {\n return exit(f(self.effect_instruction_i0))\n }\n }\n})\n\n/** @internal */\nexport const exitFromEither = <R, L>(either: Either.Either<R, L>): Exit.Exit<R, L> => {\n switch (either._tag) {\n case \"Left\":\n return exitFail(either.left)\n case \"Right\":\n return exitSucceed(either.right)\n }\n}\n\n/** @internal */\nexport const exitFromOption = <A>(option: Option.Option<A>): Exit.Exit<A, void> => {\n switch (option._tag) {\n case \"None\":\n return exitFail(void 0)\n case \"Some\":\n return exitSucceed(option.value)\n }\n}\n\n/** @internal */\nexport const exitGetOrElse = dual<\n <E, A2>(orElse: (cause: Cause.Cause<E>) => A2) => <A>(self: Exit.Exit<A, E>) => A | A2,\n <A, E, A2>(self: Exit.Exit<A, E>, orElse: (cause: Cause.Cause<E>) => A2) => A | A2\n>(2, (self, orElse) => {\n switch (self._tag) {\n case OpCodes.OP_FAILURE:\n return orElse(self.effect_instruction_i0)\n case OpCodes.OP_SUCCESS:\n return self.effect_instruction_i0\n }\n})\n\n/** @internal */\nexport const exitInterrupt = (fiberId: FiberId.FiberId): Exit.Exit<never> =>\n exitFailCause(internalCause.interrupt(fiberId))\n\n/** @internal */\nexport const exitMap = dual<\n <A, B>(f: (a: A) => B) => <E>(self: Exit.Exit<A, E>) => Exit.Exit<B, E>,\n <A, E, B>(self: Exit.Exit<A, E>, f: (a: A) => B) => Exit.Exit<B, E>\n>(2, (self, f) => {\n switch (self._tag) {\n case OpCodes.OP_FAILURE:\n return exitFailCause(self.effect_instruction_i0)\n case OpCodes.OP_SUCCESS:\n return exitSucceed(f(self.effect_instruction_i0))\n }\n})\n\n/** @internal */\nexport const exitMapBoth = dual<\n <E, A, E2, A2>(\n options: {\n readonly onFailure: (e: E) => E2\n readonly onSuccess: (a: A) => A2\n }\n ) => (self: Exit.Exit<A, E>) => Exit.Exit<A2, E2>,\n <A, E, E2, A2>(\n self: Exit.Exit<A, E>,\n options: {\n readonly onFailure: (e: E) => E2\n readonly onSuccess: (a: A) => A2\n }\n ) => Exit.Exit<A2, E2>\n>(2, (self, { onFailure, onSuccess }) => {\n switch (self._tag) {\n case OpCodes.OP_FAILURE:\n return exitFailCause(pipe(self.effect_instruction_i0, internalCause.map(onFailure)))\n case OpCodes.OP_SUCCESS:\n return exitSucceed(onSuccess(self.effect_instruction_i0))\n }\n})\n\n/** @internal */\nexport const exitMapError = dual<\n <E, E2>(f: (e: E) => E2) => <A>(self: Exit.Exit<A, E>) => Exit.Exit<A, E2>,\n <A, E, E2>(self: Exit.Exit<A, E>, f: (e: E) => E2) => Exit.Exit<A, E2>\n>(2, (self, f) => {\n switch (self._tag) {\n case OpCodes.OP_FAILURE:\n return exitFailCause(pipe(self.effect_instruction_i0, internalCause.map(f)))\n case OpCodes.OP_SUCCESS:\n return exitSucceed(self.effect_instruction_i0)\n }\n})\n\n/** @internal */\nexport const exitMapErrorCause = dual<\n <E, E2>(f: (cause: Cause.Cause<E>) => Cause.Cause<E2>) => <A>(self: Exit.Exit<A, E>) => Exit.Exit<A, E2>,\n <E, A, E2>(self: Exit.Exit<A, E>, f: (cause: Cause.Cause<E>) => Cause.Cause<E2>) => Exit.Exit<A, E2>\n>(2, (self, f) => {\n switch (self._tag) {\n case OpCodes.OP_FAILURE:\n return exitFailCause(f(self.effect_instruction_i0))\n case OpCodes.OP_SUCCESS:\n return exitSucceed(self.effect_instruction_i0)\n }\n})\n\n/** @internal */\nexport const exitMatch = dual<\n <E, A, Z1, Z2>(options: {\n readonly onFailure: (cause: Cause.Cause<E>) => Z1\n readonly onSuccess: (a: A) => Z2\n }) => (self: Exit.Exit<A, E>) => Z1 | Z2,\n <A, E, Z1, Z2>(self: Exit.Exit<A, E>, options: {\n readonly onFailure: (cause: Cause.Cause<E>) => Z1\n readonly onSuccess: (a: A) => Z2\n }) => Z1 | Z2\n>(2, (self, { onFailure, onSuccess }) => {\n switch (self._tag) {\n case OpCodes.OP_FAILURE:\n return onFailure(self.effect_instruction_i0)\n case OpCodes.OP_SUCCESS:\n return onSuccess(self.effect_instruction_i0)\n }\n})\n\n/** @internal */\nexport const exitMatchEffect = dual<\n <E, A2, E2, R, A, A3, E3, R2>(\n options: {\n readonly onFailure: (cause: Cause.Cause<E>) => Effect.Effect<A2, E2, R>\n readonly onSuccess: (a: A) => Effect.Effect<A3, E3, R2>\n }\n ) => (self: Exit.Exit<A, E>) => Effect.Effect<A2 | A3, E2 | E3, R | R2>,\n <A, E, A2, E2, R, A3, E3, R2>(\n self: Exit.Exit<A, E>,\n options: {\n readonly onFailure: (cause: Cause.Cause<E>) => Effect.Effect<A2, E2, R>\n readonly onSuccess: (a: A) => Effect.Effect<A3, E3, R2>\n }\n ) => Effect.Effect<A2 | A3, E2 | E3, R | R2>\n>(2, (self, { onFailure, onSuccess }) => {\n switch (self._tag) {\n case OpCodes.OP_FAILURE:\n return onFailure(self.effect_instruction_i0)\n case OpCodes.OP_SUCCESS:\n return onSuccess(self.effect_instruction_i0)\n }\n})\n\n/** @internal */\nexport const exitSucceed = <A>(value: A): Exit.Exit<A> => {\n const effect = new EffectPrimitiveSuccess(OpCodes.OP_SUCCESS) as any\n effect.effect_instruction_i0 = value\n return effect\n}\n\n/** @internal */\nexport const exitVoid: Exit.Exit<void> = exitSucceed(void 0)\n\n/** @internal */\nexport const exitZip = dual<\n <A2, E2>(that: Exit.Exit<A2, E2>) => <A, E>(self: Exit.Exit<A, E>) => Exit.Exit<[A, A2], E | E2>,\n <A, E, A2, E2>(self: Exit.Exit<A, E>, that: Exit.Exit<A2, E2>) => Exit.Exit<[A, A2], E | E2>\n>(2, (self, that) =>\n exitZipWith(self, that, {\n onSuccess: (a, a2) => [a, a2],\n onFailure: internalCause.sequential\n }))\n\n/** @internal */\nexport const exitZipLeft = dual<\n <A2, E2>(that: Exit.Exit<A2, E2>) => <A, E>(self: Exit.Exit<A, E>) => Exit.Exit<A, E | E2>,\n <A, E, A2, E2>(self: Exit.Exit<A, E>, that: Exit.Exit<A2, E2>) => Exit.Exit<A, E | E2>\n>(2, (self, that) =>\n exitZipWith(self, that, {\n onSuccess: (a, _) => a,\n onFailure: internalCause.sequential\n }))\n\n/** @internal */\nexport const exitZipRight = dual<\n <A2, E2>(that: Exit.Exit<A2, E2>) => <A, E>(self: Exit.Exit<A, E>) => Exit.Exit<A2, E | E2>,\n <A, E, A2, E2>(self: Exit.Exit<A, E>, that: Exit.Exit<A2, E2>) => Exit.Exit<A2, E | E2>\n>(2, (self, that) =>\n exitZipWith(self, that, {\n onSuccess: (_, a2) => a2,\n onFailure: internalCause.sequential\n }))\n\n/** @internal */\nexport const exitZipPar = dual<\n <A2, E2>(that: Exit.Exit<A2, E2>) => <A, E>(self: Exit.Exit<A, E>) => Exit.Exit<[A, A2], E | E2>,\n <A, E, A2, E2>(self: Exit.Exit<A, E>, that: Exit.Exit<A2, E2>) => Exit.Exit<[A, A2], E | E2>\n>(2, (self, that) =>\n exitZipWith(self, that, {\n onSuccess: (a, a2) => [a, a2],\n onFailure: internalCause.parallel\n }))\n\n/** @internal */\nexport const exitZipParLeft = dual<\n <A2, E2>(that: Exit.Exit<A2, E2>) => <A, E>(self: Exit.Exit<A, E>) => Exit.Exit<A, E | E2>,\n <A, E, A2, E2>(self: Exit.Exit<A, E>, that: Exit.Exit<A2, E2>) => Exit.Exit<A, E | E2>\n>(2, (self, that) =>\n exitZipWith(self, that, {\n onSuccess: (a, _) => a,\n onFailure: internalCause.parallel\n }))\n\n/** @internal */\nexport const exitZipParRight = dual<\n <A2, E2>(that: Exit.Exit<A2, E2>) => <A, E>(self: Exit.Exit<A, E>) => Exit.Exit<A2, E | E2>,\n <A, E, A2, E2>(self: Exit.Exit<A, E>, that: Exit.Exit<A2, E2>) => Exit.Exit<A2, E | E2>\n>(2, (self, that) =>\n exitZipWith(self, that, {\n onSuccess: (_, a2) => a2,\n onFailure: internalCause.parallel\n }))\n\n/** @internal */\nexport const exitZipWith = dual<\n <B, E2, A, C, E>(\n that: Exit.Exit<B, E2>,\n options: {\n readonly onSuccess: (a: A, b: B) => C\n readonly onFailure: (cause: Cause.Cause<E>, cause2: Cause.Cause<E2>) => Cause.Cause<E | E2>\n }\n ) => (self: Exit.Exit<A, E>) => Exit.Exit<C, E | E2>,\n <A, E, B, E2, C>(\n self: Exit.Exit<A, E>,\n that: Exit.Exit<B, E2>,\n options: {\n readonly onSuccess: (a: A, b: B) => C\n readonly onFailure: (cause: Cause.Cause<E>, cause2: Cause.Cause<E2>) => Cause.Cause<E | E2>\n }\n ) => Exit.Exit<C, E | E2>\n>(3, (\n self,\n that,\n { onFailure, onSuccess }\n) => {\n switch (self._tag) {\n case OpCodes.OP_FAILURE: {\n switch (that._tag) {\n case OpCodes.OP_SUCCESS:\n return exitFailCause(self.effect_instruction_i0)\n case OpCodes.OP_FAILURE: {\n return exitFailCause(onFailure(self.effect_instruction_i0, that.effect_instruction_i0))\n }\n }\n }\n case OpCodes.OP_SUCCESS: {\n switch (that._tag) {\n case OpCodes.OP_SUCCESS:\n return exitSucceed(onSuccess(self.effect_instruction_i0, that.effect_instruction_i0))\n case OpCodes.OP_FAILURE:\n return exitFailCause(that.effect_instruction_i0)\n }\n }\n }\n})\n\nconst exitCollectAllInternal = <A, E>(\n exits: Iterable<Exit.Exit<A, E>>,\n combineCauses: (causeA: Cause.Cause<E>, causeB: Cause.Cause<E>) => Cause.Cause<E>\n): Option.Option<Exit.Exit<Array<A>, E>> => {\n const list = Chunk.fromIterable(exits)\n if (!Chunk.isNonEmpty(list)) {\n return Option.none()\n }\n return pipe(\n Chunk.tailNonEmpty(list),\n Arr.reduce(\n pipe(Chunk.headNonEmpty(list), exitMap<A, Chunk.Chunk<A>>(Chunk.of)),\n (accumulator, current) =>\n pipe(\n accumulator,\n exitZipWith(current, {\n onSuccess: (list, value) => pipe(list, Chunk.prepend(value)),\n onFailure: combineCauses\n })\n )\n ),\n exitMap(Chunk.reverse),\n exitMap((chunk) => Chunk.toReadonlyArray(chunk) as Array<A>),\n Option.some\n )\n}\n\n// -----------------------------------------------------------------------------\n// Deferred\n// -----------------------------------------------------------------------------\n\n/** @internal */\nexport const deferredUnsafeMake = <A, E = never>(fiberId: FiberId.FiberId): Deferred.Deferred<A, E> => {\n const _deferred = {\n ...CommitPrototype,\n [deferred.DeferredTypeId]: deferred.deferredVariance,\n state: MutableRef.make(deferred.pending<A, E>([])),\n commit() {\n return deferredAwait(this)\n },\n blockingOn: fiberId\n }\n return _deferred\n}\n\n/* @internal */\nexport const deferredMake = <A, E = never>(): Effect.Effect<Deferred.Deferred<A, E>> =>\n flatMap(fiberId, (id) => deferredMakeAs<A, E>(id))\n\n/* @internal */\nexport const deferredMakeAs = <A, E = never>(fiberId: FiberId.FiberId): Effect.Effect<Deferred.Deferred<A, E>> =>\n sync(() => deferredUnsafeMake<A, E>(fiberId))\n\n/* @internal */\nexport const deferredAwait = <A, E>(self: Deferred.Deferred<A, E>): Effect.Effect<A, E> =>\n asyncInterrupt<A, E>((resume) => {\n const state = MutableRef.get(self.state)\n switch (state._tag) {\n case DeferredOpCodes.OP_STATE_DONE: {\n return resume(state.effect)\n }\n case DeferredOpCodes.OP_STATE_PENDING: {\n // we can push here as the internal state is mutable\n state.joiners.push(resume)\n return deferredInterruptJoiner(self, resume)\n }\n }\n }, self.blockingOn)\n\n/* @internal */\nexport const deferredComplete: {\n <A, E>(effect: Effect.Effect<A, E>): (self: Deferred.Deferred<A, E>) => Effect.Effect<boolean>\n <A, E>(self: Deferred.Deferred<A, E>, effect: Effect.Effect<A, E>): Effect.Effect<boolean>\n} = dual(\n 2,\n <A, E>(self: Deferred.Deferred<A, E>, effect: Effect.Effect<A, E>): Effect.Effect<boolean> =>\n intoDeferred(effect, self)\n)\n\n/* @internal */\nexport const deferredCompleteWith = dual<\n <A, E>(effect: Effect.Effect<A, E>) => (self: Deferred.Deferred<A, E>) => Effect.Effect<boolean>,\n <A, E>(self: Deferred.Deferred<A, E>, effect: Effect.Effect<A, E>) => Effect.Effect<boolean>\n>(2, (self, effect) =>\n sync(() => {\n const state = MutableRef.get(self.state)\n switch (state._tag) {\n case DeferredOpCodes.OP_STATE_DONE: {\n return false\n }\n case DeferredOpCodes.OP_STATE_PENDING: {\n MutableRef.set(self.state, deferred.done(effect))\n for (let i = 0, len = state.joiners.length; i < len; i++) {\n state.joiners[i](effect)\n }\n return true\n }\n }\n }))\n\n/* @internal */\nexport const deferredDone = dual<\n <A, E>(exit: Exit.Exit<A, E>) => (self: Deferred.Deferred<A, E>) => Effect.Effect<boolean>,\n <A, E>(self: Deferred.Deferred<A, E>, exit: Exit.Exit<A, E>) => Effect.Effect<boolean>\n>(2, (self, exit) => deferredCompleteWith(self, exit))\n\n/* @internal */\nexport const deferredFail = dual<\n <E>(error: E) => <A>(self: Deferred.Deferred<A, E>) => Effect.Effect<boolean>,\n <A, E>(self: Deferred.Deferred<A, E>, error: E) => Effect.Effect<boolean>\n>(2, (self, error) => deferredCompleteWith(self, fail(error)))\n\n/* @internal */\nexport const deferredFailSync = dual<\n <E>(evaluate: LazyArg<E>) => <A>(self: Deferred.Deferred<A, E>) => Effect.Effect<boolean>,\n <A, E>(self: Deferred.Deferred<A, E>, evaluate: LazyArg<E>) => Effect.Effect<boolean>\n>(2, (self, evaluate) => deferredCompleteWith(self, failSync(evaluate)))\n\n/* @internal */\nexport const deferredFailCause = dual<\n <E>(cause: Cause.Cause<E>) => <A>(self: Deferred.Deferred<A, E>) => Effect.Effect<boolean>,\n <A, E>(self: Deferred.Deferred<A, E>, cause: Cause.Cause<E>) => Effect.Effect<boolean>\n>(2, (self, cause) => deferredCompleteWith(self, failCause(cause)))\n\n/* @internal */\nexport const deferredFailCauseSync = dual<\n <E>(evaluate: LazyArg<Cause.Cause<E>>) => <A>(self: Deferred.Deferred<A, E>) => Effect.Effect<boolean>,\n <A, E>(self: Deferred.Deferred<A, E>, evaluate: LazyArg<Cause.Cause<E>>) => Effect.Effect<boolean>\n>(2, (self, evaluate) => deferredCompleteWith(self, failCauseSync(evaluate)))\n\n/* @internal */\nexport const deferredDie = dual<\n (defect: unknown) => <A, E>(self: Deferred.Deferred<A, E>) => Effect.Effect<boolean>,\n <A, E>(self: Deferred.Deferred<A, E>, defect: unknown) => Effect.Effect<boolean>\n>(2, (self, defect) => deferredCompleteWith(self, die(defect)))\n\n/* @internal */\nexport const deferredDieSync = dual<\n (evaluate: LazyArg<unknown>) => <A, E>(self: Deferred.Deferred<A, E>) => Effect.Effect<boolean>,\n <A, E>(self: Deferred.Deferred<A, E>, evaluate: LazyArg<unknown>) => Effect.Effect<boolean>\n>(2, (self, evaluate) => deferredCompleteWith(self, dieSync(evaluate)))\n\n/* @internal */\nexport const deferredInterrupt = <A, E>(self: Deferred.Deferred<A, E>): Effect.Effect<boolean> =>\n flatMap(fiberId, (fiberId) => deferredCompleteWith(self, interruptWith(fiberId)))\n\n/* @internal */\nexport const deferredInterruptWith = dual<\n (fiberId: FiberId.FiberId) => <A, E>(self: Deferred.Deferred<A, E>) => Effect.Effect<boolean>,\n <A, E>(self: Deferred.Deferred<A, E>, fiberId: FiberId.FiberId) => Effect.Effect<boolean>\n>(2, (self, fiberId) => deferredCompleteWith(self, interruptWith(fiberId)))\n\n/* @internal */\nexport const deferredIsDone = <A, E>(self: Deferred.Deferred<A, E>): Effect.Effect<boolean> =>\n sync(() => MutableRef.get(self.state)._tag === DeferredOpCodes.OP_STATE_DONE)\n\n/* @internal */\nexport const deferredPoll = <A, E>(\n self: Deferred.Deferred<A, E>\n): Effect.Effect<Option.Option<Effect.Effect<A, E>>> =>\n sync(() => {\n const state = MutableRef.get(self.state)\n switch (state._tag) {\n case DeferredOpCodes.OP_STATE_DONE: {\n return Option.some(state.effect)\n }\n case DeferredOpCodes.OP_STATE_PENDING: {\n return Option.none()\n }\n }\n })\n\n/* @internal */\nexport const deferredSucceed = dual<\n <A>(value: A) => <E>(self: Deferred.Deferred<A, E>) => Effect.Effect<boolean>,\n <A, E>(self: Deferred.Deferred<A, E>, value: A) => Effect.Effect<boolean>\n>(2, (self, value) => deferredCompleteWith(self, succeed(value)))\n\n/* @internal */\nexport const deferredSync = dual<\n <A>(evaluate: LazyArg<A>) => <E>(self: Deferred.Deferred<A, E>) => Effect.Effect<boolean>,\n <A, E>(self: Deferred.Deferred<A, E>, evaluate: LazyArg<A>) => Effect.Effect<boolean>\n>(2, (self, evaluate) => deferredCompleteWith(self, sync(evaluate)))\n\n/** @internal */\nexport const deferredUnsafeDone = <A, E>(self: Deferred.Deferred<A, E>, effect: Effect.Effect<A, E>): void => {\n const state = MutableRef.get(self.state)\n if (state._tag === DeferredOpCodes.OP_STATE_PENDING) {\n MutableRef.set(self.state, deferred.done(effect))\n for (let i = 0, len = state.joiners.length; i < len; i++) {\n state.joiners[i](effect)\n }\n }\n}\n\nconst deferredInterruptJoiner = <A, E>(\n self: Deferred.Deferred<A, E>,\n joiner: (effect: Effect.Effect<A, E>) => void\n): Effect.Effect<void> =>\n sync(() => {\n const state = MutableRef.get(self.state)\n if (state._tag === DeferredOpCodes.OP_STATE_PENDING) {\n const index = state.joiners.indexOf(joiner)\n if (index >= 0) {\n // we can splice here as the internal state is mutable\n state.joiners.splice(index, 1)\n }\n }\n })\n\n// -----------------------------------------------------------------------------\n// Context\n// -----------------------------------------------------------------------------\n\nconst constContext = withFiberRuntime((fiber) => exitSucceed(fiber.currentContext))\n\n/* @internal */\nexport const context = <R>(): Effect.Effect<Context.Context<R>, never, R> => constContext as any\n\n/* @internal */\nexport const contextWith = <R0, A>(\n f: (context: Context.Context<R0>) => A\n): Effect.Effect<A, never, R0> => map(context<R0>(), f)\n\n/* @internal */\nexport const contextWithEffect = <R2, A, E, R>(\n f: (context: Context.Context<R2>) => Effect.Effect<A, E, R>\n): Effect.Effect<A, E, R | R2> => flatMap(context<R2>(), f)\n\n/* @internal */\nexport const provideContext = dual<\n <R>(context: Context.Context<R>) => <A, E>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E>,\n <A, E, R>(self: Effect.Effect<A, E, R>, context: Context.Context<R>) => Effect.Effect<A, E>\n>(2, <A, E, R>(self: Effect.Effect<A, E, R>, context: Context.Context<R>) =>\n fiberRefLocally(\n currentContext,\n context\n )(self as Effect.Effect<A, E>))\n\n/* @internal */\nexport const provideSomeContext = dual<\n <R>(context: Context.Context<R>) => <A, E, R1>(self: Effect.Effect<A, E, R1>) => Effect.Effect<A, E, Exclude<R1, R>>,\n <A, E, R1, R>(self: Effect.Effect<A, E, R1>, context: Context.Context<R>) => Effect.Effect<A, E, Exclude<R1, R>>\n>(2, <A, E, R1, R>(self: Effect.Effect<A, E, R1>, context: Context.Context<R>) =>\n fiberRefLocallyWith(\n currentContext,\n (parent) => Context.merge(parent, context)\n )(self as Effect.Effect<A, E>))\n\n/* @internal */\nexport const mapInputContext = dual<\n <R2, R>(\n f: (context: Context.Context<R2>) => Context.Context<R>\n ) => <A, E>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R2>,\n <A, E, R, R2>(\n self: Effect.Effect<A, E, R>,\n f: (context: Context.Context<R2>) => Context.Context<R>\n ) => Effect.Effect<A, E, R2>\n>(2, <A, E, R, R2>(\n self: Effect.Effect<A, E, R>,\n f: (context: Context.Context<R2>) => Context.Context<R>\n) => contextWithEffect((context: Context.Context<R2>) => provideContext(self, f(context))))\n\n// -----------------------------------------------------------------------------\n// Tracing\n// -----------------------------------------------------------------------------\n\n/** @internal */\nexport const currentSpanFromFiber = <A, E>(fiber: Fiber.RuntimeFiber<A, E>): Option.Option<Tracer.Span> => {\n const span = fiber.currentSpan\n return span !== undefined && span._tag === \"Span\" ? Option.some(span) : Option.none()\n}\n\nconst NoopSpanProto: Omit<Tracer.Span, \"parent\" | \"name\" | \"context\"> = {\n _tag: \"Span\",\n spanId: \"noop\",\n traceId: \"noop\",\n sampled: false,\n status: {\n _tag: \"Ended\",\n startTime: BigInt(0),\n endTime: BigInt(0),\n exit: exitVoid\n },\n attributes: new Map(),\n links: [],\n kind: \"internal\",\n attribute() {},\n event() {},\n end() {}\n}\n\n/** @internal */\nexport const noopSpan = (options: {\n readonly name: string\n readonly parent: Option.Option<Tracer.AnySpan>\n readonly context: Context.Context<never>\n}): Tracer.Span => Object.assign(Object.create(NoopSpanProto), options)\n","/**\n * @since 2.0.0\n */\nimport type * as Cause from \"./Cause.js\"\nimport * as core from \"./internal/core.js\"\nimport * as internal from \"./internal/data.js\"\nimport { StructuralPrototype } from \"./internal/effectable.js\"\nimport * as Predicate from \"./Predicate.js\"\nimport type * as Types from \"./Types.js\"\nimport type { Unify } from \"./Unify.js\"\n\n/**\n * @since 2.0.0\n */\nexport declare namespace Case {\n /**\n * @since 2.0.0\n * @category models\n */\n export interface Constructor<A, Tag extends keyof A = never> {\n (\n args: Types.Equals<Omit<A, Tag>, {}> extends true ? void\n : { readonly [P in keyof A as P extends Tag ? never : P]: A[P] }\n ): A\n }\n}\n\n/**\n * @example\n * ```ts\n * import { Data, Equal } from \"effect\"\n *\n * const alice = Data.struct({ name: \"Alice\", age: 30 })\n *\n * const bob = Data.struct({ name: \"Bob\", age: 40 })\n *\n * assert.deepStrictEqual(Equal.equals(alice, alice), true)\n * assert.deepStrictEqual(Equal.equals(alice, Data.struct({ name: \"Alice\", age: 30 })), true)\n *\n * assert.deepStrictEqual(Equal.equals(alice, { name: \"Alice\", age: 30 }), false)\n * assert.deepStrictEqual(Equal.equals(alice, bob), false)\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const struct: <A extends Record<string, any>>(a: A) => { readonly [P in keyof A]: A[P] } = internal.struct\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const unsafeStruct = <A extends Record<string, any>>(as: A): { readonly [P in keyof A]: A[P] } =>\n Object.setPrototypeOf(as, StructuralPrototype)\n\n/**\n * @example\n * ```ts\n * import { Data, Equal } from \"effect\"\n *\n * const alice = Data.tuple(\"Alice\", 30)\n *\n * const bob = Data.tuple(\"Bob\", 40)\n *\n * assert.deepStrictEqual(Equal.equals(alice, alice), true)\n * assert.deepStrictEqual(Equal.equals(alice, Data.tuple(\"Alice\", 30)), true)\n *\n * assert.deepStrictEqual(Equal.equals(alice, [\"Alice\", 30]), false)\n * assert.deepStrictEqual(Equal.equals(alice, bob), false)\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const tuple = <As extends ReadonlyArray<any>>(...as: As): Readonly<As> => unsafeArray(as)\n\n/**\n * @example\n * ```ts\n * import { Data, Equal } from \"effect\"\n *\n * const alice = Data.struct({ name: \"Alice\", age: 30 })\n * const bob = Data.struct({ name: \"Bob\", age: 40 })\n *\n * const persons = Data.array([alice, bob])\n *\n * assert.deepStrictEqual(\n * Equal.equals(\n * persons,\n * Data.array([\n * Data.struct({ name: \"Alice\", age: 30 }),\n * Data.struct({ name: \"Bob\", age: 40 })\n * ])\n * ),\n * true\n * )\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const array = <As extends ReadonlyArray<any>>(as: As): Readonly<As> => unsafeArray(as.slice(0) as unknown as As)\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const unsafeArray = <As extends ReadonlyArray<any>>(as: As): Readonly<As> =>\n Object.setPrototypeOf(as, internal.ArrayProto)\n\nconst _case = <A>(): Case.Constructor<A> => (args) =>\n (args === undefined ? Object.create(StructuralPrototype) : struct(args)) as any\n\nexport {\n /**\n * Provides a constructor for the specified `Case`.\n *\n * @example\n * ```ts\n * import { Data, Equal } from \"effect\"\n *\n * interface Person {\n * readonly name: string\n * }\n *\n * // Creating a constructor for the specified Case\n * const Person = Data.case<Person>()\n *\n * // Creating instances of Person\n * const mike1 = Person({ name: \"Mike\" })\n * const mike2 = Person({ name: \"Mike\" })\n * const john = Person({ name: \"John\" })\n *\n * // Checking equality\n * assert.deepStrictEqual(Equal.equals(mike1, mike2), true)\n * assert.deepStrictEqual(Equal.equals(mike1, john), false)\n *\n * ```\n * @since 2.0.0\n * @category constructors\n */\n _case as case\n}\n\n/**\n * Provides a tagged constructor for the specified `Case`.\n *\n * @example\n * ```ts\n * import { Data } from \"effect\"\n *\n * interface Person {\n * readonly _tag: \"Person\" // the tag\n * readonly name: string\n * }\n *\n * const Person = Data.tagged<Person>(\"Person\")\n *\n * const mike = Person({ name: \"Mike\" })\n *\n * assert.deepEqual(mike, { _tag: \"Person\", name: \"Mike\" })\n * ```\n *\n * @since 2.0.0\n * @category constructors\n */\nexport const tagged = <A extends { readonly _tag: string }>(\n tag: A[\"_tag\"]\n): Case.Constructor<A, \"_tag\"> =>\n(args) => {\n const value = args === undefined ? Object.create(StructuralPrototype) : struct(args)\n value._tag = tag\n return value\n}\n\n/**\n * Provides a constructor for a Case Class.\n *\n * @example\n * ```ts\n * import { Data, Equal } from \"effect\"\n *\n * class Person extends Data.Class<{ readonly name: string }> {}\n *\n * // Creating instances of Person\n * const mike1 = new Person({ name: \"Mike\" })\n * const mike2 = new Person({ name: \"Mike\" })\n * const john = new Person({ name: \"John\" })\n *\n * // Checking equality\n * assert.deepStrictEqual(Equal.equals(mike1, mike2), true)\n * assert.deepStrictEqual(Equal.equals(mike1, john), false)\n * ```\n *\n * @since 2.0.0\n * @category constructors\n */\nexport const Class: new<A extends Record<string, any> = {}>(\n args: Types.Equals<A, {}> extends true ? void\n : { readonly [P in keyof A]: A[P] }\n) => Readonly<A> = internal.Structural as any\n\n/**\n * Provides a Tagged constructor for a Case Class.\n *\n * @example\n * ```ts\n * import { Data, Equal } from \"effect\"\n *\n * class Person extends Data.TaggedClass(\"Person\")<{ readonly name: string }> {}\n *\n * // Creating instances of Person\n * const mike1 = new Person({ name: \"Mike\" })\n * const mike2 = new Person({ name: \"Mike\" })\n * const john = new Person({ name: \"John\" })\n *\n * // Checking equality\n * assert.deepStrictEqual(Equal.equals(mike1, mike2), true)\n * assert.deepStrictEqual(Equal.equals(mike1, john), false)\n *\n * assert.deepStrictEqual(mike1._tag, \"Person\")\n * ```\n *\n * @since 2.0.0\n * @category constructors\n */\nexport const TaggedClass = <Tag extends string>(\n tag: Tag\n): new<A extends Record<string, any> = {}>(\n args: Types.Equals<A, {}> extends true ? void\n : { readonly [P in keyof A as P extends \"_tag\" ? never : P]: A[P] }\n) => Readonly<A> & { readonly _tag: Tag } => {\n class Base extends Class<any> {\n readonly _tag = tag\n }\n return Base as any\n}\n\n/**\n * @since 2.0.0\n * @category constructors\n */\nexport const Structural: new<A>(\n args: Types.Equals<A, {}> extends true ? void\n : { readonly [P in keyof A]: A[P] }\n) => {} = internal.Structural as any\n\n/**\n * Create a tagged enum data type, which is a union of `Data` structs.\n *\n * ```ts\n * import { Data } from \"effect\"\n *\n * type HttpError = Data.TaggedEnum<{\n * BadRequest: { readonly status: 400, readonly message: string }\n * NotFound: { readonly status: 404, readonly message: string }\n * }>\n *\n * // Equivalent to:\n * type HttpErrorPlain =\n * | {\n * readonly _tag: \"BadRequest\"\n * readonly status: 400\n * readonly message: string\n * }\n * | {\n * readonly _tag: \"NotFound\"\n * readonly status: 404\n * readonly message: string\n * }\n * ```\n *\n * @since 2.0.0\n * @category models\n */\nexport type TaggedEnum<\n A extends Record<string, Record<string, any>> & UntaggedChildren<A>\n> = keyof A extends infer Tag ?\n Tag extends keyof A ? Types.Simplify<{ readonly _tag: Tag } & { readonly [K in keyof A[Tag]]: A[Tag][K] }>\n : never\n : never\n\ntype ChildrenAreTagged<A> = keyof A extends infer K ? K extends keyof A ? \"_tag\" extends keyof A[K] ? true\n : false\n : never\n : never\n\ntype UntaggedChildren<A> = true extends ChildrenAreTagged<A>\n ? \"It looks like you're trying to create a tagged enum, but one or more of its members already has a `_tag` property.\"\n : unknown\n\n/**\n * @since 2.0.0\n */\nexport declare namespace TaggedEnum {\n /**\n * @since 2.0.0\n * @category models\n */\n export interface WithGenerics<Count extends number> {\n readonly taggedEnum: { readonly _tag: string }\n readonly numberOfGenerics: Count\n\n readonly A: unknown\n readonly B: unknown\n readonly C: unknown\n readonly D: unknown\n }\n\n /**\n * @since 2.0.0\n * @category models\n */\n export type Kind<\n Z extends WithGenerics<number>,\n A = unknown,\n B = unknown,\n C = unknown,\n D = unknown\n > = (Z & {\n readonly A: A\n readonly B: B\n readonly C: C\n readonly D: D\n })[\"taggedEnum\"]\n\n /**\n * @since 2.0.0\n */\n export type Args<\n A extends { readonly _tag: string },\n K extends A[\"_tag\"],\n E = Extract<A, { readonly _tag: K }>\n > = { readonly [K in keyof E as K extends \"_tag\" ? never : K]: E[K] } extends infer T ? {} extends T ? void : T\n : never\n\n /**\n * @since 2.0.0\n */\n export type Value<\n A extends { readonly _tag: string },\n K extends A[\"_tag\"]\n > = Extract<A, { readonly _tag: K }>\n\n /**\n * @since 3.1.0\n */\n export type Constructor<A extends { readonly _tag: string }> = Types.Simplify<\n & {\n readonly [Tag in A[\"_tag\"]]: Case.Constructor<Extract<A, { readonly _tag: Tag }>, \"_tag\">\n }\n & {\n readonly $is: <Tag extends A[\"_tag\"]>(tag: Tag) => (u: unknown) => u is Extract<A, { readonly _tag: Tag }>\n readonly $match: {\n <\n Cases extends {\n readonly [Tag in A[\"_tag\"]]: (args: Extract<A, { readonly _tag: Tag }>) => any\n }\n >(cases: Cases): (value: A) => Unify<ReturnType<Cases[A[\"_tag\"]]>>\n <\n Cases extends {\n readonly [Tag in A[\"_tag\"]]: (args: Extract<A, { readonly _tag: Tag }>) => any\n }\n >(value: A, cases: Cases): Unify<ReturnType<Cases[A[\"_tag\"]]>>\n }\n }\n >\n\n /**\n * @since 3.2.0\n */\n export interface GenericMatchers<Z extends WithGenerics<number>> {\n readonly $is: <Tag extends Z[\"taggedEnum\"][\"_tag\"]>(\n tag: Tag\n ) => {\n <T extends TaggedEnum.Kind<Z, any, any, any, any>>(\n u: T\n ): u is T & { readonly _tag: Tag }\n (u: unknown): u is Extract<TaggedEnum.Kind<Z>, { readonly _tag: Tag }>\n }\n readonly $match: {\n <\n A,\n B,\n C,\n D,\n Cases extends {\n readonly [Tag in Z[\"taggedEnum\"][\"_tag\"]]: (\n args: Extract<TaggedEnum.Kind<Z, A, B, C, D>, { readonly _tag: Tag }>\n ) => any\n }\n >(\n cases: Cases\n ): (self: TaggedEnum.Kind<Z, A, B, C, D>) => Unify<ReturnType<Cases[Z[\"taggedEnum\"][\"_tag\"]]>>\n <\n A,\n B,\n C,\n D,\n Cases extends {\n readonly [Tag in Z[\"taggedEnum\"][\"_tag\"]]: (\n args: Extract<TaggedEnum.Kind<Z, A, B, C, D>, { readonly _tag: Tag }>\n ) => any\n }\n >(\n self: TaggedEnum.Kind<Z, A, B, C, D>,\n cases: Cases\n ): Unify<ReturnType<Cases[Z[\"taggedEnum\"][\"_tag\"]]>>\n }\n }\n}\n\n/**\n * Create a constructor for a tagged union of `Data` structs.\n *\n * You can also pass a `TaggedEnum.WithGenerics` if you want to add generics to\n * the constructor.\n *\n * @example\n * ```ts\n * import { Data } from \"effect\"\n *\n * const { BadRequest, NotFound } = Data.taggedEnum<\n * | { readonly _tag: \"BadRequest\"; readonly status: 400; readonly message: string }\n * | { readonly _tag: \"NotFound\"; readonly status: 404; readonly message: string }\n * >()\n *\n * const notFound = NotFound({ status: 404, message: \"Not Found\" })\n * ```\n *\n * @example\n * import { Data } from \"effect\"\n *\n * type MyResult<E, A> = Data.TaggedEnum<{\n * Failure: { readonly error: E }\n * Success: { readonly value: A }\n * }>\n * interface MyResultDefinition extends Data.TaggedEnum.WithGenerics<2> {\n * readonly taggedEnum: MyResult<this[\"A\"], this[\"B\"]>\n * }\n * const { Failure, Success } = Data.taggedEnum<MyResultDefinition>()\n *\n * const success = Success({ value: 1 })\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const taggedEnum: {\n /**\n * Create a constructor for a tagged union of `Data` structs.\n *\n * You can also pass a `TaggedEnum.WithGenerics` if you want to add generics to\n * the constructor.\n *\n * @example\n * ```ts\n * import { Data } from \"effect\"\n *\n * const { BadRequest, NotFound } = Data.taggedEnum<\n * | { readonly _tag: \"BadRequest\"; readonly status: 400; readonly message: string }\n * | { readonly _tag: \"NotFound\"; readonly status: 404; readonly message: string }\n * >()\n *\n * const notFound = NotFound({ status: 404, message: \"Not Found\" })\n * ```\n *\n * @example\n * import { Data } from \"effect\"\n *\n * type MyResult<E, A> = Data.TaggedEnum<{\n * Failure: { readonly error: E }\n * Success: { readonly value: A }\n * }>\n * interface MyResultDefinition extends Data.TaggedEnum.WithGenerics<2> {\n * readonly taggedEnum: MyResult<this[\"A\"], this[\"B\"]>\n * }\n * const { Failure, Success } = Data.taggedEnum<MyResultDefinition>()\n *\n * const success = Success({ value: 1 })\n *\n * @category constructors\n * @since 2.0.0\n */\n <Z extends TaggedEnum.WithGenerics<1>>(): Types.Simplify<\n {\n readonly [Tag in Z[\"taggedEnum\"][\"_tag\"]]: <A>(\n args: TaggedEnum.Args<\n TaggedEnum.Kind<Z, A>,\n Tag,\n Extract<TaggedEnum.Kind<Z, A>, { readonly _tag: Tag }>\n >\n ) => TaggedEnum.Value<TaggedEnum.Kind<Z, A>, Tag>\n } & TaggedEnum.GenericMatchers<Z>\n >\n\n /**\n * Create a constructor for a tagged union of `Data` structs.\n *\n * You can also pass a `TaggedEnum.WithGenerics` if you want to add generics to\n * the constructor.\n *\n * @example\n * ```ts\n * import { Data } from \"effect\"\n *\n * const { BadRequest, NotFound } = Data.taggedEnum<\n * | { readonly _tag: \"BadRequest\"; readonly status: 400; readonly message: string }\n * | { readonly _tag: \"NotFound\"; readonly status: 404; readonly message: string }\n * >()\n *\n * const notFound = NotFound({ status: 404, message: \"Not Found\" })\n * ```\n *\n * @example\n * import { Data } from \"effect\"\n *\n * type MyResult<E, A> = Data.TaggedEnum<{\n * Failure: { readonly error: E }\n * Success: { readonly value: A }\n * }>\n * interface MyResultDefinition extends Data.TaggedEnum.WithGenerics<2> {\n * readonly taggedEnum: MyResult<this[\"A\"], this[\"B\"]>\n * }\n * const { Failure, Success } = Data.taggedEnum<MyResultDefinition>()\n *\n * const success = Success({ value: 1 })\n *\n * @category constructors\n * @since 2.0.0\n */\n <Z extends TaggedEnum.WithGenerics<2>>(): Types.Simplify<\n {\n readonly [Tag in Z[\"taggedEnum\"][\"_tag\"]]: <A, B>(\n args: TaggedEnum.Args<\n TaggedEnum.Kind<Z, A, B>,\n Tag,\n Extract<TaggedEnum.Kind<Z, A, B>, { readonly _tag: Tag }>\n >\n ) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B>, Tag>\n } & TaggedEnum.GenericMatchers<Z>\n >\n\n /**\n * Create a constructor for a tagged union of `Data` structs.\n *\n * You can also pass a `TaggedEnum.WithGenerics` if you want to add generics to\n * the constructor.\n *\n * @example\n * ```ts\n * import { Data } from \"effect\"\n *\n * const { BadRequest, NotFound } = Data.taggedEnum<\n * | { readonly _tag: \"BadRequest\"; readonly status: 400; readonly message: string }\n * | { readonly _tag: \"NotFound\"; readonly status: 404; readonly message: string }\n * >()\n *\n * const notFound = NotFound({ status: 404, message: \"Not Found\" })\n * ```\n *\n * @example\n * import { Data } from \"effect\"\n *\n * type MyResult<E, A> = Data.TaggedEnum<{\n * Failure: { readonly error: E }\n * Success: { readonly value: A }\n * }>\n * interface MyResultDefinition extends Data.TaggedEnum.WithGenerics<2> {\n * readonly taggedEnum: MyResult<this[\"A\"], this[\"B\"]>\n * }\n * const { Failure, Success } = Data.taggedEnum<MyResultDefinition>()\n *\n * const success = Success({ value: 1 })\n *\n * @category constructors\n * @since 2.0.0\n */\n <Z extends TaggedEnum.WithGenerics<3>>(): Types.Simplify<\n {\n readonly [Tag in Z[\"taggedEnum\"][\"_tag\"]]: <A, B, C>(\n args: TaggedEnum.Args<\n TaggedEnum.Kind<Z, A, B, C>,\n Tag,\n Extract<TaggedEnum.Kind<Z, A, B, C>, { readonly _tag: Tag }>\n >\n ) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C>, Tag>\n } & TaggedEnum.GenericMatchers<Z>\n >\n\n /**\n * Create a constructor for a tagged union of `Data` structs.\n *\n * You can also pass a `TaggedEnum.WithGenerics` if you want to add generics to\n * the constructor.\n *\n * @example\n * ```ts\n * import { Data } from \"effect\"\n *\n * const { BadRequest, NotFound } = Data.taggedEnum<\n * | { readonly _tag: \"BadRequest\"; readonly status: 400; readonly message: string }\n * | { readonly _tag: \"NotFound\"; readonly status: 404; readonly message: string }\n * >()\n *\n * const notFound = NotFound({ status: 404, message: \"Not Found\" })\n * ```\n *\n * @example\n * import { Data } from \"effect\"\n *\n * type MyResult<E, A> = Data.TaggedEnum<{\n * Failure: { readonly error: E }\n * Success: { readonly value: A }\n * }>\n * interface MyResultDefinition extends Data.TaggedEnum.WithGenerics<2> {\n * readonly taggedEnum: MyResult<this[\"A\"], this[\"B\"]>\n * }\n * const { Failure, Success } = Data.taggedEnum<MyResultDefinition>()\n *\n * const success = Success({ value: 1 })\n *\n * @category constructors\n * @since 2.0.0\n */\n <Z extends TaggedEnum.WithGenerics<4>>(): Types.Simplify<\n {\n readonly [Tag in Z[\"taggedEnum\"][\"_tag\"]]: <A, B, C, D>(\n args: TaggedEnum.Args<\n TaggedEnum.Kind<Z, A, B, C, D>,\n Tag,\n Extract<TaggedEnum.Kind<Z, A, B, C, D>, { readonly _tag: Tag }>\n >\n ) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C, D>, Tag>\n } & TaggedEnum.GenericMatchers<Z>\n >\n\n /**\n * Create a constructor for a tagged union of `Data` structs.\n *\n * You can also pass a `TaggedEnum.WithGenerics` if you want to add generics to\n * the constructor.\n *\n * @example\n * ```ts\n * import { Data } from \"effect\"\n *\n * const { BadRequest, NotFound } = Data.taggedEnum<\n * | { readonly _tag: \"BadRequest\"; readonly status: 400; readonly message: string }\n * | { readonly _tag: \"NotFound\"; readonly status: 404; readonly message: string }\n * >()\n *\n * const notFound = NotFound({ status: 404, message: \"Not Found\" })\n * ```\n *\n * @example\n * import { Data } from \"effect\"\n *\n * type MyResult<E, A> = Data.TaggedEnum<{\n * Failure: { readonly error: E }\n * Success: { readonly value: A }\n * }>\n * interface MyResultDefinition extends Data.TaggedEnum.WithGenerics<2> {\n * readonly taggedEnum: MyResult<this[\"A\"], this[\"B\"]>\n * }\n * const { Failure, Success } = Data.taggedEnum<MyResultDefinition>()\n *\n * const success = Success({ value: 1 })\n *\n * @category constructors\n * @since 2.0.0\n */\n <A extends { readonly _tag: string }>(): TaggedEnum.Constructor<A>\n} = () =>\n new Proxy({}, {\n get(_target, tag, _receiver) {\n if (tag === \"$is\") {\n return Predicate.isTagged\n } else if (tag === \"$match\") {\n return taggedMatch\n }\n return tagged(tag as string)\n }\n }) as any\n\nfunction taggedMatch<\n A extends { readonly _tag: string },\n Cases extends {\n readonly [K in A[\"_tag\"]]: (args: Extract<A, { readonly _tag: K }>) => any\n }\n>(self: A, cases: Cases): ReturnType<Cases[A[\"_tag\"]]>\nfunction taggedMatch<\n A extends { readonly _tag: string },\n Cases extends {\n readonly [K in A[\"_tag\"]]: (args: Extract<A, { readonly _tag: K }>) => any\n }\n>(cases: Cases): (value: A) => ReturnType<Cases[A[\"_tag\"]]>\nfunction taggedMatch<\n A extends { readonly _tag: string },\n Cases extends {\n readonly [K in A[\"_tag\"]]: (args: Extract<A, { readonly _tag: K }>) => any\n }\n>(): any {\n if (arguments.length === 1) {\n const cases = arguments[0] as Cases\n return function(value: A): ReturnType<Cases[A[\"_tag\"]]> {\n return cases[value._tag as A[\"_tag\"]](value as any)\n }\n }\n const value = arguments[0] as A\n const cases = arguments[1] as Cases\n return cases[value._tag as A[\"_tag\"]](value as any)\n}\n\n/**\n * Provides a constructor for a Case Class.\n *\n * @since 2.0.0\n * @category constructors\n */\nexport const Error: new<A extends Record<string, any> = {}>(\n args: Types.Equals<A, {}> extends true ? void\n : { readonly [P in keyof A]: A[P] }\n) => Cause.YieldableError & Readonly<A> = (function() {\n const plainArgsSymbol = Symbol.for(\"effect/Data/Error/plainArgs\")\n return class Base extends core.YieldableError {\n constructor(args: any) {\n super(args?.message, args?.cause ? { cause: args.cause } : undefined)\n if (args) {\n Object.assign(this, args)\n Object.defineProperty(this, plainArgsSymbol, { value: args, enumerable: false })\n }\n }\n toJSON() {\n return { ...(this as any)[plainArgsSymbol], ...this }\n }\n } as any\n})()\n\n/**\n * @since 2.0.0\n * @category constructors\n */\nexport const TaggedError = <Tag extends string>(tag: Tag): new<A extends Record<string, any> = {}>(\n args: Types.Equals<A, {}> extends true ? void\n : { readonly [P in keyof A as P extends \"_tag\" ? never : P]: A[P] }\n) => Cause.YieldableError & { readonly _tag: Tag } & Readonly<A> => {\n class Base extends Error<{}> {\n readonly _tag = tag\n }\n ;(Base.prototype as any).name = tag\n return Base as any\n}\n","import * as ReadonlyArray from \"effect/Array\"\nimport * as Data from \"effect/Data\"\nimport * as Either from \"effect/Either\"\nimport { dual, pipe } from \"effect/Function\"\nimport type { TypeLambda } from \"effect/HKT\"\nimport * as Option from \"effect/Option\"\nimport * as Gen from \"effect/Utils\"\n\nexport class NanoInterruptedException extends Data.TaggedError(\"NanoInterruptedException\")<{}> {}\nexport class NanoDefectException\n extends Data.TaggedError(\"NanoDefectException\")<{ value: unknown }>\n{}\n\nexport class NanoTag<R> {\n declare \"~nano.requirements\": R\n constructor(\n readonly key: string\n ) {}\n}\n\nexport const Tag = <I>(identifier: string) => new NanoTag<I>(identifier)\n\ntype NanoContext<R = never> = {\n _R: R\n value: Record<string, unknown>\n}\n\nexport const contextEmpty: NanoContext<never> = { value: {} } as any\nexport const contextAdd = <R, I extends NanoTag<any>>(\n context: NanoContext<R>,\n tag: I,\n value: I[\"~nano.requirements\"]\n): NanoContext<R | I> => ({\n ...context,\n value: {\n ...context.value,\n [tag.key]: value\n }\n})\nexport const contextGet = <R, I extends NanoTag<any>>(\n context: NanoContext<R | I>,\n tag: I\n): Option.Option<I[\"~nano.requirements\"]> => {\n if (tag.key in context.value) {\n return Option.some(context.value[tag.key] as I[\"~nano.requirements\"])\n }\n return Option.none()\n}\nexport const contextMerge = <R, R2>(\n old: NanoContext<R>,\n newContext: NanoContext<R2>\n): NanoContext<R | R2> => ({ ...old, value: { ...old.value, ...newContext.value } })\n\nexport interface NanoIterator<T extends Nano<any, any, any>> {\n next(...args: ReadonlyArray<any>): IteratorResult<Gen.YieldWrap<T>, T[\"~nano.success\"]>\n}\n\n/**\n * Nano is a Effect-like interface to run things.\n * It is not intended to be used by users in production.\n * It's only a mere tool to be used in the Effect dev-tools\n * to provide a familiar effect-like experience in envs\n * where using full blown Effect will cause an Effect-in-Effect issue.\n * It is supposed to be sync only and not stack-safe.\n * Thrown exceptions are catched and converted into defects,\n * so worst case scenario, you will get only standard typescript lsp.\n */\nexport class Nano<out A, out E = never, out R = never> {\n declare readonly \"~nano.success\": A\n declare readonly \"~nano.error\": E\n declare readonly \"~nano.requirements\": R\n\n constructor(\n public readonly run: (\n ctx: NanoContext<unknown>\n ) => Either.Either<Either.Either<A, E>, NanoInterruptedException | NanoDefectException>\n ) {}\n\n [Symbol.iterator](): NanoIterator<Nano<A, E, R>> {\n return new Gen.SingleShotGen(new Gen.YieldWrap(this)) as any\n }\n}\n\nexport const run = <A, E>(fa: Nano<A, E, never>) =>\n pipe(\n Either.try({\n try: () => fa.run(contextEmpty),\n catch: (error) => (new NanoDefectException({ value: error }))\n }),\n Either.flatMap((_) => _),\n Either.flatMap((_) => _)\n )\n\nexport const succeed = <A>(value: A) => new Nano(() => (Either.right(Either.right(value))))\nexport const fail = <E>(value: E) => new Nano(() => Either.right(Either.left(value)))\nexport const sync = <A>(value: () => A) => new Nano(() => Either.right(Either.right(value())))\nexport const flatMap: {\n <A, B, E2, R2>(f: (a: A) => Nano<B, E2, R2>): <E, R>(fa: Nano<A, E, R>) => Nano<B, E | E2, R | R2>\n <A, E, R, B, E2, R2>(fa: Nano<A, E, R>, f: (a: A) => Nano<B, E2, R2>): Nano<B, E | E2, R | R2>\n} = dual(2, <A, E, R, B, E2, R2>(\n fa: Nano<A, E, R>,\n f: (a: A) => Nano<B, E2, R2>\n) =>\n new Nano<B, E | E2, R | R2>((ctx) => {\n const result = fa.run(ctx)\n if (Either.isLeft(result)) return result\n if (Either.isLeft(result.right)) return result\n return f(result.right.right).run(ctx) as any\n }))\n\nexport const map: {\n <A, B>(f: (a: A) => B): <E, R>(fa: Nano<A, E, R>) => Nano<B, E, R>\n <A, E, R, B>(fa: Nano<A, E, R>, f: (a: A) => B): Nano<B, E, R>\n} = dual(2, <A, E, R, B>(\n fa: Nano<A, E, R>,\n f: (a: A) => B\n) =>\n new Nano<B, E, R>((ctx) => {\n const result = fa.run(ctx)\n if (Either.isLeft(result)) return result as any\n if (Either.isLeft(result.right)) return result\n return Either.right(Either.right(f(result.right.right) as B))\n }))\n\nexport const orElse = <B, E2, R2>(\n f: () => Nano<B, E2, R2>\n) =>\n<A, E, R>(fa: Nano<A, E, R>) =>\n new Nano<A | B, E2, R | R2>((ctx) => {\n const result = fa.run(ctx)\n if (Either.isLeft(result)) return result\n if (Either.isLeft(result.right)) return f().run(ctx) as any\n return result\n })\n\nexport const firstSuccessOf = <A extends Array<Nano<any, any, any>>>(\n arr: A\n): Nano<A[number][\"~nano.success\"], A[number][\"~nano.error\"], A[number][\"~nano.requirements\"]> =>\n ReadonlyArray.reduce(arr.slice(1), arr[0], (arr, fa) => orElse(() => fa)(arr)) as any\n\nexport const service = <I extends NanoTag<any>>(tag: I) =>\n new Nano<I[\"~nano.requirements\"], never, I[\"~nano.requirements\"]>((ctx) =>\n contextGet(ctx, tag).pipe(Option.match({\n onNone: () =>\n Either.left(new NanoDefectException({ value: `Cannot find service ${tag.key}` })),\n onSome: (value) => Either.right(Either.right(value))\n }))\n )\n\nexport const provideService = <I extends NanoTag<any>>(\n tag: I,\n value: I[\"~nano.requirements\"]\n) =>\n<A, E, R>(fa: Nano<A, E, R>) =>\n new Nano<A, E, Exclude<R, I[\"~nano.requirements\"]>>((ctx) => {\n return fa.run(contextAdd(ctx, tag, value))\n })\n\nexport interface NanoTypeLambda extends TypeLambda {\n readonly type: Nano<this[\"Target\"], this[\"Out1\"], this[\"Out2\"]>\n}\n\nexport const gen = <Eff extends Gen.YieldWrap<Nano<any, any, any>>, AEff>(\n ...args: [body: () => Generator<Eff, AEff, never>]\n) =>\n new Nano<\n AEff,\n [Eff] extends [never] ? never\n : [Eff] extends [Gen.YieldWrap<Nano<infer _A, infer E, infer _R>>] ? E\n : never,\n [Eff] extends [never] ? never\n : [Eff] extends [Gen.YieldWrap<Nano<infer _A, infer _E, infer R>>] ? R\n : never\n >((ctx) => {\n const iterator = args[0]()\n let state: IteratorResult<any> = iterator.next()\n while (!state.done) {\n const current = Gen.isGenKind(state.value)\n ? state.value.value\n : Gen.yieldWrapGet(state.value)\n const result: Either.Either<any, any> = current.run(ctx)\n if (Either.isLeft(result)) {\n return result\n }\n const inner: Either.Either<any, any> = result.right\n if (Either.isLeft(inner)) {\n return result\n }\n state = iterator.next(inner.right as never)\n }\n return Either.right(Either.right(state.value)) as any\n })\n\nexport const option = <A, E, R>(fa: Nano<A, E, R>) =>\n new Nano<Option.Option<A>, never, R>((ctx) => {\n return Either.match(fa.run(ctx), {\n onLeft: (cause) => Either.left(cause),\n onRight: Either.match({\n onLeft: () => Either.right(Either.right(Option.none())),\n onRight: (value) => Either.right(Either.right(Option.some(value)))\n })\n })\n })\n\nexport const all = <A extends Array<Nano<any, any, any>>>(\n ...args: A\n): Nano<A[number][\"~nano.success\"], A[number][\"~nano.error\"], A[number][\"~nano.requirements\"]> =>\n gen(function*() {\n const results: Array<A[number][\"~nano.success\"]> = []\n for (const arg of args) {\n const result = yield* arg\n results.push(result)\n }\n return results\n })\n","import * as Data from \"effect/Data\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport type * as TypeCheckerApi from \"../utils/TypeCheckerApi.js\"\nimport type * as TypeScriptApi from \"../utils/TypeScriptApi.js\"\nimport * as Nano from \"./Nano.js\"\n\nexport class RefactorNotApplicableError\n extends Data.TaggedError(\"RefactorNotApplicableError\")<{}>\n{}\n\nexport interface RefactorDefinition {\n name: string\n description: string\n apply: (\n sourceFile: ts.SourceFile,\n textRange: ts.TextRange\n ) => Nano.Nano<\n ApplicableRefactorDefinition,\n RefactorNotApplicableError,\n TypeScriptApi.TypeScriptApi | TypeCheckerApi.TypeCheckerApi | PluginOptions\n >\n}\n\nexport interface ApplicableRefactorDefinition {\n kind: string\n description: string\n apply: Nano.Nano<void, never, ts.textChanges.ChangeTracker>\n}\n\nexport function createRefactor(definition: RefactorDefinition) {\n return definition\n}\n\nexport interface DiagnosticDefinition {\n name: string\n code: number\n apply: (\n sourceFile: ts.SourceFile\n ) => Nano.Nano<\n Array<ApplicableDiagnosticDefinition>,\n never,\n TypeCheckerApi.TypeCheckerApi | PluginOptions | TypeScriptApi.TypeScriptApi\n >\n}\n\nexport interface ApplicableDiagnosticDefinition {\n node: ts.Node\n category: ts.DiagnosticCategory\n messageText: string\n}\n\nexport function createDiagnostic(definition: DiagnosticDefinition) {\n return definition\n}\n\nexport interface PluginOptions {\n diagnostics: boolean\n quickinfo: boolean\n}\n\nexport const PluginOptions = Nano.Tag<PluginOptions>(\"PluginOptions\")\n\nexport class SourceFileNotFoundError extends Data.TaggedError(\"SourceFileNotFoundError\")<{\n fileName: string\n}> {}\n\nexport function getSemanticDiagnostics(\n diagnostics: Array<DiagnosticDefinition>,\n sourceFile: ts.SourceFile\n) {\n return Nano.gen(function*() {\n const effectDiagnostics: Array<ts.Diagnostic> = []\n for (const diagnostic of diagnostics) {\n const result = yield* Nano.option(diagnostic.apply(sourceFile))\n if (Option.isSome(result)) {\n effectDiagnostics.push(...result.value.map((_) => ({\n file: sourceFile,\n start: _.node.getStart(sourceFile),\n length: _.node.getEnd() - _.node.getStart(sourceFile),\n messageText: _.messageText,\n category: _.category,\n code: diagnostic.code,\n source: \"effect\"\n })))\n }\n }\n return effectDiagnostics\n })\n}\n\nexport function getApplicableRefactors(\n refactors: Array<RefactorDefinition>,\n sourceFile: ts.SourceFile,\n positionOrRange: number | ts.TextRange\n) {\n return Nano.gen(function*() {\n const textRange = typeof positionOrRange === \"number\"\n ? { pos: positionOrRange, end: positionOrRange }\n : positionOrRange\n const effectRefactors: Array<ts.ApplicableRefactorInfo> = []\n for (const refactor of refactors) {\n const result = yield* Nano.option(refactor.apply(sourceFile, textRange))\n if (Option.isSome(result)) {\n effectRefactors.push({\n name: refactor.name,\n description: refactor.description,\n actions: [{\n name: refactor.name,\n description: result.value.description,\n kind: result.value.kind\n }]\n })\n }\n }\n return effectRefactors\n })\n}\n\nexport function getEditsForRefactor(\n refactors: Array<RefactorDefinition>,\n sourceFile: ts.SourceFile,\n positionOrRange: number | ts.TextRange,\n refactorName: string\n) {\n return Nano.gen(function*() {\n const refactor = refactors.find((refactor) => refactor.name === refactorName)\n if (!refactor) {\n return yield* Nano.fail(new RefactorNotApplicableError())\n }\n const textRange = typeof positionOrRange === \"number\"\n ? { pos: positionOrRange, end: positionOrRange }\n : positionOrRange\n\n return yield* refactor.apply(sourceFile, textRange)\n })\n}\n","import type ts from \"typescript\"\nimport * as Nano from \"../core/Nano.js\"\n\ndeclare module \"typescript\" {\n const nullTransformationContext: ts.TransformationContext\n\n export namespace formatting {\n interface FormattingHost {\n getNewLine?(): string\n }\n\n export interface FormatContext {\n readonly options: ts.FormatCodeSettings\n readonly getRules: unknown\n }\n\n function getFormatContext(options: ts.FormatCodeSettings, host: FormattingHost): FormatContext\n }\n\n export type TextChangesContext = any\n\n export namespace textChanges {\n export interface ChangeNodeOptions extends ConfigurableStartEnd, InsertNodeOptions {}\n export enum LeadingTriviaOption {\n /** Exclude all leading trivia (use getStart()) */\n Exclude = 0,\n /** Include leading trivia and,\n * if there are no line breaks between the node and the previous token,\n * include all trivia between the node and the previous token\n */\n IncludeAll = 1,\n /**\n * Include attached JSDoc comments\n */\n JSDoc = 2,\n /**\n * Only delete trivia on the same line as getStart().\n * Used to avoid deleting leading comments\n */\n StartLine = 3\n }\n export enum TrailingTriviaOption {\n /** Exclude all trailing trivia (use getEnd()) */\n Exclude = 0,\n /** Doesn't include whitespace, but does strip comments */\n ExcludeWhitespace = 1,\n /** Include trailing trivia */\n Include = 2\n }\n export interface ConfigurableStart {\n leadingTriviaOption?: LeadingTriviaOption\n }\n export interface ConfigurableEnd {\n trailingTriviaOption?: TrailingTriviaOption\n }\n export interface InsertNodeOptions {\n /**\n * Text to be inserted before the new node\n */\n prefix?: string\n /**\n * Text to be inserted after the new node\n */\n suffix?: string\n /**\n * Text of inserted node will be formatted with this indentation, otherwise indentation will be inferred from the old node\n */\n indentation?: number\n /**\n * Text of inserted node will be formatted with this delta, otherwise delta will be inferred from the new node kind\n */\n delta?: number\n }\n export interface ConfigurableStartEnd extends ConfigurableStart, ConfigurableEnd {\n }\n export class ChangeTracker {\n static with(\n context: ts.TextChangesContext,\n cb: (tracker: ChangeTracker) => void\n ): Array<ts.FileTextChanges>\n delete(\n sourceFile: ts.SourceFile,\n node: ts.Node | ts.NodeArray<ts.TypeParameterDeclaration>\n ): void\n deleteRange(sourceFile: ts.SourceFile, range: ts.TextRange): void\n replaceNode(\n sourceFile: ts.SourceFile,\n oldNode: ts.Node,\n newNode: ts.Node,\n options?: ts.textChanges.ChangeNodeOptions\n ): void\n insertNodeAt(\n sourceFile: ts.SourceFile,\n pos: number,\n newNode: ts.Node,\n options?: ts.textChanges.InsertNodeOptions\n ): void\n insertNodeBefore(\n sourceFile: ts.SourceFile,\n before: ts.Node,\n newNode: ts.Node,\n blankLineBetween?: boolean,\n options?: ConfigurableStartEnd\n ): void\n insertNodeAfter(sourceFile: ts.SourceFile, after: ts.Node, newNode: ts.Node): void\n insertText(sourceFile: ts.SourceFile, pos: number, text: string): void\n }\n export function applyChanges(text: string, changes: ReadonlyArray<ts.TextChange>): string\n }\n\n export function findPrecedingToken(\n position: number,\n sourceFile: ts.SourceFileLike,\n startNode: ts.Node,\n excludeJsdoc?: boolean\n ): ts.Node | undefined\n export function findPrecedingToken(\n position: number,\n sourceFile: ts.SourceFile,\n startNode?: ts.Node,\n excludeJsdoc?: boolean\n ): ts.Node | undefined\n function findChildOfKind<T extends ts.Node>(\n n: ts.Node,\n kind: T[\"kind\"],\n sourceFile: ts.SourceFileLike\n ): T | undefined\n\n export function isMemberName(node: ts.Node): node is ts.MemberName\n export function isKeyword(token: ts.SyntaxKind): token is ts.KeywordSyntaxKind\n\n export interface TypeChecker {\n isTypeAssignableTo(source: ts.Type, target: ts.Type): boolean\n getUnionType(types: ReadonlyArray<ts.Type>): ts.Type\n }\n\n export function typeToDisplayParts(\n typechecker: ts.TypeChecker,\n type: ts.Type,\n enclosingDeclaration?: ts.Node | undefined,\n flags?: ts.TypeFormatFlags\n ): Array<ts.SymbolDisplayPart>\n}\n\ntype _TypeScriptApi = typeof ts\nexport interface TypeScriptApi extends _TypeScriptApi {}\n\nexport const TypeScriptApi = Nano.Tag<TypeScriptApi>(\"TypeScriptApi\")\n\nexport const ChangeTracker = Nano.Tag<ts.textChanges.ChangeTracker>(\"ChangeTracker\")\n","import * as Data from \"effect/Data\"\nimport * as Option from \"effect/Option\"\nimport * as Order from \"effect/Order\"\nimport type ts from \"typescript\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeScriptApi from \"./TypeScriptApi.js\"\n\nexport interface TypeCheckerApi extends ts.TypeChecker {}\nexport const TypeCheckerApi = Nano.Tag<TypeCheckerApi>(\"TypeChecker\")\n\nexport const deterministicTypeOrder = Nano.gen(function*() {\n const typeChecker = yield* Nano.service(TypeCheckerApi)\n return Order.make((a: ts.Type, b: ts.Type) => {\n const aName = typeChecker.typeToString(a)\n const bName = typeChecker.typeToString(b)\n if (aName < bName) return -1\n if (aName > bName) return 1\n return 0\n })\n})\n\nexport function getMissingTypeEntriesInTargetType(realType: ts.Type, expectedType: ts.Type) {\n return Nano.gen(function*() {\n const typeChecker = yield* Nano.service(TypeCheckerApi)\n\n const result: Array<ts.Type> = []\n const toTest: Array<ts.Type> = [realType]\n while (toTest.length > 0) {\n const type = toTest.pop()\n if (!type) return result\n if (type.isUnion()) {\n toTest.push(...type.types)\n } else {\n const assignable = typeChecker.isTypeAssignableTo(type, expectedType)\n if (!assignable) {\n result.push(type)\n }\n }\n }\n return result\n })\n}\n\ntype ConvertibleDeclaration =\n | ts.FunctionDeclaration\n | ts.FunctionExpression\n | ts.ArrowFunction\n | ts.MethodDeclaration\n\nclass CannotFindAncestorConvertibleDeclarationError\n extends Data.TaggedError(\"CannotFindAncestorConvertibleDeclarationError\")<{\n node: ts.Node\n }>\n{}\n\nfunction getAncestorConvertibleDeclaration(node: ts.Node) {\n return Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n let current: ts.Node | undefined = node\n while (current) {\n if (\n ts.isFunctionDeclaration(current) ||\n ts.isFunctionExpression(current) ||\n ts.isArrowFunction(current) ||\n ts.isMethodDeclaration(current)\n ) {\n return current\n }\n current = current.parent\n }\n return yield* Nano.fail(new CannotFindAncestorConvertibleDeclarationError({ node }))\n })\n}\n\nclass CannotInferReturnTypeFromEmptyBody\n extends Data.TaggedError(\"CannotInferReturnTypeFromEmptyBody\")<{\n declaration: ConvertibleDeclaration\n }>\n{}\n\nclass CannotInferReturnType extends Data.TaggedError(\"CannotInferReturnType\")<{\n declaration: ConvertibleDeclaration\n}> {}\n\nexport function getInferredReturnType(\n declaration: ConvertibleDeclaration\n): Nano.Nano<\n ts.Type,\n CannotInferReturnTypeFromEmptyBody | CannotInferReturnType,\n ts.TypeChecker | TypeScriptApi.TypeScriptApi\n> {\n return Nano.gen(function*() {\n const typeChecker = yield* Nano.service(TypeCheckerApi)\n\n if (!declaration.body) {\n return yield* Nano.fail(\n new CannotInferReturnTypeFromEmptyBody({ declaration })\n )\n }\n\n let returnType: ts.Type | undefined\n\n if (typeChecker.isImplementationOfOverload(declaration)) {\n const signatures = typeChecker.getTypeAtLocation(declaration).getCallSignatures()\n if (signatures.length > 1) {\n returnType = typeChecker.getUnionType(\n signatures.map((s) => s.getReturnType()).filter((_) => !!_)\n )\n }\n }\n if (!returnType) {\n const signature = typeChecker.getSignatureFromDeclaration(declaration)\n if (signature) {\n const typePredicate = typeChecker.getTypePredicateOfSignature(signature)\n if (typePredicate && typePredicate.type) {\n return typePredicate.type\n } else {\n returnType = typeChecker.getReturnTypeOfSignature(signature)\n }\n }\n }\n\n if (!returnType) {\n return yield* Nano.fail(\n new CannotInferReturnType({ declaration })\n )\n }\n\n return returnType\n })\n}\n\nexport function expectedAndRealType(\n node: ts.Node\n): Nano.Nano<\n Array<[ts.Node, ts.Type, ts.Node, ts.Type]>,\n never,\n ts.TypeChecker | TypeScriptApi.TypeScriptApi\n> {\n return Nano.gen(function*() {\n const typeChecker = yield* Nano.service(TypeCheckerApi)\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n if (ts.isVariableDeclaration(node) && node.initializer) {\n const expectedType = typeChecker.getTypeAtLocation(node.name)\n const realType = typeChecker.getTypeAtLocation(node.initializer)\n return [[node.name, expectedType, node.initializer, realType]]\n }\n if (ts.isCallExpression(node)) {\n const resolvedSignature = typeChecker.getResolvedSignature(node)\n if (resolvedSignature) {\n return resolvedSignature.getParameters().map((parameter, index) => {\n const expectedType = typeChecker.getTypeOfSymbolAtLocation(parameter, node)\n const realType = typeChecker.getTypeAtLocation(node.arguments[index])\n return [node.arguments[index], expectedType, node.arguments[index], realType]\n })\n }\n }\n if (\n ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node) ||\n ts.isNoSubstitutionTemplateLiteral(node)\n ) {\n const parent = node.parent\n if (ts.isObjectLiteralElement(parent)) {\n if (ts.isObjectLiteralExpression(parent.parent) && parent.name === node) {\n const type = typeChecker.getContextualType(parent.parent)\n if (type) {\n const symbol = typeChecker.getPropertyOfType(type, node.text)\n if (symbol) {\n const expectedType = typeChecker.getTypeOfSymbolAtLocation(symbol, node)\n const realType = typeChecker.getTypeAtLocation(node)\n return [[node, expectedType, node, realType]]\n }\n }\n }\n }\n }\n if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken) {\n const expectedType = typeChecker.getTypeAtLocation(node.left)\n const realType = typeChecker.getTypeAtLocation(node.right)\n return [[node.left, expectedType, node.right, realType]]\n }\n if (ts.isReturnStatement(node) && node.expression) {\n const parentDeclaration = yield* Nano.option(getAncestorConvertibleDeclaration(node))\n if (Option.isSome(parentDeclaration)) {\n const expectedType = yield* Nano.option(getInferredReturnType(parentDeclaration.value))\n const realType = typeChecker.getTypeAtLocation(node.expression)\n if (Option.isSome(expectedType)) return [[node, expectedType.value, node, realType]]\n }\n }\n if (ts.isArrowFunction(node) && ts.isExpression(node.body)) {\n const body = node.body\n const expectedType = typeChecker.getContextualType(body)\n const realType = typeChecker.getTypeAtLocation(body)\n if (expectedType) return [[body, expectedType, body, realType]]\n }\n if (ts.isSatisfiesExpression(node)) {\n const expectedType = typeChecker.getTypeAtLocation(node.type)\n const realType = typeChecker.getTypeAtLocation(node.expression)\n return [[node.expression, expectedType, node.expression, realType]]\n }\n return []\n })\n}\n","import * as Data from \"effect/Data\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeCheckerApi from \"./TypeCheckerApi.js\"\nimport * as TypeScriptApi from \"./TypeScriptApi.js\"\n\nexport class TypeParserIssue extends Data.TaggedError(\"@effect/language-service/TypeParserIssue\")<{\n type?: ts.Type | undefined\n node?: ts.Node | undefined\n message: string\n}> {}\n\nfunction typeParserIssue(\n message: string,\n type?: ts.Type | undefined,\n node?: ts.Node | undefined\n): Nano.Nano<never, TypeParserIssue, never> {\n return Nano.fail(new TypeParserIssue({ type, message, node }))\n}\n\nexport function covariantTypeArgument(type: ts.Type): Nano.Nano<ts.Type, TypeParserIssue> {\n const signatures = type.getCallSignatures()\n // Covariant<A> has only 1 type signature\n if (signatures.length !== 1) {\n return typeParserIssue(\"Covariant type has no call signature\", type)\n }\n // get the return type\n return Nano.succeed(signatures[0].getReturnType())\n}\n\nexport function pipeableType(\n type: ts.Type,\n atLocation: ts.Node\n): Nano.Nano<ts.Type, TypeParserIssue, TypeCheckerApi.TypeCheckerApi> {\n return Nano.gen(function*() {\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n // Pipeable has a pipe property on the type\n const pipeSymbol = typeChecker.getPropertyOfType(type, \"pipe\")\n if (!pipeSymbol) {\n return yield* typeParserIssue(\"Type has no 'pipe' property\", type, atLocation)\n }\n // which should be callable with at least one call signature\n const pipeType = typeChecker.getTypeOfSymbolAtLocation(pipeSymbol, atLocation)\n const signatures = pipeType.getCallSignatures()\n if (signatures.length === 0) {\n return yield* typeParserIssue(\"'pipe' property is not callable\", type, atLocation)\n }\n return type\n })\n}\n\nexport function varianceStructCovariantType<A extends string>(\n type: ts.Type,\n atLocation: ts.Node,\n propertyName: A\n): Nano.Nano<ts.Type, TypeParserIssue, TypeCheckerApi.TypeCheckerApi> {\n return Nano.gen(function*() {\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const propertySymbol = typeChecker.getPropertyOfType(type, propertyName)\n if (!propertySymbol) {\n return yield* typeParserIssue(`Type has no '${propertyName}' property`, type, atLocation)\n }\n const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation)\n return yield* covariantTypeArgument(propertyType)\n })\n}\n\nexport function effectVarianceStruct(\n type: ts.Type,\n atLocation: ts.Node\n): Nano.Nano<\n { A: ts.Type; E: ts.Type; R: ts.Type },\n TypeParserIssue,\n TypeCheckerApi.TypeCheckerApi\n> {\n return Nano.gen(function*() {\n return ({\n A: yield* varianceStructCovariantType(type, atLocation, \"_A\"),\n E: yield* varianceStructCovariantType(type, atLocation, \"_E\"),\n R: yield* varianceStructCovariantType(type, atLocation, \"_R\")\n })\n })\n}\n\nexport function effectType(\n type: ts.Type,\n atLocation: ts.Node\n): Nano.Nano<\n { A: ts.Type; E: ts.Type; R: ts.Type },\n TypeParserIssue,\n TypeCheckerApi.TypeCheckerApi\n> {\n return Nano.gen(function*() {\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n // should be pipeable\n yield* pipeableType(type, atLocation)\n // has a property symbol which is an effect variance struct\n for (const propertySymbol of typeChecker.getPropertiesOfType(type)) {\n const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation)\n const varianceArgs = yield* Nano.option(effectVarianceStruct(\n propertyType,\n atLocation\n ))\n if (Option.isSome(varianceArgs)) {\n return varianceArgs.value\n }\n }\n return yield* typeParserIssue(\"Type has no effect variance struct\", type, atLocation)\n })\n}\n\nexport function fiberType(\n type: ts.Type,\n atLocation: ts.Node\n): Nano.Nano<\n { A: ts.Type; E: ts.Type; R: ts.Type },\n TypeParserIssue,\n TypeCheckerApi.TypeCheckerApi\n> {\n return Nano.gen(function*() {\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n // there is no better way to check if a type is a fiber right not\n // so we just check for the existence of the property \"await\" and \"poll\"\n const awaitSymbol = typeChecker.getPropertyOfType(type, \"await\")\n const pollSymbol = typeChecker.getPropertyOfType(type, \"poll\")\n if (!awaitSymbol || !pollSymbol) {\n return yield* typeParserIssue(\n \"Type is not a fiber because it does not have 'await' or 'poll' property\",\n type,\n atLocation\n )\n }\n // and it is also an effect itself\n return yield* effectType(type, atLocation)\n })\n}\n\nexport function effectSubtype(\n type: ts.Type,\n atLocation: ts.Node\n): Nano.Nano<\n { A: ts.Type; E: ts.Type; R: ts.Type },\n TypeParserIssue,\n TypeCheckerApi.TypeCheckerApi\n> {\n return Nano.gen(function*() {\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n // there is no better way to check if a type is a subtype of effect\n // so we just check for the existence of the property \"_tag\"\n // which is common for Option, Either, and others\n const tagSymbol = typeChecker.getPropertyOfType(type, \"_tag\")\n if (!tagSymbol) {\n return yield* typeParserIssue(\n \"Type is not a subtype of effect because it does not have '_tag' property\",\n type,\n atLocation\n )\n }\n // and it is also an effect itself\n return yield* effectType(type, atLocation)\n })\n}\n\nexport function importedEffectModule(\n node: ts.Node\n): Nano.Nano<\n ts.Expression,\n TypeParserIssue,\n TypeCheckerApi.TypeCheckerApi | TypeScriptApi.TypeScriptApi\n> {\n return Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const type = typeChecker.getTypeAtLocation(node)\n // if the type has a property \"never\"\n const propertySymbol = typeChecker.getPropertyOfType(type, \"never\")\n if (!propertySymbol) {\n return yield* typeParserIssue(\"Type has no 'never' property\", type, node)\n }\n // should be an expression\n if (!ts.isExpression(node)) {\n return yield* typeParserIssue(\"Node is not an expression\", type, node)\n }\n // and the property type is an effect\n const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, node)\n yield* effectType(propertyType, node)\n // return the node itself\n return node\n })\n}\n\nexport function effectGen(node: ts.Node) {\n return Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n // Effect.gen(...)\n if (!ts.isCallExpression(node)) {\n return yield* typeParserIssue(\"Node is not a call expression\", undefined, node)\n }\n // ...\n if (node.arguments.length === 0) {\n return yield* typeParserIssue(\"Node has no arguments\", undefined, node)\n }\n // firsta argument is a generator function expression\n const generatorFunction = node.arguments[0]\n if (!ts.isFunctionExpression(generatorFunction)) {\n return yield* typeParserIssue(\"Node is not a function expression\", undefined, node)\n }\n if (generatorFunction.asteriskToken === undefined) {\n return yield* typeParserIssue(\"Node is not a generator function\", undefined, node)\n }\n // Effect.gen\n if (!ts.isPropertyAccessExpression(node.expression)) {\n return yield* typeParserIssue(\"Node is not a property access expression\", undefined, node)\n }\n const propertyAccess = node.expression\n // gen\n if (propertyAccess.name.text !== \"gen\") {\n return yield* typeParserIssue(\"Call expression name is not 'gen'\", undefined, node)\n }\n // check Effect module\n const effectModule = yield* importedEffectModule(propertyAccess.expression)\n return ({\n node,\n effectModule,\n generatorFunction,\n body: generatorFunction.body,\n functionStar: generatorFunction.getFirstToken()\n })\n })\n}\n\nexport function effectFnUntracedGen(node: ts.Node) {\n return Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n // Effect.gen(...)\n if (!ts.isCallExpression(node)) {\n return yield* typeParserIssue(\"Node is not a call expression\", undefined, node)\n }\n // ...\n if (node.arguments.length === 0) {\n return yield* typeParserIssue(\"Node has no arguments\", undefined, node)\n }\n // firsta argument is a generator function expression\n const generatorFunction = node.arguments[0]\n if (!ts.isFunctionExpression(generatorFunction)) {\n return yield* typeParserIssue(\"Node is not a function expression\", undefined, node)\n }\n if (generatorFunction.asteriskToken === undefined) {\n return yield* typeParserIssue(\n \"Node is not a generator function\",\n undefined,\n node\n )\n }\n // Effect.gen\n if (!ts.isPropertyAccessExpression(node.expression)) {\n return yield* typeParserIssue(\n \"Node is not a property access expression\",\n undefined,\n node\n )\n }\n const propertyAccess = node.expression\n // gen\n if (propertyAccess.name.text !== \"fnUntraced\") {\n return yield* typeParserIssue(\n \"Call expression name is not 'fnUntraced'\",\n undefined,\n node\n )\n }\n // check Effect module\n const effectModule = yield* importedEffectModule(propertyAccess.expression)\n return ({\n node,\n effectModule,\n generatorFunction,\n body: generatorFunction.body,\n functionStar: generatorFunction.getFirstToken()\n })\n })\n}\n\nexport function effectFnGen(node: ts.Node) {\n return Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n // Effect.fn(...)\n if (!ts.isCallExpression(node)) {\n return yield* typeParserIssue(\"Node is not a call expression\", undefined, node)\n }\n // ...\n if (node.arguments.length === 0) {\n return yield* typeParserIssue(\"Node has no arguments\", undefined, node)\n }\n // firsta argument is a generator function expression\n const generatorFunction = node.arguments[0]\n if (!ts.isFunctionExpression(generatorFunction)) {\n return yield* typeParserIssue(\n \"Node is not a function expression\",\n undefined,\n node\n )\n }\n if (generatorFunction.asteriskToken === undefined) {\n return yield* typeParserIssue(\n \"Node is not a generator function\",\n undefined,\n node\n )\n }\n // either we are using Effect.fn(\"name\")(generatorFunction) or we are using Effect.fn(generatorFunction)\n const expressionToTest = ts.isCallExpression(node.expression)\n ? node.expression.expression\n : node.expression\n if (!ts.isPropertyAccessExpression(expressionToTest)) {\n return yield* typeParserIssue(\n \"Node is not a property access expression\",\n undefined,\n node\n )\n }\n const propertyAccess = expressionToTest\n // fn\n if (propertyAccess.name.text !== \"fn\") {\n return yield* typeParserIssue(\n \"Call expression name is not 'fn'\",\n undefined,\n node\n )\n }\n // check Effect module\n const effectModule = yield* importedEffectModule(propertyAccess.expression)\n return ({\n node,\n generatorFunction,\n effectModule,\n body: generatorFunction.body,\n functionStar: generatorFunction.getFirstToken()\n })\n })\n}\n\nexport function returnYieldEffectBlock(\n body: ts.Node\n): Nano.Nano<\n ts.Expression,\n TypeParserIssue,\n TypeScriptApi.TypeScriptApi | TypeCheckerApi.TypeCheckerApi\n> {\n return Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n // is the body a block?\n if (!ts.isBlock(body)) return yield* typeParserIssue(\"Node is not a block\", undefined, body)\n if (\n body.statements.length === 1 &&\n ts.isReturnStatement(body.statements[0]) &&\n body.statements[0].expression &&\n ts.isYieldExpression(body.statements[0].expression) &&\n body.statements[0].expression.expression\n ) {\n // get the type of the node\n const nodeToCheck = body.statements[0].expression.expression\n const type = typeChecker.getTypeAtLocation(nodeToCheck)\n yield* effectType(type, nodeToCheck)\n return (nodeToCheck)\n }\n return yield* typeParserIssue(\n \"Node is not a return statement with a yield expression\",\n undefined,\n body\n )\n })\n}\n","import { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeCheckerApi from \"../utils/TypeCheckerApi.js\"\nimport * as TypeParser from \"../utils/TypeParser.js\"\nimport * as TypeScriptApi from \"../utils/TypeScriptApi.js\"\n\nexport const floatingEffect = LSP.createDiagnostic({\n name: \"effect/floatingEffect\",\n code: 3,\n apply: (sourceFile) =>\n Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n function isFloatingExpression(node: ts.Node): node is ts.ExpressionStatement {\n // should be an expression statement\n if (!ts.isExpressionStatement(node)) return false\n // parent is either block or source file\n if (!(ts.isBlock(node.parent) || ts.isSourceFile(node.parent))) return false\n const expression = node.expression\n // this.variable = Effect.succeed is a valid expression\n if (\n ts.isBinaryExpression(expression) && expression.operatorToken &&\n expression.operatorToken.kind === ts.SyntaxKind.EqualsToken\n ) return false\n return true\n }\n\n const effectDiagnostics: Array<LSP.ApplicableDiagnosticDefinition> = []\n\n const nodeToVisit: Array<ts.Node> = []\n const appendNodeToVisit = (node: ts.Node) => {\n nodeToVisit.push(node)\n return undefined\n }\n\n ts.forEachChild(sourceFile, appendNodeToVisit)\n while (nodeToVisit.length > 0) {\n const node = nodeToVisit.shift()!\n ts.forEachChild(node, appendNodeToVisit)\n\n if (!isFloatingExpression(node)) continue\n\n const type = typeChecker.getTypeAtLocation(node.expression)\n // if type is an effect\n const effect = yield* Nano.option(TypeParser.effectType(type, node.expression))\n if (Option.isSome(effect)) {\n // and not a fiber (we consider that a valid operation)\n const allowedFloatingEffects = yield* pipe(\n TypeParser.fiberType(type, node.expression),\n Nano.orElse(() => TypeParser.effectSubtype(type, node.expression)),\n Nano.option\n )\n if (Option.isNone(allowedFloatingEffects)) {\n effectDiagnostics.push({\n node,\n category: ts.DiagnosticCategory.Error,\n messageText: `Effect must be yielded or assigned to a variable.`\n })\n }\n }\n }\n\n return effectDiagnostics\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport type ts from \"typescript\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeCheckerApi from \"../utils/TypeCheckerApi.js\"\nimport * as TypeParser from \"../utils/TypeParser.js\"\nimport * as TypeScriptApi from \"../utils/TypeScriptApi.js\"\n\nexport const missingEffectContext = LSP.createDiagnostic({\n name: \"effect/missingEffectContext\",\n code: 1,\n apply: (sourceFile) =>\n Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeOrder = yield* TypeCheckerApi.deterministicTypeOrder\n\n function checkForMissingContextTypes(\n node: ts.Node,\n expectedType: ts.Type,\n valueNode: ts.Node,\n realType: ts.Type\n ) {\n return Nano.gen(function*() {\n // the expected type is an effect\n const expectedEffect = yield* (TypeParser.effectType(\n expectedType,\n node\n ))\n // the real type is an effect\n const realEffect = yield* (TypeParser.effectType(\n realType,\n valueNode\n ))\n // get the missing types\n return yield* TypeCheckerApi.getMissingTypeEntriesInTargetType(\n realEffect.R,\n expectedEffect.R\n )\n })\n }\n\n const effectDiagnostics: Array<LSP.ApplicableDiagnosticDefinition> = []\n const sortTypes = ReadonlyArray.sort(typeOrder)\n\n const nodeToVisit: Array<ts.Node> = []\n const appendNodeToVisit = (node: ts.Node) => {\n nodeToVisit.push(node)\n return undefined\n }\n ts.forEachChild(sourceFile, appendNodeToVisit)\n\n while (nodeToVisit.length > 0) {\n const node = nodeToVisit.shift()!\n ts.forEachChild(node, appendNodeToVisit)\n\n const entries = yield* TypeCheckerApi.expectedAndRealType(node)\n for (const [node, expectedType, valueNode, realType] of entries) {\n const missingContext = yield* pipe(\n checkForMissingContextTypes(\n node,\n expectedType,\n valueNode,\n realType\n ),\n Nano.orElse(() => Nano.succeed([]))\n )\n if (missingContext.length > 0) {\n effectDiagnostics.push(\n {\n node,\n category: ts.DiagnosticCategory.Error,\n messageText: `Missing '${\n sortTypes(missingContext).map((_) => typeChecker.typeToString(_)).join(\" | \")\n }' in the expected Effect context.`\n }\n )\n }\n }\n }\n\n return effectDiagnostics\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport type ts from \"typescript\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeCheckerApi from \"../utils/TypeCheckerApi.js\"\nimport * as TypeParser from \"../utils/TypeParser.js\"\nimport * as TypeScriptApi from \"../utils/TypeScriptApi.js\"\n\nexport const missingEffectError = LSP.createDiagnostic({\n name: \"effect/missingEffectError\",\n code: 1,\n apply: (sourceFile) =>\n Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeOrder = yield* TypeCheckerApi.deterministicTypeOrder\n\n function checkForMissingErrorTypes(\n node: ts.Node,\n expectedType: ts.Type,\n valueNode: ts.Node,\n realType: ts.Type\n ) {\n return Nano.gen(function*() {\n // the expected type is an effect\n const expectedEffect = yield* (TypeParser.effectType(\n expectedType,\n node\n ))\n // the real type is an effect\n const realEffect = yield* (TypeParser.effectType(\n realType,\n valueNode\n ))\n // get the missing types\n return yield* TypeCheckerApi.getMissingTypeEntriesInTargetType(\n realEffect.E,\n expectedEffect.E\n )\n })\n }\n\n const effectDiagnostics: Array<LSP.ApplicableDiagnosticDefinition> = []\n const sortTypes = ReadonlyArray.sort(typeOrder)\n\n const nodeToVisit: Array<ts.Node> = []\n const appendNodeToVisit = (node: ts.Node) => {\n nodeToVisit.push(node)\n return undefined\n }\n ts.forEachChild(sourceFile, appendNodeToVisit)\n\n while (nodeToVisit.length > 0) {\n const node = nodeToVisit.shift()!\n ts.forEachChild(node, appendNodeToVisit)\n\n const entries = yield* TypeCheckerApi.expectedAndRealType(node)\n for (const [node, expectedType, valueNode, realType] of entries) {\n const missingContext = yield* pipe(\n checkForMissingErrorTypes(\n node,\n expectedType,\n valueNode,\n realType\n ),\n Nano.orElse(() => Nano.succeed([]))\n )\n if (missingContext.length > 0) {\n effectDiagnostics.push(\n {\n node,\n category: ts.DiagnosticCategory.Error,\n messageText: `Missing '${\n sortTypes(missingContext).map((_) => typeChecker.typeToString(_)).join(\" | \")\n }' in the expected Effect errors.`\n }\n )\n }\n }\n }\n\n return effectDiagnostics\n })\n})\n","import { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeCheckerApi from \"../utils/TypeCheckerApi.js\"\nimport * as TypeParser from \"../utils/TypeParser.js\"\nimport * as TypeScriptApi from \"../utils/TypeScriptApi.js\"\n\nexport const missingStarInYieldEffectGen = LSP.createDiagnostic({\n name: \"effect/missingStarInYieldEffectGen\",\n code: 4,\n apply: (sourceFile) =>\n Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n const effectDiagnostics: Array<LSP.ApplicableDiagnosticDefinition> = []\n const brokenGenerators = new Set<ts.Node>()\n const brokenYields = new Set<ts.Node>()\n\n const nodeToVisit: Array<[node: ts.Node, functionStarNode: ts.Node | undefined]> = []\n const appendNodeToVisit = (functionStarNode: ts.Node | undefined) => (node: ts.Node) => {\n nodeToVisit.push([node, functionStarNode])\n return undefined\n }\n ts.forEachChild(sourceFile, appendNodeToVisit(undefined))\n\n while (nodeToVisit.length > 0) {\n const [node, functionStarNode] = nodeToVisit.shift()!\n\n // error if yield is not followed by *\n if (\n functionStarNode && ts.isYieldExpression(node) && node.expression &&\n node.asteriskToken === undefined\n ) {\n const type = typeChecker.getTypeAtLocation(node.expression)\n const effect = yield* Nano.option(TypeParser.effectType(type, node.expression))\n if (Option.isSome(effect)) {\n brokenGenerators.add(functionStarNode)\n brokenYields.add(node)\n }\n }\n // continue if we hit effect gen-like\n const effectGenLike = yield* pipe(\n TypeParser.effectGen(node),\n Nano.orElse(() => TypeParser.effectFnUntracedGen(node)),\n Nano.orElse(() => TypeParser.effectFnGen(node)),\n Nano.option\n )\n if (Option.isSome(effectGenLike)) {\n ts.forEachChild(\n effectGenLike.value.body,\n appendNodeToVisit(effectGenLike.value.functionStar)\n )\n } // stop when we hit a generator function\n else if (\n (ts.isFunctionExpression(node) || ts.isMethodDeclaration(node)) &&\n node.asteriskToken !== undefined\n ) {\n // continue with new parent function star node\n ts.forEachChild(node, appendNodeToVisit(undefined))\n } else {\n // continue with current parent function star node\n ts.forEachChild(node, appendNodeToVisit(functionStarNode))\n }\n }\n\n // emit diagnostics\n brokenGenerators.forEach((node) =>\n effectDiagnostics.push({\n node,\n category: ts.DiagnosticCategory.Error,\n messageText: `Seems like you used yield instead of yield* inside this Effect.gen.`\n })\n )\n brokenYields.forEach((node) =>\n effectDiagnostics.push({\n node,\n category: ts.DiagnosticCategory.Error,\n messageText:\n `When yielding Effects inside Effect.gen, you should use yield* instead of yield.`\n })\n )\n\n return effectDiagnostics\n })\n})\n","import { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeParser from \"../utils/TypeParser.js\"\nimport * as TypeScriptApi from \"../utils/TypeScriptApi.js\"\n\nexport const unnecessaryEffectGen = LSP.createDiagnostic({\n name: \"effect/unnecessaryEffectGen\",\n code: 5,\n apply: (sourceFile) =>\n Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const effectDiagnostics: Array<LSP.ApplicableDiagnosticDefinition> = []\n const brokenGenerators = new Set<ts.Node>()\n\n const nodeToVisit: Array<ts.Node> = []\n const appendNodeToVisit = (node: ts.Node) => {\n nodeToVisit.push(node)\n return undefined\n }\n ts.forEachChild(sourceFile, appendNodeToVisit)\n\n while (nodeToVisit.length > 0) {\n const node = nodeToVisit.shift()!\n ts.forEachChild(node, appendNodeToVisit)\n\n const maybeUnnecessaryGen = yield* pipe(\n TypeParser.effectGen(node),\n Nano.flatMap(({ body }) => TypeParser.returnYieldEffectBlock(body)),\n Nano.option\n )\n\n if (Option.isSome(maybeUnnecessaryGen)) {\n brokenGenerators.add(node)\n }\n }\n\n // emit diagnostics\n brokenGenerators.forEach((node) =>\n effectDiagnostics.push({\n node,\n category: ts.DiagnosticCategory.Suggestion,\n messageText:\n `This Effect.gen is useless here because it only contains a single return statement.`\n })\n )\n\n return effectDiagnostics\n })\n})\n","import { floatingEffect } from \"./diagnostics/floatingEffect.js\"\nimport { missingEffectContext } from \"./diagnostics/missingEffectContext.js\"\nimport { missingEffectError } from \"./diagnostics/missingEffectError.js\"\nimport { missingStarInYieldEffectGen } from \"./diagnostics/missingStarInYieldEffectGen.js\"\nimport { unnecessaryEffectGen } from \"./diagnostics/unnecessaryEffectGen.js\"\n\nexport const diagnostics = [\n missingEffectContext,\n missingEffectError,\n floatingEffect,\n missingStarInYieldEffectGen,\n unnecessaryEffectGen\n]\n","import * as ReadonlyArray from \"effect/Array\"\nimport * as Data from \"effect/Data\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeScriptApi from \"./TypeScriptApi.js\"\n\n/**\n * Collects the given node and all its ancestor nodes that fully contain the specified TextRange.\n *\n * This function starts from the provided node and traverses up the AST, collecting\n * the node itself and its ancestors that encompass the given range.\n *\n * @param node - The starting AST node.\n * @param textRange - The range of text to use for filtering nodes.\n * @returns An array of nodes, including the starting node and its ancestors, that fully contain the specified range.\n */\nfunction collectSelfAndAncestorNodesInRange(\n node: ts.Node,\n textRange: ts.TextRange\n): Nano.Nano<Array<ts.Node>> {\n return Nano.sync(() => {\n let result = ReadonlyArray.empty<ts.Node>()\n let parent = node\n while (parent) {\n if (parent.end >= textRange.end) {\n result = pipe(result, ReadonlyArray.append(parent))\n }\n parent = parent.parent\n }\n return result\n })\n}\n\n/**\n * Collects the node at the given position and all its ancestor nodes\n * that fully contain the specified TextRange.\n *\n * This function starts from the closest token at the given position\n * and traverses up the AST, collecting nodes that encompass the range.\n *\n * @param ts - The TypeScript API.\n * @returns A function that takes a SourceFile and a TextRange, and returns\n * an array of nodes containing the range.\n */\nexport function getAncestorNodesInRange(\n sourceFile: ts.SourceFile,\n textRange: ts.TextRange\n): Nano.Nano<Array<ts.Node>, never, TypeScriptApi.TypeScriptApi> {\n return Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const precedingToken = ts.findPrecedingToken(textRange.pos, sourceFile)\n if (!precedingToken) return ReadonlyArray.empty<ts.Node>()\n return yield* collectSelfAndAncestorNodesInRange(precedingToken, textRange)\n })\n}\n\nexport class NodeNotFoundError\n extends Data.TaggedError(\"@effect/language-service/NodeNotFoundError\")<{}>\n{}\n\n/**\n * Finds the deepest AST node at the specified position within the given SourceFile.\n *\n * This function traverses the AST to locate the node that contains the given position.\n * If multiple nodes overlap the position, it returns the most specific (deepest) node.\n *\n * @param sourceFile - The TypeScript SourceFile to search within.\n * @param position - The position in the file to locate the node for.\n * @returns An `Option`:\n * - `Option.some<ts.Node>` if a node is found at the specified position.\n * - `Option.none` if no node is found at the specified position.\n */\nfunction findNodeAtPosition(\n sourceFile: ts.SourceFile,\n position: number\n): Nano.Nano<ts.Node, NodeNotFoundError, TypeScriptApi.TypeScriptApi> {\n return Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n function find(node: ts.Node): ts.Node | undefined {\n if (position >= node.getStart() && position < node.getEnd()) {\n // If the position is within this node, keep traversing its children\n return ts.forEachChild(node, find) || node\n }\n return undefined\n }\n const result = find(sourceFile)\n if (!result) return yield* Nano.fail(new NodeNotFoundError())\n return result\n })\n}\n\n/**\n * Collects the node at the given position, its descendants, and all its ancestor nodes\n * that fully contain the specified TextRange.\n *\n * This function starts by locating the node at the given position within the AST,\n * traverses down to include its descendants, and then traverses up to include its ancestors,\n * collecting all nodes that encompass the specified range.\n *\n * @param sourceFile - The TypeScript SourceFile to search within.\n * @param textRange - The range of text to use for filtering nodes.\n * @returns An array of nodes that are either descendants or ancestors of the node\n * at the given position and that fully contain the specified range.\n */\nexport function collectDescendantsAndAncestorsInRange(\n sourceFile: ts.SourceFile,\n textRange: ts.TextRange\n) {\n return Nano.gen(function*() {\n const nodeAtPosition = yield* Nano.option(findNodeAtPosition(sourceFile, textRange.pos))\n if (Option.isNone(nodeAtPosition)) return ReadonlyArray.empty<ts.Node>()\n return yield* collectSelfAndAncestorNodesInRange(nodeAtPosition.value, textRange)\n })\n}\n\n/**\n * Ensures value is a text range\n */\nexport function toTextRange(positionOrRange: number | ts.TextRange): ts.TextRange {\n return typeof positionOrRange === \"number\"\n ? { end: positionOrRange, pos: positionOrRange }\n : positionOrRange\n}\n\nexport function isNodeInRange(textRange: ts.TextRange) {\n return (node: ts.Node) => node.pos <= textRange.pos && node.end >= textRange.end\n}\n\nexport function transformAsyncAwaitToEffectGen(\n node: ts.FunctionDeclaration | ts.ArrowFunction | ts.FunctionExpression,\n effectModuleName: string,\n onAwait: (expression: ts.Expression) => ts.Expression\n) {\n return Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n function visitor(_: ts.Node): ts.Node {\n if (ts.isAwaitExpression(_)) {\n const expression = ts.visitEachChild(_.expression, visitor, ts.nullTransformationContext)\n\n return ts.factory.createYieldExpression(\n ts.factory.createToken(ts.SyntaxKind.AsteriskToken),\n onAwait(expression)\n )\n }\n return ts.visitEachChild(_, visitor, ts.nullTransformationContext)\n }\n const generatorBody = visitor(node.body!)\n\n const generator = ts.factory.createFunctionExpression(\n undefined,\n ts.factory.createToken(ts.SyntaxKind.AsteriskToken),\n undefined,\n [],\n [],\n undefined,\n generatorBody as any // NOTE(mattia): intended, to use same routine for both ConciseBody and Body\n )\n\n const effectGenCallExp = ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectModuleName),\n \"gen\"\n ),\n undefined,\n [generator as any]\n )\n\n let currentFlags = ts.getCombinedModifierFlags(node)\n currentFlags &= ~ts.ModifierFlags.Async\n const newModifiers = ts.factory.createModifiersFromModifierFlags(currentFlags)\n\n if (ts.isArrowFunction(node)) {\n return ts.factory.createArrowFunction(\n newModifiers,\n node.typeParameters,\n node.parameters,\n undefined,\n node.equalsGreaterThanToken,\n effectGenCallExp\n )\n }\n\n const newBody = ts.factory.createBlock([\n ts.factory.createReturnStatement(effectGenCallExp)\n ])\n\n if (ts.isFunctionDeclaration(node)) {\n return ts.factory.createFunctionDeclaration(\n newModifiers,\n node.asteriskToken,\n node.name,\n node.typeParameters,\n node.parameters,\n undefined,\n newBody\n )\n }\n return ts.factory.createFunctionExpression(\n newModifiers,\n node.asteriskToken,\n node.name,\n node.typeParameters,\n node.parameters,\n undefined,\n newBody\n )\n })\n}\n\nexport function addReturnTypeAnnotation(\n sourceFile: ts.SourceFile,\n declaration:\n | ts.FunctionDeclaration\n | ts.FunctionExpression\n | ts.ArrowFunction\n | ts.MethodDeclaration,\n typeNode: ts.TypeNode\n) {\n return Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const changes = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile)\n const needParens = ts.isArrowFunction(declaration) && closeParen === undefined\n const endNode = needParens ? declaration.parameters[0] : closeParen\n if (endNode) {\n if (needParens) {\n changes.insertNodeBefore(\n sourceFile,\n endNode,\n ts.factory.createToken(ts.SyntaxKind.OpenParenToken)\n )\n changes.insertNodeAfter(\n sourceFile,\n endNode,\n ts.factory.createToken(ts.SyntaxKind.CloseParenToken)\n )\n }\n changes.insertNodeAt(sourceFile, endNode.end, typeNode, { prefix: \": \" })\n }\n })\n}\n\nexport function removeReturnTypeAnnotation(\n sourceFile: ts.SourceFile,\n declaration:\n | ts.FunctionDeclaration\n | ts.FunctionExpression\n | ts.ArrowFunction\n | ts.MethodDeclaration\n) {\n return Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const changes = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile)\n const needParens = ts.isArrowFunction(declaration) && closeParen === undefined\n const endNode = needParens ? declaration.parameters[0] : closeParen\n if (endNode && declaration.type) {\n changes.deleteRange(sourceFile, { pos: endNode.end, end: declaration.type.end })\n }\n })\n}\n\nexport class ImportModuleIdentifierNotFoundError\n extends Data.TaggedError(\"@effect/language-service/ImportModuleIdentifierNotFoundError\")<{}>\n{}\n\nexport function findImportedModuleIdentifier<E = never, R = never>(\n sourceFile: ts.SourceFile,\n test: (node: ts.Node) => Nano.Nano<boolean, E, R>\n) {\n return Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n for (const statement of sourceFile.statements) {\n if (!ts.isImportDeclaration(statement)) continue\n const importClause = statement.importClause\n if (!importClause) continue\n const namedBindings = importClause.namedBindings\n if (!namedBindings) continue\n if (ts.isNamespaceImport(namedBindings)) {\n if (yield* test(namedBindings.name)) return (namedBindings.name)\n } else if (ts.isNamedImports(namedBindings)) {\n for (const importSpecifier of namedBindings.elements) {\n if (yield* test(importSpecifier.name)) return (importSpecifier.name)\n }\n }\n }\n return yield* Nano.fail(new ImportModuleIdentifierNotFoundError())\n })\n}\n\nexport function simplifyTypeNode(typeNode: ts.TypeNode) {\n function collectCallable(\n ts: TypeScriptApi.TypeScriptApi,\n typeNode: ts.TypeNode\n ): Option.Option<Array<ts.CallSignatureDeclaration>> {\n // (() => 1) -> skip to inner node\n if (ts.isParenthesizedTypeNode(typeNode)) return collectCallable(ts, typeNode.type)\n // () => 1 -> convert to call signature\n if (ts.isFunctionTypeNode(typeNode)) {\n return Option.some([\n ts.factory.createCallSignature(typeNode.typeParameters, typeNode.parameters, typeNode.type)\n ])\n }\n // { ... } -> if every member is callsignature, return a merge of all of those\n if (ts.isTypeLiteralNode(typeNode)) {\n const allCallSignatures = typeNode.members.every(ts.isCallSignatureDeclaration)\n if (allCallSignatures) {\n return Option.some(typeNode.members as any as Array<ts.CallSignatureDeclaration>)\n }\n }\n // ... & ... -> if both are callable, return merge of both\n if (ts.isIntersectionTypeNode(typeNode)) {\n const members = typeNode.types.map((node) => collectCallable(ts, node))\n if (members.every(Option.isSome)) {\n return Option.some(members.map((_) => Option.isSome(_) ? _.value : []).flat())\n }\n }\n\n return Option.none()\n }\n\n return Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const callSignatures = collectCallable(ts, typeNode)\n if (Option.isSome(callSignatures) && callSignatures.value.length > 1) {\n return ts.factory.createTypeLiteralNode(callSignatures.value)\n }\n return typeNode\n })\n}\n\nexport function tryPreserveDeclarationSemantics(nodeToReplace: ts.Node, node: ts.Node) {\n return Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n // new node should be an expression!\n if (!ts.isExpression(node)) return node\n // ok, we need to replace. is that a method or a function?\n if (ts.isFunctionDeclaration(nodeToReplace)) {\n // I need a name!!!\n if (!nodeToReplace.name) return node\n return ts.factory.createVariableStatement(\n nodeToReplace.modifiers,\n ts.factory.createVariableDeclarationList(\n [ts.factory.createVariableDeclaration(\n nodeToReplace.name,\n undefined,\n undefined,\n node\n )],\n ts.NodeFlags.Const\n )\n )\n } else if (ts.isMethodDeclaration(nodeToReplace)) {\n return ts.factory.createPropertyDeclaration(\n nodeToReplace.modifiers,\n nodeToReplace.name,\n undefined,\n undefined,\n node\n )\n }\n // I don't know what else to do!\n return node\n })\n}\n","import * as ReadonlyArray from \"effect/Array\"\nimport * as Eq from \"effect/Equivalence\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as Nano from \"./core/Nano.js\"\nimport * as AST from \"./utils/AST.js\"\nimport * as TypeCheckerApi from \"./utils/TypeCheckerApi.js\"\nimport * as TypeParser from \"./utils/TypeParser.js\"\nimport * as TypeScriptApi from \"./utils/TypeScriptApi.js\"\n\nconst SymbolDisplayPartEq = Eq.make<ts.SymbolDisplayPart>((fa, fb) =>\n fa.kind === fb.kind && fa.text === fb.text\n)\n\nconst JSDocTagInfoEq = Eq.make<ts.JSDocTagInfo>((fa, fb) =>\n fa.name === fb.name && typeof fa.text === typeof fb.text &&\n (typeof fa.text !== \"undefined\" ? Eq.array(SymbolDisplayPartEq)(fa.text!, fb.text!) : true)\n)\n\nexport function dedupeJsDocTags(quickInfo: ts.QuickInfo): ts.QuickInfo {\n if (quickInfo.tags) {\n return {\n ...quickInfo,\n tags: ReadonlyArray.dedupeWith(quickInfo.tags, JSDocTagInfoEq)\n }\n }\n return quickInfo\n}\n\nfunction formatTypeForQuickInfo(channelType: ts.Type, channelName: string) {\n return Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n const stringRepresentation = typeChecker.typeToString(\n channelType,\n undefined,\n ts.TypeFormatFlags.NoTruncation\n )\n return `type ${channelName} = ${stringRepresentation}`\n })\n}\n\nexport function prependEffectTypeArguments(\n sourceFile: ts.SourceFile,\n position: number,\n quickInfo: ts.QuickInfo\n) {\n return pipe(\n Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n const hasTruncationHappened =\n ts.displayPartsToString(quickInfo.displayParts).indexOf(\"...\") > -1\n if (!hasTruncationHappened) return quickInfo\n\n const maybeNode = pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, AST.toTextRange(position)),\n ReadonlyArray.head\n )\n if (Option.isNone(maybeNode)) return quickInfo\n const effectType = yield* TypeParser.effectType(\n typeChecker.getTypeAtLocation(maybeNode.value),\n maybeNode.value\n )\n\n const effectTypeArgsDocumentation: Array<ts.SymbolDisplayPart> = [{\n kind: \"text\",\n text: (\n \"```ts\\n\" +\n \"/* Effect Type Parameters */\\n\" +\n (yield* formatTypeForQuickInfo(effectType.A, \"Success\")) +\n \"\\n\" +\n (yield* formatTypeForQuickInfo(effectType.E, \"Failure\")) +\n \"\\n\" +\n (yield* formatTypeForQuickInfo(effectType.R, \"Requirements\")) +\n \"\\n```\\n\"\n )\n }]\n\n if (quickInfo.documentation) {\n return {\n ...quickInfo,\n documentation: effectTypeArgsDocumentation.concat(quickInfo.documentation)\n }\n }\n\n return {\n ...quickInfo,\n documentation: effectTypeArgsDocumentation\n }\n }),\n Nano.orElse(() => Nano.succeed(quickInfo))\n )\n}\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as AST from \"../utils/AST.js\"\nimport * as TypeCheckerApi from \"../utils/TypeCheckerApi.js\"\nimport * as TypeParser from \"../utils/TypeParser.js\"\nimport * as TypeScriptApi from \"../utils/TypeScriptApi.js\"\n\nexport const asyncAwaitToGen = LSP.createRefactor({\n name: \"effect/asyncAwaitToGen\",\n description: \"Convert to Effect.gen\",\n apply: (sourceFile, textRange) =>\n Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n const maybeNode = pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.filter((node) =>\n ts.isFunctionDeclaration(node) || ts.isArrowFunction(node) ||\n ts.isFunctionExpression(node)\n ),\n ReadonlyArray.filter((node) => !!node.body),\n ReadonlyArray.filter((node) =>\n !!(ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Async)\n ),\n ReadonlyArray.head\n )\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const node = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.asyncAwaitToGen\",\n description: \"Rewrite to Effect.gen\",\n apply: pipe(\n Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n const effectModuleIdentifierName = Option.match(\n yield* Nano.option(\n AST.findImportedModuleIdentifier(\n sourceFile,\n (node) =>\n pipe(\n TypeParser.importedEffectModule(node),\n Nano.option,\n Nano.map(Option.isSome)\n )\n )\n ),\n {\n onNone: () => \"Effect\",\n onSome: (node) => node.text\n }\n )\n\n const newDeclaration = yield* AST.transformAsyncAwaitToEffectGen(\n node,\n effectModuleIdentifierName,\n (expression) =>\n ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectModuleIdentifierName),\n \"promise\"\n ),\n undefined,\n [\n ts.factory.createArrowFunction(\n undefined,\n undefined,\n [],\n undefined,\n undefined,\n expression\n )\n ]\n )\n )\n\n changeTracker.replaceNode(sourceFile, node, newDeclaration)\n }),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts),\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, typeChecker)\n )\n })\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as AST from \"../utils/AST.js\"\nimport * as TypeCheckerApi from \"../utils/TypeCheckerApi.js\"\nimport * as TypeParser from \"../utils/TypeParser.js\"\nimport * as TypeScriptApi from \"../utils/TypeScriptApi.js\"\n\nexport const asyncAwaitToGenTryPromise = LSP.createRefactor({\n name: \"effect/asyncAwaitToGenTryPromise\",\n description: \"Convert to Effect.gen with failures\",\n apply: (sourceFile, textRange) =>\n Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n const maybeNode = pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.filter(\n (node) =>\n ts.isFunctionDeclaration(node) || ts.isArrowFunction(node) ||\n ts.isFunctionExpression(node)\n ),\n ReadonlyArray.filter((node) => !!node.body),\n ReadonlyArray.filter((node) =>\n !!(ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Async)\n ),\n ReadonlyArray.head\n )\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const node = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.asyncAwaitToGenTryPromise\",\n description: \"Rewrite to Effect.gen with failures\",\n apply: pipe(\n Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n const effectModuleIdentifierName = Option.match(\n yield* Nano.option(\n AST.findImportedModuleIdentifier(\n sourceFile,\n (node) =>\n pipe(\n TypeParser.importedEffectModule(node),\n Nano.option,\n Nano.map(Option.isSome)\n )\n )\n ),\n {\n onNone: () => \"Effect\",\n onSome: (node) => node.text\n }\n )\n\n let errorCount = 0\n\n function createErrorADT() {\n errorCount++\n return ts.factory.createObjectLiteralExpression([\n ts.factory.createPropertyAssignment(\n \"_tag\",\n ts.factory.createAsExpression(\n ts.factory.createStringLiteral(\"Error\" + errorCount),\n ts.factory.createTypeReferenceNode(\"const\")\n )\n ),\n ts.factory.createShorthandPropertyAssignment(\"error\")\n ])\n }\n\n const newDeclaration = yield* AST.transformAsyncAwaitToEffectGen(\n node,\n effectModuleIdentifierName,\n (expression) =>\n ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectModuleIdentifierName),\n \"tryPromise\"\n ),\n undefined,\n [\n ts.factory.createObjectLiteralExpression([\n ts.factory.createPropertyAssignment(\n ts.factory.createIdentifier(\"try\"),\n ts.factory.createArrowFunction(\n undefined,\n undefined,\n [],\n undefined,\n undefined,\n expression\n )\n ),\n ts.factory.createPropertyAssignment(\n ts.factory.createIdentifier(\"catch\"),\n ts.factory.createArrowFunction(\n undefined,\n undefined,\n [ts.factory.createParameterDeclaration(undefined, undefined, \"error\")],\n undefined,\n undefined,\n createErrorADT()\n )\n )\n ])\n ]\n )\n )\n\n changeTracker.replaceNode(sourceFile, node, newDeclaration)\n }),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts),\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, typeChecker)\n )\n })\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as AST from \"../utils/AST.js\"\nimport * as TypeParser from \"../utils/TypeParser.js\"\nimport * as TypeScriptApi from \"../utils/TypeScriptApi.js\"\n\nexport const effectGenToFn = LSP.createRefactor({\n name: \"effect/effectGenToFn\",\n description: \"Convert to Effect.fn\",\n apply: (sourceFile, textRange) =>\n Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n function parseEffectGenNode(node: ts.Node) {\n return Nano.gen(function*() {\n // check if the node is a Effect.gen(...)\n const effectGen = yield* TypeParser.effectGen(node)\n // if parent is a Effect.gen(...).pipe(...) we then move the pipe tot the new Effect.fn\n let pipeArgs = ts.factory.createNodeArray<ts.Expression>([])\n let nodeToReplace = node.parent\n if (\n ts.isPropertyAccessExpression(node.parent) && node.parent.name.text === \"pipe\" &&\n ts.isCallExpression(node.parent.parent)\n ) {\n pipeArgs = node.parent.parent.arguments\n nodeToReplace = node.parent.parent.parent\n }\n // then we iterate upwards until we find the function declaration\n while (nodeToReplace) {\n // if arrow function, exit\n if (\n ts.isArrowFunction(nodeToReplace) || ts.isFunctionDeclaration(nodeToReplace) ||\n ts.isMethodDeclaration(nodeToReplace)\n ) {\n return ({ ...effectGen, pipeArgs, nodeToReplace })\n }\n // concise body go up\n if (ts.isConciseBody(nodeToReplace) || ts.isReturnStatement(nodeToReplace)) {\n nodeToReplace = nodeToReplace.parent\n continue\n }\n // function body with only one statement, go up\n if (ts.isBlock(nodeToReplace) && nodeToReplace.statements.length === 1) {\n nodeToReplace = nodeToReplace.parent\n continue\n }\n // exit\n break\n }\n return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n })\n }\n\n const maybeNode = yield* pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.map(parseEffectGenNode),\n Nano.firstSuccessOf,\n Nano.option\n )\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const { effectModule, generatorFunction, nodeToReplace, pipeArgs } = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.effectGenToFn\",\n description: \"Convert to Effect.fn\",\n apply: pipe(\n Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n // if we have a name in the function declaration,\n // we call Effect.fn with the name\n const effectFn = nodeToReplace.name && ts.isIdentifier(nodeToReplace.name) ?\n ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n effectModule,\n \"fn\"\n ),\n undefined,\n [ts.factory.createStringLiteral(nodeToReplace.name.text)]\n ) :\n ts.factory.createPropertyAccessExpression(\n effectModule,\n \"fn\"\n )\n // append the generator and pipe arguments to the Effect.fn call\n const effectFnCallWithGenerator = ts.factory.createCallExpression(\n effectFn,\n undefined,\n [ts.factory.createFunctionExpression(\n undefined,\n ts.factory.createToken(ts.SyntaxKind.AsteriskToken),\n undefined,\n nodeToReplace.typeParameters,\n nodeToReplace.parameters,\n nodeToReplace.type,\n generatorFunction.body\n ) as ts.Expression].concat(pipeArgs)\n )\n changeTracker.replaceNode(\n sourceFile,\n nodeToReplace,\n yield* AST.tryPreserveDeclarationSemantics(nodeToReplace, effectFnCallWithGenerator)\n )\n }),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts)\n )\n })\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as AST from \"../utils/AST.js\"\nimport * as TypeScriptApi from \"../utils/TypeScriptApi.js\"\n\nexport const functionToArrow = LSP.createRefactor({\n name: \"effect/functionToArrow\",\n description: \"Convert to arrow\",\n apply: (sourceFile, textRange) =>\n Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const maybeNode = pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.filter((_) => ts.isFunctionDeclaration(_) || ts.isMethodDeclaration(_)),\n ReadonlyArray.filter((_) => !!_.body),\n ReadonlyArray.filter((_) => !!_.name && AST.isNodeInRange(textRange)(_.name)),\n ReadonlyArray.head\n )\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const node = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.functionToArrow\",\n description: \"Convert to arrow\",\n apply: pipe(\n Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n const body = node.body!\n let newBody: ts.ConciseBody = ts.factory.createBlock(body.statements)\n if (body.statements.length === 1) {\n const statement = body.statements[0]\n if (statement && ts.isReturnStatement(statement) && statement.expression) {\n newBody = statement.expression!\n }\n }\n\n let arrowFlags = ts.getCombinedModifierFlags(node)\n arrowFlags &= ~ts.ModifierFlags.Export\n arrowFlags &= ~ts.ModifierFlags.Default\n const arrowModifiers = ts.factory.createModifiersFromModifierFlags(arrowFlags)\n\n const arrowFunction = ts.factory.createArrowFunction(\n arrowModifiers,\n node.typeParameters,\n node.parameters,\n undefined,\n ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),\n newBody\n )\n\n const newDeclaration: ts.Node = yield* AST.tryPreserveDeclarationSemantics(\n node,\n arrowFunction\n )\n changeTracker.replaceNode(sourceFile, node, newDeclaration, {\n leadingTriviaOption: ts.textChanges.LeadingTriviaOption.IncludeAll,\n trailingTriviaOption: ts.textChanges.TrailingTriviaOption.Exclude\n })\n }),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts)\n )\n })\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as AST from \"../utils/AST.js\"\nimport * as TypeCheckerApi from \"../utils/TypeCheckerApi.js\"\nimport * as TypeScriptApi from \"../utils/TypeScriptApi.js\"\n\nexport const pipeableToDatafirst = LSP.createRefactor({\n name: \"effect/pipeableToDatafirst\",\n description: \"Rewrite to datafirst\",\n apply: (sourceFile, textRange) =>\n Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n function isPipeCall(node: ts.Node): node is ts.CallExpression {\n if (!ts.isCallExpression(node)) return false\n const expression = node.expression\n if (!ts.isIdentifier(expression)) return false\n if (expression.text !== \"pipe\") return false\n return true\n }\n\n function asDataFirstExpression(\n node: ts.Node,\n self: ts.Expression\n ): Option.Option<ts.CallExpression> {\n if (!ts.isCallExpression(node)) return Option.none()\n const signature = typeChecker.getResolvedSignature(node)\n if (!signature) return Option.none()\n const callSignatures = typeChecker.getTypeAtLocation(node.expression).getCallSignatures()\n for (let i = 0; i < callSignatures.length; i++) {\n const callSignature = callSignatures[i]\n if (callSignature.parameters.length === node.arguments.length + 1) {\n return Option.some(\n ts.factory.createCallExpression(\n node.expression,\n [],\n [self].concat(node.arguments)\n )\n )\n }\n }\n return Option.none()\n }\n\n const maybeNode = pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.filter(isPipeCall),\n ReadonlyArray.filter((node) => AST.isNodeInRange(textRange)(node.expression)),\n ReadonlyArray.filter(\n (node) => node.arguments.length > 0\n ),\n ReadonlyArray.map((node) => {\n let newNode = node.arguments[0]\n let didSomething = false\n for (let i = 1; i < node.arguments.length; i++) {\n const arg = node.arguments[i]\n const a = asDataFirstExpression(arg, newNode)\n if (Option.isSome(a)) {\n // use found datafirst\n newNode = a.value\n didSomething = true\n } else {\n if (isPipeCall(newNode)) {\n // avoid nested pipe(a, pipe(b, c))\n newNode = ts.factory.createCallExpression(\n ts.factory.createIdentifier(\"pipe\"),\n [],\n newNode.arguments.concat([arg])\n )\n } else {\n // no datafirst, keep pipeable\n newNode = ts.factory.createCallExpression(ts.factory.createIdentifier(\"pipe\"), [], [\n newNode,\n arg\n ])\n }\n }\n }\n return didSomething ? Option.some([node, newNode] as const) : Option.none()\n }),\n ReadonlyArray.filter(Option.isSome),\n ReadonlyArray.map((_) => _.value),\n ReadonlyArray.head\n )\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const [node, newNode] = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.pipeableToDatafirst\",\n description: \"Rewrite to datafirst\",\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n changeTracker.replaceNode(sourceFile, node, newNode)\n })\n })\n })\n})\n","import { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as AST from \"../utils/AST.js\"\nimport * as TypeParser from \"../utils/TypeParser.js\"\nimport * as TypeScriptApi from \"../utils/TypeScriptApi.js\"\n\n/**\n * Refactor to remove unnecessary `Effect.gen` calls.\n *\n * This refactor identifies `Effect.gen` calls that are redundant because they only wrap\n * a single `yield*` statement returning an `Effect`. In such cases, the `Effect.gen` wrapper\n * can be removed, and the inner `Effect` can be returned directly.\n *\n * The function works by analyzing the AST within the specified `textRange` to locate\n * `Effect.gen` calls. It checks if the body of the generator function contains only a single\n * `yield*` statement that directly returns an `Effect`. If such a pattern is found, the\n * `Effect.gen` wrapper is replaced with the inner `Effect`.\n *\n * @example\n * Input:\n * ```ts\n * const result = Effect.gen(function* () {\n * return yield* Effect.succeed(42)\n * })\n * ```\n * Output:\n * ```ts\n * const result = Effect.succeed(42)\n * ```\n *\n * @param ts - The TypeScript API.\n * @param program - The TypeScript program instance, used for type checking.\n * @returns A refactor function that takes a `SourceFile` and a `TextRange`, analyzes the AST,\n * and applies the refactor if applicable.\n */\nexport const removeUnnecessaryEffectGen = LSP.createRefactor({\n name: \"effect/removeUnnecessaryEffectGen\",\n description: \"Remove unnecessary Effect.gen\",\n apply: (sourceFile, textRange) =>\n Nano.gen(function*() {\n for (\n const nodeToReplace of yield* AST.collectDescendantsAndAncestorsInRange(\n sourceFile,\n textRange\n )\n ) {\n const maybeNode = yield* pipe(\n TypeParser.effectGen(nodeToReplace),\n Nano.flatMap(({ body }) => TypeParser.returnYieldEffectBlock(body)),\n Nano.option\n )\n\n if (Option.isNone(maybeNode)) continue\n const returnedYieldedEffect = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.removeUnnecessaryEffectGen\",\n description: \"Remove unnecessary Effect.gen\",\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n changeTracker.replaceNode(sourceFile, nodeToReplace, returnedYieldedEffect)\n })\n })\n }\n\n return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as AST from \"../utils/AST.js\"\nimport * as TypeScriptApi from \"../utils/TypeScriptApi.js\"\n\nexport const toggleLazyConst = LSP.createRefactor({\n name: \"effect/toggleLazyConst\",\n description: \"Toggle type annotation\",\n apply: (sourceFile, textRange) =>\n Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const maybeNode = pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.filter(ts.isVariableDeclaration),\n ReadonlyArray.filter((node) => AST.isNodeInRange(textRange)(node.name)),\n ReadonlyArray.filter((node) =>\n !!node.initializer &&\n !(ts.isArrowFunction(node.initializer) && ts.isBlock(node.initializer.body))\n ),\n ReadonlyArray.head\n )\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const node = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.toggleLazyConst\",\n description: \"Toggle lazy const\",\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n const initializer = node.initializer!\n\n if (ts.isArrowFunction(initializer) && initializer.parameters.length === 0) {\n // delete eventual closing bracked\n changeTracker.deleteRange(sourceFile, {\n pos: initializer.body.end,\n end: initializer.end\n })\n // remove () => {\n changeTracker.deleteRange(sourceFile, {\n pos: initializer.pos,\n end: initializer.body.pos\n })\n return\n }\n\n // adds () => before\n changeTracker.insertText(sourceFile, initializer.pos, \" () =>\")\n })\n })\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as AST from \"../utils/AST.js\"\nimport * as TypeCheckerApi from \"../utils/TypeCheckerApi.js\"\nimport * as TypeScriptApi from \"../utils/TypeScriptApi.js\"\n\nexport const toggleReturnTypeAnnotation = LSP.createRefactor({\n name: \"effect/toggleReturnTypeAnnotation\",\n description: \"Toggle return type annotation\",\n apply: (sourceFile, textRange) =>\n Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n const maybeNode = pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.filter((node) =>\n ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) ||\n ts.isArrowFunction(node) || ts.isMethodDeclaration(node)\n ),\n ReadonlyArray.head\n )\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const node = maybeNode.value\n\n if (node.type) {\n return ({\n kind: \"refactor.rewrite.effect.toggleReturnTypeAnnotation\",\n description: \"Toggle return type annotation\",\n apply: pipe(\n AST.removeReturnTypeAnnotation(sourceFile, node),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts)\n )\n })\n }\n\n const returnType = yield* Nano.option(TypeCheckerApi.getInferredReturnType(node))\n if (Option.isNone(returnType)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n\n const returnTypeNode = typeChecker.typeToTypeNode(\n returnType.value,\n node,\n ts.NodeBuilderFlags.NoTruncation\n )\n\n if (!returnTypeNode) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n\n return ({\n kind: \"refactor.rewrite.effect.toggleReturnTypeAnnotation\",\n description: \"Toggle return type annotation\",\n apply: pipe(\n AST.addReturnTypeAnnotation(\n sourceFile,\n node,\n yield* AST.simplifyTypeNode(returnTypeNode)\n ),\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, typeChecker),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts)\n )\n })\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as AST from \"../utils/AST.js\"\nimport * as TypeCheckerApi from \"../utils/TypeCheckerApi.js\"\nimport * as TypeScriptApi from \"../utils/TypeScriptApi.js\"\n\nexport const toggleTypeAnnotation = LSP.createRefactor({\n name: \"effect/toggleTypeAnnotation\",\n description: \"Toggle type annotation\",\n apply: (sourceFile, textRange) =>\n Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n const maybeNode = pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.filter((node) =>\n ts.isVariableDeclaration(node) || ts.isPropertyDeclaration(node)\n ),\n ReadonlyArray.filter((node) => AST.isNodeInRange(textRange)(node.name)),\n ReadonlyArray.filter((node) => !!node.initializer),\n ReadonlyArray.head\n )\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const node = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.toggleTypeAnnotation\",\n description: \"Toggle type annotation\",\n apply: pipe(\n Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n if (node.type) {\n changeTracker.deleteRange(sourceFile, { pos: node.name.end, end: node.type.end })\n return\n }\n\n const initializer = node.initializer!\n const initializerType = typeChecker.getTypeAtLocation(initializer)\n const initializerTypeNode = Option.fromNullable(typeChecker.typeToTypeNode(\n initializerType,\n node,\n ts.NodeBuilderFlags.NoTruncation\n )).pipe(\n Option.orElse(() =>\n Option.fromNullable(typeChecker.typeToTypeNode(\n initializerType,\n undefined,\n ts.NodeBuilderFlags.NoTruncation\n ))\n ),\n Option.getOrUndefined\n )\n if (initializerTypeNode) {\n changeTracker.insertNodeAt(\n sourceFile,\n node.name.end,\n yield* AST.simplifyTypeNode(initializerTypeNode),\n {\n prefix: \": \"\n }\n )\n }\n }),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts)\n )\n })\n })\n})\n","import * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeScriptApi from \"../utils/TypeScriptApi.js\"\n\nexport const wrapWithPipe = LSP.createRefactor({\n name: \"effect/wrapWithPipe\",\n description: \"Wrap with pipe\",\n apply: (sourceFile, textRange) =>\n Nano.gen(function*() {\n if (textRange.end - textRange.pos === 0) {\n return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n }\n\n return ({\n kind: \"refactor.rewrite.effect.wrapWithPipe\",\n description: `Wrap with pipe(...)`,\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n changeTracker.insertText(sourceFile, textRange.pos, \"pipe(\")\n changeTracker.insertText(sourceFile, textRange.end, \")\")\n })\n })\n })\n})\n","import { asyncAwaitToGen } from \"./refactors/asyncAwaitToGen.js\"\nimport { asyncAwaitToGenTryPromise } from \"./refactors/asyncAwaitToGenTryPromise.js\"\nimport { effectGenToFn } from \"./refactors/effectGenToFn.js\"\nimport { functionToArrow } from \"./refactors/functionToArrow.js\"\nimport { pipeableToDatafirst } from \"./refactors/pipeableToDatafirst.js\"\nimport { removeUnnecessaryEffectGen } from \"./refactors/removeUnnecessaryEffectGen.js\"\nimport { toggleLazyConst } from \"./refactors/toggleLazyConst.js\"\nimport { toggleReturnTypeAnnotation } from \"./refactors/toggleReturnTypeAnnotation.js\"\nimport { toggleTypeAnnotation } from \"./refactors/toggleTypeAnnotation.js\"\nimport { wrapWithPipe } from \"./refactors/wrapWithPipe.js\"\n\nexport const refactors = [\n asyncAwaitToGen,\n asyncAwaitToGenTryPromise,\n functionToArrow,\n pipeableToDatafirst,\n removeUnnecessaryEffectGen,\n toggleLazyConst,\n toggleReturnTypeAnnotation,\n toggleTypeAnnotation,\n wrapWithPipe,\n effectGenToFn\n]\n","import { Either } from \"effect\"\nimport { pipe } from \"effect/Function\"\nimport type ts from \"typescript\"\nimport * as LSP from \"./core/LSP.js\"\nimport * as Nano from \"./core/Nano.js\"\nimport { diagnostics } from \"./diagnostics.js\"\nimport { dedupeJsDocTags, prependEffectTypeArguments } from \"./quickinfo.js\"\nimport { refactors } from \"./refactors.js\"\nimport * as TypeCheckerApi from \"./utils/TypeCheckerApi.js\"\nimport * as TypeScriptApi from \"./utils/TypeScriptApi.js\"\n\nconst init = (\n modules: {\n typescript: typeof ts\n }\n) => {\n function create(info: ts.server.PluginCreateInfo) {\n const languageService = info.languageService\n const pluginOptions: LSP.PluginOptions = {\n diagnostics:\n info.config && \"diagnostics\" in info.config && typeof info.config.diagnostics === \"boolean\"\n ? info.config.diagnostics\n : true,\n quickinfo:\n info.config && \"quickinfo\" in info.config && typeof info.config.quickinfo === \"boolean\"\n ? info.config.quickinfo\n : true\n }\n\n // create the proxy\n const proxy: ts.LanguageService = Object.create(null)\n for (const k of Object.keys(info.languageService) as Array<keyof ts.LanguageService>) {\n // @ts-expect-error\n proxy[k] = (...args: Array<{}>) => languageService[k]!.apply(languageService, args)\n }\n\n proxy.getSemanticDiagnostics = (fileName, ...args) => {\n const applicableDiagnostics = languageService.getSemanticDiagnostics(fileName, ...args)\n const program = languageService.getProgram()\n\n if (pluginOptions.diagnostics && program) {\n const sourceFile = program.getSourceFile(fileName)\n\n if (sourceFile) {\n return pipe(\n LSP.getSemanticDiagnostics(diagnostics, sourceFile),\n Nano.provideService(TypeScriptApi.TypeScriptApi, modules.typescript),\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, program.getTypeChecker()),\n Nano.provideService(LSP.PluginOptions, pluginOptions),\n Nano.run,\n Either.map((effectDiagnostics) => effectDiagnostics.concat(applicableDiagnostics)),\n Either.getOrElse(() => applicableDiagnostics)\n )\n }\n }\n\n return applicableDiagnostics\n }\n\n proxy.getApplicableRefactors = (...args) => {\n const applicableRefactors = languageService.getApplicableRefactors(...args)\n const [fileName, positionOrRange] = args\n const program = languageService.getProgram()\n\n if (program) {\n const sourceFile = program.getSourceFile(fileName)\n if (sourceFile) {\n return pipe(\n LSP.getApplicableRefactors(refactors, sourceFile, positionOrRange),\n Nano.provideService(TypeScriptApi.TypeScriptApi, modules.typescript),\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, program.getTypeChecker()),\n Nano.provideService(LSP.PluginOptions, pluginOptions),\n Nano.run,\n Either.map((effectRefactors) => applicableRefactors.concat(effectRefactors)),\n Either.getOrElse(() => applicableRefactors)\n )\n }\n }\n return applicableRefactors\n }\n\n proxy.getEditsForRefactor = (\n fileName,\n formatOptions,\n positionOrRange,\n refactorName,\n actionName,\n preferences,\n ...args\n ) => {\n const program = languageService.getProgram()\n if (program) {\n const sourceFile = program.getSourceFile(fileName)\n if (sourceFile) {\n const result = pipe(\n Nano.gen(function*() {\n const applicableRefactor = yield* LSP.getEditsForRefactor(\n refactors,\n sourceFile,\n positionOrRange,\n refactorName\n )\n\n const formatContext = modules.typescript.formatting.getFormatContext(\n formatOptions,\n info.languageServiceHost\n )\n const edits = modules.typescript.textChanges.ChangeTracker.with(\n {\n formatContext,\n host: info.languageServiceHost,\n preferences: preferences || {}\n },\n (changeTracker) =>\n pipe(\n applicableRefactor.apply,\n Nano.provideService(TypeScriptApi.ChangeTracker, changeTracker),\n Nano.run\n )\n )\n\n return { edits } as ts.RefactorEditInfo\n }),\n Nano.provideService(TypeScriptApi.TypeScriptApi, modules.typescript),\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, program.getTypeChecker()),\n Nano.provideService(LSP.PluginOptions, pluginOptions),\n Nano.run\n )\n\n if (Either.isRight(result)) return result.right\n }\n }\n\n return languageService.getEditsForRefactor(\n fileName,\n formatOptions,\n positionOrRange,\n refactorName,\n actionName,\n preferences,\n ...args\n )\n }\n\n proxy.getQuickInfoAtPosition = (fileName, position, ...args) => {\n const quickInfo = languageService.getQuickInfoAtPosition(fileName, position, ...args)\n\n if (pluginOptions.quickinfo && quickInfo) {\n const dedupedTagsQuickInfo = dedupeJsDocTags(quickInfo)\n\n const program = languageService.getProgram()\n if (program) {\n const sourceFile = program.getSourceFile(fileName)\n if (sourceFile) {\n return pipe(\n prependEffectTypeArguments(\n sourceFile,\n position,\n dedupedTagsQuickInfo\n ),\n Nano.provideService(TypeScriptApi.TypeScriptApi, modules.typescript),\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, program.getTypeChecker()),\n Nano.run,\n Either.getOrElse(() => dedupedTagsQuickInfo)\n )\n }\n }\n\n return dedupedTagsQuickInfo\n }\n\n return quickInfo\n }\n\n return proxy\n }\n\n return { create }\n}\n\nmodule.exports = init\n"],"mappings":";;;;;;;;AA6BO,IAAMA,aAAcC,WAAsC,OAAOA,UAAU;AA6C3E,IAAMC,OA+FT,SAASC,OAAOC,MAAI;AACtB,MAAI,OAAOD,UAAU,YAAY;AAC/B,WAAO,WAAA;AACL,UAAIA,MAAME,SAAS,GAAG;AAEpB,eAAOD,KAAKE,MAAM,MAAMD,SAAS;MACnC;AACA,aAASE,UAAcH,KAAKG,MAAM,GAAGF,SAAS;IAChD;EACF;AAEA,UAAQF,OAAK;IACX,KAAK;IACL,KAAK;AACH,YAAM,IAAIK,WAAW,iBAAiBL,KAAK,EAAE;IAE/C,KAAK;AACH,aAAO,SAASM,GAAGC,GAAC;AAClB,YAAIL,UAAUM,UAAU,GAAG;AACzB,iBAAOP,KAAKK,GAAGC,CAAC;QAClB;AACA,eAAO,SAASH,MAAS;AACvB,iBAAOH,KAAKG,MAAME,CAAC;QACrB;MACF;IAEF,KAAK;AACH,aAAO,SAASA,GAAGC,GAAGE,GAAC;AACrB,YAAIP,UAAUM,UAAU,G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AC3C,YAAI,SAAS;AACX,gBAAM,aAAa,QAAQ,cAAc,QAAQ;AACjD,cAAI,YAAY;AACd,mBAAO;AAAA,cACL;AAAA,gBACE;AAAA,gBACA;AAAA,gBACA;AAAA,cACF;AAAA,cACK,eAA6B,eAAe,QAAQ,UAAU;AAAA,cAC9D,eAA8B,gBAAgB,QAAQ,eAAe,CAAC;AAAA,cACtE;AAAA,cACL,eAAO,UAAU,MAAM,oBAAoB;AAAA,YAC7C;AAAA,UACF;AAAA,QACF;AAEA,eAAO;AAAA,MACT;AAEA,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AAEA,SAAO,EAAE,OAAO;AAClB;AAEA,OAAO,UAAU;","names":["isFunction","input","dual","arity","body","arguments","apply","self","RangeError","a","b","length","c","d","e","args","identity","a","constant","value","constTrue","constFalse","constNull","constUndefined","undefined","pipe","a","ab","bc","cd","de","ef","fg","gh","hi","arguments","length","ret","i","TypeId","bind","bindTo","fromOption","getLeft","getRight","isEither","isLeft","isRight","left","let_","right","make","isEquivalent","self","that","array","item","make","self","that","length","i","isEq","let_","map","dual","self","name","f","a","Object","assign","bindTo","bind","flatMap","b","moduleVersion","getCurrentVersion","globalStoreId","version","getCurrentVersion","globalStore","globalValue","id","compute","globalThis","Map","has","set","get","isFunction","isFunction_","isRecordOrArray","input","isObject","isFunction","hasProperty","dual","self","property","isTagged","tag","getBugErrorMessage","message","GenKindTypeId","Symbol","for","isGenKind","u","isObject","GenKindImpl","value","constructor","_F","identity","_R","_","_O","_E","iterator","SingleShotGen","self","called","next","a","done","return","throw","e","adapter","x","arguments","i","length","GenKindImpl","MUL_HI","MUL_LO","YieldWrapTypeId","Symbol","for","YieldWrap","constructor","value","yieldWrapGet","self","Error","getBugErrorMessage","structuralRegionState","globalValue","enabled","tester","undefined","genConstructor","constructor","randomHashCache","globalValue","Symbol","for","WeakMap","symbol","hash","self","structuralRegionState","enabled","number","string","toString","String","Date","toISOString","isHash","random","Error","has","set","Math","floor","Number","MAX_SAFE_INTEGER","get","combine","b","optimize","n","u","hasProperty","Infinity","h","str","i","length","charCodeAt","structureKeys","o","keys","pipe","structure","Object","array","arr","cached","arguments","defineProperty","value","enumerable","symbol","Symbol","for","equals","arguments","length","self","compareBoth","that","selfType","isEqual","hash","structuralRegionState","enabled","tester","Date","toISOString","Array","isArray","every","v","i","Object","getPrototypeOf","prototype","keysSelf","keys","keysThat","key","u","hasProperty","NodeInspectSymbol","Symbol","for","toJSON","x","hasProperty","isFunction","length","Array","isArray","map","_","redact","format","JSON","stringify","BaseProto","toString","Class","stringifyCircular","obj","whitespace","cache","retVal","JSON","stringify","_key","value","includes","undefined","push","redactableState","fiberRefs","isRedactable","symbolRedactable","Symbol","for","u","globalValue","redact","u","isRedactable","redactableState","fiberRefs","undefined","symbolRedactable","pipeArguments","self","args","length","ret","i","len","OP_COMMIT","OP_FAILURE","OP_WITH_RUNTIME","EffectTypeId","Symbol","for","StreamTypeId","SinkTypeId","ChannelTypeId","effectVariance","_R","_","_E","_A","_V","version","getCurrentVersion","sinkVariance","_In","_L","channelVariance","_Env","_InErr","_InElem","_InDone","_OutErr","_OutElem","_OutDone","EffectPrototype","symbol","that","cached","random","iterator","SingleShotGen","YieldWrap","pipe","pipeArguments","arguments","StructuralPrototype","structure","selfKeys","Object","keys","thatKeys","length","key","equals","CommitPrototype","_op","OP_COMMIT","StructuralCommitPrototype","TypeId","Symbol","for","CommonProto","EffectPrototype","_A","_","NodeInspectSymbol","toJSON","toString","format","SomeProto","Object","assign","create","_tag","_op","symbol","that","isOption","isSome","equals","value","cached","combine","hash","_id","NoneHash","Hash","NoneProto","isNone","input","hasProperty","fa","none","some","a","TypeId","Symbol","for","CommonProto","EffectPrototype","_R","_","NodeInspectSymbol","toJSON","toString","format","RightProto","Object","assign","create","_tag","_op","symbol","that","isEither","isRight","equals","right","combine","hash","_id","LeftProto","isLeft","left","input","hasProperty","ma","a","getLeft","self","none","some","getRight","fromOption","dual","onNone","isNone","value","TypeId","right","left","fromNullable","dual","self","onNullable","fromOption","try_","evaluate","isFunction","e","try","catch","isEither","isLeft","isRight","getRight","getLeft","getEquivalence","left","right","make","x","y","mapBoth","dual","self","onLeft","onRight","mapLeft","f","map","match","liftPredicate","a","predicate","orLeftWith","filterOrLeft","flatMap","r","merge","identity","getOrElse","getOrNull","constNull","getOrUndefined","constUndefined","getOrThrowWith","getOrThrow","Error","orElse","that","andThen","b","isFunction","zipWith","r2","ap","all","input","Symbol","iterator","out","e","push","key","Object","keys","flip","adapter","Gen","gen","args","length","bind","state","next","done","value","current","isGenKind","yieldWrapGet","Do","doNotation","bindTo","let_","isNonEmptyArray","self","length","make","compare","self","that","none","some","isNone","isSome","match","dual","self","onNone","onSome","value","getOrElse","dual","self","onNone","isNone","value","orElse","that","fromNullable","nullableValue","none","some","getOrUndefined","getOrElse","constUndefined","fromIterable","collection","Array","isArray","from","append","dual","self","last","isArray","Array","isNonEmptyReadonlyArray","isNonEmptyArray","isOutOfBound","i","as","length","get","dual","self","index","i","Math","floor","isOutOfBound","none","some","unsafeGet","Error","head","get","headNonEmpty","unsafeGet","tailNonEmpty","self","slice","reverse","self","Array","from","sort","dual","O","out","empty","map","dual","self","f","filter","dual","self","predicate","as","fromIterable","out","i","length","push","reduce","dual","self","b","f","fromIterable","a","i","dedupeWith","dual","self","isEquivalent","input","fromIterable","isNonEmptyReadonlyArray","out","headNonEmpty","rest","tailNonEmpty","r","every","a","push","TypeId","Symbol","for","copy","src","srcPos","dest","destPos","len","i","Math","min","length","emptyArray","getEquivalence","isEquivalent","make","self","that","toReadonlyArray","every","value","unsafeGet","_equivalence","equals","ChunkProto","_A","_","toString","format","toJSON","_id","values","map","NodeInspectSymbol","symbol","isChunk","cached","array","iterator","backing","_tag","pipe","pipeArguments","arguments","makeChunk","chunk","Object","create","depth","left","right","max","_empty","u","hasProperty","empty","as","of","unsafeFromNonEmptyArray","a","fromIterable","copyToArray","initial","j","toReadonlyArray_","self","backing","_tag","emptyArray","array","arr","Array","length","copyToArray","left","_empty","right","depth","toReadonlyArray","reverseChunk","makeChunk","reverse","unsafeFromArray","unsafeFromArray","self","makeChunk","_tag","array","unsafeFromNonEmptyArray","unsafeGet","dual","index","backing","Error","a","length","left","right","chunk","offset","prepend","dual","self","elem","appendAll","of","appendAll","dual","self","that","backing","_tag","diff","depth","Math","abs","makeChunk","left","right","nr","nrr","nl","nll","isEmpty","self","length","isNonEmpty","unsafeHead","self","unsafeGet","headNonEmpty","SIZE","BUCKET_SIZE","Math","pow","MASK","MAX_INDEX_NODE","MIN_ARRAY_NODE","popcount","x","hashFragment","shift","h","MASK","toBitmap","fromBitmap","bitmap","bit","make","value","previous","arrayUpdate","mutate","at","v","arr","out","len","length","Array","i","arraySpliceOut","newLen","g","arraySpliceIn","EmptyNode","_tag","modify","edit","_shift","f","hash","key","size","v","none","isNone","value","LeafNode","isEmptyNode","a","isTagged","isLeafNode","node","canEditNode","constructor","shift","equals","mergeLeaves","CollisionNode","children","canEdit","list","updateCollisionList","length","mutate","len","i","child","newValue","arraySpliceOut","arrayUpdate","IndexedNode","mask","frag","hashFragment","bit","toBitmap","indx","fromBitmap","exists","_newChild","SIZE","MAX_INDEX_NODE","expand","arraySpliceIn","current","bitmap","newChildren","ArrayNode","count","newChild","MIN_ARRAY_NODE","pack","removed","elements","Array","g","elem","subNodes","arr","mergeLeavesInner","h1","n1","h2","n2","subH1","subH2","stack","undefined","currentShift","res","make","final","previous","HashMapSymbolKey","HashMapTypeId","Symbol","for","HashMapProto","iterator","HashMapIterator","k","v","symbol","hash","item","pipe","combine","cached","that","isHashMap","_size","elem","getHash","isNone","equals","value","toString","format","toJSON","_id","values","Array","from","map","NodeInspectSymbol","pipeArguments","arguments","makeImpl","editable","edit","root","size","Object","create","_editable","_edit","_root","f","constructor","visitLazy","undefined","next","done","v0","applyCont","cont","visitLazyChildren","none","node","_tag","isSome","some","key","children","length","len","i","child","isEmptyNode","_empty","EmptyNode","empty","isHashMap","u","hasProperty","HashMapTypeId","getHash","Dual","dual","self","key","hash","node","_root","shift","_tag","equals","value","none","children","i","len","length","child","frag","hashFragment","bit","toBitmap","mask","fromBitmap","SIZE","set","Dual","dual","self","key","value","modifyAt","some","setTree","newRoot","newSize","_editable","_root","_size","makeImpl","_edit","keys","HashMapIterator","size","self","_size","beginMutation","makeImpl","_edit","_root","modifyAt","Dual","dual","self","key","f","modifyHash","hash","size","value","_size","newRoot","_root","modify","_editable","_edit","NaN","pipe","setTree","forEach","Dual","dual","self","f","reduce","_","value","key","zero","root","_root","_tag","isSome","toVisit","children","pop","i","len","length","child","isEmptyNode","push","HashSetSymbolKey","HashSetTypeId","Symbol","for","HashSetProto","iterator","keys","_keyMap","symbol","cached","combine","hash","that","isHashSet","size","equals","toString","format","toJSON","_id","values","Array","from","map","NodeInspectSymbol","pipe","pipeArguments","arguments","makeImpl","keyMap","set","Object","create","u","hasProperty","_empty","HM","empty","size","self","_keyMap","beginMutation","makeImpl","endMutation","_editable","mutate","dual","f","transient","add","value","set","union","dual","self","that","mutate","empty","set","forEach","value","add","forEach","dual","self","f","_keyMap","_","k","empty","size","add","union","OP_DIE","OP_EMPTY","OP_FAIL","OP_INTERRUPT","OP_PARALLEL","OP_SEQUENTIAL","CauseSymbolKey","CauseTypeId","Symbol","for","variance","_E","_","proto","symbol","pipe","hash","combine","flattenCause","cached","that","isCause","causeEquals","pipeArguments","arguments","toJSON","_tag","_id","defect","fiberId","failure","error","left","right","toString","pretty","NodeInspectSymbol","fail","error","o","Object","create","proto","_tag","OP_FAIL","parallel","left","right","o","Object","create","proto","_tag","OP_PARALLEL","sequential","OP_SEQUENTIAL","isCause","u","hasProperty","CauseTypeId","isInterruptedOnly","self","reduceWithContext","undefined","IsInterruptedOnlyCauseReducer","causeEquals","left","right","leftStack","of","rightStack","isNonEmpty","leftParallel","leftSequential","pipe","headNonEmpty","reduce","empty","parallel","sequential","cause","par","seq","evaluateCause","some","union","appendAll","rightParallel","rightSequential","equals","flattenCause","flattenCauseLoop","causes","flattened","updated","size","prepend","isEmpty","reverse","Error","getBugErrorMessage","evaluateCause","self","cause","stack","_parallel","empty","_sequential","undefined","_tag","OP_EMPTY","length","pop","OP_FAIL","add","make","error","OP_DIE","defect","OP_INTERRUPT","fiberId","OP_SEQUENTIAL","left","right","sequential","OP_PARALLEL","parallel","prepend","push","Error","getBugErrorMessage","IsInterruptedOnlyCauseReducer","emptyCase","constTrue","failCase","constFalse","dieCase","interruptCase","sequentialCase","_","left","right","parallelCase","OP_SEQUENTIAL_CASE","OP_PARALLEL_CASE","reduce","dual","self","zero","pf","accumulator","cause","causes","undefined","option","isSome","value","_tag","OP_SEQUENTIAL","push","right","left","OP_PARALLEL","length","pop","reduceWithContext","context","reducer","input","output","OP_EMPTY","emptyCase","OP_FAIL","failCase","error","OP_DIE","dieCase","defect","OP_INTERRUPT","interruptCase","fiberId","OP_SEQUENTIAL_CASE","OP_PARALLEL_CASE","either","sequentialCase","parallelCase","Error","pretty","options","isInterruptedOnly","prettyErrors","map","e","renderErrorCause","stack","join","prefix","lines","split","i","len","PrettyError","globalThis","span","constructor","originalError","originalErrorIsObject","prevLimit","stackTraceLimit","prettyErrorMessage","message","name","spanSymbol","Object","keys","forEach","key","prettyErrorStack","u","hasProperty","isFunction","prototype","toString","Array","stringifyCircular","locationRegex","spanToTrace","globalValue","WeakMap","out","startsWith","slice","includes","replace","current","stackFn","get","locationMatchAll","matchAll","match","location","getOrUndefined","parent","Symbol","for","_","unknownError","l","r","SingleShotGen","self","called","constructor","next","a","value","done","return","throw","e","Symbol","iterator","EffectTypeId","Symbol","for","EffectPrimitive","_op","effect_instruction_i0","undefined","effect_instruction_i1","effect_instruction_i2","trace","EffectTypeId","effectVariance","constructor","symbol","that","cached","random","pipe","pipeArguments","arguments","toJSON","_id","toString","format","NodeInspectSymbol","Symbol","iterator","SingleShotGen","YieldWrap","EffectPrimitiveFailure","_tag","exitIsExit","equals","string","combine","hash","cause","EffectPrimitiveSuccess","value","isEffect","u","hasProperty","withFiberRuntime","withRuntime","effect","OP_WITH_RUNTIME","spanSymbol","Symbol","for","originalSymbol","capture","obj","span","isSome","Proxy","has","target","p","spanSymbol","originalSymbol","get","value","fail","error","isObject","spanSymbol","withFiberRuntime","fiber","failCause","capture","currentSpanFromFiber","failCause","cause","effect","EffectPrimitiveFailure","OP_FAILURE","effect_instruction_i0","logLevelAll","_tag","syslog","label","ordinal","Number","MIN_SAFE_INTEGER","pipe","pipeArguments","arguments","logLevelNone","_tag","syslog","label","ordinal","Number","MAX_SAFE_INTEGER","pipe","pipeArguments","arguments","RequestResolverSymbolKey","RequestResolverTypeId","Symbol","for","requestResolverVariance","_A","_","_R","RequestResolverImpl","runAll","target","constructor","symbol","cached","hash","random","that","isRequestResolver","equals","identified","ids","fromIterable","pipe","pipeArguments","arguments","u","hasProperty","YieldableError","globalThis","Error","commit","fail","toJSON","NodeInspectSymbol","toString","prototype","stack","split","slice","join","pretty","renderErrorCause","Object","assign","StructuralCommitPrototype","makeException","proto","tag","Base","_tag","name","RuntimeExceptionTypeId","Symbol","for","RuntimeException","InterruptedExceptionTypeId","Symbol","for","InterruptedException","makeException","IllegalArgumentExceptionTypeId","Symbol","for","IllegalArgumentException","makeException","NoSuchElementExceptionTypeId","Symbol","for","NoSuchElementException","makeException","InvalidPubSubCapacityExceptionTypeId","Symbol","for","InvalidPubSubCapacityException","makeException","ExceededCapacityExceptionTypeId","ExceededCapacityException","TimeoutExceptionTypeId","Symbol","for","TimeoutException","makeException","exitIsExit","u","isEffect","_tag","currentSpanFromFiber","fiber","span","currentSpan","undefined","_tag","some","none","Error","plainArgsSymbol","Symbol","for","Base","YieldableError","constructor","args","message","cause","undefined","Object","assign","defineProperty","value","enumerable","toJSON","TaggedError","tag","_tag","prototype","name","some","none","run","right","fail","left","flatMap","isLeft","map","orElse","arr","match","gen","none","some","diagnostics","gen","isSome","refactors","refactor","fail","gen","make","fail","symbol","isSome","fail","gen","isSome","gen","isSome","orElse","isNone","gen","node","orElse","gen","node","orElse","gen","isSome","orElse","gen","flatMap","isSome","gen","fail","isNone","typeNode","some","isSome","none","gen","isNone","effectType","orElse","gen","node","isNone","fail","match","map","isSome","gen","node","isNone","fail","match","map","isSome","gen","effectGen","pipeArgs","nodeToReplace","fail","map","isNone","gen","isNone","fail","gen","node","none","some","map","newNode","isSome","isNone","fail","gen","flatMap","isNone","fail","gen","node","isNone","fail","gen","node","isNone","fail","gen","node","isNone","fail","fromNullable","orElse","getOrUndefined","gen","fail","gen"]}
|