@effect/language-service 0.17.0 → 0.18.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/transform.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/transform.ts","../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/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/Either.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","../src/core/Nano.ts","../src/core/TypeScriptApi.ts","../src/core/LSP.ts","../src/core/TypeCheckerApi.ts","../src/utils/TypeParser.ts","../src/diagnostics/floatingEffect.ts","../src/diagnostics/missingEffectContext.ts","../src/diagnostics/missingEffectError.ts","../src/diagnostics/missingStarInYieldEffectGen.ts","../src/diagnostics/multipleEffectVersions.ts","../src/diagnostics/unnecessaryEffectGen.ts","../src/diagnostics.ts"],"sourcesContent":["import * as Array from \"effect/Array\"\nimport * as Either from \"effect/Either\"\nimport { pipe } from \"effect/Function\"\nimport type { PluginConfig, TransformerExtras } from \"ts-patch\"\nimport type * as ts from \"typescript\"\nimport * as LSP from \"../src/core/LSP\"\nimport * as Nano from \"../src/core/Nano\"\nimport * as TypeCheckerApi from \"../src/core/TypeCheckerApi\"\nimport * as TypeScriptApi from \"../src/core/TypeScriptApi\"\nimport { diagnostics } from \"../src/diagnostics\"\n\nexport default function(\n program: ts.Program,\n pluginConfig: PluginConfig,\n { addDiagnostic, ts: tsInstance }: TransformerExtras\n) {\n return (_: ts.TransformationContext) => {\n return (sourceFile: ts.SourceFile) => {\n // run the diagnostics and pipe them into addDiagnostic\n pipe(\n LSP.getSemanticDiagnosticsWithCodeFixes(diagnostics, sourceFile),\n Nano.provideService(TypeScriptApi.TypeScriptApi, tsInstance),\n Nano.provideService(TypeScriptApi.TypeScriptProgram, program),\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, program.getTypeChecker()),\n Nano.provideService(\n TypeCheckerApi.TypeCheckerApiCache,\n TypeCheckerApi.makeTypeCheckerApiCache()\n ),\n Nano.provideService(LSP.PluginOptions, LSP.parsePluginOptions(pluginConfig)),\n Nano.run,\n Either.map((_) => _.diagnostics),\n Either.map(\n Array.filter((_) =>\n _.category === tsInstance.DiagnosticCategory.Error ||\n _.category === tsInstance.DiagnosticCategory.Warning\n )\n ),\n Either.getOrElse(() => []),\n Array.map(addDiagnostic)\n )\n\n // do not transform source ccde\n return sourceFile\n }\n }\n}\n","/**\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 * @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 * 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 `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","import * as Either from \"effect/Either\"\nimport { dual } from \"effect/Function\"\nimport type { TypeLambda } from \"effect/HKT\"\nimport * as Option from \"effect/Option\"\nimport * as Gen from \"effect/Utils\"\n\nconst NanoInternalSuccessProto = {\n _tag: \"Right\"\n}\n\ninterface NanoInternalSuccess<A> {\n _tag: \"Right\"\n value: A\n}\n\nfunction makeInternalSuccess<A>(value: A): NanoInternalResult<A, never> {\n const result = Object.create(NanoInternalSuccessProto)\n result.value = value\n return result\n}\n\nconst NanoInternalFailureProto = {\n _tag: \"Left\"\n}\n\ninterface NanoInternalFailure<E> {\n _tag: \"Left\"\n value: E\n}\n\nfunction makeInternalFailure<E>(value: E): NanoInternalResult<never, E> {\n const result = Object.create(NanoInternalFailureProto)\n result.value = value\n return result\n}\n\nconst NanoInternalDefectProto = {\n _tag: \"Defect\"\n}\n\ninterface NanoInternalDefect {\n _tag: \"Defect\"\n value: unknown\n}\n\nfunction makeInternalDefect(value: unknown): NanoInternalResult<never, never> {\n const result = Object.create(NanoInternalDefectProto)\n result.value = value\n return result\n}\n\ntype NanoInternalResult<A, E> =\n | NanoInternalSuccess<A>\n | NanoInternalFailure<E>\n | NanoInternalDefect\n\nexport class NanoDefectException {\n readonly _tag = \"@effect/language-service/NanoDefectException\"\n constructor(\n readonly message: unknown\n ) {}\n}\n\nexport class NanoTag<R> {\n declare \"~nano.requirements\": R\n constructor(\n readonly key: string\n ) {}\n}\n\nexport const Tag = <I = never>(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\n\nexport interface NanoIterator<T extends Nano<any, any, any>> {\n next(...args: ReadonlyArray<any>): IteratorResult<Gen.YieldWrap<T>, T[\"~nano.success\"]>\n}\n\nexport interface NanoTypeLambda extends TypeLambda {\n readonly type: Nano<this[\"Target\"], this[\"Out1\"], this[\"Out2\"]>\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 interface Nano<out A = never, out E = never, out R = never> {\n readonly \"~nano.success\": A\n readonly \"~nano.error\": E\n readonly \"~nano.requirements\": R\n [Symbol.iterator](): NanoIterator<Nano<A, E, R>>\n run: (\n ctx: NanoContext<unknown>\n ) => NanoInternalResult<A, E>\n}\n\nconst Proto = {\n run: () => {},\n\n [Symbol.iterator]() {\n return new Gen.SingleShotGen(new Gen.YieldWrap(this))\n }\n}\n\nfunction make<A, E, R>(\n run: (\n ctx: NanoContext<unknown>\n ) => NanoInternalResult<A, E>\n): Nano<A, E, R> {\n const result = Object.create(Proto)\n result.run = run\n return result\n}\n\nexport const unsafeRun = <A, E>(\n fa: Nano<A, E, never>\n): Either.Either<A, E | NanoDefectException> => {\n const result = fa.run(contextEmpty)\n switch (result._tag) {\n case \"Left\":\n return Either.left(result.value)\n case \"Defect\":\n return Either.left(new NanoDefectException(result.value))\n case \"Right\":\n return Either.right(result.value)\n }\n}\n\nexport const run = <A, E>(fa: Nano<A, E, never>): Either.Either<A, E | NanoDefectException> => {\n try {\n return unsafeRun(fa)\n } catch (e) {\n return Either.left(new NanoDefectException(e))\n }\n}\n\nexport const succeed = <A>(value: A) => make<A, never, never>(() => makeInternalSuccess(value))\nexport const fail = <E>(value: E) => make<never, E, never>(() => makeInternalFailure(value))\nexport const sync = <A>(value: () => A) => make<A, never, never>(() => makeInternalSuccess(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 make<B, E | E2, R | R2>((ctx) => {\n const result = fa.run(ctx)\n if (result._tag !== \"Right\") return result\n return f(result.value).run(ctx)\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 make<B, E, R>((ctx) => {\n const result = fa.run(ctx)\n if (result._tag !== \"Right\") return result\n return makeInternalSuccess(f(result.value))\n }))\n\nexport const orElse = <E, B, E2, R2>(\n f: (e: E) => Nano<B, E2, R2>\n) =>\n<A, R>(fa: Nano<A, E, R>) =>\n make<A | B, E2, R | R2>((ctx) => {\n const result = fa.run(ctx)\n if (result._tag === \"Left\") return f(result.value).run(ctx)\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 arr.slice(1).reduce((arr, fa) => orElse(() => fa)(arr), arr[0])\n\nexport const service = <I extends NanoTag<any>>(tag: I) =>\n make<I[\"~nano.requirements\"], never, I[\"~nano.requirements\"]>((ctx) =>\n (tag.key in ctx.value)\n ? makeInternalSuccess(ctx.value[tag.key])\n : makeInternalDefect(`Cannot find service ${tag.key}`)\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 make<A, E, Exclude<R, I[\"~nano.requirements\"]>>((ctx) => {\n return fa.run({\n ...ctx,\n value: {\n ...ctx.value,\n [tag.key]: value\n }\n })\n })\n\nexport const gen = <Eff extends Gen.YieldWrap<Nano<any, any, any>>, AEff>(\n ...args: [body: () => Generator<Eff, AEff, never>]\n) =>\n make<\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: NanoInternalResult<any, any> = current.run(ctx)\n if (result._tag !== \"Right\") {\n return result\n }\n state = iterator.next(result.value as never)\n }\n return makeInternalSuccess(state.value)\n })\n\nexport const fn =\n (_: string) =>\n <Eff extends Gen.YieldWrap<Nano<any, any, any>>, AEff, Args extends Array<any>>(\n body: (...args: Args) => Generator<Eff, AEff, never>\n ) =>\n (...args: Args) => (\n make<\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 = body(...args)\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: NanoInternalResult<any, any> = current.run(ctx)\n if (result._tag !== \"Right\") {\n return result\n }\n state = iterator.next(result.value as never)\n }\n return makeInternalSuccess(state.value)\n })\n )\n\nexport const option = <A, E, R>(fa: Nano<A, E, R>) =>\n make<Option.Option<A>, never, R>((ctx) => {\n const result = fa.run(ctx)\n switch (result._tag) {\n case \"Right\":\n return makeInternalSuccess(Option.some(result.value))\n case \"Left\":\n return makeInternalSuccess(Option.none())\n case \"Defect\":\n return result\n }\n })\n\nexport const all = <A extends Array<Nano<any, any, any>>>(\n ...args: A\n): Nano<\n Array<A[number][\"~nano.success\"]>,\n A[number][\"~nano.error\"],\n A[number][\"~nano.requirements\"]\n> =>\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\nconst timings: Record<string, number> = {}\nconst timingsCount: Record<string, number> = {}\nexport const timed = (timingName: string) => <A, E, R>(fa: Nano<A, E, R>) =>\n make<A, E, R>((ctx) => {\n const start = performance.now()\n const result = fa.run(ctx)\n const end = performance.now()\n const duration = end - start\n timings[timingName] = (timings[timingName] || 0) + duration\n timingsCount[timingName] = (timingsCount[timingName] || 0) + 1\n return result\n })\n\nexport const getTimings = () => {\n const result: Array<[name: string, avg: number, hits: number, total: number]> = []\n for (const key in timings) {\n result.push([key, timings[key] / (timingsCount[key] || 1), timingsCount[key], timings[key]])\n }\n result.sort((a, b) => b[3] - a[3])\n const lines: Array<string> = []\n for (const [name, avg, hits, total] of result) {\n lines.push(\n `${name.padEnd(75)} tot ${total.toFixed(2).padStart(10)}ms avg ${\n avg.toFixed(2).padStart(10)\n }ms ${hits.toString().padStart(10)} hits`\n )\n }\n return lines\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 {}\nexport const TypeScriptApi = Nano.Tag<TypeScriptApi>(\"TypeScriptApi\")\n\ntype _TypeScriptProgram = ts.Program\nexport interface TypeScriptProgram extends _TypeScriptProgram {}\nexport const TypeScriptProgram = Nano.Tag<TypeScriptProgram>(\"TypeScriptProgram\")\n\nexport const ChangeTracker = Nano.Tag<ts.textChanges.ChangeTracker>(\"ChangeTracker\")\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport type * as TypeCheckerApi from \"../core/TypeCheckerApi.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as Nano from \"./Nano.js\"\n\nexport class RefactorNotApplicableError {\n readonly _tag = \"@effect/language-service/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\n | TypeCheckerApi.TypeCheckerApi\n | PluginOptions\n | TypeCheckerApi.TypeCheckerApiCache\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): 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\n | PluginOptions\n | TypeScriptApi.TypeScriptApi\n | TypeCheckerApi.TypeCheckerApiCache\n | TypeScriptApi.TypeScriptProgram\n >\n}\n\nexport interface ApplicableDiagnosticDefinition {\n node: ts.Node\n category: ts.DiagnosticCategory\n messageText: string\n fixes: Array<ApplicableDiagnosticDefinitionFix>\n}\n\nexport interface ApplicableDiagnosticDefinitionFix {\n fixName: string\n description: string\n apply: Nano.Nano<void, never, ts.textChanges.ChangeTracker>\n}\n\nexport interface ApplicableDiagnosticDefinitionFixWithPositionAndCode\n extends ApplicableDiagnosticDefinitionFix\n{\n code: number\n start: number\n end: number\n}\n\nexport function createDiagnostic(definition: DiagnosticDefinition): DiagnosticDefinition {\n return definition\n}\n\nexport interface PluginOptions {\n diagnostics: boolean\n quickinfo: boolean\n completions: boolean\n multipleEffectCheck: boolean\n}\n\nexport function parsePluginOptions(config: any) {\n return {\n diagnostics: config && \"diagnostics\" in config && typeof config.diagnostics === \"boolean\"\n ? config.diagnostics\n : true,\n quickinfo: config && \"quickinfo\" in config && typeof config.quickinfo === \"boolean\"\n ? config.quickinfo\n : true,\n completions: config && \"completions\" in config && typeof config.completions === \"boolean\"\n ? config.completions\n : true,\n multipleEffectCheck: config && \"multipleEffectCheck\" in config &&\n typeof config.multipleEffectCheck === \"boolean\"\n ? config.multipleEffectCheck\n : true\n }\n}\n\nexport interface CompletionDefinition {\n name: string\n apply: (\n sourceFile: ts.SourceFile,\n position: number,\n options: ts.GetCompletionsAtPositionOptions | undefined,\n formatCodeSettings: ts.FormatCodeSettings | undefined\n ) => Nano.Nano<\n Array<CompletionEntryDefinition>,\n never,\n | TypeCheckerApi.TypeCheckerApi\n | PluginOptions\n | TypeScriptApi.TypeScriptApi\n | TypeCheckerApi.TypeCheckerApiCache\n | TypeScriptApi.TypeScriptProgram\n >\n}\n\nexport interface CompletionEntryDefinition {\n name: string\n kind: ts.ScriptElementKind\n insertText: string\n isSnippet: true\n replacementSpan: ts.TextSpan\n}\n\nexport function createCompletion(definition: CompletionDefinition): CompletionDefinition {\n return definition\n}\n\nexport const PluginOptions = Nano.Tag<PluginOptions>(\"PluginOptions\")\n\nexport class SourceFileNotFoundError {\n readonly _tag = \"@effect/language-service/SourceFileNotFoundError\"\n constructor(\n readonly fileName: string\n ) {}\n}\n\nexport const getSemanticDiagnosticsWithCodeFixes = Nano.fn(\n \"LSP.getSemanticDiagnosticsWithCodeFixes\"\n)(function*(\n rules: Array<DiagnosticDefinition>,\n sourceFile: ts.SourceFile\n) {\n const effectDiagnostics: Array<ts.Diagnostic> = []\n const effectCodeFixes: Array<ApplicableDiagnosticDefinitionFixWithPositionAndCode> = []\n const executor = yield* createDiagnosticExecutor(sourceFile)\n for (const rule of rules) {\n const result = yield* (\n Nano.option(executor.execute(rule))\n )\n if (Option.isSome(result)) {\n effectDiagnostics.push(\n ...pipe(\n result.value,\n ReadonlyArray.map((_) => ({\n file: sourceFile,\n start: _.node.getStart(sourceFile),\n length: _.node.getEnd() - _.node.getStart(sourceFile),\n messageText: _.messageText,\n category: _.category,\n code: rule.code,\n source: \"effect\"\n }))\n )\n )\n effectCodeFixes.push(\n ...pipe(\n result.value,\n ReadonlyArray.map((_) =>\n ReadonlyArray.map(\n _.fixes,\n (fix) => ({\n ...fix,\n code: rule.code,\n start: _.node.getStart(sourceFile),\n end: _.node.getEnd()\n })\n )\n ),\n ReadonlyArray.flatten\n )\n )\n }\n }\n\n return ({\n diagnostics: effectDiagnostics,\n codeFixes: effectCodeFixes\n })\n})\n\nexport const getApplicableRefactors = Nano.fn(\"LSP.getApplicableRefactors\")(function*(\n refactors: Array<RefactorDefinition>,\n sourceFile: ts.SourceFile,\n positionOrRange: number | ts.TextRange\n) {\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\nexport const getEditsForRefactor = Nano.fn(\"LSP.getEditsForRefactor\")(function*(\n refactors: Array<RefactorDefinition>,\n sourceFile: ts.SourceFile,\n positionOrRange: number | ts.TextRange,\n refactorName: string\n) {\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\nexport const getCompletionsAtPosition = Nano.fn(\"LSP.getCompletionsAtPosition\")(function*(\n completions: Array<CompletionDefinition>,\n sourceFile: ts.SourceFile,\n position: number,\n options: ts.GetCompletionsAtPositionOptions | undefined,\n formatCodeSettings: ts.FormatCodeSettings | undefined\n) {\n const effectCompletions: Array<ts.CompletionEntry> = []\n for (const completion of completions) {\n const result = yield* completion.apply(sourceFile, position, options, formatCodeSettings)\n effectCompletions.push(\n ...result.map((_) => ({ sortText: \"11\", ..._ }) satisfies ts.CompletionEntry)\n )\n }\n return effectCompletions\n})\n\nconst createDiagnosticExecutor = Nano.fn(\"LSP.createCommentDirectivesProcessor\")(\n function*(sourceFile: ts.SourceFile) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const ruleOverrides: Record<\n string,\n Array<{ start: number; end: number; level: string }>\n > = {}\n const skippedRules: Array<string> = []\n\n const regex =\n /@effect-diagnostics((?:\\s[a-zA-Z0-9/]+:(?:off|warning|error|message|suggestion|skip-file))+)?/gm\n let match: RegExpExecArray | null\n while ((match = regex.exec(sourceFile.text)) !== null) {\n const rulesCaptureGroup = match[1]\n\n if (rulesCaptureGroup) {\n const trimmedRuleString = rulesCaptureGroup.trim()\n if (trimmedRuleString) {\n const individualRules = trimmedRuleString.split(/\\s+/)\n for (const rulePair of individualRules) {\n const [ruleName, ruleLevel] = rulePair.toLowerCase().split(\":\")\n if (ruleName && ruleLevel) {\n if (ruleLevel === \"skip-file\") skippedRules.push(ruleName)\n ruleOverrides[ruleName] = ruleOverrides[ruleName] || []\n const newLength = ruleOverrides[ruleName].push({\n start: match.index,\n end: Number.MAX_SAFE_INTEGER,\n level: ruleLevel\n })\n if (newLength > 1) ruleOverrides[ruleName][newLength - 2].end = match.index\n }\n }\n }\n }\n }\n\n const levelToDiagnosticCategory: Record<string, ts.DiagnosticCategory> = {\n error: ts.DiagnosticCategory.Error,\n warning: ts.DiagnosticCategory.Warning,\n message: ts.DiagnosticCategory.Message,\n suggestion: ts.DiagnosticCategory.Suggestion\n }\n\n const execute = Nano.fn(\"LSP.ruleExecutor\")(function*(\n rule: DiagnosticDefinition\n ) {\n const ruleNameLowered = rule.name.toLowerCase()\n // if file is skipped entirely, do not process the rule\n if (skippedRules.indexOf(ruleNameLowered) > -1) return []\n // run the executor\n let modifiedDiagnostics = yield* rule.apply(sourceFile)\n // apply overrides\n for (const override of (ruleOverrides[ruleNameLowered] || [])) {\n if (override.level === \"off\") {\n // remove from output those in range\n modifiedDiagnostics = modifiedDiagnostics.filter((_) =>\n !(_.node.getStart(sourceFile) >= override.start && _.node.getEnd() <= override.end)\n )\n } else {\n // change severity\n for (\n const message of modifiedDiagnostics.filter((_) =>\n _.node.getStart(sourceFile) >= override.start && _.node.getEnd() <= override.end\n )\n ) {\n message.category = override.level in levelToDiagnosticCategory\n ? levelToDiagnosticCategory[override.level]\n : message.category\n }\n }\n }\n\n // append a rule fix to disable this check for the entire file\n const fixByDisableEntireFile: ApplicableDiagnosticDefinitionFix = {\n fixName: rule.name + \"_skipFile\",\n description: \"Disable \" + rule.name + \" for this file\",\n apply: Nano.flatMap(\n Nano.service(TypeScriptApi.ChangeTracker),\n (changeTracker) =>\n Nano.sync(() =>\n changeTracker.insertText(\n sourceFile,\n 0,\n `/** @effect-diagnostics ${rule.name}:skip-file */` + \"\\n\"\n )\n )\n )\n }\n const rulesWithDisableFix = modifiedDiagnostics.map((diagnostic) => ({\n ...diagnostic,\n fixes: diagnostic.fixes.concat([fixByDisableEntireFile])\n }))\n\n return rulesWithDisableFix\n })\n\n return { execute }\n }\n)\n","import * 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 type TypeCheckerApiCache = {\n expectedAndRealType: WeakMap<ts.SourceFile, Array<ExpectedAndRealType>>\n}\nexport const TypeCheckerApiCache = Nano.Tag<TypeCheckerApiCache>(\"TypeCheckerApiCache\")\n\nexport function makeTypeCheckerApiCache(): TypeCheckerApiCache {\n return {\n expectedAndRealType: new WeakMap()\n }\n}\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 const getMissingTypeEntriesInTargetType = Nano.fn(\n \"TypeCheckerApi.getMissingTypeEntriesInTargetType\"\n)(\n function*(realType: ts.Type, expectedType: ts.Type) {\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 readonly _tag = \"@effect/language-service/CannotFindAncestorConvertibleDeclarationError\"\n constructor(\n readonly node: ts.Node\n ) {}\n}\n\nconst getAncestorConvertibleDeclaration = Nano.fn(\n \"TypeCheckerApi.getAncestorConvertibleDeclaration\"\n)(function*(node: ts.Node) {\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\nclass CannotInferReturnTypeFromEmptyBody {\n readonly _tag = \"@effect/language-service/CannotInferReturnTypeFromEmptyBody\"\n constructor(\n readonly declaration: ConvertibleDeclaration\n ) {}\n}\n\nclass CannotInferReturnType {\n readonly _tag = \"@effect/language-service/CannotInferReturnType\"\n constructor(\n readonly declaration: ConvertibleDeclaration\n ) {}\n}\n\nexport const getInferredReturnType = Nano.fn(\"TypeCheckerApi.getInferredReturnType\")(function*(\n declaration: ConvertibleDeclaration\n) {\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\ntype ExpectedAndRealType = [\n node: ts.Node,\n expectedType: ts.Type,\n valueNode: ts.Node,\n realType: ts.Type\n]\n\nexport const expectedAndRealType = Nano.fn(\"TypeCheckerApi.expectedAndRealType\")(function*(\n sourceFile: ts.SourceFile\n) {\n const cache = yield* Nano.service(TypeCheckerApiCache)\n const resultCached = cache.expectedAndRealType.get(sourceFile)\n if (resultCached) return resultCached\n\n const typeChecker = yield* Nano.service(TypeCheckerApi)\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const result: Array<ExpectedAndRealType> = []\n\n const nodeToVisit: Array<ts.Node> = [sourceFile]\n const appendNodeToVisit = (node: ts.Node) => {\n nodeToVisit.push(node)\n return undefined\n }\n\n while (nodeToVisit.length > 0) {\n const node = nodeToVisit.shift()!\n\n if (ts.isVariableDeclaration(node) && node.initializer) {\n // const a: Effect<...> = node\n const expectedType = typeChecker.getTypeAtLocation(node.name)\n const realType = typeChecker.getTypeAtLocation(node.initializer)\n result.push([node.name, expectedType, node.initializer, realType])\n appendNodeToVisit(node.initializer)\n continue\n } else if (ts.isCallExpression(node)) {\n // fn(a)\n const resolvedSignature = typeChecker.getResolvedSignature(node)\n if (resolvedSignature) {\n resolvedSignature.getParameters().map((parameter, index) => {\n const expectedType = typeChecker.getTypeOfSymbolAtLocation(parameter, node)\n const realType = typeChecker.getTypeAtLocation(node.arguments[index])\n result.push([\n node.arguments[index] as ts.Node,\n expectedType,\n node.arguments[index],\n realType\n ])\n })\n }\n ts.forEachChild(node, appendNodeToVisit)\n continue\n } else if (\n ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node) ||\n ts.isNoSubstitutionTemplateLiteral(node)\n ) {\n // { key: node } as { key: Effect<...> }\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 result.push([node, expectedType, node, realType])\n }\n }\n }\n }\n ts.forEachChild(node, appendNodeToVisit)\n continue\n } else if (\n ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken\n ) {\n // var a: Effect<...> = node\n const expectedType = typeChecker.getTypeAtLocation(node.left)\n const realType = typeChecker.getTypeAtLocation(node.right)\n result.push([node.left, expectedType, node.right, realType])\n appendNodeToVisit(node.right)\n continue\n } else if (ts.isReturnStatement(node) && node.expression) {\n // function(): Effect<...> { return a }\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)) {\n result.push([node, expectedType.value, node, realType])\n }\n }\n ts.forEachChild(node, appendNodeToVisit)\n continue\n } else if (\n ts.isArrowFunction(node) && (node.typeParameters || []).length === 0 &&\n ts.isExpression(node.body)\n ) {\n // (): Effect<...> => node\n const body = node.body\n const expectedType = typeChecker.getContextualType(body)\n const realType = typeChecker.getTypeAtLocation(body)\n if (expectedType) {\n result.push([body, expectedType, body, realType])\n }\n ts.forEachChild(body, appendNodeToVisit)\n continue\n } else if (\n ts.isArrowFunction(node) && (node.typeParameters || []).length > 0 &&\n ts.isExpression(node.body)\n ) {\n // <A>(): Effect<...> => node\n const body = node.body\n const expectedType = yield* Nano.option(getInferredReturnType(node))\n const realType = typeChecker.getTypeAtLocation(body)\n if (Option.isSome(expectedType)) {\n result.push([body, expectedType.value, body, realType])\n }\n ts.forEachChild(body, appendNodeToVisit)\n continue\n } else if (ts.isSatisfiesExpression(node)) {\n // node as Effect<....>\n const expectedType = typeChecker.getTypeAtLocation(node.type)\n const realType = typeChecker.getTypeAtLocation(node.expression)\n result.push([node.expression as ts.Node, expectedType, node.expression, realType])\n appendNodeToVisit(node.expression)\n continue\n }\n\n // no previous case has been hit, continue with childs\n ts.forEachChild(node, appendNodeToVisit)\n }\n cache.expectedAndRealType.set(sourceFile, result)\n return result\n})\n","import * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeCheckerApi from \"../core/TypeCheckerApi.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport class TypeParserIssue {\n readonly _tag = \"@effect/language-service/TypeParserIssue\"\n constructor(\n readonly type: ts.Type | undefined,\n readonly node: ts.Node | undefined,\n readonly message: string\n ) {\n }\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, node, message))\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 invariantTypeArgument(type: ts.Type): Nano.Nano<ts.Type, TypeParserIssue> {\n const signatures = type.getCallSignatures()\n // Invariant<A> has only 1 type signature\n if (signatures.length !== 1) {\n return typeParserIssue(\"Invariant type has no call signature\", type)\n }\n // get the return type\n return Nano.succeed(signatures[0].getReturnType())\n}\n\nexport const pipeableType = Nano.fn(\"TypeParser.pipeableType\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n) {\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\nexport const varianceStructCovariantType = Nano.fn(\"TypeParser.varianceStructCovariantType\")(\n function*<A extends string>(\n type: ts.Type,\n atLocation: ts.Node,\n propertyName: A\n ) {\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)\nexport const varianceStructInvariantType = Nano.fn(\"TypeParser.varianceStructInvariantType\")(\n function*<A extends string>(\n type: ts.Type,\n atLocation: ts.Node,\n propertyName: A\n ) {\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* invariantTypeArgument(propertyType)\n }\n)\n\nexport const effectVarianceStruct = Nano.fn(\"TypeParser.effectVarianceStruct\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n) {\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\nexport const effectType = Nano.fn(\"TypeParser.effectType\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n // should be pipeable\n yield* pipeableType(type, atLocation)\n // get the properties to check (exclude non-property and optional properties)\n const propertiesSymbols = typeChecker.getPropertiesOfType(type).filter((_) =>\n _.flags & ts.SymbolFlags.Property && !(_.flags & ts.SymbolFlags.Optional)\n )\n // try to put typeid first (heuristic to optimize hot path)\n propertiesSymbols.sort((a, b) => b.name.indexOf(\"EffectTypeId\") - a.name.indexOf(\"EffectTypeId\"))\n // has a property symbol which is an effect variance struct\n for (const propertySymbol of propertiesSymbols) {\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\nexport const fiberType = Nano.fn(\"TypeParser.fiberType\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n) {\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\nexport const effectSubtype = Nano.fn(\"TypeParser.effectSubtype\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n) {\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\nexport const importedEffectModule = Nano.fn(\"TypeParser.importedEffectModule\")(function*(\n node: ts.Node\n) {\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\nexport const effectGen = Nano.fn(\"TypeParser.effectGen\")(function*(node: ts.Node) {\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\nexport const effectFnUntracedGen = Nano.fn(\"TypeParser.effectFnUntracedGen\")(\n function*(node: ts.Node) {\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 const effectFnGen = Nano.fn(\"TypeParser.effectFnGen\")(function*(node: ts.Node) {\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\nexport const returnYieldEffectBlock = Nano.fn(\"TypeParser.returnYieldEffectBlock\")(function*(\n body: ts.Node\n) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n // check if the body is a block with a single effect return statement\n if (\n ts.isBlock(body) &&\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\nexport const effectSchemaVarianceStruct = Nano.fn(\"TypeParser.effectSchemaVarianceStruct\")(\n function*(\n type: ts.Type,\n atLocation: ts.Node\n ) {\n return ({\n A: yield* varianceStructInvariantType(type, atLocation, \"_A\"),\n I: yield* varianceStructInvariantType(type, atLocation, \"_I\"),\n R: yield* varianceStructCovariantType(type, atLocation, \"_R\")\n })\n }\n)\n\nexport const effectSchemaType = Nano.fn(\"TypeParser.effectSchemaType\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n // should be pipeable\n yield* pipeableType(type, atLocation)\n // should have an 'ast' property\n const ast = typeChecker.getPropertyOfType(type, \"ast\")\n if (!ast) return yield* typeParserIssue(\"Has no 'ast' property\", type, atLocation)\n // get the properties to check (exclude non-property and optional properties)\n const propertiesSymbols = typeChecker.getPropertiesOfType(type).filter((_) =>\n _.flags & ts.SymbolFlags.Property && !(_.flags & ts.SymbolFlags.Optional)\n )\n // try to put typeid first (heuristic to optimize hot path)\n propertiesSymbols.sort((a, b) => b.name.indexOf(\"TypeId\") - a.name.indexOf(\"TypeId\"))\n // has a property symbol which is an effect variance struct\n for (const propertySymbol of propertiesSymbols) {\n const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation)\n const varianceArgs = yield* Nano.option(effectSchemaVarianceStruct(\n propertyType,\n atLocation\n ))\n if (Option.isSome(varianceArgs)) {\n return varianceArgs.value\n }\n }\n return yield* typeParserIssue(\"Type has no schema variance struct\", type, atLocation)\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 \"../core/TypeCheckerApi.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as TypeParser from \"../utils/TypeParser.js\"\n\nexport const floatingEffect = LSP.createDiagnostic({\n name: \"effect/floatingEffect\",\n code: 3,\n apply: Nano.fn(\"floatingEffect.apply\")(function*(sourceFile) {\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 fixes: []\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 \"../core/TypeCheckerApi.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as TypeParser from \"../utils/TypeParser.js\"\n\nexport const missingEffectContext = LSP.createDiagnostic({\n name: \"effect/missingEffectContext\",\n code: 1,\n apply: Nano.fn(\"missingEffectContext.apply\")(function*(sourceFile) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeOrder = yield* TypeCheckerApi.deterministicTypeOrder\n\n const checkForMissingContextTypes = Nano.fn(\n \"missingEffectContext.apply.checkForMissingContextTypes\"\n )(function*(\n node: ts.Node,\n expectedType: ts.Type,\n valueNode: ts.Node,\n realType: ts.Type\n ) {\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 const effectDiagnostics: Array<LSP.ApplicableDiagnosticDefinition> = []\n const sortTypes = ReadonlyArray.sort(typeOrder)\n\n const entries = yield* TypeCheckerApi.expectedAndRealType(sourceFile)\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 fixes: []\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 \"../core/TypeCheckerApi.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as TypeParser from \"../utils/TypeParser.js\"\n\nexport const missingEffectError = LSP.createDiagnostic({\n name: \"effect/missingEffectError\",\n code: 1,\n apply: Nano.fn(\"missingEffectError.apply\")(function*(sourceFile) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeOrder = yield* TypeCheckerApi.deterministicTypeOrder\n\n const checkForMissingErrorTypes = Nano.fn(\"missingEffectError.apply.checkForMissingErrorTypes\")(\n function*(\n node: ts.Node,\n expectedType: ts.Type,\n valueNode: ts.Node,\n realType: ts.Type\n ) {\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 entries = yield* TypeCheckerApi.expectedAndRealType(sourceFile)\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 fixes: []\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 TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as TypeParser from \"../utils/TypeParser.js\"\n\nexport const missingStarInYieldEffectGen = LSP.createDiagnostic({\n name: \"effect/missingStarInYieldEffectGen\",\n code: 4,\n apply: Nano.fn(\"missingStarInYieldEffectGen.apply\")(function*(sourceFile) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const effectDiagnostics: Array<LSP.ApplicableDiagnosticDefinition> = []\n const brokenGenerators = new Set<ts.Node>()\n const brokenYields = new Set<ts.YieldExpression>()\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 // error if yield is not followed by *\n if (\n ts.isYieldExpression(node) && node.expression &&\n node.asteriskToken === undefined\n ) {\n // go up until we meet the causing generator\n const functionStarNode = ts.findAncestor(\n node,\n (_) =>\n (ts.isFunctionExpression(_) || ts.isMethodDeclaration(_)) &&\n _.asteriskToken !== undefined\n )\n\n // .gen should always be the parent ideally\n if (functionStarNode && functionStarNode.parent) {\n const effectGenNode = functionStarNode.parent\n // continue if we hit effect gen-like\n const effectGenLike = yield* pipe(\n TypeParser.effectGen(effectGenNode),\n Nano.orElse(() => TypeParser.effectFnUntracedGen(effectGenNode)),\n Nano.orElse(() => TypeParser.effectFnGen(effectGenNode)),\n Nano.option\n )\n if (Option.isSome(effectGenLike)) {\n if (effectGenLike.value.functionStar) {\n brokenGenerators.add(effectGenLike.value.functionStar)\n }\n brokenYields.add(node)\n }\n }\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 fixes: []\n })\n )\n brokenYields.forEach((node) => {\n const fix = node.expression ?\n [{\n fixName: \"missingStarInYieldEffectGen_fix\",\n description: \"Replace yield with yield*\",\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n changeTracker.replaceNode(\n sourceFile,\n node,\n ts.factory.createYieldExpression(\n ts.factory.createToken(ts.SyntaxKind.AsteriskToken),\n node.expression!\n )\n )\n })\n }] :\n []\n\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 fixes: fix\n })\n })\n\n return effectDiagnostics\n })\n})\n","import * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\ntype ResolvedEffectVersions = Record<string, { resolvedFileName: string }>\n\nconst effectVersionsCache = new Map<string, ResolvedEffectVersions>()\nconst programResolvedCacheSize = new Map<string, number>()\n\nexport const multipleEffectVersions = LSP.createDiagnostic({\n name: \"effect/multipleEffectVersions\",\n code: 6,\n apply: Nano.fn(\"multipleEffectVersions.apply\")(function*(sourceFile) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const program = yield* Nano.service(TypeScriptApi.TypeScriptProgram)\n const options = yield* Nano.service(LSP.PluginOptions)\n const effectDiagnostics: Array<LSP.ApplicableDiagnosticDefinition> = []\n\n if (!options.multipleEffectCheck) return []\n if (sourceFile.statements.length < 1) return []\n\n // whenever we detect the resolution cache size has changed, try again the check\n // this should mitigate how frequently this rule is triggered\n const effectVersions: ResolvedEffectVersions = effectVersionsCache.get(sourceFile.fileName) ||\n {}\n const newResolvedModuleSize =\n \"resolvedModules\" in program && typeof program.resolvedModules === \"object\" &&\n \"size\" in (program as any).resolvedModules ?\n (program.resolvedModules as any).size :\n 0\n const oldResolvedSize = programResolvedCacheSize.get(sourceFile.fileName) || 0\n if (newResolvedModuleSize !== oldResolvedSize) {\n if (\n \"forEachResolvedModule\" in program && typeof program.forEachResolvedModule === \"function\"\n ) {\n program.forEachResolvedModule((_: any) => {\n if (\n _ &&\n _.resolvedModule && _.resolvedModule.packageId &&\n _.resolvedModule.packageId.name === \"effect\" &&\n !(_.resolvedModule.packageId.version in effectVersions)\n ) {\n effectVersions[_.resolvedModule.packageId.version] = {\n resolvedFileName: _.resolvedModule.resolvedFileName\n }\n }\n })\n }\n effectVersionsCache.set(sourceFile.fileName, effectVersions)\n programResolvedCacheSize.set(sourceFile.fileName, newResolvedModuleSize)\n }\n\n if (Object.keys(effectVersions).length > 1) {\n const versions = Object.keys(effectVersions).map((version) => `version ${version}`)\n effectDiagnostics.push({\n node: sourceFile.statements[0],\n category: ts.DiagnosticCategory.Warning,\n messageText: `Seems like in this project there are multiple effect versions loaded (${\n versions.join(\", \")\n }). This may cause unexpected type errors and runtime behaviours. If you are ok with that, you can disable this warning by adding \"multipleEffectCheck\": false to the Effect LSP options inside your tsconfig.json`,\n fixes: []\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 TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as TypeParser from \"../utils/TypeParser.js\"\n\nexport const unnecessaryEffectGen = LSP.createDiagnostic({\n name: \"effect/unnecessaryEffectGen\",\n code: 5,\n apply: Nano.fn(\"unnecessaryEffectGen.apply\")(function*(sourceFile) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const effectDiagnostics: Array<LSP.ApplicableDiagnosticDefinition> = []\n const unnecessaryGenerators = new Map<ts.Node, 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 maybeNode = yield* pipe(\n TypeParser.effectGen(node),\n Nano.flatMap(({ body }) => TypeParser.returnYieldEffectBlock(body)),\n Nano.option\n )\n\n if (Option.isSome(maybeNode)) {\n unnecessaryGenerators.set(node, maybeNode.value)\n }\n }\n\n // emit diagnostics\n unnecessaryGenerators.forEach((yieldedResult, effectGenCall) =>\n effectDiagnostics.push({\n node: effectGenCall,\n category: ts.DiagnosticCategory.Suggestion,\n messageText: `This Effect.gen contains a single return statement.`,\n fixes: [{\n fixName: \"unnecessaryEffectGen_fix\",\n description: \"Remove the Effect.gen, and keep the body\",\n apply: Nano.gen(function*() {\n const textChanges = yield* Nano.service(\n TypeScriptApi.ChangeTracker\n )\n textChanges.replaceNode(sourceFile, effectGenCall, yieldedResult)\n })\n }]\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 { multipleEffectVersions } from \"./diagnostics/multipleEffectVersions.js\"\nimport { unnecessaryEffectGen } from \"./diagnostics/unnecessaryEffectGen.js\"\n\nexport const diagnostics = [\n multipleEffectVersions,\n missingEffectContext,\n missingEffectError,\n floatingEffect,\n missingStarInYieldEffectGen,\n unnecessaryEffectGen\n]\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC6BO,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,MAA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UAClE,CAAC;AAAA,QACH,CAAC;AAAA,MACH,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,EACT,CAAC;AACH,CAAC;;;ACrDM,IAAM,cAAc;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;;;A9BHe,SAAR,kBACL,SACA,cACA,EAAE,eAAe,IAAI,WAAW,GAChC;AACA,SAAO,CAAC,MAAgC;AACtC,WAAO,CAAC,eAA8B;AAEpC;AAAA,QACM,oCAAoC,aAAa,UAAU;AAAA,QAC1D,eAA6B,eAAe,UAAU;AAAA,QACtD,eAA6B,mBAAmB,OAAO;AAAA,QACvD,eAA8B,gBAAgB,QAAQ,eAAe,CAAC;AAAA,QACtE;AAAA,UACY;AAAA,UACA,wBAAwB;AAAA,QACzC;AAAA,QACK,eAAmB,eAAmB,mBAAmB,YAAY,CAAC;AAAA,QACtE;AAAA,QACE,IAAI,CAACC,OAAMA,GAAE,WAAW;AAAA,QACxB;AAAA,UACC;AAAA,YAAO,CAACA,OACZA,GAAE,aAAa,WAAW,mBAAmB,SAC7CA,GAAE,aAAa,WAAW,mBAAmB;AAAA,UAC/C;AAAA,QACF;AAAA,QACO,UAAU,MAAM,CAAC,CAAC;AAAA,QACnBC,KAAI,aAAa;AAAA,MACzB;AAGA,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":["isFunction","input","dual","arity","body","arguments","apply","self","RangeError","a","b","length","c","d","e","args","identity","a","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","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","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","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","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","right","left","isLeft","isRight","map","dual","self","f","isRight","right","left","getOrElse","dual","self","onLeft","isLeft","left","right","make","compare","self","that","none","some","isNone","isSome","fromIterable","collection","Array","isArray","from","isArray","Array","isEmptyArray","self","length","isEmptyReadonlyArray","sort","dual","self","O","out","Array","from","map","dual","self","f","flatMap","isEmptyReadonlyArray","out","i","length","inner","j","push","flatten","identity","filter","dual","self","predicate","as","fromIterable","out","i","length","push","make","run","left","right","flatMap","map","make","some","none","isSome","map","refactor","flatMap","symbol","isSome","isSome","isSome","isNone","isSome","flatMap","isSome","_","map"]}
1
+ {"version":3,"sources":["../src/transform.ts","../node_modules/.pnpm/effect@3.16.3/node_modules/effect/src/Function.ts","../node_modules/.pnpm/effect@3.16.3/node_modules/effect/src/internal/version.ts","../node_modules/.pnpm/effect@3.16.3/node_modules/effect/src/GlobalValue.ts","../node_modules/.pnpm/effect@3.16.3/node_modules/effect/src/Predicate.ts","../node_modules/.pnpm/effect@3.16.3/node_modules/effect/src/internal/errors.ts","../node_modules/.pnpm/effect@3.16.3/node_modules/effect/src/Utils.ts","../node_modules/.pnpm/effect@3.16.3/node_modules/effect/src/Hash.ts","../node_modules/.pnpm/effect@3.16.3/node_modules/effect/src/Equal.ts","../node_modules/.pnpm/effect@3.16.3/node_modules/effect/src/Inspectable.ts","../node_modules/.pnpm/effect@3.16.3/node_modules/effect/src/Pipeable.ts","../node_modules/.pnpm/effect@3.16.3/node_modules/effect/src/internal/opCodes/effect.ts","../node_modules/.pnpm/effect@3.16.3/node_modules/effect/src/internal/effectable.ts","../node_modules/.pnpm/effect@3.16.3/node_modules/effect/src/internal/option.ts","../node_modules/.pnpm/effect@3.16.3/node_modules/effect/src/internal/either.ts","../node_modules/.pnpm/effect@3.16.3/node_modules/effect/src/Either.ts","../node_modules/.pnpm/effect@3.16.3/node_modules/effect/src/Order.ts","../node_modules/.pnpm/effect@3.16.3/node_modules/effect/src/Option.ts","../node_modules/.pnpm/effect@3.16.3/node_modules/effect/src/Array.ts","../src/core/Nano.ts","../src/core/LanguageServicePluginOptions.ts","../src/core/TypeScriptApi.ts","../src/core/LSP.ts","../src/core/TypeCheckerApi.ts","../src/diagnostics/duplicatePackage.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"],"sourcesContent":["import * as Array from \"effect/Array\"\nimport * as Either from \"effect/Either\"\nimport { pipe } from \"effect/Function\"\nimport type { PluginConfig, TransformerExtras } from \"ts-patch\"\nimport type * as ts from \"typescript\"\nimport * as LanguageServicePluginOptions from \"./core/LanguageServicePluginOptions\"\nimport * as LSP from \"./core/LSP\"\nimport * as Nano from \"./core/Nano\"\nimport * as TypeCheckerApi from \"./core/TypeCheckerApi\"\nimport * as TypeScriptApi from \"./core/TypeScriptApi\"\nimport { diagnostics } from \"./diagnostics\"\n\nexport default function(\n program: ts.Program,\n pluginConfig: PluginConfig,\n { addDiagnostic, ts: tsInstance }: TransformerExtras\n) {\n return (_: ts.TransformationContext) => {\n return (sourceFile: ts.SourceFile) => {\n // run the diagnostics and pipe them into addDiagnostic\n pipe(\n LSP.getSemanticDiagnosticsWithCodeFixes(diagnostics, sourceFile),\n Nano.provideService(TypeScriptApi.TypeScriptApi, tsInstance),\n Nano.provideService(TypeScriptApi.TypeScriptProgram, program),\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, program.getTypeChecker()),\n Nano.provideService(\n TypeCheckerApi.TypeCheckerApiCache,\n TypeCheckerApi.makeTypeCheckerApiCache()\n ),\n Nano.provideService(\n LanguageServicePluginOptions.LanguageServicePluginOptions,\n LanguageServicePluginOptions.parse(pluginConfig)\n ),\n Nano.run,\n Either.map((_) => _.diagnostics),\n Either.map(\n Array.filter((_) =>\n _.category === tsInstance.DiagnosticCategory.Error ||\n _.category === tsInstance.DiagnosticCategory.Warning\n )\n ),\n Either.getOrElse(() => []),\n Array.map(addDiagnostic)\n )\n\n // do not transform source ccde\n return sourceFile\n }\n }\n}\n","/**\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * You can pass either the arity of the uncurried function or a predicate\n * which determines if the function is being used in a data-first or\n * data-last style.\n *\n * **Example** (Using arity to determine data-first or data-last style)\n *\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * const sum = dual<\n * (that: number) => (self: number) => number,\n * (self: number, that: number) => number\n * >(2, (self, that) => self + that)\n *\n * console.log(sum(2, 3)) // 5\n * console.log(pipe(2, sum(3))) // 5\n * ```\n *\n * **Example** (Using call signatures to define the overloads)\n *\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\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 * console.log(sum(2, 3)) // 5\n * console.log(pipe(2, sum(3))) // 5\n * ```\n *\n * **Example** (Using a predicate to determine data-first or data-last style)\n *\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * const sum = dual<\n * (that: number) => (self: number) => number,\n * (self: number, that: number) => number\n * >(\n * (args) => args.length === 2,\n * (self, that) => self + that\n * )\n *\n * console.log(sum(2, 3)) // 5\n * console.log(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 * You can pass either the arity of the uncurried function or a predicate\n * which determines if the function is being used in a data-first or\n * data-last style.\n *\n * **Example** (Using arity to determine data-first or data-last style)\n *\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * const sum = dual<\n * (that: number) => (self: number) => number,\n * (self: number, that: number) => number\n * >(2, (self, that) => self + that)\n *\n * console.log(sum(2, 3)) // 5\n * console.log(pipe(2, sum(3))) // 5\n * ```\n *\n * **Example** (Using call signatures to define the overloads)\n *\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\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 * console.log(sum(2, 3)) // 5\n * console.log(pipe(2, sum(3))) // 5\n * ```\n *\n * **Example** (Using a predicate to determine data-first or data-last style)\n *\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * const sum = dual<\n * (that: number) => (self: number) => number,\n * (self: number, that: number) => number\n * >(\n * (args) => args.length === 2,\n * (self, that) => self + that\n * )\n *\n * console.log(sum(2, 3)) // 5\n * console.log(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>(arity: Parameters<DataFirst>[\"length\"], body: DataFirst): 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 * You can pass either the arity of the uncurried function or a predicate\n * which determines if the function is being used in a data-first or\n * data-last style.\n *\n * **Example** (Using arity to determine data-first or data-last style)\n *\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * const sum = dual<\n * (that: number) => (self: number) => number,\n * (self: number, that: number) => number\n * >(2, (self, that) => self + that)\n *\n * console.log(sum(2, 3)) // 5\n * console.log(pipe(2, sum(3))) // 5\n * ```\n *\n * **Example** (Using call signatures to define the overloads)\n *\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\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 * console.log(sum(2, 3)) // 5\n * console.log(pipe(2, sum(3))) // 5\n * ```\n *\n * **Example** (Using a predicate to determine data-first or data-last style)\n *\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * const sum = dual<\n * (that: number) => (self: number) => number,\n * (self: number, that: number) => number\n * >(\n * (args) => args.length === 2,\n * (self, that) => self + that\n * )\n *\n * console.log(sum(2, 3)) // 5\n * console.log(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>(isDataFirst: (args: IArguments) => boolean, body: DataFirst): 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 given values.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 extends ReadonlyArray<unknown>>(...a: A) => <B>(self: (...a: A) => B): B => self(...a)\n\n/**\n * A lazy argument.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * as assert from \"node:assert\"\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 * as assert from \"node:assert\"\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 * as assert from \"node:assert\"\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 * as assert from \"node:assert\"\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 * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 version of this function: instead of `n` arguments, it accepts a single tuple argument.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * as assert from \"node:assert\"\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 * **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 skip-type-checking\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 * ```\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 * **When to Use**\n *\n * This is useful in combination with data-last functions as a simulation of\n * methods:\n *\n * ```ts skip-type-checking\n * as.map(f).filter(g)\n * ```\n *\n * becomes:\n *\n * ```ts skip-type-checking\n * import { pipe, Array } from \"effect\"\n *\n * pipe(as, Array.map(f), Array.filter(g))\n * ```\n *\n * **Example** (Chaining Arithmetic Operations)\n *\n * ```ts\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 * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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.16.3\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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// TODO: make public\n/** @internal */\nexport const isPropertyKey = (u: unknown): u is PropertyKey => isString(u) || isNumber(u) || isSymbol(u)\n\n/**\n * Tests if a value is a `function`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @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 * @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 * @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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * ```ts skip-type-checking\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 * ```ts skip-type-checking\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>>(...elements: T): [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 * ```ts skip-type-checking\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 * ```ts skip-type-checking\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>>(fields: R): [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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * as assert from \"node:assert\"\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 * as assert from \"node:assert\"\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 * as assert from \"node:assert\"\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 * - `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 * - `seedHi` - The high 32 bits of the seed.\n * - `seedLo` - The low 32 bits of the seed.\n * - `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 * - `seedHi` - The high 32 bits of the seed.\n * - `seedLo` - The low 32 bits of the seed.\n * - `incHi` - The high 32 bits of the incrementer.\n * - `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 standard = {\n effect_internal_function: <A>(body: () => A) => {\n return body()\n }\n}\n\nconst forced = {\n effect_internal_function: <A>(body: () => A) => {\n try {\n return body()\n } finally {\n //\n }\n }\n}\n\nconst isNotOptimizedAway =\n standard.effect_internal_function(() => new Error().stack)?.includes(\"effect_internal_function\") === true\n\n/**\n * @since 3.2.2\n * @status experimental\n * @category tracing\n */\nexport const internalCall = isNotOptimizedAway ? standard.effect_internal_function : forced.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 (self instanceof URL) {\n return hash(self.href)\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 } else if (self instanceof URL && that instanceof URL) {\n return self.href === that.href\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\nimport type { Ctor } from \"./Types.js\"\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\n/**\n * @since 3.15.0\n * @category Models\n */\nexport interface PipeableConstructor {\n new(...args: Array<any>): Pipeable\n}\n\n/**\n * @since 3.15.0\n * @category Prototypes\n */\nexport const Prototype: Pipeable = {\n pipe() {\n return pipeArguments(this, arguments)\n }\n}\n\nconst Base: PipeableConstructor = (function() {\n function PipeableBase() {}\n PipeableBase.prototype = Prototype\n return PipeableBase as any\n})()\n\n/**\n * @since 3.15.0\n * @category Constructors\n */\nexport const Class: {\n /**\n * @since 3.15.0\n * @category Constructors\n */\n (): PipeableConstructor\n /**\n * @since 3.15.0\n * @category Constructors\n */\n <TBase extends Ctor>(klass: TBase): TBase & PipeableConstructor\n} = (klass?: Ctor) =>\n klass ?\n class extends klass {\n pipe() {\n return pipeArguments(this, arguments)\n }\n }\n : Base\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 * 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 * as option_ from \"./internal/option.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// TODO(4.0): flip the order of the type parameters\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// TODO(4.0): flip the order of the type parameters\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\nconst void_: Either<void> = right(void 0)\nexport {\n /**\n * @category constructors\n * @since 3.13.0\n */\n void_ as void\n}\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 * as assert from \"node:assert\"\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 * as assert from \"node:assert\"\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 * as assert from \"node:assert\"\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)\n)\n\n/**\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * as assert from \"node:assert\"\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 * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * as assert from \"node:assert\"\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 * as assert from \"node:assert\"\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 * @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 * @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 * @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 * @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 * @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 * @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 * as assert from \"node:assert\"\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 * as assert from \"node:assert\"\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 * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n * const isPositiveEither = Either.liftPredicate(isPositive, n => `${n} is not positive`)\n *\n * assert.deepStrictEqual(\n * isPositiveEither(1),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * isPositiveEither(0),\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n * const isPositiveEither = Either.liftPredicate(isPositive, n => `${n} is not positive`)\n *\n * assert.deepStrictEqual(\n * isPositiveEither(1),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * isPositiveEither(0),\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<A, B>, orLeftWith: (a: 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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n * const isPositiveEither = Either.liftPredicate(isPositive, n => `${n} is not positive`)\n *\n * assert.deepStrictEqual(\n * isPositiveEither(1),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * isPositiveEither(0),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @category lifting\n * @since 3.4.0\n */\n <B extends A, E, A = B>(predicate: Predicate<A>, orLeftWith: (a: A) => E): (a: B) => 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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n * const isPositiveEither = Either.liftPredicate(isPositive, n => `${n} is not positive`)\n *\n * assert.deepStrictEqual(\n * isPositiveEither(1),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * isPositiveEither(0),\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n * const isPositiveEither = Either.liftPredicate(isPositive, n => `${n} is not positive`)\n *\n * assert.deepStrictEqual(\n * isPositiveEither(1),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * isPositiveEither(0),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @category lifting\n * @since 3.4.0\n */\n <B extends A, E, A = B>(self: B, predicate: Predicate<A>, orLeftWith: (a: A) => E): Either<B, 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 * as assert from \"node:assert\"\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 * as assert from \"node:assert\"\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 * as assert from \"node:assert\"\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>(predicate: Predicate<NoInfer<R>>, orLeftWith: (right: NoInfer<R>) => L2): <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 * as assert from \"node:assert\"\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 * as assert from \"node:assert\"\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 * as assert from \"node:assert\"\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 * as assert from \"node:assert\"\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 * as assert from \"node:assert\"\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 * as assert from \"node:assert\"\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 * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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// TODO(4.0): by default should throw `L` (i.e getOrThrowWith with the identity function)\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @throws `Error(\"getOrThrow called on a Left\")`\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 * @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 * @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 * @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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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) {\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 ? args[0] : args[1].bind(args[0])\n const iterator = f(adapter)\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 if (isLeft(current)) {\n return current\n }\n state = iterator.next(current.right as never)\n }\n return right(state.value) as any\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @see {@link bind}\n * @see {@link bindTo}\n * @see {@link let_ let}\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 2.0.0\n */\n <N extends string, A extends object, B, L2>(name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Either<B, L2>): <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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link bind}\n *\n * @category do notation\n * @since 2.0.0\n */\n let_ as let\n}\n\n/**\n * Converts an `Option` of an `Either` into an `Either` of an `Option`.\n *\n * **Details**\n *\n * This function transforms an `Option<Either<A, E>>` into an\n * `Either<Option<A>, E>`. If the `Option` is `None`, the resulting `Either`\n * will be a `Right` with a `None` value. If the `Option` is `Some`, the\n * inner `Either` will be executed, and its result wrapped in a `Some`.\n *\n * @example\n * ```ts\n * import { Effect, Either, Option } from \"effect\"\n *\n * // ┌─── Option<Either<number, never>>\n * // ▼\n * const maybe = Option.some(Either.right(42))\n *\n * // ┌─── Either<Option<number>, never, never>\n * // ▼\n * const result = Either.transposeOption(maybe)\n *\n * console.log(Effect.runSync(result))\n * // Output: { _id: 'Option', _tag: 'Some', value: 42 }\n * ```\n *\n * @since 3.14.0\n * @category Optional Wrapping & Unwrapping\n */\nexport const transposeOption = <A = never, E = never>(\n self: Option<Either<A, E>>\n): Either<Option<A>, E> => {\n return option_.isNone(self) ? right(option_.none) : map(self.value, option_.some)\n}\n\n/**\n * Applies an `Either` on an `Option` and transposes the result.\n *\n * **Details**\n *\n * If the `Option` is `None`, the resulting `Either` will immediately succeed with a `Right` value of `None`.\n * If the `Option` is `Some`, the transformation function will be applied to the inner value, and its result wrapped in a `Some`.\n *\n * @example\n * ```ts\n * import { Either, Option, pipe } from \"effect\"\n *\n * // ┌─── Either<Option<number>, never>>\n * // ▼\n * const noneResult = pipe(\n * Option.none(),\n * Either.transposeMapOption(() => Either.right(42)) // will not be executed\n * )\n * console.log(noneResult)\n * // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'None' } }\n *\n * // ┌─── Either<Option<number>, never>>\n * // ▼\n * const someRightResult = pipe(\n * Option.some(42),\n * Either.transposeMapOption((value) => Either.right(value * 2))\n * )\n * console.log(someRightResult)\n * // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'Some', value: 84 } }\n * ```\n *\n * @since 3.15.0\n * @category Optional Wrapping & Unwrapping\n */\nexport const transposeMapOption = dual<\n /**\n * Applies an `Either` on an `Option` and transposes the result.\n *\n * **Details**\n *\n * If the `Option` is `None`, the resulting `Either` will immediately succeed with a `Right` value of `None`.\n * If the `Option` is `Some`, the transformation function will be applied to the inner value, and its result wrapped in a `Some`.\n *\n * @example\n * ```ts\n * import { Either, Option, pipe } from \"effect\"\n *\n * // ┌─── Either<Option<number>, never>>\n * // ▼\n * const noneResult = pipe(\n * Option.none(),\n * Either.transposeMapOption(() => Either.right(42)) // will not be executed\n * )\n * console.log(noneResult)\n * // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'None' } }\n *\n * // ┌─── Either<Option<number>, never>>\n * // ▼\n * const someRightResult = pipe(\n * Option.some(42),\n * Either.transposeMapOption((value) => Either.right(value * 2))\n * )\n * console.log(someRightResult)\n * // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'Some', value: 84 } }\n * ```\n *\n * @since 3.15.0\n * @category Optional Wrapping & Unwrapping\n */\n <A, B, E = never>(f: (self: A) => Either<B, E>) => (self: Option<A>) => Either<Option<B>, E>,\n /**\n * Applies an `Either` on an `Option` and transposes the result.\n *\n * **Details**\n *\n * If the `Option` is `None`, the resulting `Either` will immediately succeed with a `Right` value of `None`.\n * If the `Option` is `Some`, the transformation function will be applied to the inner value, and its result wrapped in a `Some`.\n *\n * @example\n * ```ts\n * import { Either, Option, pipe } from \"effect\"\n *\n * // ┌─── Either<Option<number>, never>>\n * // ▼\n * const noneResult = pipe(\n * Option.none(),\n * Either.transposeMapOption(() => Either.right(42)) // will not be executed\n * )\n * console.log(noneResult)\n * // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'None' } }\n *\n * // ┌─── Either<Option<number>, never>>\n * // ▼\n * const someRightResult = pipe(\n * Option.some(42),\n * Either.transposeMapOption((value) => Either.right(value * 2))\n * )\n * console.log(someRightResult)\n * // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'Some', value: 84 } }\n * ```\n *\n * @since 3.15.0\n * @category Optional Wrapping & Unwrapping\n */\n <A, B, E = never>(self: Option<A>, f: (self: A) => Either<B, E>) => Either<Option<B>, E>\n>(2, (self, f) => option_.isNone(self) ? right(option_.none) : map(f(self.value), option_.some))\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 * as assert from \"node:assert\"\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 * The `Option` data type represents optional values. An `Option<A>` can either\n * be `Some<A>`, containing a value of type `A`, or `None`, representing the\n * absence of a value.\n *\n * **When to Use**\n *\n * You can use `Option` in scenarios like:\n *\n * - Using it for initial values\n * - Returning values from functions that are not defined for all possible\n * inputs (referred to as “partial functions”)\n * - Managing optional fields in data structures\n * - Handling optional function arguments\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 * Extracts the type of the value contained in an `Option`.\n *\n * **Example** (Getting the Value Type of an Option)\n *\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Declare an Option holding a string\n * declare const myOption: Option.Option<string>\n *\n * // Extract the type of the value within the Option\n * //\n * // ┌─── string\n * // ▼\n * type MyType = Option.Option.Value<typeof myOption>\n * ```\n *\n * @since 2.0.0\n * @category Type-level Utils\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 * Represents the absence of a value by creating an empty `Option`.\n *\n * `Option.none` returns an `Option<never>`, which is a subtype of `Option<A>`.\n * This means you can use it in place of any `Option<A>` regardless of the type\n * `A`.\n *\n * **Example** (Creating an Option with No Value)\n *\n * ```ts\n * import { Option } from \"effect\"\n *\n * // An Option holding no value\n * //\n * // ┌─── Option<never>\n * // ▼\n * const noValue = Option.none()\n *\n * console.log(noValue)\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @see {@link some} for the opposite operation.\n *\n * @category Constructors\n * @since 2.0.0\n */\nexport const none = <A = never>(): Option<A> => option.none\n\n/**\n * Wraps the given value into an `Option` to represent its presence.\n *\n * **Example** (Creating an Option with a Value)\n *\n * ```ts\n * import { Option } from \"effect\"\n *\n * // An Option holding the number 1\n * //\n * // ┌─── Option<number>\n * // ▼\n * const value = Option.some(1)\n *\n * console.log(value)\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n * ```\n *\n * @see {@link none} for the opposite operation.\n *\n * @category Constructors\n * @since 2.0.0\n */\nexport const some: <A>(value: A) => Option<A> = option.some\n\n/**\n * Determines whether the given value is an `Option`.\n *\n * **Details**\n *\n * This function checks if a value is an instance of `Option`. It returns `true`\n * if the value is either `Option.some` or `Option.none`, and `false` otherwise.\n * This is particularly useful when working with unknown values or when you need\n * to ensure type safety in your code.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.isOption(Option.some(1)))\n * // Output: true\n *\n * console.log(Option.isOption(Option.none()))\n * // Output: true\n *\n * console.log(Option.isOption({}))\n * // Output: 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 * Checks whether an `Option` represents the absence of a value (`None`).\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.isNone(Option.some(1)))\n * // Output: false\n *\n * console.log(Option.isNone(Option.none()))\n * // Output: true\n * ```\n *\n * @see {@link isSome} for the opposite check.\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 * Checks whether an `Option` contains a value (`Some`).\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.isSome(Option.some(1)))\n * // Output: true\n *\n * console.log(Option.isSome(Option.none()))\n * // Output: false\n * ```\n *\n * @see {@link isNone} for the opposite check.\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 * Performs pattern matching on an `Option` to handle both `Some` and `None`\n * cases.\n *\n * **Details**\n *\n * This function allows you to match against an `Option` and handle both\n * scenarios: when the `Option` is `None` (i.e., contains no value), and when\n * the `Option` is `Some` (i.e., contains a value). It executes one of the\n * provided functions based on the case:\n *\n * - If the `Option` is `None`, the `onNone` function is executed and its result\n * is returned.\n * - If the `Option` is `Some`, the `onSome` function is executed with the\n * contained value, and its result is returned.\n *\n * This function provides a concise and functional way to handle optional values\n * without resorting to `if` or manual checks, making your code more declarative\n * and readable.\n *\n * **Example** (Pattern Matching with Option)\n *\n * ```ts\n * import { Option } from \"effect\"\n *\n * const foo = Option.some(1)\n *\n * const message = Option.match(foo, {\n * onNone: () => \"Option is empty\",\n * onSome: (value) => `Option has a value: ${value}`\n * })\n *\n * console.log(message)\n * // Output: \"Option has a value: 1\"\n * ```\n *\n * @category Pattern matching\n * @since 2.0.0\n */\nexport const match: {\n /**\n * Performs pattern matching on an `Option` to handle both `Some` and `None`\n * cases.\n *\n * **Details**\n *\n * This function allows you to match against an `Option` and handle both\n * scenarios: when the `Option` is `None` (i.e., contains no value), and when\n * the `Option` is `Some` (i.e., contains a value). It executes one of the\n * provided functions based on the case:\n *\n * - If the `Option` is `None`, the `onNone` function is executed and its result\n * is returned.\n * - If the `Option` is `Some`, the `onSome` function is executed with the\n * contained value, and its result is returned.\n *\n * This function provides a concise and functional way to handle optional values\n * without resorting to `if` or manual checks, making your code more declarative\n * and readable.\n *\n * **Example** (Pattern Matching with Option)\n *\n * ```ts\n * import { Option } from \"effect\"\n *\n * const foo = Option.some(1)\n *\n * const message = Option.match(foo, {\n * onNone: () => \"Option is empty\",\n * onSome: (value) => `Option has a value: ${value}`\n * })\n *\n * console.log(message)\n * // Output: \"Option has a value: 1\"\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 * Performs pattern matching on an `Option` to handle both `Some` and `None`\n * cases.\n *\n * **Details**\n *\n * This function allows you to match against an `Option` and handle both\n * scenarios: when the `Option` is `None` (i.e., contains no value), and when\n * the `Option` is `Some` (i.e., contains a value). It executes one of the\n * provided functions based on the case:\n *\n * - If the `Option` is `None`, the `onNone` function is executed and its result\n * is returned.\n * - If the `Option` is `Some`, the `onSome` function is executed with the\n * contained value, and its result is returned.\n *\n * This function provides a concise and functional way to handle optional values\n * without resorting to `if` or manual checks, making your code more declarative\n * and readable.\n *\n * **Example** (Pattern Matching with Option)\n *\n * ```ts\n * import { Option } from \"effect\"\n *\n * const foo = Option.some(1)\n *\n * const message = Option.match(foo, {\n * onNone: () => \"Option is empty\",\n * onSome: (value) => `Option has a value: ${value}`\n * })\n *\n * console.log(message)\n * // Output: \"Option has a value: 1\"\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 * Converts an `Option`-returning function into a type guard.\n *\n * **Details**\n *\n * This function transforms a function that returns an `Option` into a type\n * guard, ensuring type safety when validating or narrowing types. The returned\n * type guard function checks whether the input satisfies the condition defined\n * in the original `Option`-returning function.\n *\n * If the original function returns `Option.some`, the type guard evaluates to\n * `true`, confirming the input is of the desired type. If the function returns\n * `Option.none`, the type guard evaluates to `false`.\n *\n * This utility is especially useful for validating types in union types,\n * filtering arrays, or ensuring safe handling of specific subtypes.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * type MyData = string | number\n *\n * const parseString = (data: MyData): Option.Option<string> =>\n * typeof data === \"string\" ? Option.some(data) : Option.none()\n *\n * // ┌─── (a: MyData) => a is string\n * // ▼\n * const isString = Option.toRefinement(parseString)\n *\n * console.log(isString(\"a\"))\n * // Output: true\n *\n * console.log(isString(1))\n * // Output: 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` into an `Option`, wrapping the first element if it\n * exists.\n *\n * **Details**\n *\n * This function takes an `Iterable` (e.g., an array, a generator, or any object\n * implementing the `Iterable` interface) and returns an `Option` based on its\n * content:\n *\n * - If the `Iterable` contains at least one element, the first element is\n * wrapped in a `Some` and returned.\n * - If the `Iterable` is empty, `None` is returned, representing the absence of\n * a value.\n *\n * This utility is useful for safely handling collections that might be empty,\n * ensuring you explicitly handle both cases where a value exists or doesn't.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.fromIterable([1, 2, 3]))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(Option.fromIterable([]))\n * // Output: { _id: 'Option', _tag: '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 an `Either` into an `Option` by discarding the error and extracting\n * the right value.\n *\n * **Details**\n *\n * This function takes an `Either` and returns an `Option` based on its value:\n *\n * - If the `Either` is a `Right`, its value is wrapped in a `Some` and\n * returned.\n * - If the `Either` is a `Left`, the error is discarded, and `None` is\n * returned.\n *\n * This is particularly useful when you only care about the success case\n * (`Right`) of an `Either` and want to handle the result using `Option`. By\n * using this function, you can convert `Either` into a simpler structure for\n * cases where error handling is not required.\n *\n * @example\n * ```ts\n * import { Either, Option } from \"effect\"\n *\n * console.log(Option.getRight(Either.right(\"ok\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'ok' }\n *\n * console.log(Option.getRight(Either.left(\"err\")))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @see {@link getLeft} for the opposite operation.\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 an `Either` into an `Option` by discarding the right value and\n * extracting the left value.\n *\n * **Details**\n *\n * This function transforms an `Either` into an `Option` as follows:\n *\n * - If the `Either` is a `Left`, its value is wrapped in a `Some` and returned.\n * - If the `Either` is a `Right`, the value is discarded, and `None` is\n * returned.\n *\n * This utility is useful when you only care about the error case (`Left`) of an\n * `Either` and want to handle it as an `Option`. By discarding the right value,\n * it simplifies error-focused workflows.\n *\n * @example\n * ```ts\n * import { Either, Option } from \"effect\"\n *\n * console.log(Option.getLeft(Either.right(\"ok\")))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(Option.getLeft(Either.left(\"err\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'err' }\n * ```\n *\n * @see {@link getRight} for the opposite operation.\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 contained in the `Option` if it is `Some`, otherwise\n * evaluates and returns the result of `onNone`.\n *\n * **Details**\n *\n * This function allows you to provide a fallback value or computation for when\n * an `Option` is `None`. If the `Option` contains a value (`Some`), that value\n * is returned. If it is empty (`None`), the `onNone` function is executed, and\n * its result is returned instead.\n *\n * This utility is helpful for safely handling `Option` values by ensuring you\n * always receive a meaningful result, whether or not the `Option` contains a\n * value. It is particularly useful for providing default values or alternative\n * logic when working with optional values.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.some(1).pipe(Option.getOrElse(() => 0)))\n * // Output: 1\n *\n * console.log(Option.none().pipe(Option.getOrElse(() => 0)))\n * // Output: 0\n * ```\n *\n * @see {@link getOrNull} for a version that returns `null` instead of executing a function.\n * @see {@link getOrUndefined} for a version that returns `undefined` instead of executing a function.\n *\n * @category Getters\n * @since 2.0.0\n */\nexport const getOrElse: {\n /**\n * Returns the value contained in the `Option` if it is `Some`, otherwise\n * evaluates and returns the result of `onNone`.\n *\n * **Details**\n *\n * This function allows you to provide a fallback value or computation for when\n * an `Option` is `None`. If the `Option` contains a value (`Some`), that value\n * is returned. If it is empty (`None`), the `onNone` function is executed, and\n * its result is returned instead.\n *\n * This utility is helpful for safely handling `Option` values by ensuring you\n * always receive a meaningful result, whether or not the `Option` contains a\n * value. It is particularly useful for providing default values or alternative\n * logic when working with optional values.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.some(1).pipe(Option.getOrElse(() => 0)))\n * // Output: 1\n *\n * console.log(Option.none().pipe(Option.getOrElse(() => 0)))\n * // Output: 0\n * ```\n *\n * @see {@link getOrNull} for a version that returns `null` instead of executing a function.\n * @see {@link getOrUndefined} for a version that returns `undefined` instead of executing a function.\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 contained in the `Option` if it is `Some`, otherwise\n * evaluates and returns the result of `onNone`.\n *\n * **Details**\n *\n * This function allows you to provide a fallback value or computation for when\n * an `Option` is `None`. If the `Option` contains a value (`Some`), that value\n * is returned. If it is empty (`None`), the `onNone` function is executed, and\n * its result is returned instead.\n *\n * This utility is helpful for safely handling `Option` values by ensuring you\n * always receive a meaningful result, whether or not the `Option` contains a\n * value. It is particularly useful for providing default values or alternative\n * logic when working with optional values.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.some(1).pipe(Option.getOrElse(() => 0)))\n * // Output: 1\n *\n * console.log(Option.none().pipe(Option.getOrElse(() => 0)))\n * // Output: 0\n * ```\n *\n * @see {@link getOrNull} for a version that returns `null` instead of executing a function.\n * @see {@link getOrUndefined} for a version that returns `undefined` instead of executing a function.\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 the current `Option` (`self`) is\n * `None`; otherwise, it returns `self`.\n *\n * **Details**\n *\n * This function provides a fallback mechanism for `Option` values. If the\n * current `Option` is `None` (i.e., it contains no value), the `that` function\n * is evaluated, and its resulting `Option` is returned. If the current `Option`\n * is `Some` (i.e., it contains a value), the original `Option` is returned\n * unchanged.\n *\n * This is particularly useful for chaining fallback values or computations,\n * allowing you to provide alternative `Option` values when the first one is\n * empty.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.none().pipe(Option.orElse(() => Option.none())))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(Option.some(\"a\").pipe(Option.orElse(() => Option.none())))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n *\n * console.log(Option.none().pipe(Option.orElse(() => Option.some(\"b\"))))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'b' }\n *\n * console.log(Option.some(\"a\").pipe(Option.orElse(() => Option.some(\"b\"))))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n * ```\n *\n * @category Error handling\n * @since 2.0.0\n */\nexport const orElse: {\n /**\n * Returns the provided `Option` `that` if the current `Option` (`self`) is\n * `None`; otherwise, it returns `self`.\n *\n * **Details**\n *\n * This function provides a fallback mechanism for `Option` values. If the\n * current `Option` is `None` (i.e., it contains no value), the `that` function\n * is evaluated, and its resulting `Option` is returned. If the current `Option`\n * is `Some` (i.e., it contains a value), the original `Option` is returned\n * unchanged.\n *\n * This is particularly useful for chaining fallback values or computations,\n * allowing you to provide alternative `Option` values when the first one is\n * empty.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.none().pipe(Option.orElse(() => Option.none())))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(Option.some(\"a\").pipe(Option.orElse(() => Option.none())))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n *\n * console.log(Option.none().pipe(Option.orElse(() => Option.some(\"b\"))))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'b' }\n *\n * console.log(Option.some(\"a\").pipe(Option.orElse(() => Option.some(\"b\"))))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\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 the current `Option` (`self`) is\n * `None`; otherwise, it returns `self`.\n *\n * **Details**\n *\n * This function provides a fallback mechanism for `Option` values. If the\n * current `Option` is `None` (i.e., it contains no value), the `that` function\n * is evaluated, and its resulting `Option` is returned. If the current `Option`\n * is `Some` (i.e., it contains a value), the original `Option` is returned\n * unchanged.\n *\n * This is particularly useful for chaining fallback values or computations,\n * allowing you to provide alternative `Option` values when the first one is\n * empty.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.none().pipe(Option.orElse(() => Option.none())))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(Option.some(\"a\").pipe(Option.orElse(() => Option.none())))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n *\n * console.log(Option.none().pipe(Option.orElse(() => Option.some(\"b\"))))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'b' }\n *\n * console.log(Option.some(\"a\").pipe(Option.orElse(() => Option.some(\"b\"))))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\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 wrapped in `Some` if the current `Option`\n * (`self`) is `None`; otherwise, returns `self`.\n *\n * **Details**\n *\n * This function provides a way to supply a default value for cases where an\n * `Option` is `None`. If the current `Option` is empty (`None`), the `onNone`\n * function is executed to compute the default value, which is then wrapped in a\n * `Some`. If the current `Option` contains a value (`Some`), it is returned as\n * is.\n *\n * This is particularly useful for handling optional values where a fallback\n * default needs to be provided explicitly in case of absence.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.none().pipe(Option.orElseSome(() => \"b\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'b' }\n *\n * console.log(Option.some(\"a\").pipe(Option.orElseSome(() => \"b\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n * ```\n *\n * @category Error handling\n * @since 2.0.0\n */\nexport const orElseSome: {\n /**\n * Returns the provided default value wrapped in `Some` if the current `Option`\n * (`self`) is `None`; otherwise, returns `self`.\n *\n * **Details**\n *\n * This function provides a way to supply a default value for cases where an\n * `Option` is `None`. If the current `Option` is empty (`None`), the `onNone`\n * function is executed to compute the default value, which is then wrapped in a\n * `Some`. If the current `Option` contains a value (`Some`), it is returned as\n * is.\n *\n * This is particularly useful for handling optional values where a fallback\n * default needs to be provided explicitly in case of absence.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.none().pipe(Option.orElseSome(() => \"b\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'b' }\n *\n * console.log(Option.some(\"a\").pipe(Option.orElseSome(() => \"b\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\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 wrapped in `Some` if the current `Option`\n * (`self`) is `None`; otherwise, returns `self`.\n *\n * **Details**\n *\n * This function provides a way to supply a default value for cases where an\n * `Option` is `None`. If the current `Option` is empty (`None`), the `onNone`\n * function is executed to compute the default value, which is then wrapped in a\n * `Some`. If the current `Option` contains a value (`Some`), it is returned as\n * is.\n *\n * This is particularly useful for handling optional values where a fallback\n * default needs to be provided explicitly in case of absence.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.none().pipe(Option.orElseSome(() => \"b\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'b' }\n *\n * console.log(Option.some(\"a\").pipe(Option.orElseSome(() => \"b\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\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 {@link orElse}, but returns an `Either` wrapped in an `Option` to\n * indicate the source of the value.\n *\n * **Details**\n *\n * This function allows you to provide a fallback `Option` in case the current\n * `Option` (`self`) is `None`. However, unlike `orElse`, it returns the value\n * wrapped in an `Either` object, providing additional information about where\n * the value came from:\n *\n * - If the value is from the fallback `Option` (`that`), it is wrapped in an\n * `Either.right`.\n * - If the value is from the original `Option` (`self`), it is wrapped in an\n * `Either.left`.\n *\n * This is especially useful when you need to differentiate between values\n * originating from the primary `Option` and those coming from the fallback,\n * while still maintaining the `Option`-style handling.\n *\n * @category Error handling\n * @since 2.0.0\n */\nexport const orElseEither: {\n /**\n * Similar to {@link orElse}, but returns an `Either` wrapped in an `Option` to\n * indicate the source of the value.\n *\n * **Details**\n *\n * This function allows you to provide a fallback `Option` in case the current\n * `Option` (`self`) is `None`. However, unlike `orElse`, it returns the value\n * wrapped in an `Either` object, providing additional information about where\n * the value came from:\n *\n * - If the value is from the fallback `Option` (`that`), it is wrapped in an\n * `Either.right`.\n * - If the value is from the original `Option` (`self`), it is wrapped in an\n * `Either.left`.\n *\n * This is especially useful when you need to differentiate between values\n * originating from the primary `Option` and those coming from the fallback,\n * while still maintaining the `Option`-style handling.\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 {@link orElse}, but returns an `Either` wrapped in an `Option` to\n * indicate the source of the value.\n *\n * **Details**\n *\n * This function allows you to provide a fallback `Option` in case the current\n * `Option` (`self`) is `None`. However, unlike `orElse`, it returns the value\n * wrapped in an `Either` object, providing additional information about where\n * the value came from:\n *\n * - If the value is from the fallback `Option` (`that`), it is wrapped in an\n * `Either.right`.\n * - If the value is from the original `Option` (`self`), it is wrapped in an\n * `Either.left`.\n *\n * This is especially useful when you need to differentiate between values\n * originating from the primary `Option` and those coming from the fallback,\n * while still maintaining the `Option`-style handling.\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 * Returns the first `Some` value found in an `Iterable` collection of\n * `Option`s, or `None` if no `Some` is found.\n *\n * **Details**\n *\n * This function iterates over a collection of `Option` values and returns the\n * first `Some` it encounters. If the collection contains only `None` values,\n * the result will also be `None`. This utility is useful for efficiently\n * finding the first valid value in a sequence of potentially empty or invalid\n * options.\n *\n * The iteration stops as soon as a `Some` is found, making this function\n * efficient for large collections.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.firstSomeOf([\n * Option.none(),\n * Option.some(1),\n * Option.some(2)\n * ]))\n * // Output: { _id: 'Option', _tag: 'Some', value: 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 * Converts a nullable value into an `Option`. Returns `None` if the value is\n * `null` or `undefined`, otherwise wraps the value in a `Some`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.fromNullable(undefined))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(Option.fromNullable(null))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(Option.fromNullable(1))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n * ```\n *\n * @category Conversions\n * @since 2.0.0\n */\nexport const fromNullable = <A>(\n nullableValue: A\n): Option<NonNullable<A>> => (nullableValue == null ? none() : some(nullableValue as NonNullable<A>))\n\n/**\n * Lifts a function that returns `null` or `undefined` into the `Option`\n * context.\n *\n * **Details**\n *\n * This function takes a function `f` that might return `null` or `undefined`\n * and transforms it into a function that returns an `Option`. The resulting\n * function will return:\n * - `Some` if the original function produces a non-null, non-undefined value.\n * - `None` if the original function produces `null` or `undefined`.\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 * console.log(parseOption(\"1\"))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(parseOption(\"not a number\"))\n * // Output: { _id: 'Option', _tag: '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 contained in the `Option` if it is `Some`; otherwise,\n * returns `null`.\n *\n * **Details**\n *\n * This function provides a way to extract the value of an `Option` while\n * falling back to `null` if the `Option` is `None`.\n *\n * It is particularly useful in scenarios where `null` is an acceptable\n * placeholder for the absence of a value, such as when interacting with APIs or\n * systems that use `null` as a default for missing values.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.getOrNull(Option.some(1)))\n * // Output: 1\n *\n * console.log(Option.getOrNull(Option.none()))\n * // Output: 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 contained in the `Option` if it is `Some`; otherwise,\n * returns `undefined`.\n *\n * **Details**\n *\n * This function provides a way to extract the value of an `Option` while\n * falling back to `undefined` if the `Option` is `None`.\n *\n * It is particularly useful in scenarios where `undefined` is an acceptable\n * placeholder for the absence of a value, such as when interacting with APIs or\n * systems that use `undefined` as a default for missing values.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.getOrUndefined(Option.some(1)))\n * // Output: 1\n *\n * console.log(Option.getOrUndefined(Option.none()))\n * // Output: 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 * Lifts a function that throws exceptions into a function that returns an\n * `Option`.\n *\n * **Details**\n *\n * This utility function takes a function `f` that might throw an exception and\n * transforms it into a safer function that returns an `Option`. If the original\n * function executes successfully, the result is wrapped in a `Some`. If an\n * exception is thrown, the result is `None`, allowing the developer to handle\n * errors in a functional, type-safe way.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const parse = Option.liftThrowable(JSON.parse)\n *\n * console.log(parse(\"1\"))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(parse(\"\"))\n * // Output: { _id: 'Option', _tag: '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 {\n return none()\n }\n}\n\n/**\n * Extracts the value of an `Option` or throws an error if the `Option` is\n * `None`, using a custom error factory.\n *\n * **Details**\n *\n * This function allows you to extract the value of an `Option` when it is\n * `Some`. If the `Option` is `None`, it throws an error generated by the\n * provided `onNone` function. This utility is particularly useful when you need\n * a fail-fast behavior for empty `Option` values and want to provide a custom\n * error message or object.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @see {@link getOrThrow} for a version that throws a default error.\n *\n * @category Conversions\n * @since 2.0.0\n */\nexport const getOrThrowWith: {\n /**\n * Extracts the value of an `Option` or throws an error if the `Option` is\n * `None`, using a custom error factory.\n *\n * **Details**\n *\n * This function allows you to extract the value of an `Option` when it is\n * `Some`. If the `Option` is `None`, it throws an error generated by the\n * provided `onNone` function. This utility is particularly useful when you need\n * a fail-fast behavior for empty `Option` values and want to provide a custom\n * error message or object.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @see {@link getOrThrow} for a version that throws a default error.\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 an error if the `Option` is\n * `None`, using a custom error factory.\n *\n * **Details**\n *\n * This function allows you to extract the value of an `Option` when it is\n * `Some`. If the `Option` is `None`, it throws an error generated by the\n * provided `onNone` function. This utility is particularly useful when you need\n * a fail-fast behavior for empty `Option` values and want to provide a custom\n * error message or object.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @see {@link getOrThrow} for a version that throws a default error.\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 a default error if the `Option`\n * is `None`.\n *\n * **Details**\n *\n * This function extracts the value from an `Option` if it is `Some`. If the\n * `Option` is `None`, it throws a default error. It is useful for fail-fast\n * scenarios where the absence of a value is treated as an exceptional case and\n * a default error is sufficient.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @see {@link getOrThrowWith} for a version that allows you to provide a custom error.\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 * Transforms the value inside a `Some` to a new value using the provided\n * function, while leaving `None` unchanged.\n *\n * **Details**\n *\n * This function applies a mapping function `f` to the value inside an `Option`\n * if it is a `Some`. If the `Option` is `None`, it remains unchanged. The\n * result is a new `Option` with the transformed value (if it was a `Some`) or\n * still `None`.\n *\n * This utility is particularly useful for chaining transformations in a\n * functional way without needing to manually handle `None` cases.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Mapping over a `Some`\n * const someValue = Option.some(2)\n *\n * console.log(Option.map(someValue, (n) => n * 2))\n * // Output: { _id: 'Option', _tag: 'Some', value: 4 }\n *\n * // Mapping over a `None`\n * const noneValue = Option.none<number>()\n *\n * console.log(Option.map(noneValue, (n) => n * 2))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Mapping\n * @since 2.0.0\n */\nexport const map: {\n /**\n * Transforms the value inside a `Some` to a new value using the provided\n * function, while leaving `None` unchanged.\n *\n * **Details**\n *\n * This function applies a mapping function `f` to the value inside an `Option`\n * if it is a `Some`. If the `Option` is `None`, it remains unchanged. The\n * result is a new `Option` with the transformed value (if it was a `Some`) or\n * still `None`.\n *\n * This utility is particularly useful for chaining transformations in a\n * functional way without needing to manually handle `None` cases.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Mapping over a `Some`\n * const someValue = Option.some(2)\n *\n * console.log(Option.map(someValue, (n) => n * 2))\n * // Output: { _id: 'Option', _tag: 'Some', value: 4 }\n *\n * // Mapping over a `None`\n * const noneValue = Option.none<number>()\n *\n * console.log(Option.map(noneValue, (n) => n * 2))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Mapping\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B): (self: Option<A>) => Option<B>\n /**\n * Transforms the value inside a `Some` to a new value using the provided\n * function, while leaving `None` unchanged.\n *\n * **Details**\n *\n * This function applies a mapping function `f` to the value inside an `Option`\n * if it is a `Some`. If the `Option` is `None`, it remains unchanged. The\n * result is a new `Option` with the transformed value (if it was a `Some`) or\n * still `None`.\n *\n * This utility is particularly useful for chaining transformations in a\n * functional way without needing to manually handle `None` cases.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Mapping over a `Some`\n * const someValue = Option.some(2)\n *\n * console.log(Option.map(someValue, (n) => n * 2))\n * // Output: { _id: 'Option', _tag: 'Some', value: 4 }\n *\n * // Mapping over a `None`\n * const noneValue = Option.none<number>()\n *\n * console.log(Option.map(noneValue, (n) => n * 2))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\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 * Replaces the value inside a `Some` with the specified constant value, leaving\n * `None` unchanged.\n *\n * **Details**\n *\n * This function transforms an `Option` by replacing the value inside a `Some`\n * with the given constant value `b`. If the `Option` is `None`, it remains\n * unchanged.\n *\n * This is useful when you want to preserve the presence of a value (`Some`) but\n * replace its content with a fixed value.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Replacing the value of a `Some`\n * const someValue = Option.some(42)\n *\n * console.log(Option.as(someValue, \"new value\"))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'new value' }\n *\n * // Replacing a `None` (no effect)\n * const noneValue = Option.none<number>()\n *\n * console.log(Option.as(noneValue, \"new value\"))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Mapping\n * @since 2.0.0\n */\nexport const as: {\n /**\n * Replaces the value inside a `Some` with the specified constant value, leaving\n * `None` unchanged.\n *\n * **Details**\n *\n * This function transforms an `Option` by replacing the value inside a `Some`\n * with the given constant value `b`. If the `Option` is `None`, it remains\n * unchanged.\n *\n * This is useful when you want to preserve the presence of a value (`Some`) but\n * replace its content with a fixed value.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Replacing the value of a `Some`\n * const someValue = Option.some(42)\n *\n * console.log(Option.as(someValue, \"new value\"))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'new value' }\n *\n * // Replacing a `None` (no effect)\n * const noneValue = Option.none<number>()\n *\n * console.log(Option.as(noneValue, \"new value\"))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Mapping\n * @since 2.0.0\n */\n <B>(b: B): <X>(self: Option<X>) => Option<B>\n /**\n * Replaces the value inside a `Some` with the specified constant value, leaving\n * `None` unchanged.\n *\n * **Details**\n *\n * This function transforms an `Option` by replacing the value inside a `Some`\n * with the given constant value `b`. If the `Option` is `None`, it remains\n * unchanged.\n *\n * This is useful when you want to preserve the presence of a value (`Some`) but\n * replace its content with a fixed value.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Replacing the value of a `Some`\n * const someValue = Option.some(42)\n *\n * console.log(Option.as(someValue, \"new value\"))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'new value' }\n *\n * // Replacing a `None` (no effect)\n * const noneValue = Option.none<number>()\n *\n * console.log(Option.as(noneValue, \"new value\"))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Mapping\n * @since 2.0.0\n */\n <X, B>(self: Option<X>, b: B): Option<B>\n} = dual(2, <X, B>(self: Option<X>, b: B): Option<B> => map(self, () => b))\n\n/**\n * Replaces the value inside a `Some` with the constant value `void`, leaving\n * `None` unchanged.\n *\n * **Details**\n *\n * This function transforms an `Option` by replacing the value inside a `Some`\n * with `void`. If the `Option` is `None`, it remains unchanged.\n *\n * This is particularly useful in scenarios where the presence or absence of a\n * value is significant, but the actual content of the value is irrelevant.\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 a `Some` and flattens the resulting\n * `Option`. If the input is `None`, it remains `None`.\n *\n * **Details**\n *\n * This function allows you to chain computations that return `Option` values.\n * If the input `Option` is `Some`, the provided function `f` is applied to the\n * contained value, and the resulting `Option` is returned. If the input is\n * `None`, the function is not applied, and the result remains `None`.\n *\n * This utility is particularly useful for sequencing operations that may fail\n * or produce optional results, enabling clean and concise workflows for\n * handling such cases.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * interface Address {\n * readonly city: string\n * readonly street: Option.Option<string>\n * }\n *\n * interface User {\n * readonly id: number\n * readonly username: string\n * readonly email: Option.Option<string>\n * readonly address: Option.Option<Address>\n * }\n *\n * const user: User = {\n * id: 1,\n * username: \"john_doe\",\n * email: Option.some(\"john.doe@example.com\"),\n * address: Option.some({\n * city: \"New York\",\n * street: Option.some(\"123 Main St\")\n * })\n * }\n *\n * // Use flatMap to extract the street value\n * const street = user.address.pipe(\n * Option.flatMap((address) => address.street)\n * )\n *\n * console.log(street)\n * // Output: { _id: 'Option', _tag: 'Some', value: '123 Main St' }\n * ```\n *\n * @category Sequencing\n * @since 2.0.0\n */\nexport const flatMap: {\n /**\n * Applies a function to the value of a `Some` and flattens the resulting\n * `Option`. If the input is `None`, it remains `None`.\n *\n * **Details**\n *\n * This function allows you to chain computations that return `Option` values.\n * If the input `Option` is `Some`, the provided function `f` is applied to the\n * contained value, and the resulting `Option` is returned. If the input is\n * `None`, the function is not applied, and the result remains `None`.\n *\n * This utility is particularly useful for sequencing operations that may fail\n * or produce optional results, enabling clean and concise workflows for\n * handling such cases.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * interface Address {\n * readonly city: string\n * readonly street: Option.Option<string>\n * }\n *\n * interface User {\n * readonly id: number\n * readonly username: string\n * readonly email: Option.Option<string>\n * readonly address: Option.Option<Address>\n * }\n *\n * const user: User = {\n * id: 1,\n * username: \"john_doe\",\n * email: Option.some(\"john.doe@example.com\"),\n * address: Option.some({\n * city: \"New York\",\n * street: Option.some(\"123 Main St\")\n * })\n * }\n *\n * // Use flatMap to extract the street value\n * const street = user.address.pipe(\n * Option.flatMap((address) => address.street)\n * )\n *\n * console.log(street)\n * // Output: { _id: 'Option', _tag: 'Some', value: '123 Main St' }\n * ```\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 a `Some` and flattens the resulting\n * `Option`. If the input is `None`, it remains `None`.\n *\n * **Details**\n *\n * This function allows you to chain computations that return `Option` values.\n * If the input `Option` is `Some`, the provided function `f` is applied to the\n * contained value, and the resulting `Option` is returned. If the input is\n * `None`, the function is not applied, and the result remains `None`.\n *\n * This utility is particularly useful for sequencing operations that may fail\n * or produce optional results, enabling clean and concise workflows for\n * handling such cases.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * interface Address {\n * readonly city: string\n * readonly street: Option.Option<string>\n * }\n *\n * interface User {\n * readonly id: number\n * readonly username: string\n * readonly email: Option.Option<string>\n * readonly address: Option.Option<Address>\n * }\n *\n * const user: User = {\n * id: 1,\n * username: \"john_doe\",\n * email: Option.some(\"john.doe@example.com\"),\n * address: Option.some({\n * city: \"New York\",\n * street: Option.some(\"123 Main St\")\n * })\n * }\n *\n * // Use flatMap to extract the street value\n * const street = user.address.pipe(\n * Option.flatMap((address) => address.street)\n * )\n *\n * console.log(street)\n * // Output: { _id: 'Option', _tag: 'Some', value: '123 Main St' }\n * ```\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 * Chains two `Option`s together. The second `Option` can either be a static\n * value or depend on the result of the first `Option`.\n *\n * **Details**\n *\n * This function enables sequencing of two `Option` computations. If the first\n * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can\n * either:\n *\n * - Be a static `Option` value.\n * - Be a function that produces an `Option`, optionally based on the value of\n * the first `Option`.\n *\n * If the first `Option` is `None`, the function skips the evaluation of the\n * second `Option` and directly returns `None`.\n *\n * @category Sequencing\n * @since 2.0.0\n */\nexport const andThen: {\n /**\n * Chains two `Option`s together. The second `Option` can either be a static\n * value or depend on the result of the first `Option`.\n *\n * **Details**\n *\n * This function enables sequencing of two `Option` computations. If the first\n * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can\n * either:\n *\n * - Be a static `Option` value.\n * - Be a function that produces an `Option`, optionally based on the value of\n * the first `Option`.\n *\n * If the first `Option` is `None`, the function skips the evaluation of the\n * second `Option` and directly returns `None`.\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 * Chains two `Option`s together. The second `Option` can either be a static\n * value or depend on the result of the first `Option`.\n *\n * **Details**\n *\n * This function enables sequencing of two `Option` computations. If the first\n * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can\n * either:\n *\n * - Be a static `Option` value.\n * - Be a function that produces an `Option`, optionally based on the value of\n * the first `Option`.\n *\n * If the first `Option` is `None`, the function skips the evaluation of the\n * second `Option` and directly returns `None`.\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <B>(f: Option<B>): <A>(self: Option<A>) => Option<B>\n /**\n * Chains two `Option`s together. The second `Option` can either be a static\n * value or depend on the result of the first `Option`.\n *\n * **Details**\n *\n * This function enables sequencing of two `Option` computations. If the first\n * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can\n * either:\n *\n * - Be a static `Option` value.\n * - Be a function that produces an `Option`, optionally based on the value of\n * the first `Option`.\n *\n * If the first `Option` is `None`, the function skips the evaluation of the\n * second `Option` and directly returns `None`.\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B): (self: Option<A>) => Option<B>\n /**\n * Chains two `Option`s together. The second `Option` can either be a static\n * value or depend on the result of the first `Option`.\n *\n * **Details**\n *\n * This function enables sequencing of two `Option` computations. If the first\n * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can\n * either:\n *\n * - Be a static `Option` value.\n * - Be a function that produces an `Option`, optionally based on the value of\n * the first `Option`.\n *\n * If the first `Option` is `None`, the function skips the evaluation of the\n * second `Option` and directly returns `None`.\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <B>(f: NotFunction<B>): <A>(self: Option<A>) => Option<B>\n /**\n * Chains two `Option`s together. The second `Option` can either be a static\n * value or depend on the result of the first `Option`.\n *\n * **Details**\n *\n * This function enables sequencing of two `Option` computations. If the first\n * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can\n * either:\n *\n * - Be a static `Option` value.\n * - Be a function that produces an `Option`, optionally based on the value of\n * the first `Option`.\n *\n * If the first `Option` is `None`, the function skips the evaluation of the\n * second `Option` and directly returns `None`.\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 * Chains two `Option`s together. The second `Option` can either be a static\n * value or depend on the result of the first `Option`.\n *\n * **Details**\n *\n * This function enables sequencing of two `Option` computations. If the first\n * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can\n * either:\n *\n * - Be a static `Option` value.\n * - Be a function that produces an `Option`, optionally based on the value of\n * the first `Option`.\n *\n * If the first `Option` is `None`, the function skips the evaluation of the\n * second `Option` and directly returns `None`.\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: Option<B>): Option<B>\n /**\n * Chains two `Option`s together. The second `Option` can either be a static\n * value or depend on the result of the first `Option`.\n *\n * **Details**\n *\n * This function enables sequencing of two `Option` computations. If the first\n * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can\n * either:\n *\n * - Be a static `Option` value.\n * - Be a function that produces an `Option`, optionally based on the value of\n * the first `Option`.\n *\n * If the first `Option` is `None`, the function skips the evaluation of the\n * second `Option` and directly returns `None`.\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => B): Option<B>\n /**\n * Chains two `Option`s together. The second `Option` can either be a static\n * value or depend on the result of the first `Option`.\n *\n * **Details**\n *\n * This function enables sequencing of two `Option` computations. If the first\n * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can\n * either:\n *\n * - Be a static `Option` value.\n * - Be a function that produces an `Option`, optionally based on the value of\n * the first `Option`.\n *\n * If the first `Option` is `None`, the function skips the evaluation of the\n * second `Option` and directly returns `None`.\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 * Combines `flatMap` and `fromNullable`, transforming the value inside a `Some`\n * using a function that may return `null` or `undefined`.\n *\n * **Details**\n *\n * This function applies a transformation function `f` to the value inside a\n * `Some`. The function `f` may return a value, `null`, or `undefined`. If `f`\n * returns a value, it is wrapped in a `Some`. If `f` returns `null` or\n * `undefined`, the result is `None`. If the input `Option` is `None`, the\n * function is not applied, and `None` is returned.\n *\n * This utility is particularly useful when working with deeply nested optional\n * values or chaining computations that may result in `null` or `undefined` at\n * some point.\n *\n * @example\n * ```ts\n * import { 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 * // Extracting a deeply nested property\n * console.log(\n * Option.some(employee1)\n * .pipe(Option.flatMapNullable((employee) => employee.company?.address?.street?.name))\n * )\n * // Output: { _id: 'Option', _tag: 'Some', value: 'high street' }\n *\n * const employee2: Employee = { company: { address: { street: {} } } }\n *\n * // Property does not exist\n * console.log(\n * Option.some(employee2)\n * .pipe(Option.flatMapNullable((employee) => employee.company?.address?.street?.name))\n * )\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Sequencing\n * @since 2.0.0\n */\nexport const flatMapNullable: {\n /**\n * Combines `flatMap` and `fromNullable`, transforming the value inside a `Some`\n * using a function that may return `null` or `undefined`.\n *\n * **Details**\n *\n * This function applies a transformation function `f` to the value inside a\n * `Some`. The function `f` may return a value, `null`, or `undefined`. If `f`\n * returns a value, it is wrapped in a `Some`. If `f` returns `null` or\n * `undefined`, the result is `None`. If the input `Option` is `None`, the\n * function is not applied, and `None` is returned.\n *\n * This utility is particularly useful when working with deeply nested optional\n * values or chaining computations that may result in `null` or `undefined` at\n * some point.\n *\n * @example\n * ```ts\n * import { 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 * // Extracting a deeply nested property\n * console.log(\n * Option.some(employee1)\n * .pipe(Option.flatMapNullable((employee) => employee.company?.address?.street?.name))\n * )\n * // Output: { _id: 'Option', _tag: 'Some', value: 'high street' }\n *\n * const employee2: Employee = { company: { address: { street: {} } } }\n *\n * // Property does not exist\n * console.log(\n * Option.some(employee2)\n * .pipe(Option.flatMapNullable((employee) => employee.company?.address?.street?.name))\n * )\n * // Output: { _id: 'Option', _tag: 'None' }\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 * Combines `flatMap` and `fromNullable`, transforming the value inside a `Some`\n * using a function that may return `null` or `undefined`.\n *\n * **Details**\n *\n * This function applies a transformation function `f` to the value inside a\n * `Some`. The function `f` may return a value, `null`, or `undefined`. If `f`\n * returns a value, it is wrapped in a `Some`. If `f` returns `null` or\n * `undefined`, the result is `None`. If the input `Option` is `None`, the\n * function is not applied, and `None` is returned.\n *\n * This utility is particularly useful when working with deeply nested optional\n * values or chaining computations that may result in `null` or `undefined` at\n * some point.\n *\n * @example\n * ```ts\n * import { 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 * // Extracting a deeply nested property\n * console.log(\n * Option.some(employee1)\n * .pipe(Option.flatMapNullable((employee) => employee.company?.address?.street?.name))\n * )\n * // Output: { _id: 'Option', _tag: 'Some', value: 'high street' }\n *\n * const employee2: Employee = { company: { address: { street: {} } } }\n *\n * // Property does not exist\n * console.log(\n * Option.some(employee2)\n * .pipe(Option.flatMapNullable((employee) => employee.company?.address?.street?.name))\n * )\n * // Output: { _id: 'Option', _tag: 'None' }\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 * Flattens an `Option` of `Option` into a single `Option`.\n *\n * **Details**\n *\n * This function takes an `Option` that wraps another `Option` and flattens it\n * into a single `Option`. If the outer `Option` is `Some`, the function\n * extracts the inner `Option`. If the outer `Option` is `None`, the result\n * remains `None`.\n *\n * This is useful for simplifying nested `Option` structures that may arise\n * during functional operations.\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 * Combines two `Option`s, keeping the value from the second `Option` if both\n * are `Some`.\n *\n * **Details**\n *\n * This function takes two `Option`s and returns the second one if the first is\n * `Some`. If the first `Option` is `None`, the result will also be `None`,\n * regardless of the second `Option`. It effectively \"zips\" the two `Option`s\n * while discarding the value from the first `Option`.\n *\n * This is particularly useful when sequencing computations where the result of\n * the first computation is not needed, and you only care about the result of\n * the second computation.\n *\n * @category Zipping\n * @since 2.0.0\n */\nexport const zipRight: {\n /**\n * Combines two `Option`s, keeping the value from the second `Option` if both\n * are `Some`.\n *\n * **Details**\n *\n * This function takes two `Option`s and returns the second one if the first is\n * `Some`. If the first `Option` is `None`, the result will also be `None`,\n * regardless of the second `Option`. It effectively \"zips\" the two `Option`s\n * while discarding the value from the first `Option`.\n *\n * This is particularly useful when sequencing computations where the result of\n * the first computation is not needed, and you only care about the result of\n * the second computation.\n *\n * @category Zipping\n * @since 2.0.0\n */\n <B>(that: Option<B>): <_>(self: Option<_>) => Option<B>\n /**\n * Combines two `Option`s, keeping the value from the second `Option` if both\n * are `Some`.\n *\n * **Details**\n *\n * This function takes two `Option`s and returns the second one if the first is\n * `Some`. If the first `Option` is `None`, the result will also be `None`,\n * regardless of the second `Option`. It effectively \"zips\" the two `Option`s\n * while discarding the value from the first `Option`.\n *\n * This is particularly useful when sequencing computations where the result of\n * the first computation is not needed, and you only care about the result of\n * the second computation.\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 * Combines two `Option`s, keeping the value from the first `Option` if both are\n * `Some`.\n *\n * **Details**\n *\n * This function takes two `Option`s and returns the first one if it is `Some`.\n * If either the first `Option` or the second `Option` is `None`, the result\n * will be `None`. This operation \"zips\" the two `Option`s while discarding the\n * value from the second `Option`.\n *\n * This is useful when sequencing computations where the second `Option`\n * represents a dependency or condition that must hold, but its value is\n * irrelevant.\n *\n * @category Zipping\n * @since 2.0.0\n */\nexport const zipLeft: {\n /**\n * Combines two `Option`s, keeping the value from the first `Option` if both are\n * `Some`.\n *\n * **Details**\n *\n * This function takes two `Option`s and returns the first one if it is `Some`.\n * If either the first `Option` or the second `Option` is `None`, the result\n * will be `None`. This operation \"zips\" the two `Option`s while discarding the\n * value from the second `Option`.\n *\n * This is useful when sequencing computations where the second `Option`\n * represents a dependency or condition that must hold, but its value is\n * irrelevant.\n *\n * @category Zipping\n * @since 2.0.0\n */\n <_>(that: Option<_>): <A>(self: Option<A>) => Option<A>\n /**\n * Combines two `Option`s, keeping the value from the first `Option` if both are\n * `Some`.\n *\n * **Details**\n *\n * This function takes two `Option`s and returns the first one if it is `Some`.\n * If either the first `Option` or the second `Option` is `None`, the result\n * will be `None`. This operation \"zips\" the two `Option`s while discarding the\n * value from the second `Option`.\n *\n * This is useful when sequencing computations where the second `Option`\n * represents a dependency or condition that must hold, but its value is\n * irrelevant.\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 * Composes two functions that return `Option` values, creating a new function\n * that chains them together.\n *\n * **Details**\n *\n * This function allows you to compose two computations, each represented by a\n * function that returns an `Option`. The result of the first function is passed\n * to the second function if it is `Some`. If the first function returns `None`,\n * the composed function short-circuits and returns `None` without invoking the\n * second function.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const parse = (s: string): Option.Option<number> => isNaN(Number(s)) ? Option.none() : Option.some(Number(s))\n *\n * const double = (n: number): Option.Option<number> => n > 0 ? Option.some(n * 2) : Option.none()\n *\n * const parseAndDouble = Option.composeK(parse, double)\n *\n * console.log(parseAndDouble(\"42\"))\n * // Output: { _id: 'Option', _tag: 'Some', value: 84 }\n *\n * console.log(parseAndDouble(\"not a number\"))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Sequencing\n * @since 2.0.0\n */\nexport const composeK: {\n /**\n * Composes two functions that return `Option` values, creating a new function\n * that chains them together.\n *\n * **Details**\n *\n * This function allows you to compose two computations, each represented by a\n * function that returns an `Option`. The result of the first function is passed\n * to the second function if it is `Some`. If the first function returns `None`,\n * the composed function short-circuits and returns `None` without invoking the\n * second function.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const parse = (s: string): Option.Option<number> => isNaN(Number(s)) ? Option.none() : Option.some(Number(s))\n *\n * const double = (n: number): Option.Option<number> => n > 0 ? Option.some(n * 2) : Option.none()\n *\n * const parseAndDouble = Option.composeK(parse, double)\n *\n * console.log(parseAndDouble(\"42\"))\n * // Output: { _id: 'Option', _tag: 'Some', value: 84 }\n *\n * console.log(parseAndDouble(\"not a number\"))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\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 * Composes two functions that return `Option` values, creating a new function\n * that chains them together.\n *\n * **Details**\n *\n * This function allows you to compose two computations, each represented by a\n * function that returns an `Option`. The result of the first function is passed\n * to the second function if it is `Some`. If the first function returns `None`,\n * the composed function short-circuits and returns `None` without invoking the\n * second function.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const parse = (s: string): Option.Option<number> => isNaN(Number(s)) ? Option.none() : Option.some(Number(s))\n *\n * const double = (n: number): Option.Option<number> => n > 0 ? Option.some(n * 2) : Option.none()\n *\n * const parseAndDouble = Option.composeK(parse, double)\n *\n * console.log(parseAndDouble(\"42\"))\n * // Output: { _id: 'Option', _tag: 'Some', value: 84 }\n *\n * console.log(parseAndDouble(\"not a number\"))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\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 * Applies the provided function `f` to the value of the `Option` if it is\n * `Some` and returns the original `Option`, unless `f` returns `None`, in which\n * case it returns `None`.\n *\n * **Details**\n *\n * This function allows you to perform additional computations on the value of\n * an `Option` without modifying its original value. If the `Option` is `Some`,\n * the provided function `f` is executed with the value, and its result\n * determines whether the original `Option` is returned (`Some`) or the result\n * is `None` if `f` returns `None`. If the input `Option` is `None`, the\n * function is not executed, and `None` is returned.\n *\n * This is particularly useful for applying side conditions or performing\n * validation checks while retaining the original `Option`'s value.\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 * console.log(Option.tap(Option.none(), getInteger))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(Option.tap(Option.some(1), getInteger))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(Option.tap(Option.some(1.14), getInteger))\n * // Output: { _id: 'Option', _tag: '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\n * `Some` and returns the original `Option`, unless `f` returns `None`, in which\n * case it returns `None`.\n *\n * **Details**\n *\n * This function allows you to perform additional computations on the value of\n * an `Option` without modifying its original value. If the `Option` is `Some`,\n * the provided function `f` is executed with the value, and its result\n * determines whether the original `Option` is returned (`Some`) or the result\n * is `None` if `f` returns `None`. If the input `Option` is `None`, the\n * function is not executed, and `None` is returned.\n *\n * This is particularly useful for applying side conditions or performing\n * validation checks while retaining the original `Option`'s value.\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 * console.log(Option.tap(Option.none(), getInteger))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(Option.tap(Option.some(1), getInteger))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(Option.tap(Option.some(1.14), getInteger))\n * // Output: { _id: 'Option', _tag: '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\n * `Some` and returns the original `Option`, unless `f` returns `None`, in which\n * case it returns `None`.\n *\n * **Details**\n *\n * This function allows you to perform additional computations on the value of\n * an `Option` without modifying its original value. If the `Option` is `Some`,\n * the provided function `f` is executed with the value, and its result\n * determines whether the original `Option` is returned (`Some`) or the result\n * is `None` if `f` returns `None`. If the input `Option` is `None`, the\n * function is not executed, and `None` is returned.\n *\n * This is particularly useful for applying side conditions or performing\n * validation checks while retaining the original `Option`'s value.\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 * console.log(Option.tap(Option.none(), getInteger))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(Option.tap(Option.some(1), getInteger))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(Option.tap(Option.some(1.14), getInteger))\n * // Output: { _id: 'Option', _tag: '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 * Combines two `Option` values into a single `Option` containing a tuple of\n * their values if both are `Some`.\n *\n * **Details**\n *\n * This function takes two `Option`s and combines their values into a tuple `[A,\n * B]` if both are `Some`. If either of the `Option`s is `None`, the result is\n * `None`. This is particularly useful for combining multiple `Option` values\n * into a single one, ensuring both contain valid values.\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 * Combines an `Option` with a collection of `Option`s into a single `Option`\n * containing a tuple of their values if all are `Some`.\n *\n * **Details**\n *\n * This function takes a primary `Option` and a collection of `Option`s and\n * combines their values into a tuple `[A, ...Array<A>]` if all are `Some`. If\n * the primary `Option` or any `Option` in the collection is `None`, the result\n * is `None`.\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 * Combines a structure of `Option`s into a single `Option` containing the\n * values with the same structure.\n *\n * **Details**\n *\n * This function takes a structure of `Option`s (a tuple, struct, or iterable)\n * and produces a single `Option` that contains the values from the input\n * structure if all `Option`s are `Some`. If any `Option` in the input is\n * `None`, the result is `None`. The structure of the input is preserved in the\n * output.\n *\n * - If the input is a tuple (e.g., an array), the result will be an `Option`\n * containing a tuple with the same length.\n * - If the input is a struct (e.g., an object), the result will be an `Option`\n * containing a struct with the same keys.\n * - If the input is an iterable, the result will be an `Option` containing an\n * array.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const maybeName: Option.Option<string> = Option.some(\"John\")\n * const maybeAge: Option.Option<number> = Option.some(25)\n *\n * // ┌─── Option<[string, number]>\n * // ▼\n * const tuple = Option.all([maybeName, maybeAge])\n * console.log(tuple)\n * // Output:\n * // { _id: 'Option', _tag: 'Some', value: [ 'John', 25 ] }\n *\n * // ┌─── Option<{ name: string; age: number; }>\n * // ▼\n * const struct = Option.all({ name: maybeName, age: maybeAge })\n * console.log(struct)\n * // Output:\n * // { _id: 'Option', _tag: 'Some', value: { name: 'John', age: 25 } }\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 * Combines two `Option` values into a new `Option` by applying a provided\n * function to their values.\n *\n * **Details**\n *\n * This function takes two `Option` values (`self` and `that`) and a combining\n * function `f`. If both `Option` values are `Some`, the function `f` is applied\n * to their values, and the result is wrapped in a new `Some`. If either\n * `Option` is `None`, the result is `None`.\n *\n * This utility is useful for combining two optional computations into a single\n * result while maintaining type safety and avoiding explicit checks for `None`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const maybeName: Option.Option<string> = Option.some(\"John\")\n * const maybeAge: Option.Option<number> = Option.some(25)\n *\n * // Combine the name and age into a person object\n * const person = Option.zipWith(maybeName, maybeAge, (name, age) => ({\n * name: name.toUpperCase(),\n * age\n * }))\n *\n * console.log(person)\n * // Output:\n * // { _id: 'Option', _tag: 'Some', value: { name: 'JOHN', age: 25 } }\n * ```\n *\n * @category Zipping\n * @since 2.0.0\n */\nexport const zipWith: {\n /**\n * Combines two `Option` values into a new `Option` by applying a provided\n * function to their values.\n *\n * **Details**\n *\n * This function takes two `Option` values (`self` and `that`) and a combining\n * function `f`. If both `Option` values are `Some`, the function `f` is applied\n * to their values, and the result is wrapped in a new `Some`. If either\n * `Option` is `None`, the result is `None`.\n *\n * This utility is useful for combining two optional computations into a single\n * result while maintaining type safety and avoiding explicit checks for `None`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const maybeName: Option.Option<string> = Option.some(\"John\")\n * const maybeAge: Option.Option<number> = Option.some(25)\n *\n * // Combine the name and age into a person object\n * const person = Option.zipWith(maybeName, maybeAge, (name, age) => ({\n * name: name.toUpperCase(),\n * age\n * }))\n *\n * console.log(person)\n * // Output:\n * // { _id: 'Option', _tag: 'Some', value: { name: 'JOHN', age: 25 } }\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 * Combines two `Option` values into a new `Option` by applying a provided\n * function to their values.\n *\n * **Details**\n *\n * This function takes two `Option` values (`self` and `that`) and a combining\n * function `f`. If both `Option` values are `Some`, the function `f` is applied\n * to their values, and the result is wrapped in a new `Some`. If either\n * `Option` is `None`, the result is `None`.\n *\n * This utility is useful for combining two optional computations into a single\n * result while maintaining type safety and avoiding explicit checks for `None`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const maybeName: Option.Option<string> = Option.some(\"John\")\n * const maybeAge: Option.Option<number> = Option.some(25)\n *\n * // Combine the name and age into a person object\n * const person = Option.zipWith(maybeName, maybeAge, (name, age) => ({\n * name: name.toUpperCase(),\n * age\n * }))\n *\n * console.log(person)\n * // Output:\n * // { _id: 'Option', _tag: 'Some', value: { name: 'JOHN', age: 25 } }\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 * Applies a function inside a `Some` to a value inside another `Some`,\n * combining them into a new `Option`.\n *\n * **Details**\n *\n * This function allows you to apply a function wrapped in an `Option` (`self`)\n * to a value wrapped in another `Option` (`that`). If both `Option`s are\n * `Some`, the function is applied to the value, and the result is wrapped in a\n * new `Some`. If either `Option` is `None`, the result is `None`.\n *\n * @category Combining\n * @since 2.0.0\n */\nexport const ap: {\n /**\n * Applies a function inside a `Some` to a value inside another `Some`,\n * combining them into a new `Option`.\n *\n * **Details**\n *\n * This function allows you to apply a function wrapped in an `Option` (`self`)\n * to a value wrapped in another `Option` (`that`). If both `Option`s are\n * `Some`, the function is applied to the value, and the result is wrapped in a\n * new `Some`. If either `Option` is `None`, the result is `None`.\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 * Applies a function inside a `Some` to a value inside another `Some`,\n * combining them into a new `Option`.\n *\n * **Details**\n *\n * This function allows you to apply a function wrapped in an `Option` (`self`)\n * to a value wrapped in another `Option` (`that`). If both `Option`s are\n * `Some`, the function is applied to the value, and the result is wrapped in a\n * new `Some`. If either `Option` is `None`, the result is `None`.\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`, ignoring\n * elements that are `None`.\n *\n * **Details**\n *\n * This function takes an initial value of type `B` and a reducing function `f`\n * that combines the accumulator with values of type `A`. It processes an\n * iterable of `Option<A>`, applying `f` only to the `Some` values while\n * ignoring the `None` values. The result is a single value of type `B`.\n *\n * This utility is particularly useful for aggregating values from an iterable\n * of `Option`s while skipping the absent (`None`) values.\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const iterable = [Option.some(1), Option.none(), Option.some(2), Option.none()]\n *\n * console.log(pipe(iterable, Option.reduceCompact(0, (b, a) => b + a)))\n * // Output: 3\n * ```\n *\n * @category Reducing\n * @since 2.0.0\n */\nexport const reduceCompact: {\n /**\n * Reduces an `Iterable` of `Option<A>` to a single value of type `B`, ignoring\n * elements that are `None`.\n *\n * **Details**\n *\n * This function takes an initial value of type `B` and a reducing function `f`\n * that combines the accumulator with values of type `A`. It processes an\n * iterable of `Option<A>`, applying `f` only to the `Some` values while\n * ignoring the `None` values. The result is a single value of type `B`.\n *\n * This utility is particularly useful for aggregating values from an iterable\n * of `Option`s while skipping the absent (`None`) values.\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const iterable = [Option.some(1), Option.none(), Option.some(2), Option.none()]\n *\n * console.log(pipe(iterable, Option.reduceCompact(0, (b, a) => b + a)))\n * // Output: 3\n * ```\n *\n * @category Reducing\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`, ignoring\n * elements that are `None`.\n *\n * **Details**\n *\n * This function takes an initial value of type `B` and a reducing function `f`\n * that combines the accumulator with values of type `A`. It processes an\n * iterable of `Option<A>`, applying `f` only to the `Some` values while\n * ignoring the `None` values. The result is a single value of type `B`.\n *\n * This utility is particularly useful for aggregating values from an iterable\n * of `Option`s while skipping the absent (`None`) values.\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const iterable = [Option.some(1), Option.none(), Option.some(2), Option.none()]\n *\n * console.log(pipe(iterable, Option.reduceCompact(0, (b, a) => b + a)))\n * // Output: 3\n * ```\n *\n * @category Reducing\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 * Converts an `Option` into an `Array`.\n * If the input is `None`, an empty array is returned.\n * If the input is `Some`, its value is wrapped in a single-element array.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.toArray(Option.some(1)))\n * // Output: [1]\n *\n * console.log(Option.toArray(Option.none()))\n * // Output: []\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 * Splits an `Option` into two `Option`s based on the result of a mapping\n * function that produces an `Either`.\n *\n * **Details**\n *\n * This function takes an `Option` and a mapping function `f` that converts its\n * value into an `Either`. It returns a tuple of two `Option`s:\n *\n * - The first `Option` (`left`) contains the value from the `Left` side of the\n * `Either` if it exists, otherwise `None`.\n * - The second `Option` (`right`) contains the value from the `Right` side of\n * the `Either` if it exists, otherwise `None`.\n *\n * If the input `Option` is `None`, both returned `Option`s are `None`.\n *\n * This utility is useful for filtering and categorizing the contents of an\n * `Option` based on a bifurcating computation.\n *\n * @category Filtering\n * @since 2.0.0\n */\nexport const partitionMap: {\n /**\n * Splits an `Option` into two `Option`s based on the result of a mapping\n * function that produces an `Either`.\n *\n * **Details**\n *\n * This function takes an `Option` and a mapping function `f` that converts its\n * value into an `Either`. It returns a tuple of two `Option`s:\n *\n * - The first `Option` (`left`) contains the value from the `Left` side of the\n * `Either` if it exists, otherwise `None`.\n * - The second `Option` (`right`) contains the value from the `Right` side of\n * the `Either` if it exists, otherwise `None`.\n *\n * If the input `Option` is `None`, both returned `Option`s are `None`.\n *\n * This utility is useful for filtering and categorizing the contents of an\n * `Option` based on a bifurcating computation.\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 * Splits an `Option` into two `Option`s based on the result of a mapping\n * function that produces an `Either`.\n *\n * **Details**\n *\n * This function takes an `Option` and a mapping function `f` that converts its\n * value into an `Either`. It returns a tuple of two `Option`s:\n *\n * - The first `Option` (`left`) contains the value from the `Left` side of the\n * `Either` if it exists, otherwise `None`.\n * - The second `Option` (`right`) contains the value from the `Right` side of\n * the `Either` if it exists, otherwise `None`.\n *\n * If the input `Option` is `None`, both returned `Option`s are `None`.\n *\n * This utility is useful for filtering and categorizing the contents of an\n * `Option` based on a bifurcating computation.\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// TODO(4.0): remove?\n/**\n * Alias of {@link flatMap}.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Transform and filter numbers\n * const transformEven = (n: Option.Option<number>): Option.Option<string> =>\n * Option.filterMap(n, (n) => (n % 2 === 0 ? Option.some(`Even: ${n}`) : Option.none()))\n *\n * console.log(transformEven(Option.none()))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(transformEven(Option.some(1)))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(transformEven(Option.some(2)))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'Even: 2' }\n * ```\n *\n * @category Filtering\n * @since 2.0.0\n */\nexport const filterMap: {\n // TODO(4.0): remove?\n /**\n * Alias of {@link flatMap}.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Transform and filter numbers\n * const transformEven = (n: Option.Option<number>): Option.Option<string> =>\n * Option.filterMap(n, (n) => (n % 2 === 0 ? Option.some(`Even: ${n}`) : Option.none()))\n *\n * console.log(transformEven(Option.none()))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(transformEven(Option.some(1)))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(transformEven(Option.some(2)))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'Even: 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 // TODO(4.0): remove?\n /**\n * Alias of {@link flatMap}.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Transform and filter numbers\n * const transformEven = (n: Option.Option<number>): Option.Option<string> =>\n * Option.filterMap(n, (n) => (n % 2 === 0 ? Option.some(`Even: ${n}`) : Option.none()))\n *\n * console.log(transformEven(Option.none()))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(transformEven(Option.some(1)))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(transformEven(Option.some(2)))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'Even: 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} = flatMap\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 * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const removeEmptyString = (input: Option.Option<string>) =>\n * Option.filter(input, (value) => value !== \"\")\n *\n * console.log(removeEmptyString(Option.none()))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"\")))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"a\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\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 * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const removeEmptyString = (input: Option.Option<string>) =>\n * Option.filter(input, (value) => value !== \"\")\n *\n * console.log(removeEmptyString(Option.none()))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"\")))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"a\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\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 * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const removeEmptyString = (input: Option.Option<string>) =>\n * Option.filter(input, (value) => value !== \"\")\n *\n * console.log(removeEmptyString(Option.none()))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"\")))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"a\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\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 * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const removeEmptyString = (input: Option.Option<string>) =>\n * Option.filter(input, (value) => value !== \"\")\n *\n * console.log(removeEmptyString(Option.none()))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"\")))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"a\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\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 * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const removeEmptyString = (input: Option.Option<string>) =>\n * Option.filter(input, (value) => value !== \"\")\n *\n * console.log(removeEmptyString(Option.none()))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"\")))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"a\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\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 * Creates an `Equivalence` instance for comparing `Option` values, using a\n * provided `Equivalence` for the inner type.\n *\n * **Details**\n *\n * This function takes an `Equivalence` instance for a specific type `A` and\n * produces an `Equivalence` instance for `Option<A>`. The resulting\n * `Equivalence` determines whether two `Option` values are equivalent:\n *\n * - Two `None`s are considered equivalent.\n * - A `Some` and a `None` are not equivalent.\n * - Two `Some` values are equivalent if their inner values are equivalent\n * according to the provided `Equivalence`.\n *\n * **Example** (Comparing Optional Numbers for Equivalence)\n *\n * ```ts\n * import { Number, Option } from \"effect\"\n *\n * const isEquivalent = Option.getEquivalence(Number.Equivalence)\n *\n * console.log(isEquivalent(Option.none(), Option.none()))\n * // Output: true\n *\n * console.log(isEquivalent(Option.none(), Option.some(1)))\n * // Output: false\n *\n * console.log(isEquivalent(Option.some(1), Option.none()))\n * // Output: false\n *\n * console.log(isEquivalent(Option.some(1), Option.some(2)))\n * // Output: false\n *\n * console.log(isEquivalent(Option.some(1), Option.some(1)))\n * // Output: 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 * Creates an `Order` instance for comparing `Option` values, using a provided\n * `Order` for the inner type.\n *\n * **Details**\n *\n * This function produces an `Order` instance for `Option<A>`, allowing `Option`\n * values to be compared:\n *\n * - `None` is always considered less than any `Some` value.\n * - If both are `Some`, their inner values are compared using the provided\n * `Order` instance.\n *\n * @example\n * ```ts\n * import { Number, Option } from \"effect\"\n *\n * const order = Option.getOrder(Number.Order)\n *\n * console.log(order(Option.none(), Option.none()))\n * // Output: 0\n *\n * console.log(order(Option.none(), Option.some(1)))\n * // Output: -1\n *\n * console.log(order(Option.some(1), Option.none()))\n * // Output: 1\n *\n * console.log(order(Option.some(1), Option.some(2)))\n * // Output: -1\n *\n * console.log(order(Option.some(1), Option.some(1)))\n * // Output: 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 to work with `Option` values, allowing the function\n * to operate on two `Option`s.\n *\n * **Details**\n *\n * This function takes a binary function `f` and returns a new function that\n * applies `f` to the values of two `Option`s (`self` and `that`). If both\n * `Option`s are `Some`, the binary function `f` is applied to their values, and\n * the result is wrapped in a new `Some`. If either `Option` is `None`, the\n * result is `None`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // A binary function to add two numbers\n * const add = (a: number, b: number): number => a + b\n *\n * // Lift the `add` function to work with `Option` values\n * const addOptions = Option.lift2(add)\n *\n * // Both `Option`s are `Some`\n * console.log(addOptions(Option.some(2), Option.some(3)))\n * // Output: { _id: 'Option', _tag: 'Some', value: 5 }\n *\n * // One `Option` is `None`\n * console.log(addOptions(Option.some(2), Option.none()))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\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 * Lifts a `Predicate` or `Refinement` into the `Option` context, returning a\n * `Some` of the input value if the predicate is satisfied, or `None` otherwise.\n *\n * **Details**\n *\n * This function transforms a `Predicate` (or a more specific `Refinement`) into\n * a function that produces an `Option`. If the predicate evaluates to `true`,\n * the input value is wrapped in a `Some`. If the predicate evaluates to\n * `false`, the result is `None`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Check if a number is positive\n * const isPositive = (n: number) => n > 0\n *\n * // ┌─── (b: number) => Option<number>\n * // ▼\n * const parsePositive = Option.liftPredicate(isPositive)\n *\n * console.log(parsePositive(1))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(parsePositive(-1))\n * // OUtput: { _id: 'Option', _tag: 'None' }\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 * Lifts a `Predicate` or `Refinement` into the `Option` context, returning a\n * `Some` of the input value if the predicate is satisfied, or `None` otherwise.\n *\n * **Details**\n *\n * This function transforms a `Predicate` (or a more specific `Refinement`) into\n * a function that produces an `Option`. If the predicate evaluates to `true`,\n * the input value is wrapped in a `Some`. If the predicate evaluates to\n * `false`, the result is `None`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Check if a number is positive\n * const isPositive = (n: number) => n > 0\n *\n * // ┌─── (b: number) => Option<number>\n * // ▼\n * const parsePositive = Option.liftPredicate(isPositive)\n *\n * console.log(parsePositive(1))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(parsePositive(-1))\n * // OUtput: { _id: 'Option', _tag: 'None' }\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 * Lifts a `Predicate` or `Refinement` into the `Option` context, returning a\n * `Some` of the input value if the predicate is satisfied, or `None` otherwise.\n *\n * **Details**\n *\n * This function transforms a `Predicate` (or a more specific `Refinement`) into\n * a function that produces an `Option`. If the predicate evaluates to `true`,\n * the input value is wrapped in a `Some`. If the predicate evaluates to\n * `false`, the result is `None`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Check if a number is positive\n * const isPositive = (n: number) => n > 0\n *\n * // ┌─── (b: number) => Option<number>\n * // ▼\n * const parsePositive = Option.liftPredicate(isPositive)\n *\n * console.log(parsePositive(1))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(parsePositive(-1))\n * // OUtput: { _id: 'Option', _tag: 'None' }\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 * Lifts a `Predicate` or `Refinement` into the `Option` context, returning a\n * `Some` of the input value if the predicate is satisfied, or `None` otherwise.\n *\n * **Details**\n *\n * This function transforms a `Predicate` (or a more specific `Refinement`) into\n * a function that produces an `Option`. If the predicate evaluates to `true`,\n * the input value is wrapped in a `Some`. If the predicate evaluates to\n * `false`, the result is `None`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Check if a number is positive\n * const isPositive = (n: number) => n > 0\n *\n * // ┌─── (b: number) => Option<number>\n * // ▼\n * const parsePositive = Option.liftPredicate(isPositive)\n *\n * console.log(parsePositive(1))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(parsePositive(-1))\n * // OUtput: { _id: 'Option', _tag: 'None' }\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 an `Option` contains a specified value,\n * using a provided equivalence function.\n *\n * **Details**\n *\n * This function allows you to check whether an `Option` contains a specific\n * value. It uses an equivalence function `isEquivalent` to compare the value\n * inside the `Option` to the provided value. If the `Option` is `Some` and the\n * equivalence function returns `true`, the result is `true`. If the `Option` is\n * `None` or the values are not equivalent, the result is `false`.\n *\n * @example\n * ```ts\n * import { Number, Option } from \"effect\"\n *\n * const contains = Option.containsWith(Number.Equivalence)\n *\n * console.log(Option.some(2).pipe(contains(2)))\n * // Output: true\n *\n * console.log(Option.some(1).pipe(contains(2)))\n * // Output: false\n *\n * console.log(Option.none().pipe(contains(2)))\n * // Output: false\n * ```\n *\n * @see {@link contains} for a version that uses the default `Equivalence`.\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 specified value\n * using the default `Equivalence`.\n *\n * **Details**\n *\n * This function allows you to check whether an `Option` contains a specific\n * value. It uses the default `Equivalence` for equality comparison. If the\n * `Option` is `Some` and its value is equivalent to the provided value, the\n * result is `true`. If the `Option` is `None` or the values are not equivalent,\n * the result is `false`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.some(2).pipe(Option.contains(2)))\n * // Output: true\n *\n * console.log(Option.some(1).pipe(Option.contains(2)))\n * // Output: false\n *\n * console.log(Option.none().pipe(Option.contains(2)))\n * // Output: false\n * ```\n *\n * @see {@link containsWith} for a version that allows you to specify a custom equivalence function.\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 specified value\n * using the default `Equivalence`.\n *\n * **Details**\n *\n * This function allows you to check whether an `Option` contains a specific\n * value. It uses the default `Equivalence` for equality comparison. If the\n * `Option` is `Some` and its value is equivalent to the provided value, the\n * result is `true`. If the `Option` is `None` or the values are not equivalent,\n * the result is `false`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.some(2).pipe(Option.contains(2)))\n * // Output: true\n *\n * console.log(Option.some(1).pipe(Option.contains(2)))\n * // Output: false\n *\n * console.log(Option.none().pipe(Option.contains(2)))\n * // Output: false\n * ```\n *\n * @see {@link containsWith} for a version that allows you to specify a custom equivalence function.\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 specified value\n * using the default `Equivalence`.\n *\n * **Details**\n *\n * This function allows you to check whether an `Option` contains a specific\n * value. It uses the default `Equivalence` for equality comparison. If the\n * `Option` is `Some` and its value is equivalent to the provided value, the\n * result is `true`. If the `Option` is `None` or the values are not equivalent,\n * the result is `false`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.some(2).pipe(Option.contains(2)))\n * // Output: true\n *\n * console.log(Option.some(1).pipe(Option.contains(2)))\n * // Output: false\n *\n * console.log(Option.none().pipe(Option.contains(2)))\n * // Output: false\n * ```\n *\n * @see {@link containsWith} for a version that allows you to specify a custom equivalence function.\n *\n * @category Elements\n * @since 2.0.0\n */\n <A>(self: Option<A>, a: A): boolean\n} = containsWith(_equivalence)\n\n/**\n * Checks if a value in an `Option` satisfies a given predicate or refinement.\n *\n * **Details**\n *\n * This function allows you to check if a value inside a `Some` meets a\n * specified condition. If the `Option` is `None`, the result is `false`. If the\n * `Option` is `Some`, the provided predicate or refinement is applied to the\n * value:\n *\n * - If the condition is met, the result is `true`.\n * - If the condition is not met, the result is `false`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * console.log(Option.some(2).pipe(Option.exists(isEven)))\n * // Output: true\n *\n * console.log(Option.some(1).pipe(Option.exists(isEven)))\n * // Output: false\n *\n * console.log(Option.none().pipe(Option.exists(isEven)))\n * // Output: false\n * ```\n *\n * @category Elements\n * @since 2.0.0\n */\nexport const exists: {\n /**\n * Checks if a value in an `Option` satisfies a given predicate or refinement.\n *\n * **Details**\n *\n * This function allows you to check if a value inside a `Some` meets a\n * specified condition. If the `Option` is `None`, the result is `false`. If the\n * `Option` is `Some`, the provided predicate or refinement is applied to the\n * value:\n *\n * - If the condition is met, the result is `true`.\n * - If the condition is not met, the result is `false`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * console.log(Option.some(2).pipe(Option.exists(isEven)))\n * // Output: true\n *\n * console.log(Option.some(1).pipe(Option.exists(isEven)))\n * // Output: false\n *\n * console.log(Option.none().pipe(Option.exists(isEven)))\n * // Output: false\n * ```\n *\n * @category Elements\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 * Checks if a value in an `Option` satisfies a given predicate or refinement.\n *\n * **Details**\n *\n * This function allows you to check if a value inside a `Some` meets a\n * specified condition. If the `Option` is `None`, the result is `false`. If the\n * `Option` is `Some`, the provided predicate or refinement is applied to the\n * value:\n *\n * - If the condition is met, the result is `true`.\n * - If the condition is not met, the result is `false`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * console.log(Option.some(2).pipe(Option.exists(isEven)))\n * // Output: true\n *\n * console.log(Option.some(1).pipe(Option.exists(isEven)))\n * // Output: false\n *\n * console.log(Option.none().pipe(Option.exists(isEven)))\n * // Output: false\n * ```\n *\n * @category Elements\n * @since 2.0.0\n */\n <A>(predicate: Predicate<NoInfer<A>>): (self: Option<A>) => boolean\n /**\n * Checks if a value in an `Option` satisfies a given predicate or refinement.\n *\n * **Details**\n *\n * This function allows you to check if a value inside a `Some` meets a\n * specified condition. If the `Option` is `None`, the result is `false`. If the\n * `Option` is `Some`, the provided predicate or refinement is applied to the\n * value:\n *\n * - If the condition is met, the result is `true`.\n * - If the condition is not met, the result is `false`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * console.log(Option.some(2).pipe(Option.exists(isEven)))\n * // Output: true\n *\n * console.log(Option.some(1).pipe(Option.exists(isEven)))\n * // Output: false\n *\n * console.log(Option.none().pipe(Option.exists(isEven)))\n * // Output: false\n * ```\n *\n * @category Elements\n * @since 2.0.0\n */\n <A, B extends A>(self: Option<A>, refinement: Refinement<A, B>): self is Option<B>\n /**\n * Checks if a value in an `Option` satisfies a given predicate or refinement.\n *\n * **Details**\n *\n * This function allows you to check if a value inside a `Some` meets a\n * specified condition. If the `Option` is `None`, the result is `false`. If the\n * `Option` is `Some`, the provided predicate or refinement is applied to the\n * value:\n *\n * - If the condition is met, the result is `true`.\n * - If the condition is not met, the result is `false`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * console.log(Option.some(2).pipe(Option.exists(isEven)))\n * // Output: true\n *\n * console.log(Option.some(1).pipe(Option.exists(isEven)))\n * // Output: false\n *\n * console.log(Option.none().pipe(Option.exists(isEven)))\n * // Output: false\n * ```\n *\n * @category Elements\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @see {@link Do}\n * @see {@link bind}\n * @see {@link bindTo}\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @category Do notation\n * @since 2.0.0\n */\n <N extends string, A extends object, B>(name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Option<B>): (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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\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 * @example\n * ```ts\n * import * as assert from \"node:assert\"\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 * @see {@link bindTo}\n * @see {@link bind}\n * @see {@link let_ let}\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 * Similar to `Effect.gen`, `Option.gen` provides a more readable,\n * generator-based syntax for working with `Option` values, making code that\n * involves `Option` easier to write and understand. This approach is similar to\n * using `async/await` but tailored for `Option`.\n *\n * **Example** (Using `Option.gen` to Create a Combined Value)\n *\n * ```ts\n * import { Option } from \"effect\"\n *\n * const maybeName: Option.Option<string> = Option.some(\"John\")\n * const maybeAge: Option.Option<number> = Option.some(25)\n *\n * const person = Option.gen(function* () {\n * const name = (yield* maybeName).toUpperCase()\n * const age = yield* maybeAge\n * return { name, age }\n * })\n *\n * console.log(person)\n * // Output:\n * // { _id: 'Option', _tag: 'Some', value: { name: 'JOHN', age: 25 } }\n * ```\n *\n * @category Generators\n * @since 2.0.0\n */\nexport const gen: Gen.Gen<OptionTypeLambda, Gen.Adapter<OptionTypeLambda>> = (...args) => {\n const f = args.length === 1 ? args[0] : args[1].bind(args[0])\n const iterator = f(adapter)\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 if (isNone(current)) {\n return current\n }\n state = iterator.next(current.value as never)\n }\n return some(state.value)\n}\n\n/**\n * Merges two optional values, applying a function if both exist.\n * Unlike {@link zipWith}, this function returns `None` only if both inputs are `None`.\n *\n * @internal\n */\nexport const mergeWith = <A>(f: (a1: A, a2: A) => A) => (o1: Option<A>, o2: Option<A>): Option<A> => {\n if (isNone(o1)) {\n return o2\n } else if (isNone(o2)) {\n return o1\n }\n return some(f(o1.value, o2.value))\n}\n","/**\n * This module provides utility functions for working with arrays in TypeScript.\n *\n * @since 2.0.0\n */\n\nimport * as Either 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 internalArray from \"./internal/array.js\"\nimport * as internalDoNotation from \"./internal/doNotation.js\"\nimport * as moduleIterable from \"./Iterable.js\"\nimport * as Option from \"./Option.js\"\nimport * as Order from \"./Order.js\"\nimport * as Predicate 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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.make(1, 2, 3)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.allocate<number>(3)\n * console.log(result) // [ <3 empty items> ]\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 *\n * ```ts\n * import { makeBy } from \"effect/Array\"\n *\n * const result = makeBy(5, n => n * 2)\n * console.log(result) // [0, 2, 4, 6, 8]\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const makeBy: {\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 *\n * ```ts\n * import { makeBy } from \"effect/Array\"\n *\n * const result = makeBy(5, n => n * 2)\n * console.log(result) // [0, 2, 4, 6, 8]\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <A>(f: (i: number) => A): (n: number) => NonEmptyArray<A>\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 *\n * ```ts\n * import { makeBy } from \"effect/Array\"\n *\n * const result = makeBy(5, n => n * 2)\n * console.log(result) // [0, 2, 4, 6, 8]\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <A>(n: number, f: (i: number) => A): NonEmptyArray<A>\n} = dual(2, <A>(n: number, f: (i: number) => 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 *\n * ```ts\n * import { range } from \"effect/Array\"\n *\n * const result = range(1, 3)\n * console.log(result) // [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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.replicate(\"a\", 3)\n * console.log(result) // [\"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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.replicate(\"a\", 3)\n * console.log(result) // [\"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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.replicate(\"a\", 3)\n * console.log(result) // [\"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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.fromIterable(new Set([1, 2, 3]))\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * console.log(Array.ensure(\"a\")) // [\"a\"]\n * console.log(Array.ensure([\"a\"])) // [\"a\"]\n * console.log(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 * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.fromRecord({ a: 1, b: 2, c: 3 })\n * console.log(result) // [[\"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 *\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * console.log(Array.fromOption(Option.some(1))) // [1]\n * console.log(Array.fromOption(Option.none())) // []\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const fromOption: <A>(self: Option.Option<A>) => Array<A> = Option.toArray\n\n/**\n * Matches the elements of an array, applying functions to cases of empty and non-empty arrays.\n *\n * **Example**\n *\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 * console.log(match([])) // \"empty\"\n * console.log(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 *\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 * console.log(match([])) // \"empty\"\n * console.log(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 *\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 * console.log(match([])) // \"empty\"\n * console.log(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 *\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 * console.log(matchLeft([])) // \"empty\"\n * console.log(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 *\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 * console.log(matchLeft([])) // \"empty\"\n * console.log(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 *\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 * console.log(matchLeft([])) // \"empty\"\n * console.log(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 *\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 * console.log(matchRight([])) // \"empty\"\n * console.log(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 *\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 * console.log(matchRight([])) // \"empty\"\n * console.log(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 *\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 * console.log(matchRight([])) // \"empty\"\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.prepend([2, 3, 4], 1)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.prepend([2, 3, 4], 1)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.prepend([2, 3, 4], 1)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.prependAll([2, 3], [0, 1])\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.prependAll([2, 3], [0, 1])\n * console.log(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>>(that: T): (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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.prependAll([2, 3], [0, 1])\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.prependAll([2, 3], [0, 1])\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.prependAll([2, 3], [0, 1])\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.append([1, 2, 3], 4);\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.append([1, 2, 3], 4);\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.append([1, 2, 3], 4);\n * console.log(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>>(that: T): (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 *\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.scan([1, 2, 3, 4], 0, (acc, value) => acc + value)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.scan([1, 2, 3, 4], 0, (acc, value) => acc + value)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.scan([1, 2, 3, 4], 0, (acc, value) => acc + value)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.scanRight([1, 2, 3, 4], 0, (acc, value) => acc + value)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.scanRight([1, 2, 3, 4], 0, (acc, value) => acc + value)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.scanRight([1, 2, 3, 4], 0, (acc, value) => acc + value)\n * console.log(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 * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * console.log(Array.isArray(null)) // false\n * console.log(Array.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 * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * console.log(Array.isArray(null)) // false\n * console.log(Array.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 * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * console.log(Array.isArray(null)) // false\n * console.log(Array.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 * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * console.log(Array.isEmptyArray([])) // true\n * console.log(Array.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 * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * console.log(Array.isEmptyReadonlyArray([])) // true\n * console.log(Array.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 * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * console.log(Array.isNonEmptyArray([])) // false\n * console.log(Array.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> = internalArray.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 * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * console.log(Array.isNonEmptyReadonlyArray([])) // false\n * console.log(Array.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 internalArray.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 isOutOfBounds = <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.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.Option<A>\n} = dual(2, <A>(self: ReadonlyArray<A>, index: number): Option.Option<A> => {\n const i = Math.floor(index)\n return isOutOfBounds(i, self) ? Option.none() : Option.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 (isOutOfBounds(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 *\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.unprepend([1, 2, 3, 4])\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.unappend([1, 2, 3, 4])\n * console.log(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.Option<A> = get(0)\n\n/**\n * Get the first element of a non empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.headNonEmpty([1, 2, 3, 4])\n * console.log(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.Option<A> =>\n isNonEmptyReadonlyArray(self) ? Option.some(lastNonEmpty(self)) : Option.none()\n\n/**\n * Get the last element of a non empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.lastNonEmpty([1, 2, 3, 4])\n * console.log(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.Option<Array<A>> => {\n const input = fromIterable(self)\n return isNonEmptyReadonlyArray(input) ? Option.some(tailNonEmpty(input)) : Option.none()\n}\n\n/**\n * Get all but the first element of a `NonEmptyReadonlyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.tailNonEmpty([1, 2, 3, 4])\n * console.log(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.Option<Array<A>> => {\n const input = fromIterable(self)\n return isNonEmptyReadonlyArray(input) ? Option.some(initNonEmpty(input)) : Option.none()\n}\n\n/**\n * Get all but the last element of a non empty array, creating a new array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.initNonEmpty([1, 2, 3, 4])\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.take([1, 2, 3, 4, 5], 3)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.take([1, 2, 3, 4, 5], 3)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.take([1, 2, 3, 4, 5], 3)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.takeRight([1, 2, 3, 4, 5], 3)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.takeRight([1, 2, 3, 4, 5], 3)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.takeRight([1, 2, 3, 4, 5], 3)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.takeWhile([1, 3, 2, 4, 1, 2], x => x < 4)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.takeWhile([1, 3, 2, 4, 1, 2], x => x < 4)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.takeWhile([1, 3, 2, 4, 1, 2], x => x < 4)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.takeWhile([1, 3, 2, 4, 1, 2], x => x < 4)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.takeWhile([1, 3, 2, 4, 1, 2], x => x < 4)\n * console.log(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>(refinement: (a: NoInfer<A>, i: number) => a is B): (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>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): [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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.drop([1, 2, 3, 4, 5], 2)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.drop([1, 2, 3, 4, 5], 2)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.drop([1, 2, 3, 4, 5], 2)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dropRight([1, 2, 3, 4, 5], 2)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dropRight([1, 2, 3, 4, 5], 2)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dropRight([1, 2, 3, 4, 5], 2)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dropWhile([1, 2, 3, 4, 5], x => x < 4)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dropWhile([1, 2, 3, 4, 5], x => x < 4)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dropWhile([1, 2, 3, 4, 5], x => x < 4)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirstIndex([5, 3, 8, 9], x => x > 5)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirstIndex([5, 3, 8, 9], x => x > 5)\n * console.log(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.Option<number>\n /**\n * Return the first index for which a predicate holds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirstIndex([5, 3, 8, 9], x => x > 5)\n * console.log(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.Option<number>\n} = dual(2, <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option.Option<number> => {\n let i = 0\n for (const a of self) {\n if (predicate(a, i)) {\n return Option.some(i)\n }\n i++\n }\n return Option.none()\n})\n\n/**\n * Return the last index for which a predicate holds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLastIndex([1, 3, 8, 9], x => x < 5)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLastIndex([1, 3, 8, 9], x => x < 5)\n * console.log(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.Option<number>\n /**\n * Return the last index for which a predicate holds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLastIndex([1, 3, 8, 9], x => x < 5)\n * console.log(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.Option<number>\n} = dual(2, <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option.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 Option.some(i)\n }\n }\n return Option.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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirst([1, 2, 3, 4, 5], x => x > 3)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirst([1, 2, 3, 4, 5], x => x > 3)\n * console.log(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.Option<B>): (self: Iterable<A>) => Option.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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirst([1, 2, 3, 4, 5], x => x > 3)\n * console.log(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.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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirst([1, 2, 3, 4, 5], x => x > 3)\n * console.log(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.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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirst([1, 2, 3, 4, 5], x => x > 3)\n * console.log(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.Option<B>): Option.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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirst([1, 2, 3, 4, 5], x => x > 3)\n * console.log(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.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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirst([1, 2, 3, 4, 5], x => x > 3)\n * console.log(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.Option<A>\n} = moduleIterable.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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLast([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLast([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(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.Option<B>): (self: Iterable<A>) => Option.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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLast([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(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.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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLast([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(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.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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLast([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(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.Option<B>): Option.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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLast([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(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.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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLast([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(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.Option<A>\n} = dual(\n 2,\n <A>(\n self: Iterable<A>,\n f: ((a: A, i: number) => boolean) | ((a: A, i: number) => Option.Option<A>)\n ): Option.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 (Predicate.isBoolean(o)) {\n if (o) {\n return Option.some(a)\n }\n } else {\n if (Option.isSome(o)) {\n return o\n }\n }\n }\n return Option.none()\n }\n)\n\n/**\n * Counts all the element of the given array that pass the given predicate\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.countBy([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(result) // 2\n * ```\n *\n * @category folding\n * @since 3.16.0\n */\nexport const countBy: {\n /**\n * Counts all the element of the given array that pass the given predicate\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.countBy([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(result) // 2\n * ```\n *\n * @category folding\n * @since 3.16.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => number\n /**\n * Counts all the element of the given array that pass the given predicate\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.countBy([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(result) // 2\n * ```\n *\n * @category folding\n * @since 3.16.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): number\n} = dual(\n 2,\n <A>(\n self: Iterable<A>,\n f: (a: A, i: number) => boolean\n ): number => {\n let count = 0\n const as = fromIterable(self)\n for (let i = 0; i < as.length; i++) {\n const a = as[i]\n if (f(a, i)) {\n count++\n }\n }\n return count\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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.insertAt(['a', 'b', 'c', 'e'], 3, 'd')\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.insertAt(['a', 'b', 'c', 'e'], 3, 'd')\n * console.log(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.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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.insertAt(['a', 'b', 'c', 'e'], 3, 'd')\n * console.log(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.Option<NonEmptyArray<A | B>>\n} = dual(3, <A, B>(self: Iterable<A>, i: number, b: B): Option.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 Option.none()\n }\n out.splice(i, 0, b)\n return Option.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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.replace(['a', 'b', 'c', 'd'], 1, 'z')\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.replace(['a', 'b', 'c', 'd'], 1, 'z')\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.replace(['a', 'b', 'c', 'd'], 1, 'z')\n * console.log(result) // ['a', 'z', 'c', 'd']\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(self: S, i: number, b: B): 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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.replaceOption([1, 2, 3], 1, 4)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.replaceOption([1, 2, 3], 1, 4)\n * console.log(result) // Option.some([1, 4, 3])\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 ) => Option.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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.replaceOption([1, 2, 3], 1, 4)\n * console.log(result) // Option.some([1, 4, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(self: S, i: number, b: B): Option.Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>\n} = dual(\n 3,\n <A, B>(self: Iterable<A>, i: number, b: B): Option.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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modify([1, 2, 3, 4], 2, (n) => n * 2)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modify([1, 2, 3, 4], 2, (n) => n * 2)\n * console.log(result) // [1, 2, 6, 4]\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(i: number, f: (a: ReadonlyArray.Infer<S>) => B): (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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modify([1, 2, 3, 4], 2, (n) => n * 2)\n * console.log(result) // [1, 2, 6, 4]\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(self: S, i: number, f: (a: ReadonlyArray.Infer<S>) => B): 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 const out: Array<A | B> = Array.from(self)\n if (isOutOfBounds(i, out)) {\n return out\n }\n const b = f(out[i] as A)\n out[i] = b\n return out\n }\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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const input = [1, 2, 3, 4]\n * const result = Array.modifyOption(input, 2, (n) => n * 2)\n * console.log(result) // Option.some([1, 2, 6, 4])\n *\n * const outOfBoundsResult = Array.modifyOption(input, 5, (n) => n * 2)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const input = [1, 2, 3, 4]\n * const result = Array.modifyOption(input, 2, (n) => n * 2)\n * console.log(result) // Option.some([1, 2, 6, 4])\n *\n * const outOfBoundsResult = Array.modifyOption(input, 5, (n) => n * 2)\n * console.log(outOfBoundsResult) // Option.none()\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(i: number, f: (a: ReadonlyArray.Infer<S>) => B): (self: S) => Option.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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const input = [1, 2, 3, 4]\n * const result = Array.modifyOption(input, 2, (n) => n * 2)\n * console.log(result) // Option.some([1, 2, 6, 4])\n *\n * const outOfBoundsResult = Array.modifyOption(input, 5, (n) => n * 2)\n * console.log(outOfBoundsResult) // Option.none()\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(self: S, i: number, f: (a: ReadonlyArray.Infer<S>) => B): Option.Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>\n} = dual(3, <A, B>(self: Iterable<A>, i: number, f: (a: A) => B): Option.Option<Array<A | B>> => {\n const arr = fromIterable(self)\n if (isOutOfBounds(i, arr)) {\n return Option.none()\n }\n const out: Array<A | B> = Array.isArray(self) ? self.slice() : arr\n const b = f(arr[i])\n out[i] = b\n return Option.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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const input = [1, 2, 3, 4]\n * const result = Array.remove(input, 2)\n * console.log(result) // [1, 2, 4]\n *\n * const outOfBoundsResult = Array.remove(input, 5)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const input = [1, 2, 3, 4]\n * const result = Array.remove(input, 2)\n * console.log(result) // [1, 2, 4]\n *\n * const outOfBoundsResult = Array.remove(input, 5)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const input = [1, 2, 3, 4]\n * const result = Array.remove(input, 2)\n * console.log(result) // [1, 2, 4]\n *\n * const outOfBoundsResult = Array.remove(input, 5)\n * console.log(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 (isOutOfBounds(i, out)) {\n return out\n }\n out.splice(i, 1)\n return out\n})\n\n/**\n * Delete 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 * as assert from \"node:assert\"\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.removeOption(numbers, 2)\n * assert.deepStrictEqual(result, Option.some([1, 2, 4]))\n *\n * const outOfBoundsResult = Array.removeOption(numbers, 5)\n * assert.deepStrictEqual(outOfBoundsResult, Option.none())\n * ```\n *\n * @since 3.16.0\n */\nexport const removeOption: {\n /**\n * Delete 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 * as assert from \"node:assert\"\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.removeOption(numbers, 2)\n * assert.deepStrictEqual(result, Option.some([1, 2, 4]))\n *\n * const outOfBoundsResult = Array.removeOption(numbers, 5)\n * assert.deepStrictEqual(outOfBoundsResult, Option.none())\n * ```\n *\n * @since 3.16.0\n */\n (i: number): <A>(self: Iterable<A>) => Option.Option<Array<A>>\n /**\n * Delete 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 * as assert from \"node:assert\"\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.removeOption(numbers, 2)\n * assert.deepStrictEqual(result, Option.some([1, 2, 4]))\n *\n * const outOfBoundsResult = Array.removeOption(numbers, 5)\n * assert.deepStrictEqual(outOfBoundsResult, Option.none())\n * ```\n *\n * @since 3.16.0\n */\n <A>(self: Iterable<A>, i: number): Option.Option<Array<A>>\n} = dual(2, <A>(self: Iterable<A>, i: number): Option.Option<Array<A>> => {\n const arr = fromIterable(self)\n if (isOutOfBounds(i, arr)) {\n return Option.none()\n }\n const out = Array.isArray(self) ? self.slice() : arr\n out.splice(i, 1)\n return Option.some(out)\n})\n\n/**\n * Reverse an `Iterable`, creating a new `Array`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.reverse([1, 2, 3, 4])\n * console.log(result) // [4, 3, 2, 1]\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const reverse = <S extends Iterable<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>(O: Order.Order<B>): <A extends B, S extends 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 *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.sortWith([\"aaa\", \"b\", \"cc\"], (s) => s.length, Order.number)\n * console.log(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 *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.sortWith([\"aaa\", \"b\", \"cc\"], (s) => s.length, Order.number)\n * console.log(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>, B>(f: (a: ReadonlyArray.Infer<S>) => B, order: Order.Order<B>): (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 *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.sortWith([\"aaa\", \"b\", \"cc\"], (s) => s.length, Order.number)\n * console.log(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 *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.sortWith([\"aaa\", \"b\", \"cc\"], (s) => s.length, Order.number)\n * console.log(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, b)).map(([_]) => _)\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 *\n * ```ts\n * import { Array, Order, pipe } 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 = pipe(\n * users,\n * 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 * )\n * )\n *\n * console.log(result)\n * // [\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>>(\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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zip([1, 2, 3], ['a', 'b'])\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zip([1, 2, 3], ['a', 'b'])\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zip([1, 2, 3], ['a', 'b'])\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zip([1, 2, 3], ['a', 'b'])\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zip([1, 2, 3], ['a', 'b'])\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zipWith([1, 2, 3], [4, 5, 6], (a, b) => a + b)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zipWith([1, 2, 3], [4, 5, 6], (a, b) => a + b)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zipWith([1, 2, 3], [4, 5, 6], (a, b) => a + b)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zipWith([1, 2, 3], [4, 5, 6], (a, b) => a + b)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zipWith([1, 2, 3], [4, 5, 6], (a, b) => a + b)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.unzip([[1, \"a\"], [2, \"b\"], [3, \"c\"]])\n * console.log(result) // [[1, 2, 3], ['a', 'b', 'c']]\n * ```\n *\n * @since 2.0.0\n */\nexport const unzip: <S extends Iterable<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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.intersperse([1, 2, 3], 0)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.intersperse([1, 2, 3], 0)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.intersperse([1, 2, 3], 0)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.intersperse([1, 2, 3], 0)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyHead([1, 2, 3], n => n * 10)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyHead([1, 2, 3], n => n * 10)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyHead([1, 2, 3], n => n * 10)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyHead([1, 2, 3], 10)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyHead([1, 2, 3], 10)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyHead([1, 2, 3], 10)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyLast([1, 2, 3], n => n * 2)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyLast([1, 2, 3], n => n * 2)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyLast([1, 2, 3], n => n * 2)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyLast([1, 2, 3], 4)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyLast([1, 2, 3], 4)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyLast([1, 2, 3], 4)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.rotate(['a', 'b', 'c', 'd'], 2)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.rotate(['a', 'b', 'c', 'd'], 2)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.rotate(['a', 'b', 'c', 'd'], 2)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.rotate(['a', 'b', 'c', 'd'], 2)\n * console.log(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 (isOutOfBounds(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 *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const isEquivalent = (a: number, b: number) => a === b\n * const containsNumber = Array.containsWith(isEquivalent)\n * const result = pipe([1, 2, 3, 4], containsNumber(3))\n * console.log(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 *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const result = pipe(['a', 'b', 'c', 'd'], Array.contains('c'))\n * console.log(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 *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const result = pipe(['a', 'b', 'c', 'd'], Array.contains('c'))\n * console.log(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 *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const result = pipe(['a', 'b', 'c', 'd'], Array.contains('c'))\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.chop([1, 2, 3, 4, 5], (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.chop([1, 2, 3, 4, 5], (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.chop([1, 2, 3, 4, 5], (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.chop([1, 2, 3, 4, 5], (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * console.log(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 (internalArray.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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitAt([1, 2, 3, 4, 5], 3)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitAt([1, 2, 3, 4, 5], 3)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitAt([1, 2, 3, 4, 5], 3)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitNonEmptyAt([\"a\", \"b\", \"c\", \"d\", \"e\"], 3)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitNonEmptyAt([\"a\", \"b\", \"c\", \"d\", \"e\"], 3)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitNonEmptyAt([\"a\", \"b\", \"c\", \"d\", \"e\"], 3)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.split([1, 2, 3, 4, 5, 6, 7, 8], 3)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.split([1, 2, 3, 4, 5, 6, 7, 8], 3)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.split([1, 2, 3, 4, 5, 6, 7, 8], 3)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitWhere([1, 2, 3, 4, 5], n => n > 3)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitWhere([1, 2, 3, 4, 5], n => n > 3)\n * console.log(result) // [[1, 2, 3], [4, 5]]\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitWhere([1, 2, 3, 4, 5], n => n > 3)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.copy([1, 2, 3])\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\nexport const copy: {\n /**\n * Copies an array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.copy([1, 2, 3])\n * console.log(result) // [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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.copy([1, 2, 3])\n * console.log(result) // [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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.pad([1, 2, 3], 6, 0)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.pad([1, 2, 3], 6, 0)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.pad([1, 2, 3], 6, 0)\n * console.log(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 skip-type-checking\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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.chunksOf([1, 2, 3, 4, 5], 2)\n * console.log(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 skip-type-checking\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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.chunksOf([1, 2, 3, 4, 5], 2)\n * console.log(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 skip-type-checking\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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.chunksOf([1, 2, 3, 4, 5], 2)\n * console.log(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 skip-type-checking\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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.chunksOf([1, 2, 3, 4, 5], 2)\n * console.log(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 * Creates sliding windows of size `n` from an `Iterable`.\n * If the number of elements is less than `n` or if `n` is not greater than zero,\n * an empty array is returned.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * assert.deepStrictEqual(Array.window(numbers, 3), [[1, 2, 3], [2, 3, 4], [3, 4, 5]])\n * assert.deepStrictEqual(Array.window(numbers, 6), [])\n * ```\n *\n * @category splitting\n * @since 3.13.2\n */\nexport const window: {\n /**\n * Creates sliding windows of size `n` from an `Iterable`.\n * If the number of elements is less than `n` or if `n` is not greater than zero,\n * an empty array is returned.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * assert.deepStrictEqual(Array.window(numbers, 3), [[1, 2, 3], [2, 3, 4], [3, 4, 5]])\n * assert.deepStrictEqual(Array.window(numbers, 6), [])\n * ```\n *\n * @category splitting\n * @since 3.13.2\n */\n (n: number): <A>(self: Iterable<A>) => Array<Array<A>>\n /**\n * Creates sliding windows of size `n` from an `Iterable`.\n * If the number of elements is less than `n` or if `n` is not greater than zero,\n * an empty array is returned.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * assert.deepStrictEqual(Array.window(numbers, 3), [[1, 2, 3], [2, 3, 4], [3, 4, 5]])\n * assert.deepStrictEqual(Array.window(numbers, 6), [])\n * ```\n *\n * @category splitting\n * @since 3.13.2\n */\n <A>(self: Iterable<A>, n: number): Array<Array<A>>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<Array<A>> => {\n const input = fromIterable(self)\n if (n > 0 && isNonEmptyReadonlyArray(input)) {\n return Array.from(\n { length: input.length - (n - 1) },\n (_, index) => input.slice(index, index + n)\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 *\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 * console.log(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 *\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 * console.log(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 *\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 * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.group([1, 1, 2, 2, 2, 3, 1])\n * console.log(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 *\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 *\n * const result = Array.groupBy(people, person => person.group)\n * console.log(result)\n * // {\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 *\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 *\n * const result = Array.groupBy(people, person => person.group)\n * console.log(result)\n * // {\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>(f: (a: A) => K): (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 *\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 *\n * const result = Array.groupBy(people, person => person.group)\n * console.log(result)\n * // {\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>(self: Iterable<A>, f: (a: A) => K): 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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const union = Array.unionWith([1, 2], [2, 3], (a, b) => a === b)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const union = Array.unionWith([1, 2], [2, 3], (a, b) => a === b)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const union = Array.unionWith([1, 2], [2, 3], (a, b) => a === b)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const union = Array.unionWith([1, 2], [2, 3], (a, b) => a === b)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const union = Array.unionWith([1, 2], [2, 3], (a, b) => a === b)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.union([1, 2], [2, 3])\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.union([1, 2], [2, 3])\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.union([1, 2], [2, 3])\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.union([1, 2], [2, 3])\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.union([1, 2], [2, 3])\n * console.log(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 *\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 * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.intersection([1, 2, 3], [3, 4, 1])\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.intersection([1, 2, 3], [3, 4, 1])\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.intersection([1, 2, 3], [3, 4, 1])\n * console.log(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 *\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 * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const difference = Array.difference([1, 2, 3], [2, 3, 4])\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const difference = Array.difference([1, 2, 3], [2, 3, 4])\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const difference = Array.difference([1, 2, 3], [2, 3, 4])\n * console.log(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>(f: (a: ReadonlyArray.Infer<S>, i: number) => B): (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>>(f: (a: ReadonlyArray.Infer<S>, i: number) => T): (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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.flatten([[1, 2], [], [3, 4], [], [5, 6]])\n * console.log(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 *\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none()\n *\n * const result = Array.filterMap([1, 2, 3, 4, 5], evenSquares);\n * console.log(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 *\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none()\n *\n * const result = Array.filterMap([1, 2, 3, 4, 5], evenSquares);\n * console.log(result) // [4, 16]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(f: (a: A, i: number) => Option.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 *\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none()\n *\n * const result = Array.filterMap([1, 2, 3, 4, 5], evenSquares);\n * console.log(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.Option<B>): Array<B>\n} = dual(\n 2,\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option.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 (Option.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 *\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none()\n *\n * const result = Array.filterMapWhile([2, 4, 5], toSquareTillOdd)\n * console.log(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 *\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none()\n *\n * const result = Array.filterMapWhile([2, 4, 5], toSquareTillOdd)\n * console.log(result) // [4, 16]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(f: (a: A, i: number) => Option.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 *\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none()\n *\n * const result = Array.filterMapWhile([2, 4, 5], toSquareTillOdd)\n * console.log(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.Option<B>): Array<B>\n} = dual(2, <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option.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 (Option.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 *\n * ```ts\n * import { Array, Either } from \"effect\";\n *\n * const isEven = (x: number) => x % 2 === 0\n *\n * const result = Array.partitionMap([1, 2, 3, 4, 5], x =>\n * isEven(x) ? Either.right(x) : Either.left(x)\n * )\n * console.log(result)\n * // [\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 *\n * ```ts\n * import { Array, Either } from \"effect\";\n *\n * const isEven = (x: number) => x % 2 === 0\n *\n * const result = Array.partitionMap([1, 2, 3, 4, 5], x =>\n * isEven(x) ? Either.right(x) : Either.left(x)\n * )\n * console.log(result)\n * // [\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) => Either.Either<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 *\n * ```ts\n * import { Array, Either } from \"effect\";\n *\n * const isEven = (x: number) => x % 2 === 0\n *\n * const result = Array.partitionMap([1, 2, 3, 4, 5], x =>\n * isEven(x) ? Either.right(x) : Either.left(x)\n * )\n * console.log(result)\n * // [\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) => Either.Either<C, B>): [left: Array<B>, right: Array<C>]\n} = dual(\n 2,\n <A, B, C>(self: Iterable<A>, f: (a: A, i: number) => Either.Either<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 (Either.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 *\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const result = Array.getSomes([Option.some(1), Option.none(), Option.some(2)])\n * console.log(result) // [1, 2]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n\nexport const getSomes: <T extends Iterable<Option.Option<X>>, X = any>(\n self: T\n) => Array<Option.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 *\n * ```ts\n * import { Array, Either } from \"effect\"\n *\n * const result = Array.getLefts([Either.right(1), Either.left(\"err\"), Either.right(2)])\n * console.log(result) // [\"err\"]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const getLefts = <T extends Iterable<Either.Either<any, any>>>(\n self: T\n): Array<Either.Either.Left<ReadonlyArray.Infer<T>>> => {\n const out: Array<any> = []\n for (const a of self) {\n if (Either.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 *\n * ```ts\n * import { Array, Either } from \"effect\"\n *\n * const result = Array.getRights([Either.right(1), Either.left(\"err\"), Either.right(2)])\n * console.log(result) // [1, 2]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const getRights = <T extends Iterable<Either.Either<any, any>>>(\n self: T\n): Array<Either.Either.Right<ReadonlyArray.Infer<T>>> => {\n const out: Array<any> = []\n for (const a of self) {\n if (Either.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 * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.partition([1, 2, 3, 4], n => n % 2 === 0)\n * console.log(result) // [[1, 3], [2, 4]]\n * ```\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 * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.partition([1, 2, 3, 4], n => n % 2 === 0)\n * console.log(result) // [[1, 3], [2, 4]]\n * ```\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 * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.partition([1, 2, 3, 4], n => n % 2 === 0)\n * console.log(result) // [[1, 3], [2, 4]]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (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 * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.partition([1, 2, 3, 4], n => n % 2 === 0)\n * console.log(result) // [[1, 3], [2, 4]]\n * ```\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): [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 * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.partition([1, 2, 3, 4], n => n % 2 === 0)\n * console.log(result) // [[1, 3], [2, 4]]\n * ```\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 * @category filtering\n * @since 2.0.0\n */\nexport const separate: <T extends Iterable<Either.Either<any, any>>>(\n self: T\n) => [Array<Either.Either.Left<ReadonlyArray.Infer<T>>>, Array<Either.Either.Right<ReadonlyArray.Infer<T>>>] =\n partitionMap(identity)\n\n/**\n * Reduces an array from the left.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.reduce([1, 2, 3], 0, (acc, n) => acc + n)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.reduce([1, 2, 3], 0, (acc, n) => acc + n)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.reduce([1, 2, 3], 0, (acc, n) => acc + n)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.reduceRight([1, 2, 3], 0, (acc, n) => acc + n)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.reduceRight([1, 2, 3], 0, (acc, n) => acc + n)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.reduceRight([1, 2, 3], 0, (acc, n) => acc + n)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n * const to = Array.liftPredicate(isEven)\n * console.log(to(1)) // []\n * console.log(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: Predicate.Refinement<A, B>): (a: A) => Array<B>\n /**\n * Lifts a predicate into an array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n * const to = Array.liftPredicate(isEven)\n * console.log(to(1)) // []\n * console.log(to(2)) // [2]\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\n <A>(predicate: Predicate.Predicate<A>): <B extends A>(b: B) => Array<B>\n} = <A>(predicate: 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.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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.flatMapNullable([1, 2, 3], n => (n % 2 === 0 ? null : n))\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.flatMapNullable([1, 2, 3], n => (n % 2 === 0 ? null : n))\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.flatMapNullable([1, 2, 3], n => (n % 2 === 0 ? null : n))\n * console.log(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 *\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 * console.log(result1) // [42]\n *\n * const result2 = liftedParseNumber(\"not a number\")\n * console.log(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) => Either.Either<B, E>\n) =>\n(...a: A): Array<B> => {\n const e = f(...a)\n return Either.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>(refinement: (a: NoInfer<A>, i: number) => a is B): (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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.extend([1, 2, 3], as => as.length)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.extend([1, 2, 3], as => as.length)\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.extend([1, 2, 3], as => as.length)\n * console.log(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 *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.min([3, 1, 2], Order.number)\n * console.log(result) // 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 *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.min([3, 1, 2], Order.number)\n * console.log(result) // 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 *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.min([3, 1, 2], Order.number)\n * console.log(result) // 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 *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.max([3, 1, 2], Order.number)\n * console.log(result) // 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 *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.max([3, 1, 2], Order.number)\n * console.log(result) // 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 *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.max([3, 1, 2], Order.number)\n * console.log(result) // 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.Option<readonly [A, B]>): Array<A> => {\n const out: Array<A> = []\n let next: B = b\n let o: Option.Option<readonly [A, B]>\n while (Option.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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const eq = Array.getEquivalence<number>((a, b) => a === b)\n * console.log(eq([1, 2, 3], [1, 2, 3])) // 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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * Array.forEach([1, 2, 3], 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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * Array.forEach([1, 2, 3], 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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * Array.forEach([1, 2, 3], 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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dedupeWith([1, 2, 2, 3, 3, 3], (a, b) => a === b)\n * console.log(result) // [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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dedupeWith([1, 2, 2, 3, 3, 3], (a, b) => a === b)\n * console.log(result) // [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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dedupeWith([1, 2, 2, 3, 3, 3], (a, b) => a === b)\n * console.log(result) // [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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dedupeWith([1, 2, 2, 3, 3, 3], (a, b) => a === b)\n * console.log(result) // [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>>(\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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dedupeAdjacentWith([1, 1, 2, 2, 3, 3], (a, b) => a === b)\n * console.log(result) // [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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dedupeAdjacentWith([1, 1, 2, 2, 3, 3], (a, b) => a === b)\n * console.log(result) // [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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dedupeAdjacentWith([1, 1, 2, 2, 3, 3], (a, b) => a === b)\n * console.log(result) // [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: Option.Option<A> = Option.none()\n for (const a of self) {\n if (Option.isNone(lastA) || !isEquivalent(a, lastA.value)) {\n out.push(a)\n lastA = Option.some(a)\n }\n }\n return out\n})\n\n/**\n * Deduplicates adjacent elements that are identical.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dedupeAdjacent([1, 1, 2, 2, 3, 3])\n * console.log(result) // [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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const strings = [\"a\", \"b\", \"c\"]\n * const joined = Array.join(strings, \"-\")\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const strings = [\"a\", \"b\", \"c\"]\n * const joined = Array.join(strings, \"-\")\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const strings = [\"a\", \"b\", \"c\"]\n * const joined = Array.join(strings, \"-\")\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.mapAccum([1, 2, 3], 0, (acc, n) => [acc + n, acc + n])\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.mapAccum([1, 2, 3], 0, (acc, n) => [acc + n, acc + n])\n * console.log(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>>(s: S, f: (s: S, a: ReadonlyArray.Infer<I>, i: number) => readonly [S, B]): (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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.mapAccum([1, 2, 3], 0, (acc, n) => [acc + n, acc + n])\n * console.log(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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.cartesianWith([1, 2], [\"a\", \"b\"], (a, b) => `${a}-${b}`)\n * console.log(result) // [\"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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.cartesianWith([1, 2], [\"a\", \"b\"], (a, b) => `${a}-${b}`)\n * console.log(result) // [\"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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.cartesianWith([1, 2], [\"a\", \"b\"], (a, b) => `${a}-${b}`)\n * console.log(result) // [\"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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.cartesian([1, 2], [\"a\", \"b\"])\n * console.log(result) // [[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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.cartesian([1, 2], [\"a\", \"b\"])\n * console.log(result) // [[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 *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.cartesian([1, 2], [\"a\", \"b\"])\n * console.log(result) // [[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 * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const doResult = pipe(\n * Array.Do,\n * Array.bind(\"x\", () => [1, 3, 5]),\n * Array.bind(\"y\", () => [2, 4, 6]),\n * Array.filter(({ x, y }) => x < y), // condition\n * Array.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * console.log(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 * @see {@link bindTo}\n * @see {@link bind}\n * @see {@link let_ let}\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 * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const doResult = pipe(\n * Array.Do,\n * Array.bind(\"x\", () => [1, 3, 5]),\n * Array.bind(\"y\", () => [2, 4, 6]),\n * Array.filter(({ x, y }) => x < y), // condition\n * Array.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * console.log(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 * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\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 * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const doResult = pipe(\n * Array.Do,\n * Array.bind(\"x\", () => [1, 3, 5]),\n * Array.bind(\"y\", () => [2, 4, 6]),\n * Array.filter(({ x, y }) => x < y), // condition\n * Array.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * console.log(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 * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\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 * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const doResult = pipe(\n * Array.Do,\n * Array.bind(\"x\", () => [1, 3, 5]),\n * Array.bind(\"y\", () => [2, 4, 6]),\n * Array.filter(({ x, y }) => x < y), // condition\n * Array.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * console.log(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 * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\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} = internalDoNotation.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 * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const doResult = pipe(\n * Array.Do,\n * Array.bind(\"x\", () => [1, 3, 5]),\n * Array.bind(\"y\", () => [2, 4, 6]),\n * Array.filter(({ x, y }) => x < y), // condition\n * Array.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * console.log(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 * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\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 * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const doResult = pipe(\n * Array.Do,\n * Array.bind(\"x\", () => [1, 3, 5]),\n * Array.bind(\"y\", () => [2, 4, 6]),\n * Array.filter(({ x, y }) => x < y), // condition\n * Array.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * console.log(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 * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\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 * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const doResult = pipe(\n * Array.Do,\n * Array.bind(\"x\", () => [1, 3, 5]),\n * Array.bind(\"y\", () => [2, 4, 6]),\n * Array.filter(({ x, y }) => x < y), // condition\n * Array.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * console.log(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 * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\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} = internalDoNotation.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} = internalDoNotation.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 * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const doResult = pipe(\n * Array.Do,\n * Array.bind(\"x\", () => [1, 3, 5]),\n * Array.bind(\"y\", () => [2, 4, 6]),\n * Array.filter(({ x, y }) => x < y), // condition\n * Array.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * console.log(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 *\n * @see {@link bindTo}\n * @see {@link bind}\n * @see {@link Do}\n *\n * @category do notation\n * @since 3.2.0\n */\n let_ as let\n}\n","import * as Either from \"effect/Either\"\nimport { dual } from \"effect/Function\"\nimport type { TypeLambda } from \"effect/HKT\"\nimport * as Option from \"effect/Option\"\nimport * as Gen from \"effect/Utils\"\n\nconst NanoInternalSuccessProto = {\n _tag: \"Right\"\n}\n\ninterface NanoInternalSuccess<A> {\n _tag: \"Right\"\n value: A\n}\n\nfunction makeInternalSuccess<A>(value: A): NanoInternalResult<A, never> {\n const result = Object.create(NanoInternalSuccessProto)\n result.value = value\n return result\n}\n\nconst NanoInternalFailureProto = {\n _tag: \"Left\"\n}\n\ninterface NanoInternalFailure<E> {\n _tag: \"Left\"\n value: E\n}\n\nfunction makeInternalFailure<E>(value: E): NanoInternalResult<never, E> {\n const result = Object.create(NanoInternalFailureProto)\n result.value = value\n return result\n}\n\nconst NanoInternalDefectProto = {\n _tag: \"Defect\"\n}\n\ninterface NanoInternalDefect {\n _tag: \"Defect\"\n value: unknown\n}\n\nfunction makeInternalDefect(value: unknown): NanoInternalResult<never, never> {\n const result = Object.create(NanoInternalDefectProto)\n result.value = value\n return result\n}\n\ntype NanoInternalResult<A, E> =\n | NanoInternalSuccess<A>\n | NanoInternalFailure<E>\n | NanoInternalDefect\n\nexport class NanoDefectException {\n readonly _tag = \"@effect/language-service/NanoDefectException\"\n constructor(\n readonly message: unknown\n ) {}\n}\n\nexport class NanoTag<R> {\n declare \"~nano.requirements\": R\n constructor(\n readonly key: string\n ) {}\n}\n\nexport const Tag = <I = never>(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\n\nexport interface NanoIterator<T extends Nano<any, any, any>> {\n next(...args: ReadonlyArray<any>): IteratorResult<Gen.YieldWrap<T>, T[\"~nano.success\"]>\n}\n\nexport interface NanoTypeLambda extends TypeLambda {\n readonly type: Nano<this[\"Target\"], this[\"Out1\"], this[\"Out2\"]>\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 interface Nano<out A = never, out E = never, out R = never> {\n readonly \"~nano.success\": A\n readonly \"~nano.error\": E\n readonly \"~nano.requirements\": R\n [Symbol.iterator](): NanoIterator<Nano<A, E, R>>\n run: (\n ctx: NanoContext<unknown>\n ) => NanoInternalResult<A, E>\n}\n\nconst Proto = {\n run: () => {},\n\n [Symbol.iterator]() {\n return new Gen.SingleShotGen(new Gen.YieldWrap(this))\n }\n}\n\nfunction make<A, E, R>(\n run: (\n ctx: NanoContext<unknown>\n ) => NanoInternalResult<A, E>\n): Nano<A, E, R> {\n const result = Object.create(Proto)\n result.run = run\n return result\n}\n\nexport const unsafeRun = <A, E>(\n fa: Nano<A, E, never>\n): Either.Either<A, E | NanoDefectException> => {\n const result = fa.run(contextEmpty)\n switch (result._tag) {\n case \"Left\":\n return Either.left(result.value)\n case \"Defect\":\n return Either.left(new NanoDefectException(result.value))\n case \"Right\":\n return Either.right(result.value)\n }\n}\n\nexport const run = <A, E>(fa: Nano<A, E, never>): Either.Either<A, E | NanoDefectException> => {\n try {\n return unsafeRun(fa)\n } catch (e) {\n return Either.left(new NanoDefectException(e))\n }\n}\n\nexport const succeed = <A>(value: A) => make<A, never, never>(() => makeInternalSuccess(value))\nexport const fail = <E>(value: E) => make<never, E, never>(() => makeInternalFailure(value))\nexport const sync = <A>(value: () => A) => make<A, never, never>(() => makeInternalSuccess(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 make<B, E | E2, R | R2>((ctx) => {\n const result = fa.run(ctx)\n if (result._tag !== \"Right\") return result\n return f(result.value).run(ctx)\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 make<B, E, R>((ctx) => {\n const result = fa.run(ctx)\n if (result._tag !== \"Right\") return result\n return makeInternalSuccess(f(result.value))\n }))\n\nexport const orElse = <E, B, E2, R2>(\n f: (e: E) => Nano<B, E2, R2>\n) =>\n<A, R>(fa: Nano<A, E, R>) =>\n make<A | B, E2, R | R2>((ctx) => {\n const result = fa.run(ctx)\n if (result._tag === \"Left\") return f(result.value).run(ctx)\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 arr.slice(1).reduce((arr, fa) => orElse(() => fa)(arr), arr[0])\n\nexport const service = <I extends NanoTag<any>>(tag: I) =>\n make<I[\"~nano.requirements\"], never, I[\"~nano.requirements\"]>((ctx) =>\n (tag.key in ctx.value)\n ? makeInternalSuccess(ctx.value[tag.key])\n : makeInternalDefect(`Cannot find service ${tag.key}`)\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 make<A, E, Exclude<R, I[\"~nano.requirements\"]>>((ctx) => {\n return fa.run({\n ...ctx,\n value: {\n ...ctx.value,\n [tag.key]: value\n }\n })\n })\n\nexport const gen = <Eff extends Gen.YieldWrap<Nano<any, any, any>>, AEff>(\n ...args: [body: () => Generator<Eff, AEff, never>]\n) =>\n make<\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: NanoInternalResult<any, any> = current.run(ctx)\n if (result._tag !== \"Right\") {\n return result\n }\n state = iterator.next(result.value as never)\n }\n return makeInternalSuccess(state.value)\n })\n\nexport const fn = (_: string) =>\n<Eff extends Gen.YieldWrap<Nano<any, any, any>>, AEff, Args extends Array<any>>(\n body: (...args: Args) => Generator<Eff, AEff, never>\n) =>\n(...args: Args) => (\n make<\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 = body(...args)\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: NanoInternalResult<any, any> = current.run(ctx)\n if (result._tag !== \"Right\") {\n return result\n }\n state = iterator.next(result.value as never)\n }\n return makeInternalSuccess(state.value)\n })\n)\n\nexport const option = <A, E, R>(fa: Nano<A, E, R>) =>\n make<Option.Option<A>, never, R>((ctx) => {\n const result = fa.run(ctx)\n switch (result._tag) {\n case \"Right\":\n return makeInternalSuccess(Option.some(result.value))\n case \"Left\":\n return makeInternalSuccess(Option.none())\n case \"Defect\":\n return result\n }\n })\n\nexport const all = <A extends Array<Nano<any, any, any>>>(\n ...args: A\n): Nano<\n Array<A[number][\"~nano.success\"]>,\n A[number][\"~nano.error\"],\n A[number][\"~nano.requirements\"]\n> =>\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\nconst timings: Record<string, number> = {}\nconst timingsCount: Record<string, number> = {}\nexport const timed = (timingName: string) => <A, E, R>(fa: Nano<A, E, R>) =>\n make<A, E, R>((ctx) => {\n const start = performance.now()\n const result = fa.run(ctx)\n const end = performance.now()\n const duration = end - start\n timings[timingName] = (timings[timingName] || 0) + duration\n timingsCount[timingName] = (timingsCount[timingName] || 0) + 1\n return result\n })\n\nexport const getTimings = () => {\n const result: Array<[name: string, avg: number, hits: number, total: number]> = []\n for (const key in timings) {\n result.push([key, timings[key] / (timingsCount[key] || 1), timingsCount[key], timings[key]])\n }\n result.sort((a, b) => b[3] - a[3])\n const lines: Array<string> = []\n for (const [name, avg, hits, total] of result) {\n lines.push(\n `${name.padEnd(75)} tot ${total.toFixed(2).padStart(10)}ms avg ${avg.toFixed(2).padStart(10)}ms ${\n hits.toString().padStart(10)\n } hits`\n )\n }\n return lines\n}\n","import { isArray } from \"effect/Array\"\nimport { hasProperty, isBoolean, isObject, isString } from \"effect/Predicate\"\nimport * as Nano from \"./Nano\"\n\nexport interface LanguageServicePluginOptions {\n diagnostics: boolean\n quickinfo: boolean\n completions: boolean\n allowedDuplicatedPackages: Array<string>\n}\n\nexport const LanguageServicePluginOptions = Nano.Tag<LanguageServicePluginOptions>(\"PluginOptions\")\n\nexport function parse(config: any): LanguageServicePluginOptions {\n return {\n diagnostics: isObject(config) && hasProperty(config, \"diagnostics\") && isBoolean(config.diagnostics)\n ? config.diagnostics\n : true,\n quickinfo: isObject(config) && hasProperty(config, \"quickinfo\") && isBoolean(config.quickinfo)\n ? config.quickinfo\n : true,\n completions: isObject(config) && hasProperty(config, \"completions\") && isBoolean(config.completions)\n ? config.completions\n : true,\n allowedDuplicatedPackages: isObject(config) && hasProperty(config, \"allowedDuplicatedPackages\") &&\n isArray(config.allowedDuplicatedPackages) && config.allowedDuplicatedPackages.every(isString)\n ? config.allowedDuplicatedPackages.map((_) => _.toLowerCase())\n : []\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 insertCommentBeforeLine(\n sourceFile: ts.SourceFile,\n lineNumber: number,\n position: number,\n commentText: string\n ): 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 {}\nexport const TypeScriptApi = Nano.Tag<TypeScriptApi>(\"TypeScriptApi\")\n\ntype _TypeScriptProgram = ts.Program\nexport interface TypeScriptProgram extends _TypeScriptProgram {}\nexport const TypeScriptProgram = Nano.Tag<TypeScriptProgram>(\"TypeScriptProgram\")\n\nexport const ChangeTracker = Nano.Tag<ts.textChanges.ChangeTracker>(\"ChangeTracker\")\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport type * as TypeCheckerApi from \"../core/TypeCheckerApi.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport type * as LanguageServicePluginOptions from \"./LanguageServicePluginOptions.js\"\nimport * as Nano from \"./Nano.js\"\n\nexport class RefactorNotApplicableError {\n readonly _tag = \"@effect/language-service/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\n | TypeCheckerApi.TypeCheckerApi\n | LanguageServicePluginOptions.LanguageServicePluginOptions\n | TypeCheckerApi.TypeCheckerApiCache\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): 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\n | LanguageServicePluginOptions.LanguageServicePluginOptions\n | TypeScriptApi.TypeScriptApi\n | TypeCheckerApi.TypeCheckerApiCache\n | TypeScriptApi.TypeScriptProgram\n >\n}\n\nexport interface ApplicableDiagnosticDefinition {\n node: ts.Node\n category: ts.DiagnosticCategory\n messageText: string\n fixes: Array<ApplicableDiagnosticDefinitionFix>\n}\n\nexport interface ApplicableDiagnosticDefinitionFix {\n fixName: string\n description: string\n apply: Nano.Nano<void, never, ts.textChanges.ChangeTracker>\n}\n\nexport interface ApplicableDiagnosticDefinitionFixWithPositionAndCode extends ApplicableDiagnosticDefinitionFix {\n code: number\n start: number\n end: number\n}\n\nexport function createDiagnostic(definition: DiagnosticDefinition): DiagnosticDefinition {\n return definition\n}\n\nexport interface CompletionDefinition {\n name: string\n apply: (\n sourceFile: ts.SourceFile,\n position: number,\n options: ts.GetCompletionsAtPositionOptions | undefined,\n formatCodeSettings: ts.FormatCodeSettings | undefined\n ) => Nano.Nano<\n Array<CompletionEntryDefinition>,\n never,\n | TypeCheckerApi.TypeCheckerApi\n | LanguageServicePluginOptions.LanguageServicePluginOptions\n | TypeScriptApi.TypeScriptApi\n | TypeCheckerApi.TypeCheckerApiCache\n | TypeScriptApi.TypeScriptProgram\n >\n}\n\nexport interface CompletionEntryDefinition {\n name: string\n kind: ts.ScriptElementKind\n insertText: string\n isSnippet: true\n replacementSpan: ts.TextSpan\n}\n\nexport function createCompletion(definition: CompletionDefinition): CompletionDefinition {\n return definition\n}\n\nexport class SourceFileNotFoundError {\n readonly _tag = \"@effect/language-service/SourceFileNotFoundError\"\n constructor(\n readonly fileName: string\n ) {}\n}\n\nexport const getSemanticDiagnosticsWithCodeFixes = Nano.fn(\n \"LSP.getSemanticDiagnosticsWithCodeFixes\"\n)(function*(\n rules: Array<DiagnosticDefinition>,\n sourceFile: ts.SourceFile\n) {\n let effectDiagnostics: Array<ts.Diagnostic> = []\n let effectCodeFixes: Array<ApplicableDiagnosticDefinitionFixWithPositionAndCode> = []\n const executor = yield* createDiagnosticExecutor(sourceFile)\n for (const rule of rules) {\n const result = yield* (\n Nano.option(executor.execute(rule))\n )\n if (Option.isSome(result)) {\n effectDiagnostics = effectDiagnostics.concat(\n pipe(\n result.value,\n ReadonlyArray.map((_) => ({\n file: sourceFile,\n start: _.node.getStart(sourceFile),\n length: _.node.getEnd() - _.node.getStart(sourceFile),\n messageText: _.messageText,\n category: _.category,\n code: rule.code,\n source: \"effect\"\n }))\n )\n )\n effectCodeFixes = effectCodeFixes.concat(\n pipe(\n result.value,\n ReadonlyArray.map((_) =>\n ReadonlyArray.map(\n _.fixes,\n (fix) => ({\n ...fix,\n code: rule.code,\n start: _.node.getStart(sourceFile),\n end: _.node.getEnd()\n })\n )\n ),\n ReadonlyArray.flatten\n )\n )\n }\n }\n\n return ({\n diagnostics: effectDiagnostics,\n codeFixes: effectCodeFixes\n })\n})\n\nfunction refactorNameToFullyQualifiedName(name: string) {\n return `@effect/language-service/refactors/${name}`\n}\n\nexport const getApplicableRefactors = Nano.fn(\"LSP.getApplicableRefactors\")(function*(\n refactors: Array<RefactorDefinition>,\n sourceFile: ts.SourceFile,\n positionOrRange: number | ts.TextRange\n) {\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: refactorNameToFullyQualifiedName(refactor.name),\n description: refactor.description,\n actions: [{\n name: refactorNameToFullyQualifiedName(refactor.name),\n description: result.value.description,\n kind: result.value.kind\n }]\n })\n }\n }\n return effectRefactors\n})\n\nexport const getEditsForRefactor = Nano.fn(\"LSP.getEditsForRefactor\")(function*(\n refactors: Array<RefactorDefinition>,\n sourceFile: ts.SourceFile,\n positionOrRange: number | ts.TextRange,\n refactorName: string\n) {\n const refactor = refactors.find((refactor) => refactorNameToFullyQualifiedName(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\nexport const getCompletionsAtPosition = Nano.fn(\"LSP.getCompletionsAtPosition\")(function*(\n completions: Array<CompletionDefinition>,\n sourceFile: ts.SourceFile,\n position: number,\n options: ts.GetCompletionsAtPositionOptions | undefined,\n formatCodeSettings: ts.FormatCodeSettings | undefined\n) {\n let effectCompletions: Array<ts.CompletionEntry> = []\n for (const completion of completions) {\n const result = yield* completion.apply(sourceFile, position, options, formatCodeSettings)\n effectCompletions = effectCompletions.concat(\n result.map((_) => ({ sortText: \"11\", ..._ }) satisfies ts.CompletionEntry)\n )\n }\n return effectCompletions\n})\n\nconst createDiagnosticExecutor = Nano.fn(\"LSP.createCommentDirectivesProcessor\")(\n function*(sourceFile: ts.SourceFile) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n function findNodeWithLeadingCommentAtPosition(position: number) {\n const sourceText = sourceFile.text\n let result: ts.Node | undefined\n\n function find(node: ts.Node) {\n // Check leading comments\n const leading = ts.getLeadingCommentRanges(sourceText, node.getFullStart())\n if (leading) {\n for (const r of leading) {\n if (r.pos <= position && position < r.end) {\n // we found the comment\n result = node\n return\n }\n }\n }\n // Continue traversing only if the position is within this node\n if (node.getFullStart() <= position && position < node.getEnd()) {\n node.forEachChild(find)\n }\n }\n find(sourceFile)\n return result\n }\n\n function findParentStatementForDisableNextLine(node: ts.Node) {\n let result: ts.Node | undefined\n\n function find(node: ts.Node) {\n if (ts.isStatement(node)) {\n result = node\n return\n }\n if (result) return\n if (node.parent) find(node.parent)\n }\n find(node)\n return result || node\n }\n\n const lineOverrides: Record<\n string,\n Array<{ pos: number; end: number; level: string }>\n > = {}\n const sectionOverrides: Record<\n string,\n Array<{ pos: number; level: string }>\n > = {}\n const skippedRules: Array<string> = []\n\n const regex =\n /@effect-diagnostics(-next-line)?((?:\\s[a-zA-Z0-9/]+:(?:off|warning|error|message|suggestion|skip-file))+)?/gm\n let match: RegExpExecArray | null\n while ((match = regex.exec(sourceFile.text)) !== null) {\n const nextLineCaptureGroup = match[1]\n const rulesCaptureGroup = match[2]\n\n if (rulesCaptureGroup) {\n const trimmedRuleString = rulesCaptureGroup.trim()\n if (trimmedRuleString) {\n const individualRules = trimmedRuleString.split(/\\s+/)\n for (const rulePair of individualRules) {\n const [rawRuleName, ruleLevel] = rulePair.toLowerCase().split(\":\")\n // NOTE: for backwards compatibility, treat \"effect/ruleName\" same as \"ruleName\"\n const ruleName = rawRuleName.startsWith(\"effect/\")\n ? rawRuleName.substring(\"effect/\".length)\n : rawRuleName\n if (ruleName && ruleLevel) {\n if (ruleLevel === \"skip-file\") skippedRules.push(ruleName)\n const isOverrideNextLine = nextLineCaptureGroup &&\n nextLineCaptureGroup.trim().toLowerCase() === \"-next-line\"\n if (isOverrideNextLine) {\n const node = findNodeWithLeadingCommentAtPosition(match.index)\n if (node) {\n lineOverrides[ruleName] = lineOverrides[ruleName] || []\n lineOverrides[ruleName].unshift({\n pos: node.getFullStart(),\n end: node.end,\n level: ruleLevel\n })\n }\n } else {\n sectionOverrides[ruleName] = sectionOverrides[ruleName] || []\n sectionOverrides[ruleName].unshift({\n pos: match.index,\n level: ruleLevel\n })\n }\n }\n }\n }\n }\n }\n\n const levelToDiagnosticCategory: Record<string, ts.DiagnosticCategory> = {\n error: ts.DiagnosticCategory.Error,\n warning: ts.DiagnosticCategory.Warning,\n message: ts.DiagnosticCategory.Message,\n suggestion: ts.DiagnosticCategory.Suggestion\n }\n\n const execute = Nano.fn(\"LSP.ruleExecutor\")(function*(\n rule: DiagnosticDefinition\n ) {\n const ruleNameLowered = rule.name.toLowerCase()\n // if file is skipped entirely, do not process the rule\n if (skippedRules.indexOf(ruleNameLowered) > -1) return []\n // run the executor\n let modifiedDiagnostics = yield* rule.apply(sourceFile)\n // loop through rules\n for (const emitted of modifiedDiagnostics.slice(0)) {\n let newLevel: string | undefined = undefined\n // early exit, no customizations\n if (!(ruleNameLowered in sectionOverrides || ruleNameLowered in lineOverrides)) continue\n // attempt with line overrides\n const lineOverride = (lineOverrides[ruleNameLowered] || []).find((_) =>\n _.pos < emitted.node.getStart(sourceFile) && _.end >= emitted.node.getEnd()\n )\n if (lineOverride) {\n newLevel = lineOverride.level\n } else {\n // then attempt with section overrides\n const sectionOverride = (sectionOverrides[ruleNameLowered] || []).find((_) =>\n _.pos < emitted.node.getStart(sourceFile)\n )\n if (sectionOverride) newLevel = sectionOverride.level\n }\n if (newLevel === \"off\") {\n // remove from output those in range\n modifiedDiagnostics = modifiedDiagnostics.filter((_) => _ !== emitted)\n } else {\n // change severity\n emitted.category = newLevel && newLevel in levelToDiagnosticCategory\n ? levelToDiagnosticCategory[newLevel]\n : emitted.category\n }\n }\n\n // append a rule fix to disable this check only for next line\n const fixByDisableNextLine = (\n _: ApplicableDiagnosticDefinition\n ): ApplicableDiagnosticDefinitionFix => ({\n fixName: rule.name + \"_skipNextLine\",\n description: \"Disable \" + rule.name + \" for this line\",\n apply: Nano.flatMap(\n Nano.service(TypeScriptApi.ChangeTracker),\n (changeTracker) =>\n Nano.sync(() => {\n const disableAtNode = findParentStatementForDisableNextLine(_.node)\n const { line } = ts.getLineAndCharacterOfPosition(sourceFile, disableAtNode.getStart())\n\n changeTracker.insertCommentBeforeLine(\n sourceFile,\n line,\n disableAtNode.getStart(),\n ` @effect-diagnostics-next-line ${rule.name}:off`\n )\n })\n )\n })\n\n // append a rule fix to disable this check for the entire file\n const fixByDisableEntireFile: ApplicableDiagnosticDefinitionFix = {\n fixName: rule.name + \"_skipFile\",\n description: \"Disable \" + rule.name + \" for this entire file\",\n apply: Nano.flatMap(\n Nano.service(TypeScriptApi.ChangeTracker),\n (changeTracker) =>\n Nano.sync(() =>\n changeTracker.insertText(\n sourceFile,\n 0,\n `/** @effect-diagnostics ${rule.name}:skip-file */\\n`\n )\n )\n )\n }\n\n const rulesWithDisableFix = modifiedDiagnostics.map((diagnostic) => ({\n ...diagnostic,\n fixes: diagnostic.fixes.concat([fixByDisableNextLine(diagnostic), fixByDisableEntireFile])\n }))\n\n return rulesWithDisableFix\n })\n\n return { execute }\n }\n)\n","import * 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 type TypeCheckerApiCache = {\n expectedAndRealType: WeakMap<ts.SourceFile, Array<ExpectedAndRealType>>\n}\nexport const TypeCheckerApiCache = Nano.Tag<TypeCheckerApiCache>(\"TypeCheckerApiCache\")\n\nexport function makeTypeCheckerApiCache(): TypeCheckerApiCache {\n return {\n expectedAndRealType: new WeakMap()\n }\n}\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 const getMissingTypeEntriesInTargetType = Nano.fn(\n \"TypeCheckerApi.getMissingTypeEntriesInTargetType\"\n)(\n function*(realType: ts.Type, expectedType: ts.Type) {\n const typeChecker = yield* Nano.service(TypeCheckerApi)\n\n const result: Array<ts.Type> = []\n let 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 = toTest.concat(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 readonly _tag = \"@effect/language-service/CannotFindAncestorConvertibleDeclarationError\"\n constructor(\n readonly node: ts.Node\n ) {}\n}\n\nconst getAncestorConvertibleDeclaration = Nano.fn(\n \"TypeCheckerApi.getAncestorConvertibleDeclaration\"\n)(function*(node: ts.Node) {\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\nclass CannotInferReturnTypeFromEmptyBody {\n readonly _tag = \"@effect/language-service/CannotInferReturnTypeFromEmptyBody\"\n constructor(\n readonly declaration: ConvertibleDeclaration\n ) {}\n}\n\nclass CannotInferReturnType {\n readonly _tag = \"@effect/language-service/CannotInferReturnType\"\n constructor(\n readonly declaration: ConvertibleDeclaration\n ) {}\n}\n\nexport const getInferredReturnType = Nano.fn(\"TypeCheckerApi.getInferredReturnType\")(function*(\n declaration: ConvertibleDeclaration\n) {\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\ntype ExpectedAndRealType = [\n node: ts.Node,\n expectedType: ts.Type,\n valueNode: ts.Node,\n realType: ts.Type\n]\n\nexport const expectedAndRealType = Nano.fn(\"TypeCheckerApi.expectedAndRealType\")(function*(\n sourceFile: ts.SourceFile\n) {\n const cache = yield* Nano.service(TypeCheckerApiCache)\n const resultCached = cache.expectedAndRealType.get(sourceFile)\n if (resultCached) return resultCached\n\n const typeChecker = yield* Nano.service(TypeCheckerApi)\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const result: Array<ExpectedAndRealType> = []\n\n const nodeToVisit: Array<ts.Node> = [sourceFile]\n const appendNodeToVisit = (node: ts.Node) => {\n nodeToVisit.push(node)\n return undefined\n }\n\n while (nodeToVisit.length > 0) {\n const node = nodeToVisit.shift()!\n\n if (ts.isVariableDeclaration(node) && node.initializer) {\n // const a: Effect<...> = node\n const expectedType = typeChecker.getTypeAtLocation(node.name)\n const realType = typeChecker.getTypeAtLocation(node.initializer)\n result.push([node.name, expectedType, node.initializer, realType])\n appendNodeToVisit(node.initializer)\n continue\n } else if (ts.isCallExpression(node)) {\n // fn(a)\n const resolvedSignature = typeChecker.getResolvedSignature(node)\n if (resolvedSignature) {\n resolvedSignature.getParameters().map((parameter, index) => {\n const expectedType = typeChecker.getTypeOfSymbolAtLocation(parameter, node)\n const realType = typeChecker.getTypeAtLocation(node.arguments[index])\n result.push([\n node.arguments[index] as ts.Node,\n expectedType,\n node.arguments[index],\n realType\n ])\n })\n }\n ts.forEachChild(node, appendNodeToVisit)\n continue\n } else if (\n ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node) ||\n ts.isNoSubstitutionTemplateLiteral(node)\n ) {\n // { key: node } as { key: Effect<...> }\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 result.push([node, expectedType, node, realType])\n }\n }\n }\n }\n ts.forEachChild(node, appendNodeToVisit)\n continue\n } else if (\n ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken\n ) {\n // var a: Effect<...> = node\n const expectedType = typeChecker.getTypeAtLocation(node.left)\n const realType = typeChecker.getTypeAtLocation(node.right)\n result.push([node.left, expectedType, node.right, realType])\n appendNodeToVisit(node.right)\n continue\n } else if (ts.isReturnStatement(node) && node.expression) {\n // function(): Effect<...> { return a }\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)) {\n result.push([node, expectedType.value, node, realType])\n }\n }\n ts.forEachChild(node, appendNodeToVisit)\n continue\n } else if (\n ts.isArrowFunction(node) && (node.typeParameters || []).length === 0 &&\n ts.isExpression(node.body)\n ) {\n // (): Effect<...> => node\n const body = node.body\n const expectedType = typeChecker.getContextualType(body)\n const realType = typeChecker.getTypeAtLocation(body)\n if (expectedType) {\n result.push([body, expectedType, body, realType])\n }\n ts.forEachChild(body, appendNodeToVisit)\n continue\n } else if (\n ts.isArrowFunction(node) && (node.typeParameters || []).length > 0 &&\n ts.isExpression(node.body)\n ) {\n // <A>(): Effect<...> => node\n const body = node.body\n const expectedType = yield* Nano.option(getInferredReturnType(node))\n const realType = typeChecker.getTypeAtLocation(body)\n if (Option.isSome(expectedType)) {\n result.push([body, expectedType.value, body, realType])\n }\n ts.forEachChild(body, appendNodeToVisit)\n continue\n } else if (ts.isSatisfiesExpression(node)) {\n // node as Effect<....>\n const expectedType = typeChecker.getTypeAtLocation(node.type)\n const realType = typeChecker.getTypeAtLocation(node.expression)\n result.push([node.expression as ts.Node, expectedType, node.expression, realType])\n appendNodeToVisit(node.expression)\n continue\n }\n\n // no previous case has been hit, continue with childs\n ts.forEachChild(node, appendNodeToVisit)\n }\n cache.expectedAndRealType.set(sourceFile, result)\n return result\n})\n","import { hasProperty, isNumber, isObject, isString } from \"effect/Predicate\"\nimport * as LanguageServicePluginOptions from \"../core/LanguageServicePluginOptions.js\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\ntype ResolvedPackagesCache = Record<string, Record<string, any>>\n\nconst checkedPackagesCache = new Map<string, ResolvedPackagesCache>()\nconst programResolvedCacheSize = new Map<string, number>()\n\ninterface ModuleWithPackageInfo {\n name: string\n version: string\n hasEffectInPeerDependencies: boolean\n contents: any\n}\n\nfunction parsePackageContentNameAndVersion(v: unknown): ModuleWithPackageInfo | undefined {\n if (!isObject(v)) return\n if (!hasProperty(v, \"packageJsonScope\")) return\n if (!v.packageJsonScope) return\n const packageJsonScope = v.packageJsonScope\n if (!hasProperty(packageJsonScope, \"contents\")) return\n if (!hasProperty(packageJsonScope.contents, \"packageJsonContent\")) return\n const packageJsonContent = packageJsonScope.contents.packageJsonContent\n if (!hasProperty(packageJsonContent, \"name\")) return\n if (!hasProperty(packageJsonContent, \"version\")) return\n const { name, version } = packageJsonContent\n if (!isString(name)) return\n if (!isString(version)) return\n const hasEffectInPeerDependencies = hasProperty(packageJsonContent, \"peerDependencies\") &&\n isObject(packageJsonContent.peerDependencies) &&\n hasProperty(packageJsonContent.peerDependencies, \"effect\")\n return {\n name: name.toLowerCase(),\n version: version.toLowerCase(),\n hasEffectInPeerDependencies,\n contents: packageJsonContent\n }\n}\n\nexport const duplicatePackage = LSP.createDiagnostic({\n name: \"duplicatePackage\",\n code: 6,\n apply: Nano.fn(\"duplicatePackage.apply\")(function*(sourceFile) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const program = yield* Nano.service(TypeScriptApi.TypeScriptProgram)\n const options = yield* Nano.service(LanguageServicePluginOptions.LanguageServicePluginOptions)\n const effectDiagnostics: Array<LSP.ApplicableDiagnosticDefinition> = []\n\n if (sourceFile.statements.length < 1) return []\n\n // whenever we detect the resolution cache size has changed, try again the check\n // this should mitigate how frequently this rule is triggered\n let resolvedPackages: ResolvedPackagesCache = checkedPackagesCache.get(sourceFile.fileName) ||\n {}\n const newResolvedModuleSize =\n hasProperty(program, \"resolvedModules\") && hasProperty(program.resolvedModules, \"size\") &&\n isNumber(program.resolvedModules.size) ?\n program.resolvedModules.size :\n 0\n const oldResolvedSize = programResolvedCacheSize.get(sourceFile.fileName) || -1\n if (newResolvedModuleSize !== oldResolvedSize) {\n const seenPackages = new Set<string>()\n resolvedPackages = {}\n program.getSourceFiles().map((_) => {\n const packageInfo = parsePackageContentNameAndVersion(_)\n if (!packageInfo) return\n const packageNameAndVersion = packageInfo.name + \"@\" + packageInfo.version\n if (seenPackages.has(packageNameAndVersion)) return\n seenPackages.add(packageNameAndVersion)\n if (\n !(packageInfo.name === \"effect\" || packageInfo.hasEffectInPeerDependencies)\n ) return\n if (options.allowedDuplicatedPackages.indexOf(packageInfo.name) > -1) return\n resolvedPackages[packageInfo.name] = resolvedPackages[packageInfo.name] || {}\n resolvedPackages[packageInfo.name][packageInfo.version] = packageInfo.contents\n })\n checkedPackagesCache.set(sourceFile.fileName, resolvedPackages)\n programResolvedCacheSize.set(sourceFile.fileName, newResolvedModuleSize)\n }\n\n for (const packageName of Object.keys(resolvedPackages)) {\n if (Object.keys(resolvedPackages[packageName]).length > 1) {\n const versions = Object.keys(resolvedPackages[packageName])\n effectDiagnostics.push({\n node: sourceFile.statements[0],\n category: ts.DiagnosticCategory.Warning,\n messageText: `Package ${packageName} is referenced multiple times with different versions (${\n versions.join(\", \")\n }) and may cause unexpected type errors.\\nCleanup your dependencies and your package lockfile to avoid multiple instances of this package and reload the project.\\nIf this is intended set the LSP config \"allowedDuplicatedPackages\" to ${\n JSON.stringify(options.allowedDuplicatedPackages.concat([packageName]))\n }.`,\n fixes: []\n })\n }\n }\n\n return effectDiagnostics\n })\n})\n","import * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeCheckerApi from \"../core/TypeCheckerApi.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport class TypeParserIssue {\n readonly _tag = \"@effect/language-service/TypeParserIssue\"\n constructor(\n readonly type: ts.Type | undefined,\n readonly node: ts.Node | undefined,\n readonly message: string\n ) {\n }\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, node, message))\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 invariantTypeArgument(type: ts.Type): Nano.Nano<ts.Type, TypeParserIssue> {\n const signatures = type.getCallSignatures()\n // Invariant<A> has only 1 type signature\n if (signatures.length !== 1) {\n return typeParserIssue(\"Invariant type has no call signature\", type)\n }\n // get the return type\n return Nano.succeed(signatures[0].getReturnType())\n}\n\nexport const pipeableType = Nano.fn(\"TypeParser.pipeableType\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n) {\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\nexport const varianceStructCovariantType = Nano.fn(\"TypeParser.varianceStructCovariantType\")(\n function*<A extends string>(\n type: ts.Type,\n atLocation: ts.Node,\n propertyName: A\n ) {\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)\nexport const varianceStructInvariantType = Nano.fn(\"TypeParser.varianceStructInvariantType\")(\n function*<A extends string>(\n type: ts.Type,\n atLocation: ts.Node,\n propertyName: A\n ) {\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* invariantTypeArgument(propertyType)\n }\n)\n\nexport const effectVarianceStruct = Nano.fn(\"TypeParser.effectVarianceStruct\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n) {\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\nexport const effectType = Nano.fn(\"TypeParser.effectType\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n // should be pipeable\n yield* pipeableType(type, atLocation)\n // get the properties to check (exclude non-property and optional properties)\n const propertiesSymbols = typeChecker.getPropertiesOfType(type).filter((_) =>\n _.flags & ts.SymbolFlags.Property && !(_.flags & ts.SymbolFlags.Optional)\n )\n // try to put typeid first (heuristic to optimize hot path)\n propertiesSymbols.sort((a, b) => b.name.indexOf(\"EffectTypeId\") - a.name.indexOf(\"EffectTypeId\"))\n // has a property symbol which is an effect variance struct\n for (const propertySymbol of propertiesSymbols) {\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\nexport const fiberType = Nano.fn(\"TypeParser.fiberType\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n) {\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\nexport const effectSubtype = Nano.fn(\"TypeParser.effectSubtype\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n) {\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 // and other datatypes as \"Pool\" have \"get\"\n const tagSymbol = typeChecker.getPropertyOfType(type, \"_tag\")\n const getSymbol = typeChecker.getPropertyOfType(type, \"get\")\n if (!(tagSymbol || getSymbol)) {\n return yield* typeParserIssue(\n \"Type is not a subtype of effect because it does not have '_tag' or 'get' property\",\n type,\n atLocation\n )\n }\n // and it is also an effect itself\n return yield* effectType(type, atLocation)\n})\n\nexport const importedEffectModule = Nano.fn(\"TypeParser.importedEffectModule\")(function*(\n node: ts.Node\n) {\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\nexport const effectGen = Nano.fn(\"TypeParser.effectGen\")(function*(node: ts.Node) {\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\nexport const effectFnUntracedGen = Nano.fn(\"TypeParser.effectFnUntracedGen\")(\n function*(node: ts.Node) {\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 const effectFnGen = Nano.fn(\"TypeParser.effectFnGen\")(function*(node: ts.Node) {\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\nexport const returnYieldEffectBlock = Nano.fn(\"TypeParser.returnYieldEffectBlock\")(function*(\n body: ts.Node\n) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n // check if the body is a block with a single effect return statement\n if (\n ts.isBlock(body) &&\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\nexport const effectSchemaVarianceStruct = Nano.fn(\"TypeParser.effectSchemaVarianceStruct\")(\n function*(\n type: ts.Type,\n atLocation: ts.Node\n ) {\n return ({\n A: yield* varianceStructInvariantType(type, atLocation, \"_A\"),\n I: yield* varianceStructInvariantType(type, atLocation, \"_I\"),\n R: yield* varianceStructCovariantType(type, atLocation, \"_R\")\n })\n }\n)\n\nexport const effectSchemaType = Nano.fn(\"TypeParser.effectSchemaType\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n // should be pipeable\n yield* pipeableType(type, atLocation)\n // should have an 'ast' property\n const ast = typeChecker.getPropertyOfType(type, \"ast\")\n if (!ast) return yield* typeParserIssue(\"Has no 'ast' property\", type, atLocation)\n // get the properties to check (exclude non-property and optional properties)\n const propertiesSymbols = typeChecker.getPropertiesOfType(type).filter((_) =>\n _.flags & ts.SymbolFlags.Property && !(_.flags & ts.SymbolFlags.Optional)\n )\n // try to put typeid first (heuristic to optimize hot path)\n propertiesSymbols.sort((a, b) => b.name.indexOf(\"TypeId\") - a.name.indexOf(\"TypeId\"))\n // has a property symbol which is an effect variance struct\n for (const propertySymbol of propertiesSymbols) {\n const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation)\n const varianceArgs = yield* Nano.option(effectSchemaVarianceStruct(\n propertyType,\n atLocation\n ))\n if (Option.isSome(varianceArgs)) {\n return varianceArgs.value\n }\n }\n return yield* typeParserIssue(\"Type has no schema variance struct\", type, atLocation)\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 \"../core/TypeCheckerApi.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as TypeParser from \"../utils/TypeParser.js\"\n\nexport const floatingEffect = LSP.createDiagnostic({\n name: \"floatingEffect\",\n code: 3,\n apply: Nano.fn(\"floatingEffect.apply\")(function*(sourceFile) {\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 expression.operatorToken.kind === ts.SyntaxKind.QuestionQuestionEqualsToken ||\n expression.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandEqualsToken ||\n expression.operatorToken.kind === ts.SyntaxKind.BarBarEqualsToken)\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 fixes: []\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 \"../core/TypeCheckerApi.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as TypeParser from \"../utils/TypeParser.js\"\n\nexport const missingEffectContext = LSP.createDiagnostic({\n name: \"missingEffectContext\",\n code: 1,\n apply: Nano.fn(\"missingEffectContext.apply\")(function*(sourceFile) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeOrder = yield* TypeCheckerApi.deterministicTypeOrder\n\n const checkForMissingContextTypes = Nano.fn(\n \"missingEffectContext.apply.checkForMissingContextTypes\"\n )(function*(\n node: ts.Node,\n expectedType: ts.Type,\n valueNode: ts.Node,\n realType: ts.Type\n ) {\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 const effectDiagnostics: Array<LSP.ApplicableDiagnosticDefinition> = []\n const sortTypes = ReadonlyArray.sort(typeOrder)\n\n const entries = yield* TypeCheckerApi.expectedAndRealType(sourceFile)\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 fixes: []\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 \"../core/TypeCheckerApi.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as TypeParser from \"../utils/TypeParser.js\"\n\nexport const missingEffectError = LSP.createDiagnostic({\n name: \"missingEffectError\",\n code: 1,\n apply: Nano.fn(\"missingEffectError.apply\")(function*(sourceFile) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeOrder = yield* TypeCheckerApi.deterministicTypeOrder\n\n const checkForMissingErrorTypes = Nano.fn(\"missingEffectError.apply.checkForMissingErrorTypes\")(\n function*(\n node: ts.Node,\n expectedType: ts.Type,\n valueNode: ts.Node,\n realType: ts.Type\n ) {\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 entries = yield* TypeCheckerApi.expectedAndRealType(sourceFile)\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 fixes: []\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 TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as TypeParser from \"../utils/TypeParser.js\"\n\nexport const missingStarInYieldEffectGen = LSP.createDiagnostic({\n name: \"missingStarInYieldEffectGen\",\n code: 4,\n apply: Nano.fn(\"missingStarInYieldEffectGen.apply\")(function*(sourceFile) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const effectDiagnostics: Array<LSP.ApplicableDiagnosticDefinition> = []\n const brokenGenerators = new Set<ts.Node>()\n const brokenYields = new Set<ts.YieldExpression>()\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 // error if yield is not followed by *\n if (\n ts.isYieldExpression(node) && node.expression &&\n node.asteriskToken === undefined\n ) {\n // go up until we meet the causing generator\n const functionStarNode = ts.findAncestor(\n node,\n (_) => (ts.isFunctionExpression(_) || ts.isFunctionDeclaration(_) || ts.isMethodDeclaration(_))\n )\n\n // .gen should always be the parent ideally\n if (functionStarNode && functionStarNode.parent) {\n const effectGenNode = functionStarNode.parent\n // continue if we hit effect gen-like\n const effectGenLike = yield* pipe(\n TypeParser.effectGen(effectGenNode),\n Nano.orElse(() => TypeParser.effectFnUntracedGen(effectGenNode)),\n Nano.orElse(() => TypeParser.effectFnGen(effectGenNode)),\n Nano.option\n )\n if (Option.isSome(effectGenLike)) {\n if (effectGenLike.value.functionStar) {\n brokenGenerators.add(effectGenLike.value.functionStar)\n }\n brokenYields.add(node)\n }\n }\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 fixes: []\n })\n )\n brokenYields.forEach((node) => {\n const fix = node.expression ?\n [{\n fixName: \"missingStarInYieldEffectGen_fix\",\n description: \"Replace yield with yield*\",\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n changeTracker.replaceNode(\n sourceFile,\n node,\n ts.factory.createYieldExpression(\n ts.factory.createToken(ts.SyntaxKind.AsteriskToken),\n node.expression!\n )\n )\n })\n }] :\n []\n\n effectDiagnostics.push({\n node,\n category: ts.DiagnosticCategory.Error,\n messageText: `When yielding Effects inside Effect.gen, you should use yield* instead of yield.`,\n fixes: fix\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 TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as TypeParser from \"../utils/TypeParser.js\"\n\nexport const unnecessaryEffectGen = LSP.createDiagnostic({\n name: \"unnecessaryEffectGen\",\n code: 5,\n apply: Nano.fn(\"unnecessaryEffectGen.apply\")(function*(sourceFile) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const effectDiagnostics: Array<LSP.ApplicableDiagnosticDefinition> = []\n const unnecessaryGenerators = new Map<ts.Node, 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 maybeNode = yield* pipe(\n TypeParser.effectGen(node),\n Nano.flatMap(({ body }) => TypeParser.returnYieldEffectBlock(body)),\n Nano.option\n )\n\n if (Option.isSome(maybeNode)) {\n unnecessaryGenerators.set(node, maybeNode.value)\n }\n }\n\n // emit diagnostics\n unnecessaryGenerators.forEach((yieldedResult, effectGenCall) =>\n effectDiagnostics.push({\n node: effectGenCall,\n category: ts.DiagnosticCategory.Suggestion,\n messageText: `This Effect.gen contains a single return statement.`,\n fixes: [{\n fixName: \"unnecessaryEffectGen_fix\",\n description: \"Remove the Effect.gen, and keep the body\",\n apply: Nano.gen(function*() {\n const textChanges = yield* Nano.service(\n TypeScriptApi.ChangeTracker\n )\n textChanges.replaceNode(sourceFile, effectGenCall, yieldedResult)\n })\n }]\n })\n )\n\n return effectDiagnostics\n })\n})\n","import { duplicatePackage } from \"./diagnostics/duplicatePackage.js\"\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\nexport const diagnostics = [\n duplicatePackage,\n missingEffectContext,\n missingEffectError,\n floatingEffect,\n missingStarInYieldEffectGen,\n unnecessaryEffectGen\n]\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC4BO,IAAMA,aAAcC,WAAsC,OAAOA,UAAU;AAkE3E,IAAMC,OAmIT,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,GA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O,CAAC,eAA8B;AAEpC;AAAA,QACM,oCAAoC,aAAa,UAAU;AAAA,QAC1D,eAA6B,eAAe,UAAU;AAAA,QACtD,eAA6B,mBAAmB,OAAO;AAAA,QACvD,eAA8B,gBAAgB,QAAQ,eAAe,CAAC;AAAA,QACtE;AAAA,UACY;AAAA,UACA,wBAAwB;AAAA,QACzC;AAAA,QACK;AAAA,UAC0B;AAAA,UACA,MAAM,YAAY;AAAA,QACjD;AAAA,QACK;AAAA,QACE,IAAI,CAACC,OAAMA,GAAE,WAAW;AAAA,QACxB;AAAA,UACC;AAAA,YAAO,CAACA,OACZA,GAAE,aAAa,WAAW,mBAAmB,SAC7CA,GAAE,aAAa,WAAW,mBAAmB;AAAA,UAC/C;AAAA,QACF;AAAA,QACO,UAAU,MAAM,CAAC,CAAC;AAAA,QACnBC,KAAI,aAAa;AAAA,MACzB;AAGA,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":["isFunction","input","dual","arity","body","arguments","apply","self","RangeError","a","b","length","c","d","e","args","identity","a","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","isString","input","isNumber","isBoolean","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","MUL_HI","MUL_LO","YieldWrapTypeId","Symbol","for","YieldWrap","constructor","value","yieldWrapGet","self","Error","getBugErrorMessage","structuralRegionState","globalValue","enabled","tester","undefined","standard","effect_internal_function","body","forced","isNotOptimizedAway","Error","stack","includes","internalCall","genConstructor","constructor","randomHashCache","globalValue","Symbol","for","WeakMap","symbol","hash","self","structuralRegionState","enabled","number","string","toString","String","Date","toISOString","URL","href","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","URL","href","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","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","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","right","left","isLeft","isRight","map","dual","self","f","isRight","right","left","getOrElse","dual","self","onLeft","isLeft","left","right","make","compare","self","that","none","some","isNone","isSome","fromIterable","collection","Array","isArray","from","isArray","Array","isEmptyArray","self","length","isEmptyReadonlyArray","sort","dual","self","O","out","Array","from","map","dual","self","f","flatMap","isEmptyReadonlyArray","out","i","length","inner","j","push","flatten","identity","filter","dual","self","predicate","as","fromIterable","out","i","length","push","make","run","left","right","flatMap","map","make","some","none","isSome","map","refactor","node","flatMap","symbol","isSome","isSome","isSome","isNone","isSome","flatMap","isSome","_","map"]}