@effect/language-service 0.16.1 → 0.16.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Function.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Either.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Equivalence.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/doNotation.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/version.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/GlobalValue.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Predicate.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/errors.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Utils.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Hash.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Equal.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Inspectable.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Pipeable.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/opCodes/effect.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/effectable.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/option.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/either.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/array.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Order.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Option.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Array.ts","../src/core/Nano.ts","../src/core/TypeScriptApi.ts","../src/core/AST.ts","../src/core/LSP.ts","../src/completions/contextSelfInClasses.ts","../src/completions/effectDataClasses.ts","../src/completions/effectSchemaSelfInClasses.ts","../src/completions/effectSelfInClasses.ts","../src/completions.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","../src/quickinfo.ts","../src/refactors/asyncAwaitToGen.ts","../src/refactors/asyncAwaitToGenTryPromise.ts","../src/refactors/effectGenToFn.ts","../src/refactors/functionToArrow.ts","../src/refactors/makeSchemaOpaque.ts","../src/refactors/makeSchemaOpaqueWithNs.ts","../src/refactors/pipeableToDatafirst.ts","../src/refactors/removeUnnecessaryEffectGen.ts","../src/refactors/toggleLazyConst.ts","../src/refactors/toggleReturnTypeAnnotation.ts","../src/refactors/toggleTypeAnnotation.ts","../src/utils/SchemaGen.ts","../src/refactors/typeToEffectSchema.ts","../src/refactors/typeToEffectSchemaClass.ts","../src/refactors/wrapWithEffectGen.ts","../src/refactors/wrapWithPipe.ts","../src/refactors.ts","../src/index.ts"],"sourcesContent":["/**\n * @since 2.0.0\n */\nimport type { TypeLambda } from \"./HKT.js\"\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface FunctionTypeLambda extends TypeLambda {\n readonly type: (a: this[\"In\"]) => this[\"Target\"]\n}\n\n/**\n * Tests if a value is a `function`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isFunction } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isFunction(isFunction), true)\n * assert.deepStrictEqual(isFunction(\"function\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isFunction = (input: unknown): input is Function => typeof input === \"function\"\n\n/**\n * Creates a function that can be used in a data-last (aka `pipe`able) or\n * data-first style.\n *\n * The first parameter to `dual` is either the arity of the uncurried function\n * or a predicate that determines if the function is being used in a data-first\n * or data-last style.\n *\n * Using the arity is the most common use case, but there are some cases where\n * you may want to use a predicate. For example, if you have a function that\n * takes an optional argument, you can use a predicate to determine if the\n * function is being used in a data-first or data-last style.\n *\n * @param arity - Either the arity of the uncurried function or a predicate\n * which determines if the function is being used in a data-first\n * or data-last style.\n * @param body - The definition of the uncurried function.\n *\n * @example\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * // Exampe using arity to determine data-first or data-last style\n * const sum: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual(2, (self: number, that: number): number => self + that)\n *\n * assert.deepStrictEqual(sum(2, 3), 5)\n * assert.deepStrictEqual(pipe(2, sum(3)), 5)\n *\n * // Example using a predicate to determine data-first or data-last style\n * const sum2: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual((args) => args.length === 1, (self: number, that: number): number => self + that)\n *\n * assert.deepStrictEqual(sum(2, 3), 5)\n * assert.deepStrictEqual(pipe(2, sum(3)), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const dual: {\n /**\n * Creates a function that can be used in a data-last (aka `pipe`able) or\n * data-first style.\n *\n * The first parameter to `dual` is either the arity of the uncurried function\n * or a predicate that determines if the function is being used in a data-first\n * or data-last style.\n *\n * Using the arity is the most common use case, but there are some cases where\n * you may want to use a predicate. For example, if you have a function that\n * takes an optional argument, you can use a predicate to determine if the\n * function is being used in a data-first or data-last style.\n *\n * @param arity - Either the arity of the uncurried function or a predicate\n * which determines if the function is being used in a data-first\n * or data-last style.\n * @param body - The definition of the uncurried function.\n *\n * @example\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * // Exampe using arity to determine data-first or data-last style\n * const sum: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual(2, (self: number, that: number): number => self + that)\n *\n * assert.deepStrictEqual(sum(2, 3), 5)\n * assert.deepStrictEqual(pipe(2, sum(3)), 5)\n *\n * // Example using a predicate to determine data-first or data-last style\n * const sum2: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual((args) => args.length === 1, (self: number, that: number): number => self + that)\n *\n * assert.deepStrictEqual(sum(2, 3), 5)\n * assert.deepStrictEqual(pipe(2, sum(3)), 5)\n * ```\n *\n * @since 2.0.0\n */\n <DataLast extends (...args: Array<any>) => any, DataFirst extends (...args: Array<any>) => any>(\n arity: Parameters<DataFirst>[\"length\"],\n body: DataFirst\n ): DataLast & DataFirst\n /**\n * Creates a function that can be used in a data-last (aka `pipe`able) or\n * data-first style.\n *\n * The first parameter to `dual` is either the arity of the uncurried function\n * or a predicate that determines if the function is being used in a data-first\n * or data-last style.\n *\n * Using the arity is the most common use case, but there are some cases where\n * you may want to use a predicate. For example, if you have a function that\n * takes an optional argument, you can use a predicate to determine if the\n * function is being used in a data-first or data-last style.\n *\n * @param arity - Either the arity of the uncurried function or a predicate\n * which determines if the function is being used in a data-first\n * or data-last style.\n * @param body - The definition of the uncurried function.\n *\n * @example\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * // Exampe using arity to determine data-first or data-last style\n * const sum: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual(2, (self: number, that: number): number => self + that)\n *\n * assert.deepStrictEqual(sum(2, 3), 5)\n * assert.deepStrictEqual(pipe(2, sum(3)), 5)\n *\n * // Example using a predicate to determine data-first or data-last style\n * const sum2: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual((args) => args.length === 1, (self: number, that: number): number => self + that)\n *\n * assert.deepStrictEqual(sum(2, 3), 5)\n * assert.deepStrictEqual(pipe(2, sum(3)), 5)\n * ```\n *\n * @since 2.0.0\n */\n <DataLast extends (...args: Array<any>) => any, DataFirst extends (...args: Array<any>) => any>(\n isDataFirst: (args: IArguments) => boolean,\n body: DataFirst\n ): DataLast & DataFirst\n} = function(arity, body) {\n if (typeof arity === \"function\") {\n return function() {\n if (arity(arguments)) {\n // @ts-expect-error\n return body.apply(this, arguments)\n }\n return ((self: any) => body(self, ...arguments)) as any\n }\n }\n\n switch (arity) {\n case 0:\n case 1:\n throw new RangeError(`Invalid arity ${arity}`)\n\n case 2:\n return function(a, b) {\n if (arguments.length >= 2) {\n return body(a, b)\n }\n return function(self: any) {\n return body(self, a)\n }\n }\n\n case 3:\n return function(a, b, c) {\n if (arguments.length >= 3) {\n return body(a, b, c)\n }\n return function(self: any) {\n return body(self, a, b)\n }\n }\n\n case 4:\n return function(a, b, c, d) {\n if (arguments.length >= 4) {\n return body(a, b, c, d)\n }\n return function(self: any) {\n return body(self, a, b, c)\n }\n }\n\n case 5:\n return function(a, b, c, d, e) {\n if (arguments.length >= 5) {\n return body(a, b, c, d, e)\n }\n return function(self: any) {\n return body(self, a, b, c, d)\n }\n }\n\n default:\n return function() {\n if (arguments.length >= arity) {\n // @ts-expect-error\n return body.apply(this, arguments)\n }\n const args = arguments\n return function(self: any) {\n return body(self, ...args)\n }\n }\n }\n}\n/**\n * Apply a function to a given value.\n *\n * @param a - The value that the function will be applied to.\n * @param self - The function to be applied to a value.\n *\n * @example\n * ```ts\n * import { pipe, apply } from \"effect/Function\"\n * import { length } from \"effect/String\"\n *\n * assert.deepStrictEqual(pipe(length, apply(\"hello\")), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const apply = <A>(a: A) => <B>(self: (a: A) => B): B => self(a)\n\n/**\n * A lazy argument.\n *\n * @example\n * ```ts\n * import { LazyArg, constant } from \"effect/Function\"\n *\n * const constNull: LazyArg<null> = constant(null)\n * ```\n *\n * @since 2.0.0\n */\nexport interface LazyArg<A> {\n (): A\n}\n\n/**\n * @example\n * ```ts\n * import { FunctionN } from \"effect/Function\"\n *\n * const sum: FunctionN<[number, number], number> = (a, b) => a + b\n * ```\n *\n * @since 2.0.0\n */\nexport interface FunctionN<A extends ReadonlyArray<unknown>, B> {\n (...args: A): B\n}\n\n/**\n * The identity function, i.e. A function that returns its input argument.\n *\n * @param a - The input argument.\n *\n * @example\n * ```ts\n * import { identity } from \"effect/Function\"\n *\n * assert.deepStrictEqual(identity(5), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const identity = <A>(a: A): A => a\n\n/**\n * A function that ensures that the type of an expression matches some type,\n * without changing the resulting type of that expression.\n *\n * @example\n * ```ts\n * import { satisfies } from \"effect/Function\"\n *\n * const test1 = satisfies<number>()(5 as const)\n * //^? const test: 5\n * // @ts-expect-error\n * const test2 = satisfies<string>()(5)\n * //^? Argument of type 'number' is not assignable to parameter of type 'string'\n *\n * assert.deepStrictEqual(satisfies<number>()(5), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const satisfies = <A>() => <B extends A>(b: B) => b\n\n/**\n * Casts the result to the specified type.\n *\n * @param a - The value to be casted to the target type.\n *\n * @example\n * ```ts\n * import { unsafeCoerce, identity } from \"effect/Function\"\n *\n * assert.deepStrictEqual(unsafeCoerce, identity)\n * ```\n *\n * @since 2.0.0\n */\nexport const unsafeCoerce: <A, B>(a: A) => B = identity as any\n\n/**\n * Creates a constant value that never changes.\n *\n * This is useful when you want to pass a value to a higher-order function (a function that takes another function as its argument)\n * and want that inner function to always use the same value, no matter how many times it is called.\n *\n * @param value - The constant value to be returned.\n *\n * @example\n * ```ts\n * import { constant } from \"effect/Function\"\n *\n * const constNull = constant(null)\n *\n * assert.deepStrictEqual(constNull(), null)\n * assert.deepStrictEqual(constNull(), null)\n * ```\n *\n * @since 2.0.0\n */\nexport const constant = <A>(value: A): LazyArg<A> => () => value\n\n/**\n * A thunk that returns always `true`.\n *\n * @example\n * ```ts\n * import { constTrue } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constTrue(), true)\n * ```\n *\n * @since 2.0.0\n */\nexport const constTrue: LazyArg<boolean> = constant(true)\n\n/**\n * A thunk that returns always `false`.\n *\n * @example\n * ```ts\n * import { constFalse } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constFalse(), false)\n * ```\n *\n * @since 2.0.0\n */\nexport const constFalse: LazyArg<boolean> = constant(false)\n\n/**\n * A thunk that returns always `null`.\n *\n * @example\n * ```ts\n * import { constNull } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constNull(), null)\n * ```\n *\n * @since 2.0.0\n */\nexport const constNull: LazyArg<null> = constant(null)\n\n/**\n * A thunk that returns always `undefined`.\n *\n * @example\n * ```ts\n * import { constUndefined } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constUndefined(), undefined)\n * ```\n *\n * @since 2.0.0\n */\nexport const constUndefined: LazyArg<undefined> = constant(undefined)\n\n/**\n * A thunk that returns always `void`.\n *\n * @example\n * ```ts\n * import { constVoid } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constVoid(), undefined)\n * ```\n *\n * @since 2.0.0\n */\nexport const constVoid: LazyArg<void> = constUndefined\n\n/**\n * Reverses the order of arguments for a curried function.\n *\n * @param f - A curried function that takes multiple arguments.\n *\n * @example\n * ```ts\n * import { flip } from \"effect/Function\"\n *\n * const f = (a: number) => (b: string) => a - b.length\n *\n * assert.deepStrictEqual(flip(f)('aaa')(2), -1)\n * ```\n *\n * @since 2.0.0\n */\nexport const flip = <A extends Array<unknown>, B extends Array<unknown>, C>(\n f: (...a: A) => (...b: B) => C\n): (...b: B) => (...a: A) => C =>\n(...b) =>\n(...a) => f(...a)(...b)\n\n/**\n * Composes two functions, `ab` and `bc` into a single function that takes in an argument `a` of type `A` and returns a result of type `C`.\n * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.\n *\n * @param ab - A function that maps from `A` to `B`.\n * @param bc - A function that maps from `B` to `C`.\n *\n * @example\n * ```ts\n * import { compose } from \"effect/Function\"\n *\n * const increment = (n: number) => n + 1;\n * const square = (n: number) => n * n;\n *\n * assert.strictEqual(compose(increment, square)(2), 9);\n * ```\n *\n * @since 2.0.0\n */\nexport const compose: {\n /**\n * Composes two functions, `ab` and `bc` into a single function that takes in an argument `a` of type `A` and returns a result of type `C`.\n * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.\n *\n * @param ab - A function that maps from `A` to `B`.\n * @param bc - A function that maps from `B` to `C`.\n *\n * @example\n * ```ts\n * import { compose } from \"effect/Function\"\n *\n * const increment = (n: number) => n + 1;\n * const square = (n: number) => n * n;\n *\n * assert.strictEqual(compose(increment, square)(2), 9);\n * ```\n *\n * @since 2.0.0\n */\n <B, C>(bc: (b: B) => C): <A>(self: (a: A) => B) => (a: A) => C\n /**\n * Composes two functions, `ab` and `bc` into a single function that takes in an argument `a` of type `A` and returns a result of type `C`.\n * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.\n *\n * @param ab - A function that maps from `A` to `B`.\n * @param bc - A function that maps from `B` to `C`.\n *\n * @example\n * ```ts\n * import { compose } from \"effect/Function\"\n *\n * const increment = (n: number) => n + 1;\n * const square = (n: number) => n * n;\n *\n * assert.strictEqual(compose(increment, square)(2), 9);\n * ```\n *\n * @since 2.0.0\n */\n <A, B, C>(self: (a: A) => B, bc: (b: B) => C): (a: A) => C\n} = dual(2, <A, B, C>(ab: (a: A) => B, bc: (b: B) => C): (a: A) => C => (a) => bc(ab(a)))\n\n/**\n * The `absurd` function is a stub for cases where a value of type `never` is encountered in your code,\n * meaning that it should be impossible for this code to be executed.\n *\n * This function is particularly useful when it's necessary to specify that certain cases are impossible.\n *\n * @since 2.0.0\n */\nexport const absurd = <A>(_: never): A => {\n throw new Error(\"Called `absurd` function which should be uncallable\")\n}\n\n/**\n * Creates a tupled version of this function: instead of `n` arguments, it accepts a single tuple argument.\n *\n * @example\n * ```ts\n * import { tupled } from \"effect/Function\"\n *\n * const sumTupled = tupled((x: number, y: number): number => x + y)\n *\n * assert.deepStrictEqual(sumTupled([1, 2]), 3)\n * ```\n *\n * @since 2.0.0\n */\nexport const tupled = <A extends ReadonlyArray<unknown>, B>(f: (...a: A) => B): (a: A) => B => (a) => f(...a)\n\n/**\n * Inverse function of `tupled`\n *\n * @example\n * ```ts\n * import { untupled } from \"effect/Function\"\n *\n * const getFirst = untupled(<A, B>(tuple: [A, B]): A => tuple[0])\n *\n * assert.deepStrictEqual(getFirst(1, 2), 1)\n * ```\n *\n * @since 2.0.0\n */\nexport const untupled = <A extends ReadonlyArray<unknown>, B>(f: (a: A) => B): (...a: A) => B => (...a) => f(a)\n\n/**\n * Pipes the value of an expression into a pipeline of functions.\n *\n * **When to Use**\n *\n * This is useful in combination with data-last functions as a simulation of\n * methods:\n *\n * ```ts\n * as.map(f).filter(g)\n * ```\n *\n * becomes:\n *\n * ```ts\n * import { pipe, Array } from \"effect\"\n *\n * pipe(as, Array.map(f), Array.filter(g))\n * ```\n *\n * **Details**\n *\n * The `pipe` function is a utility that allows us to compose functions in a\n * readable and sequential manner. It takes the output of one function and\n * passes it as the input to the next function in the pipeline. This enables us\n * to build complex transformations by chaining multiple functions together.\n *\n * ```ts\n * import { pipe } from \"effect\"\n *\n * const result = pipe(input, func1, func2, ..., funcN)\n * ```\n *\n * In this syntax, `input` is the initial value, and `func1`, `func2`, ...,\n * `funcN` are the functions to be applied in sequence. The result of each\n * function becomes the input for the next function, and the final result is\n * returned.\n *\n * Here's an illustration of how `pipe` works:\n *\n * ```text\n * ┌───────┐ ┌───────┐ ┌───────┐ ┌───────┐ ┌───────┐ ┌────────┐\n * │ input │───►│ func1 │───►│ func2 │───►│ ... │───►│ funcN │───►│ result │\n * └───────┘ └───────┘ └───────┘ └───────┘ └───────┘ └────────┘\n * ```\n *\n * It's important to note that functions passed to `pipe` must have a **single\n * argument** because they are only called with a single argument.\n *\n * @example\n * ```ts\n * // Example: Chaining Arithmetic Operations\n * import { pipe } from \"effect\"\n *\n * // Define simple arithmetic operations\n * const increment = (x: number) => x + 1\n * const double = (x: number) => x * 2\n * const subtractTen = (x: number) => x - 10\n *\n * // Sequentially apply these operations using `pipe`\n * const result = pipe(5, increment, double, subtractTen)\n *\n * console.log(result)\n * // Output: 2\n * ```\n *\n * @since 2.0.0\n */\nexport function pipe<A>(a: A): A\nexport function pipe<A, B = never>(a: A, ab: (a: A) => B): B\nexport function pipe<A, B = never, C = never>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C\n): C\nexport function pipe<A, B = never, C = never, D = never>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D\n): D\nexport function pipe<A, B = never, C = never, D = never, E = never>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E\n): E\nexport function pipe<A, B = never, C = never, D = never, E = never, F = never>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F\n): F\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G\n): G\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H\n): H\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I\n): I\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J\n): J\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K\n): K\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L\n): L\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M\n): M\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N\n): N\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O\n): O\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P\n): P\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q\n): Q\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R\n): R\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => S\n): S\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never,\n T = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => S,\n st: (s: S) => T\n): T\nexport function pipe(\n a: unknown,\n ab?: Function,\n bc?: Function,\n cd?: Function,\n de?: Function,\n ef?: Function,\n fg?: Function,\n gh?: Function,\n hi?: Function\n): unknown {\n switch (arguments.length) {\n case 1:\n return a\n case 2:\n return ab!(a)\n case 3:\n return bc!(ab!(a))\n case 4:\n return cd!(bc!(ab!(a)))\n case 5:\n return de!(cd!(bc!(ab!(a))))\n case 6:\n return ef!(de!(cd!(bc!(ab!(a)))))\n case 7:\n return fg!(ef!(de!(cd!(bc!(ab!(a))))))\n case 8:\n return gh!(fg!(ef!(de!(cd!(bc!(ab!(a)))))))\n case 9:\n return hi!(gh!(fg!(ef!(de!(cd!(bc!(ab!(a))))))))\n default: {\n let ret = arguments[0]\n for (let i = 1; i < arguments.length; i++) {\n ret = arguments[i](ret)\n }\n return ret\n }\n }\n}\n\n/**\n * Performs left-to-right function composition. The first argument may have any arity, the remaining arguments must be unary.\n *\n * See also [`pipe`](#pipe).\n *\n * @example\n * ```ts\n * import { flow } from \"effect/Function\"\n *\n * const len = (s: string): number => s.length\n * const double = (n: number): number => n * 2\n *\n * const f = flow(len, double)\n *\n * assert.strictEqual(f('aaa'), 6)\n * ```\n *\n * @since 2.0.0\n */\nexport function flow<A extends ReadonlyArray<unknown>, B = never>(\n ab: (...a: A) => B\n): (...a: A) => B\nexport function flow<A extends ReadonlyArray<unknown>, B = never, C = never>(\n ab: (...a: A) => B,\n bc: (b: B) => C\n): (...a: A) => C\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never\n>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...a: A) => D\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E\n): (...a: A) => E\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F\n): (...a: A) => F\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G\n): (...a: A) => G\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H\n): (...a: A) => H\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I\n): (...a: A) => I\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J\n): (...a: A) => J\nexport function flow(\n ab: Function,\n bc?: Function,\n cd?: Function,\n de?: Function,\n ef?: Function,\n fg?: Function,\n gh?: Function,\n hi?: Function,\n ij?: Function\n): unknown {\n switch (arguments.length) {\n case 1:\n return ab\n case 2:\n return function(this: unknown) {\n return bc!(ab.apply(this, arguments))\n }\n case 3:\n return function(this: unknown) {\n return cd!(bc!(ab.apply(this, arguments)))\n }\n case 4:\n return function(this: unknown) {\n return de!(cd!(bc!(ab.apply(this, arguments))))\n }\n case 5:\n return function(this: unknown) {\n return ef!(de!(cd!(bc!(ab.apply(this, arguments)))))\n }\n case 6:\n return function(this: unknown) {\n return fg!(ef!(de!(cd!(bc!(ab.apply(this, arguments))))))\n }\n case 7:\n return function(this: unknown) {\n return gh!(fg!(ef!(de!(cd!(bc!(ab.apply(this, arguments)))))))\n }\n case 8:\n return function(this: unknown) {\n return hi!(gh!(fg!(ef!(de!(cd!(bc!(ab.apply(this, arguments))))))))\n }\n case 9:\n return function(this: unknown) {\n return ij!(hi!(gh!(fg!(ef!(de!(cd!(bc!(ab.apply(this, arguments)))))))))\n }\n }\n return\n}\n\n/**\n * Type hole simulation.\n *\n * @since 2.0.0\n */\nexport const hole: <T>() => T = unsafeCoerce(absurd)\n\n/**\n * The SK combinator, also known as the \"S-K combinator\" or \"S-combinator\", is a fundamental combinator in the\n * lambda calculus and the SKI combinator calculus.\n *\n * This function is useful for discarding the first argument passed to it and returning the second argument.\n *\n * @param _ - The first argument to be discarded.\n * @param b - The second argument to be returned.\n *\n * @example\n * ```ts\n * import { SK } from \"effect/Function\";\n *\n * assert.deepStrictEqual(SK(0, \"hello\"), \"hello\")\n * ```\n *\n * @since 2.0.0\n */\nexport const SK = <A, B>(_: A, b: B): B => b\n","/**\n * @since 2.0.0\n */\n\nimport * as Equivalence from \"./Equivalence.js\"\nimport type { LazyArg } from \"./Function.js\"\nimport { constNull, constUndefined, dual, identity } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\nimport type { Inspectable } from \"./Inspectable.js\"\nimport * as doNotation from \"./internal/doNotation.js\"\nimport * as either from \"./internal/either.js\"\nimport type { Option } from \"./Option.js\"\nimport type { Pipeable } from \"./Pipeable.js\"\nimport type { Predicate, Refinement } from \"./Predicate.js\"\nimport { isFunction } from \"./Predicate.js\"\nimport type { Covariant, NoInfer, NotFunction } from \"./Types.js\"\nimport type * as Unify from \"./Unify.js\"\nimport * as Gen from \"./Utils.js\"\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport type Either<R, L = never> = Left<L, R> | Right<L, R>\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport const TypeId: unique symbol = either.TypeId\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport type TypeId = typeof TypeId\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Left<out L, out R> extends Pipeable, Inspectable {\n readonly _tag: \"Left\"\n readonly _op: \"Left\"\n readonly left: L\n readonly [TypeId]: {\n readonly _R: Covariant<R>\n readonly _L: Covariant<L>\n }\n [Unify.typeSymbol]?: unknown\n [Unify.unifySymbol]?: EitherUnify<this>\n [Unify.ignoreSymbol]?: EitherUnifyIgnore\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Right<out L, out R> extends Pipeable, Inspectable {\n readonly _tag: \"Right\"\n readonly _op: \"Right\"\n readonly right: R\n readonly [TypeId]: {\n readonly _R: Covariant<R>\n readonly _L: Covariant<L>\n }\n [Unify.typeSymbol]?: unknown\n [Unify.unifySymbol]?: EitherUnify<this>\n [Unify.ignoreSymbol]?: EitherUnifyIgnore\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface EitherUnify<A extends { [Unify.typeSymbol]?: any }> {\n Either?: () => A[Unify.typeSymbol] extends Either<infer R0, infer L0> | infer _ ? Either<R0, L0> : never\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface EitherUnifyIgnore {}\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface EitherTypeLambda extends TypeLambda {\n readonly type: Either<this[\"Target\"], this[\"Out1\"]>\n}\n\n/**\n * @since 2.0.0\n */\nexport declare namespace Either {\n /**\n * @since 2.0.0\n * @category type-level\n */\n export type Left<T extends Either<any, any>> = [T] extends [Either<infer _A, infer _E>] ? _E : never\n /**\n * @since 2.0.0\n * @category type-level\n */\n export type Right<T extends Either<any, any>> = [T] extends [Either<infer _A, infer _E>] ? _A : never\n}\n\n/**\n * Constructs a new `Either` holding a `Right` value. This usually represents a successful value due to the right bias\n * of this structure.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const right: <R>(right: R) => Either<R> = either.right\n\n/**\n * Constructs a new `Either` holding a `Left` value. This usually represents a failure, due to the right-bias of this\n * structure.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const left: <L>(left: L) => Either<never, L> = either.left\n\n/**\n * Takes a lazy default and a nullable value, if the value is not nully (`null` or `undefined`), turn it into a `Right`, if the value is nully use\n * the provided default as a `Left`.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromNullable(1, () => 'fallback'), Either.right(1))\n * assert.deepStrictEqual(Either.fromNullable(null, () => 'fallback'), Either.left('fallback'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const fromNullable: {\n /**\n * Takes a lazy default and a nullable value, if the value is not nully (`null` or `undefined`), turn it into a `Right`, if the value is nully use\n * the provided default as a `Left`.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromNullable(1, () => 'fallback'), Either.right(1))\n * assert.deepStrictEqual(Either.fromNullable(null, () => 'fallback'), Either.left('fallback'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <R, L>(onNullable: (right: R) => L): (self: R) => Either<NonNullable<R>, L>\n /**\n * Takes a lazy default and a nullable value, if the value is not nully (`null` or `undefined`), turn it into a `Right`, if the value is nully use\n * the provided default as a `Left`.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromNullable(1, () => 'fallback'), Either.right(1))\n * assert.deepStrictEqual(Either.fromNullable(null, () => 'fallback'), Either.left('fallback'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <R, L>(self: R, onNullable: (right: R) => L): Either<NonNullable<R>, L>\n} = dual(\n 2,\n <R, L>(self: R, onNullable: (right: R) => L): Either<NonNullable<R>, L> =>\n self == null ? left(onNullable(self)) : right(self as NonNullable<R>)\n)\n\n/**\n * @example\n * ```ts\n * import { Either, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromOption(Option.some(1), () => 'error'), Either.right(1))\n * assert.deepStrictEqual(Either.fromOption(Option.none(), () => 'error'), Either.left('error'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const fromOption: {\n /**\n * @example\n * ```ts\n * import { Either, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromOption(Option.some(1), () => 'error'), Either.right(1))\n * assert.deepStrictEqual(Either.fromOption(Option.none(), () => 'error'), Either.left('error'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <L>(onNone: () => L): <R>(self: Option<R>) => Either<R, L>\n /**\n * @example\n * ```ts\n * import { Either, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromOption(Option.some(1), () => 'error'), Either.right(1))\n * assert.deepStrictEqual(Either.fromOption(Option.none(), () => 'error'), Either.left('error'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <R, L>(self: Option<R>, onNone: () => L): Either<R, L>\n} = either.fromOption\n\nconst try_: {\n <R, L>(\n options: {\n readonly try: LazyArg<R>\n readonly catch: (error: unknown) => L\n }\n ): Either<R, L>\n <R>(evaluate: LazyArg<R>): Either<R, unknown>\n} = (<R, L>(\n evaluate: LazyArg<R> | {\n readonly try: LazyArg<R>\n readonly catch: (error: unknown) => L\n }\n) => {\n if (isFunction(evaluate)) {\n try {\n return right(evaluate())\n } catch (e) {\n return left(e)\n }\n } else {\n try {\n return right(evaluate.try())\n } catch (e) {\n return left(evaluate.catch(e))\n }\n }\n}) as any\n\nexport {\n /**\n * Imports a synchronous side-effect into a pure `Either` value, translating any\n * thrown exceptions into typed failed eithers creating with `Either.left`.\n *\n * @category constructors\n * @since 2.0.0\n */\n try_ as try\n}\n\n/**\n * Tests if a value is a `Either`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.isEither(Either.right(1)), true)\n * assert.deepStrictEqual(Either.isEither(Either.left(\"a\")), true)\n * assert.deepStrictEqual(Either.isEither({ right: 1 }), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isEither: (input: unknown) => input is Either<unknown, unknown> = either.isEither\n\n/**\n * Determine if a `Either` is a `Left`.\n *\n * @param self - The `Either` to check.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.isLeft(Either.right(1)), false)\n * assert.deepStrictEqual(Either.isLeft(Either.left(\"a\")), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isLeft: <R, L>(self: Either<R, L>) => self is Left<L, R> = either.isLeft\n\n/**\n * Determine if a `Either` is a `Right`.\n *\n * @param self - The `Either` to check.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.isRight(Either.right(1)), true)\n * assert.deepStrictEqual(Either.isRight(Either.left(\"a\")), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isRight: <R, L>(self: Either<R, L>) => self is Right<L, R> = either.isRight\n\n/**\n * Converts a `Either` to an `Option` discarding the `Left`.\n *\n * @example\n * ```ts\n * import { Either, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getRight(Either.right('ok')), Option.some('ok'))\n * assert.deepStrictEqual(Either.getRight(Either.left('err')), Option.none())\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getRight: <R, L>(self: Either<R, L>) => Option<R> = either.getRight\n\n/**\n * Converts a `Either` to an `Option` discarding the value.\n *\n * @example\n * ```ts\n * import { Either, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getLeft(Either.right('ok')), Option.none())\n * assert.deepStrictEqual(Either.getLeft(Either.left('err')), Option.some('err'))\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getLeft: <R, L>(self: Either<R, L>) => Option<L> = either.getLeft\n\n/**\n * @category equivalence\n * @since 2.0.0\n */\nexport const getEquivalence = <R, L>({ left, right }: {\n right: Equivalence.Equivalence<R>\n left: Equivalence.Equivalence<L>\n}): Equivalence.Equivalence<Either<R, L>> =>\n Equivalence.make((x, y) =>\n isLeft(x) ?\n isLeft(y) && left(x.left, y.left) :\n isRight(y) && right(x.right, y.right)\n )\n\n/**\n * @category mapping\n * @since 2.0.0\n */\nexport const mapBoth: {\n /**\n * @category mapping\n * @since 2.0.0\n */\n <L, L2, R, R2>(\n options: {\n readonly onLeft: (left: L) => L2\n readonly onRight: (right: R) => R2\n }\n ): (self: Either<R, L>) => Either<R2, L2>\n /**\n * @category mapping\n * @since 2.0.0\n */\n <L, R, L2, R2>(\n self: Either<R, L>,\n options: {\n readonly onLeft: (left: L) => L2\n readonly onRight: (right: R) => R2\n }\n ): Either<R2, L2>\n} = dual(\n 2,\n <L, R, L2, R2>(self: Either<R, L>, { onLeft, onRight }: {\n readonly onLeft: (left: L) => L2\n readonly onRight: (right: R) => R2\n }): Either<R2, L2> => isLeft(self) ? left(onLeft(self.left)) : right(onRight(self.right))\n)\n\n/**\n * Maps the `Left` side of an `Either` value to a new `Either` value.\n *\n * @param self - The input `Either` value to map.\n * @param f - A transformation function to apply to the `Left` value of the input `Either`.\n *\n * @category mapping\n * @since 2.0.0\n */\nexport const mapLeft: {\n /**\n * Maps the `Left` side of an `Either` value to a new `Either` value.\n *\n * @param self - The input `Either` value to map.\n * @param f - A transformation function to apply to the `Left` value of the input `Either`.\n *\n * @category mapping\n * @since 2.0.0\n */\n <L, L2>(f: (left: L) => L2): <R>(self: Either<R, L>) => Either<R, L2>\n /**\n * Maps the `Left` side of an `Either` value to a new `Either` value.\n *\n * @param self - The input `Either` value to map.\n * @param f - A transformation function to apply to the `Left` value of the input `Either`.\n *\n * @category mapping\n * @since 2.0.0\n */\n <R, L, L2>(self: Either<R, L>, f: (left: L) => L2): Either<R, L2>\n} = dual(\n 2,\n <R, L1, L2>(self: Either<R, L1>, f: (left: L1) => L2): Either<R, L2> =>\n isLeft(self) ? left(f(self.left)) : right(self.right)\n)\n\n/**\n * Maps the `Right` side of an `Either` value to a new `Either` value.\n *\n * @param self - An `Either` to map\n * @param f - The function to map over the value of the `Either`\n *\n * @category mapping\n * @since 2.0.0\n */\nexport const map: {\n /**\n * Maps the `Right` side of an `Either` value to a new `Either` value.\n *\n * @param self - An `Either` to map\n * @param f - The function to map over the value of the `Either`\n *\n * @category mapping\n * @since 2.0.0\n */\n <R, R2>(f: (right: R) => R2): <L>(self: Either<R, L>) => Either<R2, L>\n /**\n * Maps the `Right` side of an `Either` value to a new `Either` value.\n *\n * @param self - An `Either` to map\n * @param f - The function to map over the value of the `Either`\n *\n * @category mapping\n * @since 2.0.0\n */\n <R, L, R2>(self: Either<R, L>, f: (right: R) => R2): Either<R2, L>\n} = dual(\n 2,\n <R1, L, R2>(self: Either<R1, L>, f: (right: R1) => R2): Either<R2, L> =>\n isRight(self) ? right(f(self.right)) : left(self.left)\n)\n\n/**\n * Takes two functions and an `Either` value, if the value is a `Left` the inner value is applied to the `onLeft function,\n * if the value is a `Right` the inner value is applied to the `onRight` function.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const onLeft = (strings: ReadonlyArray<string>): string => `strings: ${strings.join(', ')}`\n *\n * const onRight = (value: number): string => `Ok: ${value}`\n *\n * assert.deepStrictEqual(pipe(Either.right(1), Either.match({ onLeft, onRight })), 'Ok: 1')\n * assert.deepStrictEqual(\n * pipe(Either.left(['string 1', 'string 2']), Either.match({ onLeft, onRight })),\n * 'strings: string 1, string 2'\n * )\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\nexport const match: {\n /**\n * Takes two functions and an `Either` value, if the value is a `Left` the inner value is applied to the `onLeft function,\n * if the value is a `Right` the inner value is applied to the `onRight` function.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const onLeft = (strings: ReadonlyArray<string>): string => `strings: ${strings.join(', ')}`\n *\n * const onRight = (value: number): string => `Ok: ${value}`\n *\n * assert.deepStrictEqual(pipe(Either.right(1), Either.match({ onLeft, onRight })), 'Ok: 1')\n * assert.deepStrictEqual(\n * pipe(Either.left(['string 1', 'string 2']), Either.match({ onLeft, onRight })),\n * 'strings: string 1, string 2'\n * )\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <L, B, R, C = B>(\n options: {\n readonly onLeft: (left: L) => B\n readonly onRight: (right: R) => C\n }\n ): (self: Either<R, L>) => B | C\n /**\n * Takes two functions and an `Either` value, if the value is a `Left` the inner value is applied to the `onLeft function,\n * if the value is a `Right` the inner value is applied to the `onRight` function.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const onLeft = (strings: ReadonlyArray<string>): string => `strings: ${strings.join(', ')}`\n *\n * const onRight = (value: number): string => `Ok: ${value}`\n *\n * assert.deepStrictEqual(pipe(Either.right(1), Either.match({ onLeft, onRight })), 'Ok: 1')\n * assert.deepStrictEqual(\n * pipe(Either.left(['string 1', 'string 2']), Either.match({ onLeft, onRight })),\n * 'strings: string 1, string 2'\n * )\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <R, L, B, C = B>(\n self: Either<R, L>,\n options: {\n readonly onLeft: (left: L) => B\n readonly onRight: (right: R) => C\n }\n ): B | C\n} = dual(\n 2,\n <R, L, B, C = B>(self: Either<R, L>, { onLeft, onRight }: {\n readonly onLeft: (left: L) => B\n readonly onRight: (right: R) => C\n }): B | C => isLeft(self) ? onLeft(self.left) : onRight(self.right)\n)\n\n/**\n * Transforms a `Predicate` function into a `Right` of the input value if the predicate returns `true`\n * or `Left` of the result of the provided function if the predicate returns false\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * 1,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * 0,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @category lifting\n * @since 3.4.0\n */\nexport const liftPredicate: {\n /**\n * Transforms a `Predicate` function into a `Right` of the input value if the predicate returns `true`\n * or `Left` of the result of the provided function if the predicate returns false\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * 1,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * 0,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @category lifting\n * @since 3.4.0\n */\n <A, B extends A, E>(refinement: Refinement<NoInfer<A>, B>, orLeftWith: (a: NoInfer<A>) => E): (a: A) => Either<B, E>\n /**\n * Transforms a `Predicate` function into a `Right` of the input value if the predicate returns `true`\n * or `Left` of the result of the provided function if the predicate returns false\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * 1,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * 0,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @category lifting\n * @since 3.4.0\n */\n <A, E>(predicate: Predicate<NoInfer<A>>, orLeftWith: (a: NoInfer<A>) => E): (a: A) => Either<A, E>\n /**\n * Transforms a `Predicate` function into a `Right` of the input value if the predicate returns `true`\n * or `Left` of the result of the provided function if the predicate returns false\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * 1,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * 0,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @category lifting\n * @since 3.4.0\n */\n <A, E, B extends A>(self: A, refinement: Refinement<A, B>, orLeftWith: (a: A) => E): Either<B, E>\n /**\n * Transforms a `Predicate` function into a `Right` of the input value if the predicate returns `true`\n * or `Left` of the result of the provided function if the predicate returns false\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * 1,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * 0,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @category lifting\n * @since 3.4.0\n */\n <A, E>(\n self: A,\n predicate: Predicate<NoInfer<A>>,\n orLeftWith: (a: NoInfer<A>) => E\n ): Either<A, E>\n} = dual(\n 3,\n <A, E>(a: A, predicate: Predicate<A>, orLeftWith: (a: A) => E): Either<A, E> =>\n predicate(a) ? right(a) : left(orLeftWith(a))\n)\n\n/**\n * Filter the right value with the provided function.\n * If the predicate fails, set the left value with the result of the provided function.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(1),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(0),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @since 2.0.0\n * @category filtering & conditionals\n */\nexport const filterOrLeft: {\n /**\n * Filter the right value with the provided function.\n * If the predicate fails, set the left value with the result of the provided function.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(1),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(0),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @since 2.0.0\n * @category filtering & conditionals\n */\n <R, B extends R, L2>(\n refinement: Refinement<NoInfer<R>, B>,\n orLeftWith: (right: NoInfer<R>) => L2\n ): <L>(self: Either<R, L>) => Either<B, L2 | L>\n /**\n * Filter the right value with the provided function.\n * If the predicate fails, set the left value with the result of the provided function.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(1),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(0),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @since 2.0.0\n * @category filtering & conditionals\n */\n <R, L2>(\n predicate: Predicate<NoInfer<R>>,\n orLeftWith: (right: NoInfer<R>) => L2\n ): <L>(self: Either<R, L>) => Either<R, L2 | L>\n /**\n * Filter the right value with the provided function.\n * If the predicate fails, set the left value with the result of the provided function.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(1),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(0),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @since 2.0.0\n * @category filtering & conditionals\n */\n <R, L, B extends R, L2>(\n self: Either<R, L>,\n refinement: Refinement<R, B>,\n orLeftWith: (right: R) => L2\n ): Either<B, L | L2>\n /**\n * Filter the right value with the provided function.\n * If the predicate fails, set the left value with the result of the provided function.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(1),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(0),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @since 2.0.0\n * @category filtering & conditionals\n */\n <R, L, E2>(self: Either<R, L>, predicate: Predicate<R>, orLeftWith: (right: R) => E2): Either<R, L | E2>\n} = dual(3, <R, L, E2>(\n self: Either<R, L>,\n predicate: Predicate<R>,\n orLeftWith: (right: R) => E2\n): Either<R, L | E2> => flatMap(self, (r) => predicate(r) ? right(r) : left(orLeftWith(r))))\n\n/**\n * @category getters\n * @since 2.0.0\n */\nexport const merge: <R, L>(self: Either<R, L>) => L | R = match({\n onLeft: identity,\n onRight: identity\n})\n\n/**\n * Returns the wrapped value if it's a `Right` or a default value if is a `Left`.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrElse(Either.right(1), (error) => error + \"!\"), 1)\n * assert.deepStrictEqual(Either.getOrElse(Either.left(\"not a number\"), (error) => error + \"!\"), \"not a number!\")\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrElse: {\n /**\n * Returns the wrapped value if it's a `Right` or a default value if is a `Left`.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrElse(Either.right(1), (error) => error + \"!\"), 1)\n * assert.deepStrictEqual(Either.getOrElse(Either.left(\"not a number\"), (error) => error + \"!\"), \"not a number!\")\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <L, R2>(onLeft: (left: L) => R2): <R>(self: Either<R, L>) => R2 | R\n /**\n * Returns the wrapped value if it's a `Right` or a default value if is a `Left`.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrElse(Either.right(1), (error) => error + \"!\"), 1)\n * assert.deepStrictEqual(Either.getOrElse(Either.left(\"not a number\"), (error) => error + \"!\"), \"not a number!\")\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <R, L, R2>(self: Either<R, L>, onLeft: (left: L) => R2): R | R2\n} = dual(\n 2,\n <R, L, B>(self: Either<R, L>, onLeft: (left: L) => B): R | B => isLeft(self) ? onLeft(self.left) : self.right\n)\n\n/**\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrNull(Either.right(1)), 1)\n * assert.deepStrictEqual(Either.getOrNull(Either.left(\"a\")), null)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrNull: <R, L>(self: Either<R, L>) => R | null = getOrElse(constNull)\n\n/**\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrUndefined(Either.right(1)), 1)\n * assert.deepStrictEqual(Either.getOrUndefined(Either.left(\"a\")), undefined)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrUndefined: <R, L>(self: Either<R, L>) => R | undefined = getOrElse(constUndefined)\n\n/**\n * Extracts the value of an `Either` or throws if the `Either` is `Left`.\n *\n * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.\n *\n * @param self - The `Either` to extract the value from.\n * @param onLeft - A function that will be called if the `Either` is `Left`. It returns the error to be thrown.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Either.getOrThrowWith(Either.right(1), () => new Error('Unexpected Left')),\n * 1\n * )\n * assert.throws(() => Either.getOrThrowWith(Either.left(\"error\"), () => new Error('Unexpected Left')))\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrThrowWith: {\n /**\n * Extracts the value of an `Either` or throws if the `Either` is `Left`.\n *\n * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.\n *\n * @param self - The `Either` to extract the value from.\n * @param onLeft - A function that will be called if the `Either` is `Left`. It returns the error to be thrown.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Either.getOrThrowWith(Either.right(1), () => new Error('Unexpected Left')),\n * 1\n * )\n * assert.throws(() => Either.getOrThrowWith(Either.left(\"error\"), () => new Error('Unexpected Left')))\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <L>(onLeft: (left: L) => unknown): <A>(self: Either<A, L>) => A\n /**\n * Extracts the value of an `Either` or throws if the `Either` is `Left`.\n *\n * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.\n *\n * @param self - The `Either` to extract the value from.\n * @param onLeft - A function that will be called if the `Either` is `Left`. It returns the error to be thrown.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Either.getOrThrowWith(Either.right(1), () => new Error('Unexpected Left')),\n * 1\n * )\n * assert.throws(() => Either.getOrThrowWith(Either.left(\"error\"), () => new Error('Unexpected Left')))\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <R, L>(self: Either<R, L>, onLeft: (left: L) => unknown): R\n} = dual(2, <R, L>(self: Either<R, L>, onLeft: (left: L) => unknown): R => {\n if (isRight(self)) {\n return self.right\n }\n throw onLeft(self.left)\n})\n\n/**\n * Extracts the value of an `Either` or throws if the `Either` is `Left`.\n *\n * The thrown error is a default error. To configure the error thrown, see {@link getOrThrowWith}.\n *\n * @param self - The `Either` to extract the value from.\n * @throws `Error(\"getOrThrow called on a Left\")`\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrThrow(Either.right(1)), 1)\n * assert.throws(() => Either.getOrThrow(Either.left(\"error\")))\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrThrow: <R, L>(self: Either<R, L>) => R = getOrThrowWith(() =>\n new Error(\"getOrThrow called on a Left\")\n)\n\n/**\n * Returns `self` if it is a `Right` or `that` otherwise.\n *\n * @param self - The input `Either` value to check and potentially return.\n * @param that - A function that takes the error value from `self` (if it's a `Left`) and returns a new `Either` value.\n *\n * @category error handling\n * @since 2.0.0\n */\nexport const orElse: {\n /**\n * Returns `self` if it is a `Right` or `that` otherwise.\n *\n * @param self - The input `Either` value to check and potentially return.\n * @param that - A function that takes the error value from `self` (if it's a `Left`) and returns a new `Either` value.\n *\n * @category error handling\n * @since 2.0.0\n */\n <L, R2, L2>(that: (left: L) => Either<R2, L2>): <R>(self: Either<R, L>) => Either<R | R2, L2>\n /**\n * Returns `self` if it is a `Right` or `that` otherwise.\n *\n * @param self - The input `Either` value to check and potentially return.\n * @param that - A function that takes the error value from `self` (if it's a `Left`) and returns a new `Either` value.\n *\n * @category error handling\n * @since 2.0.0\n */\n <R, L, R2, L2>(self: Either<R, L>, that: (left: L) => Either<R2, L2>): Either<R | R2, L2>\n} = dual(\n 2,\n <R1, L1, R2, L2>(self: Either<R1, L1>, that: (left: L1) => Either<R2, L2>): Either<R1 | R2, L2> =>\n isLeft(self) ? that(self.left) : right(self.right)\n)\n\n/**\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatMap: {\n /**\n * @category sequencing\n * @since 2.0.0\n */\n <R, R2, L2>(f: (right: R) => Either<R2, L2>): <L>(self: Either<R, L>) => Either<R2, L | L2>\n /**\n * @category sequencing\n * @since 2.0.0\n */\n <R, L, R2, L2>(self: Either<R, L>, f: (right: R) => Either<R2, L2>): Either<R2, L | L2>\n} = dual(\n 2,\n <R1, L1, R2, L2>(self: Either<R1, L1>, f: (right: R1) => Either<R2, L2>): Either<R2, L1 | L2> =>\n isLeft(self) ? left(self.left) : f(self.right)\n)\n\n/**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const andThen: {\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, R2, L2>(f: (right: R) => Either<R2, L2>): <L>(self: Either<R, L>) => Either<R2, L | L2>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R2, L2>(f: Either<R2, L2>): <L, R1>(self: Either<R1, L>) => Either<R2, L | L2>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, R2>(f: (right: R) => R2): <L>(self: Either<R, L>) => Either<R2, L>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R2>(right: NotFunction<R2>): <R1, L>(self: Either<R1, L>) => Either<R2, L>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, L, R2, L2>(self: Either<R, L>, f: (right: R) => Either<R2, L2>): Either<R2, L | L2>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, L, R2, L2>(self: Either<R, L>, f: Either<R2, L2>): Either<R2, L | L2>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, L, R2>(self: Either<R, L>, f: (right: R) => R2): Either<R2, L>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, L, R2>(self: Either<R, L>, f: NotFunction<R2>): Either<R2, L>\n} = dual(\n 2,\n <R, L, R2, L2>(self: Either<R, L>, f: (right: R) => Either<R2, L2> | Either<R2, L2>): Either<R2, L | L2> =>\n flatMap(self, (a) => {\n const b = isFunction(f) ? f(a) : f\n return isEither(b) ? b : right(b)\n })\n)\n\n/**\n * @category zipping\n * @since 2.0.0\n */\nexport const zipWith: {\n /**\n * @category zipping\n * @since 2.0.0\n */\n <R2, L2, R, B>(that: Either<R2, L2>, f: (right: R, right2: R2) => B): <L>(self: Either<R, L>) => Either<B, L2 | L>\n /**\n * @category zipping\n * @since 2.0.0\n */\n <R, L, R2, L2, B>(self: Either<R, L>, that: Either<R2, L2>, f: (right: R, right2: R2) => B): Either<B, L | L2>\n} = dual(\n 3,\n <R, L, R2, L2, B>(self: Either<R, L>, that: Either<R2, L2>, f: (right: R, right2: R2) => B): Either<B, L | L2> =>\n flatMap(self, (r) => map(that, (r2) => f(r, r2)))\n)\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const ap: {\n /**\n * @category combining\n * @since 2.0.0\n */\n <R, L2>(that: Either<R, L2>): <R2, L>(self: Either<(right: R) => R2, L>) => Either<R2, L | L2>\n /**\n * @category combining\n * @since 2.0.0\n */\n <R, R2, L, L2>(self: Either<(right: R) => R2, L>, that: Either<R, L2>): Either<R2, L | L2>\n} = dual(\n 2,\n <R, R2, L, L2>(self: Either<(right: R) => R2, L>, that: Either<R, L2>): Either<R2, L | L2> =>\n zipWith(self, that, (f, a) => f(a))\n)\n\n/**\n * Takes a structure of `Either`s and returns an `Either` of values with the same structure.\n *\n * - If a tuple is supplied, then the returned `Either` will contain a tuple with the same length.\n * - If a struct is supplied, then the returned `Either` will contain a struct with the same keys.\n * - If an iterable is supplied, then the returned `Either` will contain an array.\n *\n * @param fields - the struct of `Either`s to be sequenced.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.all([Either.right(1), Either.right(2)]), Either.right([1, 2]))\n * assert.deepStrictEqual(Either.all({ right: Either.right(1), b: Either.right(\"hello\") }), Either.right({ right: 1, b: \"hello\" }))\n * assert.deepStrictEqual(Either.all({ right: Either.right(1), b: Either.left(\"error\") }), Either.left(\"error\"))\n * ```\n *\n * @category combining\n * @since 2.0.0\n */\n// @ts-expect-error\nexport const all: <const I extends Iterable<Either<any, any>> | Record<string, Either<any, any>>>(\n input: I\n) => [I] extends [ReadonlyArray<Either<any, any>>] ? Either<\n { -readonly [K in keyof I]: [I[K]] extends [Either<infer R, any>] ? R : never },\n I[number] extends never ? never : [I[number]] extends [Either<any, infer L>] ? L : never\n >\n : [I] extends [Iterable<Either<infer R, infer L>>] ? Either<Array<R>, L>\n : Either<\n { -readonly [K in keyof I]: [I[K]] extends [Either<infer R, any>] ? R : never },\n I[keyof I] extends never ? never : [I[keyof I]] extends [Either<any, infer L>] ? L : never\n > = (\n input: Iterable<Either<any, any>> | Record<string, Either<any, any>>\n ): Either<any, any> => {\n if (Symbol.iterator in input) {\n const out: Array<Either<any, any>> = []\n for (const e of (input as Iterable<Either<any, any>>)) {\n if (isLeft(e)) {\n return e\n }\n out.push(e.right)\n }\n return right(out)\n }\n\n const out: Record<string, any> = {}\n for (const key of Object.keys(input)) {\n const e = input[key]\n if (isLeft(e)) {\n return e\n }\n out[key] = e.right\n }\n return right(out)\n }\n\n/**\n * Returns an `Either` that swaps the error/success cases. This allows you to\n * use all methods on the error channel, possibly before flipping back.\n *\n * @since 2.0.0\n * @category mapping\n */\nexport const flip = <R, L>(self: Either<R, L>): Either<L, R> => isLeft(self) ? right(self.left) : left(self.right)\n\nconst adapter = Gen.adapter<EitherTypeLambda>()\n\n/**\n * @category generators\n * @since 2.0.0\n */\nexport const gen: Gen.Gen<EitherTypeLambda, Gen.Adapter<EitherTypeLambda>> = (...args) => {\n const f = (args.length === 1)\n ? args[0]\n : args[1].bind(args[0])\n const iterator = f(adapter)\n let state: IteratorYieldResult<any> | IteratorReturnResult<any> = iterator.next()\n if (state.done) {\n return right(state.value) as any\n } else {\n let current = state.value\n if (Gen.isGenKind(current)) {\n current = current.value\n } else {\n current = Gen.yieldWrapGet(current)\n }\n if (isLeft(current)) {\n return current\n }\n while (!state.done) {\n state = iterator.next(current.right as never)\n if (!state.done) {\n current = state.value\n if (Gen.isGenKind(current)) {\n current = current.value\n } else {\n current = Gen.yieldWrapGet(current)\n }\n if (isLeft(current)) {\n return current\n }\n }\n }\n return right(state.value)\n }\n}\n\n// -------------------------------------------------------------------------------------\n// do notation\n// -------------------------------------------------------------------------------------\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @see {@link bind}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\nexport const Do: Either<{}> = right({})\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\nexport const bind: {\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <N extends string, A extends object, B, L2>(\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => Either<B, L2>\n ): <L1>(self: Either<A, L1>) => Either<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, L1 | L2>\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <A extends object, L1, N extends string, B, L2>(\n self: Either<A, L1>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => Either<B, L2>\n ): Either<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, L1 | L2>\n} = doNotation.bind<EitherTypeLambda>(map, flatMap)\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\nexport const bindTo: {\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <N extends string>(name: N): <R, L>(self: Either<R, L>) => Either<{ [K in N]: R }, L>\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <R, L, N extends string>(self: Either<R, L>, name: N): Either<{ [K in N]: R }, L>\n} = doNotation.bindTo<EitherTypeLambda>(map)\n\nconst let_: {\n <N extends string, R extends object, B>(\n name: Exclude<N, keyof R>,\n f: (r: NoInfer<R>) => B\n ): <L>(self: Either<R, L>) => Either<{ [K in N | keyof R]: K extends keyof R ? R[K] : B }, L>\n <R extends object, L, N extends string, B>(\n self: Either<R, L>,\n name: Exclude<N, keyof R>,\n f: (r: NoInfer<R>) => B\n ): Either<{ [K in N | keyof R]: K extends keyof R ? R[K] : B }, L>\n} = doNotation.let_<EitherTypeLambda>(map)\n\nexport {\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link bind}\n *\n * @example\n * ```ts\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n *\n * ```\n * @category do notation\n * @since 2.0.0\n */\n let_ as let\n}\n","/**\n * This module provides an implementation of the `Equivalence` type class, which defines a binary relation\n * that is reflexive, symmetric, and transitive. In other words, it defines a notion of equivalence between values of a certain type.\n * These properties are also known in mathematics as an \"equivalence relation\".\n *\n * @since 2.0.0\n */\nimport { dual } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\n\n/**\n * @category type class\n * @since 2.0.0\n */\nexport interface Equivalence<in A> {\n (self: A, that: A): boolean\n}\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface EquivalenceTypeLambda extends TypeLambda {\n readonly type: Equivalence<this[\"Target\"]>\n}\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const make = <A>(isEquivalent: (self: A, that: A) => boolean): Equivalence<A> => (self: A, that: A): boolean =>\n self === that || isEquivalent(self, that)\n\nconst isStrictEquivalent = (x: unknown, y: unknown) => x === y\n\n/**\n * Return an `Equivalence` that uses strict equality (===) to compare values.\n *\n * @since 2.0.0\n * @category constructors\n */\nexport const strict: <A>() => Equivalence<A> = () => isStrictEquivalent\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const string: Equivalence<string> = strict()\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const number: Equivalence<number> = strict()\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const boolean: Equivalence<boolean> = strict()\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const bigint: Equivalence<bigint> = strict()\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const symbol: Equivalence<symbol> = strict()\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const combine: {\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(that: Equivalence<A>): (self: Equivalence<A>) => Equivalence<A>\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(self: Equivalence<A>, that: Equivalence<A>): Equivalence<A>\n} = dual(2, <A>(self: Equivalence<A>, that: Equivalence<A>): Equivalence<A> => make((x, y) => self(x, y) && that(x, y)))\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const combineMany: {\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(collection: Iterable<Equivalence<A>>): (self: Equivalence<A>) => Equivalence<A>\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(self: Equivalence<A>, collection: Iterable<Equivalence<A>>): Equivalence<A>\n} = dual(2, <A>(self: Equivalence<A>, collection: Iterable<Equivalence<A>>): Equivalence<A> =>\n make((x, y) => {\n if (!self(x, y)) {\n return false\n }\n for (const equivalence of collection) {\n if (!equivalence(x, y)) {\n return false\n }\n }\n return true\n }))\n\nconst isAlwaysEquivalent: Equivalence<unknown> = (_x, _y) => true\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const combineAll = <A>(collection: Iterable<Equivalence<A>>): Equivalence<A> =>\n combineMany(isAlwaysEquivalent, collection)\n\n/**\n * @category mapping\n * @since 2.0.0\n */\nexport const mapInput: {\n /**\n * @category mapping\n * @since 2.0.0\n */\n <B, A>(f: (b: B) => A): (self: Equivalence<A>) => Equivalence<B>\n /**\n * @category mapping\n * @since 2.0.0\n */\n <A, B>(self: Equivalence<A>, f: (b: B) => A): Equivalence<B>\n} = dual(\n 2,\n <A, B>(self: Equivalence<A>, f: (b: B) => A): Equivalence<B> => make((x, y) => self(f(x), f(y)))\n)\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const Date: Equivalence<Date> = mapInput(number, (date) => date.getTime())\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const product: {\n <B>(that: Equivalence<B>): <A>(self: Equivalence<A>) => Equivalence<readonly [A, B]> // readonly because invariant\n <A, B>(self: Equivalence<A>, that: Equivalence<B>): Equivalence<readonly [A, B]> // readonly because invariant\n} = dual(\n 2,\n <A, B>(self: Equivalence<A>, that: Equivalence<B>): Equivalence<readonly [A, B]> =>\n make(([xa, xb], [ya, yb]) => self(xa, ya) && that(xb, yb))\n)\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const all = <A>(collection: Iterable<Equivalence<A>>): Equivalence<ReadonlyArray<A>> => {\n return make((x, y) => {\n const len = Math.min(x.length, y.length)\n\n let collectionLength = 0\n for (const equivalence of collection) {\n if (collectionLength >= len) {\n break\n }\n if (!equivalence(x[collectionLength], y[collectionLength])) {\n return false\n }\n collectionLength++\n }\n return true\n })\n}\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const productMany = <A>(\n self: Equivalence<A>,\n collection: Iterable<Equivalence<A>>\n): Equivalence<readonly [A, ...Array<A>]> /* readonly because invariant */ => {\n const equivalence = all(collection)\n return make((x, y) => !self(x[0], y[0]) ? false : equivalence(x.slice(1), y.slice(1)))\n}\n\n/**\n * Similar to `Promise.all` but operates on `Equivalence`s.\n *\n * ```\n * [Equivalence<A>, Equivalence<B>, ...] -> Equivalence<[A, B, ...]>\n * ```\n *\n * Given a tuple of `Equivalence`s returns a new `Equivalence` that compares values of a tuple\n * by applying each `Equivalence` to the corresponding element of the tuple.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const tuple = <T extends ReadonlyArray<Equivalence<any>>>(\n ...elements: T\n): Equivalence<Readonly<{ [I in keyof T]: [T[I]] extends [Equivalence<infer A>] ? A : never }>> => all(elements) as any\n\n/**\n * Creates a new `Equivalence` for an array of values based on a given `Equivalence` for the elements of the array.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const array = <A>(item: Equivalence<A>): Equivalence<ReadonlyArray<A>> =>\n make((self, that) => {\n if (self.length !== that.length) {\n return false\n }\n\n for (let i = 0; i < self.length; i++) {\n const isEq = item(self[i], that[i])\n if (!isEq) {\n return false\n }\n }\n\n return true\n })\n\n/**\n * Given a struct of `Equivalence`s returns a new `Equivalence` that compares values of a struct\n * by applying each `Equivalence` to the corresponding property of the struct.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const struct = <R extends Record<string, Equivalence<any>>>(\n fields: R\n): Equivalence<{ readonly [K in keyof R]: [R[K]] extends [Equivalence<infer A>] ? A : never }> => {\n const keys = Object.keys(fields)\n return make((self, that) => {\n for (const key of keys) {\n if (!fields[key](self[key], that[key])) {\n return false\n }\n }\n return true\n })\n}\n","import { dual } from \"../Function.js\"\nimport type { Kind, TypeLambda } from \"../HKT.js\"\nimport type { NoInfer } from \"../Types.js\"\n\ntype Map<F extends TypeLambda> = {\n <A, B>(f: (a: A) => B): <R, O, E>(self: Kind<F, R, O, E, A>) => Kind<F, R, O, E, B>\n <R, O, E, A, B>(self: Kind<F, R, O, E, A>, f: (a: A) => B): Kind<F, R, O, E, B>\n}\n\ntype FlatMap<F extends TypeLambda> = {\n <A, R2, O2, E2, B>(\n f: (a: A) => Kind<F, R2, O2, E2, B>\n ): <R1, O1, E1>(self: Kind<F, R1, O1, E1, A>) => Kind<F, R1 & R2, O1 | O2, E1 | E2, B>\n <R1, O1, E1, A, R2, O2, E2, B>(\n self: Kind<F, R1, O1, E1, A>,\n f: (a: A) => Kind<F, R2, O2, E2, B>\n ): Kind<F, R1 & R2, O1 | O2, E1 | E2, B>\n}\n\n/** @internal */\nexport const let_ = <F extends TypeLambda>(\n map: Map<F>\n): {\n <N extends string, A extends object, B>(\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): <R, O, E>(\n self: Kind<F, R, O, E, A>\n ) => Kind<F, R, O, E, { [K in keyof A | N]: K extends keyof A ? A[K] : B }>\n <R, O, E, A extends object, N extends string, B>(\n self: Kind<F, R, O, E, A>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): Kind<F, R, O, E, { [K in keyof A | N]: K extends keyof A ? A[K] : B }>\n} =>\n dual(3, <R, O, E, A extends object, N extends string, B>(\n self: Kind<F, R, O, E, A>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): Kind<F, R, O, E, { [K in keyof A | N]: K extends keyof A ? A[K] : B }> =>\n map(self, (a) => Object.assign({}, a, { [name]: f(a) }) as any))\n\n/** @internal */\nexport const bindTo = <F extends TypeLambda>(map: Map<F>): {\n <N extends string>(\n name: N\n ): <R, O, E, A>(self: Kind<F, R, O, E, A>) => Kind<F, R, O, E, { [K in N]: A }>\n <R, O, E, A, N extends string>(\n self: Kind<F, R, O, E, A>,\n name: N\n ): Kind<F, R, O, E, { [K in N]: A }>\n} =>\n dual(2, <R, O, E, A, N extends string>(\n self: Kind<F, R, O, E, A>,\n name: N\n ): Kind<F, R, O, E, { [K in N]: A }> => map(self, (a) => ({ [name]: a } as { [K in N]: A })))\n\n/** @internal */\nexport const bind = <F extends TypeLambda>(map: Map<F>, flatMap: FlatMap<F>): {\n <N extends string, A extends object, R2, O2, E2, B>(\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => Kind<F, R2, O2, E2, B>\n ): <R1, O1, E1>(\n self: Kind<F, R1, O1, E1, A>\n ) => Kind<F, R1 & R2, O1 | O2, E1 | E2, { [K in keyof A | N]: K extends keyof A ? A[K] : B }>\n <R1, O1, E1, A extends object, N extends string, R2, O2, E2, B>(\n self: Kind<F, R1, O1, E1, A>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => Kind<F, R2, O2, E2, B>\n ): Kind<F, R1 & R2, O1 | O2, E1 | E2, { [K in keyof A | N]: K extends keyof A ? A[K] : B }>\n} =>\n dual(3, <R1, O1, E1, A, N extends string, R2, O2, E2, B>(\n self: Kind<F, R1, O1, E1, A>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => Kind<F, R2, O2, E2, B>\n ): Kind<F, R1 & R2, O1 | O2, E1 | E2, { [K in keyof A | N]: K extends keyof A ? A[K] : B }> =>\n flatMap(self, (a) =>\n map(f(a), (b) => Object.assign({}, a, { [name]: b }) as { [K in keyof A | N]: K extends keyof A ? A[K] : B })))\n","let moduleVersion = \"3.12.5\"\n\nexport const getCurrentVersion = () => moduleVersion\n\nexport const setCurrentVersion = (version: string) => {\n moduleVersion = version\n}\n","/**\n * The `GlobalValue` module ensures that a single instance of a value is created globally,\n * even when modules are imported multiple times (e.g., due to mixing CommonJS and ESM builds)\n * or during hot-reloading in development environments like Next.js or Remix.\n *\n * It achieves this by using a versioned global store, identified by a unique `Symbol` tied to\n * the current version of the `effect` library. The store holds values that are keyed by an identifier,\n * allowing the reuse of previously computed instances across imports or reloads.\n *\n * This pattern is particularly useful in scenarios where frequent reloading can cause services or\n * single-instance objects to be recreated unnecessarily, such as in development environments with hot-reloading.\n *\n * @since 2.0.0\n */\nimport * as version from \"./internal/version.js\"\n\nconst globalStoreId = `effect/GlobalValue/globalStoreId/${version.getCurrentVersion()}`\n\nlet globalStore: Map<unknown, any>\n\n/**\n * Retrieves or computes a global value associated with the given `id`. If the value for this `id`\n * has already been computed, it will be returned from the global store. If it does not exist yet,\n * the provided `compute` function will be executed to compute the value, store it, and then return it.\n *\n * This ensures that even in cases where the module is imported multiple times (e.g., in mixed environments\n * like CommonJS and ESM, or during hot-reloading in development), the value is computed only once and reused\n * thereafter.\n *\n * @example\n * ```ts\n * import { globalValue } from \"effect/GlobalValue\"\n *\n * // This cache will persist as long as the module is running,\n * // even if reloaded or imported elsewhere\n * const myCache = globalValue(\n * Symbol.for(\"myCache\"),\n * () => new WeakMap<object, number>()\n * )\n * ```\n *\n * @since 2.0.0\n */\nexport const globalValue = <A>(id: unknown, compute: () => A): A => {\n if (!globalStore) {\n // @ts-expect-error\n globalThis[globalStoreId] ??= new Map()\n // @ts-expect-error\n globalStore = globalThis[globalStoreId] as Map<unknown, any>\n }\n if (!globalStore.has(id)) {\n globalStore.set(id, compute())\n }\n return globalStore.get(id)!\n}\n","/**\n * @since 2.0.0\n */\nimport { dual, isFunction as isFunction_ } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\nimport type { TupleOf, TupleOfAtLeast } from \"./Types.js\"\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Predicate<in A> {\n (a: A): boolean\n}\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface PredicateTypeLambda extends TypeLambda {\n readonly type: Predicate<this[\"Target\"]>\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Refinement<in A, out B extends A> {\n (a: A): a is B\n}\n\n/**\n * @since 3.6.0\n * @category type-level\n */\nexport declare namespace Predicate {\n /**\n * @since 3.6.0\n * @category type-level\n */\n export type In<T extends Any> = [T] extends [Predicate<infer _A>] ? _A : never\n /**\n * @since 3.6.0\n * @category type-level\n */\n export type Any = Predicate<never>\n}\n\n/**\n * @since 3.6.0\n * @category type-level\n */\nexport declare namespace Refinement {\n /**\n * @since 3.6.0\n * @category type-level\n */\n export type In<T extends Any> = [T] extends [Refinement<infer _A, infer _>] ? _A : never\n /**\n * @since 3.6.0\n * @category type-level\n */\n export type Out<T extends Any> = [T] extends [Refinement<infer _, infer _B>] ? _B : never\n /**\n * @since 3.6.0\n * @category type-level\n */\n export type Any = Refinement<any, any>\n}\n\n/**\n * Given a `Predicate<A>` returns a `Predicate<B>`\n *\n * @param self - the `Predicate<A>` to be transformed to `Predicate<B>`.\n * @param f - a function to transform `B` to `A`.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const minLength3 = Predicate.mapInput(Number.greaterThan(2), (s: string) => s.length)\n *\n * assert.deepStrictEqual(minLength3(\"a\"), false)\n * assert.deepStrictEqual(minLength3(\"aa\"), false)\n * assert.deepStrictEqual(minLength3(\"aaa\"), true)\n * assert.deepStrictEqual(minLength3(\"aaaa\"), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const mapInput: {\n /**\n * Given a `Predicate<A>` returns a `Predicate<B>`\n *\n * @param self - the `Predicate<A>` to be transformed to `Predicate<B>`.\n * @param f - a function to transform `B` to `A`.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const minLength3 = Predicate.mapInput(Number.greaterThan(2), (s: string) => s.length)\n *\n * assert.deepStrictEqual(minLength3(\"a\"), false)\n * assert.deepStrictEqual(minLength3(\"aa\"), false)\n * assert.deepStrictEqual(minLength3(\"aaa\"), true)\n * assert.deepStrictEqual(minLength3(\"aaaa\"), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <B, A>(f: (b: B) => A): (self: Predicate<A>) => Predicate<B>\n /**\n * Given a `Predicate<A>` returns a `Predicate<B>`\n *\n * @param self - the `Predicate<A>` to be transformed to `Predicate<B>`.\n * @param f - a function to transform `B` to `A`.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const minLength3 = Predicate.mapInput(Number.greaterThan(2), (s: string) => s.length)\n *\n * assert.deepStrictEqual(minLength3(\"a\"), false)\n * assert.deepStrictEqual(minLength3(\"aa\"), false)\n * assert.deepStrictEqual(minLength3(\"aaa\"), true)\n * assert.deepStrictEqual(minLength3(\"aaaa\"), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A, B>(self: Predicate<A>, f: (b: B) => A): Predicate<B>\n} = dual(2, <A, B>(self: Predicate<A>, f: (b: B) => A): Predicate<B> => (b) => self(f(b)))\n\n/**\n * Determine if an `Array` is a tuple with exactly `N` elements, narrowing down the type to `TupleOf`.\n *\n * An `Array` is considered to be a `TupleOf` if its length is exactly `N`.\n *\n * @param self - The `Array` to check.\n * @param n - The exact number of elements that the `Array` should have to be considered a `TupleOf`.\n *\n * @example\n * ```ts\n * import { isTupleOf } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 3), true);\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 2), false);\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 4), false);\n *\n * const arr: number[] = [1, 2, 3];\n * if (isTupleOf(arr, 3)) {\n * console.log(arr);\n * // ^? [number, number, number]\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\nexport const isTupleOf: {\n /**\n * Determine if an `Array` is a tuple with exactly `N` elements, narrowing down the type to `TupleOf`.\n *\n * An `Array` is considered to be a `TupleOf` if its length is exactly `N`.\n *\n * @param self - The `Array` to check.\n * @param n - The exact number of elements that the `Array` should have to be considered a `TupleOf`.\n *\n * @example\n * ```ts\n * import { isTupleOf } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 3), true);\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 2), false);\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 4), false);\n *\n * const arr: number[] = [1, 2, 3];\n * if (isTupleOf(arr, 3)) {\n * console.log(arr);\n * // ^? [number, number, number]\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\n <N extends number>(n: N): <T>(self: ReadonlyArray<T>) => self is TupleOf<N, T>\n /**\n * Determine if an `Array` is a tuple with exactly `N` elements, narrowing down the type to `TupleOf`.\n *\n * An `Array` is considered to be a `TupleOf` if its length is exactly `N`.\n *\n * @param self - The `Array` to check.\n * @param n - The exact number of elements that the `Array` should have to be considered a `TupleOf`.\n *\n * @example\n * ```ts\n * import { isTupleOf } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 3), true);\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 2), false);\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 4), false);\n *\n * const arr: number[] = [1, 2, 3];\n * if (isTupleOf(arr, 3)) {\n * console.log(arr);\n * // ^? [number, number, number]\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\n <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T>\n} = dual(2, <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T> => self.length === n)\n\n/**\n * Determine if an `Array` is a tuple with at least `N` elements, narrowing down the type to `TupleOfAtLeast`.\n *\n * An `Array` is considered to be a `TupleOfAtLeast` if its length is at least `N`.\n *\n * @param self - The `Array` to check.\n * @param n - The minimum number of elements that the `Array` should have to be considered a `TupleOfAtLeast`.\n *\n * @example\n * ```ts\n * import { isTupleOfAtLeast } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 3), true);\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 2), true);\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 4), false);\n *\n * const arr: number[] = [1, 2, 3, 4];\n * if (isTupleOfAtLeast(arr, 3)) {\n * console.log(arr);\n * // ^? [number, number, number, ...number[]]\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\nexport const isTupleOfAtLeast: {\n /**\n * Determine if an `Array` is a tuple with at least `N` elements, narrowing down the type to `TupleOfAtLeast`.\n *\n * An `Array` is considered to be a `TupleOfAtLeast` if its length is at least `N`.\n *\n * @param self - The `Array` to check.\n * @param n - The minimum number of elements that the `Array` should have to be considered a `TupleOfAtLeast`.\n *\n * @example\n * ```ts\n * import { isTupleOfAtLeast } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 3), true);\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 2), true);\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 4), false);\n *\n * const arr: number[] = [1, 2, 3, 4];\n * if (isTupleOfAtLeast(arr, 3)) {\n * console.log(arr);\n * // ^? [number, number, number, ...number[]]\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\n <N extends number>(n: N): <T>(self: ReadonlyArray<T>) => self is TupleOfAtLeast<N, T>\n /**\n * Determine if an `Array` is a tuple with at least `N` elements, narrowing down the type to `TupleOfAtLeast`.\n *\n * An `Array` is considered to be a `TupleOfAtLeast` if its length is at least `N`.\n *\n * @param self - The `Array` to check.\n * @param n - The minimum number of elements that the `Array` should have to be considered a `TupleOfAtLeast`.\n *\n * @example\n * ```ts\n * import { isTupleOfAtLeast } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 3), true);\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 2), true);\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 4), false);\n *\n * const arr: number[] = [1, 2, 3, 4];\n * if (isTupleOfAtLeast(arr, 3)) {\n * console.log(arr);\n * // ^? [number, number, number, ...number[]]\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\n <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOfAtLeast<N, T>\n} = dual(2, <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOfAtLeast<N, T> => self.length >= n)\n\n/**\n * Tests if a value is `truthy`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isTruthy } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTruthy(1), true)\n * assert.deepStrictEqual(isTruthy(0), false)\n * assert.deepStrictEqual(isTruthy(\"\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isTruthy = (input: unknown) => !!input\n\n/**\n * Tests if a value is a `Set`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isSet } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isSet(new Set([1, 2])), true)\n * assert.deepStrictEqual(isSet(new Set()), true)\n * assert.deepStrictEqual(isSet({}), false)\n * assert.deepStrictEqual(isSet(null), false)\n * assert.deepStrictEqual(isSet(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isSet = (input: unknown): input is Set<unknown> => input instanceof Set\n\n/**\n * Tests if a value is a `Map`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isMap } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isMap(new Map()), true)\n * assert.deepStrictEqual(isMap({}), false)\n * assert.deepStrictEqual(isMap(null), false)\n * assert.deepStrictEqual(isMap(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isMap = (input: unknown): input is Map<unknown, unknown> => input instanceof Map\n\n/**\n * Tests if a value is a `string`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isString } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isString(\"a\"), true)\n *\n * assert.deepStrictEqual(isString(1), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isString = (input: unknown): input is string => typeof input === \"string\"\n\n/**\n * Tests if a value is a `number`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isNumber } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNumber(2), true)\n *\n * assert.deepStrictEqual(isNumber(\"2\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNumber = (input: unknown): input is number => typeof input === \"number\"\n\n/**\n * Tests if a value is a `boolean`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isBoolean } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isBoolean(true), true)\n *\n * assert.deepStrictEqual(isBoolean(\"true\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isBoolean = (input: unknown): input is boolean => typeof input === \"boolean\"\n\n/**\n * Tests if a value is a `bigint`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isBigInt } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isBigInt(1n), true)\n *\n * assert.deepStrictEqual(isBigInt(1), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isBigInt = (input: unknown): input is bigint => typeof input === \"bigint\"\n\n/**\n * Tests if a value is a `symbol`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isSymbol } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isSymbol(Symbol.for(\"a\")), true)\n *\n * assert.deepStrictEqual(isSymbol(\"a\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isSymbol = (input: unknown): input is symbol => typeof input === \"symbol\"\n\n/**\n * Tests if a value is a `function`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isFunction } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isFunction(isFunction), true)\n *\n * assert.deepStrictEqual(isFunction(\"function\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isFunction: (input: unknown) => input is Function = isFunction_\n\n/**\n * Tests if a value is `undefined`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isUndefined } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isUndefined(undefined), true)\n *\n * assert.deepStrictEqual(isUndefined(null), false)\n * assert.deepStrictEqual(isUndefined(\"undefined\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isUndefined = (input: unknown): input is undefined => input === undefined\n\n/**\n * Tests if a value is not `undefined`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isNotUndefined } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNotUndefined(null), true)\n * assert.deepStrictEqual(isNotUndefined(\"undefined\"), true)\n *\n * assert.deepStrictEqual(isNotUndefined(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNotUndefined = <A>(input: A): input is Exclude<A, undefined> => input !== undefined\n\n/**\n * Tests if a value is `null`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isNull } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNull(null), true)\n *\n * assert.deepStrictEqual(isNull(undefined), false)\n * assert.deepStrictEqual(isNull(\"null\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNull = (input: unknown): input is null => input === null\n\n/**\n * Tests if a value is not `null`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isNotNull } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNotNull(undefined), true)\n * assert.deepStrictEqual(isNotNull(\"null\"), true)\n *\n * assert.deepStrictEqual(isNotNull(null), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNotNull = <A>(input: A): input is Exclude<A, null> => input !== null\n\n/**\n * A guard that always fails.\n *\n * @param _ - The value to test.\n *\n * @example\n * ```ts\n * import { isNever } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNever(null), false)\n * assert.deepStrictEqual(isNever(undefined), false)\n * assert.deepStrictEqual(isNever({}), false)\n * assert.deepStrictEqual(isNever([]), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNever: (input: unknown) => input is never = (_: unknown): _ is never => false\n\n/**\n * A guard that always succeeds.\n *\n * @param _ - The value to test.\n *\n * @example\n * ```ts\n * import { isUnknown } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isUnknown(null), true)\n * assert.deepStrictEqual(isUnknown(undefined), true)\n *\n * assert.deepStrictEqual(isUnknown({}), true)\n * assert.deepStrictEqual(isUnknown([]), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isUnknown: (input: unknown) => input is unknown = (_): _ is unknown => true\n\n/** @internal */\nexport const isRecordOrArray = (input: unknown): input is { [x: PropertyKey]: unknown } =>\n typeof input === \"object\" && input !== null\n\n/**\n * Tests if a value is an `object`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isObject } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isObject({}), true)\n * assert.deepStrictEqual(isObject([]), true)\n *\n * assert.deepStrictEqual(isObject(null), false)\n * assert.deepStrictEqual(isObject(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isObject = (input: unknown): input is object => isRecordOrArray(input) || isFunction(input)\n\n/**\n * Checks whether a value is an `object` containing a specified property key.\n *\n * @param property - The field to check within the object.\n * @param self - The value to examine.\n *\n * @category guards\n * @since 2.0.0\n */\nexport const hasProperty: {\n /**\n * Checks whether a value is an `object` containing a specified property key.\n *\n * @param property - The field to check within the object.\n * @param self - The value to examine.\n *\n * @category guards\n * @since 2.0.0\n */\n <P extends PropertyKey>(property: P): (self: unknown) => self is { [K in P]: unknown }\n /**\n * Checks whether a value is an `object` containing a specified property key.\n *\n * @param property - The field to check within the object.\n * @param self - The value to examine.\n *\n * @category guards\n * @since 2.0.0\n */\n <P extends PropertyKey>(self: unknown, property: P): self is { [K in P]: unknown }\n} = dual(\n 2,\n <P extends PropertyKey>(self: unknown, property: P): self is { [K in P]: unknown } =>\n isObject(self) && (property in self)\n)\n\n/**\n * Tests if a value is an `object` with a property `_tag` that matches the given tag.\n *\n * @param input - The value to test.\n * @param tag - The tag to test for.\n *\n * @example\n * ```ts\n * import { isTagged } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTagged(1, \"a\"), false)\n * assert.deepStrictEqual(isTagged(null, \"a\"), false)\n * assert.deepStrictEqual(isTagged({}, \"a\"), false)\n * assert.deepStrictEqual(isTagged({ a: \"a\" }, \"a\"), false)\n * assert.deepStrictEqual(isTagged({ _tag: \"a\" }, \"a\"), true)\n * assert.deepStrictEqual(isTagged(\"a\")({ _tag: \"a\" }), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isTagged: {\n /**\n * Tests if a value is an `object` with a property `_tag` that matches the given tag.\n *\n * @param input - The value to test.\n * @param tag - The tag to test for.\n *\n * @example\n * ```ts\n * import { isTagged } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTagged(1, \"a\"), false)\n * assert.deepStrictEqual(isTagged(null, \"a\"), false)\n * assert.deepStrictEqual(isTagged({}, \"a\"), false)\n * assert.deepStrictEqual(isTagged({ a: \"a\" }, \"a\"), false)\n * assert.deepStrictEqual(isTagged({ _tag: \"a\" }, \"a\"), true)\n * assert.deepStrictEqual(isTagged(\"a\")({ _tag: \"a\" }), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\n <K extends string>(tag: K): (self: unknown) => self is { _tag: K }\n /**\n * Tests if a value is an `object` with a property `_tag` that matches the given tag.\n *\n * @param input - The value to test.\n * @param tag - The tag to test for.\n *\n * @example\n * ```ts\n * import { isTagged } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTagged(1, \"a\"), false)\n * assert.deepStrictEqual(isTagged(null, \"a\"), false)\n * assert.deepStrictEqual(isTagged({}, \"a\"), false)\n * assert.deepStrictEqual(isTagged({ a: \"a\" }, \"a\"), false)\n * assert.deepStrictEqual(isTagged({ _tag: \"a\" }, \"a\"), true)\n * assert.deepStrictEqual(isTagged(\"a\")({ _tag: \"a\" }), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\n <K extends string>(self: unknown, tag: K): self is { _tag: K }\n} = dual(\n 2,\n <K extends string>(self: unknown, tag: K): self is { _tag: K } => hasProperty(self, \"_tag\") && self[\"_tag\"] === tag\n)\n\n/**\n * A guard that succeeds when the input is `null` or `undefined`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isNullable } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNullable(null), true)\n * assert.deepStrictEqual(isNullable(undefined), true)\n *\n * assert.deepStrictEqual(isNullable({}), false)\n * assert.deepStrictEqual(isNullable([]), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNullable = <A>(input: A): input is Extract<A, null | undefined> => input === null || input === undefined\n\n/**\n * A guard that succeeds when the input is not `null` or `undefined`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isNotNullable } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNotNullable({}), true)\n * assert.deepStrictEqual(isNotNullable([]), true)\n *\n * assert.deepStrictEqual(isNotNullable(null), false)\n * assert.deepStrictEqual(isNotNullable(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNotNullable = <A>(input: A): input is NonNullable<A> => input !== null && input !== undefined\n\n/**\n * A guard that succeeds when the input is an `Error`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isError } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isError(new Error()), true)\n *\n * assert.deepStrictEqual(isError(null), false)\n * assert.deepStrictEqual(isError({}), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isError = (input: unknown): input is Error => input instanceof Error\n\n/**\n * A guard that succeeds when the input is a `Uint8Array`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isUint8Array } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isUint8Array(new Uint8Array()), true)\n *\n * assert.deepStrictEqual(isUint8Array(null), false)\n * assert.deepStrictEqual(isUint8Array({}), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isUint8Array = (input: unknown): input is Uint8Array => input instanceof Uint8Array\n\n/**\n * A guard that succeeds when the input is a `Date`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isDate } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isDate(new Date()), true)\n *\n * assert.deepStrictEqual(isDate(null), false)\n * assert.deepStrictEqual(isDate({}), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isDate = (input: unknown): input is Date => input instanceof Date\n\n/**\n * A guard that succeeds when the input is an `Iterable`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isIterable } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isIterable([]), true)\n * assert.deepStrictEqual(isIterable(new Set()), true)\n *\n * assert.deepStrictEqual(isIterable(null), false)\n * assert.deepStrictEqual(isIterable({}), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isIterable = (input: unknown): input is Iterable<unknown> => hasProperty(input, Symbol.iterator)\n\n/**\n * A guard that succeeds when the input is a record.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isRecord } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isRecord({}), true)\n * assert.deepStrictEqual(isRecord({ a: 1 }), true)\n *\n * assert.deepStrictEqual(isRecord([]), false)\n * assert.deepStrictEqual(isRecord([1, 2, 3]), false)\n * assert.deepStrictEqual(isRecord(null), false)\n * assert.deepStrictEqual(isRecord(undefined), false)\n * assert.deepStrictEqual(isRecord(() => null), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isRecord = (input: unknown): input is { [x: string | symbol]: unknown } =>\n isRecordOrArray(input) && !Array.isArray(input)\n\n/**\n * A guard that succeeds when the input is a readonly record.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isReadonlyRecord } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isReadonlyRecord({}), true)\n * assert.deepStrictEqual(isReadonlyRecord({ a: 1 }), true)\n *\n * assert.deepStrictEqual(isReadonlyRecord([]), false)\n * assert.deepStrictEqual(isReadonlyRecord([1, 2, 3]), false)\n * assert.deepStrictEqual(isReadonlyRecord(null), false)\n * assert.deepStrictEqual(isReadonlyRecord(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isReadonlyRecord: (\n input: unknown\n) => input is { readonly [x: string | symbol]: unknown } = isRecord\n\n/**\n * A guard that succeeds when the input is a Promise.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isPromise } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isPromise({}), false)\n * assert.deepStrictEqual(isPromise(Promise.resolve(\"hello\")), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isPromise = (\n input: unknown\n): input is Promise<unknown> =>\n hasProperty(input, \"then\") && \"catch\" in input && isFunction(input.then) && isFunction(input.catch)\n\n/**\n * @category guards\n * @since 2.0.0\n */\nexport const isPromiseLike = (\n input: unknown\n): input is PromiseLike<unknown> => hasProperty(input, \"then\") && isFunction(input.then)\n\n/**\n * Tests if a value is a `RegExp`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * assert.deepStrictEqual(Predicate.isRegExp(/a/), true)\n * assert.deepStrictEqual(Predicate.isRegExp(\"a\"), false)\n * ```\n *\n * @category guards\n * @since 3.9.0\n */\nexport const isRegExp = (input: unknown): input is RegExp => input instanceof RegExp\n\n/**\n * @since 2.0.0\n */\nexport const compose: {\n /**\n * @since 2.0.0\n */\n <A, B extends A, C extends B>(bc: Refinement<B, C>): (ab: Refinement<A, B>) => Refinement<A, C>\n /**\n * @since 2.0.0\n */\n <A, B extends A>(bc: Predicate<NoInfer<B>>): (ab: Refinement<A, B>) => Refinement<A, B>\n /**\n * @since 2.0.0\n */\n <A, B extends A, C extends B>(ab: Refinement<A, B>, bc: Refinement<B, C>): Refinement<A, C>\n /**\n * @since 2.0.0\n */\n <A, B extends A>(ab: Refinement<A, B>, bc: Predicate<NoInfer<B>>): Refinement<A, B>\n} = dual(\n 2,\n <A, B extends A, C extends B>(ab: Refinement<A, B>, bc: Refinement<B, C>): Refinement<A, C> => (a): a is C =>\n ab(a) && bc(a)\n)\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const product =\n <A, B>(self: Predicate<A>, that: Predicate<B>): Predicate<readonly [A, B]> /* readonly because contravariant */ =>\n ([a, b]) => self(a) && that(b)\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const all = <A>(\n collection: Iterable<Predicate<A>>\n): Predicate<ReadonlyArray<A>> => {\n return (as) => {\n let collectionIndex = 0\n for (const p of collection) {\n if (collectionIndex >= as.length) {\n break\n }\n if (p(as[collectionIndex]) === false) {\n return false\n }\n collectionIndex++\n }\n return true\n }\n}\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const productMany = <A>(\n self: Predicate<A>,\n collection: Iterable<Predicate<A>>\n): Predicate<readonly [A, ...Array<A>]> /* readonly because contravariant */ => {\n const rest = all(collection)\n return ([head, ...tail]) => self(head) === false ? false : rest(tail)\n}\n\n/**\n * Similar to `Promise.all` but operates on `Predicate`s.\n *\n * ```\n * [Refinement<A, B>, Refinement<C, D>, ...] -> Refinement<[A, C, ...], [B, D, ...]>\n * [Predicate<A>, Predicate<B>, ...] -> Predicate<[A, B, ...]>\n * [Refinement<A, B>, Predicate<C>, ...] -> Refinement<[A, C, ...], [B, C, ...]>\n * ```\n *\n * @since 2.0.0\n */\nexport const tuple: {\n /**\n * Similar to `Promise.all` but operates on `Predicate`s.\n *\n * ```\n * [Refinement<A, B>, Refinement<C, D>, ...] -> Refinement<[A, C, ...], [B, D, ...]>\n * [Predicate<A>, Predicate<B>, ...] -> Predicate<[A, B, ...]>\n * [Refinement<A, B>, Predicate<C>, ...] -> Refinement<[A, C, ...], [B, C, ...]>\n * ```\n *\n * @since 2.0.0\n */\n <T extends ReadonlyArray<Predicate.Any>>(\n ...elements: T\n ): [Extract<T[number], Refinement.Any>] extends [never] ? Predicate<{ readonly [I in keyof T]: Predicate.In<T[I]> }>\n : Refinement<\n { readonly [I in keyof T]: T[I] extends Refinement.Any ? Refinement.In<T[I]> : Predicate.In<T[I]> },\n { readonly [I in keyof T]: T[I] extends Refinement.Any ? Refinement.Out<T[I]> : Predicate.In<T[I]> }\n >\n} = (...elements: ReadonlyArray<Predicate.Any>) => all(elements) as any\n\n/**\n * ```\n * { ab: Refinement<A, B>; cd: Refinement<C, D>, ... } -> Refinement<{ ab: A; cd: C; ... }, { ab: B; cd: D; ... }>\n * { a: Predicate<A, B>; b: Predicate<B>, ... } -> Predicate<{ a: A; b: B; ... }>\n * { ab: Refinement<A, B>; c: Predicate<C>, ... } -> Refinement<{ ab: A; c: C; ... }, { ab: B; c: С; ... }>\n * ```\n *\n * @since 2.0.0\n */\nexport const struct: {\n /**\n * ```\n * { ab: Refinement<A, B>; cd: Refinement<C, D>, ... } -> Refinement<{ ab: A; cd: C; ... }, { ab: B; cd: D; ... }>\n * { a: Predicate<A, B>; b: Predicate<B>, ... } -> Predicate<{ a: A; b: B; ... }>\n * { ab: Refinement<A, B>; c: Predicate<C>, ... } -> Refinement<{ ab: A; c: C; ... }, { ab: B; c: С; ... }>\n * ```\n *\n * @since 2.0.0\n */\n <R extends Record<string, Predicate.Any>>(\n fields: R\n ): [Extract<R[keyof R], Refinement.Any>] extends [never] ?\n Predicate<{ readonly [K in keyof R]: Predicate.In<R[K]> }> :\n Refinement<\n { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.In<R[K]> : Predicate.In<R[K]> },\n { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.Out<R[K]> : Predicate.In<R[K]> }\n >\n} = (<R extends Record<string, Predicate.Any>>(fields: R) => {\n const keys = Object.keys(fields)\n return (a: Record<string, unknown>) => {\n for (const key of keys) {\n if (!fields[key](a[key] as never)) {\n return false\n }\n }\n return true\n }\n}) as any\n\n/**\n * Negates the result of a given predicate.\n *\n * @param self - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const isPositive = Predicate.not(Number.lessThan(0))\n *\n * assert.deepStrictEqual(isPositive(-1), false)\n * assert.deepStrictEqual(isPositive(0), true)\n * assert.deepStrictEqual(isPositive(1), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const not = <A>(self: Predicate<A>): Predicate<A> => (a) => !self(a)\n\n/**\n * Combines two predicates into a new predicate that returns `true` if at least one of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const nonZero = Predicate.or(Number.lessThan(0), Number.greaterThan(0))\n *\n * assert.deepStrictEqual(nonZero(-1), true)\n * assert.deepStrictEqual(nonZero(0), false)\n * assert.deepStrictEqual(nonZero(1), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const or: {\n /**\n * Combines two predicates into a new predicate that returns `true` if at least one of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const nonZero = Predicate.or(Number.lessThan(0), Number.greaterThan(0))\n *\n * assert.deepStrictEqual(nonZero(-1), true)\n * assert.deepStrictEqual(nonZero(0), false)\n * assert.deepStrictEqual(nonZero(1), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A, C extends A>(that: Refinement<A, C>): <B extends A>(self: Refinement<A, B>) => Refinement<A, B | C>\n /**\n * Combines two predicates into a new predicate that returns `true` if at least one of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const nonZero = Predicate.or(Number.lessThan(0), Number.greaterThan(0))\n *\n * assert.deepStrictEqual(nonZero(-1), true)\n * assert.deepStrictEqual(nonZero(0), false)\n * assert.deepStrictEqual(nonZero(1), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A, B extends A, C extends A>(self: Refinement<A, B>, that: Refinement<A, C>): Refinement<A, B | C>\n /**\n * Combines two predicates into a new predicate that returns `true` if at least one of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const nonZero = Predicate.or(Number.lessThan(0), Number.greaterThan(0))\n *\n * assert.deepStrictEqual(nonZero(-1), true)\n * assert.deepStrictEqual(nonZero(0), false)\n * assert.deepStrictEqual(nonZero(1), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>\n /**\n * Combines two predicates into a new predicate that returns `true` if at least one of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const nonZero = Predicate.or(Number.lessThan(0), Number.greaterThan(0))\n *\n * assert.deepStrictEqual(nonZero(-1), true)\n * assert.deepStrictEqual(nonZero(0), false)\n * assert.deepStrictEqual(nonZero(1), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>\n} = dual(2, <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => self(a) || that(a))\n\n/**\n * Combines two predicates into a new predicate that returns `true` if both of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * const minLength = (n: number) => (s: string) => s.length >= n\n * const maxLength = (n: number) => (s: string) => s.length <= n\n *\n * const length = (n: number) => Predicate.and(minLength(n), maxLength(n))\n *\n * assert.deepStrictEqual(length(2)(\"aa\"), true)\n * assert.deepStrictEqual(length(2)(\"a\"), false)\n * assert.deepStrictEqual(length(2)(\"aaa\"), false)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const and: {\n /**\n * Combines two predicates into a new predicate that returns `true` if both of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * const minLength = (n: number) => (s: string) => s.length >= n\n * const maxLength = (n: number) => (s: string) => s.length <= n\n *\n * const length = (n: number) => Predicate.and(minLength(n), maxLength(n))\n *\n * assert.deepStrictEqual(length(2)(\"aa\"), true)\n * assert.deepStrictEqual(length(2)(\"a\"), false)\n * assert.deepStrictEqual(length(2)(\"aaa\"), false)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A, C extends A>(that: Refinement<A, C>): <B extends A>(self: Refinement<A, B>) => Refinement<A, B & C>\n /**\n * Combines two predicates into a new predicate that returns `true` if both of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * const minLength = (n: number) => (s: string) => s.length >= n\n * const maxLength = (n: number) => (s: string) => s.length <= n\n *\n * const length = (n: number) => Predicate.and(minLength(n), maxLength(n))\n *\n * assert.deepStrictEqual(length(2)(\"aa\"), true)\n * assert.deepStrictEqual(length(2)(\"a\"), false)\n * assert.deepStrictEqual(length(2)(\"aaa\"), false)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A, B extends A, C extends A>(self: Refinement<A, B>, that: Refinement<A, C>): Refinement<A, B & C>\n /**\n * Combines two predicates into a new predicate that returns `true` if both of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * const minLength = (n: number) => (s: string) => s.length >= n\n * const maxLength = (n: number) => (s: string) => s.length <= n\n *\n * const length = (n: number) => Predicate.and(minLength(n), maxLength(n))\n *\n * assert.deepStrictEqual(length(2)(\"aa\"), true)\n * assert.deepStrictEqual(length(2)(\"a\"), false)\n * assert.deepStrictEqual(length(2)(\"aaa\"), false)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>\n /**\n * Combines two predicates into a new predicate that returns `true` if both of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * const minLength = (n: number) => (s: string) => s.length >= n\n * const maxLength = (n: number) => (s: string) => s.length <= n\n *\n * const length = (n: number) => Predicate.and(minLength(n), maxLength(n))\n *\n * assert.deepStrictEqual(length(2)(\"aa\"), true)\n * assert.deepStrictEqual(length(2)(\"a\"), false)\n * assert.deepStrictEqual(length(2)(\"aaa\"), false)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>\n} = dual(2, <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => self(a) && that(a))\n\n/**\n * @category combinators\n * @since 2.0.0\n */\nexport const xor: {\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>\n} = dual(2, <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => self(a) !== that(a))\n\n/**\n * @category combinators\n * @since 2.0.0\n */\nexport const eqv: {\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>\n} = dual(2, <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => self(a) === that(a))\n\n/**\n * Represents the logical implication combinator for predicates. In formal\n * logic, the implication operator `->` denotes that if the first proposition\n * (antecedent) is true, then the second proposition (consequent) must also be\n * true. In simpler terms, `p implies q` can be interpreted as \"if p then q\". If\n * the first predicate holds, then the second predicate must hold\n * for the given context.\n *\n * In practical terms within TypeScript, `p implies q` is equivalent to `!p || (p && q)`.\n *\n * Note that if the antecedent is `false`, the result is `true` by default\n * because the outcome of the consequent cannot be determined.\n *\n * This function is useful in situations where you need to enforce rules or\n * constraints that are contingent on certain conditions.\n * It proves especially helpful in defining property tests.\n *\n * The example below illustrates the transitive property of order using the\n * `implies` function. In simple terms, if `a <= b` and `b <= c`, then `a <= c`\n * must be true.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * type Triple = {\n * readonly a: number\n * readonly b: number\n * readonly c: number\n * }\n *\n * const transitivity = Predicate.implies(\n * // antecedent\n * (input: Triple) => input.a <= input.b && input.b <= input.c,\n * // consequent\n * (input: Triple) => input.a <= input.c\n * )\n *\n * assert.equal(transitivity({ a: 1, b: 2, c: 3 }), true)\n * // antecedent is `false`, so the result is `true`\n * assert.equal(transitivity({ a: 1, b: 0, c: 0 }), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const implies: {\n /**\n * Represents the logical implication combinator for predicates. In formal\n * logic, the implication operator `->` denotes that if the first proposition\n * (antecedent) is true, then the second proposition (consequent) must also be\n * true. In simpler terms, `p implies q` can be interpreted as \"if p then q\". If\n * the first predicate holds, then the second predicate must hold\n * for the given context.\n *\n * In practical terms within TypeScript, `p implies q` is equivalent to `!p || (p && q)`.\n *\n * Note that if the antecedent is `false`, the result is `true` by default\n * because the outcome of the consequent cannot be determined.\n *\n * This function is useful in situations where you need to enforce rules or\n * constraints that are contingent on certain conditions.\n * It proves especially helpful in defining property tests.\n *\n * The example below illustrates the transitive property of order using the\n * `implies` function. In simple terms, if `a <= b` and `b <= c`, then `a <= c`\n * must be true.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * type Triple = {\n * readonly a: number\n * readonly b: number\n * readonly c: number\n * }\n *\n * const transitivity = Predicate.implies(\n * // antecedent\n * (input: Triple) => input.a <= input.b && input.b <= input.c,\n * // consequent\n * (input: Triple) => input.a <= input.c\n * )\n *\n * assert.equal(transitivity({ a: 1, b: 2, c: 3 }), true)\n * // antecedent is `false`, so the result is `true`\n * assert.equal(transitivity({ a: 1, b: 0, c: 0 }), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A>(consequent: Predicate<A>): (antecedent: Predicate<A>) => Predicate<A>\n /**\n * Represents the logical implication combinator for predicates. In formal\n * logic, the implication operator `->` denotes that if the first proposition\n * (antecedent) is true, then the second proposition (consequent) must also be\n * true. In simpler terms, `p implies q` can be interpreted as \"if p then q\". If\n * the first predicate holds, then the second predicate must hold\n * for the given context.\n *\n * In practical terms within TypeScript, `p implies q` is equivalent to `!p || (p && q)`.\n *\n * Note that if the antecedent is `false`, the result is `true` by default\n * because the outcome of the consequent cannot be determined.\n *\n * This function is useful in situations where you need to enforce rules or\n * constraints that are contingent on certain conditions.\n * It proves especially helpful in defining property tests.\n *\n * The example below illustrates the transitive property of order using the\n * `implies` function. In simple terms, if `a <= b` and `b <= c`, then `a <= c`\n * must be true.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * type Triple = {\n * readonly a: number\n * readonly b: number\n * readonly c: number\n * }\n *\n * const transitivity = Predicate.implies(\n * // antecedent\n * (input: Triple) => input.a <= input.b && input.b <= input.c,\n * // consequent\n * (input: Triple) => input.a <= input.c\n * )\n *\n * assert.equal(transitivity({ a: 1, b: 2, c: 3 }), true)\n * // antecedent is `false`, so the result is `true`\n * assert.equal(transitivity({ a: 1, b: 0, c: 0 }), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A>(antecedent: Predicate<A>, consequent: Predicate<A>): Predicate<A>\n} = dual(\n 2,\n <A>(antecedent: Predicate<A>, consequent: Predicate<A>): Predicate<A> => (a) => antecedent(a) ? consequent(a) : true\n)\n\n/**\n * @category combinators\n * @since 2.0.0\n */\nexport const nor: {\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>\n} = dual(\n 2,\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => !(self(a) || that(a))\n)\n\n/**\n * @category combinators\n * @since 2.0.0\n */\nexport const nand: {\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>\n} = dual(\n 2,\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => !(self(a) && that(a))\n)\n\n/**\n * @category elements\n * @since 2.0.0\n */\nexport const every = <A>(collection: Iterable<Predicate<A>>): Predicate<A> => (a: A) => {\n for (const p of collection) {\n if (!p(a)) {\n return false\n }\n }\n return true\n}\n\n/**\n * @category elements\n * @since 2.0.0\n */\nexport const some = <A>(collection: Iterable<Predicate<A>>): Predicate<A> => (a) => {\n for (const p of collection) {\n if (p(a)) {\n return true\n }\n }\n return false\n}\n","/**\n * @since 2.0.0\n */\n\n/** @internal */\nexport const getBugErrorMessage = (message: string) =>\n `BUG: ${message} - please report an issue at https://github.com/Effect-TS/effect/issues`\n","/**\n * @since 2.0.0\n */\nimport { identity } from \"./Function.js\"\nimport { globalValue } from \"./GlobalValue.js\"\nimport type { Kind, TypeLambda } from \"./HKT.js\"\nimport { getBugErrorMessage } from \"./internal/errors.js\"\nimport { isNullable, isObject } from \"./Predicate.js\"\nimport type * as Types from \"./Types.js\"\n\n/*\n * Copyright 2014 Thom Chiovoloni, released under the MIT license.\n *\n * A random number generator based on the basic implementation of the PCG algorithm,\n * as described here: http://www.pcg-random.org/\n *\n * Adapted for TypeScript from Thom's original code at https://github.com/thomcc/pcg-random\n *\n * forked from https://github.com/frptools\n *\n * @since 2.0.0\n */\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport const GenKindTypeId: unique symbol = Symbol.for(\"effect/Gen/GenKind\")\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport type GenKindTypeId = typeof GenKindTypeId\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface GenKind<F extends TypeLambda, R, O, E, A> extends Variance<F, R, O, E> {\n readonly value: Kind<F, R, O, E, A>\n\n [Symbol.iterator](): IterableIterator<GenKind<F, R, O, E, A>, A>\n}\n\n/**\n * @category predicates\n * @since 3.0.6\n */\nexport const isGenKind = (u: unknown): u is GenKind<any, any, any, any, any> => isObject(u) && GenKindTypeId in u\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport class GenKindImpl<F extends TypeLambda, R, O, E, A> implements GenKind<F, R, O, E, A> {\n constructor(\n /**\n * @since 2.0.0\n */\n readonly value: Kind<F, R, O, E, A>\n ) {}\n\n /**\n * @since 2.0.0\n */\n get _F() {\n return identity\n }\n\n /**\n * @since 2.0.0\n */\n get _R() {\n return (_: R) => _\n }\n\n /**\n * @since 2.0.0\n */\n get _O() {\n return (_: never): O => _\n }\n\n /**\n * @since 2.0.0\n */\n get _E() {\n return (_: never): E => _\n }\n\n /**\n * @since 2.0.0\n */\n readonly [GenKindTypeId]: typeof GenKindTypeId = GenKindTypeId;\n\n /**\n * @since 2.0.0\n */\n [Symbol.iterator](): IterableIterator<GenKind<F, R, O, E, A>, A> {\n return new SingleShotGen<GenKind<F, R, O, E, A>, A>(this as any)\n }\n}\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport class SingleShotGen<T, A> implements IterableIterator<T, A> {\n private called = false\n\n constructor(readonly self: T) {}\n\n /**\n * @since 2.0.0\n */\n next(a: A): IteratorResult<T, A> {\n return this.called ?\n ({\n value: a,\n done: true\n }) :\n (this.called = true,\n ({\n value: this.self,\n done: false\n }))\n }\n\n /**\n * @since 2.0.0\n */\n return(a: A): IteratorResult<T, A> {\n return ({\n value: a,\n done: true\n })\n }\n\n /**\n * @since 2.0.0\n */\n throw(e: unknown): IteratorResult<T, A> {\n throw e\n }\n\n /**\n * @since 2.0.0\n */\n [Symbol.iterator](): IterableIterator<T, A> {\n return new SingleShotGen<T, A>(this.self)\n }\n}\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const makeGenKind = <F extends TypeLambda, R, O, E, A>(\n kind: Kind<F, R, O, E, A>\n): GenKind<F, R, O, E, A> => new GenKindImpl(kind)\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Variance<in out F extends TypeLambda, in R, out O, out E> {\n readonly [GenKindTypeId]: GenKindTypeId\n readonly _F: Types.Invariant<F>\n readonly _R: Types.Contravariant<R>\n readonly _O: Types.Covariant<O>\n readonly _E: Types.Covariant<E>\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Gen<F extends TypeLambda, Z> {\n <Self, K extends Variance<F, any, any, any> | YieldWrap<Kind<F, any, any, any, any>>, A>(\n ...args:\n | [\n self: Self,\n body: (this: Self, resume: Z) => Generator<K, A, never>\n ]\n | [\n body: (resume: Z) => Generator<K, A, never>\n ]\n ): Kind<\n F,\n [K] extends [Variance<F, infer R, any, any>] ? R\n : [K] extends [YieldWrap<Kind<F, infer R, any, any, any>>] ? R\n : never,\n [K] extends [Variance<F, any, infer O, any>] ? O\n : [K] extends [YieldWrap<Kind<F, any, infer O, any, any>>] ? O\n : never,\n [K] extends [Variance<F, any, any, infer E>] ? E\n : [K] extends [YieldWrap<Kind<F, any, any, infer E, any>>] ? E\n : never,\n A\n >\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Adapter<Z extends TypeLambda> {\n <_R, _O, _E, _A>(\n self: Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, _R, _O, _E, _A>(a: A, ab: (a: A) => Kind<Z, _R, _O, _E, _A>): GenKind<Z, _R, _O, _E, _A>\n <A, B, _R, _O, _E, _A>(a: A, ab: (a: A) => B, bc: (b: B) => Kind<Z, _R, _O, _E, _A>): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: F) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (g: H) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => S,\n st: (s: S) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => S,\n st: (s: S) => T,\n tu: (s: T) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n}\n\n/**\n * @category adapters\n * @since 2.0.0\n */\nexport const adapter: <F extends TypeLambda>() => Adapter<F> = () => (function() {\n let x = arguments[0]\n for (let i = 1; i < arguments.length; i++) {\n x = arguments[i](x)\n }\n return new GenKindImpl(x) as any\n})\n\nconst defaultIncHi = 0x14057b7e\nconst defaultIncLo = 0xf767814f\nconst MUL_HI = 0x5851f42d >>> 0\nconst MUL_LO = 0x4c957f2d >>> 0\nconst BIT_53 = 9007199254740992.0\nconst BIT_27 = 134217728.0\n\n/**\n * @category model\n * @since 2.0.0\n */\nexport type PCGRandomState = [number, number, number, number]\n\n/**\n * @category model\n * @since 2.0.0\n */\nexport type OptionalNumber = number | null | undefined\n\n/**\n * PCG is a family of simple fast space-efficient statistically good algorithms\n * for random number generation. Unlike many general-purpose RNGs, they are also\n * hard to predict.\n *\n * @category model\n * @since 2.0.0\n */\nexport class PCGRandom {\n private _state!: Int32Array\n\n /**\n * Creates an instance of PCGRandom.\n *\n * @param seed - The low 32 bits of the seed (0 is used for high 32 bits).\n *\n * @memberOf PCGRandom\n */\n constructor(seed?: OptionalNumber)\n /**\n * Creates an instance of PCGRandom.\n *\n * @param seedHi - The high 32 bits of the seed.\n * @param seedLo - The low 32 bits of the seed.\n * @param inc - The low 32 bits of the incrementer (0 is used for high 32 bits).\n *\n * @memberOf PCGRandom\n */\n constructor(seedHi: OptionalNumber, seedLo: OptionalNumber, inc?: OptionalNumber)\n /**\n * Creates an instance of PCGRandom.\n *\n * @param seedHi - The high 32 bits of the seed.\n * @param seedLo - The low 32 bits of the seed.\n * @param incHi - The high 32 bits of the incrementer.\n * @param incLo - The low 32 bits of the incrementer.\n *\n * @memberOf PCGRandom\n */\n constructor(\n seedHi: OptionalNumber,\n seedLo: OptionalNumber,\n incHi: OptionalNumber,\n incLo: OptionalNumber\n )\n constructor(\n seedHi?: OptionalNumber,\n seedLo?: OptionalNumber,\n incHi?: OptionalNumber,\n incLo?: OptionalNumber\n ) {\n if (isNullable(seedLo) && isNullable(seedHi)) {\n seedLo = (Math.random() * 0xffffffff) >>> 0\n seedHi = 0\n } else if (isNullable(seedLo)) {\n seedLo = seedHi\n seedHi = 0\n }\n if (isNullable(incLo) && isNullable(incHi)) {\n incLo = this._state ? this._state[3] : defaultIncLo\n incHi = this._state ? this._state[2] : defaultIncHi\n } else if (isNullable(incLo)) {\n incLo = <number> incHi\n incHi = 0\n }\n\n this._state = new Int32Array([0, 0, (<number> incHi) >>> 0, ((incLo || 0) | 1) >>> 0])\n this._next()\n add64(\n this._state,\n this._state[0]!,\n this._state[1]!,\n (<number> seedHi) >>> 0,\n (<number> seedLo) >>> 0\n )\n this._next()\n return this\n }\n\n /**\n * Returns a copy of the internal state of this random number generator as a\n * JavaScript Array.\n *\n * @category getters\n * @since 2.0.0\n */\n getState(): PCGRandomState {\n return [this._state[0]!, this._state[1]!, this._state[2]!, this._state[3]!]\n }\n\n /**\n * Restore state previously retrieved using `getState()`.\n *\n * @since 2.0.0\n */\n setState(state: PCGRandomState) {\n this._state[0] = state[0]\n this._state[1] = state[1]\n this._state[2] = state[2]\n this._state[3] = state[3] | 1\n }\n\n /**\n * Get a uniformly distributed 32 bit integer between [0, max).\n *\n * @category getter\n * @since 2.0.0\n */\n integer(max: number) {\n return Math.round(this.number() * Number.MAX_SAFE_INTEGER) % max\n }\n\n /**\n * Get a uniformly distributed IEEE-754 double between 0.0 and 1.0, with\n * 53 bits of precision (every bit of the mantissa is randomized).\n *\n * @category getters\n * @since 2.0.0\n */\n number() {\n const hi = (this._next() & 0x03ffffff) * 1.0\n const lo = (this._next() & 0x07ffffff) * 1.0\n return (hi * BIT_27 + lo) / BIT_53\n }\n\n /** @internal */\n private _next() {\n // save current state (what we'll use for this number)\n const oldHi = this._state[0]! >>> 0\n const oldLo = this._state[1]! >>> 0\n\n // churn LCG.\n mul64(this._state, oldHi, oldLo, MUL_HI, MUL_LO)\n add64(this._state, this._state[0]!, this._state[1]!, this._state[2]!, this._state[3]!)\n\n // get least sig. 32 bits of ((oldstate >> 18) ^ oldstate) >> 27\n let xsHi = oldHi >>> 18\n let xsLo = ((oldLo >>> 18) | (oldHi << 14)) >>> 0\n xsHi = (xsHi ^ oldHi) >>> 0\n xsLo = (xsLo ^ oldLo) >>> 0\n const xorshifted = ((xsLo >>> 27) | (xsHi << 5)) >>> 0\n // rotate xorshifted right a random amount, based on the most sig. 5 bits\n // bits of the old state.\n const rot = oldHi >>> 27\n const rot2 = ((-rot >>> 0) & 31) >>> 0\n return ((xorshifted >>> rot) | (xorshifted << rot2)) >>> 0\n }\n}\n\nfunction mul64(\n out: Int32Array,\n aHi: number,\n aLo: number,\n bHi: number,\n bLo: number\n): void {\n let c1 = ((aLo >>> 16) * (bLo & 0xffff)) >>> 0\n let c0 = ((aLo & 0xffff) * (bLo >>> 16)) >>> 0\n\n let lo = ((aLo & 0xffff) * (bLo & 0xffff)) >>> 0\n let hi = ((aLo >>> 16) * (bLo >>> 16) + ((c0 >>> 16) + (c1 >>> 16))) >>> 0\n\n c0 = (c0 << 16) >>> 0\n lo = (lo + c0) >>> 0\n if ((lo >>> 0) < (c0 >>> 0)) {\n hi = (hi + 1) >>> 0\n }\n\n c1 = (c1 << 16) >>> 0\n lo = (lo + c1) >>> 0\n if ((lo >>> 0) < (c1 >>> 0)) {\n hi = (hi + 1) >>> 0\n }\n\n hi = (hi + Math.imul(aLo, bHi)) >>> 0\n hi = (hi + Math.imul(aHi, bLo)) >>> 0\n\n out[0] = hi\n out[1] = lo\n}\n\n// add two 64 bit numbers (given in parts), and store the result in `out`.\nfunction add64(\n out: Int32Array,\n aHi: number,\n aLo: number,\n bHi: number,\n bLo: number\n): void {\n let hi = (aHi + bHi) >>> 0\n const lo = (aLo + bLo) >>> 0\n if ((lo >>> 0) < (aLo >>> 0)) {\n hi = (hi + 1) | 0\n }\n out[0] = hi\n out[1] = lo\n}\n\n/**\n * @since 3.0.6\n */\nexport const YieldWrapTypeId: unique symbol = Symbol.for(\"effect/Utils/YieldWrap\")\n\n/**\n * @since 3.0.6\n */\nexport class YieldWrap<T> {\n /**\n * @since 3.0.6\n */\n readonly #value: T\n constructor(value: T) {\n this.#value = value\n }\n /**\n * @since 3.0.6\n */\n [YieldWrapTypeId](): T {\n return this.#value\n }\n}\n\n/**\n * @since 3.0.6\n */\nexport function yieldWrapGet<T>(self: YieldWrap<T>): T {\n if (typeof self === \"object\" && self !== null && YieldWrapTypeId in self) {\n return self[YieldWrapTypeId]()\n }\n throw new Error(getBugErrorMessage(\"yieldWrapGet\"))\n}\n\n/**\n * Note: this is an experimental feature made available to allow custom matchers in tests, not to be directly used yet in user code\n *\n * @since 3.1.1\n * @status experimental\n * @category modifiers\n */\nexport const structuralRegionState = globalValue(\n \"effect/Utils/isStructuralRegion\",\n (): { enabled: boolean; tester: ((a: unknown, b: unknown) => boolean) | undefined } => ({\n enabled: false,\n tester: undefined\n })\n)\n\n/**\n * Note: this is an experimental feature made available to allow custom matchers in tests, not to be directly used yet in user code\n *\n * @since 3.1.1\n * @status experimental\n * @category modifiers\n */\nexport const structuralRegion = <A>(body: () => A, tester?: (a: unknown, b: unknown) => boolean): A => {\n const current = structuralRegionState.enabled\n const currentTester = structuralRegionState.tester\n structuralRegionState.enabled = true\n if (tester) {\n structuralRegionState.tester = tester\n }\n try {\n return body()\n } finally {\n structuralRegionState.enabled = current\n structuralRegionState.tester = currentTester\n }\n}\n\nconst tracingFunction = (name: string) => {\n const wrap = {\n [name]<A>(body: () => A) {\n return body()\n }\n }\n return function<A>(fn: () => A): A {\n return wrap[name](fn)\n }\n}\n\n/**\n * @since 3.2.2\n * @status experimental\n * @category tracing\n */\nexport const internalCall = tracingFunction(\"effect_internal_function\")\n\nconst genConstructor = (function*() {}).constructor\n\n/**\n * @since 3.11.0\n */\nexport const isGeneratorFunction = (u: unknown): u is (...args: Array<any>) => Generator<any, any, any> =>\n isObject(u) && u.constructor === genConstructor\n","/**\n * @since 2.0.0\n */\nimport { pipe } from \"./Function.js\"\nimport { globalValue } from \"./GlobalValue.js\"\nimport { hasProperty } from \"./Predicate.js\"\nimport { structuralRegionState } from \"./Utils.js\"\n\n/** @internal */\nconst randomHashCache = globalValue(\n Symbol.for(\"effect/Hash/randomHashCache\"),\n () => new WeakMap<object, number>()\n)\n\n/**\n * @since 2.0.0\n * @category symbols\n */\nexport const symbol: unique symbol = Symbol.for(\"effect/Hash\")\n\n/**\n * @since 2.0.0\n * @category models\n */\nexport interface Hash {\n [symbol](): number\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const hash: <A>(self: A) => number = <A>(self: A) => {\n if (structuralRegionState.enabled === true) {\n return 0\n }\n\n switch (typeof self) {\n case \"number\":\n return number(self)\n case \"bigint\":\n return string(self.toString(10))\n case \"boolean\":\n return string(String(self))\n case \"symbol\":\n return string(String(self))\n case \"string\":\n return string(self)\n case \"undefined\":\n return string(\"undefined\")\n case \"function\":\n case \"object\": {\n if (self === null) {\n return string(\"null\")\n } else if (self instanceof Date) {\n return hash(self.toISOString())\n } else if (isHash(self)) {\n return self[symbol]()\n } else {\n return random(self)\n }\n }\n default:\n throw new Error(\n `BUG: unhandled typeof ${typeof self} - please report an issue at https://github.com/Effect-TS/effect/issues`\n )\n }\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const random: <A extends object>(self: A) => number = (self) => {\n if (!randomHashCache.has(self)) {\n randomHashCache.set(self, number(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)))\n }\n return randomHashCache.get(self)!\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const combine: (b: number) => (self: number) => number = (b) => (self) => (self * 53) ^ b\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const optimize = (n: number): number => (n & 0xbfffffff) | ((n >>> 1) & 0x40000000)\n\n/**\n * @since 2.0.0\n * @category guards\n */\nexport const isHash = (u: unknown): u is Hash => hasProperty(u, symbol)\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const number = (n: number) => {\n if (n !== n || n === Infinity) {\n return 0\n }\n let h = n | 0\n if (h !== n) {\n h ^= n * 0xffffffff\n }\n while (n > 0xffffffff) {\n h ^= n /= 0xffffffff\n }\n return optimize(h)\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const string = (str: string) => {\n let h = 5381, i = str.length\n while (i) {\n h = (h * 33) ^ str.charCodeAt(--i)\n }\n return optimize(h)\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const structureKeys = <A extends object>(o: A, keys: ReadonlyArray<keyof A>) => {\n let h = 12289\n for (let i = 0; i < keys.length; i++) {\n h ^= pipe(string(keys[i]! as string), combine(hash((o as any)[keys[i]!])))\n }\n return optimize(h)\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const structure = <A extends object>(o: A) =>\n structureKeys(o, Object.keys(o) as unknown as ReadonlyArray<keyof A>)\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const array = <A>(arr: ReadonlyArray<A>) => {\n let h = 6151\n for (let i = 0; i < arr.length; i++) {\n h = pipe(h, combine(hash(arr[i])))\n }\n return optimize(h)\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const cached: {\n /**\n * @since 2.0.0\n * @category hashing\n */\n (self: object): (hash: number) => number\n /**\n * @since 2.0.0\n * @category hashing\n */\n (self: object, hash: number): number\n} = function() {\n if (arguments.length === 1) {\n const self = arguments[0] as object\n return function(hash: number) {\n Object.defineProperty(self, symbol, {\n value() {\n return hash\n },\n enumerable: false\n })\n return hash\n } as any\n }\n const self = arguments[0] as object\n const hash = arguments[1] as number\n Object.defineProperty(self, symbol, {\n value() {\n return hash\n },\n enumerable: false\n })\n\n return hash\n}\n","/**\n * @since 2.0.0\n */\nimport type { Equivalence } from \"./Equivalence.js\"\nimport * as Hash from \"./Hash.js\"\nimport { hasProperty } from \"./Predicate.js\"\nimport { structuralRegionState } from \"./Utils.js\"\n\n/**\n * @since 2.0.0\n * @category symbols\n */\nexport const symbol: unique symbol = Symbol.for(\"effect/Equal\")\n\n/**\n * @since 2.0.0\n * @category models\n */\nexport interface Equal extends Hash.Hash {\n [symbol](that: Equal): boolean\n}\n\n/**\n * @since 2.0.0\n * @category equality\n */\nexport function equals<B>(that: B): <A>(self: A) => boolean\nexport function equals<A, B>(self: A, that: B): boolean\nexport function equals(): any {\n if (arguments.length === 1) {\n return (self: unknown) => compareBoth(self, arguments[0])\n }\n return compareBoth(arguments[0], arguments[1])\n}\n\nfunction compareBoth(self: unknown, that: unknown): boolean {\n if (self === that) {\n return true\n }\n const selfType = typeof self\n if (selfType !== typeof that) {\n return false\n }\n if (selfType === \"object\" || selfType === \"function\") {\n if (self !== null && that !== null) {\n if (isEqual(self) && isEqual(that)) {\n if (Hash.hash(self) === Hash.hash(that) && self[symbol](that)) {\n return true\n } else {\n return structuralRegionState.enabled && structuralRegionState.tester\n ? structuralRegionState.tester(self, that)\n : false\n }\n } else if (self instanceof Date && that instanceof Date) {\n return self.toISOString() === that.toISOString()\n }\n }\n if (structuralRegionState.enabled) {\n if (Array.isArray(self) && Array.isArray(that)) {\n return self.length === that.length && self.every((v, i) => compareBoth(v, that[i]))\n }\n if (Object.getPrototypeOf(self) === Object.prototype && Object.getPrototypeOf(self) === Object.prototype) {\n const keysSelf = Object.keys(self as any)\n const keysThat = Object.keys(that as any)\n if (keysSelf.length === keysThat.length) {\n for (const key of keysSelf) {\n // @ts-expect-error\n if (!(key in that && compareBoth(self[key], that[key]))) {\n return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false\n }\n }\n return true\n }\n }\n return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false\n }\n }\n\n return structuralRegionState.enabled && structuralRegionState.tester\n ? structuralRegionState.tester(self, that)\n : false\n}\n\n/**\n * @since 2.0.0\n * @category guards\n */\nexport const isEqual = (u: unknown): u is Equal => hasProperty(u, symbol)\n\n/**\n * @since 2.0.0\n * @category instances\n */\nexport const equivalence: <A>() => Equivalence<A> = () => equals\n","/**\n * @since 2.0.0\n */\nimport type * as FiberRefs from \"./FiberRefs.js\"\nimport { globalValue } from \"./GlobalValue.js\"\nimport { hasProperty, isFunction } from \"./Predicate.js\"\n\n/**\n * @since 2.0.0\n * @category symbols\n */\nexport const NodeInspectSymbol = Symbol.for(\"nodejs.util.inspect.custom\")\n\n/**\n * @since 2.0.0\n * @category symbols\n */\nexport type NodeInspectSymbol = typeof NodeInspectSymbol\n\n/**\n * @since 2.0.0\n * @category models\n */\nexport interface Inspectable {\n toString(): string\n toJSON(): unknown\n [NodeInspectSymbol](): unknown\n}\n\n/**\n * @since 2.0.0\n */\nexport const toJSON = (x: unknown): unknown => {\n try {\n if (\n hasProperty(x, \"toJSON\") && isFunction(x[\"toJSON\"]) &&\n x[\"toJSON\"].length === 0\n ) {\n return x.toJSON()\n } else if (Array.isArray(x)) {\n return x.map(toJSON)\n }\n } catch (_) {\n return {}\n }\n return redact(x)\n}\n\n/**\n * @since 2.0.0\n */\nexport const format = (x: unknown): string => JSON.stringify(x, null, 2)\n\n/**\n * @since 2.0.0\n */\nexport const BaseProto: Inspectable = {\n toJSON() {\n return toJSON(this)\n },\n [NodeInspectSymbol]() {\n return this.toJSON()\n },\n toString() {\n return format(this.toJSON())\n }\n}\n\n/**\n * @since 2.0.0\n */\nexport abstract class Class {\n /**\n * @since 2.0.0\n */\n abstract toJSON(): unknown\n /**\n * @since 2.0.0\n */\n [NodeInspectSymbol]() {\n return this.toJSON()\n }\n /**\n * @since 2.0.0\n */\n toString() {\n return format(this.toJSON())\n }\n}\n\n/**\n * @since 2.0.0\n */\nexport const toStringUnknown = (u: unknown, whitespace: number | string | undefined = 2): string => {\n if (typeof u === \"string\") {\n return u\n }\n try {\n return typeof u === \"object\" ? stringifyCircular(u, whitespace) : String(u)\n } catch (_) {\n return String(u)\n }\n}\n\n/**\n * @since 2.0.0\n */\nexport const stringifyCircular = (obj: unknown, whitespace?: number | string | undefined): string => {\n let cache: Array<unknown> = []\n const retVal = JSON.stringify(\n obj,\n (_key, value) =>\n typeof value === \"object\" && value !== null\n ? cache.includes(value)\n ? undefined // circular reference\n : cache.push(value) && (redactableState.fiberRefs !== undefined && isRedactable(value)\n ? value[symbolRedactable](redactableState.fiberRefs)\n : value)\n : value,\n whitespace\n )\n ;(cache as any) = undefined\n return retVal\n}\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport interface Redactable {\n readonly [symbolRedactable]: (fiberRefs: FiberRefs.FiberRefs) => unknown\n}\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport const symbolRedactable: unique symbol = Symbol.for(\"effect/Inspectable/Redactable\")\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport const isRedactable = (u: unknown): u is Redactable =>\n typeof u === \"object\" && u !== null && symbolRedactable in u\n\nconst redactableState = globalValue(\"effect/Inspectable/redactableState\", () => ({\n fiberRefs: undefined as FiberRefs.FiberRefs | undefined\n}))\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport const withRedactableContext = <A>(context: FiberRefs.FiberRefs, f: () => A): A => {\n const prev = redactableState.fiberRefs\n redactableState.fiberRefs = context\n try {\n return f()\n } finally {\n redactableState.fiberRefs = prev\n }\n}\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport const redact = (u: unknown): unknown => {\n if (isRedactable(u) && redactableState.fiberRefs !== undefined) {\n return u[symbolRedactable](redactableState.fiberRefs)\n }\n return u\n}\n","/**\n * @since 2.0.0\n */\n\n/**\n * @since 2.0.0\n * @category models\n */\nexport interface Pipeable {\n pipe<A>(this: A): A\n pipe<A, B = never>(this: A, ab: (_: A) => B): B\n pipe<A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C\n pipe<A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D\n pipe<A, B = never, C = never, D = never, E = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E\n ): E\n pipe<A, B = never, C = never, D = never, E = never, F = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F\n ): F\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G\n ): G\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H\n ): H\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I\n ): I\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J\n ): J\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K\n ): K\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L\n ): L\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M\n ): M\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N\n ): N\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O\n ): O\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P\n ): P\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q\n ): Q\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R\n ): R\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R,\n rs: (_: R) => S\n ): S\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never,\n T = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R,\n rs: (_: R) => S,\n st: (_: S) => T\n ): T\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never,\n T = never,\n U = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R,\n rs: (_: R) => S,\n st: (_: S) => T,\n tu: (_: T) => U\n ): U\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never,\n T = never,\n U = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R,\n rs: (_: R) => S,\n st: (_: S) => T,\n tu: (_: T) => U\n ): U\n}\n\n/**\n * @since 2.0.0\n */\nexport const pipeArguments = <A>(self: A, args: IArguments): unknown => {\n switch (args.length) {\n case 0:\n return self\n case 1:\n return args[0](self)\n case 2:\n return args[1](args[0](self))\n case 3:\n return args[2](args[1](args[0](self)))\n case 4:\n return args[3](args[2](args[1](args[0](self))))\n case 5:\n return args[4](args[3](args[2](args[1](args[0](self)))))\n case 6:\n return args[5](args[4](args[3](args[2](args[1](args[0](self))))))\n case 7:\n return args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))))\n case 8:\n return args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self))))))))\n case 9:\n return args[8](args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))))))\n default: {\n let ret = self\n for (let i = 0, len = args.length; i < len; i++) {\n ret = args[i](ret)\n }\n return ret\n }\n }\n}\n","/** @internal */\nexport type OP_ASYNC = typeof OP_ASYNC\n\n/** @internal */\nexport const OP_ASYNC = \"Async\" as const\n\n/** @internal */\nexport type OP_COMMIT = typeof OP_COMMIT\n\n/** @internal */\nexport const OP_COMMIT = \"Commit\" as const\n\n/** @internal */\nexport type OP_FAILURE = typeof OP_FAILURE\n\n/** @internal */\nexport const OP_FAILURE = \"Failure\" as const\n\n/** @internal */\nexport type OP_ON_FAILURE = typeof OP_ON_FAILURE\n\n/** @internal */\nexport const OP_ON_FAILURE = \"OnFailure\" as const\n\n/** @internal */\nexport type OP_ON_SUCCESS = typeof OP_ON_SUCCESS\n\n/** @internal */\nexport const OP_ON_SUCCESS = \"OnSuccess\" as const\n\n/** @internal */\nexport type OP_ON_SUCCESS_AND_FAILURE = typeof OP_ON_SUCCESS_AND_FAILURE\n\n/** @internal */\nexport const OP_ON_SUCCESS_AND_FAILURE = \"OnSuccessAndFailure\" as const\n\n/** @internal */\nexport type OP_SUCCESS = typeof OP_SUCCESS\n\n/** @internal */\nexport const OP_SUCCESS = \"Success\" as const\n\n/** @internal */\nexport type OP_SYNC = typeof OP_SYNC\n\n/** @internal */\nexport const OP_SYNC = \"Sync\" as const\n\n/** @internal */\nexport const OP_TAG = \"Tag\" as const\n\n/** @internal */\nexport type OP_TAG = typeof OP_TAG\n\n/** @internal */\nexport type OP_UPDATE_RUNTIME_FLAGS = typeof OP_UPDATE_RUNTIME_FLAGS\n\n/** @internal */\nexport const OP_UPDATE_RUNTIME_FLAGS = \"UpdateRuntimeFlags\" as const\n\n/** @internal */\nexport type OP_WHILE = typeof OP_WHILE\n\n/** @internal */\nexport const OP_WHILE = \"While\" as const\n\n/** @internal */\nexport type OP_ITERATOR = typeof OP_ITERATOR\n\n/** @internal */\nexport const OP_ITERATOR = \"Iterator\" as const\n\n/** @internal */\nexport type OP_WITH_RUNTIME = typeof OP_WITH_RUNTIME\n\n/** @internal */\nexport const OP_WITH_RUNTIME = \"WithRuntime\" as const\n\n/** @internal */\nexport type OP_YIELD = typeof OP_YIELD\n\n/** @internal */\nexport const OP_YIELD = \"Yield\" as const\n\n/** @internal */\nexport type OP_REVERT_FLAGS = typeof OP_REVERT_FLAGS\n\n/** @internal */\nexport const OP_REVERT_FLAGS = \"RevertFlags\" as const\n","import type * as Channel from \"../Channel.js\"\nimport type * as Effect from \"../Effect.js\"\nimport type * as Effectable from \"../Effectable.js\"\nimport * as Equal from \"../Equal.js\"\nimport * as Hash from \"../Hash.js\"\nimport { pipeArguments } from \"../Pipeable.js\"\nimport type * as Sink from \"../Sink.js\"\nimport type * as Stream from \"../Stream.js\"\nimport { SingleShotGen, YieldWrap } from \"../Utils.js\"\nimport * as OpCodes from \"./opCodes/effect.js\"\nimport * as version from \"./version.js\"\n\n/** @internal */\nexport const EffectTypeId: Effect.EffectTypeId = Symbol.for(\"effect/Effect\") as Effect.EffectTypeId\n\n/** @internal */\nexport const StreamTypeId: Stream.StreamTypeId = Symbol.for(\"effect/Stream\") as Stream.StreamTypeId\n\n/** @internal */\nexport const SinkTypeId: Sink.SinkTypeId = Symbol.for(\"effect/Sink\") as Sink.SinkTypeId\n\n/** @internal */\nexport const ChannelTypeId: Channel.ChannelTypeId = Symbol.for(\"effect/Channel\") as Channel.ChannelTypeId\n\n/** @internal */\nexport const effectVariance = {\n /* c8 ignore next */\n _R: (_: never) => _,\n /* c8 ignore next */\n _E: (_: never) => _,\n /* c8 ignore next */\n _A: (_: never) => _,\n\n _V: version.getCurrentVersion()\n}\n\nconst sinkVariance = {\n /* c8 ignore next */\n _A: (_: never) => _,\n /* c8 ignore next */\n _In: (_: unknown) => _,\n /* c8 ignore next */\n _L: (_: never) => _,\n /* c8 ignore next */\n _E: (_: never) => _,\n /* c8 ignore next */\n _R: (_: never) => _\n}\n\nconst channelVariance = {\n /* c8 ignore next */\n _Env: (_: never) => _,\n /* c8 ignore next */\n _InErr: (_: unknown) => _,\n /* c8 ignore next */\n _InElem: (_: unknown) => _,\n /* c8 ignore next */\n _InDone: (_: unknown) => _,\n /* c8 ignore next */\n _OutErr: (_: never) => _,\n /* c8 ignore next */\n _OutElem: (_: never) => _,\n /* c8 ignore next */\n _OutDone: (_: never) => _\n}\n\n/** @internal */\nexport const EffectPrototype: Effect.Effect<never> & Equal.Equal = {\n [EffectTypeId]: effectVariance,\n [StreamTypeId]: effectVariance,\n [SinkTypeId]: sinkVariance,\n [ChannelTypeId]: channelVariance,\n [Equal.symbol](that: any) {\n return this === that\n },\n [Hash.symbol]() {\n return Hash.cached(this, Hash.random(this))\n },\n [Symbol.iterator]() {\n return new SingleShotGen(new YieldWrap(this)) as any\n },\n pipe() {\n return pipeArguments(this, arguments)\n }\n}\n\n/** @internal */\nexport const StructuralPrototype: Equal.Equal = {\n [Hash.symbol]() {\n return Hash.cached(this, Hash.structure(this))\n },\n [Equal.symbol](this: Equal.Equal, that: Equal.Equal) {\n const selfKeys = Object.keys(this)\n const thatKeys = Object.keys(that as object)\n if (selfKeys.length !== thatKeys.length) {\n return false\n }\n for (const key of selfKeys) {\n if (!(key in (that as object) && Equal.equals((this as any)[key], (that as any)[key]))) {\n return false\n }\n }\n return true\n }\n}\n\n/** @internal */\nexport const CommitPrototype: Effect.Effect<never> = {\n ...EffectPrototype,\n _op: OpCodes.OP_COMMIT\n} as any\n\n/** @internal */\nexport const StructuralCommitPrototype: Effect.Effect<never> = {\n ...CommitPrototype,\n ...StructuralPrototype\n} as any\n\n/** @internal */\nexport const Base: Effectable.CommitPrimitive = (function() {\n function Base() {}\n Base.prototype = CommitPrototype\n return Base as any\n})()\n\n/** @internal */\nexport const StructuralBase: Effectable.CommitPrimitive = (function() {\n function Base() {}\n Base.prototype = StructuralCommitPrototype\n return Base as any\n})()\n","/**\n * @since 2.0.0\n */\n\nimport * as Equal from \"../Equal.js\"\nimport * as Hash from \"../Hash.js\"\nimport { format, NodeInspectSymbol, toJSON } from \"../Inspectable.js\"\nimport type * as Option from \"../Option.js\"\nimport { hasProperty } from \"../Predicate.js\"\nimport { EffectPrototype } from \"./effectable.js\"\n\nconst TypeId: Option.TypeId = Symbol.for(\"effect/Option\") as Option.TypeId\n\nconst CommonProto = {\n ...EffectPrototype,\n [TypeId]: {\n _A: (_: never) => _\n },\n [NodeInspectSymbol]<A>(this: Option.Option<A>) {\n return this.toJSON()\n },\n toString<A>(this: Option.Option<A>) {\n return format(this.toJSON())\n }\n}\n\nconst SomeProto = Object.assign(Object.create(CommonProto), {\n _tag: \"Some\",\n _op: \"Some\",\n [Equal.symbol]<A>(this: Option.Some<A>, that: unknown): boolean {\n return isOption(that) && isSome(that) && Equal.equals(this.value, that.value)\n },\n [Hash.symbol]<A>(this: Option.Some<A>) {\n return Hash.cached(this, Hash.combine(Hash.hash(this._tag))(Hash.hash(this.value)))\n },\n toJSON<A>(this: Option.Some<A>) {\n return {\n _id: \"Option\",\n _tag: this._tag,\n value: toJSON(this.value)\n }\n }\n})\n\nconst NoneHash = Hash.hash(\"None\")\nconst NoneProto = Object.assign(Object.create(CommonProto), {\n _tag: \"None\",\n _op: \"None\",\n [Equal.symbol]<A>(this: Option.None<A>, that: unknown): boolean {\n return isOption(that) && isNone(that)\n },\n [Hash.symbol]<A>(this: Option.None<A>) {\n return NoneHash\n },\n toJSON<A>(this: Option.None<A>) {\n return {\n _id: \"Option\",\n _tag: this._tag\n }\n }\n})\n\n/** @internal */\nexport const isOption = (input: unknown): input is Option.Option<unknown> => hasProperty(input, TypeId)\n\n/** @internal */\nexport const isNone = <A>(fa: Option.Option<A>): fa is Option.None<A> => fa._tag === \"None\"\n\n/** @internal */\nexport const isSome = <A>(fa: Option.Option<A>): fa is Option.Some<A> => fa._tag === \"Some\"\n\n/** @internal */\nexport const none: Option.Option<never> = Object.create(NoneProto)\n\n/** @internal */\nexport const some = <A>(value: A): Option.Option<A> => {\n const a = Object.create(SomeProto)\n a.value = value\n return a\n}\n","/**\n * @since 2.0.0\n */\n\nimport type * as Either from \"../Either.js\"\nimport * as Equal from \"../Equal.js\"\nimport { dual } from \"../Function.js\"\nimport * as Hash from \"../Hash.js\"\nimport { format, NodeInspectSymbol, toJSON } from \"../Inspectable.js\"\nimport type { Option } from \"../Option.js\"\nimport { hasProperty } from \"../Predicate.js\"\nimport { EffectPrototype } from \"./effectable.js\"\nimport * as option from \"./option.js\"\n\n/**\n * @internal\n */\nexport const TypeId: Either.TypeId = Symbol.for(\"effect/Either\") as Either.TypeId\n\nconst CommonProto = {\n ...EffectPrototype,\n [TypeId]: {\n _R: (_: never) => _\n },\n [NodeInspectSymbol]<L, R>(this: Either.Either<R, L>) {\n return this.toJSON()\n },\n toString<L, R>(this: Either.Left<L, R>) {\n return format(this.toJSON())\n }\n}\n\nconst RightProto = Object.assign(Object.create(CommonProto), {\n _tag: \"Right\",\n _op: \"Right\",\n [Equal.symbol]<L, R>(this: Either.Right<L, R>, that: unknown): boolean {\n return isEither(that) && isRight(that) && Equal.equals(this.right, that.right)\n },\n [Hash.symbol]<L, R>(this: Either.Right<L, R>) {\n return Hash.combine(Hash.hash(this._tag))(Hash.hash(this.right))\n },\n toJSON<L, R>(this: Either.Right<L, R>) {\n return {\n _id: \"Either\",\n _tag: this._tag,\n right: toJSON(this.right)\n }\n }\n})\n\nconst LeftProto = Object.assign(Object.create(CommonProto), {\n _tag: \"Left\",\n _op: \"Left\",\n [Equal.symbol]<L, R>(this: Either.Left<L, R>, that: unknown): boolean {\n return isEither(that) && isLeft(that) && Equal.equals(this.left, that.left)\n },\n [Hash.symbol]<L, R>(this: Either.Left<L, R>) {\n return Hash.combine(Hash.hash(this._tag))(Hash.hash(this.left))\n },\n toJSON<E, A>(this: Either.Left<E, A>) {\n return {\n _id: \"Either\",\n _tag: this._tag,\n left: toJSON(this.left)\n }\n }\n})\n\n/** @internal */\nexport const isEither = (input: unknown): input is Either.Either<unknown, unknown> => hasProperty(input, TypeId)\n\n/** @internal */\nexport const isLeft = <R, L>(ma: Either.Either<R, L>): ma is Either.Left<L, R> => ma._tag === \"Left\"\n\n/** @internal */\nexport const isRight = <R, L>(ma: Either.Either<R, L>): ma is Either.Right<L, R> => ma._tag === \"Right\"\n\n/** @internal */\nexport const left = <L>(left: L): Either.Either<never, L> => {\n const a = Object.create(LeftProto)\n a.left = left\n return a\n}\n\n/** @internal */\nexport const right = <R>(right: R): Either.Either<R> => {\n const a = Object.create(RightProto)\n a.right = right\n return a\n}\n\n/** @internal */\nexport const getLeft = <R, L>(\n self: Either.Either<R, L>\n): Option<L> => (isRight(self) ? option.none : option.some(self.left))\n\n/** @internal */\nexport const getRight = <R, L>(\n self: Either.Either<R, L>\n): Option<R> => (isLeft(self) ? option.none : option.some(self.right))\n\n/** @internal */\nexport const fromOption: {\n <L>(onNone: () => L): <R>(self: Option<R>) => Either.Either<R, L>\n <R, L>(self: Option<R>, onNone: () => L): Either.Either<R, L>\n} = dual(\n 2,\n <R, L>(self: Option<R>, onNone: () => L): Either.Either<R, L> =>\n option.isNone(self) ? left(onNone()) : right(self.value)\n)\n","/**\n * @since 2.0.0\n */\n\nimport type { NonEmptyArray } from \"../Array.js\"\n\n/** @internal */\nexport const isNonEmptyArray = <A>(self: ReadonlyArray<A>): self is NonEmptyArray<A> => self.length > 0\n","/**\n * This module provides an implementation of the `Order` type class which is used to define a total ordering on some type `A`.\n * An order is defined by a relation `<=`, which obeys the following laws:\n *\n * - either `x <= y` or `y <= x` (totality)\n * - if `x <= y` and `y <= x`, then `x == y` (antisymmetry)\n * - if `x <= y` and `y <= z`, then `x <= z` (transitivity)\n *\n * The truth table for compare is defined as follows:\n *\n * | `x <= y` | `x >= y` | Ordering | |\n * | -------- | -------- | -------- | --------------------- |\n * | `true` | `true` | `0` | corresponds to x == y |\n * | `true` | `false` | `< 0` | corresponds to x < y |\n * | `false` | `true` | `> 0` | corresponds to x > y |\n *\n * @since 2.0.0\n */\nimport { dual } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\n\n/**\n * @category type class\n * @since 2.0.0\n */\nexport interface Order<in A> {\n (self: A, that: A): -1 | 0 | 1\n}\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface OrderTypeLambda extends TypeLambda {\n readonly type: Order<this[\"Target\"]>\n}\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const make = <A>(\n compare: (self: A, that: A) => -1 | 0 | 1\n): Order<A> =>\n(self, that) => self === that ? 0 : compare(self, that)\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const string: Order<string> = make((self, that) => self < that ? -1 : 1)\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const number: Order<number> = make((self, that) => self < that ? -1 : 1)\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const boolean: Order<boolean> = make((self, that) => self < that ? -1 : 1)\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const bigint: Order<bigint> = make((self, that) => self < that ? -1 : 1)\n\n/**\n * @since 2.0.0\n */\nexport const reverse = <A>(O: Order<A>): Order<A> => make((self, that) => O(that, self))\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const combine: {\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(that: Order<A>): (self: Order<A>) => Order<A>\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(self: Order<A>, that: Order<A>): Order<A>\n} = dual(2, <A>(self: Order<A>, that: Order<A>): Order<A> =>\n make((a1, a2) => {\n const out = self(a1, a2)\n if (out !== 0) {\n return out\n }\n return that(a1, a2)\n }))\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const combineMany: {\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(collection: Iterable<Order<A>>): (self: Order<A>) => Order<A>\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(self: Order<A>, collection: Iterable<Order<A>>): Order<A>\n} = dual(2, <A>(self: Order<A>, collection: Iterable<Order<A>>): Order<A> =>\n make((a1, a2) => {\n let out = self(a1, a2)\n if (out !== 0) {\n return out\n }\n for (const O of collection) {\n out = O(a1, a2)\n if (out !== 0) {\n return out\n }\n }\n return out\n }))\n\n/**\n * @since 2.0.0\n */\nexport const empty = <A>(): Order<A> => make(() => 0)\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const combineAll = <A>(collection: Iterable<Order<A>>): Order<A> => combineMany(empty(), collection)\n\n/**\n * @category mapping\n * @since 2.0.0\n */\nexport const mapInput: {\n /**\n * @category mapping\n * @since 2.0.0\n */\n <B, A>(f: (b: B) => A): (self: Order<A>) => Order<B>\n /**\n * @category mapping\n * @since 2.0.0\n */\n <A, B>(self: Order<A>, f: (b: B) => A): Order<B>\n} = dual(\n 2,\n <A, B>(self: Order<A>, f: (b: B) => A): Order<B> => make((b1, b2) => self(f(b1), f(b2)))\n)\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const Date: Order<Date> = mapInput(number, (date) => date.getTime())\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const product: {\n <B>(that: Order<B>): <A>(self: Order<A>) => Order<readonly [A, B]> // readonly because invariant\n <A, B>(self: Order<A>, that: Order<B>): Order<readonly [A, B]> // readonly because invariant\n} = dual(2, <A, B>(self: Order<A>, that: Order<B>): Order<readonly [A, B]> =>\n make(([xa, xb], [ya, yb]) => {\n const o = self(xa, ya)\n return o !== 0 ? o : that(xb, yb)\n }))\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const all = <A>(collection: Iterable<Order<A>>): Order<ReadonlyArray<A>> => {\n return make((x, y) => {\n const len = Math.min(x.length, y.length)\n let collectionLength = 0\n for (const O of collection) {\n if (collectionLength >= len) {\n break\n }\n const o = O(x[collectionLength], y[collectionLength])\n if (o !== 0) {\n return o\n }\n collectionLength++\n }\n return 0\n })\n}\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const productMany: {\n <A>(collection: Iterable<Order<A>>): (self: Order<A>) => Order<readonly [A, ...Array<A>]> // readonly because invariant\n <A>(self: Order<A>, collection: Iterable<Order<A>>): Order<readonly [A, ...Array<A>]> // readonly because invariant\n} = dual(2, <A>(self: Order<A>, collection: Iterable<Order<A>>): Order<readonly [A, ...Array<A>]> => {\n const O = all(collection)\n return make((x, y) => {\n const o = self(x[0], y[0])\n return o !== 0 ? o : O(x.slice(1), y.slice(1))\n })\n})\n\n/**\n * Similar to `Promise.all` but operates on `Order`s.\n *\n * ```\n * [Order<A>, Order<B>, ...] -> Order<[A, B, ...]>\n * ```\n *\n * This function creates and returns a new `Order` for a tuple of values based on the given `Order`s for each element in the tuple.\n * The returned `Order` compares two tuples of the same type by applying the corresponding `Order` to each element in the tuple.\n * It is useful when you need to compare two tuples of the same type and you have a specific way of comparing each element\n * of the tuple.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const tuple = <T extends ReadonlyArray<Order<any>>>(\n ...elements: T\n): Order<Readonly<{ [I in keyof T]: [T[I]] extends [Order<infer A>] ? A : never }>> => all(elements) as any\n\n/**\n * This function creates and returns a new `Order` for an array of values based on a given `Order` for the elements of the array.\n * The returned `Order` compares two arrays by applying the given `Order` to each element in the arrays.\n * If all elements are equal, the arrays are then compared based on their length.\n * It is useful when you need to compare two arrays of the same type and you have a specific way of comparing each element of the array.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const array = <A>(O: Order<A>): Order<ReadonlyArray<A>> =>\n make((self, that) => {\n const aLen = self.length\n const bLen = that.length\n const len = Math.min(aLen, bLen)\n for (let i = 0; i < len; i++) {\n const o = O(self[i], that[i])\n if (o !== 0) {\n return o\n }\n }\n return number(aLen, bLen)\n })\n\n/**\n * This function creates and returns a new `Order` for a struct of values based on the given `Order`s\n * for each property in the struct.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const struct = <R extends { readonly [x: string]: Order<any> }>(\n fields: R\n): Order<{ [K in keyof R]: [R[K]] extends [Order<infer A>] ? A : never }> => {\n const keys = Object.keys(fields)\n return make((self, that) => {\n for (const key of keys) {\n const o = fields[key](self[key], that[key])\n if (o !== 0) {\n return o\n }\n }\n return 0\n })\n}\n\n/**\n * Test whether one value is _strictly less than_ another.\n *\n * @since 2.0.0\n */\nexport const lessThan = <A>(O: Order<A>): {\n (that: A): (self: A) => boolean\n (self: A, that: A): boolean\n} => dual(2, (self: A, that: A) => O(self, that) === -1)\n\n/**\n * Test whether one value is _strictly greater than_ another.\n *\n * @since 2.0.0\n */\nexport const greaterThan = <A>(O: Order<A>): {\n (that: A): (self: A) => boolean\n (self: A, that: A): boolean\n} => dual(2, (self: A, that: A) => O(self, that) === 1)\n\n/**\n * Test whether one value is _non-strictly less than_ another.\n *\n * @since 2.0.0\n */\nexport const lessThanOrEqualTo = <A>(O: Order<A>): {\n (that: A): (self: A) => boolean\n (self: A, that: A): boolean\n} => dual(2, (self: A, that: A) => O(self, that) !== 1)\n\n/**\n * Test whether one value is _non-strictly greater than_ another.\n *\n * @since 2.0.0\n */\nexport const greaterThanOrEqualTo = <A>(O: Order<A>): {\n (that: A): (self: A) => boolean\n (self: A, that: A): boolean\n} => dual(2, (self: A, that: A) => O(self, that) !== -1)\n\n/**\n * Take the minimum of two values. If they are considered equal, the first argument is chosen.\n *\n * @since 2.0.0\n */\nexport const min = <A>(O: Order<A>): {\n (that: A): (self: A) => A\n (self: A, that: A): A\n} => dual(2, (self: A, that: A) => self === that || O(self, that) < 1 ? self : that)\n\n/**\n * Take the maximum of two values. If they are considered equal, the first argument is chosen.\n *\n * @since 2.0.0\n */\nexport const max = <A>(O: Order<A>): {\n (that: A): (self: A) => A\n (self: A, that: A): A\n} => dual(2, (self: A, that: A) => self === that || O(self, that) > -1 ? self : that)\n\n/**\n * Clamp a value between a minimum and a maximum.\n *\n * @example\n * ```ts\n * import { Order, Number } from \"effect\"\n *\n * const clamp = Order.clamp(Number.Order)({ minimum: 1, maximum: 5 })\n *\n * assert.equal(clamp(3), 3)\n * assert.equal(clamp(0), 1)\n * assert.equal(clamp(6), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const clamp = <A>(O: Order<A>): {\n (options: {\n minimum: A\n maximum: A\n }): (self: A) => A\n (self: A, options: {\n minimum: A\n maximum: A\n }): A\n} =>\n dual(\n 2,\n (self: A, options: {\n minimum: A\n maximum: A\n }): A => min(O)(options.maximum, max(O)(options.minimum, self))\n )\n\n/**\n * Test whether a value is between a minimum and a maximum (inclusive).\n *\n * @since 2.0.0\n */\nexport const between = <A>(O: Order<A>): {\n (options: {\n minimum: A\n maximum: A\n }): (self: A) => boolean\n (self: A, options: {\n minimum: A\n maximum: A\n }): boolean\n} =>\n dual(\n 2,\n (self: A, options: {\n minimum: A\n maximum: A\n }): boolean => !lessThan(O)(self, options.minimum) && !greaterThan(O)(self, options.maximum)\n )\n","/**\n * @since 2.0.0\n */\nimport type { Either } from \"./Either.js\"\nimport * as Equal from \"./Equal.js\"\nimport * as Equivalence from \"./Equivalence.js\"\nimport type { LazyArg } from \"./Function.js\"\nimport { constNull, constUndefined, dual, identity, isFunction } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\nimport type { Inspectable } from \"./Inspectable.js\"\nimport * as doNotation from \"./internal/doNotation.js\"\nimport * as either from \"./internal/either.js\"\nimport * as option from \"./internal/option.js\"\nimport type { Order } from \"./Order.js\"\nimport * as order from \"./Order.js\"\nimport type { Pipeable } from \"./Pipeable.js\"\nimport type { Predicate, Refinement } from \"./Predicate.js\"\nimport type { Covariant, NoInfer, NotFunction } from \"./Types.js\"\nimport type * as Unify from \"./Unify.js\"\nimport * as Gen from \"./Utils.js\"\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport type Option<A> = None<A> | Some<A>\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport const TypeId: unique symbol = Symbol.for(\"effect/Option\")\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport type TypeId = typeof TypeId\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface None<out A> extends Pipeable, Inspectable {\n readonly _tag: \"None\"\n readonly _op: \"None\"\n readonly [TypeId]: {\n readonly _A: Covariant<A>\n }\n [Unify.typeSymbol]?: unknown\n [Unify.unifySymbol]?: OptionUnify<this>\n [Unify.ignoreSymbol]?: OptionUnifyIgnore\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Some<out A> extends Pipeable, Inspectable {\n readonly _tag: \"Some\"\n readonly _op: \"Some\"\n readonly value: A\n readonly [TypeId]: {\n readonly _A: Covariant<A>\n }\n [Unify.typeSymbol]?: unknown\n [Unify.unifySymbol]?: OptionUnify<this>\n [Unify.ignoreSymbol]?: OptionUnifyIgnore\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface OptionUnify<A extends { [Unify.typeSymbol]?: any }> {\n Option?: () => A[Unify.typeSymbol] extends Option<infer A0> | infer _ ? Option<A0> : never\n}\n\n/**\n * @since 2.0.0\n */\nexport declare namespace Option {\n /**\n * @since 2.0.0\n * @category type-level\n */\n export type Value<T extends Option<any>> = [T] extends [Option<infer _A>] ? _A : never\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface OptionUnifyIgnore {}\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface OptionTypeLambda extends TypeLambda {\n readonly type: Option<this[\"Target\"]>\n}\n\n/**\n * Creates a new `Option` that represents the absence of a value.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const none = <A = never>(): Option<A> => option.none\n\n/**\n * Creates a new `Option` that wraps the given value.\n *\n * @param value - The value to wrap.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const some: <A>(value: A) => Option<A> = option.some\n\n/**\n * Checks if a given value is an `Option` value.\n *\n * @param input - The value to check.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.isOption(Option.some(1)), true)\n * assert.deepStrictEqual(Option.isOption(Option.none()), true)\n * assert.deepStrictEqual(Option.isOption({}), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isOption: (input: unknown) => input is Option<unknown> = option.isOption\n\n/**\n * Determine if a `Option` is a `None`.\n *\n * @param self - The `Option` to check.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.isNone(Option.some(1)), false)\n * assert.deepStrictEqual(Option.isNone(Option.none()), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNone: <A>(self: Option<A>) => self is None<A> = option.isNone\n\n/**\n * Determine if a `Option` is a `Some`.\n *\n * @param self - The `Option` to check.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.isSome(Option.some(1)), true)\n * assert.deepStrictEqual(Option.isSome(Option.none()), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isSome: <A>(self: Option<A>) => self is Some<A> = option.isSome\n\n/**\n * Matches the given `Option` and returns either the provided `onNone` value or the result of the provided `onSome`\n * function when passed the `Option`'s value.\n *\n * @param self - The `Option` to match\n * @param onNone - The value to be returned if the `Option` is `None`\n * @param onSome - The function to be called if the `Option` is `Some`, it will be passed the `Option`'s value and its result will be returned\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(Option.some(1), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),\n * 'a some containing 1'\n * )\n *\n * assert.deepStrictEqual(\n * pipe(Option.none(), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),\n * 'a none'\n * )\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\nexport const match: {\n /**\n * Matches the given `Option` and returns either the provided `onNone` value or the result of the provided `onSome`\n * function when passed the `Option`'s value.\n *\n * @param self - The `Option` to match\n * @param onNone - The value to be returned if the `Option` is `None`\n * @param onSome - The function to be called if the `Option` is `Some`, it will be passed the `Option`'s value and its result will be returned\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(Option.some(1), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),\n * 'a some containing 1'\n * )\n *\n * assert.deepStrictEqual(\n * pipe(Option.none(), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),\n * 'a none'\n * )\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <B, A, C = B>(\n options: {\n readonly onNone: LazyArg<B>\n readonly onSome: (a: A) => C\n }\n ): (self: Option<A>) => B | C\n /**\n * Matches the given `Option` and returns either the provided `onNone` value or the result of the provided `onSome`\n * function when passed the `Option`'s value.\n *\n * @param self - The `Option` to match\n * @param onNone - The value to be returned if the `Option` is `None`\n * @param onSome - The function to be called if the `Option` is `Some`, it will be passed the `Option`'s value and its result will be returned\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(Option.some(1), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),\n * 'a some containing 1'\n * )\n *\n * assert.deepStrictEqual(\n * pipe(Option.none(), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),\n * 'a none'\n * )\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <A, B, C = B>(\n self: Option<A>,\n options: {\n readonly onNone: LazyArg<B>\n readonly onSome: (a: A) => C\n }\n ): B | C\n} = dual(\n 2,\n <A, B, C = B>(self: Option<A>, { onNone, onSome }: {\n readonly onNone: LazyArg<B>\n readonly onSome: (a: A) => C\n }): B | C => isNone(self) ? onNone() : onSome(self.value)\n)\n\n/**\n * Returns a type guard from a `Option` returning function.\n * This function ensures that a type guard definition is type-safe.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const parsePositive = (n: number): Option.Option<number> =>\n * n > 0 ? Option.some(n) : Option.none()\n *\n * const isPositive = Option.toRefinement(parsePositive)\n *\n * assert.deepStrictEqual(isPositive(1), true)\n * assert.deepStrictEqual(isPositive(-1), false)\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const toRefinement = <A, B extends A>(f: (a: A) => Option<B>): (a: A) => a is B => (a: A): a is B => isSome(f(a))\n\n/**\n * Converts an `Iterable` of values into an `Option`. Returns the first value of the `Iterable` wrapped in a `Some`\n * if the `Iterable` is not empty, otherwise returns `None`.\n *\n * @param collection - The `Iterable` to be converted to an `Option`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.fromIterable([1, 2, 3]), Option.some(1))\n * assert.deepStrictEqual(Option.fromIterable([]), Option.none())\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const fromIterable = <A>(collection: Iterable<A>): Option<A> => {\n for (const a of collection) {\n return some(a)\n }\n return none()\n}\n\n/**\n * Converts a `Either` to an `Option` discarding the error.\n *\n * @example\n * ```ts\n * import { Option, Either } from \"effect\"\n *\n * assert.deepStrictEqual(Option.getRight(Either.right('ok')), Option.some('ok'))\n * assert.deepStrictEqual(Option.getRight(Either.left('err')), Option.none())\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const getRight: <R, L>(self: Either<R, L>) => Option<R> = either.getRight\n\n/**\n * Converts a `Either` to an `Option` discarding the value.\n *\n * @example\n * ```ts\n * import { Option, Either } from \"effect\"\n *\n * assert.deepStrictEqual(Option.getLeft(Either.right(\"ok\")), Option.none())\n * assert.deepStrictEqual(Option.getLeft(Either.left(\"a\")), Option.some(\"a\"))\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const getLeft: <R, L>(self: Either<R, L>) => Option<L> = either.getLeft\n\n/**\n * Returns the value of the `Option` if it is `Some`, otherwise returns `onNone`\n *\n * @param self - The `Option` to get the value of.\n * @param onNone - Function that returns the default value to return if the `Option` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(pipe(Option.some(1), Option.getOrElse(() => 0)), 1)\n * assert.deepStrictEqual(pipe(Option.none(), Option.getOrElse(() => 0)), 0)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrElse: {\n /**\n * Returns the value of the `Option` if it is `Some`, otherwise returns `onNone`\n *\n * @param self - The `Option` to get the value of.\n * @param onNone - Function that returns the default value to return if the `Option` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(pipe(Option.some(1), Option.getOrElse(() => 0)), 1)\n * assert.deepStrictEqual(pipe(Option.none(), Option.getOrElse(() => 0)), 0)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <B>(onNone: LazyArg<B>): <A>(self: Option<A>) => B | A\n /**\n * Returns the value of the `Option` if it is `Some`, otherwise returns `onNone`\n *\n * @param self - The `Option` to get the value of.\n * @param onNone - Function that returns the default value to return if the `Option` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(pipe(Option.some(1), Option.getOrElse(() => 0)), 1)\n * assert.deepStrictEqual(pipe(Option.none(), Option.getOrElse(() => 0)), 0)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, onNone: LazyArg<B>): A | B\n} = dual(\n 2,\n <A, B>(self: Option<A>, onNone: LazyArg<B>): A | B => isNone(self) ? onNone() : self.value\n)\n\n/**\n * Returns the provided `Option` `that` if `self` is `None`, otherwise returns `self`.\n *\n * @param self - The first `Option` to be checked.\n * @param that - The `Option` to return if `self` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElse(() => Option.none())\n * ),\n * Option.none()\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElse(() => Option.none())\n * ),\n * Option.some('a')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElse(() => Option.some('b'))\n * ),\n * Option.some('b')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElse(() => Option.some('b'))\n * ),\n * Option.some('a')\n * )\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\nexport const orElse: {\n /**\n * Returns the provided `Option` `that` if `self` is `None`, otherwise returns `self`.\n *\n * @param self - The first `Option` to be checked.\n * @param that - The `Option` to return if `self` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElse(() => Option.none())\n * ),\n * Option.none()\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElse(() => Option.none())\n * ),\n * Option.some('a')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElse(() => Option.some('b'))\n * ),\n * Option.some('b')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElse(() => Option.some('b'))\n * ),\n * Option.some('a')\n * )\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\n <B>(that: LazyArg<Option<B>>): <A>(self: Option<A>) => Option<B | A>\n /**\n * Returns the provided `Option` `that` if `self` is `None`, otherwise returns `self`.\n *\n * @param self - The first `Option` to be checked.\n * @param that - The `Option` to return if `self` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElse(() => Option.none())\n * ),\n * Option.none()\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElse(() => Option.none())\n * ),\n * Option.some('a')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElse(() => Option.some('b'))\n * ),\n * Option.some('b')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElse(() => Option.some('b'))\n * ),\n * Option.some('a')\n * )\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<A | B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<A | B> => isNone(self) ? that() : self\n)\n\n/**\n * Returns the provided default value as `Some` if `self` is `None`, otherwise returns `self`.\n *\n * @param self - The first `Option` to be checked.\n * @param onNone - Function that returns the default value to return if the `Option` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElseSome(() => 'b')\n * ),\n * Option.some('b')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElseSome(() => 'b')\n * ),\n * Option.some('a')\n * )\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\nexport const orElseSome: {\n /**\n * Returns the provided default value as `Some` if `self` is `None`, otherwise returns `self`.\n *\n * @param self - The first `Option` to be checked.\n * @param onNone - Function that returns the default value to return if the `Option` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElseSome(() => 'b')\n * ),\n * Option.some('b')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElseSome(() => 'b')\n * ),\n * Option.some('a')\n * )\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\n <B>(onNone: LazyArg<B>): <A>(self: Option<A>) => Option<B | A>\n /**\n * Returns the provided default value as `Some` if `self` is `None`, otherwise returns `self`.\n *\n * @param self - The first `Option` to be checked.\n * @param onNone - Function that returns the default value to return if the `Option` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElseSome(() => 'b')\n * ),\n * Option.some('b')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElseSome(() => 'b')\n * ),\n * Option.some('a')\n * )\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, onNone: LazyArg<B>): Option<A | B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, onNone: LazyArg<B>): Option<A | B> => isNone(self) ? some(onNone()) : self\n)\n\n/**\n * Similar to `orElse`, but instead of returning a simple union, it returns an `Either` object,\n * which contains information about which of the two `Option`s has been chosen.\n *\n * This is useful when it's important to know whether the value was retrieved from the first `Option` or the second option.\n *\n * @param self - The first `Option` to be checked.\n * @param that - The second `Option` to be considered if the first `Option` is `None`.\n *\n * @category error handling\n * @since 2.0.0\n */\nexport const orElseEither: {\n /**\n * Similar to `orElse`, but instead of returning a simple union, it returns an `Either` object,\n * which contains information about which of the two `Option`s has been chosen.\n *\n * This is useful when it's important to know whether the value was retrieved from the first `Option` or the second option.\n *\n * @param self - The first `Option` to be checked.\n * @param that - The second `Option` to be considered if the first `Option` is `None`.\n *\n * @category error handling\n * @since 2.0.0\n */\n <B>(that: LazyArg<Option<B>>): <A>(self: Option<A>) => Option<Either<B, A>>\n /**\n * Similar to `orElse`, but instead of returning a simple union, it returns an `Either` object,\n * which contains information about which of the two `Option`s has been chosen.\n *\n * This is useful when it's important to know whether the value was retrieved from the first `Option` or the second option.\n *\n * @param self - The first `Option` to be checked.\n * @param that - The second `Option` to be considered if the first `Option` is `None`.\n *\n * @category error handling\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<Either<B, A>>\n} = dual(\n 2,\n <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<Either<B, A>> =>\n isNone(self) ? map(that(), either.right) : map(self, either.left)\n)\n\n/**\n * Given an `Iterable` collection of `Option`s, returns the first `Some` found in the collection.\n *\n * @param collection - An iterable collection of `Option` to be searched.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.firstSomeOf([Option.none(), Option.some(1), Option.some(2)]), Option.some(1))\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\nexport const firstSomeOf = <T, C extends Iterable<Option<T>> = Iterable<Option<T>>>(\n collection: C\n): [C] extends [Iterable<Option<infer A>>] ? Option<A> : never => {\n let out: Option<unknown> = none()\n for (out of collection) {\n if (isSome(out)) {\n return out as any\n }\n }\n return out as any\n}\n\n/**\n * Constructs a new `Option` from a nullable type. If the value is `null` or `undefined`, returns `None`, otherwise\n * returns the value wrapped in a `Some`.\n *\n * @param nullableValue - The nullable value to be converted to an `Option`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.fromNullable(undefined), Option.none())\n * assert.deepStrictEqual(Option.fromNullable(null), Option.none())\n * assert.deepStrictEqual(Option.fromNullable(1), Option.some(1))\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const fromNullable = <A>(\n nullableValue: A\n): Option<\n NonNullable<A>\n> => (nullableValue == null ? none() : some(nullableValue as NonNullable<A>))\n\n/**\n * This API is useful for lifting a function that returns `null` or `undefined` into the `Option` context.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const parse = (s: string): number | undefined => {\n * const n = parseFloat(s)\n * return isNaN(n) ? undefined : n\n * }\n *\n * const parseOption = Option.liftNullable(parse)\n *\n * assert.deepStrictEqual(parseOption('1'), Option.some(1))\n * assert.deepStrictEqual(parseOption('not a number'), Option.none())\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const liftNullable = <A extends ReadonlyArray<unknown>, B>(\n f: (...a: A) => B | null | undefined\n): (...a: A) => Option<NonNullable<B>> =>\n(...a) => fromNullable(f(...a))\n\n/**\n * Returns the value of the `Option` if it is a `Some`, otherwise returns `null`.\n *\n * @param self - The `Option` to extract the value from.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.getOrNull(Option.some(1)), 1)\n * assert.deepStrictEqual(Option.getOrNull(Option.none()), null)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrNull: <A>(self: Option<A>) => A | null = getOrElse(constNull)\n\n/**\n * Returns the value of the `Option` if it is a `Some`, otherwise returns `undefined`.\n *\n * @param self - The `Option` to extract the value from.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.getOrUndefined(Option.some(1)), 1)\n * assert.deepStrictEqual(Option.getOrUndefined(Option.none()), undefined)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrUndefined: <A>(self: Option<A>) => A | undefined = getOrElse(constUndefined)\n\n/**\n * A utility function that lifts a function that throws exceptions into a function that returns an `Option`.\n *\n * This function is useful for any function that might throw an exception, allowing the developer to handle\n * the exception in a more functional way.\n *\n * @param f - the function that can throw exceptions.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const parse = Option.liftThrowable(JSON.parse)\n *\n * assert.deepStrictEqual(parse(\"1\"), Option.some(1))\n * assert.deepStrictEqual(parse(\"\"), Option.none())\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const liftThrowable = <A extends ReadonlyArray<unknown>, B>(\n f: (...a: A) => B\n): (...a: A) => Option<B> =>\n(...a) => {\n try {\n return some(f(...a))\n } catch (e) {\n return none()\n }\n}\n\n/**\n * Extracts the value of an `Option` or throws if the `Option` is `None`.\n *\n * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.\n *\n * @param self - The `Option` to extract the value from.\n * @param onNone - A function that will be called if the `Option` is `None`. It returns the error to be thrown.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Option.getOrThrowWith(Option.some(1), () => new Error('Unexpected None')),\n * 1\n * )\n * assert.throws(() => Option.getOrThrowWith(Option.none(), () => new Error('Unexpected None')))\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const getOrThrowWith: {\n /**\n * Extracts the value of an `Option` or throws if the `Option` is `None`.\n *\n * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.\n *\n * @param self - The `Option` to extract the value from.\n * @param onNone - A function that will be called if the `Option` is `None`. It returns the error to be thrown.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Option.getOrThrowWith(Option.some(1), () => new Error('Unexpected None')),\n * 1\n * )\n * assert.throws(() => Option.getOrThrowWith(Option.none(), () => new Error('Unexpected None')))\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\n (onNone: () => unknown): <A>(self: Option<A>) => A\n /**\n * Extracts the value of an `Option` or throws if the `Option` is `None`.\n *\n * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.\n *\n * @param self - The `Option` to extract the value from.\n * @param onNone - A function that will be called if the `Option` is `None`. It returns the error to be thrown.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Option.getOrThrowWith(Option.some(1), () => new Error('Unexpected None')),\n * 1\n * )\n * assert.throws(() => Option.getOrThrowWith(Option.none(), () => new Error('Unexpected None')))\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\n <A>(self: Option<A>, onNone: () => unknown): A\n} = dual(2, <A>(self: Option<A>, onNone: () => unknown): A => {\n if (isSome(self)) {\n return self.value\n }\n throw onNone()\n})\n\n/**\n * Extracts the value of an `Option` or throws if the `Option` is `None`.\n *\n * The thrown error is a default error. To configure the error thrown, see {@link getOrThrowWith}.\n *\n * @param self - The `Option` to extract the value from.\n * @throws `Error(\"getOrThrow called on a None\")`\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.getOrThrow(Option.some(1)), 1)\n * assert.throws(() => Option.getOrThrow(Option.none()))\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const getOrThrow: <A>(self: Option<A>) => A = getOrThrowWith(() => new Error(\"getOrThrow called on a None\"))\n\n/**\n * Maps the `Some` side of an `Option` value to a new `Option` value.\n *\n * @param self - An `Option` to map\n * @param f - The function to map over the value of the `Option`\n *\n * @category mapping\n * @since 2.0.0\n */\nexport const map: {\n /**\n * Maps the `Some` side of an `Option` value to a new `Option` value.\n *\n * @param self - An `Option` to map\n * @param f - The function to map over the value of the `Option`\n *\n * @category mapping\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B): (self: Option<A>) => Option<B>\n /**\n * Maps the `Some` side of an `Option` value to a new `Option` value.\n *\n * @param self - An `Option` to map\n * @param f - The function to map over the value of the `Option`\n *\n * @category mapping\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => B): Option<B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => B): Option<B> => isNone(self) ? none() : some(f(self.value))\n)\n\n/**\n * Maps the `Some` value of this `Option` to the specified constant value.\n *\n * @category mapping\n * @since 2.0.0\n */\nexport const as: {\n /**\n * Maps the `Some` value of this `Option` to the specified constant value.\n *\n * @category mapping\n * @since 2.0.0\n */\n <B>(b: B): <X>(self: Option<X>) => Option<B>\n} = dual(2, <X, B>(self: Option<X>, b: B): Option<B> => map(self, () => b))\n\n/**\n * Maps the `Some` value of this `Option` to the `void` constant value.\n *\n * This is useful when the value of the `Option` is not needed, but the presence or absence of the value is important.\n *\n * @category mapping\n * @since 2.0.0\n */\nexport const asVoid: <_>(self: Option<_>) => Option<void> = as(undefined)\n\nconst void_: Option<void> = some(undefined)\nexport {\n /**\n * @since 2.0.0\n */\n void_ as void\n}\n\n/**\n * Applies a function to the value of an `Option` and flattens the result, if the input is `Some`.\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatMap: {\n /**\n * Applies a function to the value of an `Option` and flattens the result, if the input is `Some`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => Option<B>): (self: Option<A>) => Option<B>\n /**\n * Applies a function to the value of an `Option` and flattens the result, if the input is `Some`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B> => isNone(self) ? none() : f(self.value)\n)\n\n/**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const andThen: {\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => Option<B>): (self: Option<A>) => Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <B>(f: Option<B>): <A>(self: Option<A>) => Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B): (self: Option<A>) => Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <B>(f: NotFunction<B>): <A>(self: Option<A>) => Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: Option<B>): Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => B): Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: NotFunction<B>): Option<B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => Option<B> | Option<B>): Option<B> =>\n flatMap(self, (a) => {\n const b = isFunction(f) ? f(a) : f\n return isOption(b) ? b : some(b)\n })\n)\n\n/**\n * This is `flatMap` + `fromNullable`, useful when working with optional values.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * interface Employee {\n * company?: {\n * address?: {\n * street?: {\n * name?: string\n * }\n * }\n * }\n * }\n *\n * const employee1: Employee = { company: { address: { street: { name: 'high street' } } } }\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.some(employee1),\n * Option.flatMapNullable(employee => employee.company?.address?.street?.name),\n * ),\n * Option.some('high street')\n * )\n *\n * const employee2: Employee = { company: { address: { street: {} } } }\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.some(employee2),\n * Option.flatMapNullable(employee => employee.company?.address?.street?.name),\n * ),\n * Option.none()\n * )\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatMapNullable: {\n /**\n * This is `flatMap` + `fromNullable`, useful when working with optional values.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * interface Employee {\n * company?: {\n * address?: {\n * street?: {\n * name?: string\n * }\n * }\n * }\n * }\n *\n * const employee1: Employee = { company: { address: { street: { name: 'high street' } } } }\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.some(employee1),\n * Option.flatMapNullable(employee => employee.company?.address?.street?.name),\n * ),\n * Option.some('high street')\n * )\n *\n * const employee2: Employee = { company: { address: { street: {} } } }\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.some(employee2),\n * Option.flatMapNullable(employee => employee.company?.address?.street?.name),\n * ),\n * Option.none()\n * )\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B | null | undefined): (self: Option<A>) => Option<NonNullable<B>>\n /**\n * This is `flatMap` + `fromNullable`, useful when working with optional values.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * interface Employee {\n * company?: {\n * address?: {\n * street?: {\n * name?: string\n * }\n * }\n * }\n * }\n *\n * const employee1: Employee = { company: { address: { street: { name: 'high street' } } } }\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.some(employee1),\n * Option.flatMapNullable(employee => employee.company?.address?.street?.name),\n * ),\n * Option.some('high street')\n * )\n *\n * const employee2: Employee = { company: { address: { street: {} } } }\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.some(employee2),\n * Option.flatMapNullable(employee => employee.company?.address?.street?.name),\n * ),\n * Option.none()\n * )\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => B | null | undefined): Option<NonNullable<B>>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => B | null | undefined): Option<NonNullable<B>> =>\n isNone(self) ? none() : fromNullable(f(self.value))\n)\n\n/**\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatten: <A>(self: Option<Option<A>>) => Option<A> = flatMap(identity)\n\n/**\n * @category zipping\n * @since 2.0.0\n */\nexport const zipRight: {\n /**\n * @category zipping\n * @since 2.0.0\n */\n <B>(that: Option<B>): <_>(self: Option<_>) => Option<B>\n /**\n * @category zipping\n * @since 2.0.0\n */\n <X, B>(self: Option<X>, that: Option<B>): Option<B>\n} = dual(2, <X, B>(self: Option<X>, that: Option<B>): Option<B> => flatMap(self, () => that))\n\n/**\n * @category sequencing\n * @since 2.0.0\n */\nexport const composeK: {\n /**\n * @category sequencing\n * @since 2.0.0\n */\n <B, C>(bfc: (b: B) => Option<C>): <A>(afb: (a: A) => Option<B>) => (a: A) => Option<C>\n /**\n * @category sequencing\n * @since 2.0.0\n */\n <A, B, C>(afb: (a: A) => Option<B>, bfc: (b: B) => Option<C>): (a: A) => Option<C>\n} = dual(2, <A, B, C>(afb: (a: A) => Option<B>, bfc: (b: B) => Option<C>) => (a: A): Option<C> => flatMap(afb(a), bfc))\n\n/**\n * Sequences the specified `that` `Option` but ignores its value.\n *\n * It is useful when we want to chain multiple operations, but only care about the result of `self`.\n *\n * @param that - The `Option` that will be ignored in the chain and discarded\n * @param self - The `Option` we care about\n *\n * @category zipping\n * @since 2.0.0\n */\nexport const zipLeft: {\n /**\n * Sequences the specified `that` `Option` but ignores its value.\n *\n * It is useful when we want to chain multiple operations, but only care about the result of `self`.\n *\n * @param that - The `Option` that will be ignored in the chain and discarded\n * @param self - The `Option` we care about\n *\n * @category zipping\n * @since 2.0.0\n */\n <_>(that: Option<_>): <A>(self: Option<A>) => Option<A>\n /**\n * Sequences the specified `that` `Option` but ignores its value.\n *\n * It is useful when we want to chain multiple operations, but only care about the result of `self`.\n *\n * @param that - The `Option` that will be ignored in the chain and discarded\n * @param self - The `Option` we care about\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, X>(self: Option<A>, that: Option<X>): Option<A>\n} = dual(2, <A, X>(self: Option<A>, that: Option<X>): Option<A> => tap(self, () => that))\n\n/**\n * Applies the provided function `f` to the value of the `Option` if it is `Some` and returns the original `Option`\n * unless `f` returns `None`, in which case it returns `None`.\n *\n * This function is useful for performing additional computations on the value of the input `Option` without affecting its value.\n *\n * @param f - Function to apply to the value of the `Option` if it is `Some`\n * @param self - The `Option` to apply the function to\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getInteger = (n: number) => Number.isInteger(n) ? Option.some(n) : Option.none()\n *\n * assert.deepStrictEqual(Option.tap(Option.none(), getInteger), Option.none())\n * assert.deepStrictEqual(Option.tap(Option.some(1), getInteger), Option.some(1))\n * assert.deepStrictEqual(Option.tap(Option.some(1.14), getInteger), Option.none())\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const tap: {\n /**\n * Applies the provided function `f` to the value of the `Option` if it is `Some` and returns the original `Option`\n * unless `f` returns `None`, in which case it returns `None`.\n *\n * This function is useful for performing additional computations on the value of the input `Option` without affecting its value.\n *\n * @param f - Function to apply to the value of the `Option` if it is `Some`\n * @param self - The `Option` to apply the function to\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getInteger = (n: number) => Number.isInteger(n) ? Option.some(n) : Option.none()\n *\n * assert.deepStrictEqual(Option.tap(Option.none(), getInteger), Option.none())\n * assert.deepStrictEqual(Option.tap(Option.some(1), getInteger), Option.some(1))\n * assert.deepStrictEqual(Option.tap(Option.some(1.14), getInteger), Option.none())\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, X>(f: (a: A) => Option<X>): (self: Option<A>) => Option<A>\n /**\n * Applies the provided function `f` to the value of the `Option` if it is `Some` and returns the original `Option`\n * unless `f` returns `None`, in which case it returns `None`.\n *\n * This function is useful for performing additional computations on the value of the input `Option` without affecting its value.\n *\n * @param f - Function to apply to the value of the `Option` if it is `Some`\n * @param self - The `Option` to apply the function to\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getInteger = (n: number) => Number.isInteger(n) ? Option.some(n) : Option.none()\n *\n * assert.deepStrictEqual(Option.tap(Option.none(), getInteger), Option.none())\n * assert.deepStrictEqual(Option.tap(Option.some(1), getInteger), Option.some(1))\n * assert.deepStrictEqual(Option.tap(Option.some(1.14), getInteger), Option.none())\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, X>(self: Option<A>, f: (a: A) => Option<X>): Option<A>\n} = dual(2, <A, X>(self: Option<A>, f: (a: A) => Option<X>): Option<A> => flatMap(self, (a) => map(f(a), () => a)))\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const product = <A, B>(self: Option<A>, that: Option<B>): Option<[A, B]> =>\n isSome(self) && isSome(that) ? some([self.value, that.value]) : none()\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const productMany = <A>(\n self: Option<A>,\n collection: Iterable<Option<A>>\n): Option<[A, ...Array<A>]> => {\n if (isNone(self)) {\n return none()\n }\n const out: [A, ...Array<A>] = [self.value]\n for (const o of collection) {\n if (isNone(o)) {\n return none()\n }\n out.push(o.value)\n }\n return some(out)\n}\n\n/**\n * Takes a structure of `Option`s and returns an `Option` of values with the same structure.\n *\n * - If a tuple is supplied, then the returned `Option` will contain a tuple with the same length.\n * - If a struct is supplied, then the returned `Option` will contain a struct with the same keys.\n * - If an iterable is supplied, then the returned `Option` will contain an array.\n *\n * @param fields - the struct of `Option`s to be sequenced.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.all([Option.some(1), Option.some(2)]), Option.some([1, 2]))\n * assert.deepStrictEqual(Option.all({ a: Option.some(1), b: Option.some(\"hello\") }), Option.some({ a: 1, b: \"hello\" }))\n * assert.deepStrictEqual(Option.all({ a: Option.some(1), b: Option.none() }), Option.none())\n * ```\n *\n * @category combining\n * @since 2.0.0\n */\n// @ts-expect-error\nexport const all: <const I extends Iterable<Option<any>> | Record<string, Option<any>>>(\n input: I\n) => [I] extends [ReadonlyArray<Option<any>>] ? Option<\n { -readonly [K in keyof I]: [I[K]] extends [Option<infer A>] ? A : never }\n >\n : [I] extends [Iterable<Option<infer A>>] ? Option<Array<A>>\n : Option<{ -readonly [K in keyof I]: [I[K]] extends [Option<infer A>] ? A : never }> = (\n input: Iterable<Option<any>> | Record<string, Option<any>>\n ): Option<any> => {\n if (Symbol.iterator in input) {\n const out: Array<Option<any>> = []\n for (const o of (input as Iterable<Option<any>>)) {\n if (isNone(o)) {\n return none()\n }\n out.push(o.value)\n }\n return some(out)\n }\n\n const out: Record<string, any> = {}\n for (const key of Object.keys(input)) {\n const o = input[key]\n if (isNone(o)) {\n return none()\n }\n out[key] = o.value\n }\n return some(out)\n }\n\n/**\n * Zips two `Option` values together using a provided function, returning a new `Option` of the result.\n *\n * @param self - The left-hand side of the zip operation\n * @param that - The right-hand side of the zip operation\n * @param f - The function used to combine the values of the two `Option`s\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * type Complex = [real: number, imaginary: number]\n *\n * const complex = (real: number, imaginary: number): Complex => [real, imaginary]\n *\n * assert.deepStrictEqual(Option.zipWith(Option.none(), Option.none(), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.none(), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.none(), Option.some(1), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.some(2), complex), Option.some([1, 2]))\n *\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), complex)(Option.some(2)), Option.some([2, 1]))\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\nexport const zipWith: {\n /**\n * Zips two `Option` values together using a provided function, returning a new `Option` of the result.\n *\n * @param self - The left-hand side of the zip operation\n * @param that - The right-hand side of the zip operation\n * @param f - The function used to combine the values of the two `Option`s\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * type Complex = [real: number, imaginary: number]\n *\n * const complex = (real: number, imaginary: number): Complex => [real, imaginary]\n *\n * assert.deepStrictEqual(Option.zipWith(Option.none(), Option.none(), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.none(), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.none(), Option.some(1), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.some(2), complex), Option.some([1, 2]))\n *\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), complex)(Option.some(2)), Option.some([2, 1]))\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B, A, C>(that: Option<B>, f: (a: A, b: B) => C): (self: Option<A>) => Option<C>\n /**\n * Zips two `Option` values together using a provided function, returning a new `Option` of the result.\n *\n * @param self - The left-hand side of the zip operation\n * @param that - The right-hand side of the zip operation\n * @param f - The function used to combine the values of the two `Option`s\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * type Complex = [real: number, imaginary: number]\n *\n * const complex = (real: number, imaginary: number): Complex => [real, imaginary]\n *\n * assert.deepStrictEqual(Option.zipWith(Option.none(), Option.none(), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.none(), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.none(), Option.some(1), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.some(2), complex), Option.some([1, 2]))\n *\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), complex)(Option.some(2)), Option.some([2, 1]))\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C>\n} = dual(\n 3,\n <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C> =>\n map(product(self, that), ([a, b]) => f(a, b))\n)\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const ap: {\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(that: Option<A>): <B>(self: Option<(a: A) => B>) => Option<B>\n /**\n * @category combining\n * @since 2.0.0\n */\n <A, B>(self: Option<(a: A) => B>, that: Option<A>): Option<B>\n} = dual(2, <A, B>(self: Option<(a: A) => B>, that: Option<A>): Option<B> => zipWith(self, that, (f, a) => f(a)))\n\n/**\n * Reduces an `Iterable` of `Option<A>` to a single value of type `B`, elements that are `None` are ignored.\n *\n * @param self - The Iterable of `Option<A>` to be reduced.\n * @param b - The initial value of the accumulator.\n * @param f - The reducing function that takes the current accumulator value and the unwrapped value of an `Option<A>`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const iterable = [Option.some(1), Option.none(), Option.some(2), Option.none()]\n * assert.deepStrictEqual(pipe(iterable, Option.reduceCompact(0, (b, a) => b + a)), 3)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const reduceCompact: {\n /**\n * Reduces an `Iterable` of `Option<A>` to a single value of type `B`, elements that are `None` are ignored.\n *\n * @param self - The Iterable of `Option<A>` to be reduced.\n * @param b - The initial value of the accumulator.\n * @param f - The reducing function that takes the current accumulator value and the unwrapped value of an `Option<A>`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const iterable = [Option.some(1), Option.none(), Option.some(2), Option.none()]\n * assert.deepStrictEqual(pipe(iterable, Option.reduceCompact(0, (b, a) => b + a)), 3)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A) => B): (self: Iterable<Option<A>>) => B\n /**\n * Reduces an `Iterable` of `Option<A>` to a single value of type `B`, elements that are `None` are ignored.\n *\n * @param self - The Iterable of `Option<A>` to be reduced.\n * @param b - The initial value of the accumulator.\n * @param f - The reducing function that takes the current accumulator value and the unwrapped value of an `Option<A>`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const iterable = [Option.some(1), Option.none(), Option.some(2), Option.none()]\n * assert.deepStrictEqual(pipe(iterable, Option.reduceCompact(0, (b, a) => b + a)), 3)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<Option<A>>, b: B, f: (b: B, a: A) => B): B\n} = dual(\n 3,\n <A, B>(self: Iterable<Option<A>>, b: B, f: (b: B, a: A) => B): B => {\n let out: B = b\n for (const oa of self) {\n if (isSome(oa)) {\n out = f(out, oa.value)\n }\n }\n return out\n }\n)\n\n/**\n * Transforms an `Option` into an `Array`.\n * If the input is `None`, an empty array is returned.\n * If the input is `Some`, the value is wrapped in an array.\n *\n * @param self - The `Option` to convert to an array.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.toArray(Option.some(1)), [1])\n * assert.deepStrictEqual(Option.toArray(Option.none()), [])\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const toArray = <A>(self: Option<A>): Array<A> => isNone(self) ? [] : [self.value]\n\n/**\n * @category filtering\n * @since 2.0.0\n */\nexport const partitionMap: {\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A, B, C>(f: (a: A) => Either<C, B>): (self: Option<A>) => [left: Option<B>, right: Option<C>]\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A, B, C>(self: Option<A>, f: (a: A) => Either<C, B>): [left: Option<B>, right: Option<C>]\n} = dual(2, <A, B, C>(\n self: Option<A>,\n f: (a: A) => Either<C, B>\n): [excluded: Option<B>, satisfying: Option<C>] => {\n if (isNone(self)) {\n return [none(), none()]\n }\n const e = f(self.value)\n return either.isLeft(e) ? [some(e.left), none()] : [none(), some(e.right)]\n})\n\n/**\n * Maps over the value of an `Option` and filters out `None`s.\n *\n * Useful when in addition to filtering you also want to change the type of the `Option`.\n *\n * @param self - The `Option` to map over.\n * @param f - A function to apply to the value of the `Option`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const evenNumber = (n: number) => n % 2 === 0 ? Option.some(n) : Option.none()\n *\n * assert.deepStrictEqual(Option.filterMap(Option.none(), evenNumber), Option.none())\n * assert.deepStrictEqual(Option.filterMap(Option.some(3), evenNumber), Option.none())\n * assert.deepStrictEqual(Option.filterMap(Option.some(2), evenNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const filterMap: {\n /**\n * Maps over the value of an `Option` and filters out `None`s.\n *\n * Useful when in addition to filtering you also want to change the type of the `Option`.\n *\n * @param self - The `Option` to map over.\n * @param f - A function to apply to the value of the `Option`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const evenNumber = (n: number) => n % 2 === 0 ? Option.some(n) : Option.none()\n *\n * assert.deepStrictEqual(Option.filterMap(Option.none(), evenNumber), Option.none())\n * assert.deepStrictEqual(Option.filterMap(Option.some(3), evenNumber), Option.none())\n * assert.deepStrictEqual(Option.filterMap(Option.some(2), evenNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => Option<B>): (self: Option<A>) => Option<B>\n /**\n * Maps over the value of an `Option` and filters out `None`s.\n *\n * Useful when in addition to filtering you also want to change the type of the `Option`.\n *\n * @param self - The `Option` to map over.\n * @param f - A function to apply to the value of the `Option`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const evenNumber = (n: number) => n % 2 === 0 ? Option.some(n) : Option.none()\n *\n * assert.deepStrictEqual(Option.filterMap(Option.none(), evenNumber), Option.none())\n * assert.deepStrictEqual(Option.filterMap(Option.some(3), evenNumber), Option.none())\n * assert.deepStrictEqual(Option.filterMap(Option.some(2), evenNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B> => isNone(self) ? none() : f(self.value)\n)\n\n/**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @param predicate - A predicate function to apply to the `Option` value.\n * @param fb - The `Option` to filter.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // predicate\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(3), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isEven), Option.some(2))\n *\n * // refinement\n * const isNumber = (v: unknown): v is number => typeof v === \"number\"\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some('hello'), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const filter: {\n /**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @param predicate - A predicate function to apply to the `Option` value.\n * @param fb - The `Option` to filter.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // predicate\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(3), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isEven), Option.some(2))\n *\n * // refinement\n * const isNumber = (v: unknown): v is number => typeof v === \"number\"\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some('hello'), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: Option<A>) => Option<B>\n /**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @param predicate - A predicate function to apply to the `Option` value.\n * @param fb - The `Option` to filter.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // predicate\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(3), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isEven), Option.some(2))\n *\n * // refinement\n * const isNumber = (v: unknown): v is number => typeof v === \"number\"\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some('hello'), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A>(predicate: Predicate<NoInfer<A>>): (self: Option<A>) => Option<A>\n /**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @param predicate - A predicate function to apply to the `Option` value.\n * @param fb - The `Option` to filter.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // predicate\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(3), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isEven), Option.some(2))\n *\n * // refinement\n * const isNumber = (v: unknown): v is number => typeof v === \"number\"\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some('hello'), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(self: Option<A>, refinement: Refinement<A, B>): Option<B>\n /**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @param predicate - A predicate function to apply to the `Option` value.\n * @param fb - The `Option` to filter.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // predicate\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(3), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isEven), Option.some(2))\n *\n * // refinement\n * const isNumber = (v: unknown): v is number => typeof v === \"number\"\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some('hello'), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A>(self: Option<A>, predicate: Predicate<A>): Option<A>\n} = dual(\n 2,\n <A>(self: Option<A>, predicate: Predicate<A>): Option<A> =>\n filterMap(self, (b) => (predicate(b) ? option.some(b) : option.none))\n)\n\n/**\n * @example\n * ```ts\n * import { Option, Number } from \"effect\"\n *\n * const isEquivalent = Option.getEquivalence(Number.Equivalence)\n * assert.deepStrictEqual(isEquivalent(Option.none(), Option.none()), true)\n * assert.deepStrictEqual(isEquivalent(Option.none(), Option.some(1)), false)\n * assert.deepStrictEqual(isEquivalent(Option.some(1), Option.none()), false)\n * assert.deepStrictEqual(isEquivalent(Option.some(1), Option.some(2)), false)\n * assert.deepStrictEqual(isEquivalent(Option.some(1), Option.some(1)), true)\n * ```\n *\n * @category equivalence\n * @since 2.0.0\n */\nexport const getEquivalence = <A>(isEquivalent: Equivalence.Equivalence<A>): Equivalence.Equivalence<Option<A>> =>\n Equivalence.make((x, y) => isNone(x) ? isNone(y) : isNone(y) ? false : isEquivalent(x.value, y.value))\n\n/**\n * The `Order` instance allows `Option` values to be compared with\n * `compare`, whenever there is an `Order` instance for\n * the type the `Option` contains.\n *\n * `None` is considered to be less than any `Some` value.\n *\n * @example\n * ```ts\n * import { pipe, Option, Number } from \"effect\"\n *\n * const O = Option.getOrder(Number.Order)\n * assert.deepStrictEqual(O(Option.none(), Option.none()), 0)\n * assert.deepStrictEqual(O(Option.none(), Option.some(1)), -1)\n * assert.deepStrictEqual(O(Option.some(1), Option.none()), 1)\n * assert.deepStrictEqual(O(Option.some(1), Option.some(2)), -1)\n * assert.deepStrictEqual(O(Option.some(1), Option.some(1)), 0)\n * ```\n *\n * @category sorting\n * @since 2.0.0\n */\nexport const getOrder = <A>(O: Order<A>): Order<Option<A>> =>\n order.make((self, that) => isSome(self) ? (isSome(that) ? O(self.value, that.value) : 1) : -1)\n\n/**\n * Lifts a binary function into `Option`.\n *\n * @param f - The function to lift.\n *\n * @category lifting\n * @since 2.0.0\n */\nexport const lift2 = <A, B, C>(f: (a: A, b: B) => C): {\n (that: Option<B>): (self: Option<A>) => Option<C>\n (self: Option<A>, that: Option<B>): Option<C>\n} => dual(2, (self: Option<A>, that: Option<B>): Option<C> => zipWith(self, that, f))\n\n/**\n * Transforms a `Predicate` function into a `Some` of the input value if the predicate returns `true` or `None`\n * if the predicate returns `false`.\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getOption = Option.liftPredicate((n: number) => n >= 0)\n *\n * assert.deepStrictEqual(getOption(-1), Option.none())\n * assert.deepStrictEqual(getOption(1), Option.some(1))\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\nexport const liftPredicate: { // Note: I intentionally avoid using the NoInfer pattern here.\n <A, B extends A>(refinement: Refinement<A, B>): (a: A) => Option<B>\n /**\n * Transforms a `Predicate` function into a `Some` of the input value if the predicate returns `true` or `None`\n * if the predicate returns `false`.\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getOption = Option.liftPredicate((n: number) => n >= 0)\n *\n * assert.deepStrictEqual(getOption(-1), Option.none())\n * assert.deepStrictEqual(getOption(1), Option.some(1))\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\n <B extends A, A = B>(predicate: Predicate<A>): (b: B) => Option<B>\n /**\n * Transforms a `Predicate` function into a `Some` of the input value if the predicate returns `true` or `None`\n * if the predicate returns `false`.\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getOption = Option.liftPredicate((n: number) => n >= 0)\n *\n * assert.deepStrictEqual(getOption(-1), Option.none())\n * assert.deepStrictEqual(getOption(1), Option.some(1))\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\n <A, B extends A>(self: A, refinement: Refinement<A, B>): Option<B>\n /**\n * Transforms a `Predicate` function into a `Some` of the input value if the predicate returns `true` or `None`\n * if the predicate returns `false`.\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getOption = Option.liftPredicate((n: number) => n >= 0)\n *\n * assert.deepStrictEqual(getOption(-1), Option.none())\n * assert.deepStrictEqual(getOption(1), Option.some(1))\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\n <B extends A, A = B>(self: B, predicate: Predicate<A>): Option<B>\n} = dual(\n 2,\n <B extends A, A = B>(b: B, predicate: Predicate<A>): Option<B> => predicate(b) ? some(b) : none()\n)\n\n/**\n * Returns a function that checks if a `Option` contains a given value using a provided `isEquivalent` function.\n *\n * @param equivalent - An `Equivalence` instance to compare values of the `Option`.\n * @param self - The `Option` to apply the comparison to.\n * @param a - The value to compare against the `Option`.\n *\n * @example\n * ```ts\n * import { pipe, Option, Number } from \"effect\"\n *\n * assert.deepStrictEqual(pipe(Option.some(2), Option.containsWith(Number.Equivalence)(2)), true)\n * assert.deepStrictEqual(pipe(Option.some(1), Option.containsWith(Number.Equivalence)(2)), false)\n * assert.deepStrictEqual(pipe(Option.none(), Option.containsWith(Number.Equivalence)(2)), false)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const containsWith = <A>(isEquivalent: (self: A, that: A) => boolean): {\n (a: A): (self: Option<A>) => boolean\n (self: Option<A>, a: A): boolean\n} => dual(2, (self: Option<A>, a: A): boolean => isNone(self) ? false : isEquivalent(self.value, a))\n\nconst _equivalence = Equal.equivalence()\n\n/**\n * Returns a function that checks if an `Option` contains a given value using the default `Equivalence`.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const contains: {\n /**\n * Returns a function that checks if an `Option` contains a given value using the default `Equivalence`.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(a: A): (self: Option<A>) => boolean\n /**\n * Returns a function that checks if an `Option` contains a given value using the default `Equivalence`.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Option<A>, a: A): boolean\n} = containsWith(_equivalence)\n\n/**\n * Check if a value in an `Option` type meets a certain predicate.\n *\n * @param self - The `Option` to check.\n * @param predicate - The condition to check.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(pipe(Option.some(2), Option.exists(isEven)), true)\n * assert.deepStrictEqual(pipe(Option.some(1), Option.exists(isEven)), false)\n * assert.deepStrictEqual(pipe(Option.none(), Option.exists(isEven)), false)\n * ```\n *\n * @since 2.0.0\n */\nexport const exists: {\n /**\n * Check if a value in an `Option` type meets a certain predicate.\n *\n * @param self - The `Option` to check.\n * @param predicate - The condition to check.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(pipe(Option.some(2), Option.exists(isEven)), true)\n * assert.deepStrictEqual(pipe(Option.some(1), Option.exists(isEven)), false)\n * assert.deepStrictEqual(pipe(Option.none(), Option.exists(isEven)), false)\n * ```\n *\n * @since 2.0.0\n */\n <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: Option<A>) => self is Option<B>\n /**\n * Check if a value in an `Option` type meets a certain predicate.\n *\n * @param self - The `Option` to check.\n * @param predicate - The condition to check.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(pipe(Option.some(2), Option.exists(isEven)), true)\n * assert.deepStrictEqual(pipe(Option.some(1), Option.exists(isEven)), false)\n * assert.deepStrictEqual(pipe(Option.none(), Option.exists(isEven)), false)\n * ```\n *\n * @since 2.0.0\n */\n <A>(predicate: Predicate<NoInfer<A>>): (self: Option<A>) => boolean\n /**\n * Check if a value in an `Option` type meets a certain predicate.\n *\n * @param self - The `Option` to check.\n * @param predicate - The condition to check.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(pipe(Option.some(2), Option.exists(isEven)), true)\n * assert.deepStrictEqual(pipe(Option.some(1), Option.exists(isEven)), false)\n * assert.deepStrictEqual(pipe(Option.none(), Option.exists(isEven)), false)\n * ```\n *\n * @since 2.0.0\n */\n <A, B extends A>(self: Option<A>, refinement: Refinement<A, B>): self is Option<B>\n /**\n * Check if a value in an `Option` type meets a certain predicate.\n *\n * @param self - The `Option` to check.\n * @param predicate - The condition to check.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(pipe(Option.some(2), Option.exists(isEven)), true)\n * assert.deepStrictEqual(pipe(Option.some(1), Option.exists(isEven)), false)\n * assert.deepStrictEqual(pipe(Option.none(), Option.exists(isEven)), false)\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Option<A>, predicate: Predicate<A>): boolean\n} = dual(\n 2,\n <A, B extends A>(self: Option<A>, refinement: Refinement<A, B>): self is Option<B> =>\n isNone(self) ? false : refinement(self.value)\n)\n\n// -------------------------------------------------------------------------------------\n// do notation\n// -------------------------------------------------------------------------------------\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\nexport const bindTo: {\n // -------------------------------------------------------------------------------------\n // do notation\n // -------------------------------------------------------------------------------------\n\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <N extends string>(name: N): <A>(self: Option<A>) => Option<{ [K in N]: A }>\n // -------------------------------------------------------------------------------------\n // do notation\n // -------------------------------------------------------------------------------------\n\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <A, N extends string>(self: Option<A>, name: N): Option<{ [K in N]: A }>\n} = doNotation.bindTo<OptionTypeLambda>(map)\n\nconst let_: {\n <N extends string, A extends object, B>(\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): (self: Option<A>) => Option<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n <A extends object, N extends string, B>(\n self: Option<A>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): Option<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n} = doNotation.let_<OptionTypeLambda>(map)\n\nexport {\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link bindTo}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n *\n * ```\n * @category do notation\n * @since 2.0.0\n */\n let_ as let\n}\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\nexport const bind: {\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <N extends string, A extends object, B>(\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => Option<B>\n ): (self: Option<A>) => Option<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <A extends object, N extends string, B>(\n self: Option<A>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => Option<B>\n ): Option<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n} = doNotation.bind<OptionTypeLambda>(map, flatMap)\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\nexport const Do: Option<{}> = some({})\n\nconst adapter = Gen.adapter<OptionTypeLambda>()\n\n/**\n * @category generators\n * @since 2.0.0\n */\nexport const gen: Gen.Gen<OptionTypeLambda, Gen.Adapter<OptionTypeLambda>> = (...args) => {\n let f: any\n if (args.length === 1) {\n f = args[0]\n } else {\n f = args[1].bind(args[0])\n }\n const iterator = f(adapter)\n let state: IteratorYieldResult<any> | IteratorReturnResult<any> = iterator.next()\n if (state.done) {\n return some(state.value)\n } else {\n let current = state.value\n if (Gen.isGenKind(current)) {\n current = current.value\n } else {\n current = Gen.yieldWrapGet(current)\n }\n if (isNone(current)) {\n return current\n }\n while (!state.done) {\n state = iterator.next(current.value as never)\n if (!state.done) {\n current = state.value\n if (Gen.isGenKind(current)) {\n current = current.value\n } else {\n current = Gen.yieldWrapGet(current)\n }\n if (isNone(current)) {\n return current\n }\n }\n }\n return some(state.value)\n }\n}\n","/**\n * This module provides utility functions for working with arrays in TypeScript.\n *\n * @since 2.0.0\n */\n\nimport type { Either as array_ } from \"./Either.js\"\nimport * as E from \"./Either.js\"\nimport * as Equal from \"./Equal.js\"\nimport * as Equivalence from \"./Equivalence.js\"\nimport type { LazyArg } from \"./Function.js\"\nimport { dual, identity } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\nimport * as readonlyArray from \"./internal/array.js\"\nimport * as doNotation from \"./internal/doNotation.js\"\nimport * as EffectIterable from \"./Iterable.js\"\nimport type { Option } from \"./Option.js\"\nimport * as O from \"./Option.js\"\nimport * as Order from \"./Order.js\"\nimport type { Predicate, Refinement } from \"./Predicate.js\"\nimport { isBoolean } from \"./Predicate.js\"\nimport * as Record from \"./Record.js\"\nimport * as Tuple from \"./Tuple.js\"\nimport type { NoInfer } from \"./Types.js\"\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface ReadonlyArrayTypeLambda extends TypeLambda {\n readonly type: ReadonlyArray<this[\"Target\"]>\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport type NonEmptyReadonlyArray<A> = readonly [A, ...Array<A>]\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport type NonEmptyArray<A> = [A, ...Array<A>]\n\n/**\n * Builds a `NonEmptyArray` from an non-empty collection of elements.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.make(1, 2, 3)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const make = <Elements extends NonEmptyArray<any>>(\n ...elements: Elements\n): NonEmptyArray<Elements[number]> => elements\n\n/**\n * Creates a new `Array` of the specified length.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.allocate<number>(3)\n * assert.deepStrictEqual(result.length, 3)\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const allocate = <A = never>(n: number): Array<A | undefined> => new Array(n)\n\n/**\n * Return a `NonEmptyArray` of length `n` with element `i` initialized with `f(i)`.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * @example\n * ```ts\n * import { makeBy } from \"effect/Array\"\n *\n * assert.deepStrictEqual(makeBy(5, n => n * 2), [0, 2, 4, 6, 8])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const makeBy = <A>(n: number, f: (i: number) => A): NonEmptyArray<A> => {\n const max = Math.max(1, Math.floor(n))\n const out = new Array(max)\n for (let i = 0; i < max; i++) {\n out[i] = f(i)\n }\n return out as NonEmptyArray<A>\n}\n\n/**\n * Return a `NonEmptyArray` containing a range of integers, including both endpoints.\n *\n * @example\n * ```ts\n * import { range } from \"effect/Array\"\n *\n * assert.deepStrictEqual(range(1, 3), [1, 2, 3])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const range = (start: number, end: number): NonEmptyArray<number> =>\n start <= end ? makeBy(end - start + 1, (i) => start + i) : [start]\n\n/**\n * Return a `NonEmptyArray` containing a value repeated the specified number of times.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * assert.deepStrictEqual(Array.replicate(\"a\", 3), [\"a\", \"a\", \"a\"])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const replicate: {\n /**\n * Return a `NonEmptyArray` containing a value repeated the specified number of times.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * assert.deepStrictEqual(Array.replicate(\"a\", 3), [\"a\", \"a\", \"a\"])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n (n: number): <A>(a: A) => NonEmptyArray<A>\n /**\n * Return a `NonEmptyArray` containing a value repeated the specified number of times.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * assert.deepStrictEqual(Array.replicate(\"a\", 3), [\"a\", \"a\", \"a\"])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <A>(a: A, n: number): NonEmptyArray<A>\n} = dual(2, <A>(a: A, n: number): NonEmptyArray<A> => makeBy(n, () => a))\n\n/**\n * Creates a new `Array` from an iterable collection of values.\n * If the input is already an array, it returns the input as-is.\n * Otherwise, it converts the iterable collection to an array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const set = new Set([1, 2, 3])\n * const result = Array.fromIterable(set)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const fromIterable = <A>(collection: Iterable<A>): Array<A> =>\n Array.isArray(collection) ? collection : Array.from(collection)\n\n/**\n * Creates a new `Array` from a value that might not be an iterable.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * assert.deepStrictEqual(Array.ensure(\"a\"), [\"a\"])\n * assert.deepStrictEqual(Array.ensure([\"a\"]), [\"a\"])\n * assert.deepStrictEqual(Array.ensure([\"a\", \"b\", \"c\"]), [\"a\", \"b\", \"c\"])\n * ```\n *\n * @category constructors\n * @since 3.3.0\n */\nexport const ensure = <A>(self: ReadonlyArray<A> | A): Array<A> => Array.isArray(self) ? self : [self as A]\n\n/**\n * Takes a record and returns an array of tuples containing its keys and values.\n *\n * @param self - The record to transform.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const x = { a: 1, b: 2, c: 3 }\n * assert.deepStrictEqual(Array.fromRecord(x), [[\"a\", 1], [\"b\", 2], [\"c\", 3]])\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const fromRecord: <K extends string, A>(self: Readonly<Record<K, A>>) => Array<[K, A]> = Record.toEntries\n\n/**\n * Converts an `Option` to an array.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Array.fromOption(Option.some(1)), [1])\n * assert.deepStrictEqual(Array.fromOption(Option.none()), [])\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const fromOption: <A>(self: Option<A>) => Array<A> = O.toArray\n\n/**\n * Matches the elements of an array, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const match = Array.match({\n * onEmpty: () => \"empty\",\n * onNonEmpty: ([head, ...tail]) => `head: ${head}, tail: ${tail.length}`\n * })\n * assert.deepStrictEqual(match([]), \"empty\")\n * assert.deepStrictEqual(match([1, 2, 3]), \"head: 1, tail: 2\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\nexport const match: {\n /**\n * Matches the elements of an array, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const match = Array.match({\n * onEmpty: () => \"empty\",\n * onNonEmpty: ([head, ...tail]) => `head: ${head}, tail: ${tail.length}`\n * })\n * assert.deepStrictEqual(match([]), \"empty\")\n * assert.deepStrictEqual(match([1, 2, 3]), \"head: 1, tail: 2\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <B, A, C = B>(\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (self: NonEmptyReadonlyArray<A>) => C\n }\n ): (self: ReadonlyArray<A>) => B | C\n /**\n * Matches the elements of an array, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const match = Array.match({\n * onEmpty: () => \"empty\",\n * onNonEmpty: ([head, ...tail]) => `head: ${head}, tail: ${tail.length}`\n * })\n * assert.deepStrictEqual(match([]), \"empty\")\n * assert.deepStrictEqual(match([1, 2, 3]), \"head: 1, tail: 2\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <A, B, C = B>(\n self: ReadonlyArray<A>,\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (self: NonEmptyReadonlyArray<A>) => C\n }\n ): B | C\n} = dual(2, <A, B, C = B>(\n self: ReadonlyArray<A>,\n { onEmpty, onNonEmpty }: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (self: NonEmptyReadonlyArray<A>) => C\n }\n): B | C => isNonEmptyReadonlyArray(self) ? onNonEmpty(self) : onEmpty())\n\n/**\n * Matches the elements of an array from the left, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchLeft = Array.matchLeft({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (head, tail) => `head: ${head}, tail: ${tail.length}`\n * })\n * assert.deepStrictEqual(matchLeft([]), \"empty\")\n * assert.deepStrictEqual(matchLeft([1, 2, 3]), \"head: 1, tail: 2\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\nexport const matchLeft: {\n /**\n * Matches the elements of an array from the left, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchLeft = Array.matchLeft({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (head, tail) => `head: ${head}, tail: ${tail.length}`\n * })\n * assert.deepStrictEqual(matchLeft([]), \"empty\")\n * assert.deepStrictEqual(matchLeft([1, 2, 3]), \"head: 1, tail: 2\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <B, A, C = B>(\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (head: A, tail: Array<A>) => C\n }\n ): (self: ReadonlyArray<A>) => B | C\n /**\n * Matches the elements of an array from the left, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchLeft = Array.matchLeft({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (head, tail) => `head: ${head}, tail: ${tail.length}`\n * })\n * assert.deepStrictEqual(matchLeft([]), \"empty\")\n * assert.deepStrictEqual(matchLeft([1, 2, 3]), \"head: 1, tail: 2\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <A, B, C = B>(\n self: ReadonlyArray<A>,\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (head: A, tail: Array<A>) => C\n }\n ): B | C\n} = dual(2, <A, B, C = B>(\n self: ReadonlyArray<A>,\n { onEmpty, onNonEmpty }: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (head: A, tail: Array<A>) => C\n }\n): B | C => isNonEmptyReadonlyArray(self) ? onNonEmpty(headNonEmpty(self), tailNonEmpty(self)) : onEmpty())\n\n/**\n * Matches the elements of an array from the right, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchRight = Array.matchRight({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (init, last) => `init: ${init.length}, last: ${last}`\n * })\n * assert.deepStrictEqual(matchRight([]), \"empty\")\n * assert.deepStrictEqual(matchRight([1, 2, 3]), \"init: 2, last: 3\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\nexport const matchRight: {\n /**\n * Matches the elements of an array from the right, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchRight = Array.matchRight({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (init, last) => `init: ${init.length}, last: ${last}`\n * })\n * assert.deepStrictEqual(matchRight([]), \"empty\")\n * assert.deepStrictEqual(matchRight([1, 2, 3]), \"init: 2, last: 3\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <B, A, C = B>(\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (init: Array<A>, last: A) => C\n }\n ): (self: ReadonlyArray<A>) => B | C\n /**\n * Matches the elements of an array from the right, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchRight = Array.matchRight({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (init, last) => `init: ${init.length}, last: ${last}`\n * })\n * assert.deepStrictEqual(matchRight([]), \"empty\")\n * assert.deepStrictEqual(matchRight([1, 2, 3]), \"init: 2, last: 3\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <A, B, C = B>(\n self: ReadonlyArray<A>,\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (init: Array<A>, last: A) => C\n }\n ): B | C\n} = dual(2, <A, B, C = B>(\n self: ReadonlyArray<A>,\n { onEmpty, onNonEmpty }: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (init: Array<A>, last: A) => C\n }\n): B | C =>\n isNonEmptyReadonlyArray(self) ?\n onNonEmpty(initNonEmpty(self), lastNonEmpty(self)) :\n onEmpty())\n\n/**\n * Prepend an element to the front of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const original = [2, 3, 4];\n * const result = Array.prepend(original, 1);\n * assert.deepStrictEqual(result, [1, 2, 3, 4]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const prepend: {\n /**\n * Prepend an element to the front of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const original = [2, 3, 4];\n * const result = Array.prepend(original, 1);\n * assert.deepStrictEqual(result, [1, 2, 3, 4]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <B>(head: B): <A>(self: Iterable<A>) => NonEmptyArray<A | B>\n /**\n * Prepend an element to the front of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const original = [2, 3, 4];\n * const result = Array.prepend(original, 1);\n * assert.deepStrictEqual(result, [1, 2, 3, 4]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, head: B): NonEmptyArray<A | B>\n} = dual(2, <A, B>(self: Iterable<A>, head: B): NonEmptyArray<A | B> => [head, ...self])\n\n/**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const prefix = [0, 1];\n * const array = [2, 3];\n * const result = Array.prependAll(array, prefix);\n * assert.deepStrictEqual(result, [0, 1, 2, 3]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const prependAll: {\n /**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const prefix = [0, 1];\n * const array = [2, 3];\n * const result = Array.prependAll(array, prefix);\n * assert.deepStrictEqual(result, [0, 1, 2, 3]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <S extends Iterable<any>, T extends Iterable<any>>(\n that: T\n ): (self: S) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>\n /**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const prefix = [0, 1];\n * const array = [2, 3];\n * const result = Array.prependAll(array, prefix);\n * assert.deepStrictEqual(result, [0, 1, 2, 3]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<A | B>\n /**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const prefix = [0, 1];\n * const array = [2, 3];\n * const result = Array.prependAll(array, prefix);\n * assert.deepStrictEqual(result, [0, 1, 2, 3]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, that: Iterable<B>): NonEmptyArray<A | B>\n /**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const prefix = [0, 1];\n * const array = [2, 3];\n * const result = Array.prependAll(array, prefix);\n * assert.deepStrictEqual(result, [0, 1, 2, 3]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B>\n} = dual(\n 2,\n <A>(self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(that).concat(fromIterable(self))\n)\n\n/**\n * Append an element to the end of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const original = [1, 2, 3];\n * const result = Array.append(original, 4);\n * assert.deepStrictEqual(result, [1, 2, 3, 4]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const append: {\n /**\n * Append an element to the end of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const original = [1, 2, 3];\n * const result = Array.append(original, 4);\n * assert.deepStrictEqual(result, [1, 2, 3, 4]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <B>(last: B): <A>(self: Iterable<A>) => NonEmptyArray<A | B>\n /**\n * Append an element to the end of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const original = [1, 2, 3];\n * const result = Array.append(original, 4);\n * assert.deepStrictEqual(result, [1, 2, 3, 4]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, last: B): NonEmptyArray<A | B>\n} = dual(2, <A, B>(self: Iterable<A>, last: B): Array<A | B> => [...self, last])\n\n/**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const appendAll: {\n /**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <S extends Iterable<any>, T extends Iterable<any>>(\n that: T\n ): (self: S) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>\n /**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<A | B>\n /**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, that: Iterable<B>): NonEmptyArray<A | B>\n /**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B>\n} = dual(\n 2,\n <A>(self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(self).concat(fromIterable(that))\n)\n\n/**\n * Accumulates values from an `Iterable` starting from the left, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.scan(numbers, 0, (acc, value) => acc + value)\n * assert.deepStrictEqual(result, [0, 1, 3, 6, 10])\n *\n * // Explanation:\n * // This function starts with the initial value (0 in this case)\n * // and adds each element of the array to this accumulator one by one,\n * // keeping track of the cumulative sum after each addition.\n * // Each of these sums is captured in the resulting array.\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const scan: {\n /**\n * Accumulates values from an `Iterable` starting from the left, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.scan(numbers, 0, (acc, value) => acc + value)\n * assert.deepStrictEqual(result, [0, 1, 3, 6, 10])\n *\n * // Explanation:\n * // This function starts with the initial value (0 in this case)\n * // and adds each element of the array to this accumulator one by one,\n * // keeping track of the cumulative sum after each addition.\n * // Each of these sums is captured in the resulting array.\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A) => B): (self: Iterable<A>) => NonEmptyArray<B>\n /**\n * Accumulates values from an `Iterable` starting from the left, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.scan(numbers, 0, (acc, value) => acc + value)\n * assert.deepStrictEqual(result, [0, 1, 3, 6, 10])\n *\n * // Explanation:\n * // This function starts with the initial value (0 in this case)\n * // and adds each element of the array to this accumulator one by one,\n * // keeping track of the cumulative sum after each addition.\n * // Each of these sums is captured in the resulting array.\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B>\n} = dual(3, <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B> => {\n const out: NonEmptyArray<B> = [b]\n let i = 0\n for (const a of self) {\n out[i + 1] = f(out[i], a)\n i++\n }\n return out\n})\n\n/**\n * Accumulates values from an `Iterable` starting from the right, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.scanRight(numbers, 0, (acc, value) => acc + value)\n * assert.deepStrictEqual(result, [10, 9, 7, 4, 0])\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const scanRight: {\n /**\n * Accumulates values from an `Iterable` starting from the right, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.scanRight(numbers, 0, (acc, value) => acc + value)\n * assert.deepStrictEqual(result, [10, 9, 7, 4, 0])\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A) => B): (self: Iterable<A>) => NonEmptyArray<B>\n /**\n * Accumulates values from an `Iterable` starting from the right, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.scanRight(numbers, 0, (acc, value) => acc + value)\n * assert.deepStrictEqual(result, [10, 9, 7, 4, 0])\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B>\n} = dual(3, <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B> => {\n const input = fromIterable(self)\n const out: NonEmptyArray<B> = new Array(input.length + 1) as any\n out[input.length] = b\n for (let i = input.length - 1; i >= 0; i--) {\n out[i] = f(out[i + 1], input[i])\n }\n return out\n})\n\n/**\n * Determine if `unknown` is an Array.\n *\n * @param self - The value to check.\n *\n * @example\n * ```ts\n * import { isArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isArray(null), false);\n * assert.deepStrictEqual(isArray([1, 2, 3]), true);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isArray: {\n /**\n * Determine if `unknown` is an Array.\n *\n * @param self - The value to check.\n *\n * @example\n * ```ts\n * import { isArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isArray(null), false);\n * assert.deepStrictEqual(isArray([1, 2, 3]), true);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\n (self: unknown): self is Array<unknown>\n /**\n * Determine if `unknown` is an Array.\n *\n * @param self - The value to check.\n *\n * @example\n * ```ts\n * import { isArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isArray(null), false);\n * assert.deepStrictEqual(isArray([1, 2, 3]), true);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\n <T>(self: T): self is Extract<T, ReadonlyArray<any>>\n} = Array.isArray\n\n/**\n * Determine if an `Array` is empty narrowing down the type to `[]`.\n *\n * @param self - The `Array` to check.\n *\n * @example\n * ```ts\n * import { isEmptyArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isEmptyArray([]), true);\n * assert.deepStrictEqual(isEmptyArray([1, 2, 3]), false);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isEmptyArray = <A>(self: Array<A>): self is [] => self.length === 0\n\n/**\n * Determine if a `ReadonlyArray` is empty narrowing down the type to `readonly []`.\n *\n * @param self - The `ReadonlyArray` to check.\n *\n * @example\n * ```ts\n * import { isEmptyReadonlyArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isEmptyReadonlyArray([]), true);\n * assert.deepStrictEqual(isEmptyReadonlyArray([1, 2, 3]), false);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isEmptyReadonlyArray: <A>(self: ReadonlyArray<A>) => self is readonly [] = isEmptyArray as any\n\n/**\n * Determine if an `Array` is non empty narrowing down the type to `NonEmptyArray`.\n *\n * An `Array` is considered to be a `NonEmptyArray` if it contains at least one element.\n *\n * @param self - The `Array` to check.\n *\n * @example\n * ```ts\n * import { isNonEmptyArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isNonEmptyArray([]), false);\n * assert.deepStrictEqual(isNonEmptyArray([1, 2, 3]), true);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNonEmptyArray: <A>(self: Array<A>) => self is NonEmptyArray<A> = readonlyArray.isNonEmptyArray\n\n/**\n * Determine if a `ReadonlyArray` is non empty narrowing down the type to `NonEmptyReadonlyArray`.\n *\n * A `ReadonlyArray` is considered to be a `NonEmptyReadonlyArray` if it contains at least one element.\n *\n * @param self - The `ReadonlyArray` to check.\n *\n * @example\n * ```ts\n * import { isNonEmptyReadonlyArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isNonEmptyReadonlyArray([]), false);\n * assert.deepStrictEqual(isNonEmptyReadonlyArray([1, 2, 3]), true);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNonEmptyReadonlyArray: <A>(self: ReadonlyArray<A>) => self is NonEmptyReadonlyArray<A> =\n readonlyArray.isNonEmptyArray\n\n/**\n * Return the number of elements in a `ReadonlyArray`.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const length = <A>(self: ReadonlyArray<A>): number => self.length\n\nconst isOutOfBound = <A>(i: number, as: ReadonlyArray<A>): boolean => i < 0 || i >= as.length\n\nconst clamp = <A>(i: number, as: ReadonlyArray<A>): number => Math.floor(Math.min(Math.max(0, i), as.length))\n\n/**\n * This function provides a safe way to read a value at a particular index from a `ReadonlyArray`.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const get: {\n /**\n * This function provides a safe way to read a value at a particular index from a `ReadonlyArray`.\n *\n * @category getters\n * @since 2.0.0\n */\n (index: number): <A>(self: ReadonlyArray<A>) => Option<A>\n /**\n * This function provides a safe way to read a value at a particular index from a `ReadonlyArray`.\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: ReadonlyArray<A>, index: number): Option<A>\n} = dual(2, <A>(self: ReadonlyArray<A>, index: number): Option<A> => {\n const i = Math.floor(index)\n return isOutOfBound(i, self) ? O.none() : O.some(self[i])\n})\n\n/**\n * Gets an element unsafely, will throw on out of bounds.\n *\n * @since 2.0.0\n * @category unsafe\n */\nexport const unsafeGet: {\n /**\n * Gets an element unsafely, will throw on out of bounds.\n *\n * @since 2.0.0\n * @category unsafe\n */\n (index: number): <A>(self: ReadonlyArray<A>) => A\n /**\n * Gets an element unsafely, will throw on out of bounds.\n *\n * @since 2.0.0\n * @category unsafe\n */\n <A>(self: ReadonlyArray<A>, index: number): A\n} = dual(2, <A>(self: ReadonlyArray<A>, index: number): A => {\n const i = Math.floor(index)\n if (isOutOfBound(i, self)) {\n throw new Error(`Index ${i} out of bounds`)\n }\n return self[i]\n})\n\n/**\n * Return a tuple containing the first element, and a new `Array` of the remaining elements, if any.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.unprepend([1, 2, 3, 4])\n * assert.deepStrictEqual(result, [1, [2, 3, 4]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const unprepend = <A>(\n self: NonEmptyReadonlyArray<A>\n): [firstElement: A, remainingElements: Array<A>] => [headNonEmpty(self), tailNonEmpty(self)]\n\n/**\n * Return a tuple containing a copy of the `NonEmptyReadonlyArray` without its last element, and that last element.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.unappend([1, 2, 3, 4])\n * assert.deepStrictEqual(result, [[1, 2, 3], 4])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const unappend = <A>(\n self: NonEmptyReadonlyArray<A>\n): [arrayWithoutLastElement: Array<A>, lastElement: A] => [initNonEmpty(self), lastNonEmpty(self)]\n\n/**\n * Get the first element of a `ReadonlyArray`, or `None` if the `ReadonlyArray` is empty.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const head: <A>(self: ReadonlyArray<A>) => Option<A> = get(0)\n\n/**\n * Get the first element of a non empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.headNonEmpty([1, 2, 3, 4])\n * assert.deepStrictEqual(result, 1)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const headNonEmpty: <A>(self: NonEmptyReadonlyArray<A>) => A = unsafeGet(0)\n\n/**\n * Get the last element in a `ReadonlyArray`, or `None` if the `ReadonlyArray` is empty.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const last = <A>(self: ReadonlyArray<A>): Option<A> =>\n isNonEmptyReadonlyArray(self) ? O.some(lastNonEmpty(self)) : O.none()\n\n/**\n * Get the last element of a non empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.lastNonEmpty([1, 2, 3, 4])\n * assert.deepStrictEqual(result, 4)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const lastNonEmpty = <A>(self: NonEmptyReadonlyArray<A>): A => self[self.length - 1]\n\n/**\n * Get all but the first element of an `Iterable`, creating a new `Array`, or `None` if the `Iterable` is empty.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const tail = <A>(self: Iterable<A>): Option<Array<A>> => {\n const input = fromIterable(self)\n return isNonEmptyReadonlyArray(input) ? O.some(tailNonEmpty(input)) : O.none()\n}\n\n/**\n * Get all but the first element of a `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.tailNonEmpty([1, 2, 3, 4])\n * assert.deepStrictEqual(result, [2, 3, 4])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const tailNonEmpty = <A>(self: NonEmptyReadonlyArray<A>): Array<A> => self.slice(1)\n\n/**\n * Get all but the last element of an `Iterable`, creating a new `Array`, or `None` if the `Iterable` is empty.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const init = <A>(self: Iterable<A>): Option<Array<A>> => {\n const input = fromIterable(self)\n return isNonEmptyReadonlyArray(input) ? O.some(initNonEmpty(input)) : O.none()\n}\n\n/**\n * Get all but the last element of a non empty array, creating a new array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.initNonEmpty([1, 2, 3, 4])\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const initNonEmpty = <A>(self: NonEmptyReadonlyArray<A>): Array<A> => self.slice(0, -1)\n\n/**\n * Keep only a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.take(numbers, 3)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const take: {\n /**\n * Keep only a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.take(numbers, 3)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Keep only a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.take(numbers, 3)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n return input.slice(0, clamp(n, input))\n})\n\n/**\n * Keep only a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.takeRight(numbers, 3)\n * assert.deepStrictEqual(result, [3, 4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const takeRight: {\n /**\n * Keep only a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.takeRight(numbers, 3)\n * assert.deepStrictEqual(result, [3, 4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Keep only a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.takeRight(numbers, 3)\n * assert.deepStrictEqual(result, [3, 4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n const i = clamp(n, input)\n return i === 0 ? [] : input.slice(-i)\n})\n\n/**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 3, 2, 4, 1, 2]\n * const result = Array.takeWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [1, 3, 2])\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const takeWhile: {\n /**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 3, 2, 4, 1, 2]\n * const result = Array.takeWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [1, 3, 2])\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Array<B>\n /**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 3, 2, 4, 1, 2]\n * const result = Array.takeWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [1, 3, 2])\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Array<A>\n /**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 3, 2, 4, 1, 2]\n * const result = Array.takeWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [1, 3, 2])\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Array<B>\n /**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 3, 2, 4, 1, 2]\n * const result = Array.takeWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [1, 3, 2])\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A>\n} = dual(2, <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A> => {\n let i = 0\n const out: Array<A> = []\n for (const a of self) {\n if (!predicate(a, i)) {\n break\n }\n out.push(a)\n i++\n }\n return out\n})\n\nconst spanIndex = <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): number => {\n let i = 0\n for (const a of self) {\n if (!predicate(a, i)) {\n break\n }\n i++\n }\n return i\n}\n\n/**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const span: {\n /**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\n <A, B extends A>(\n refinement: (a: NoInfer<A>, i: number) => a is B\n ): (self: Iterable<A>) => [init: Array<B>, rest: Array<Exclude<A, B>>]\n /**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => [init: Array<A>, rest: Array<A>]\n /**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\n <A, B extends A>(\n self: Iterable<A>,\n refinement: (a: A, i: number) => a is B\n ): [init: Array<B>, rest: Array<Exclude<A, B>>]\n /**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [init: Array<A>, rest: Array<A>]\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [init: Array<A>, rest: Array<A>] =>\n splitAt(self, spanIndex(self, predicate))\n)\n\n/**\n * Drop a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.drop(numbers, 2)\n * assert.deepStrictEqual(result, [3, 4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const drop: {\n /**\n * Drop a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.drop(numbers, 2)\n * assert.deepStrictEqual(result, [3, 4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Drop a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.drop(numbers, 2)\n * assert.deepStrictEqual(result, [3, 4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n return input.slice(clamp(n, input), input.length)\n})\n\n/**\n * Drop a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.dropRight(numbers, 2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const dropRight: {\n /**\n * Drop a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.dropRight(numbers, 2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Drop a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.dropRight(numbers, 2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n return input.slice(0, input.length - clamp(n, input))\n})\n\n/**\n * Remove the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.dropWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const dropWhile: {\n /**\n * Remove the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.dropWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Array<A>\n /**\n * Remove the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.dropWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A>\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A> =>\n fromIterable(self).slice(spanIndex(self, predicate))\n)\n\n/**\n * Return the first index for which a predicate holds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [5, 3, 8, 9]\n * const result = Array.findFirstIndex(numbers, x => x > 5)\n * assert.deepStrictEqual(result, Option.some(2))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findFirstIndex: {\n /**\n * Return the first index for which a predicate holds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [5, 3, 8, 9]\n * const result = Array.findFirstIndex(numbers, x => x > 5)\n * assert.deepStrictEqual(result, Option.some(2))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option<number>\n /**\n * Return the first index for which a predicate holds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [5, 3, 8, 9]\n * const result = Array.findFirstIndex(numbers, x => x > 5)\n * assert.deepStrictEqual(result, Option.some(2))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<number>\n} = dual(2, <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<number> => {\n let i = 0\n for (const a of self) {\n if (predicate(a, i)) {\n return O.some(i)\n }\n i++\n }\n return O.none()\n})\n\n/**\n * Return the last index for which a predicate holds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 3, 8, 9]\n * const result = Array.findLastIndex(numbers, x => x < 5)\n * assert.deepStrictEqual(result, Option.some(1))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findLastIndex: {\n /**\n * Return the last index for which a predicate holds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 3, 8, 9]\n * const result = Array.findLastIndex(numbers, x => x < 5)\n * assert.deepStrictEqual(result, Option.some(1))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option<number>\n /**\n * Return the last index for which a predicate holds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 3, 8, 9]\n * const result = Array.findLastIndex(numbers, x => x < 5)\n * assert.deepStrictEqual(result, Option.some(1))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<number>\n} = dual(2, <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<number> => {\n const input = fromIterable(self)\n for (let i = input.length - 1; i >= 0; i--) {\n if (predicate(input[i], i)) {\n return O.some(i)\n }\n }\n return O.none()\n})\n\n/**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findFirst: {\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(f: (a: NoInfer<A>, i: number) => Option<B>): (self: Iterable<A>) => Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option<A>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<A>\n} = EffectIterable.findFirst\n\n/**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findLast: {\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(f: (a: NoInfer<A>, i: number) => Option<B>): (self: Iterable<A>) => Option<B>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Option<B>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option<A>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Option<B>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Option<B>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<A>\n} = dual(\n 2,\n <A>(self: Iterable<A>, f: ((a: A, i: number) => boolean) | ((a: A, i: number) => Option<A>)): Option<A> => {\n const input = fromIterable(self)\n for (let i = input.length - 1; i >= 0; i--) {\n const a = input[i]\n const o = f(a, i)\n if (isBoolean(o)) {\n if (o) {\n return O.some(a)\n }\n } else {\n if (O.isSome(o)) {\n return o\n }\n }\n }\n return O.none()\n }\n)\n\n/**\n * Insert an element at the specified index, creating a new `NonEmptyArray`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'e']\n * const result = Array.insertAt(letters, 3, 'd')\n * assert.deepStrictEqual(result, Option.some(['a', 'b', 'c', 'd', 'e']))\n * ```\n *\n * @since 2.0.0\n */\nexport const insertAt: {\n /**\n * Insert an element at the specified index, creating a new `NonEmptyArray`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'e']\n * const result = Array.insertAt(letters, 3, 'd')\n * assert.deepStrictEqual(result, Option.some(['a', 'b', 'c', 'd', 'e']))\n * ```\n *\n * @since 2.0.0\n */\n <B>(i: number, b: B): <A>(self: Iterable<A>) => Option<NonEmptyArray<A | B>>\n /**\n * Insert an element at the specified index, creating a new `NonEmptyArray`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'e']\n * const result = Array.insertAt(letters, 3, 'd')\n * assert.deepStrictEqual(result, Option.some(['a', 'b', 'c', 'd', 'e']))\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, i: number, b: B): Option<NonEmptyArray<A | B>>\n} = dual(3, <A, B>(self: Iterable<A>, i: number, b: B): Option<NonEmptyArray<A | B>> => {\n const out: Array<A | B> = Array.from(self)\n // v--- `= self.length` is ok, it means inserting in last position\n if (i < 0 || i > out.length) {\n return O.none()\n }\n out.splice(i, 0, b)\n return O.some(out) as any\n})\n\n/**\n * Change the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.replace(letters, 1, 'z')\n * assert.deepStrictEqual(result, ['a', 'z', 'c', 'd'])\n * ```\n *\n * @since 2.0.0\n */\nexport const replace: {\n /**\n * Change the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.replace(letters, 1, 'z')\n * assert.deepStrictEqual(result, ['a', 'z', 'c', 'd'])\n * ```\n *\n * @since 2.0.0\n */\n <B>(i: number, b: B): <A, S extends Iterable<A> = Iterable<A>>(\n self: S\n ) => ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n /**\n * Change the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.replace(letters, 1, 'z')\n * assert.deepStrictEqual(result, ['a', 'z', 'c', 'd'])\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(\n self: S,\n i: number,\n b: B\n ): ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n} = dual(3, <A, B>(self: Iterable<A>, i: number, b: B): Array<A | B> => modify(self, i, () => b))\n\n/**\n * Replaces an element in an array with the given value, returning an option of the updated array.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.replaceOption(numbers, 1, 4)\n * assert.deepStrictEqual(result, Option.some([1, 4, 3]))\n * ```\n *\n * @since 2.0.0\n */\nexport const replaceOption: {\n /**\n * Replaces an element in an array with the given value, returning an option of the updated array.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.replaceOption(numbers, 1, 4)\n * assert.deepStrictEqual(result, Option.some([1, 4, 3]))\n * ```\n *\n * @since 2.0.0\n */\n <B>(\n i: number,\n b: B\n ): <A, S extends Iterable<A> = Iterable<A>>(self: S) => Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>\n /**\n * Replaces an element in an array with the given value, returning an option of the updated array.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.replaceOption(numbers, 1, 4)\n * assert.deepStrictEqual(result, Option.some([1, 4, 3]))\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(\n self: S,\n i: number,\n b: B\n ): Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>\n} = dual(\n 3,\n <A, B>(self: Iterable<A>, i: number, b: B): Option<Array<A | B>> => modifyOption(self, i, () => b)\n)\n\n/**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.modify(numbers, 2, (n) => n * 2)\n * assert.deepStrictEqual(result, [1, 2, 6, 4])\n * ```\n *\n * @since 2.0.0\n */\nexport const modify: {\n /**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.modify(numbers, 2, (n) => n * 2)\n * assert.deepStrictEqual(result, [1, 2, 6, 4])\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(\n i: number,\n f: (a: ReadonlyArray.Infer<S>) => B\n ): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n /**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.modify(numbers, 2, (n) => n * 2)\n * assert.deepStrictEqual(result, [1, 2, 6, 4])\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(\n self: S,\n i: number,\n f: (a: ReadonlyArray.Infer<S>) => B\n ): ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n} = dual(\n 3,\n <A, B>(self: Iterable<A>, i: number, f: (a: A) => B): Array<A | B> =>\n O.getOrElse(modifyOption(self, i, f), () => Array.from(self))\n)\n\n/**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.modifyOption(numbers, 2, (n) => n * 2)\n * assert.deepStrictEqual(result, Option.some([1, 2, 6, 4]))\n *\n * const outOfBoundsResult = Array.modifyOption(numbers, 5, (n) => n * 2)\n * assert.deepStrictEqual(outOfBoundsResult, Option.none())\n * ```\n *\n * @since 2.0.0\n */\nexport const modifyOption: {\n /**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.modifyOption(numbers, 2, (n) => n * 2)\n * assert.deepStrictEqual(result, Option.some([1, 2, 6, 4]))\n *\n * const outOfBoundsResult = Array.modifyOption(numbers, 5, (n) => n * 2)\n * assert.deepStrictEqual(outOfBoundsResult, Option.none())\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(\n i: number,\n f: (a: ReadonlyArray.Infer<S>) => B\n ): (self: S) => Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>\n /**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.modifyOption(numbers, 2, (n) => n * 2)\n * assert.deepStrictEqual(result, Option.some([1, 2, 6, 4]))\n *\n * const outOfBoundsResult = Array.modifyOption(numbers, 5, (n) => n * 2)\n * assert.deepStrictEqual(outOfBoundsResult, Option.none())\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(\n self: S,\n i: number,\n f: (a: ReadonlyArray.Infer<S>) => B\n ): Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>\n} = dual(3, <A, B>(self: Iterable<A>, i: number, f: (a: A) => B): Option<Array<A | B>> => {\n const out = Array.from(self)\n if (isOutOfBound(i, out)) {\n return O.none()\n }\n const next = f(out[i])\n // @ts-expect-error\n out[i] = next\n return O.some(out)\n})\n\n/**\n * Delete the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.remove(numbers, 2)\n * assert.deepStrictEqual(result, [1, 2, 4])\n *\n * const outOfBoundsResult = Array.remove(numbers, 5)\n * assert.deepStrictEqual(outOfBoundsResult, [1, 2, 3, 4])\n * ```\n *\n * @since 2.0.0\n */\nexport const remove: {\n /**\n * Delete the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.remove(numbers, 2)\n * assert.deepStrictEqual(result, [1, 2, 4])\n *\n * const outOfBoundsResult = Array.remove(numbers, 5)\n * assert.deepStrictEqual(outOfBoundsResult, [1, 2, 3, 4])\n * ```\n *\n * @since 2.0.0\n */\n (i: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Delete the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.remove(numbers, 2)\n * assert.deepStrictEqual(result, [1, 2, 4])\n *\n * const outOfBoundsResult = Array.remove(numbers, 5)\n * assert.deepStrictEqual(outOfBoundsResult, [1, 2, 3, 4])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, i: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, i: number): Array<A> => {\n const out = Array.from(self)\n if (isOutOfBound(i, out)) {\n return out\n }\n out.splice(i, 1)\n return out\n})\n\n/**\n * Reverse an `Iterable`, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.reverse(numbers)\n * assert.deepStrictEqual(result, [4, 3, 2, 1])\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const reverse = <S extends Iterable<any> | NonEmptyReadonlyArray<any>>(\n self: S\n): S extends NonEmptyReadonlyArray<infer A> ? NonEmptyArray<A> : S extends Iterable<infer A> ? Array<A> : never =>\n Array.from(self).reverse() as any\n\n/**\n * Create a new array with elements sorted in increasing order based on the specified comparator.\n * If the input is a `NonEmptyReadonlyArray`, the output will also be a `NonEmptyReadonlyArray`.\n *\n * @category sorting\n * @since 2.0.0\n */\nexport const sort: {\n /**\n * Create a new array with elements sorted in increasing order based on the specified comparator.\n * If the input is a `NonEmptyReadonlyArray`, the output will also be a `NonEmptyReadonlyArray`.\n *\n * @category sorting\n * @since 2.0.0\n */\n <B>(\n O: Order.Order<B>\n ): <A extends B, S extends ReadonlyArray<A> | Iterable<A>>(self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * Create a new array with elements sorted in increasing order based on the specified comparator.\n * If the input is a `NonEmptyReadonlyArray`, the output will also be a `NonEmptyReadonlyArray`.\n *\n * @category sorting\n * @since 2.0.0\n */\n <A extends B, B>(self: NonEmptyReadonlyArray<A>, O: Order.Order<B>): NonEmptyArray<A>\n /**\n * Create a new array with elements sorted in increasing order based on the specified comparator.\n * If the input is a `NonEmptyReadonlyArray`, the output will also be a `NonEmptyReadonlyArray`.\n *\n * @category sorting\n * @since 2.0.0\n */\n <A extends B, B>(self: Iterable<A>, O: Order.Order<B>): Array<A>\n} = dual(2, <A extends B, B>(self: Iterable<A>, O: Order.Order<B>): Array<A> => {\n const out = Array.from(self)\n out.sort(O)\n return out\n})\n\n/**\n * Sorts an array based on a provided mapping function and order. The mapping\n * function transforms the elements into a value that can be compared, and the\n * order defines how those values should be sorted.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const strings = [\"aaa\", \"b\", \"cc\"]\n * const result = Array.sortWith(strings, (s) => s.length, Order.number)\n * assert.deepStrictEqual(result, [\"b\", \"cc\", \"aaa\"])\n *\n * // Explanation:\n * // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`\n * // converts each string into its length, and the `Order.number` specifies that the lengths should\n * // be sorted in ascending order.\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\nexport const sortWith: {\n /**\n * Sorts an array based on a provided mapping function and order. The mapping\n * function transforms the elements into a value that can be compared, and the\n * order defines how those values should be sorted.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const strings = [\"aaa\", \"b\", \"cc\"]\n * const result = Array.sortWith(strings, (s) => s.length, Order.number)\n * assert.deepStrictEqual(result, [\"b\", \"cc\", \"aaa\"])\n *\n * // Explanation:\n * // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`\n * // converts each string into its length, and the `Order.number` specifies that the lengths should\n * // be sorted in ascending order.\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <S extends Iterable<any> | NonEmptyReadonlyArray<any>, B>(\n f: (a: ReadonlyArray.Infer<S>) => B,\n order: Order.Order<B>\n ): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * Sorts an array based on a provided mapping function and order. The mapping\n * function transforms the elements into a value that can be compared, and the\n * order defines how those values should be sorted.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const strings = [\"aaa\", \"b\", \"cc\"]\n * const result = Array.sortWith(strings, (s) => s.length, Order.number)\n * assert.deepStrictEqual(result, [\"b\", \"cc\", \"aaa\"])\n *\n * // Explanation:\n * // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`\n * // converts each string into its length, and the `Order.number` specifies that the lengths should\n * // be sorted in ascending order.\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B, O: Order.Order<B>): NonEmptyArray<A>\n /**\n * Sorts an array based on a provided mapping function and order. The mapping\n * function transforms the elements into a value that can be compared, and the\n * order defines how those values should be sorted.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const strings = [\"aaa\", \"b\", \"cc\"]\n * const result = Array.sortWith(strings, (s) => s.length, Order.number)\n * assert.deepStrictEqual(result, [\"b\", \"cc\", \"aaa\"])\n *\n * // Explanation:\n * // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`\n * // converts each string into its length, and the `Order.number` specifies that the lengths should\n * // be sorted in ascending order.\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B>(self: Iterable<A>, f: (a: A) => B, order: Order.Order<B>): Array<A>\n} = dual(\n 3,\n <A, B>(self: Iterable<A>, f: (a: A) => B, order: Order.Order<B>): Array<A> =>\n Array.from(self).map((a) => [a, f(a)] as const).sort((a, b) => order(a[1], b[1])).map((x) => x[0])\n)\n\n/**\n * Sorts the elements of an `Iterable` in increasing order based on the provided\n * orders. The elements are compared using the first order in `orders`, then the\n * second order if the first comparison is equal, and so on.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const users = [\n * { name: \"Alice\", age: 30 },\n * { name: \"Bob\", age: 25 },\n * { name: \"Charlie\", age: 30 }\n * ]\n *\n * const result = Array.sortBy(\n * Order.mapInput(Order.number, (user: (typeof users)[number]) => user.age),\n * Order.mapInput(Order.string, (user: (typeof users)[number]) => user.name)\n * )(users)\n *\n * assert.deepStrictEqual(result, [\n * { name: \"Bob\", age: 25 },\n * { name: \"Alice\", age: 30 },\n * { name: \"Charlie\", age: 30 }\n * ])\n *\n * // Explanation:\n * // The array of users is sorted first by age in ascending order. When ages are equal,\n * // the users are further sorted by name in ascending order.\n * ```\n *\n * @category sorting\n * @since 2.0.0\n */\nexport const sortBy = <S extends Iterable<any> | NonEmptyReadonlyArray<any>>(\n ...orders: ReadonlyArray<Order.Order<ReadonlyArray.Infer<S>>>\n) => {\n const sortByAll = sort(Order.combineAll(orders))\n return (\n self: S\n ): S extends NonEmptyReadonlyArray<infer A> ? NonEmptyArray<A> : S extends Iterable<infer A> ? Array<A> : never => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n return sortByAll(input) as any\n }\n return [] as any\n }\n}\n\n/**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = ['a', 'b']\n * const result = Array.zip(array1, array2)\n * assert.deepStrictEqual(result, [[1, 'a'], [2, 'b']])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\nexport const zip: {\n /**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = ['a', 'b']\n * const result = Array.zip(array1, array2)\n * assert.deepStrictEqual(result, [[1, 'a'], [2, 'b']])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B>(that: NonEmptyReadonlyArray<B>): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<[A, B]>\n /**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = ['a', 'b']\n * const result = Array.zip(array1, array2)\n * assert.deepStrictEqual(result, [[1, 'a'], [2, 'b']])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B>(that: Iterable<B>): <A>(self: Iterable<A>) => Array<[A, B]>\n /**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = ['a', 'b']\n * const result = Array.zip(array1, array2)\n * assert.deepStrictEqual(result, [[1, 'a'], [2, 'b']])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<[A, B]>\n /**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = ['a', 'b']\n * const result = Array.zip(array1, array2)\n * assert.deepStrictEqual(result, [[1, 'a'], [2, 'b']])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<[A, B]>\n} = dual(\n 2,\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<[A, B]> => zipWith(self, that, Tuple.make)\n)\n\n/**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [4, 5, 6]\n * const result = Array.zipWith(array1, array2, (a, b) => a + b)\n * assert.deepStrictEqual(result, [5, 7, 9])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\nexport const zipWith: {\n /**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [4, 5, 6]\n * const result = Array.zipWith(array1, array2, (a, b) => a + b)\n * assert.deepStrictEqual(result, [5, 7, 9])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B, A, C>(that: NonEmptyReadonlyArray<B>, f: (a: A, b: B) => C): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<C>\n /**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [4, 5, 6]\n * const result = Array.zipWith(array1, array2, (a, b) => a + b)\n * assert.deepStrictEqual(result, [5, 7, 9])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Array<C>\n /**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [4, 5, 6]\n * const result = Array.zipWith(array1, array2, (a, b) => a + b)\n * assert.deepStrictEqual(result, [5, 7, 9])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, B, C>(\n self: NonEmptyReadonlyArray<A>,\n that: NonEmptyReadonlyArray<B>,\n f: (a: A, b: B) => C\n ): NonEmptyArray<C>\n /**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [4, 5, 6]\n * const result = Array.zipWith(array1, array2, (a, b) => a + b)\n * assert.deepStrictEqual(result, [5, 7, 9])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C>\n} = dual(3, <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C> => {\n const as = fromIterable(self)\n const bs = fromIterable(that)\n if (isNonEmptyReadonlyArray(as) && isNonEmptyReadonlyArray(bs)) {\n const out: NonEmptyArray<C> = [f(headNonEmpty(as), headNonEmpty(bs))]\n const len = Math.min(as.length, bs.length)\n for (let i = 1; i < len; i++) {\n out[i] = f(as[i], bs[i])\n }\n return out\n }\n return []\n})\n\n/**\n * This function is the inverse of `zip`. Takes an `Iterable` of pairs and return two corresponding `Array`s.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.unzip([[1, \"a\"], [2, \"b\"], [3, \"c\"]])\n * assert.deepStrictEqual(result, [[1, 2, 3], ['a', 'b', 'c']])\n * ```\n *\n * @since 2.0.0\n */\nexport const unzip: <S extends Iterable<readonly [any, any]> | NonEmptyReadonlyArray<readonly [any, any]>>(\n self: S\n) => S extends NonEmptyReadonlyArray<readonly [infer A, infer B]> ? [NonEmptyArray<A>, NonEmptyArray<B>]\n : S extends Iterable<readonly [infer A, infer B]> ? [Array<A>, Array<B>]\n : never = (<A, B>(self: Iterable<readonly [A, B]>): [Array<A>, Array<B>] => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const fa: NonEmptyArray<A> = [input[0][0]]\n const fb: NonEmptyArray<B> = [input[0][1]]\n for (let i = 1; i < input.length; i++) {\n fa[i] = input[i][0]\n fb[i] = input[i][1]\n }\n return [fa, fb]\n }\n return [[], []]\n }) as any\n\n/**\n * Places an element in between members of an `Iterable`.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.intersperse(numbers, 0)\n * assert.deepStrictEqual(result, [1, 0, 2, 0, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const intersperse: {\n /**\n * Places an element in between members of an `Iterable`.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.intersperse(numbers, 0)\n * assert.deepStrictEqual(result, [1, 0, 2, 0, 3])\n * ```\n *\n * @since 2.0.0\n */\n <B>(middle: B): <S extends Iterable<any>>(self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n /**\n * Places an element in between members of an `Iterable`.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.intersperse(numbers, 0)\n * assert.deepStrictEqual(result, [1, 0, 2, 0, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, middle: B): NonEmptyArray<A | B>\n /**\n * Places an element in between members of an `Iterable`.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.intersperse(numbers, 0)\n * assert.deepStrictEqual(result, [1, 0, 2, 0, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, middle: B): Array<A | B>\n} = dual(2, <A, B>(self: Iterable<A>, middle: B): Array<A | B> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const out: NonEmptyArray<A | B> = [headNonEmpty(input)]\n const tail = tailNonEmpty(input)\n for (let i = 0; i < tail.length; i++) {\n if (i < tail.length) {\n out.push(middle)\n }\n out.push(tail[i])\n }\n return out\n }\n return []\n})\n\n/**\n * Apply a function to the head, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyHead([1, 2, 3], n => n * 10)\n * assert.deepStrictEqual(result, [10, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const modifyNonEmptyHead: {\n /**\n * Apply a function to the head, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyHead([1, 2, 3], n => n * 10)\n * assert.deepStrictEqual(result, [10, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>\n /**\n * Apply a function to the head, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyHead([1, 2, 3], n => n * 10)\n * assert.deepStrictEqual(result, [10, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B): NonEmptyArray<A | B>\n} = dual(\n 2,\n <A, B>(\n self: NonEmptyReadonlyArray<A>,\n f: (a: A) => B\n ): NonEmptyArray<A | B> => [f(headNonEmpty(self)), ...tailNonEmpty(self)]\n)\n\n/**\n * Change the head, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyHead([1, 2, 3], 10)\n * assert.deepStrictEqual(result, [10, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const setNonEmptyHead: {\n /**\n * Change the head, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyHead([1, 2, 3], 10)\n * assert.deepStrictEqual(result, [10, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <B>(b: B): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>\n /**\n * Change the head, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyHead([1, 2, 3], 10)\n * assert.deepStrictEqual(result, [10, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B>\n} = dual(\n 2,\n <A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B> => modifyNonEmptyHead(self, () => b)\n)\n\n/**\n * Apply a function to the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyLast([1, 2, 3], n => n * 2)\n * assert.deepStrictEqual(result, [1, 2, 6])\n * ```\n *\n * @since 2.0.0\n */\nexport const modifyNonEmptyLast: {\n /**\n * Apply a function to the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyLast([1, 2, 3], n => n * 2)\n * assert.deepStrictEqual(result, [1, 2, 6])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>\n /**\n * Apply a function to the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyLast([1, 2, 3], n => n * 2)\n * assert.deepStrictEqual(result, [1, 2, 6])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B): NonEmptyArray<A | B>\n} = dual(\n 2,\n <A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B): NonEmptyArray<A | B> =>\n append(initNonEmpty(self), f(lastNonEmpty(self)))\n)\n\n/**\n * Change the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyLast([1, 2, 3], 4)\n * assert.deepStrictEqual(result, [1, 2, 4])\n * ```\n *\n * @since 2.0.0\n */\nexport const setNonEmptyLast: {\n /**\n * Change the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyLast([1, 2, 3], 4)\n * assert.deepStrictEqual(result, [1, 2, 4])\n * ```\n *\n * @since 2.0.0\n */\n <B>(b: B): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>\n /**\n * Change the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyLast([1, 2, 3], 4)\n * assert.deepStrictEqual(result, [1, 2, 4])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B>\n} = dual(\n 2,\n <A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B> => modifyNonEmptyLast(self, () => b)\n)\n\n/**\n * Rotate an `Iterable` by `n` steps.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.rotate(letters, 2)\n * assert.deepStrictEqual(result, ['c', 'd', 'a', 'b'])\n * ```\n *\n * @since 2.0.0\n */\nexport const rotate: {\n /**\n * Rotate an `Iterable` by `n` steps.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.rotate(letters, 2)\n * assert.deepStrictEqual(result, ['c', 'd', 'a', 'b'])\n * ```\n *\n * @since 2.0.0\n */\n (n: number): <S extends Iterable<any>>(self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * Rotate an `Iterable` by `n` steps.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.rotate(letters, 2)\n * assert.deepStrictEqual(result, ['c', 'd', 'a', 'b'])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, n: number): NonEmptyArray<A>\n /**\n * Rotate an `Iterable` by `n` steps.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.rotate(letters, 2)\n * assert.deepStrictEqual(result, ['c', 'd', 'a', 'b'])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const len = input.length\n const m = Math.round(n) % len\n if (isOutOfBound(Math.abs(m), input) || m === 0) {\n return copy(input)\n }\n if (m < 0) {\n const [f, s] = splitNonEmptyAt(input, -m)\n return appendAll(s, f)\n } else {\n return rotate(self, m - len)\n }\n }\n return []\n})\n\n/**\n * Returns a function that checks if a `ReadonlyArray` contains a given value using a provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const isEquivalent = (a: number, b: number) => a === b\n * const containsNumber = Array.containsWith(isEquivalent)\n * const result = containsNumber(3)(numbers)\n * assert.deepStrictEqual(result, true)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const containsWith = <A>(isEquivalent: (self: A, that: A) => boolean): {\n (a: A): (self: Iterable<A>) => boolean\n (self: Iterable<A>, a: A): boolean\n} =>\n dual(2, (self: Iterable<A>, a: A): boolean => {\n for (const i of self) {\n if (isEquivalent(a, i)) {\n return true\n }\n }\n return false\n })\n\nconst _equivalence = Equal.equivalence()\n\n/**\n * Returns a function that checks if a `ReadonlyArray` contains a given value using the default `Equivalence`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.contains('c')(letters)\n * assert.deepStrictEqual(result, true)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const contains: {\n /**\n * Returns a function that checks if a `ReadonlyArray` contains a given value using the default `Equivalence`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.contains('c')(letters)\n * assert.deepStrictEqual(result, true)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(a: A): (self: Iterable<A>) => boolean\n /**\n * Returns a function that checks if a `ReadonlyArray` contains a given value using the default `Equivalence`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.contains('c')(letters)\n * assert.deepStrictEqual(result, true)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, a: A): boolean\n} = containsWith(_equivalence)\n\n/**\n * A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for \"chopping\" up the input\n * `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a\n * value and the rest of the `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chop(numbers, (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * assert.deepStrictEqual(result, [2, 4, 6, 8, 10])\n *\n * // Explanation:\n * // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.\n * // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,\n * // resulting in a new array `[2, 4, 6, 8, 10]`.\n * ```\n *\n * @since 2.0.0\n */\nexport const chop: {\n /**\n * A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for \"chopping\" up the input\n * `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a\n * value and the rest of the `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chop(numbers, (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * assert.deepStrictEqual(result, [2, 4, 6, 8, 10])\n *\n * // Explanation:\n * // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.\n * // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,\n * // resulting in a new array `[2, 4, 6, 8, 10]`.\n * ```\n *\n * @since 2.0.0\n */\n <S extends Iterable<any>, B>(\n f: (as: NonEmptyReadonlyArray<ReadonlyArray.Infer<S>>) => readonly [B, ReadonlyArray<ReadonlyArray.Infer<S>>]\n ): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for \"chopping\" up the input\n * `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a\n * value and the rest of the `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chop(numbers, (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * assert.deepStrictEqual(result, [2, 4, 6, 8, 10])\n *\n * // Explanation:\n * // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.\n * // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,\n * // resulting in a new array `[2, 4, 6, 8, 10]`.\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: NonEmptyReadonlyArray<A>,\n f: (as: NonEmptyReadonlyArray<A>) => readonly [B, ReadonlyArray<A>]\n ): NonEmptyArray<B>\n /**\n * A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for \"chopping\" up the input\n * `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a\n * value and the rest of the `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chop(numbers, (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * assert.deepStrictEqual(result, [2, 4, 6, 8, 10])\n *\n * // Explanation:\n * // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.\n * // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,\n * // resulting in a new array `[2, 4, 6, 8, 10]`.\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: Iterable<A>,\n f: (as: NonEmptyReadonlyArray<A>) => readonly [B, ReadonlyArray<A>]\n ): Array<B>\n} = dual(2, <A, B>(\n self: Iterable<A>,\n f: (as: NonEmptyReadonlyArray<A>) => readonly [B, ReadonlyArray<A>]\n): Array<B> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const [b, rest] = f(input)\n const out: NonEmptyArray<B> = [b]\n let next: ReadonlyArray<A> = rest\n while (readonlyArray.isNonEmptyArray(next)) {\n const [b, rest] = f(next)\n out.push(b)\n next = rest\n }\n return out\n }\n return []\n})\n\n/**\n * Splits an `Iterable` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` can be `0`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.splitAt(numbers, 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const splitAt: {\n /**\n * Splits an `Iterable` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` can be `0`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.splitAt(numbers, 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => [beforeIndex: Array<A>, fromIndex: Array<A>]\n /**\n * Splits an `Iterable` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` can be `0`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.splitAt(numbers, 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): [beforeIndex: Array<A>, fromIndex: Array<A>]\n} = dual(2, <A>(self: Iterable<A>, n: number): [Array<A>, Array<A>] => {\n const input = Array.from(self)\n const _n = Math.floor(n)\n if (isNonEmptyReadonlyArray(input)) {\n if (_n >= 1) {\n return splitNonEmptyAt(input, _n)\n }\n return [[], input]\n }\n return [input, []]\n})\n\n/**\n * Splits a `NonEmptyReadonlyArray` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` must be `>= 1`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitNonEmptyAt([\"a\", \"b\", \"c\", \"d\", \"e\"], 3)\n * assert.deepStrictEqual(result, [[\"a\", \"b\", \"c\"], [\"d\", \"e\"]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const splitNonEmptyAt: {\n /**\n * Splits a `NonEmptyReadonlyArray` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` must be `>= 1`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitNonEmptyAt([\"a\", \"b\", \"c\", \"d\", \"e\"], 3)\n * assert.deepStrictEqual(result, [[\"a\", \"b\", \"c\"], [\"d\", \"e\"]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n (n: number): <A>(self: NonEmptyReadonlyArray<A>) => [beforeIndex: NonEmptyArray<A>, fromIndex: Array<A>]\n /**\n * Splits a `NonEmptyReadonlyArray` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` must be `>= 1`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitNonEmptyAt([\"a\", \"b\", \"c\", \"d\", \"e\"], 3)\n * assert.deepStrictEqual(result, [[\"a\", \"b\", \"c\"], [\"d\", \"e\"]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, n: number): [beforeIndex: NonEmptyArray<A>, fromIndex: Array<A>]\n} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, n: number): [NonEmptyArray<A>, Array<A>] => {\n const _n = Math.max(1, Math.floor(n))\n return _n >= self.length ?\n [copy(self), []] :\n [prepend(self.slice(1, _n), headNonEmpty(self)), self.slice(_n)]\n})\n\n/**\n * Splits this iterable into `n` equally sized arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5, 6, 7, 8]\n * const result = Array.split(numbers, 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5, 6], [7, 8]])\n * ```\n *\n * @since 2.0.0\n * @category splitting\n */\nexport const split: {\n /**\n * Splits this iterable into `n` equally sized arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5, 6, 7, 8]\n * const result = Array.split(numbers, 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5, 6], [7, 8]])\n * ```\n *\n * @since 2.0.0\n * @category splitting\n */\n (n: number): <A>(self: Iterable<A>) => Array<Array<A>>\n /**\n * Splits this iterable into `n` equally sized arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5, 6, 7, 8]\n * const result = Array.split(numbers, 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5, 6], [7, 8]])\n * ```\n *\n * @since 2.0.0\n * @category splitting\n */\n <A>(self: Iterable<A>, n: number): Array<Array<A>>\n} = dual(2, <A>(self: Iterable<A>, n: number) => {\n const input = fromIterable(self)\n return chunksOf(input, Math.ceil(input.length / Math.floor(n)))\n})\n\n/**\n * Splits this iterable on the first element that matches this predicate.\n * Returns a tuple containing two arrays: the first one is before the match, and the second one is from the match onward.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.splitWhere(numbers, n => n > 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const splitWhere: {\n /**\n * Splits this iterable on the first element that matches this predicate.\n * Returns a tuple containing two arrays: the first one is before the match, and the second one is from the match onward.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.splitWhere(numbers, n => n > 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(\n predicate: (a: NoInfer<A>, i: number) => boolean\n ): (self: Iterable<A>) => [beforeMatch: Array<A>, fromMatch: Array<A>]\n /**\n * Splits this iterable on the first element that matches this predicate.\n * Returns a tuple containing two arrays: the first one is before the match, and the second one is from the match onward.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.splitWhere(numbers, n => n > 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [beforeMatch: Array<A>, fromMatch: Array<A>]\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [beforeMatch: Array<A>, fromMatch: Array<A>] =>\n span(self, (a: A, i: number) => !predicate(a, i))\n)\n\n/**\n * Copies an array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const copy = Array.copy(numbers)\n * assert.deepStrictEqual(copy, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const copy: {\n /**\n * Copies an array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const copy = Array.copy(numbers)\n * assert.deepStrictEqual(copy, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>): NonEmptyArray<A>\n /**\n * Copies an array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const copy = Array.copy(numbers)\n * assert.deepStrictEqual(copy, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: ReadonlyArray<A>): Array<A>\n} = (<A>(self: ReadonlyArray<A>): Array<A> => self.slice()) as any\n\n/**\n * Pads an array.\n * Returns a new array of length `n` with the elements of `array` followed by `fill` elements if `array` is shorter than `n`.\n * If `array` is longer than `n`, the returned array will be a slice of `array` containing the `n` first elements of `array`.\n * If `n` is less than or equal to 0, the returned array will be an empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const arr = [1, 2, 3]\n * const result = Array.pad(arr, 6, 0)\n * assert.deepStrictEqual(result, [1, 2, 3, 0, 0, 0])\n * ```\n *\n * @since 3.8.4\n */\nexport const pad: {\n /**\n * Pads an array.\n * Returns a new array of length `n` with the elements of `array` followed by `fill` elements if `array` is shorter than `n`.\n * If `array` is longer than `n`, the returned array will be a slice of `array` containing the `n` first elements of `array`.\n * If `n` is less than or equal to 0, the returned array will be an empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const arr = [1, 2, 3]\n * const result = Array.pad(arr, 6, 0)\n * assert.deepStrictEqual(result, [1, 2, 3, 0, 0, 0])\n * ```\n *\n * @since 3.8.4\n */\n <A, T>(n: number, fill: T): (\n self: Array<A>\n ) => Array<A | T>\n /**\n * Pads an array.\n * Returns a new array of length `n` with the elements of `array` followed by `fill` elements if `array` is shorter than `n`.\n * If `array` is longer than `n`, the returned array will be a slice of `array` containing the `n` first elements of `array`.\n * If `n` is less than or equal to 0, the returned array will be an empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const arr = [1, 2, 3]\n * const result = Array.pad(arr, 6, 0)\n * assert.deepStrictEqual(result, [1, 2, 3, 0, 0, 0])\n * ```\n *\n * @since 3.8.4\n */\n <A, T>(self: Array<A>, n: number, fill: T): Array<A | T>\n} = dual(3, <A, T>(self: Array<A>, n: number, fill: T): Array<A | T> => {\n if (self.length >= n) {\n return take(self, n)\n }\n return appendAll(\n self,\n makeBy(n - self.length, () => fill)\n )\n})\n\n/**\n * Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of\n * the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive\n * definition of `chunksOf`; it satisfies the property that\n *\n * ```ts\n * chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))\n * ```\n *\n * whenever `n` evenly divides the length of `self`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chunksOf(numbers, 2)\n * assert.deepStrictEqual(result, [[1, 2], [3, 4], [5]])\n *\n * // Explanation:\n * // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.\n * // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,\n * // the last chunk contains the remaining elements.\n * // The result is `[[1, 2], [3, 4], [5]]`.\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const chunksOf: {\n /**\n * Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of\n * the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive\n * definition of `chunksOf`; it satisfies the property that\n *\n * ```ts\n * chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))\n * ```\n *\n * whenever `n` evenly divides the length of `self`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chunksOf(numbers, 2)\n * assert.deepStrictEqual(result, [[1, 2], [3, 4], [5]])\n *\n * // Explanation:\n * // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.\n * // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,\n * // the last chunk contains the remaining elements.\n * // The result is `[[1, 2], [3, 4], [5]]`.\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n (n: number): <S extends Iterable<any>>(\n self: S\n ) => ReadonlyArray.With<S, NonEmptyArray<ReadonlyArray.Infer<S>>>\n /**\n * Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of\n * the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive\n * definition of `chunksOf`; it satisfies the property that\n *\n * ```ts\n * chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))\n * ```\n *\n * whenever `n` evenly divides the length of `self`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chunksOf(numbers, 2)\n * assert.deepStrictEqual(result, [[1, 2], [3, 4], [5]])\n *\n * // Explanation:\n * // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.\n * // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,\n * // the last chunk contains the remaining elements.\n * // The result is `[[1, 2], [3, 4], [5]]`.\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, n: number): NonEmptyArray<NonEmptyArray<A>>\n /**\n * Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of\n * the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive\n * definition of `chunksOf`; it satisfies the property that\n *\n * ```ts\n * chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))\n * ```\n *\n * whenever `n` evenly divides the length of `self`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chunksOf(numbers, 2)\n * assert.deepStrictEqual(result, [[1, 2], [3, 4], [5]])\n *\n * // Explanation:\n * // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.\n * // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,\n * // the last chunk contains the remaining elements.\n * // The result is `[[1, 2], [3, 4], [5]]`.\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<NonEmptyArray<A>>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<NonEmptyArray<A>> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n return chop(input, splitNonEmptyAt(n))\n }\n return []\n})\n\n/**\n * Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s using the provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.groupWith([\"a\", \"a\", \"b\", \"b\", \"b\", \"c\", \"a\"], (x, y) => x === y)\n * assert.deepStrictEqual(result, [[\"a\", \"a\"], [\"b\", \"b\", \"b\"], [\"c\"], [\"a\"]])\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\nexport const groupWith: {\n /**\n * Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s using the provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.groupWith([\"a\", \"a\", \"b\", \"b\", \"b\", \"c\", \"a\"], (x, y) => x === y)\n * assert.deepStrictEqual(result, [[\"a\", \"a\"], [\"b\", \"b\", \"b\"], [\"c\"], [\"a\"]])\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\n <A>(isEquivalent: (self: A, that: A) => boolean): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<NonEmptyArray<A>>\n /**\n * Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s using the provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.groupWith([\"a\", \"a\", \"b\", \"b\", \"b\", \"c\", \"a\"], (x, y) => x === y)\n * assert.deepStrictEqual(result, [[\"a\", \"a\"], [\"b\", \"b\", \"b\"], [\"c\"], [\"a\"]])\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\n <A>(\n self: NonEmptyReadonlyArray<A>,\n isEquivalent: (self: A, that: A) => boolean\n ): NonEmptyArray<NonEmptyArray<A>>\n} = dual(\n 2,\n <A>(self: NonEmptyReadonlyArray<A>, isEquivalent: (self: A, that: A) => boolean): NonEmptyArray<NonEmptyArray<A>> =>\n chop(self, (as) => {\n const h = headNonEmpty(as)\n const out: NonEmptyArray<A> = [h]\n let i = 1\n for (; i < as.length; i++) {\n const a = as[i]\n if (isEquivalent(a, h)) {\n out.push(a)\n } else {\n break\n }\n }\n return [out, as.slice(i)]\n })\n)\n\n/**\n * Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.group([1, 1, 2, 2, 2, 3, 1])\n * assert.deepStrictEqual(result, [[1, 1], [2, 2, 2], [3], [1]])\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\nexport const group: <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<NonEmptyArray<A>> = groupWith(\n Equal.equivalence()\n)\n\n/**\n * Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning\n * function on each element, and grouping the results according to values returned\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const people = [\n * { name: \"Alice\", group: \"A\" },\n * { name: \"Bob\", group: \"B\" },\n * { name: \"Charlie\", group: \"A\" }\n * ]\n * const result = Array.groupBy(people, person => person.group)\n * assert.deepStrictEqual(result, {\n * A: [{ name: \"Alice\", group: \"A\" }, { name: \"Charlie\", group: \"A\" }],\n * B: [{ name: \"Bob\", group: \"B\" }]\n * })\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\nexport const groupBy: {\n /**\n * Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning\n * function on each element, and grouping the results according to values returned\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const people = [\n * { name: \"Alice\", group: \"A\" },\n * { name: \"Bob\", group: \"B\" },\n * { name: \"Charlie\", group: \"A\" }\n * ]\n * const result = Array.groupBy(people, person => person.group)\n * assert.deepStrictEqual(result, {\n * A: [{ name: \"Alice\", group: \"A\" }, { name: \"Charlie\", group: \"A\" }],\n * B: [{ name: \"Bob\", group: \"B\" }]\n * })\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\n <A, K extends string | symbol>(\n f: (a: A) => K\n ): (self: Iterable<A>) => Record<Record.ReadonlyRecord.NonLiteralKey<K>, NonEmptyArray<A>>\n /**\n * Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning\n * function on each element, and grouping the results according to values returned\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const people = [\n * { name: \"Alice\", group: \"A\" },\n * { name: \"Bob\", group: \"B\" },\n * { name: \"Charlie\", group: \"A\" }\n * ]\n * const result = Array.groupBy(people, person => person.group)\n * assert.deepStrictEqual(result, {\n * A: [{ name: \"Alice\", group: \"A\" }, { name: \"Charlie\", group: \"A\" }],\n * B: [{ name: \"Bob\", group: \"B\" }]\n * })\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\n <A, K extends string | symbol>(\n self: Iterable<A>,\n f: (a: A) => K\n ): Record<Record.ReadonlyRecord.NonLiteralKey<K>, NonEmptyArray<A>>\n} = dual(2, <A, K extends string | symbol>(\n self: Iterable<A>,\n f: (a: A) => K\n): Record<Record.ReadonlyRecord.NonLiteralKey<K>, NonEmptyArray<A>> => {\n const out: Record<string | symbol, NonEmptyArray<A>> = {}\n for (const a of self) {\n const k = f(a)\n if (Object.prototype.hasOwnProperty.call(out, k)) {\n out[k].push(a)\n } else {\n out[k] = [a]\n }\n }\n return out\n})\n\n/**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const union = Array.unionWith(array1, array2, (a, b) => a === b)\n * assert.deepStrictEqual(union, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const unionWith: {\n /**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const union = Array.unionWith(array1, array2, (a, b) => a === b)\n * assert.deepStrictEqual(union, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <S extends Iterable<any>, T extends Iterable<any>>(\n that: T,\n isEquivalent: (self: ReadonlyArray.Infer<S>, that: ReadonlyArray.Infer<T>) => boolean\n ): (self: S) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>\n /**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const union = Array.unionWith(array1, array2, (a, b) => a === b)\n * assert.deepStrictEqual(union, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: NonEmptyReadonlyArray<A>,\n that: Iterable<B>,\n isEquivalent: (self: A, that: B) => boolean\n ): NonEmptyArray<A | B>\n /**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const union = Array.unionWith(array1, array2, (a, b) => a === b)\n * assert.deepStrictEqual(union, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: Iterable<A>,\n that: NonEmptyReadonlyArray<B>,\n isEquivalent: (self: A, that: B) => boolean\n ): NonEmptyArray<A | B>\n /**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const union = Array.unionWith(array1, array2, (a, b) => a === b)\n * assert.deepStrictEqual(union, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: Iterable<A>,\n that: Iterable<B>,\n isEquivalent: (self: A, that: B) => boolean\n ): Array<A | B>\n} = dual(3, <A>(self: Iterable<A>, that: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A> => {\n const a = fromIterable(self)\n const b = fromIterable(that)\n if (isNonEmptyReadonlyArray(a)) {\n if (isNonEmptyReadonlyArray(b)) {\n const dedupe = dedupeWith(isEquivalent)\n return dedupe(appendAll(a, b))\n }\n return a\n }\n return b\n})\n\n/**\n * Creates a union of two arrays, removing duplicates.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const result = Array.union(array1, array2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const union: {\n /**\n * Creates a union of two arrays, removing duplicates.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const result = Array.union(array1, array2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <T extends Iterable<any>>(that: T): <S extends Iterable<any>>(\n self: S\n ) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>\n /**\n * Creates a union of two arrays, removing duplicates.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const result = Array.union(array1, array2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, that: ReadonlyArray<B>): NonEmptyArray<A | B>\n /**\n * Creates a union of two arrays, removing duplicates.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const result = Array.union(array1, array2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: ReadonlyArray<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<A | B>\n /**\n * Creates a union of two arrays, removing duplicates.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const result = Array.union(array1, array2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B>\n} = dual(2, <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B> => unionWith(self, that, _equivalence))\n\n/**\n * Creates an `Array` of unique values that are included in all given `Iterable`s using the provided `isEquivalent` function.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }]\n * const array2 = [{ id: 3 }, { id: 4 }, { id: 1 }]\n * const isEquivalent = (a: { id: number }, b: { id: number }) => a.id === b.id\n * const result = Array.intersectionWith(isEquivalent)(array2)(array1)\n * assert.deepStrictEqual(result, [{ id: 1 }, { id: 3 }])\n * ```\n *\n * @since 2.0.0\n */\nexport const intersectionWith = <A>(isEquivalent: (self: A, that: A) => boolean): {\n (that: Iterable<A>): (self: Iterable<A>) => Array<A>\n (self: Iterable<A>, that: Iterable<A>): Array<A>\n} => {\n const has = containsWith(isEquivalent)\n return dual(\n 2,\n (self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(self).filter((a) => has(that, a))\n )\n}\n\n/**\n * Creates an `Array` of unique values that are included in all given `Iterable`s.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [3, 4, 1]\n * const result = Array.intersection(array1, array2)\n * assert.deepStrictEqual(result, [1, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const intersection: {\n /**\n * Creates an `Array` of unique values that are included in all given `Iterable`s.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [3, 4, 1]\n * const result = Array.intersection(array1, array2)\n * assert.deepStrictEqual(result, [1, 3])\n * ```\n *\n * @since 2.0.0\n */\n <B>(that: Iterable<B>): <A>(self: Iterable<A>) => Array<A & B>\n /**\n * Creates an `Array` of unique values that are included in all given `Iterable`s.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [3, 4, 1]\n * const result = Array.intersection(array1, array2)\n * assert.deepStrictEqual(result, [1, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A & B>\n} = intersectionWith(_equivalence)\n\n/**\n * Creates a `Array` of values not included in the other given `Iterable` using the provided `isEquivalent` function.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [2, 3, 4]\n * const difference = Array.differenceWith<number>((a, b) => a === b)(array1, array2)\n * assert.deepStrictEqual(difference, [1])\n * ```\n *\n * @since 2.0.0\n */\nexport const differenceWith = <A>(isEquivalent: (self: A, that: A) => boolean): {\n (that: Iterable<A>): (self: Iterable<A>) => Array<A>\n (self: Iterable<A>, that: Iterable<A>): Array<A>\n} => {\n const has = containsWith(isEquivalent)\n return dual(\n 2,\n (self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(self).filter((a) => !has(that, a))\n )\n}\n\n/**\n * Creates a `Array` of values not included in the other given `Iterable`.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [2, 3, 4]\n * const difference = Array.difference(array1, array2)\n * assert.deepStrictEqual(difference, [1])\n * ```\n *\n * @since 2.0.0\n */\nexport const difference: {\n /**\n * Creates a `Array` of values not included in the other given `Iterable`.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [2, 3, 4]\n * const difference = Array.difference(array1, array2)\n * assert.deepStrictEqual(difference, [1])\n * ```\n *\n * @since 2.0.0\n */\n <A>(that: Iterable<A>): (self: Iterable<A>) => Array<A>\n /**\n * Creates a `Array` of values not included in the other given `Iterable`.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [2, 3, 4]\n * const difference = Array.difference(array1, array2)\n * assert.deepStrictEqual(difference, [1])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, that: Iterable<A>): Array<A>\n} = differenceWith(_equivalence)\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const empty: <A = never>() => Array<A> = () => []\n\n/**\n * Constructs a new `NonEmptyArray<A>` from the specified value.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const of = <A>(a: A): NonEmptyArray<A> => [a]\n\n/**\n * @since 2.0.0\n */\nexport declare namespace ReadonlyArray {\n /**\n * @since 2.0.0\n */\n export type Infer<S extends Iterable<any>> = S extends ReadonlyArray<infer A> ? A\n : S extends Iterable<infer A> ? A\n : never\n\n /**\n * @since 2.0.0\n */\n export type With<S extends Iterable<any>, A> = S extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>\n : Array<A>\n\n /**\n * @since 2.0.0\n */\n export type OrNonEmpty<\n S extends Iterable<any>,\n T extends Iterable<any>,\n A\n > = S extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>\n : T extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>\n : Array<A>\n\n /**\n * @since 2.0.0\n */\n export type AndNonEmpty<\n S extends Iterable<any>,\n T extends Iterable<any>,\n A\n > = S extends NonEmptyReadonlyArray<any> ? T extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>\n : Array<A>\n : Array<A>\n\n /**\n * @since 2.0.0\n */\n export type Flatten<T extends ReadonlyArray<ReadonlyArray<any>>> = T extends\n NonEmptyReadonlyArray<NonEmptyReadonlyArray<infer A>> ? NonEmptyArray<A>\n : T extends ReadonlyArray<ReadonlyArray<infer A>> ? Array<A>\n : never\n}\n\n/**\n * @category mapping\n * @since 2.0.0\n */\nexport const map: {\n /**\n * @category mapping\n * @since 2.0.0\n */\n <S extends ReadonlyArray<any>, B>(\n f: (a: ReadonlyArray.Infer<S>, i: number) => B\n ): (self: S) => ReadonlyArray.With<S, B>\n /**\n * @category mapping\n * @since 2.0.0\n */\n <S extends ReadonlyArray<any>, B>(self: S, f: (a: ReadonlyArray.Infer<S>, i: number) => B): ReadonlyArray.With<S, B>\n} = dual(2, <A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => B): Array<B> => self.map(f))\n\n/**\n * Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatMap: {\n /**\n * Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <S extends ReadonlyArray<any>, T extends ReadonlyArray<any>>(\n f: (a: ReadonlyArray.Infer<S>, i: number) => T\n ): (self: S) => ReadonlyArray.AndNonEmpty<S, T, ReadonlyArray.Infer<T>>\n /**\n * Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(\n self: NonEmptyReadonlyArray<A>,\n f: (a: A, i: number) => NonEmptyReadonlyArray<B>\n ): NonEmptyArray<B>\n /**\n * Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => ReadonlyArray<B>): Array<B>\n} = dual(\n 2,\n <A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => ReadonlyArray<B>): Array<B> => {\n if (isEmptyReadonlyArray(self)) {\n return []\n }\n const out: Array<B> = []\n for (let i = 0; i < self.length; i++) {\n const inner = f(self[i], i)\n for (let j = 0; j < inner.length; j++) {\n out.push(inner[j])\n }\n }\n return out\n }\n)\n\n/**\n * Combines multiple arrays into a single array by concatenating all elements\n * from each nested array. This function ensures that the structure of nested\n * arrays is collapsed into a single, flat array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const nestedArrays = [[1, 2], [], [3, 4], [], [5, 6]]\n * const result = Array.flatten(nestedArrays)\n *\n * assert.deepStrictEqual(result, [1, 2, 3, 4, 5, 6]);\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatten: <S extends ReadonlyArray<ReadonlyArray<any>>>(self: S) => ReadonlyArray.Flatten<S> = flatMap(\n identity\n) as any\n\n/**\n * Applies a function to each element of the `Iterable` and filters based on the result, keeping the transformed values where the function returns `Some`.\n * This method combines filtering and mapping functionalities, allowing transformations and filtering of elements based on a single function pass.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\";\n *\n * const data = [1, 2, 3, 4, 5];\n * const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();\n * const result = Array.filterMap(data, evenSquares);\n *\n * assert.deepStrictEqual(result, [4, 16]);\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const filterMap: {\n /**\n * Applies a function to each element of the `Iterable` and filters based on the result, keeping the transformed values where the function returns `Some`.\n * This method combines filtering and mapping functionalities, allowing transformations and filtering of elements based on a single function pass.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\";\n *\n * const data = [1, 2, 3, 4, 5];\n * const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();\n * const result = Array.filterMap(data, evenSquares);\n *\n * assert.deepStrictEqual(result, [4, 16]);\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(f: (a: A, i: number) => Option<B>): (self: Iterable<A>) => Array<B>\n /**\n * Applies a function to each element of the `Iterable` and filters based on the result, keeping the transformed values where the function returns `Some`.\n * This method combines filtering and mapping functionalities, allowing transformations and filtering of elements based on a single function pass.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\";\n *\n * const data = [1, 2, 3, 4, 5];\n * const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();\n * const result = Array.filterMap(data, evenSquares);\n *\n * assert.deepStrictEqual(result, [4, 16]);\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Array<B>\n} = dual(\n 2,\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Array<B> => {\n const as = fromIterable(self)\n const out: Array<B> = []\n for (let i = 0; i < as.length; i++) {\n const o = f(as[i], i)\n if (O.isSome(o)) {\n out.push(o.value)\n }\n }\n return out\n }\n)\n\n/**\n * Applies a function to each element of the array and filters based on the result, stopping when a condition is not met.\n * This method combines filtering and mapping in a single pass, and short-circuits, i.e., stops processing, as soon as the function returns `None`.\n * This is useful when you need to transform an array but only up to the point where a certain condition holds true.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\";\n *\n * const data = [2, 4, 5];\n * const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();\n * const result = Array.filterMapWhile(data, toSquareTillOdd);\n *\n * assert.deepStrictEqual(result, [4, 16]);\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const filterMapWhile: {\n /**\n * Applies a function to each element of the array and filters based on the result, stopping when a condition is not met.\n * This method combines filtering and mapping in a single pass, and short-circuits, i.e., stops processing, as soon as the function returns `None`.\n * This is useful when you need to transform an array but only up to the point where a certain condition holds true.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\";\n *\n * const data = [2, 4, 5];\n * const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();\n * const result = Array.filterMapWhile(data, toSquareTillOdd);\n *\n * assert.deepStrictEqual(result, [4, 16]);\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(f: (a: A, i: number) => Option<B>): (self: Iterable<A>) => Array<B>\n /**\n * Applies a function to each element of the array and filters based on the result, stopping when a condition is not met.\n * This method combines filtering and mapping in a single pass, and short-circuits, i.e., stops processing, as soon as the function returns `None`.\n * This is useful when you need to transform an array but only up to the point where a certain condition holds true.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\";\n *\n * const data = [2, 4, 5];\n * const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();\n * const result = Array.filterMapWhile(data, toSquareTillOdd);\n *\n * assert.deepStrictEqual(result, [4, 16]);\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Array<B>\n} = dual(2, <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>) => {\n let i = 0\n const out: Array<B> = []\n for (const a of self) {\n const b = f(a, i)\n if (O.isSome(b)) {\n out.push(b.value)\n } else {\n break\n }\n i++\n }\n return out\n})\n\n/**\n * Applies a function to each element of the `Iterable`, categorizing the results into two separate arrays.\n * This function is particularly useful for operations where each element can result in two possible types,\n * and you want to separate these types into different collections. For instance, separating validation results\n * into successes and failures.\n *\n * @example\n * ```ts\n * import { Array, Either } from \"effect\";\n *\n * const data = [1, 2, 3, 4, 5]\n * const isEven = (x: number) => x % 2 === 0\n * const partitioned = Array.partitionMap(data, x =>\n * isEven(x) ? Either.right(x) : Either.left(x)\n * )\n *\n * assert.deepStrictEqual(partitioned, [\n * [1, 3, 5],\n * [2, 4]\n * ])\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const partitionMap: {\n /**\n * Applies a function to each element of the `Iterable`, categorizing the results into two separate arrays.\n * This function is particularly useful for operations where each element can result in two possible types,\n * and you want to separate these types into different collections. For instance, separating validation results\n * into successes and failures.\n *\n * @example\n * ```ts\n * import { Array, Either } from \"effect\";\n *\n * const data = [1, 2, 3, 4, 5]\n * const isEven = (x: number) => x % 2 === 0\n * const partitioned = Array.partitionMap(data, x =>\n * isEven(x) ? Either.right(x) : Either.left(x)\n * )\n *\n * assert.deepStrictEqual(partitioned, [\n * [1, 3, 5],\n * [2, 4]\n * ])\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B, C>(f: (a: A, i: number) => array_<C, B>): (self: Iterable<A>) => [left: Array<B>, right: Array<C>]\n /**\n * Applies a function to each element of the `Iterable`, categorizing the results into two separate arrays.\n * This function is particularly useful for operations where each element can result in two possible types,\n * and you want to separate these types into different collections. For instance, separating validation results\n * into successes and failures.\n *\n * @example\n * ```ts\n * import { Array, Either } from \"effect\";\n *\n * const data = [1, 2, 3, 4, 5]\n * const isEven = (x: number) => x % 2 === 0\n * const partitioned = Array.partitionMap(data, x =>\n * isEven(x) ? Either.right(x) : Either.left(x)\n * )\n *\n * assert.deepStrictEqual(partitioned, [\n * [1, 3, 5],\n * [2, 4]\n * ])\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B, C>(self: Iterable<A>, f: (a: A, i: number) => array_<C, B>): [left: Array<B>, right: Array<C>]\n} = dual(\n 2,\n <A, B, C>(self: Iterable<A>, f: (a: A, i: number) => array_<C, B>): [left: Array<B>, right: Array<C>] => {\n const left: Array<B> = []\n const right: Array<C> = []\n const as = fromIterable(self)\n for (let i = 0; i < as.length; i++) {\n const e = f(as[i], i)\n if (E.isLeft(e)) {\n left.push(e.left)\n } else {\n right.push(e.right)\n }\n }\n return [left, right]\n }\n)\n\n/**\n * Retrieves the `Some` values from an `Iterable` of `Option`s, collecting them into an array.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Array.getSomes([Option.some(1), Option.none(), Option.some(2)]),\n * [1, 2]\n * )\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n\nexport const getSomes: <T extends Iterable<Option<X>>, X = any>(\n self: T\n) => Array<Option.Value<ReadonlyArray.Infer<T>>> = filterMap(identity as any)\n\n/**\n * Retrieves the `Left` values from an `Iterable` of `Either`s, collecting them into an array.\n *\n * @example\n * ```ts\n * import { Array, Either } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Array.getLefts([Either.right(1), Either.left(\"err\"), Either.right(2)]),\n * [\"err\"]\n * )\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const getLefts = <T extends Iterable<array_<any, any>>>(self: T): Array<array_.Left<ReadonlyArray.Infer<T>>> => {\n const out: Array<any> = []\n for (const a of self) {\n if (E.isLeft(a)) {\n out.push(a.left)\n }\n }\n\n return out\n}\n\n/**\n * Retrieves the `Right` values from an `Iterable` of `Either`s, collecting them into an array.\n *\n * @example\n * ```ts\n * import { Array, Either } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Array.getRights([Either.right(1), Either.left(\"err\"), Either.right(2)]),\n * [1, 2]\n * )\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const getRights = <T extends Iterable<array_<any, any>>>(\n self: T\n): Array<array_.Right<ReadonlyArray.Infer<T>>> => {\n const out: Array<any> = []\n for (const a of self) {\n if (E.isRight(a)) {\n out.push(a.right)\n }\n }\n\n return out\n}\n\n/**\n * @category filtering\n * @since 2.0.0\n */\nexport const filter: {\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Array<B>\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Array<A>\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Array<B>\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A>\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A> => {\n const as = fromIterable(self)\n const out: Array<A> = []\n for (let i = 0; i < as.length; i++) {\n if (predicate(as[i], i)) {\n out.push(as[i])\n }\n }\n return out\n }\n)\n\n/**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const partition: {\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (\n self: Iterable<A>\n ) => [excluded: Array<Exclude<A, B>>, satisfying: Array<B>]\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * @category filtering\n * @since 2.0.0\n */\n <A>(\n predicate: (a: NoInfer<A>, i: number) => boolean\n ): (self: Iterable<A>) => [excluded: Array<A>, satisfying: Array<A>]\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(\n self: Iterable<A>,\n refinement: (a: A, i: number) => a is B\n ): [excluded: Array<Exclude<A, B>>, satisfying: Array<B>]\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * @category filtering\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [excluded: Array<A>, satisfying: Array<A>]\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [excluded: Array<A>, satisfying: Array<A>] => {\n const left: Array<A> = []\n const right: Array<A> = []\n const as = fromIterable(self)\n for (let i = 0; i < as.length; i++) {\n if (predicate(as[i], i)) {\n right.push(as[i])\n } else {\n left.push(as[i])\n }\n }\n return [left, right]\n }\n)\n\n/**\n * Separates an `Iterable` into two arrays based on a predicate.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.partition(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, [[1, 3], [2, 4]])\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const separate: <T extends Iterable<array_<any, any>>>(\n self: T\n) => [Array<array_.Left<ReadonlyArray.Infer<T>>>, Array<array_.Right<ReadonlyArray.Infer<T>>>] = partitionMap(\n identity\n)\n\n/**\n * Reduces an array from the left.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.reduce(numbers, 0, (acc, n) => acc + n)\n * assert.deepStrictEqual(result, 6)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const reduce: {\n /**\n * Reduces an array from the left.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.reduce(numbers, 0, (acc, n) => acc + n)\n * assert.deepStrictEqual(result, 6)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Iterable<A>) => B\n /**\n * Reduces an array from the left.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.reduce(numbers, 0, (acc, n) => acc + n)\n * assert.deepStrictEqual(result, 6)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B\n} = dual(\n 3,\n <B, A>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B =>\n fromIterable(self).reduce((b, a, i) => f(b, a, i), b)\n)\n\n/**\n * Reduces an array from the right.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.reduceRight(numbers, 0, (acc, n) => acc + n)\n * assert.deepStrictEqual(result, 6)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const reduceRight: {\n /**\n * Reduces an array from the right.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.reduceRight(numbers, 0, (acc, n) => acc + n)\n * assert.deepStrictEqual(result, 6)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Iterable<A>) => B\n /**\n * Reduces an array from the right.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.reduceRight(numbers, 0, (acc, n) => acc + n)\n * assert.deepStrictEqual(result, 6)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B\n} = dual(\n 3,\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B =>\n fromIterable(self).reduceRight((b, a, i) => f(b, a, i), b)\n)\n\n/**\n * Lifts a predicate into an array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n * const to = Array.liftPredicate(isEven)\n * assert.deepStrictEqual(to(1), [])\n * assert.deepStrictEqual(to(2), [2])\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\nexport const liftPredicate: { // Note: I intentionally avoid using the NoInfer pattern here.\n <A, B extends A>(refinement: Refinement<A, B>): (a: A) => Array<B>\n /**\n * Lifts a predicate into an array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n * const to = Array.liftPredicate(isEven)\n * assert.deepStrictEqual(to(1), [])\n * assert.deepStrictEqual(to(2), [2])\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\n <A>(predicate: Predicate<A>): <B extends A>(b: B) => Array<B>\n} = <A>(predicate: Predicate<A>) => <B extends A>(b: B): Array<B> => predicate(b) ? [b] : []\n\n/**\n * @category lifting\n * @since 2.0.0\n */\nexport const liftOption = <A extends Array<unknown>, B>(\n f: (...a: A) => Option<B>\n) =>\n(...a: A): Array<B> => fromOption(f(...a))\n\n/**\n * @category conversions\n * @since 2.0.0\n */\nexport const fromNullable = <A>(a: A): Array<NonNullable<A>> => a == null ? empty() : [a as NonNullable<A>]\n\n/**\n * @category lifting\n * @since 2.0.0\n */\nexport const liftNullable = <A extends Array<unknown>, B>(\n f: (...a: A) => B | null | undefined\n): (...a: A) => Array<NonNullable<B>> =>\n(...a) => fromNullable(f(...a))\n\n/**\n * Maps over an array and flattens the result, removing null and undefined values.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.flatMapNullable(numbers, n => (n % 2 === 0 ? null : n))\n * assert.deepStrictEqual(result, [1, 3])\n *\n * // Explanation:\n * // The array of numbers [1, 2, 3] is mapped with a function that returns null for even numbers\n * // and the number itself for odd numbers. The resulting array [1, null, 3] is then flattened\n * // to remove null values, resulting in [1, 3].\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatMapNullable: {\n /**\n * Maps over an array and flattens the result, removing null and undefined values.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.flatMapNullable(numbers, n => (n % 2 === 0 ? null : n))\n * assert.deepStrictEqual(result, [1, 3])\n *\n * // Explanation:\n * // The array of numbers [1, 2, 3] is mapped with a function that returns null for even numbers\n * // and the number itself for odd numbers. The resulting array [1, null, 3] is then flattened\n * // to remove null values, resulting in [1, 3].\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B | null | undefined): (self: ReadonlyArray<A>) => Array<NonNullable<B>>\n /**\n * Maps over an array and flattens the result, removing null and undefined values.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.flatMapNullable(numbers, n => (n % 2 === 0 ? null : n))\n * assert.deepStrictEqual(result, [1, 3])\n *\n * // Explanation:\n * // The array of numbers [1, 2, 3] is mapped with a function that returns null for even numbers\n * // and the number itself for odd numbers. The resulting array [1, null, 3] is then flattened\n * // to remove null values, resulting in [1, 3].\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: ReadonlyArray<A>, f: (a: A) => B | null | undefined): Array<NonNullable<B>>\n} = dual(\n 2,\n <A, B>(self: ReadonlyArray<A>, f: (a: A) => B | null | undefined): Array<NonNullable<B>> =>\n flatMap(self, (a) => fromNullable(f(a)))\n)\n\n/**\n * Lifts a function that returns an `Either` into a function that returns an array.\n * If the `Either` is a left, it returns an empty array.\n * If the `Either` is a right, it returns an array with the right value.\n *\n * @example\n * ```ts\n * import { Array, Either } from \"effect\"\n *\n * const parseNumber = (s: string): Either.Either<number, Error> =>\n * isNaN(Number(s)) ? Either.left(new Error(\"Not a number\")) : Either.right(Number(s))\n *\n * const liftedParseNumber = Array.liftEither(parseNumber)\n *\n * const result1 = liftedParseNumber(\"42\")\n * assert.deepStrictEqual(result1, [42])\n *\n * const result2 = liftedParseNumber(\"not a number\")\n * assert.deepStrictEqual(result2, [])\n *\n * // Explanation:\n * // The function parseNumber is lifted to return an array.\n * // When parsing \"42\", it returns an Either.left with the number 42, resulting in [42].\n * // When parsing \"not a number\", it returns an Either.right with an error, resulting in an empty array [].\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\nexport const liftEither = <A extends Array<unknown>, E, B>(\n f: (...a: A) => array_<B, E>\n) =>\n(...a: A): Array<B> => {\n const e = f(...a)\n return E.isLeft(e) ? [] : [e.right]\n}\n\n/**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const every: {\n /**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(\n refinement: (a: NoInfer<A>, i: number) => a is B\n ): (self: ReadonlyArray<A>) => self is ReadonlyArray<B>\n /**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: ReadonlyArray<A>) => boolean\n /**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(self: ReadonlyArray<A>, refinement: (a: A, i: number) => a is B): self is ReadonlyArray<B>\n /**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): boolean\n} = dual(\n 2,\n <A, B extends A>(self: ReadonlyArray<A>, refinement: (a: A, i: number) => a is B): self is ReadonlyArray<B> =>\n self.every(refinement)\n)\n\n/**\n * Check if a predicate holds true for some `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const some: {\n /**\n * Check if a predicate holds true for some `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: ReadonlyArray<A>) => self is NonEmptyReadonlyArray<A>\n /**\n * Check if a predicate holds true for some `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): self is NonEmptyReadonlyArray<A>\n} = dual(\n 2,\n <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): self is NonEmptyReadonlyArray<A> =>\n self.some(predicate)\n)\n\n/**\n * Extends an array with a function that maps each subarray to a value.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.extend(numbers, as => as.length)\n * assert.deepStrictEqual(result, [3, 2, 1])\n *\n * // Explanation:\n * // The function maps each subarray starting from each element to its length.\n * // The subarrays are: [1, 2, 3], [2, 3], [3].\n * // The lengths are: 3, 2, 1.\n * // Therefore, the result is [3, 2, 1].\n * ```\n *\n * @since 2.0.0\n */\nexport const extend: {\n /**\n * Extends an array with a function that maps each subarray to a value.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.extend(numbers, as => as.length)\n * assert.deepStrictEqual(result, [3, 2, 1])\n *\n * // Explanation:\n * // The function maps each subarray starting from each element to its length.\n * // The subarrays are: [1, 2, 3], [2, 3], [3].\n * // The lengths are: 3, 2, 1.\n * // Therefore, the result is [3, 2, 1].\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(f: (as: ReadonlyArray<A>) => B): (self: ReadonlyArray<A>) => Array<B>\n /**\n * Extends an array with a function that maps each subarray to a value.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.extend(numbers, as => as.length)\n * assert.deepStrictEqual(result, [3, 2, 1])\n *\n * // Explanation:\n * // The function maps each subarray starting from each element to its length.\n * // The subarrays are: [1, 2, 3], [2, 3], [3].\n * // The lengths are: 3, 2, 1.\n * // Therefore, the result is [3, 2, 1].\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: ReadonlyArray<A>, f: (as: ReadonlyArray<A>) => B): Array<B>\n} = dual(\n 2,\n <A, B>(self: ReadonlyArray<A>, f: (as: ReadonlyArray<A>) => B): Array<B> => self.map((_, i, as) => f(as.slice(i)))\n)\n\n/**\n * Finds the minimum element in an array based on a comparator.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const min = Array.min([3, 1, 2], Order.number)\n * assert.deepStrictEqual(min, 1)\n * ```\n *\n * @since 2.0.0\n */\nexport const min: {\n /**\n * Finds the minimum element in an array based on a comparator.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const min = Array.min([3, 1, 2], Order.number)\n * assert.deepStrictEqual(min, 1)\n * ```\n *\n * @since 2.0.0\n */\n <A>(O: Order.Order<A>): (self: NonEmptyReadonlyArray<A>) => A\n /**\n * Finds the minimum element in an array based on a comparator.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const min = Array.min([3, 1, 2], Order.number)\n * assert.deepStrictEqual(min, 1)\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A\n} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A => self.reduce(Order.min(O)))\n\n/**\n * Finds the maximum element in an array based on a comparator.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const max = Array.max([3, 1, 2], Order.number)\n * assert.deepStrictEqual(max, 3)\n * ```\n *\n * @since 2.0.0\n */\nexport const max: {\n /**\n * Finds the maximum element in an array based on a comparator.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const max = Array.max([3, 1, 2], Order.number)\n * assert.deepStrictEqual(max, 3)\n * ```\n *\n * @since 2.0.0\n */\n <A>(O: Order.Order<A>): (self: NonEmptyReadonlyArray<A>) => A\n /**\n * Finds the maximum element in an array based on a comparator.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const max = Array.max([3, 1, 2], Order.number)\n * assert.deepStrictEqual(max, 3)\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A\n} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A => self.reduce(Order.max(O)))\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const unfold = <B, A>(b: B, f: (b: B) => Option<readonly [A, B]>): Array<A> => {\n const out: Array<A> = []\n let next: B = b\n let o: Option<readonly [A, B]>\n while (O.isSome(o = f(next))) {\n const [a, b] = o.value\n out.push(a)\n next = b\n }\n return out\n}\n\n/**\n * This function creates and returns a new `Order` for an array of values based on a given `Order` for the elements of the array.\n * The returned `Order` compares two arrays by applying the given `Order` to each element in the arrays.\n * If all elements are equal, the arrays are then compared based on their length.\n * It is useful when you need to compare two arrays of the same type and you have a specific way of comparing each element of the array.\n *\n * @category instances\n * @since 2.0.0\n */\nexport const getOrder: <A>(O: Order.Order<A>) => Order.Order<ReadonlyArray<A>> = Order.array\n\n/**\n * Creates an equivalence relation for arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers1 = [1, 2, 3]\n * const numbers2 = [1, 2, 3]\n * const eq = Array.getEquivalence<number>((a, b) => a === b)\n * assert.deepStrictEqual(eq(numbers1, numbers2), true)\n * ```\n *\n * @category instances\n * @since 2.0.0\n */\nexport const getEquivalence: <A>(\n isEquivalent: Equivalence.Equivalence<A>\n) => Equivalence.Equivalence<ReadonlyArray<A>> = Equivalence.array\n\n/**\n * Performs a side-effect for each element of the `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * Array.forEach(numbers, n => console.log(n)) // 1, 2, 3\n * ```\n *\n * @since 2.0.0\n */\nexport const forEach: {\n /**\n * Performs a side-effect for each element of the `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * Array.forEach(numbers, n => console.log(n)) // 1, 2, 3\n * ```\n *\n * @since 2.0.0\n */\n <A>(f: (a: A, i: number) => void): (self: Iterable<A>) => void\n /**\n * Performs a side-effect for each element of the `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * Array.forEach(numbers, n => console.log(n)) // 1, 2, 3\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, f: (a: A, i: number) => void): void\n} = dual(2, <A>(self: Iterable<A>, f: (a: A, i: number) => void): void => fromIterable(self).forEach((a, i) => f(a, i)))\n\n/**\n * Remove duplicates from an `Iterable` using the provided `isEquivalent` function,\n * preserving the order of the first occurrence of each element.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 2, 3, 3, 3]\n * const unique = Array.dedupeWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const dedupeWith: {\n /**\n * Remove duplicates from an `Iterable` using the provided `isEquivalent` function,\n * preserving the order of the first occurrence of each element.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 2, 3, 3, 3]\n * const unique = Array.dedupeWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <S extends Iterable<any>>(\n isEquivalent: (self: ReadonlyArray.Infer<S>, that: ReadonlyArray.Infer<S>) => boolean\n ): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * Remove duplicates from an `Iterable` using the provided `isEquivalent` function,\n * preserving the order of the first occurrence of each element.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 2, 3, 3, 3]\n * const unique = Array.dedupeWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A>(\n self: NonEmptyReadonlyArray<A>,\n isEquivalent: (self: A, that: A) => boolean\n ): NonEmptyArray<A>\n /**\n * Remove duplicates from an `Iterable` using the provided `isEquivalent` function,\n * preserving the order of the first occurrence of each element.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 2, 3, 3, 3]\n * const unique = Array.dedupeWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A>\n} = dual(\n 2,\n <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const out: NonEmptyArray<A> = [headNonEmpty(input)]\n const rest = tailNonEmpty(input)\n for (const r of rest) {\n if (out.every((a) => !isEquivalent(r, a))) {\n out.push(r)\n }\n }\n return out\n }\n return []\n }\n)\n\n/**\n * Remove duplicates from an `Iterable`, preserving the order of the first occurrence of each element.\n * The equivalence used to compare elements is provided by `Equal.equivalence()` from the `Equal` module.\n *\n * @since 2.0.0\n */\nexport const dedupe = <S extends Iterable<any> | NonEmptyReadonlyArray<any>>(\n self: S\n): S extends NonEmptyReadonlyArray<infer A> ? NonEmptyArray<A> : S extends Iterable<infer A> ? Array<A> : never =>\n dedupeWith(self, Equal.equivalence()) as any\n\n/**\n * Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 1, 2, 2, 3, 3]\n * const unique = Array.dedupeAdjacentWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const dedupeAdjacentWith: {\n /**\n * Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 1, 2, 2, 3, 3]\n * const unique = Array.dedupeAdjacentWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A>(isEquivalent: (self: A, that: A) => boolean): (self: Iterable<A>) => Array<A>\n /**\n * Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 1, 2, 2, 3, 3]\n * const unique = Array.dedupeAdjacentWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A>\n} = dual(2, <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A> => {\n const out: Array<A> = []\n let lastA: O.Option<A> = O.none()\n for (const a of self) {\n if (O.isNone(lastA) || !isEquivalent(a, lastA.value)) {\n out.push(a)\n lastA = O.some(a)\n }\n }\n return out\n})\n\n/**\n * Deduplicates adjacent elements that are identical.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 1, 2, 2, 3, 3]\n * const unique = Array.dedupeAdjacent(numbers)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const dedupeAdjacent: <A>(self: Iterable<A>) => Array<A> = dedupeAdjacentWith(Equal.equivalence())\n\n/**\n * Joins the elements together with \"sep\" in the middle.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const strings = [\"a\", \"b\", \"c\"]\n * const joined = Array.join(strings, \"-\")\n * assert.deepStrictEqual(joined, \"a-b-c\")\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\nexport const join: {\n /**\n * Joins the elements together with \"sep\" in the middle.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const strings = [\"a\", \"b\", \"c\"]\n * const joined = Array.join(strings, \"-\")\n * assert.deepStrictEqual(joined, \"a-b-c\")\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\n (sep: string): (self: Iterable<string>) => string\n /**\n * Joins the elements together with \"sep\" in the middle.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const strings = [\"a\", \"b\", \"c\"]\n * const joined = Array.join(strings, \"-\")\n * assert.deepStrictEqual(joined, \"a-b-c\")\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\n (self: Iterable<string>, sep: string): string\n} = dual(2, (self: Iterable<string>, sep: string): string => fromIterable(self).join(sep))\n\n/**\n * Statefully maps over the chunk, producing new elements of type `B`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.mapAccum(numbers, 0, (acc, n) => [acc + n, acc + n])\n * assert.deepStrictEqual(result, [6, [1, 3, 6]])\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\nexport const mapAccum: {\n /**\n * Statefully maps over the chunk, producing new elements of type `B`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.mapAccum(numbers, 0, (acc, n) => [acc + n, acc + n])\n * assert.deepStrictEqual(result, [6, [1, 3, 6]])\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\n <S, A, B, I extends Iterable<A> = Iterable<A>>(\n s: S,\n f: (s: S, a: ReadonlyArray.Infer<I>, i: number) => readonly [S, B]\n ): (self: I) => [state: S, mappedArray: ReadonlyArray.With<I, B>]\n /**\n * Statefully maps over the chunk, producing new elements of type `B`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.mapAccum(numbers, 0, (acc, n) => [acc + n, acc + n])\n * assert.deepStrictEqual(result, [6, [1, 3, 6]])\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\n <S, A, B, I extends Iterable<A> = Iterable<A>>(\n self: I,\n s: S,\n f: (s: S, a: ReadonlyArray.Infer<I>, i: number) => readonly [S, B]\n ): [state: S, mappedArray: ReadonlyArray.With<I, B>]\n} = dual(\n 3,\n <S, A, B>(self: Iterable<A>, s: S, f: (s: S, a: A, i: number) => [S, B]): [state: S, mappedArray: Array<B>] => {\n let i = 0\n let s1 = s\n const out: Array<B> = []\n for (const a of self) {\n const r = f(s1, a, i)\n s1 = r[0]\n out.push(r[1])\n i++\n }\n return [s1, out]\n }\n)\n\n/**\n * Zips this chunk crosswise with the specified chunk using the specified combiner.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [\"a\", \"b\"]\n * const product = Array.cartesianWith(array1, array2, (a, b) => `${a}-${b}`)\n * assert.deepStrictEqual(product, [\"1-a\", \"1-b\", \"2-a\", \"2-b\"])\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\nexport const cartesianWith: {\n /**\n * Zips this chunk crosswise with the specified chunk using the specified combiner.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [\"a\", \"b\"]\n * const product = Array.cartesianWith(array1, array2, (a, b) => `${a}-${b}`)\n * assert.deepStrictEqual(product, [\"1-a\", \"1-b\", \"2-a\", \"2-b\"])\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B, C>(that: ReadonlyArray<B>, f: (a: A, b: B) => C): (self: ReadonlyArray<A>) => Array<C>\n /**\n * Zips this chunk crosswise with the specified chunk using the specified combiner.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [\"a\", \"b\"]\n * const product = Array.cartesianWith(array1, array2, (a, b) => `${a}-${b}`)\n * assert.deepStrictEqual(product, [\"1-a\", \"1-b\", \"2-a\", \"2-b\"])\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B, C>(self: ReadonlyArray<A>, that: ReadonlyArray<B>, f: (a: A, b: B) => C): Array<C>\n} = dual(\n 3,\n <A, B, C>(self: ReadonlyArray<A>, that: ReadonlyArray<B>, f: (a: A, b: B) => C): Array<C> =>\n flatMap(self, (a) => map(that, (b) => f(a, b)))\n)\n\n/**\n * Zips this chunk crosswise with the specified chunk.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [\"a\", \"b\"]\n * const product = Array.cartesian(array1, array2)\n * assert.deepStrictEqual(product, [[1, \"a\"], [1, \"b\"], [2, \"a\"], [2, \"b\"]])\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\nexport const cartesian: {\n /**\n * Zips this chunk crosswise with the specified chunk.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [\"a\", \"b\"]\n * const product = Array.cartesian(array1, array2)\n * assert.deepStrictEqual(product, [[1, \"a\"], [1, \"b\"], [2, \"a\"], [2, \"b\"]])\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <B>(that: ReadonlyArray<B>): <A>(self: ReadonlyArray<A>) => Array<[A, B]>\n /**\n * Zips this chunk crosswise with the specified chunk.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [\"a\", \"b\"]\n * const product = Array.cartesian(array1, array2)\n * assert.deepStrictEqual(product, [[1, \"a\"], [1, \"b\"], [2, \"a\"], [2, \"b\"]])\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B>(self: ReadonlyArray<A>, that: ReadonlyArray<B>): Array<[A, B]>\n} = dual(\n 2,\n <A, B>(self: ReadonlyArray<A>, that: ReadonlyArray<B>): Array<[A, B]> => cartesianWith(self, that, (a, b) => [a, b])\n)\n\n// -------------------------------------------------------------------------------------\n// do notation\n// -------------------------------------------------------------------------------------\n\n/**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\nexport const Do: ReadonlyArray<{}> = of({})\n\n/**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\nexport const bind: {\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\n <A extends object, N extends string, B>(tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): (\n self: ReadonlyArray<A>\n ) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\n <A extends object, N extends string, B>(\n self: ReadonlyArray<A>,\n tag: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => ReadonlyArray<B>\n ): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n} = doNotation.bind<ReadonlyArrayTypeLambda>(map, flatMap) as any\n\n/**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\nexport const bindTo: {\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\n <N extends string>(tag: N): <A>(self: ReadonlyArray<A>) => Array<{ [K in N]: A }>\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\n <A, N extends string>(self: ReadonlyArray<A>, tag: N): Array<{ [K in N]: A }>\n} = doNotation.bindTo<ReadonlyArrayTypeLambda>(map) as any\n\nconst let_: {\n <N extends string, B, A extends object>(\n tag: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): (self: ReadonlyArray<A>) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n <N extends string, A extends object, B>(\n self: ReadonlyArray<A>,\n tag: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n} = doNotation.let_<ReadonlyArrayTypeLambda>(map) as any\n\nexport {\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link bind}\n * @see {@link Do}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n *\n * ```\n * @category do notation\n * @since 3.2.0\n */\n let_ as let\n}\n","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 * as Nano from \"../core/Nano.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\n/**\n * Collects the given node and all its ancestor nodes that fully contain the specified TextRange.\n *\n * This function starts from the provided node and traverses up the AST, collecting\n * the node itself and its ancestors that encompass the given range.\n *\n * @param node - The starting AST node.\n * @param textRange - The range of text to use for filtering nodes.\n * @returns An array of `ts.Node` objects that fully contain the specified range.\n */\nfunction collectSelfAndAncestorNodesInRange(\n node: ts.Node,\n textRange: ts.TextRange\n): Nano.Nano<Array<ts.Node>> {\n return Nano.sync(() => {\n let result = ReadonlyArray.empty<ts.Node>()\n let parent = node\n while (parent) {\n if (parent.end >= textRange.end) {\n result = pipe(result, ReadonlyArray.append(parent))\n }\n parent = parent.parent\n }\n return result\n })\n}\n\n/**\n * Collects the node at the given position and all its ancestor nodes\n * that fully contain the specified TextRange.\n *\n * This function starts from the closest token at the given position\n * and traverses up the AST, collecting nodes that encompass the range.\n *\n * @param sourceFile - The TypeScript SourceFile to search within.\n * @param textRange - The range of text to use for filtering nodes.\n * @returns An array of `ts.Node` containing the range.\n */\nexport const getAncestorNodesInRange = Nano.fn(\"AST.getAncestorNodesInRange\")(function*(\n sourceFile: ts.SourceFile,\n textRange: ts.TextRange\n) {\n const nodeAtPosition = yield* Nano.option(findNodeAtPosition(sourceFile, textRange.pos))\n if (Option.isNone(nodeAtPosition)) return ReadonlyArray.empty<ts.Node>()\n return yield* collectSelfAndAncestorNodesInRange(nodeAtPosition.value, textRange)\n})\n\nexport class NodeNotFoundError {\n readonly _tag = \"@effect/language-service/NodeNotFoundError\"\n}\n\n/**\n * Finds the deepest AST node at the specified position within the given SourceFile.\n *\n * This function traverses the AST to locate the node that contains the given position.\n * If multiple nodes overlap the position, it returns the most specific (deepest) node.\n *\n * @param sourceFile - The TypeScript SourceFile to search within.\n * @param position - The position in the file to locate the node for.\n * @returns The deepest `ts.Node` found at the specified position.\n * If no node is found, it fails with a `NodeNotFoundError`.\n */\nconst findNodeAtPosition = Nano.fn(\"AST.findNodeAtPosition\")(function*(\n sourceFile: ts.SourceFile,\n position: number\n) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n function find(node: ts.Node): ts.Node | undefined {\n if (position >= node.getStart() && position < node.getEnd()) {\n // If the position is within this node, keep traversing its children\n return ts.forEachChild(node, find) || node\n }\n return undefined\n }\n\n const result = find(sourceFile)\n if (!result) return yield* Nano.fail(new NodeNotFoundError())\n\n return result\n})\n\nexport const getCommentAtPosition = Nano.fn(\"TypeScriptApi.getCommentAtPosition\")(function*(\n sourceFile: ts.SourceFile,\n pos: number\n) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const token = yield* findNodeAtPosition(sourceFile, pos)\n\n if (\n token === undefined || token.kind === ts.SyntaxKind.JsxText ||\n pos >= token.end - (ts.tokenToString(token.kind) || \"\").length\n ) {\n return yield* Nano.fail(new NodeNotFoundError())\n }\n const startPos = token.pos === 0 ? (ts.getShebang(sourceFile.text) || \"\").length : token.pos\n\n if (startPos === 0) return yield* Nano.fail(new NodeNotFoundError())\n\n const result = ts.forEachTrailingCommentRange(sourceFile.text, startPos, isCommentInRange, pos) ||\n ts.forEachLeadingCommentRange(sourceFile.text, startPos, isCommentInRange, pos)\n\n if (!result) return yield* Nano.fail(new NodeNotFoundError())\n\n return result\n})\n\nfunction isCommentInRange(\n pos: number,\n end: number,\n kind: ts.CommentKind,\n _nl: boolean,\n at: number\n): ts.CommentRange | undefined {\n return at >= pos && at < end ? { pos, end, kind } : undefined\n}\n\n/**\n * Ensures value is a text range\n */\nexport function toTextRange(positionOrRange: number | ts.TextRange): ts.TextRange {\n return typeof positionOrRange === \"number\"\n ? { end: positionOrRange, pos: positionOrRange }\n : positionOrRange\n}\n\nexport function isNodeInRange(textRange: ts.TextRange) {\n return (node: ts.Node) => node.pos <= textRange.pos && node.end >= textRange.end\n}\n\nexport const transformAsyncAwaitToEffectGen = Nano.fn(\"AST.transformAsyncAwaitToEffectGen\")(\n function*(\n node: ts.FunctionDeclaration | ts.ArrowFunction | ts.FunctionExpression,\n effectModuleName: string,\n onAwait: (expression: ts.Expression) => ts.Expression\n ) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n function visitor(_: ts.Node): ts.Node {\n if (ts.isAwaitExpression(_)) {\n const expression = ts.visitEachChild(_.expression, visitor, ts.nullTransformationContext)\n\n return ts.factory.createYieldExpression(\n ts.factory.createToken(ts.SyntaxKind.AsteriskToken),\n onAwait(expression)\n )\n }\n return ts.visitEachChild(_, visitor, ts.nullTransformationContext)\n }\n const generatorBody = visitor(node.body!)\n\n const effectGenCallExp = yield* createEffectGenCallExpression(effectModuleName, generatorBody)\n\n let currentFlags = ts.getCombinedModifierFlags(node)\n currentFlags &= ~ts.ModifierFlags.Async\n const newModifiers = ts.factory.createModifiersFromModifierFlags(currentFlags)\n\n if (ts.isArrowFunction(node)) {\n return ts.factory.createArrowFunction(\n newModifiers,\n node.typeParameters,\n node.parameters,\n undefined,\n node.equalsGreaterThanToken,\n effectGenCallExp\n )\n }\n\n const newBody = ts.factory.createBlock([\n ts.factory.createReturnStatement(effectGenCallExp)\n ])\n\n if (ts.isFunctionDeclaration(node)) {\n return ts.factory.createFunctionDeclaration(\n newModifiers,\n node.asteriskToken,\n node.name,\n node.typeParameters,\n node.parameters,\n undefined,\n newBody\n )\n }\n return ts.factory.createFunctionExpression(\n newModifiers,\n node.asteriskToken,\n node.name,\n node.typeParameters,\n node.parameters,\n undefined,\n newBody\n )\n }\n)\n\nexport const addReturnTypeAnnotation = Nano.fn(\"AST.addReturnTypeAnnotation\")(function*(\n sourceFile: ts.SourceFile,\n declaration:\n | ts.FunctionDeclaration\n | ts.FunctionExpression\n | ts.ArrowFunction\n | ts.MethodDeclaration,\n typeNode: ts.TypeNode\n) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const changes = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile)\n const needParens = ts.isArrowFunction(declaration) && closeParen === undefined\n const endNode = needParens ? declaration.parameters[0] : closeParen\n if (endNode) {\n if (needParens) {\n changes.insertNodeBefore(\n sourceFile,\n endNode,\n ts.factory.createToken(ts.SyntaxKind.OpenParenToken)\n )\n changes.insertNodeAfter(\n sourceFile,\n endNode,\n ts.factory.createToken(ts.SyntaxKind.CloseParenToken)\n )\n }\n changes.insertNodeAt(sourceFile, endNode.end, typeNode, { prefix: \": \" })\n }\n})\n\nexport const removeReturnTypeAnnotation = Nano.fn(\"AST.removeReturnTypeAnnotation\")(function*(\n sourceFile: ts.SourceFile,\n declaration:\n | ts.FunctionDeclaration\n | ts.FunctionExpression\n | ts.ArrowFunction\n | ts.MethodDeclaration\n) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const changes = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile)\n const needParens = ts.isArrowFunction(declaration) && closeParen === undefined\n const endNode = needParens ? declaration.parameters[0] : closeParen\n if (endNode && declaration.type) {\n changes.deleteRange(sourceFile, { pos: endNode.end, end: declaration.type.end })\n }\n})\n\nexport class ImportModuleIdentifierNotFoundError {\n readonly _tag = \"@effect/language-service/ImportModuleIdentifierNotFoundError\"\n}\n\nexport const findImportedModuleIdentifier = Nano.fn(\"AST.findImportedModuleIdentifier\")(\n function*<E = never, R = never>(\n sourceFile: ts.SourceFile,\n test: (\n node: ts.Node,\n fromModule: ts.Expression,\n importProperty: Option.Option<ts.ModuleExportName>\n ) => Nano.Nano<boolean, E, R>\n ) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n for (const statement of sourceFile.statements) {\n if (!ts.isImportDeclaration(statement)) continue\n const importClause = statement.importClause\n if (!importClause) continue\n const namedBindings = importClause.namedBindings\n if (!namedBindings) continue\n if (ts.isNamespaceImport(namedBindings)) {\n if (yield* test(namedBindings.name, statement.moduleSpecifier, Option.none())) {\n return (namedBindings.name)\n }\n } else if (ts.isNamedImports(namedBindings)) {\n for (const importSpecifier of namedBindings.elements) {\n const importProperty = Option.fromNullable(importSpecifier.propertyName).pipe(\n Option.orElse(() => Option.some(importSpecifier.name))\n )\n if (yield* test(importSpecifier.name, statement.moduleSpecifier, importProperty)) {\n return (importSpecifier.name)\n }\n }\n }\n }\n return yield* Nano.fail(new ImportModuleIdentifierNotFoundError())\n }\n)\n\nexport function findImportedModuleIdentifierByPackageAndNameOrBarrel(\n sourceFile: ts.SourceFile,\n packageName: string,\n moduleName: string\n) {\n return findImportedModuleIdentifier(\n sourceFile,\n Nano.fn(\n \"AST.findImportedModuleIdentifierByPackageAndNameOrBarrel.findImportedModuleIdentifier\"\n )(function*(_, fromModule, importProperty) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n // import * as Module from \"package/module\"\n if (\n Option.isNone(importProperty) && ts.isStringLiteral(fromModule) &&\n fromModule.text === packageName + \"/\" + moduleName\n ) {\n return true\n }\n // import { Module } from \"package\"\n // or\n // import { Module as M } from \"package\"\n if (\n Option.isSome(importProperty) && ts.isIdentifier(importProperty.value) &&\n importProperty.value.text === moduleName && ts.isStringLiteral(fromModule) &&\n fromModule.text === packageName\n ) {\n return true\n }\n return false\n })\n )\n}\n\nexport const simplifyTypeNode = Nano.fn(\"AST.simplifyTypeNode\")(function*(typeNode: ts.TypeNode) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n function collectCallable(\n typeNode: ts.TypeNode\n ): Option.Option<Array<ts.CallSignatureDeclaration>> {\n // (() => 1) -> skip to inner node\n if (ts.isParenthesizedTypeNode(typeNode)) return collectCallable(typeNode.type)\n // () => 1 -> convert to call signature\n if (ts.isFunctionTypeNode(typeNode)) {\n return Option.some([\n ts.factory.createCallSignature(typeNode.typeParameters, typeNode.parameters, typeNode.type)\n ])\n }\n // { ... } -> if every member is callsignature, return a merge of all of those\n if (ts.isTypeLiteralNode(typeNode)) {\n const allCallSignatures = typeNode.members.every(ts.isCallSignatureDeclaration)\n if (allCallSignatures) {\n return Option.some(typeNode.members as any as Array<ts.CallSignatureDeclaration>)\n }\n }\n // ... & ... -> if both are callable, return merge of both\n if (ts.isIntersectionTypeNode(typeNode)) {\n const members = typeNode.types.map((node) => collectCallable(node))\n if (members.every(Option.isSome)) {\n return Option.some(members.map((_) => Option.isSome(_) ? _.value : []).flat())\n }\n }\n\n return Option.none()\n }\n\n const callSignatures = collectCallable(typeNode)\n if (Option.isSome(callSignatures) && callSignatures.value.length > 1) {\n return ts.factory.createTypeLiteralNode(callSignatures.value)\n }\n return typeNode\n})\n\nexport const tryPreserveDeclarationSemantics = Nano.fn(\"AST.tryPreserveDeclarationSemantics\")(\n function*(nodeToReplace: ts.Node, node: ts.Node) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n // new node should be an expression!\n if (!ts.isExpression(node)) return node\n // ok, we need to replace. is that a method or a function?\n if (ts.isFunctionDeclaration(nodeToReplace)) {\n // I need a name!!!\n if (!nodeToReplace.name) return node\n return ts.factory.createVariableStatement(\n nodeToReplace.modifiers,\n ts.factory.createVariableDeclarationList(\n [ts.factory.createVariableDeclaration(\n nodeToReplace.name,\n undefined,\n undefined,\n node\n )],\n ts.NodeFlags.Const\n )\n )\n } else if (ts.isMethodDeclaration(nodeToReplace)) {\n return ts.factory.createPropertyDeclaration(\n nodeToReplace.modifiers,\n nodeToReplace.name,\n undefined,\n undefined,\n node\n )\n }\n // I don't know what else to do!\n return node\n }\n)\n\nexport const parseDataForExtendsClassCompletion = Nano.fn(\n \"AST.parseDataForExtendsClassCompletion\"\n)(function*(\n sourceFile: ts.SourceFile,\n position: number\n) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n // first, we find the preceding token\n const precedingToken = ts.findPrecedingToken(position, sourceFile, undefined, true)\n if (!precedingToken) return Option.none()\n\n let accessedObject = precedingToken\n let replacementSpan = ts.createTextSpan(position, 0)\n let outerNode: ts.Node = precedingToken\n if (\n ts.isIdentifier(precedingToken) && precedingToken.parent &&\n ts.isPropertyAccessExpression(precedingToken.parent)\n ) {\n // we are in a \"extends Schema.Tag|\"\n replacementSpan = ts.createTextSpan(\n precedingToken.parent.getStart(sourceFile),\n precedingToken.end - precedingToken.parent.getStart(sourceFile)\n )\n accessedObject = precedingToken.parent.expression\n outerNode = precedingToken.parent\n } else if (\n ts.isToken(precedingToken) && precedingToken.kind === ts.SyntaxKind.DotToken &&\n ts.isPropertyAccessExpression(precedingToken.parent)\n ) {\n // we are in a \"extends Schema.|\"\n replacementSpan = ts.createTextSpan(\n precedingToken.parent.getStart(sourceFile),\n precedingToken.end - precedingToken.parent.getStart(sourceFile)\n )\n accessedObject = precedingToken.parent.expression\n outerNode = precedingToken.parent\n } else if (ts.isIdentifier(precedingToken) && precedingToken.parent) {\n // we are in a \"extends Schema|\"\n replacementSpan = ts.createTextSpan(\n precedingToken.getStart(sourceFile),\n precedingToken.end - precedingToken.getStart(sourceFile)\n )\n accessedObject = precedingToken\n outerNode = precedingToken\n } else {\n return Option.none()\n }\n\n if (!ts.isIdentifier(accessedObject)) return Option.none()\n\n // go up allowed nodes until we find the class declaration\n let classDeclaration: ts.Node = outerNode.parent\n while (\n ts.isExpressionWithTypeArguments(classDeclaration) || ts.isHeritageClause(classDeclaration)\n ) {\n if (!classDeclaration.parent) break\n classDeclaration = classDeclaration.parent\n }\n if (!ts.isClassDeclaration(classDeclaration)) return Option.none()\n if (!classDeclaration.name) return Option.none()\n\n return Option.some(\n { accessedObject, classDeclaration, className: classDeclaration.name, replacementSpan } as const\n )\n})\n\nconst createEffectGenCallExpression = Nano.fn(\"AST.createEffectGenCallExpression\")(function*(\n effectModuleIdentifierName: string,\n node: ts.Node\n) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const generator = ts.factory.createFunctionExpression(\n undefined,\n ts.factory.createToken(ts.SyntaxKind.AsteriskToken),\n undefined,\n [],\n [],\n undefined,\n node as any // NOTE(mattia): intended, to use same routine for both ConciseBody and Body\n )\n\n return ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectModuleIdentifierName),\n \"gen\"\n ),\n undefined,\n [generator]\n )\n})\n\nexport const createEffectGenCallExpressionWithBlock = Nano.fn(\n \"AST.createEffectGenCallExpressionWithBlock\"\n)(function*(\n effectModuleIdentifierName: string,\n statement: ts.Statement | Array<ts.Statement>\n) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n return yield* createEffectGenCallExpression(\n effectModuleIdentifierName,\n ts.factory.createBlock(Array.isArray(statement) ? statement : [statement], false)\n )\n})\n\nexport const createReturnYieldStarStatement = Nano.fn(\"AST.createReturnYieldStarStatement\")(\n function*(expr: ts.Expression) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n return ts.factory.createReturnStatement(\n ts.factory.createYieldExpression(\n ts.factory.createToken(ts.SyntaxKind.AsteriskToken),\n expr\n )\n )\n }\n)\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport 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 AST from \"../core/AST\"\nimport * as LSP from \"../core/LSP\"\nimport * as Nano from \"../core/Nano\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi\"\n\nexport const contextSelfInClasses = LSP.createCompletion({\n name: \"effect/contextSelfInClasses\",\n apply: Nano.fn(\"contextSelfInClasses\")(function*(sourceFile, position) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const maybeInfos = yield* AST.parseDataForExtendsClassCompletion(sourceFile, position)\n if (Option.isNone(maybeInfos)) return []\n const { accessedObject, className, replacementSpan } = maybeInfos.value\n\n // first, given the position, we go back\n const contextName = yield* Nano.option(\n AST.findImportedModuleIdentifierByPackageAndNameOrBarrel(\n sourceFile,\n \"effect\",\n \"Context\"\n )\n )\n const contextIdentifier = Option.match(contextName, {\n onNone: () => \"Context\",\n onSome: (_) => _.text\n })\n\n // ensure accessed is an identifier\n if (contextIdentifier !== accessedObject.text) return []\n const name = className.text\n\n return [{\n name: `Tag(\"${name}\")`,\n kind: ts.ScriptElementKind.constElement,\n insertText: `${contextIdentifier}.Tag(\"${name}\")<${name}, ${\"${0}\"}>(){}`,\n replacementSpan,\n isSnippet: true\n }] satisfies Array<LSP.CompletionEntryDefinition>\n })\n})\n","import * as Option from \"effect/Option\"\nimport * as AST from \"../core/AST\"\nimport * as LSP from \"../core/LSP\"\nimport * as Nano from \"../core/Nano\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi\"\n\nexport const effectDataClasses = LSP.createCompletion({\n name: \"effect/effectDataClasses\",\n apply: Nano.fn(\"effectDataClasses\")(function*(sourceFile, position) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const maybeInfos = yield* AST.parseDataForExtendsClassCompletion(sourceFile, position)\n if (Option.isNone(maybeInfos)) return []\n const { accessedObject, className, replacementSpan } = maybeInfos.value\n\n // first, given the position, we go back\n const dataName = yield* Nano.option(\n AST.findImportedModuleIdentifierByPackageAndNameOrBarrel(\n sourceFile,\n \"effect\",\n \"Data\"\n )\n )\n const effectDataIdentifier = Option.match(dataName, {\n onNone: () => \"Data\",\n onSome: (_) => _.text\n })\n\n // ensure accessed is an identifier\n if (effectDataIdentifier !== accessedObject.text) return []\n const name = className.text\n\n return [{\n name: `TaggedError(\"${name}\")`,\n kind: ts.ScriptElementKind.constElement,\n insertText: `${effectDataIdentifier}.TaggedError(\"${name}\")<{${\"${0}\"}}>{}`,\n replacementSpan,\n isSnippet: true\n }, {\n name: `TaggedClass(\"${name}\")`,\n kind: ts.ScriptElementKind.constElement,\n insertText: `${effectDataIdentifier}.TaggedClass(\"${name}\")<{${\"${0}\"}}>{}`,\n replacementSpan,\n isSnippet: true\n }] satisfies Array<LSP.CompletionEntryDefinition>\n })\n})\n","import * as Option from \"effect/Option\"\nimport * as AST from \"../core/AST\"\nimport * as LSP from \"../core/LSP\"\nimport * as Nano from \"../core/Nano\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi\"\n\nexport const effectSchemaSelfInClasses = LSP.createCompletion({\n name: \"effect/effectSchemaSelfInClasses\",\n apply: Nano.fn(\"effectSchemaSelfInClasses\")(function*(sourceFile, position) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const maybeInfos = yield* AST.parseDataForExtendsClassCompletion(sourceFile, position)\n if (Option.isNone(maybeInfos)) return []\n const { accessedObject, className, replacementSpan } = maybeInfos.value\n\n // first, given the position, we go back\n const effectSchemaName = yield* Nano.option(\n AST.findImportedModuleIdentifierByPackageAndNameOrBarrel(\n sourceFile,\n \"effect\",\n \"Schema\"\n )\n )\n const schemaIdentifier = Option.match(effectSchemaName, {\n onNone: () => \"Schema\",\n onSome: (_) => _.text\n })\n\n // ensure accessed is an identifier\n if (schemaIdentifier !== accessedObject.text) return []\n const name = className.text\n\n return [{\n name: `Class<${name}>`,\n kind: ts.ScriptElementKind.constElement,\n insertText: `${schemaIdentifier}.Class<${name}>(\"${name}\")({${\"${0}\"}}){}`,\n replacementSpan,\n isSnippet: true\n }, {\n name: `TaggedError<${name}>`,\n kind: ts.ScriptElementKind.constElement,\n insertText: `${schemaIdentifier}.TaggedError<${name}>(\"${name}\")(\"${name}\", {${\"${0}\"}}){}`,\n replacementSpan,\n isSnippet: true\n }, {\n name: `TaggedClass<${name}>`,\n kind: ts.ScriptElementKind.constElement,\n insertText: `${schemaIdentifier}.TaggedClass<${name}>(\"${name}\")(\"${name}\", {${\"${0}\"}}){}`,\n replacementSpan,\n isSnippet: true\n }, {\n name: `TaggedRequest<${name}>`,\n kind: ts.ScriptElementKind.constElement,\n insertText: `${schemaIdentifier}.TaggedRequest<${name}>(\"${name}\")(\"${name}\", {${\"${0}\"}}){}`,\n replacementSpan,\n isSnippet: true\n }] satisfies Array<LSP.CompletionEntryDefinition>\n })\n})\n","import * as Option from \"effect/Option\"\nimport * as AST from \"../core/AST\"\nimport * as LSP from \"../core/LSP\"\nimport * as Nano from \"../core/Nano\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi\"\n\nexport const effectSelfInClasses = LSP.createCompletion({\n name: \"effect/effectSelfInClasses\",\n apply: Nano.fn(\"effectSelfInClasses\")(function*(sourceFile, position) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const maybeInfos = yield* AST.parseDataForExtendsClassCompletion(sourceFile, position)\n if (Option.isNone(maybeInfos)) return []\n const { accessedObject, className, replacementSpan } = maybeInfos.value\n\n // first, given the position, we go back\n const effectName = yield* Nano.option(\n AST.findImportedModuleIdentifierByPackageAndNameOrBarrel(\n sourceFile,\n \"effect\",\n \"Effect\"\n )\n )\n const effectIdentifier = Option.match(effectName, {\n onNone: () => \"Effect\",\n onSome: (_) => _.text\n })\n\n // ensure accessed is an identifier\n if (effectIdentifier !== accessedObject.text) return []\n const name = className.text\n\n return [{\n name: `Service<${name}>`,\n kind: ts.ScriptElementKind.constElement,\n insertText: `${effectIdentifier}.Service<${name}>()(\"${name}\", {${\"${0}\"}}){}`,\n replacementSpan,\n isSnippet: true\n }] satisfies Array<LSP.CompletionEntryDefinition>\n })\n})\n","import { contextSelfInClasses } from \"./completions/contextSelfInClasses.js\"\nimport { effectDataClasses } from \"./completions/effectDataClasses.js\"\nimport { effectSchemaSelfInClasses } from \"./completions/effectSchemaSelfInClasses.js\"\nimport { effectSelfInClasses } from \"./completions/effectSelfInClasses.js\"\n\nexport const completions = [\n effectSchemaSelfInClasses,\n effectSelfInClasses,\n contextSelfInClasses,\n effectDataClasses\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 ts.forEachChild(node, appendNodeToVisit)\n continue\n }\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 ts.forEachChild(node, appendNodeToVisit)\n continue\n }\n }\n }\n }\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 ts.forEachChild(node, appendNodeToVisit)\n continue\n }\n }\n } else if (ts.isArrowFunction(node) && ts.isExpression(node.body)) {\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 appendNodeToVisit(body)\n continue\n }\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","import * as ReadonlyArray from \"effect/Array\"\nimport * as Eq from \"effect/Equivalence\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as AST from \"./core/AST.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\nconst SymbolDisplayPartEq = Eq.make<ts.SymbolDisplayPart>((fa, fb) =>\n fa.kind === fb.kind && fa.text === fb.text\n)\n\nconst JSDocTagInfoEq = Eq.make<ts.JSDocTagInfo>((fa, fb) =>\n fa.name === fb.name && typeof fa.text === typeof fb.text &&\n (typeof fa.text !== \"undefined\" ? Eq.array(SymbolDisplayPartEq)(fa.text!, fb.text!) : true)\n)\n\nexport function dedupeJsDocTags(quickInfo: ts.QuickInfo | undefined): ts.QuickInfo | undefined {\n if (!quickInfo) return quickInfo\n if (quickInfo.tags) {\n return {\n ...quickInfo,\n tags: ReadonlyArray.dedupeWith(quickInfo.tags, JSDocTagInfoEq)\n }\n }\n return quickInfo\n}\n\nfunction formatTypeForQuickInfo(channelType: ts.Type, channelName: string) {\n return Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n const stringRepresentation = typeChecker.typeToString(\n channelType,\n undefined,\n ts.TypeFormatFlags.NoTruncation\n )\n return `type ${channelName} = ${stringRepresentation}`\n })\n}\n\nexport function prependEffectTypeArguments(\n sourceFile: ts.SourceFile,\n position: number,\n quickInfo: ts.QuickInfo | undefined\n) {\n return pipe(\n Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n // find the node we are hovering\n const maybeNode = pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, AST.toTextRange(position)),\n ReadonlyArray.head\n )\n if (Option.isNone(maybeNode)) return quickInfo\n const node = maybeNode.value\n\n const hasTruncationHappened = quickInfo &&\n ts.displayPartsToString(quickInfo.displayParts).indexOf(\"...\") > -1\n\n // if we are hovering a \"yield*\" and there are no quickinfo,\n // we try to parse the effect type\n // otherwise if no truncation has happened, do nothing\n const nodeForType =\n (!quickInfo && ts.isYieldExpression(node) && node.asteriskToken && node.expression)\n ? node.expression\n : (hasTruncationHappened ? node : undefined)\n\n // we have no node to get type from\n if (!nodeForType) return quickInfo\n\n const effectType = yield* TypeParser.effectType(\n typeChecker.getTypeAtLocation(nodeForType),\n nodeForType\n )\n\n const effectTypeArgsDocumentation: Array<ts.SymbolDisplayPart> = [{\n kind: \"text\",\n text: (\n \"```ts\\n\" +\n \"/* Effect Type Parameters */\\n\" +\n (yield* formatTypeForQuickInfo(effectType.A, \"Success\")) +\n \"\\n\" +\n (yield* formatTypeForQuickInfo(effectType.E, \"Failure\")) +\n \"\\n\" +\n (yield* formatTypeForQuickInfo(effectType.R, \"Requirements\")) +\n \"\\n```\\n\"\n )\n }]\n\n // there are cases where we create it from scratch\n if (!quickInfo) {\n const start = node.getStart()\n const end = node.getEnd()\n return {\n kind: ts.ScriptElementKind.callSignatureElement,\n kindModifiers: \"\",\n textSpan: { start, length: end - start },\n documentation: effectTypeArgsDocumentation\n } satisfies ts.QuickInfo\n }\n\n if (quickInfo.documentation) {\n return {\n ...quickInfo,\n documentation: effectTypeArgsDocumentation.concat(quickInfo.documentation)\n }\n }\n\n return {\n ...quickInfo,\n documentation: effectTypeArgsDocumentation\n }\n }),\n Nano.orElse(() => Nano.succeed(quickInfo))\n )\n}\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as AST from \"../core/AST.js\"\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 asyncAwaitToGen = LSP.createRefactor({\n name: \"effect/asyncAwaitToGen\",\n description: \"Convert to Effect.gen\",\n apply: Nano.fn(\"asyncAwaitToGen.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n const maybeNode = pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.filter((node) =>\n ts.isFunctionDeclaration(node) || ts.isArrowFunction(node) ||\n ts.isFunctionExpression(node)\n ),\n ReadonlyArray.filter((node) => !!node.body),\n ReadonlyArray.filter((node) =>\n !!(ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Async)\n ),\n ReadonlyArray.head\n )\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const node = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.asyncAwaitToGen\",\n description: \"Rewrite to Effect.gen\",\n apply: pipe(\n Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n const effectModuleIdentifierName = Option.match(\n yield* Nano.option(\n AST.findImportedModuleIdentifier(\n sourceFile,\n (node) =>\n pipe(\n TypeParser.importedEffectModule(node),\n Nano.option,\n Nano.map(Option.isSome)\n )\n )\n ),\n {\n onNone: () => \"Effect\",\n onSome: (node) => node.text\n }\n )\n\n const newDeclaration = yield* AST.transformAsyncAwaitToEffectGen(\n node,\n effectModuleIdentifierName,\n (expression) =>\n ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectModuleIdentifierName),\n \"promise\"\n ),\n undefined,\n [\n ts.factory.createArrowFunction(\n undefined,\n undefined,\n [],\n undefined,\n undefined,\n expression\n )\n ]\n )\n )\n\n changeTracker.replaceNode(sourceFile, node, newDeclaration)\n }),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts),\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, typeChecker)\n )\n })\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as AST from \"../core/AST.js\"\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 asyncAwaitToGenTryPromise = LSP.createRefactor({\n name: \"effect/asyncAwaitToGenTryPromise\",\n description: \"Convert to Effect.gen with failures\",\n apply: Nano.fn(\"asyncAwaitToGenTryPromise.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n const maybeNode = pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.filter(\n (node) =>\n ts.isFunctionDeclaration(node) || ts.isArrowFunction(node) ||\n ts.isFunctionExpression(node)\n ),\n ReadonlyArray.filter((node) => !!node.body),\n ReadonlyArray.filter((node) =>\n !!(ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Async)\n ),\n ReadonlyArray.head\n )\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const node = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.asyncAwaitToGenTryPromise\",\n description: \"Rewrite to Effect.gen with failures\",\n apply: pipe(\n Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n const effectModuleIdentifierName = Option.match(\n yield* Nano.option(\n AST.findImportedModuleIdentifier(\n sourceFile,\n (node) =>\n pipe(\n TypeParser.importedEffectModule(node),\n Nano.option,\n Nano.map(Option.isSome)\n )\n )\n ),\n {\n onNone: () => \"Effect\",\n onSome: (node) => node.text\n }\n )\n\n let errorCount = 0\n\n function createErrorADT() {\n errorCount++\n return ts.factory.createObjectLiteralExpression([\n ts.factory.createPropertyAssignment(\n \"_tag\",\n ts.factory.createAsExpression(\n ts.factory.createStringLiteral(\"Error\" + errorCount),\n ts.factory.createTypeReferenceNode(\"const\")\n )\n ),\n ts.factory.createShorthandPropertyAssignment(\"error\")\n ])\n }\n\n const newDeclaration = yield* AST.transformAsyncAwaitToEffectGen(\n node,\n effectModuleIdentifierName,\n (expression) =>\n ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectModuleIdentifierName),\n \"tryPromise\"\n ),\n undefined,\n [\n ts.factory.createObjectLiteralExpression([\n ts.factory.createPropertyAssignment(\n ts.factory.createIdentifier(\"try\"),\n ts.factory.createArrowFunction(\n undefined,\n undefined,\n [],\n undefined,\n undefined,\n expression\n )\n ),\n ts.factory.createPropertyAssignment(\n ts.factory.createIdentifier(\"catch\"),\n ts.factory.createArrowFunction(\n undefined,\n undefined,\n [ts.factory.createParameterDeclaration(undefined, undefined, \"error\")],\n undefined,\n undefined,\n createErrorADT()\n )\n )\n ])\n ]\n )\n )\n\n changeTracker.replaceNode(sourceFile, node, newDeclaration)\n }),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts),\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, typeChecker)\n )\n })\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as AST from \"../core/AST.js\"\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 effectGenToFn = LSP.createRefactor({\n name: \"effect/effectGenToFn\",\n description: \"Convert to Effect.fn\",\n apply: Nano.fn(\"effectGenToFn.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const parseEffectGenNode = Nano.fn(\"asyncAwaitToGen.apply\")(function*(node: ts.Node) {\n // check if the node is a Effect.gen(...)\n const effectGen = yield* TypeParser.effectGen(node)\n // if parent is a Effect.gen(...).pipe(...) we then move the pipe tot the new Effect.fn\n let pipeArgs = ts.factory.createNodeArray<ts.Expression>([])\n let nodeToReplace = node.parent\n if (\n ts.isPropertyAccessExpression(node.parent) && node.parent.name.text === \"pipe\" &&\n ts.isCallExpression(node.parent.parent)\n ) {\n pipeArgs = node.parent.parent.arguments\n nodeToReplace = node.parent.parent.parent\n }\n // then we iterate upwards until we find the function declaration\n while (nodeToReplace) {\n // if arrow function, exit\n if (\n ts.isArrowFunction(nodeToReplace) || ts.isFunctionDeclaration(nodeToReplace) ||\n ts.isMethodDeclaration(nodeToReplace)\n ) {\n return ({ ...effectGen, pipeArgs, nodeToReplace })\n }\n // concise body go up\n if (ts.isConciseBody(nodeToReplace) || ts.isReturnStatement(nodeToReplace)) {\n nodeToReplace = nodeToReplace.parent\n continue\n }\n // function body with only one statement, go up\n if (ts.isBlock(nodeToReplace) && nodeToReplace.statements.length === 1) {\n nodeToReplace = nodeToReplace.parent\n continue\n }\n // exit\n break\n }\n return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n })\n\n const maybeNode = yield* pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.map(parseEffectGenNode),\n Nano.firstSuccessOf,\n Nano.option\n )\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const { effectModule, generatorFunction, nodeToReplace, pipeArgs } = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.effectGenToFn\",\n description: \"Convert to Effect.fn\",\n apply: pipe(\n Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n // if we have a name in the function declaration,\n // we call Effect.fn with the name\n const effectFn = nodeToReplace.name && ts.isIdentifier(nodeToReplace.name) ?\n ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n effectModule,\n \"fn\"\n ),\n undefined,\n [ts.factory.createStringLiteral(nodeToReplace.name.text)]\n ) :\n ts.factory.createPropertyAccessExpression(\n effectModule,\n \"fn\"\n )\n // append the generator and pipe arguments to the Effect.fn call\n const effectFnCallWithGenerator = ts.factory.createCallExpression(\n effectFn,\n undefined,\n [ts.factory.createFunctionExpression(\n undefined,\n ts.factory.createToken(ts.SyntaxKind.AsteriskToken),\n undefined,\n nodeToReplace.typeParameters,\n nodeToReplace.parameters,\n nodeToReplace.type,\n generatorFunction.body\n ) as ts.Expression].concat(pipeArgs)\n )\n changeTracker.replaceNode(\n sourceFile,\n nodeToReplace,\n yield* AST.tryPreserveDeclarationSemantics(nodeToReplace, effectFnCallWithGenerator)\n )\n }),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts)\n )\n })\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as AST from \"../core/AST.js\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const functionToArrow = LSP.createRefactor({\n name: \"effect/functionToArrow\",\n description: \"Convert to arrow\",\n apply: Nano.fn(\"functionToArrow.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const maybeNode = pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.filter((_) => ts.isFunctionDeclaration(_) || ts.isMethodDeclaration(_)),\n ReadonlyArray.filter((_) => !!_.body),\n ReadonlyArray.filter((_) => !!_.name && AST.isNodeInRange(textRange)(_.name)),\n ReadonlyArray.head\n )\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const node = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.functionToArrow\",\n description: \"Convert to arrow\",\n apply: pipe(\n Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n const body = node.body!\n let newBody: ts.ConciseBody = ts.factory.createBlock(body.statements)\n if (body.statements.length === 1) {\n const statement = body.statements[0]\n if (statement && ts.isReturnStatement(statement) && statement.expression) {\n newBody = statement.expression!\n }\n }\n\n let arrowFlags = ts.getCombinedModifierFlags(node)\n arrowFlags &= ~ts.ModifierFlags.Export\n arrowFlags &= ~ts.ModifierFlags.Default\n const arrowModifiers = ts.factory.createModifiersFromModifierFlags(arrowFlags)\n\n const arrowFunction = ts.factory.createArrowFunction(\n arrowModifiers,\n node.typeParameters,\n node.parameters,\n undefined,\n ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),\n newBody\n )\n\n const newDeclaration: ts.Node = yield* AST.tryPreserveDeclarationSemantics(\n node,\n arrowFunction\n )\n changeTracker.replaceNode(sourceFile, node, newDeclaration, {\n leadingTriviaOption: ts.textChanges.LeadingTriviaOption.IncludeAll,\n trailingTriviaOption: ts.textChanges.TrailingTriviaOption.Exclude\n })\n }),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts)\n )\n })\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as AST from \"../core/AST.js\"\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 _findSchemaVariableDeclaration = Nano.fn(\n \"makeSchemaOpaque._findSchemaVariableDeclaration\"\n)(\n function*(sourceFile: ts.SourceFile, textRange: ts.TextRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n const findSchema = Nano.fn(\"makeSchemaOpaque.apply.findSchema\")(\n function*(node: ts.Node) {\n if (!ts.isVariableDeclaration(node)) {\n return yield* Nano.fail(\"parent should be variable declaration\")\n }\n const identifier = node.name\n if (!ts.isIdentifier(identifier)) return yield* Nano.fail(\"name should be an identifier\")\n const initializer = node.initializer\n if (!initializer) return yield* Nano.fail(\"should have an initializer\")\n\n const variableDeclarationList = node.parent\n if (!variableDeclarationList || !ts.isVariableDeclarationList(variableDeclarationList)) {\n return yield* Nano.fail(\"parent is not a variable declaration list\")\n }\n\n const variableStatement = variableDeclarationList.parent\n if (!variableStatement || !ts.isVariableStatement(variableStatement)) {\n return yield* Nano.fail(\"parent not variable declaration statement\")\n }\n\n const type = typeChecker.getTypeAtLocation(initializer)\n const types = yield* TypeParser.effectSchemaType(type, initializer)\n\n return { identifier, variableStatement, variableDeclarationList, types }\n }\n )\n\n return yield* pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.map(findSchema),\n Nano.firstSuccessOf,\n Nano.option\n )\n }\n)\n\nexport const _createOpaqueTypes = Nano.fn(\"_createOpaqueTypes\")(function*(\n effectSchemaName: string,\n inferFromName: string,\n typeA: ts.Type,\n opaqueTypeName: string,\n typeE: ts.Type,\n opaqueEncodedName: string,\n opaqueContextName: string\n) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n // opaque type\n const opaqueInferred = ts.factory.createExpressionWithTypeArguments(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectSchemaName),\n ts.factory.createIdentifier(\"Schema\")\n ),\n ts.factory.createIdentifier(\"Type\")\n ),\n [ts.factory.createTypeQueryNode(\n ts.factory.createIdentifier(inferFromName)\n )]\n )\n const opaqueType = typeA.isUnion() ?\n ts.factory.createTypeAliasDeclaration(\n [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n opaqueTypeName,\n [],\n opaqueInferred\n ) :\n ts.factory.createInterfaceDeclaration(\n [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n opaqueTypeName,\n undefined,\n [ts.factory.createHeritageClause(\n ts.SyntaxKind.ExtendsKeyword,\n [opaqueInferred]\n )],\n []\n )\n // encoded type\n const encodedInferred = ts.factory.createExpressionWithTypeArguments(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectSchemaName),\n ts.factory.createIdentifier(\"Schema\")\n ),\n ts.factory.createIdentifier(\"Encoded\")\n ),\n [ts.factory.createTypeQueryNode(\n ts.factory.createIdentifier(inferFromName)\n )]\n )\n const encodedType = typeE.isUnion() ?\n ts.factory.createTypeAliasDeclaration(\n [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n opaqueEncodedName,\n [],\n encodedInferred\n ) :\n ts.factory.createInterfaceDeclaration(\n [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n opaqueEncodedName,\n undefined,\n [ts.factory.createHeritageClause(\n ts.SyntaxKind.ExtendsKeyword,\n [encodedInferred]\n )],\n []\n )\n\n // context\n const contextInferred = ts.factory.createExpressionWithTypeArguments(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectSchemaName),\n ts.factory.createIdentifier(\"Schema\")\n ),\n ts.factory.createIdentifier(\"Context\")\n ),\n [ts.factory.createTypeQueryNode(\n ts.factory.createIdentifier(inferFromName)\n )]\n )\n const contextType = ts.factory.createTypeAliasDeclaration(\n [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n opaqueContextName,\n [],\n contextInferred\n )\n\n return { contextType, encodedType, opaqueType }\n})\n\nexport const makeSchemaOpaque = LSP.createRefactor({\n name: \"effect/makeSchemaOpaque\",\n description: \"Make Schema opaque\",\n apply: Nano.fn(\"makeSchemaOpaque.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const maybeNode = yield* _findSchemaVariableDeclaration(sourceFile, textRange)\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n\n const { identifier, types, variableDeclarationList, variableStatement } = maybeNode.value\n\n return {\n kind: \"refactor.rewrite.effect.makeSchemaOpaque\",\n description: `Make Schema opaque`,\n apply: pipe(\n Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n const effectSchemaName = Option.match(\n yield* Nano.option(\n AST.findImportedModuleIdentifierByPackageAndNameOrBarrel(\n sourceFile,\n \"effect\",\n \"Schema\"\n )\n ),\n {\n onNone: () => \"Schema\",\n onSome: (_) => _.text\n }\n )\n const newIdentifier = ts.factory.createIdentifier(identifier.text + \"_\")\n const { contextType, encodedType, opaqueType } = yield* _createOpaqueTypes(\n effectSchemaName,\n newIdentifier.text,\n types.A,\n identifier.text,\n types.I,\n identifier.text + \"Encoded\",\n identifier.text + \"Context\"\n )\n\n changeTracker.replaceNode(\n sourceFile,\n identifier,\n newIdentifier\n )\n changeTracker.insertNodeAfter(sourceFile, variableStatement, opaqueType)\n changeTracker.insertNodeAfter(sourceFile, variableStatement, encodedType)\n changeTracker.insertNodeAfter(sourceFile, variableStatement, contextType)\n\n // insert new declaration\n const newSchemaType = ts.factory.createTypeReferenceNode(\n ts.factory.createQualifiedName(\n ts.factory.createIdentifier(effectSchemaName),\n ts.factory.createIdentifier(\"Schema\")\n ),\n [\n ts.factory.createTypeReferenceNode(opaqueType.name),\n ts.factory.createTypeReferenceNode(encodedType.name),\n ts.factory.createTypeReferenceNode(contextType.name)\n ]\n )\n const newConstDeclaration = ts.factory.createVariableStatement(\n variableStatement.modifiers,\n ts.factory.createVariableDeclarationList(\n [ts.factory.createVariableDeclaration(\n identifier.text,\n undefined,\n newSchemaType,\n ts.factory.createIdentifier(newIdentifier.text)\n )],\n variableDeclarationList.flags\n )\n )\n\n changeTracker.insertNodeAfter(sourceFile, variableStatement, newConstDeclaration)\n changeTracker.insertText(sourceFile, variableStatement.end, \"\\n\")\n }),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts)\n )\n }\n })\n})\n","import { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as AST from \"../core/AST.js\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport { _createOpaqueTypes, _findSchemaVariableDeclaration } from \"./makeSchemaOpaque.js\"\n\nexport const makeSchemaOpaqueWithNs = LSP.createRefactor({\n name: \"effect/makeSchemaOpaqueWithNs\",\n description: \"Make Schema opaque with namespace\",\n apply: Nano.fn(\"makeSchemaOpaqueWithNs.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const maybeNode = yield* _findSchemaVariableDeclaration(sourceFile, textRange)\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n\n const { identifier, types, variableDeclarationList, variableStatement } = maybeNode.value\n\n return {\n kind: \"refactor.rewrite.effect.makeSchemaOpaqueWithNs\",\n description: `Make Schema opaque with namespace`,\n apply: pipe(\n Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n const effectSchemaName = Option.match(\n yield* Nano.option(\n AST.findImportedModuleIdentifierByPackageAndNameOrBarrel(\n sourceFile,\n \"effect\",\n \"Schema\"\n )\n ),\n {\n onNone: () => \"Schema\",\n onSome: (_) => _.text\n }\n )\n const newIdentifier = ts.factory.createIdentifier(identifier.text + \"_\")\n const { contextType, encodedType, opaqueType } = yield* _createOpaqueTypes(\n effectSchemaName,\n newIdentifier.text,\n types.A,\n identifier.text,\n types.I,\n \"Encoded\",\n \"Context\"\n )\n\n const namespace = ts.factory.createModuleDeclaration(\n [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n ts.factory.createIdentifier(identifier.text),\n ts.factory.createModuleBlock([\n encodedType,\n contextType\n ]),\n ts.NodeFlags.Namespace\n )\n\n changeTracker.replaceNode(\n sourceFile,\n identifier,\n newIdentifier\n )\n changeTracker.insertNodeAfter(sourceFile, variableStatement, opaqueType)\n changeTracker.insertNodeAfter(sourceFile, variableStatement, namespace)\n\n // insert new declaration\n const newSchemaType = ts.factory.createTypeReferenceNode(\n ts.factory.createQualifiedName(\n ts.factory.createIdentifier(effectSchemaName),\n ts.factory.createIdentifier(\"Schema\")\n ),\n [\n ts.factory.createTypeReferenceNode(opaqueType.name),\n ts.factory.createTypeReferenceNode(\n ts.factory.createQualifiedName(\n ts.factory.createIdentifier(namespace.name.text),\n encodedType.name\n )\n ),\n ts.factory.createTypeReferenceNode(ts.factory.createQualifiedName(\n ts.factory.createIdentifier(namespace.name.text),\n contextType.name\n ))\n ]\n )\n const newConstDeclaration = ts.factory.createVariableStatement(\n variableStatement.modifiers,\n ts.factory.createVariableDeclarationList(\n [ts.factory.createVariableDeclaration(\n identifier.text,\n undefined,\n newSchemaType,\n ts.factory.createIdentifier(newIdentifier.text)\n )],\n variableDeclarationList.flags\n )\n )\n\n changeTracker.insertNodeAfter(sourceFile, variableStatement, newConstDeclaration)\n changeTracker.insertText(sourceFile, variableStatement.end, \"\\n\")\n }),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts)\n )\n }\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as AST from \"../core/AST.js\"\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\"\n\nexport const pipeableToDatafirst = LSP.createRefactor({\n name: \"effect/pipeableToDatafirst\",\n description: \"Rewrite to datafirst\",\n apply: Nano.fn(\"pipeableToDatafirst.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n function isPipeCall(node: ts.Node): node is ts.CallExpression {\n if (!ts.isCallExpression(node)) return false\n const expression = node.expression\n if (!ts.isIdentifier(expression)) return false\n if (expression.text !== \"pipe\") return false\n return true\n }\n\n function asDataFirstExpression(\n node: ts.Node,\n self: ts.Expression\n ): Option.Option<ts.CallExpression> {\n if (!ts.isCallExpression(node)) return Option.none()\n const signature = typeChecker.getResolvedSignature(node)\n if (!signature) return Option.none()\n const callSignatures = typeChecker.getTypeAtLocation(node.expression).getCallSignatures()\n for (let i = 0; i < callSignatures.length; i++) {\n const callSignature = callSignatures[i]\n if (callSignature.parameters.length === node.arguments.length + 1) {\n return Option.some(\n ts.factory.createCallExpression(\n node.expression,\n [],\n [self].concat(node.arguments)\n )\n )\n }\n }\n return Option.none()\n }\n\n const maybeNode = pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.filter(isPipeCall),\n ReadonlyArray.filter((node) => AST.isNodeInRange(textRange)(node.expression)),\n ReadonlyArray.filter(\n (node) => node.arguments.length > 0\n ),\n ReadonlyArray.map((node) => {\n let newNode = node.arguments[0]\n let didSomething = false\n for (let i = 1; i < node.arguments.length; i++) {\n const arg = node.arguments[i]\n const a = asDataFirstExpression(arg, newNode)\n if (Option.isSome(a)) {\n // use found datafirst\n newNode = a.value\n didSomething = true\n } else {\n if (isPipeCall(newNode)) {\n // avoid nested pipe(a, pipe(b, c))\n newNode = ts.factory.createCallExpression(\n ts.factory.createIdentifier(\"pipe\"),\n [],\n newNode.arguments.concat([arg])\n )\n } else {\n // no datafirst, keep pipeable\n newNode = ts.factory.createCallExpression(ts.factory.createIdentifier(\"pipe\"), [], [\n newNode,\n arg\n ])\n }\n }\n }\n return didSomething ? Option.some([node, newNode] as const) : Option.none()\n }),\n ReadonlyArray.filter(Option.isSome),\n ReadonlyArray.map((_) => _.value),\n ReadonlyArray.head\n )\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const [node, newNode] = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.pipeableToDatafirst\",\n description: \"Rewrite to datafirst\",\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n changeTracker.replaceNode(sourceFile, node, newNode)\n })\n })\n })\n})\n","import { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as AST from \"../core/AST.js\"\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\n/**\n * Refactor to remove unnecessary `Effect.gen` calls.\n *\n * This refactor identifies `Effect.gen` calls that are redundant because they only wrap\n * a single `yield*` statement returning an `Effect`. In such cases, the `Effect.gen` wrapper\n * can be removed, and the inner `Effect` can be returned directly.\n *\n * The function works by analyzing the AST within the specified `textRange` to locate\n * `Effect.gen` calls. It checks if the body of the generator function contains only a single\n * `yield*` statement that directly returns an `Effect`. If such a pattern is found, the\n * `Effect.gen` wrapper is replaced with the inner `Effect`.\n *\n * @example\n * Input:\n * ```ts\n * const result = Effect.gen(function* () {\n * return yield* Effect.succeed(42)\n * })\n * ```\n * Output:\n * ```ts\n * const result = Effect.succeed(42)\n * ```\n *\n * @param ts - The TypeScript API.\n * @param program - The TypeScript program instance, used for type checking.\n * @returns A refactor function that takes a `SourceFile` and a `TextRange`, analyzes the AST,\n * and applies the refactor if applicable.\n */\nexport const removeUnnecessaryEffectGen = LSP.createRefactor({\n name: \"effect/removeUnnecessaryEffectGen\",\n description: \"Remove unnecessary Effect.gen\",\n apply: Nano.fn(\"removeUnnecessaryEffectGen.apply\")(function*(sourceFile, textRange) {\n for (\n const nodeToReplace of yield* AST.getAncestorNodesInRange(sourceFile, textRange)\n ) {\n const maybeNode = yield* pipe(\n TypeParser.effectGen(nodeToReplace),\n Nano.flatMap(({ body }) => TypeParser.returnYieldEffectBlock(body)),\n Nano.option\n )\n\n if (Option.isNone(maybeNode)) continue\n const returnedYieldedEffect = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.removeUnnecessaryEffectGen\",\n description: \"Remove unnecessary Effect.gen\",\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n changeTracker.replaceNode(sourceFile, nodeToReplace, returnedYieldedEffect)\n })\n })\n }\n\n return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as AST from \"../core/AST.js\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const toggleLazyConst = LSP.createRefactor({\n name: \"effect/toggleLazyConst\",\n description: \"Toggle lazy const\",\n apply: Nano.fn(\"toggleLazyConst.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const maybeNode = pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.filter(ts.isVariableDeclaration),\n ReadonlyArray.filter((node) => AST.isNodeInRange(textRange)(node.name)),\n ReadonlyArray.filter((node) =>\n !!node.initializer &&\n !(ts.isArrowFunction(node.initializer) && ts.isBlock(node.initializer.body))\n ),\n ReadonlyArray.head\n )\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const node = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.toggleLazyConst\",\n description: \"Toggle lazy const\",\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n const initializer = node.initializer!\n\n if (ts.isArrowFunction(initializer) && initializer.parameters.length === 0) {\n // delete eventual closing bracked\n changeTracker.deleteRange(sourceFile, {\n pos: initializer.body.end,\n end: initializer.end\n })\n // remove () => {\n changeTracker.deleteRange(sourceFile, {\n pos: initializer.pos,\n end: initializer.body.pos\n })\n return\n }\n\n // adds () => before\n changeTracker.insertText(sourceFile, initializer.pos, \" () =>\")\n })\n })\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as AST from \"../core/AST.js\"\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\"\n\nexport const toggleReturnTypeAnnotation = LSP.createRefactor({\n name: \"effect/toggleReturnTypeAnnotation\",\n description: \"Toggle return type annotation\",\n apply: Nano.fn(\"toggleReturnTypeAnnotation.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n const maybeNode = pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.filter((node) =>\n ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) ||\n ts.isArrowFunction(node) || ts.isMethodDeclaration(node)\n ),\n ReadonlyArray.head\n )\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const node = maybeNode.value\n\n if (node.type) {\n return ({\n kind: \"refactor.rewrite.effect.toggleReturnTypeAnnotation\",\n description: \"Toggle return type annotation\",\n apply: pipe(\n AST.removeReturnTypeAnnotation(sourceFile, node),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts)\n )\n })\n }\n\n const returnType = yield* Nano.option(TypeCheckerApi.getInferredReturnType(node))\n if (Option.isNone(returnType)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n\n const returnTypeNode = typeChecker.typeToTypeNode(\n returnType.value,\n node,\n ts.NodeBuilderFlags.NoTruncation\n )\n\n if (!returnTypeNode) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n\n return ({\n kind: \"refactor.rewrite.effect.toggleReturnTypeAnnotation\",\n description: \"Toggle return type annotation\",\n apply: pipe(\n AST.addReturnTypeAnnotation(\n sourceFile,\n node,\n yield* AST.simplifyTypeNode(returnTypeNode)\n ),\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, typeChecker),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts)\n )\n })\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as AST from \"../core/AST.js\"\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\"\n\nexport const toggleTypeAnnotation = LSP.createRefactor({\n name: \"effect/toggleTypeAnnotation\",\n description: \"Toggle type annotation\",\n apply: Nano.fn(\"toggleTypeAnnotation.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n const maybeNode = pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.filter((node) =>\n ts.isVariableDeclaration(node) || ts.isPropertyDeclaration(node)\n ),\n ReadonlyArray.filter((node) => AST.isNodeInRange(textRange)(node.name)),\n ReadonlyArray.filter((node) => !!node.initializer),\n ReadonlyArray.head\n )\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const node = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.toggleTypeAnnotation\",\n description: \"Toggle type annotation\",\n apply: pipe(\n Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n if (node.type) {\n changeTracker.deleteRange(sourceFile, { pos: node.name.end, end: node.type.end })\n return\n }\n\n const initializer = node.initializer!\n const initializerType = typeChecker.getTypeAtLocation(initializer)\n const initializerTypeNode = Option.fromNullable(typeChecker.typeToTypeNode(\n initializerType,\n node,\n ts.NodeBuilderFlags.NoTruncation\n )).pipe(\n Option.orElse(() =>\n Option.fromNullable(typeChecker.typeToTypeNode(\n initializerType,\n undefined,\n ts.NodeBuilderFlags.NoTruncation\n ))\n ),\n Option.getOrUndefined\n )\n if (initializerTypeNode) {\n changeTracker.insertNodeAt(\n sourceFile,\n node.name.end,\n yield* AST.simplifyTypeNode(initializerTypeNode),\n {\n prefix: \": \"\n }\n )\n }\n }),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts)\n )\n })\n })\n})\n","import * as Array from \"effect/Array\"\nimport { identity, pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as AST from \"../core/AST\"\nimport * as Nano from \"../core/Nano\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi\"\n\nexport class TypeParametersNotSupportedError {\n readonly _tag = \"@effect/language-service/TypeParametersNotSupportedError\"\n constructor(\n readonly node: ts.Node\n ) {\n }\n\n toString() {\n return `Could not process types with type parameters.`\n }\n}\n\nexport class OnlyLiteralPropertiesSupportedError {\n readonly _tag = \"@effect/language-service/OnlyLiteralPropertiesSupportedError\"\n constructor(\n readonly node: ts.Node\n ) {\n }\n\n toString() {\n return `Could not process ${this.node.getText()} as only literal properties are supported.`\n }\n}\n\nexport class RequiredExplicitTypesError {\n readonly _tag = \"@effect/language-service/RequiredExplicitTypesError\"\n constructor(\n readonly node: ts.Node\n ) {\n }\n toString() {\n return `Could not process ${this.node.getText()} as only explicit types are supported.`\n }\n}\n\nexport class IndexSignatureWithMoreThanOneParameterError {\n readonly _tag = \"@effect/language-service/IndexSignatureWithMoreThanOneParameterError\"\n constructor(\n readonly node: ts.Node\n ) {\n }\n toString() {\n return `Could not process ${this.node.getText()} as only index signatures with one parameter are supported.`\n }\n}\n\ninterface SchemaGenContext {\n sourceFile: ts.SourceFile\n ts: TypeScriptApi.TypeScriptApi\n createApiPropertyAccess(apiName: string): ts.PropertyAccessExpression\n createApiCall(apiName: string, args: Array<ts.Expression>): ts.CallExpression\n entityNameToDataTypeName(name: ts.EntityName): Option.Option<string>\n}\nconst SchemaGenContext = Nano.Tag<SchemaGenContext>(\"SchemaGenContext\")\n\nexport const makeSchemaGenContext = Nano.fn(\"SchemaGen.makeSchemaGenContext\")(function*(\n sourceFile: ts.SourceFile\n) {\n const effectSchemaIdentifier = pipe(\n yield* Nano.option(\n AST.findImportedModuleIdentifierByPackageAndNameOrBarrel(sourceFile, \"effect\", \"Schema\")\n ),\n Option.match({\n onNone: () => \"Schema\",\n onSome: (_) => _.text\n })\n )\n\n const moduleToImportedName: Record<string, string> = {}\n for (const moduleName of [\"Option\", \"Either\", \"Chunk\", \"Duration\"]) {\n const importedName = yield* Nano.option(\n AST.findImportedModuleIdentifierByPackageAndNameOrBarrel(sourceFile, \"effect\", moduleName)\n )\n if (Option.isSome(importedName)) moduleToImportedName[moduleName] = importedName.value.text\n }\n\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n return {\n sourceFile,\n createApiPropertyAccess: (apiName) =>\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectSchemaIdentifier),\n apiName\n ),\n createApiCall: (apiName, args) =>\n ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectSchemaIdentifier),\n apiName\n ),\n [],\n args\n ),\n entityNameToDataTypeName: (name) => {\n if (ts.isIdentifier(name)) {\n switch (name.text) {\n case \"Date\":\n case \"Pick\":\n case \"Omit\":\n case \"Record\":\n return Option.some(name.text)\n case \"ReadonlyArray\":\n case \"Array\":\n return Option.some(\"Array\")\n }\n return Option.none()\n }\n if (!ts.isIdentifier(name.left)) return Option.none()\n for (const moduleName in moduleToImportedName) {\n if (name.left.text === moduleToImportedName[moduleName] && name.right.text === moduleName) {\n return Option.some(moduleName)\n }\n }\n return Option.none()\n },\n ts\n } satisfies SchemaGenContext\n})\n\nconst typeEntityNameToNode: (\n entityName: ts.EntityName\n) => Nano.Nano<ts.Identifier | ts.PropertyAccessExpression, never, SchemaGenContext> = Nano.fn(\n \"SchemaGen.typeEntityNameToNode\"\n)(\n function*(entityName: ts.EntityName) {\n const { ts } = yield* Nano.service(SchemaGenContext)\n if (ts.isIdentifier(entityName)) return ts.factory.createIdentifier(entityName.text)\n const left = yield* typeEntityNameToNode(entityName.left)\n return ts.factory.createPropertyAccessExpression(\n left,\n ts.factory.createIdentifier(entityName.right.text)\n )\n }\n)\n\nconst parseAllLiterals: (\n node: ts.TypeNode\n) => Nano.Nano<\n Array<ts.StringLiteral | ts.NumericLiteral | ts.NullLiteral | ts.TrueLiteral | ts.FalseLiteral>,\n ts.TypeNode,\n SchemaGenContext\n> = Nano\n .fn(\n \"SchemaGen.parseAllLiterals\"\n )(\n function*(node: ts.TypeNode) {\n const { ts } = yield* Nano.service(SchemaGenContext)\n if (ts.isLiteralTypeNode(node)) {\n switch (node.literal.kind) {\n case ts.SyntaxKind.StringLiteral:\n return [ts.factory.createStringLiteral(node.literal.text)]\n case ts.SyntaxKind.NumericLiteral:\n return [ts.factory.createNumericLiteral(node.literal.text)]\n case ts.SyntaxKind.TrueKeyword:\n return [ts.factory.createTrue()]\n case ts.SyntaxKind.FalseKeyword:\n return [ts.factory.createFalse()]\n }\n }\n if (ts.isUnionTypeNode(node)) {\n return Array.flatten(yield* Nano.all(...node.types.map((_) => parseAllLiterals(_))))\n }\n if (ts.isParenthesizedTypeNode(node)) {\n return yield* parseAllLiterals(node.type)\n }\n return yield* Nano.fail(node)\n }\n )\n\nconst createUnsupportedNodeComment = (\n ts: TypeScriptApi.TypeScriptApi,\n sourceFile: ts.SourceFile,\n node: ts.Node\n) =>\n ts.addSyntheticTrailingComment(\n ts.factory.createIdentifier(\"\"),\n ts.SyntaxKind.MultiLineCommentTrivia,\n \" Not supported conversion: \" + node.getText(sourceFile) + \" \"\n )\n\nexport const processNode = (\n node: ts.Node\n): Nano.Nano<\n ts.Expression,\n | RequiredExplicitTypesError\n | TypeParametersNotSupportedError\n | OnlyLiteralPropertiesSupportedError\n | IndexSignatureWithMoreThanOneParameterError,\n TypeScriptApi.TypeScriptApi | SchemaGenContext\n> =>\n Nano.gen(function*() {\n const { createApiCall, createApiPropertyAccess, entityNameToDataTypeName, sourceFile, ts } =\n yield* Nano.service(\n SchemaGenContext\n )\n // string | number | boolean | undefined | void | never\n switch (node.kind) {\n case ts.SyntaxKind.AnyKeyword:\n return createApiPropertyAccess(\"Any\")\n case ts.SyntaxKind.NeverKeyword:\n return createApiPropertyAccess(\"Never\")\n case ts.SyntaxKind.UnknownKeyword:\n return createApiPropertyAccess(\"Unknown\")\n case ts.SyntaxKind.VoidKeyword:\n return createApiPropertyAccess(\"Void\")\n case ts.SyntaxKind.NullKeyword:\n return createApiPropertyAccess(\"Null\")\n case ts.SyntaxKind.UndefinedKeyword:\n return createApiPropertyAccess(\"Undefined\")\n case ts.SyntaxKind.StringKeyword:\n return createApiPropertyAccess(\"String\")\n case ts.SyntaxKind.NumberKeyword:\n return createApiPropertyAccess(\"Number\")\n case ts.SyntaxKind.BooleanKeyword:\n return createApiPropertyAccess(\"Boolean\")\n case ts.SyntaxKind.BigIntKeyword:\n return createApiPropertyAccess(\"BigInt\")\n }\n // null and other literals\n if (ts.isLiteralTypeNode(node)) {\n if (node.literal.kind === ts.SyntaxKind.NullKeyword) return createApiPropertyAccess(\"Null\")\n const literalMembers = yield* Nano.option(parseAllLiterals(node))\n if (Option.isSome(literalMembers)) return createApiCall(\"Literal\", literalMembers.value)\n }\n // A | B\n if (ts.isUnionTypeNode(node)) {\n // \"a\" | \"b\" can be optimized into a single Schema.Literal(\"a\", \"b\")\n const allLiterals = yield* Nano.option(parseAllLiterals(node))\n if (Option.isSome(allLiterals)) return createApiCall(\"Literal\", allLiterals.value)\n // regular union\n const members = yield* Nano.all(...node.types.map((_) => processNode(_)))\n return createApiCall(\"Union\", members)\n }\n // {a: 1} & {b: 2} & {c: 3}\n if (ts.isIntersectionTypeNode(node)) {\n const [firstSchema, ...otherSchemas] = yield* Nano.all(\n ...node.types.map((_) => processNode(_))\n )\n if (otherSchemas.length === 0) return firstSchema\n return ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n firstSchema,\n \"pipe\"\n ),\n [],\n otherSchemas.map((_) => createApiCall(\"extend\", [_]))\n )\n }\n // string[]\n if (ts.isArrayTypeNode(node)) {\n const typeSchema = yield* processNode(node.elementType)\n return createApiCall(\"Array\", [typeSchema])\n }\n // { a: string, b: boolean }\n if (ts.isTypeLiteralNode(node)) {\n const { properties, records } = yield* processMembers(node.members)\n\n return createApiCall(\n \"Struct\",\n [ts.factory.createObjectLiteralExpression(properties, true)].concat(records)\n )\n }\n // type reference\n if (ts.isTypeReferenceNode(node)) {\n const parsedName = entityNameToDataTypeName(node.typeName)\n if (Option.isSome(parsedName)) {\n switch (parsedName.value) {\n case \"Duration\":\n case \"Date\":\n return createApiPropertyAccess(parsedName.value)\n case \"Option\":\n case \"Chunk\":\n case \"Array\": {\n const elements = yield* Nano.all(\n ...(node.typeArguments ? node.typeArguments.map(processNode) : [])\n )\n return createApiCall(parsedName.value, elements)\n }\n case \"Record\": {\n const elements = yield* Nano.all(\n ...(node.typeArguments ? node.typeArguments.map(processNode) : [])\n )\n if (elements.length >= 2) {\n return createApiCall(parsedName.value, [\n ts.factory.createObjectLiteralExpression([\n ts.factory.createPropertyAssignment(\"key\", elements[0]),\n ts.factory.createPropertyAssignment(\"value\", elements[1])\n ])\n ])\n }\n return createUnsupportedNodeComment(ts, sourceFile, node)\n }\n case \"Either\": {\n const elements = yield* Nano.all(\n ...(node.typeArguments ? node.typeArguments.map(processNode) : [])\n )\n if (elements.length >= 2) {\n return createApiCall(parsedName.value, [\n ts.factory.createObjectLiteralExpression([\n ts.factory.createPropertyAssignment(\"right\", elements[0]),\n ts.factory.createPropertyAssignment(\"left\", elements[1])\n ])\n ])\n }\n return createUnsupportedNodeComment(ts, sourceFile, node)\n }\n case \"Pick\":\n case \"Omit\": {\n const typeArguments = Array.fromIterable(node.typeArguments || [])\n if (typeArguments.length !== 2) {\n return createUnsupportedNodeComment(ts, sourceFile, node)\n }\n const baseType = yield* processNode(typeArguments[0])\n const stringLiteralArguments = yield* Nano.option(parseAllLiterals(typeArguments[1]))\n\n if (Option.isNone(stringLiteralArguments)) {\n return createUnsupportedNodeComment(ts, sourceFile, node)\n }\n return ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n baseType,\n \"pipe\"\n ),\n [],\n [createApiCall(parsedName.value.toLowerCase(), stringLiteralArguments.value)]\n )\n }\n }\n }\n }\n // type reference\n if (ts.isTypeReferenceNode(node)) {\n if (!(node.typeArguments && node.typeArguments.length > 0)) {\n return yield* typeEntityNameToNode(node.typeName)\n }\n }\n\n // wtf\n return createUnsupportedNodeComment(ts, sourceFile, node)\n })\n\nconst processMembers = Nano.fn(\n \"SchemaGen.processMembers\"\n)(\n function*(members: ts.NodeArray<ts.TypeElement>) {\n const { createApiCall, ts } = yield* Nano.service(\n SchemaGenContext\n )\n\n const properties: Array<ts.PropertyAssignment> = []\n for (const propertySignature of members.filter(ts.isPropertySignature)) {\n const name = propertySignature.name\n if (!(ts.isIdentifier(name) || ts.isStringLiteral(name))) {\n return yield* Nano.fail(new OnlyLiteralPropertiesSupportedError(propertySignature))\n }\n if (!propertySignature.type) {\n return yield* Nano.fail(new RequiredExplicitTypesError(propertySignature))\n }\n const propertyAssignment = pipe(\n yield* processNode(propertySignature.type),\n propertySignature.questionToken ? (_) => createApiCall(\"optional\", [_]) : identity,\n (_) => ts.factory.createPropertyAssignment(name, _)\n )\n\n properties.push(propertyAssignment)\n }\n\n const records: Array<ts.ObjectLiteralExpression> = []\n for (const indexSignature of members.filter(ts.isIndexSignatureDeclaration)) {\n if (indexSignature.parameters.length !== 1) {\n return yield* Nano.fail(new IndexSignatureWithMoreThanOneParameterError(indexSignature))\n }\n const parameter = indexSignature.parameters[0]\n if (!parameter.type) return yield* Nano.fail(new RequiredExplicitTypesError(parameter))\n const parameterType = parameter.type\n const key = yield* processNode(parameterType)\n const value = yield* processNode(indexSignature.type)\n records.push(\n ts.factory.createObjectLiteralExpression([\n ts.factory.createPropertyAssignment(\"key\", key),\n ts.factory.createPropertyAssignment(\"value\", value)\n ])\n )\n }\n\n return { properties, records }\n }\n)\n\nconst processInterfaceDeclaration = Nano.fn(\"SchemaGen.processInterfaceDeclaration\")(\n function*(node: ts.InterfaceDeclaration, preferClass: boolean) {\n if (node.typeParameters && node.typeParameters.length > 0) {\n return yield* Nano.fail(new TypeParametersNotSupportedError(node))\n }\n const { createApiCall, ts } = yield* Nano.service(\n SchemaGenContext\n )\n\n const { properties, records } = yield* processMembers(node.members)\n\n if (preferClass && records.length === 0) {\n return yield* createExportSchemaClassDeclaration(node.name.text, properties)\n }\n\n const schemaStruct = createApiCall(\n \"Struct\",\n [ts.factory.createObjectLiteralExpression(properties, true)].concat(records)\n )\n\n return yield* createExportVariableDeclaration(node.name.text, schemaStruct)\n }\n)\n\nconst processTypeAliasDeclaration = Nano.fn(\"SchemaGen.processInterfaceDeclaration\")(\n function*(node: ts.TypeAliasDeclaration, preferClass: boolean) {\n const { ts } = yield* Nano.service(SchemaGenContext)\n\n if (node.typeParameters && node.typeParameters.length > 0) {\n return yield* Nano.fail(new TypeParametersNotSupportedError(node))\n }\n\n if (preferClass && ts.isTypeLiteralNode(node.type)) {\n const { properties, records } = yield* processMembers(node.type.members)\n if (records.length === 0) {\n return yield* createExportSchemaClassDeclaration(node.name.text, properties)\n }\n }\n\n const effectSchema = yield* processNode(node.type)\n\n return yield* createExportVariableDeclaration(node.name.text, effectSchema)\n }\n)\n\nconst createExportVariableDeclaration = Nano.fn(\"SchemaGen.createExportVariableDeclaration\")(\n function*(\n name: string,\n initializer: ts.Expression\n ) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n return ts.factory.createVariableStatement(\n [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n ts.factory.createVariableDeclarationList([\n ts.factory.createVariableDeclaration(\n ts.factory.createIdentifier(name),\n undefined,\n undefined,\n initializer\n )\n ], ts.NodeFlags.Const)\n )\n }\n)\n\nconst createExportSchemaClassDeclaration = Nano.fn(\"SchemaGen.createExportSchemaClassDeclaration\")(\n function*(\n name: string,\n members: Array<ts.PropertyAssignment>\n ) {\n const { createApiPropertyAccess } = yield* Nano.service(SchemaGenContext)\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n return ts.factory.createClassDeclaration(\n [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n ts.factory.createIdentifier(name),\n [],\n [ts.factory.createHeritageClause(\n ts.SyntaxKind.ExtendsKeyword,\n [\n ts.factory.createExpressionWithTypeArguments(\n ts.factory.createCallExpression(\n ts.factory.createCallExpression(\n createApiPropertyAccess(\"Class\"),\n [ts.factory.createTypeReferenceNode(\n name\n )],\n [ts.factory.createStringLiteral(name)]\n ),\n [],\n [ts.factory.createObjectLiteralExpression(\n members,\n true\n )]\n ),\n []\n )\n ]\n )],\n []\n )\n }\n)\n\nexport const process = Nano.fn(\"SchemaGen.process\")(\n function*(\n sourceFile: ts.SourceFile,\n node: ts.InterfaceDeclaration | ts.TypeAliasDeclaration,\n preferClass: boolean\n ) {\n const ctx = yield* makeSchemaGenContext(sourceFile)\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n return yield* pipe(\n ts.isInterfaceDeclaration(node)\n ? processInterfaceDeclaration(node, preferClass)\n : processTypeAliasDeclaration(node, preferClass),\n Nano.provideService(SchemaGenContext, ctx)\n )\n }\n)\n\nexport const findNodeToProcess = Nano.fn(\"SchemaGen.findNodeToProcess\")(\n function*(sourceFile: ts.SourceFile, textRange: ts.TextRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n return pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n Array.filter((node) => ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node)),\n Array.filter((node) => AST.isNodeInRange(textRange)(node.name)),\n Array.filter((node) => (node.typeParameters || []).length === 0),\n Array.head\n )\n }\n)\n\nexport const applyAtNode = Nano.fn(\"SchemaGen.applyAtNode\")(\n function*(\n sourceFile: ts.SourceFile,\n node: ts.TypeAliasDeclaration | ts.InterfaceDeclaration,\n preferClass: boolean\n ) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n const newNode = yield* pipe(\n process(sourceFile, node, preferClass),\n Nano.orElse((error) =>\n Nano.succeed(ts.addSyntheticLeadingComment(\n ts.factory.createIdentifier(\"\"),\n ts.SyntaxKind.MultiLineCommentTrivia,\n \" \" + String(error) + \" \",\n true\n ))\n )\n )\n changeTracker.insertNodeBefore(sourceFile, node, newNode, true, {\n leadingTriviaOption: ts.textChanges.LeadingTriviaOption.StartLine\n })\n }\n)\n","import { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as SchemaGen from \"../utils/SchemaGen.js\"\n\nexport const typeToEffectSchema = LSP.createRefactor({\n name: \"effect/typeToEffectSchema\",\n description: \"Refactor to Schema\",\n apply: Nano.fn(\"typeToEffectSchema.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const maybeNode = yield* SchemaGen.findNodeToProcess(sourceFile, textRange)\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const node = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.typeToEffectSchema\",\n description: \"Refactor to Schema\",\n apply: pipe(\n SchemaGen.applyAtNode(sourceFile, node, false),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts)\n )\n })\n })\n})\n","import { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as SchemaGen from \"../utils/SchemaGen.js\"\n\nexport const typeToEffectSchemaClass = LSP.createRefactor({\n name: \"effect/typeToEffectSchemaClass\",\n description: \"Refactor to Schema.Class\",\n apply: Nano.fn(\"typeToEffectSchemaClass.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const maybeNode = yield* SchemaGen.findNodeToProcess(sourceFile, textRange)\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const node = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.typeToEffectSchemaClass\",\n description: \"Refactor to Schema.Class\",\n apply: pipe(\n SchemaGen.applyAtNode(sourceFile, node, true),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts)\n )\n })\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as AST from \"../core/AST.js\"\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 wrapWithEffectGen = LSP.createRefactor({\n name: \"effect/wrapWithEffectGen\",\n description: \"Wrap with Effect.gen\",\n apply: Nano.fn(\"wrapWithEffectGen.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n const findEffectToWrap = Nano.fn(\"wrapWithEffectGen.apply.findEffectToWrap\")(\n function*(node: ts.Node) {\n if (!ts.isExpression(node)) return yield* Nano.fail(\"is not an expression\")\n\n const parent = node.parent\n if (\n parent != null && ts.isVariableDeclaration(parent) && parent.initializer !== node\n ) return yield* Nano.fail(\"is LHS of variable declaration\")\n\n const type = typeChecker.getTypeAtLocation(node)\n yield* TypeParser.effectType(type, node)\n\n return node\n }\n )\n\n const maybeNode = yield* pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.map(findEffectToWrap),\n Nano.firstSuccessOf,\n Nano.option\n )\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n\n return {\n kind: \"refactor.rewrite.effect.wrapWithEffectGen\",\n description: `Wrap with Effect.gen`,\n apply: pipe(\n Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n const effectGen = yield* pipe(\n AST.createEffectGenCallExpressionWithBlock(\n yield* getEffectModuleIdentifierName(sourceFile),\n yield* AST.createReturnYieldStarStatement(maybeNode.value)\n )\n )\n\n changeTracker.replaceNode(sourceFile, maybeNode.value, effectGen)\n }),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts),\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, typeChecker)\n )\n }\n })\n})\n\nexport const getEffectModuleIdentifierName = Nano.fn(\"getEffectModuleIdentifierName\")(\n function*(sourceFile: ts.SourceFile) {\n return Option.match(\n yield* Nano.option(\n AST.findImportedModuleIdentifier(\n sourceFile,\n (node) =>\n pipe(\n TypeParser.importedEffectModule(node),\n Nano.option,\n Nano.map(Option.isSome)\n )\n )\n ),\n {\n onNone: () => \"Effect\",\n onSome: (node) => node.text\n }\n )\n }\n)\n","import * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const wrapWithPipe = LSP.createRefactor({\n name: \"effect/wrapWithPipe\",\n description: \"Wrap with pipe\",\n apply: Nano.fn(\"wrapWithPipe.apply\")(function*(sourceFile, textRange) {\n if (textRange.end - textRange.pos === 0) {\n return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n }\n\n return ({\n kind: \"refactor.rewrite.effect.wrapWithPipe\",\n description: `Wrap with pipe(...)`,\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n changeTracker.insertText(sourceFile, textRange.pos, \"pipe(\")\n changeTracker.insertText(sourceFile, textRange.end, \")\")\n })\n })\n })\n})\n","import { asyncAwaitToGen } from \"./refactors/asyncAwaitToGen.js\"\nimport { asyncAwaitToGenTryPromise } from \"./refactors/asyncAwaitToGenTryPromise.js\"\nimport { effectGenToFn } from \"./refactors/effectGenToFn.js\"\nimport { functionToArrow } from \"./refactors/functionToArrow.js\"\nimport { makeSchemaOpaque } from \"./refactors/makeSchemaOpaque.js\"\nimport { makeSchemaOpaqueWithNs } from \"./refactors/makeSchemaOpaqueWithNs.js\"\nimport { pipeableToDatafirst } from \"./refactors/pipeableToDatafirst.js\"\nimport { removeUnnecessaryEffectGen } from \"./refactors/removeUnnecessaryEffectGen.js\"\nimport { toggleLazyConst } from \"./refactors/toggleLazyConst.js\"\nimport { toggleReturnTypeAnnotation } from \"./refactors/toggleReturnTypeAnnotation.js\"\nimport { toggleTypeAnnotation } from \"./refactors/toggleTypeAnnotation.js\"\nimport { typeToEffectSchema } from \"./refactors/typeToEffectSchema.js\"\nimport { typeToEffectSchemaClass } from \"./refactors/typeToEffectSchemaClass.js\"\nimport { wrapWithEffectGen } from \"./refactors/wrapWithEffectGen.js\"\nimport { wrapWithPipe } from \"./refactors/wrapWithPipe.js\"\n\nexport const refactors = [\n asyncAwaitToGen,\n asyncAwaitToGenTryPromise,\n functionToArrow,\n typeToEffectSchema,\n typeToEffectSchemaClass,\n makeSchemaOpaque,\n makeSchemaOpaqueWithNs,\n pipeableToDatafirst,\n removeUnnecessaryEffectGen,\n toggleLazyConst,\n toggleReturnTypeAnnotation,\n toggleTypeAnnotation,\n wrapWithEffectGen,\n wrapWithPipe,\n effectGenToFn\n]\n","import { Either } from \"effect\"\nimport { pipe } from \"effect/Function\"\nimport type ts from \"typescript\"\nimport { completions } from \"./completions.js\"\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 { diagnostics } from \"./diagnostics.js\"\nimport { dedupeJsDocTags, prependEffectTypeArguments } from \"./quickinfo.js\"\nimport { refactors } from \"./refactors.js\"\n\nconst init = (\n modules: {\n typescript: typeof ts\n }\n) => {\n function create(info: ts.server.PluginCreateInfo) {\n const languageService = info.languageService\n const pluginOptions: LSP.PluginOptions = LSP.parsePluginOptions(info.config)\n\n // this is nothing more than an hack. Seems like vscode and other editors do not\n // support new error codes in diagnostics. Because they somehow rely on looking into\n // typescript.codefixes object. SO ONLY OPTION here is to register fake codefix.\n // by hooking into the codefixes object and registering a fake codefix.\n\n const diagnosticsErrorCodes = diagnostics.map((diagnostic) => diagnostic.code)\n try {\n ;(modules.typescript as any).codefix.registerCodeFix({\n errorCodes: diagnosticsErrorCodes,\n getCodeActions: () => undefined\n })\n // eslint-disable-next-line no-empty\n } catch (_) {}\n\n // create the proxy\n const proxy: ts.LanguageService = Object.create(null)\n for (const k of Object.keys(languageService) as Array<keyof ts.LanguageService>) {\n // @ts-expect-error\n proxy[k] = (...args: Array<{}>) => languageService[k]!.apply(languageService, args)\n }\n\n const effectCodeFixesForFile = new Map<\n string,\n Array<LSP.ApplicableDiagnosticDefinitionFixWithPositionAndCode>\n >()\n proxy.getSemanticDiagnostics = (fileName, ...args) => {\n const applicableDiagnostics = languageService.getSemanticDiagnostics(fileName, ...args)\n const program = languageService.getProgram()\n\n if (pluginOptions.diagnostics && program) {\n effectCodeFixesForFile.delete(fileName)\n const sourceFile = program.getSourceFile(fileName)\n\n if (sourceFile) {\n return pipe(\n LSP.getSemanticDiagnosticsWithCodeFixes(diagnostics, sourceFile),\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(TypeScriptApi.TypeScriptApi, modules.typescript),\n Nano.provideService(LSP.PluginOptions, pluginOptions),\n Nano.run,\n Either.map(({ codeFixes, diagnostics }) => {\n effectCodeFixesForFile.set(fileName, codeFixes)\n return diagnostics.concat(applicableDiagnostics)\n }),\n Either.getOrElse(() => applicableDiagnostics)\n )\n }\n }\n\n return applicableDiagnostics\n }\n\n proxy.getSupportedCodeFixes = (...args) =>\n languageService.getSupportedCodeFixes(...args).concat(\n diagnosticsErrorCodes.map((_) => \"\" + _)\n )\n\n proxy.getCodeFixesAtPosition = (\n fileName,\n start,\n end,\n errorCodes,\n formatOptions,\n preferences,\n ...args\n ) => {\n const applicableCodeFixes = languageService.getCodeFixesAtPosition(\n fileName,\n start,\n end,\n errorCodes,\n formatOptions,\n preferences,\n ...args\n )\n\n return pipe(\n Nano.sync(() => {\n const effectCodeFixes: Array<ts.CodeFixAction> = []\n const applicableFixes = (effectCodeFixesForFile.get(fileName) || []).filter((_) =>\n _.start === start && _.end === end && errorCodes.indexOf(_.code) > -1\n )\n\n const formatContext = modules.typescript.formatting.getFormatContext(\n formatOptions,\n info.languageServiceHost\n )\n\n for (const applicableFix of applicableFixes) {\n const changes = modules.typescript.textChanges.ChangeTracker.with(\n {\n formatContext,\n host: info.languageServiceHost,\n preferences: preferences || {}\n },\n (changeTracker) =>\n pipe(\n applicableFix.apply,\n Nano.provideService(TypeScriptApi.ChangeTracker, changeTracker),\n Nano.run\n )\n )\n effectCodeFixes.push({\n fixName: applicableFix.fixName,\n description: applicableFix.description,\n changes\n })\n }\n\n return effectCodeFixes\n }),\n Nano.run,\n Either.map((effectCodeFixes) => applicableCodeFixes.concat(effectCodeFixes)),\n Either.getOrElse(() => applicableCodeFixes)\n )\n }\n\n proxy.getApplicableRefactors = (...args) => {\n const applicableRefactors = languageService.getApplicableRefactors(...args)\n const [fileName, positionOrRange] = args\n const program = languageService.getProgram()\n\n if (program) {\n const sourceFile = program.getSourceFile(fileName)\n if (sourceFile) {\n return pipe(\n LSP.getApplicableRefactors(refactors, sourceFile, positionOrRange),\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, program.getTypeChecker()),\n Nano.provideService(\n TypeCheckerApi.TypeCheckerApiCache,\n TypeCheckerApi.makeTypeCheckerApiCache()\n ),\n Nano.provideService(TypeScriptApi.TypeScriptApi, modules.typescript),\n Nano.provideService(LSP.PluginOptions, pluginOptions),\n Nano.run,\n Either.map((effectRefactors) => applicableRefactors.concat(effectRefactors)),\n Either.getOrElse(() => applicableRefactors)\n )\n }\n }\n return applicableRefactors\n }\n\n proxy.getEditsForRefactor = (\n fileName,\n formatOptions,\n positionOrRange,\n refactorName,\n actionName,\n preferences,\n ...args\n ) => {\n const program = languageService.getProgram()\n if (program) {\n const sourceFile = program.getSourceFile(fileName)\n if (sourceFile) {\n const result = pipe(\n Nano.gen(function*() {\n const applicableRefactor = yield* LSP.getEditsForRefactor(\n refactors,\n sourceFile,\n positionOrRange,\n refactorName\n )\n\n const formatContext = modules.typescript.formatting.getFormatContext(\n formatOptions,\n info.languageServiceHost\n )\n\n const edits = modules.typescript.textChanges.ChangeTracker.with(\n {\n formatContext,\n host: info.languageServiceHost,\n preferences: preferences || {}\n },\n (changeTracker) =>\n pipe(\n applicableRefactor.apply,\n Nano.provideService(TypeScriptApi.ChangeTracker, changeTracker),\n Nano.run\n )\n )\n\n return { edits } as ts.RefactorEditInfo\n }),\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, program.getTypeChecker()),\n Nano.provideService(\n TypeCheckerApi.TypeCheckerApiCache,\n TypeCheckerApi.makeTypeCheckerApiCache()\n ),\n Nano.provideService(TypeScriptApi.TypeScriptApi, modules.typescript),\n Nano.provideService(LSP.PluginOptions, pluginOptions),\n Nano.run\n )\n\n if (Either.isRight(result)) return result.right\n }\n }\n\n return languageService.getEditsForRefactor(\n fileName,\n formatOptions,\n positionOrRange,\n refactorName,\n actionName,\n preferences,\n ...args\n )\n }\n\n proxy.getQuickInfoAtPosition = (fileName, position, ...args) => {\n const quickInfo = languageService.getQuickInfoAtPosition(fileName, position, ...args)\n\n if (pluginOptions.quickinfo) {\n const dedupedTagsQuickInfo = dedupeJsDocTags(quickInfo)\n\n const program = languageService.getProgram()\n if (program) {\n const sourceFile = program.getSourceFile(fileName)\n if (sourceFile) {\n return pipe(\n prependEffectTypeArguments(\n sourceFile,\n position,\n dedupedTagsQuickInfo\n ),\n Nano.provideService(TypeScriptApi.TypeScriptProgram, program),\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, program.getTypeChecker()),\n Nano.provideService(TypeScriptApi.TypeScriptApi, modules.typescript),\n Nano.provideService(LSP.PluginOptions, pluginOptions),\n Nano.run,\n Either.getOrElse(() => dedupedTagsQuickInfo)\n )\n }\n }\n\n return dedupedTagsQuickInfo\n }\n\n return quickInfo\n }\n\n proxy.getCompletionsAtPosition = (fileName, position, options, formattingSettings, ...args) => {\n const applicableCompletions = languageService.getCompletionsAtPosition(\n fileName,\n position,\n options,\n formattingSettings,\n ...args\n )\n\n if (pluginOptions.completions) {\n const program = languageService.getProgram()\n if (program) {\n const sourceFile = program.getSourceFile(fileName)\n if (sourceFile) {\n return pipe(\n LSP.getCompletionsAtPosition(\n completions,\n sourceFile,\n position,\n options,\n formattingSettings\n ),\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(TypeScriptApi.TypeScriptApi, modules.typescript),\n Nano.provideService(LSP.PluginOptions, pluginOptions),\n Nano.run,\n Either.map((effectCompletions) => (applicableCompletions\n ? {\n ...applicableCompletions,\n entries: effectCompletions.concat(applicableCompletions.entries)\n }\n : (effectCompletions.length > 0 ?\n ({\n entries: effectCompletions,\n isGlobalCompletion: false,\n isMemberCompletion: false,\n isNewIdentifierLocation: false\n }) satisfies ts.CompletionInfo :\n undefined))\n ),\n Either.getOrElse(() => applicableCompletions)\n )\n }\n }\n }\n\n return applicableCompletions\n }\n\n return proxy\n }\n\n return { create }\n}\n\nmodule.exports = init\n"],"mappings":";;;;;;;;AA6BO,IAAMA,aAAcC,WAAsC,OAAOA,UAAU;AA6C3E,IAAMC,OA+FT,SAASC,OAAOC,MAAI;AACtB,MAAI,OAAOD,UAAU,YAAY;AAC/B,WAAO,WAAA;AACL,UAAIA,MAAME,SAAS,GAAG;AAEpB,eAAOD,KAAKE,MAAM,MAAMD,SAAS;MACnC;AACA,aAASE,UAAcH,KAAKG,MAAM,GAAGF,SAAS;IAChD;EACF;AAEA,UAAQF,OAAK;IACX,KAAK;IACL,KAAK;AACH,YAAM,IAAIK,WAAW,iBAAiBL,KAAK,EAAE;IAE/C,KAAK;AACH,aAAO,SAASM,GAAGC,GAAC;AAClB,YAAIL,UAAUM,UAAU,GAAG;AACzB,iBAAOP,KAAKK,GAAGC,CAAC;QAClB;AACA,eAAO,SAASH,MAAS;AACvB,iBAAOH,KAAKG,MAAME,CAAC;QACrB;MACF;IAEF,KAAK;AACH,aAAO,SAASA,GAAGC,GAAGE,GAAC;AACrB,YAAIP,UAAUM,UAAU,GAAG;AACzB,iBAAOP,KAAKK,GAAGC,GAAGE,CAAC;QACrB;AACA,eAAO,SAASL,MAAS;AACvB,iBAAOH,KAAKG,MAAME,GAAGC,CAAC;QACxB;MACF;IAEF,KAAK;AACH,aAAO,SAASD,GAAGC,GAAGE,GAAGC,GAAC;AACxB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BAAO;AAAA,cACD;AAAA,gBACF;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA;AAAA,cACF;AAAA,cACK,eAA6B,mBAAmB,OAAO;AAAA,cACvD,eAA8B,gBAAgB,QAAQ,eAAe,CAAC;AAAA,cACtE;AAAA,gBACY;AAAA,gBACA,wBAAwB;AAAA,cACzC;AAAA,cACK,eAA6B,eAAe,QAAQ,UAAU;AAAA,cAC9D,eAAmB,eAAe,aAAa;AAAA,cAC/C;AAAA,cACL,eAAO;AAAA,gBAAI,CAAC,sBAAuB,wBAC/B;AAAA,kBACA,GAAG;AAAA,kBACH,SAAS,kBAAkB,OAAO,sBAAsB,OAAO;AAAA,gBACjE,IACG,kBAAkB,SAAS,IAC3B;AAAA,kBACC,SAAS;AAAA,kBACT,oBAAoB;AAAA,kBACpB,oBAAoB;AAAA,kBACpB,yBAAyB;AAAA,gBAC3B,IACA;AAAA,cACJ;AAAA,cACA,eAAO,UAAU,MAAM,qBAAqB;AAAA,YAC9C;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AAEA,SAAO,EAAE,OAAO;AAClB;AAEA,OAAO,UAAU;","names":["isFunction","input","dual","arity","body","arguments","apply","self","RangeError","a","b","length","c","d","e","args","identity","a","constant","value","constNull","constant","constUndefined","undefined","pipe","a","ab","bc","cd","de","ef","fg","gh","hi","arguments","length","ret","i","TypeId","bind","bindTo","fromOption","getLeft","getRight","isEither","isLeft","isRight","left","let_","right","make","isEquivalent","self","that","array","item","make","self","that","length","i","isEq","let_","map","dual","self","name","f","a","Object","assign","bindTo","bind","flatMap","b","moduleVersion","getCurrentVersion","globalStoreId","version","getCurrentVersion","globalStore","globalValue","id","compute","globalThis","Map","has","set","get","isFunction","isFunction_","isRecordOrArray","input","isObject","isFunction","hasProperty","dual","self","property","getBugErrorMessage","message","GenKindTypeId","Symbol","for","isGenKind","u","isObject","GenKindImpl","value","constructor","_F","identity","_R","_","_O","_E","iterator","SingleShotGen","self","called","next","a","done","return","throw","e","adapter","x","arguments","i","length","GenKindImpl","MUL_HI","MUL_LO","YieldWrapTypeId","Symbol","for","YieldWrap","constructor","value","yieldWrapGet","self","Error","getBugErrorMessage","structuralRegionState","globalValue","enabled","tester","undefined","genConstructor","constructor","randomHashCache","globalValue","Symbol","for","WeakMap","symbol","hash","self","structuralRegionState","enabled","number","string","toString","String","Date","toISOString","isHash","random","Error","has","set","Math","floor","Number","MAX_SAFE_INTEGER","get","combine","b","optimize","n","u","hasProperty","Infinity","h","str","i","length","charCodeAt","structureKeys","o","keys","pipe","structure","Object","cached","arguments","length","self","hash","Object","defineProperty","symbol","value","enumerable","symbol","Symbol","for","equals","arguments","length","self","compareBoth","that","selfType","isEqual","hash","structuralRegionState","enabled","tester","Date","toISOString","Array","isArray","every","v","i","Object","getPrototypeOf","prototype","keysSelf","keys","keysThat","key","u","hasProperty","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","getLeft","self","none","some","getRight","fromOption","dual","onNone","isNone","value","TypeId","right","left","fromNullable","dual","self","onNullable","fromOption","try_","evaluate","isFunction","e","try","catch","isEither","isLeft","isRight","getRight","getLeft","getEquivalence","left","right","make","x","y","mapBoth","dual","self","onLeft","onRight","mapLeft","f","map","match","liftPredicate","a","predicate","orLeftWith","filterOrLeft","flatMap","r","merge","identity","getOrElse","getOrNull","constNull","getOrUndefined","constUndefined","getOrThrowWith","getOrThrow","Error","orElse","that","andThen","b","isFunction","zipWith","r2","ap","all","input","Symbol","iterator","out","e","push","key","Object","keys","flip","adapter","Gen","gen","args","length","bind","state","next","done","value","current","isGenKind","yieldWrapGet","Do","doNotation","bindTo","let_","isNonEmptyArray","self","length","make","compare","self","that","none","some","isNone","isSome","match","dual","self","onNone","onSome","value","getOrElse","dual","self","onNone","isNone","value","orElse","that","fromNullable","nullableValue","none","some","getOrUndefined","getOrElse","constUndefined","fromIterable","collection","Array","isArray","from","append","dual","self","last","isArray","Array","isEmptyArray","self","length","isEmptyReadonlyArray","isNonEmptyReadonlyArray","isNonEmptyArray","isOutOfBound","i","as","length","get","dual","self","index","i","Math","floor","isOutOfBound","none","some","unsafeGet","Error","head","get","headNonEmpty","unsafeGet","tailNonEmpty","self","slice","sort","dual","self","O","out","Array","from","empty","map","dual","self","f","flatMap","isEmptyReadonlyArray","out","i","length","inner","j","push","flatten","identity","filter","dual","self","predicate","as","fromIterable","out","i","length","push","dedupeWith","dual","self","isEquivalent","input","fromIterable","isNonEmptyReadonlyArray","out","headNonEmpty","rest","tailNonEmpty","r","every","a","push","make","run","left","right","flatMap","map","orElse","arr","gen","some","none","all","isNone","none","fromNullable","orElse","some","isSome","typeNode","isSome","map","refactors","refactor","completions","match","flatMap","isNone","match","isNone","match","isNone","match","isNone","match","gen","make","symbol","isSome","isSome","isSome","orElse","isNone","orElse","orElse","orElse","isSome","gen","flatMap","isSome","gen","gen","isNone","effectType","orElse","node","isNone","gen","match","map","isSome","node","isNone","gen","match","map","isSome","effectGen","pipeArgs","nodeToReplace","map","isNone","gen","isNone","gen","map","isNone","gen","match","isNone","gen","match","node","none","some","map","newNode","isSome","isNone","gen","flatMap","isNone","gen","node","isNone","gen","node","isNone","node","isNone","gen","fromNullable","orElse","getOrUndefined","match","isSome","some","none","left","all","gen","isNone","orElse","isNone","isNone","map","isNone","gen","effectGen","match","isSome","gen","diagnostics","gen"]}
1
+ {"version":3,"sources":["../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Function.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Either.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Equivalence.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/doNotation.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/version.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/GlobalValue.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Predicate.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/errors.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Utils.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Hash.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Equal.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Inspectable.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Pipeable.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/opCodes/effect.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/effectable.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/option.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/either.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/internal/array.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Order.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Option.ts","../node_modules/.pnpm/effect@3.12.5/node_modules/effect/src/Array.ts","../src/core/Nano.ts","../src/core/TypeScriptApi.ts","../src/core/AST.ts","../src/core/LSP.ts","../src/completions/contextSelfInClasses.ts","../src/completions/effectDataClasses.ts","../src/completions/effectSchemaSelfInClasses.ts","../src/completions/effectSelfInClasses.ts","../src/completions.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","../src/quickinfo.ts","../src/refactors/asyncAwaitToGen.ts","../src/refactors/asyncAwaitToGenTryPromise.ts","../src/refactors/effectGenToFn.ts","../src/refactors/functionToArrow.ts","../src/refactors/makeSchemaOpaque.ts","../src/refactors/makeSchemaOpaqueWithNs.ts","../src/refactors/pipeableToDatafirst.ts","../src/refactors/removeUnnecessaryEffectGen.ts","../src/refactors/toggleLazyConst.ts","../src/refactors/toggleReturnTypeAnnotation.ts","../src/refactors/toggleTypeAnnotation.ts","../src/utils/SchemaGen.ts","../src/refactors/typeToEffectSchema.ts","../src/refactors/typeToEffectSchemaClass.ts","../src/refactors/wrapWithEffectGen.ts","../src/refactors/wrapWithPipe.ts","../src/refactors.ts","../src/index.ts"],"sourcesContent":["/**\n * @since 2.0.0\n */\nimport type { TypeLambda } from \"./HKT.js\"\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface FunctionTypeLambda extends TypeLambda {\n readonly type: (a: this[\"In\"]) => this[\"Target\"]\n}\n\n/**\n * Tests if a value is a `function`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isFunction } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isFunction(isFunction), true)\n * assert.deepStrictEqual(isFunction(\"function\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isFunction = (input: unknown): input is Function => typeof input === \"function\"\n\n/**\n * Creates a function that can be used in a data-last (aka `pipe`able) or\n * data-first style.\n *\n * The first parameter to `dual` is either the arity of the uncurried function\n * or a predicate that determines if the function is being used in a data-first\n * or data-last style.\n *\n * Using the arity is the most common use case, but there are some cases where\n * you may want to use a predicate. For example, if you have a function that\n * takes an optional argument, you can use a predicate to determine if the\n * function is being used in a data-first or data-last style.\n *\n * @param arity - Either the arity of the uncurried function or a predicate\n * which determines if the function is being used in a data-first\n * or data-last style.\n * @param body - The definition of the uncurried function.\n *\n * @example\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * // Exampe using arity to determine data-first or data-last style\n * const sum: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual(2, (self: number, that: number): number => self + that)\n *\n * assert.deepStrictEqual(sum(2, 3), 5)\n * assert.deepStrictEqual(pipe(2, sum(3)), 5)\n *\n * // Example using a predicate to determine data-first or data-last style\n * const sum2: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual((args) => args.length === 1, (self: number, that: number): number => self + that)\n *\n * assert.deepStrictEqual(sum(2, 3), 5)\n * assert.deepStrictEqual(pipe(2, sum(3)), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const dual: {\n /**\n * Creates a function that can be used in a data-last (aka `pipe`able) or\n * data-first style.\n *\n * The first parameter to `dual` is either the arity of the uncurried function\n * or a predicate that determines if the function is being used in a data-first\n * or data-last style.\n *\n * Using the arity is the most common use case, but there are some cases where\n * you may want to use a predicate. For example, if you have a function that\n * takes an optional argument, you can use a predicate to determine if the\n * function is being used in a data-first or data-last style.\n *\n * @param arity - Either the arity of the uncurried function or a predicate\n * which determines if the function is being used in a data-first\n * or data-last style.\n * @param body - The definition of the uncurried function.\n *\n * @example\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * // Exampe using arity to determine data-first or data-last style\n * const sum: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual(2, (self: number, that: number): number => self + that)\n *\n * assert.deepStrictEqual(sum(2, 3), 5)\n * assert.deepStrictEqual(pipe(2, sum(3)), 5)\n *\n * // Example using a predicate to determine data-first or data-last style\n * const sum2: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual((args) => args.length === 1, (self: number, that: number): number => self + that)\n *\n * assert.deepStrictEqual(sum(2, 3), 5)\n * assert.deepStrictEqual(pipe(2, sum(3)), 5)\n * ```\n *\n * @since 2.0.0\n */\n <DataLast extends (...args: Array<any>) => any, DataFirst extends (...args: Array<any>) => any>(\n arity: Parameters<DataFirst>[\"length\"],\n body: DataFirst\n ): DataLast & DataFirst\n /**\n * Creates a function that can be used in a data-last (aka `pipe`able) or\n * data-first style.\n *\n * The first parameter to `dual` is either the arity of the uncurried function\n * or a predicate that determines if the function is being used in a data-first\n * or data-last style.\n *\n * Using the arity is the most common use case, but there are some cases where\n * you may want to use a predicate. For example, if you have a function that\n * takes an optional argument, you can use a predicate to determine if the\n * function is being used in a data-first or data-last style.\n *\n * @param arity - Either the arity of the uncurried function or a predicate\n * which determines if the function is being used in a data-first\n * or data-last style.\n * @param body - The definition of the uncurried function.\n *\n * @example\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * // Exampe using arity to determine data-first or data-last style\n * const sum: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual(2, (self: number, that: number): number => self + that)\n *\n * assert.deepStrictEqual(sum(2, 3), 5)\n * assert.deepStrictEqual(pipe(2, sum(3)), 5)\n *\n * // Example using a predicate to determine data-first or data-last style\n * const sum2: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual((args) => args.length === 1, (self: number, that: number): number => self + that)\n *\n * assert.deepStrictEqual(sum(2, 3), 5)\n * assert.deepStrictEqual(pipe(2, sum(3)), 5)\n * ```\n *\n * @since 2.0.0\n */\n <DataLast extends (...args: Array<any>) => any, DataFirst extends (...args: Array<any>) => any>(\n isDataFirst: (args: IArguments) => boolean,\n body: DataFirst\n ): DataLast & DataFirst\n} = function(arity, body) {\n if (typeof arity === \"function\") {\n return function() {\n if (arity(arguments)) {\n // @ts-expect-error\n return body.apply(this, arguments)\n }\n return ((self: any) => body(self, ...arguments)) as any\n }\n }\n\n switch (arity) {\n case 0:\n case 1:\n throw new RangeError(`Invalid arity ${arity}`)\n\n case 2:\n return function(a, b) {\n if (arguments.length >= 2) {\n return body(a, b)\n }\n return function(self: any) {\n return body(self, a)\n }\n }\n\n case 3:\n return function(a, b, c) {\n if (arguments.length >= 3) {\n return body(a, b, c)\n }\n return function(self: any) {\n return body(self, a, b)\n }\n }\n\n case 4:\n return function(a, b, c, d) {\n if (arguments.length >= 4) {\n return body(a, b, c, d)\n }\n return function(self: any) {\n return body(self, a, b, c)\n }\n }\n\n case 5:\n return function(a, b, c, d, e) {\n if (arguments.length >= 5) {\n return body(a, b, c, d, e)\n }\n return function(self: any) {\n return body(self, a, b, c, d)\n }\n }\n\n default:\n return function() {\n if (arguments.length >= arity) {\n // @ts-expect-error\n return body.apply(this, arguments)\n }\n const args = arguments\n return function(self: any) {\n return body(self, ...args)\n }\n }\n }\n}\n/**\n * Apply a function to a given value.\n *\n * @param a - The value that the function will be applied to.\n * @param self - The function to be applied to a value.\n *\n * @example\n * ```ts\n * import { pipe, apply } from \"effect/Function\"\n * import { length } from \"effect/String\"\n *\n * assert.deepStrictEqual(pipe(length, apply(\"hello\")), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const apply = <A>(a: A) => <B>(self: (a: A) => B): B => self(a)\n\n/**\n * A lazy argument.\n *\n * @example\n * ```ts\n * import { LazyArg, constant } from \"effect/Function\"\n *\n * const constNull: LazyArg<null> = constant(null)\n * ```\n *\n * @since 2.0.0\n */\nexport interface LazyArg<A> {\n (): A\n}\n\n/**\n * @example\n * ```ts\n * import { FunctionN } from \"effect/Function\"\n *\n * const sum: FunctionN<[number, number], number> = (a, b) => a + b\n * ```\n *\n * @since 2.0.0\n */\nexport interface FunctionN<A extends ReadonlyArray<unknown>, B> {\n (...args: A): B\n}\n\n/**\n * The identity function, i.e. A function that returns its input argument.\n *\n * @param a - The input argument.\n *\n * @example\n * ```ts\n * import { identity } from \"effect/Function\"\n *\n * assert.deepStrictEqual(identity(5), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const identity = <A>(a: A): A => a\n\n/**\n * A function that ensures that the type of an expression matches some type,\n * without changing the resulting type of that expression.\n *\n * @example\n * ```ts\n * import { satisfies } from \"effect/Function\"\n *\n * const test1 = satisfies<number>()(5 as const)\n * //^? const test: 5\n * // @ts-expect-error\n * const test2 = satisfies<string>()(5)\n * //^? Argument of type 'number' is not assignable to parameter of type 'string'\n *\n * assert.deepStrictEqual(satisfies<number>()(5), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const satisfies = <A>() => <B extends A>(b: B) => b\n\n/**\n * Casts the result to the specified type.\n *\n * @param a - The value to be casted to the target type.\n *\n * @example\n * ```ts\n * import { unsafeCoerce, identity } from \"effect/Function\"\n *\n * assert.deepStrictEqual(unsafeCoerce, identity)\n * ```\n *\n * @since 2.0.0\n */\nexport const unsafeCoerce: <A, B>(a: A) => B = identity as any\n\n/**\n * Creates a constant value that never changes.\n *\n * This is useful when you want to pass a value to a higher-order function (a function that takes another function as its argument)\n * and want that inner function to always use the same value, no matter how many times it is called.\n *\n * @param value - The constant value to be returned.\n *\n * @example\n * ```ts\n * import { constant } from \"effect/Function\"\n *\n * const constNull = constant(null)\n *\n * assert.deepStrictEqual(constNull(), null)\n * assert.deepStrictEqual(constNull(), null)\n * ```\n *\n * @since 2.0.0\n */\nexport const constant = <A>(value: A): LazyArg<A> => () => value\n\n/**\n * A thunk that returns always `true`.\n *\n * @example\n * ```ts\n * import { constTrue } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constTrue(), true)\n * ```\n *\n * @since 2.0.0\n */\nexport const constTrue: LazyArg<boolean> = constant(true)\n\n/**\n * A thunk that returns always `false`.\n *\n * @example\n * ```ts\n * import { constFalse } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constFalse(), false)\n * ```\n *\n * @since 2.0.0\n */\nexport const constFalse: LazyArg<boolean> = constant(false)\n\n/**\n * A thunk that returns always `null`.\n *\n * @example\n * ```ts\n * import { constNull } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constNull(), null)\n * ```\n *\n * @since 2.0.0\n */\nexport const constNull: LazyArg<null> = constant(null)\n\n/**\n * A thunk that returns always `undefined`.\n *\n * @example\n * ```ts\n * import { constUndefined } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constUndefined(), undefined)\n * ```\n *\n * @since 2.0.0\n */\nexport const constUndefined: LazyArg<undefined> = constant(undefined)\n\n/**\n * A thunk that returns always `void`.\n *\n * @example\n * ```ts\n * import { constVoid } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constVoid(), undefined)\n * ```\n *\n * @since 2.0.0\n */\nexport const constVoid: LazyArg<void> = constUndefined\n\n/**\n * Reverses the order of arguments for a curried function.\n *\n * @param f - A curried function that takes multiple arguments.\n *\n * @example\n * ```ts\n * import { flip } from \"effect/Function\"\n *\n * const f = (a: number) => (b: string) => a - b.length\n *\n * assert.deepStrictEqual(flip(f)('aaa')(2), -1)\n * ```\n *\n * @since 2.0.0\n */\nexport const flip = <A extends Array<unknown>, B extends Array<unknown>, C>(\n f: (...a: A) => (...b: B) => C\n): (...b: B) => (...a: A) => C =>\n(...b) =>\n(...a) => f(...a)(...b)\n\n/**\n * Composes two functions, `ab` and `bc` into a single function that takes in an argument `a` of type `A` and returns a result of type `C`.\n * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.\n *\n * @param ab - A function that maps from `A` to `B`.\n * @param bc - A function that maps from `B` to `C`.\n *\n * @example\n * ```ts\n * import { compose } from \"effect/Function\"\n *\n * const increment = (n: number) => n + 1;\n * const square = (n: number) => n * n;\n *\n * assert.strictEqual(compose(increment, square)(2), 9);\n * ```\n *\n * @since 2.0.0\n */\nexport const compose: {\n /**\n * Composes two functions, `ab` and `bc` into a single function that takes in an argument `a` of type `A` and returns a result of type `C`.\n * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.\n *\n * @param ab - A function that maps from `A` to `B`.\n * @param bc - A function that maps from `B` to `C`.\n *\n * @example\n * ```ts\n * import { compose } from \"effect/Function\"\n *\n * const increment = (n: number) => n + 1;\n * const square = (n: number) => n * n;\n *\n * assert.strictEqual(compose(increment, square)(2), 9);\n * ```\n *\n * @since 2.0.0\n */\n <B, C>(bc: (b: B) => C): <A>(self: (a: A) => B) => (a: A) => C\n /**\n * Composes two functions, `ab` and `bc` into a single function that takes in an argument `a` of type `A` and returns a result of type `C`.\n * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.\n *\n * @param ab - A function that maps from `A` to `B`.\n * @param bc - A function that maps from `B` to `C`.\n *\n * @example\n * ```ts\n * import { compose } from \"effect/Function\"\n *\n * const increment = (n: number) => n + 1;\n * const square = (n: number) => n * n;\n *\n * assert.strictEqual(compose(increment, square)(2), 9);\n * ```\n *\n * @since 2.0.0\n */\n <A, B, C>(self: (a: A) => B, bc: (b: B) => C): (a: A) => C\n} = dual(2, <A, B, C>(ab: (a: A) => B, bc: (b: B) => C): (a: A) => C => (a) => bc(ab(a)))\n\n/**\n * The `absurd` function is a stub for cases where a value of type `never` is encountered in your code,\n * meaning that it should be impossible for this code to be executed.\n *\n * This function is particularly useful when it's necessary to specify that certain cases are impossible.\n *\n * @since 2.0.0\n */\nexport const absurd = <A>(_: never): A => {\n throw new Error(\"Called `absurd` function which should be uncallable\")\n}\n\n/**\n * Creates a tupled version of this function: instead of `n` arguments, it accepts a single tuple argument.\n *\n * @example\n * ```ts\n * import { tupled } from \"effect/Function\"\n *\n * const sumTupled = tupled((x: number, y: number): number => x + y)\n *\n * assert.deepStrictEqual(sumTupled([1, 2]), 3)\n * ```\n *\n * @since 2.0.0\n */\nexport const tupled = <A extends ReadonlyArray<unknown>, B>(f: (...a: A) => B): (a: A) => B => (a) => f(...a)\n\n/**\n * Inverse function of `tupled`\n *\n * @example\n * ```ts\n * import { untupled } from \"effect/Function\"\n *\n * const getFirst = untupled(<A, B>(tuple: [A, B]): A => tuple[0])\n *\n * assert.deepStrictEqual(getFirst(1, 2), 1)\n * ```\n *\n * @since 2.0.0\n */\nexport const untupled = <A extends ReadonlyArray<unknown>, B>(f: (a: A) => B): (...a: A) => B => (...a) => f(a)\n\n/**\n * Pipes the value of an expression into a pipeline of functions.\n *\n * **When to Use**\n *\n * This is useful in combination with data-last functions as a simulation of\n * methods:\n *\n * ```ts\n * as.map(f).filter(g)\n * ```\n *\n * becomes:\n *\n * ```ts\n * import { pipe, Array } from \"effect\"\n *\n * pipe(as, Array.map(f), Array.filter(g))\n * ```\n *\n * **Details**\n *\n * The `pipe` function is a utility that allows us to compose functions in a\n * readable and sequential manner. It takes the output of one function and\n * passes it as the input to the next function in the pipeline. This enables us\n * to build complex transformations by chaining multiple functions together.\n *\n * ```ts\n * import { pipe } from \"effect\"\n *\n * const result = pipe(input, func1, func2, ..., funcN)\n * ```\n *\n * In this syntax, `input` is the initial value, and `func1`, `func2`, ...,\n * `funcN` are the functions to be applied in sequence. The result of each\n * function becomes the input for the next function, and the final result is\n * returned.\n *\n * Here's an illustration of how `pipe` works:\n *\n * ```text\n * ┌───────┐ ┌───────┐ ┌───────┐ ┌───────┐ ┌───────┐ ┌────────┐\n * │ input │───►│ func1 │───►│ func2 │───►│ ... │───►│ funcN │───►│ result │\n * └───────┘ └───────┘ └───────┘ └───────┘ └───────┘ └────────┘\n * ```\n *\n * It's important to note that functions passed to `pipe` must have a **single\n * argument** because they are only called with a single argument.\n *\n * @example\n * ```ts\n * // Example: Chaining Arithmetic Operations\n * import { pipe } from \"effect\"\n *\n * // Define simple arithmetic operations\n * const increment = (x: number) => x + 1\n * const double = (x: number) => x * 2\n * const subtractTen = (x: number) => x - 10\n *\n * // Sequentially apply these operations using `pipe`\n * const result = pipe(5, increment, double, subtractTen)\n *\n * console.log(result)\n * // Output: 2\n * ```\n *\n * @since 2.0.0\n */\nexport function pipe<A>(a: A): A\nexport function pipe<A, B = never>(a: A, ab: (a: A) => B): B\nexport function pipe<A, B = never, C = never>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C\n): C\nexport function pipe<A, B = never, C = never, D = never>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D\n): D\nexport function pipe<A, B = never, C = never, D = never, E = never>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E\n): E\nexport function pipe<A, B = never, C = never, D = never, E = never, F = never>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F\n): F\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G\n): G\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H\n): H\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I\n): I\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J\n): J\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K\n): K\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L\n): L\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M\n): M\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N\n): N\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O\n): O\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P\n): P\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q\n): Q\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R\n): R\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => S\n): S\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never,\n T = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => S,\n st: (s: S) => T\n): T\nexport function pipe(\n a: unknown,\n ab?: Function,\n bc?: Function,\n cd?: Function,\n de?: Function,\n ef?: Function,\n fg?: Function,\n gh?: Function,\n hi?: Function\n): unknown {\n switch (arguments.length) {\n case 1:\n return a\n case 2:\n return ab!(a)\n case 3:\n return bc!(ab!(a))\n case 4:\n return cd!(bc!(ab!(a)))\n case 5:\n return de!(cd!(bc!(ab!(a))))\n case 6:\n return ef!(de!(cd!(bc!(ab!(a)))))\n case 7:\n return fg!(ef!(de!(cd!(bc!(ab!(a))))))\n case 8:\n return gh!(fg!(ef!(de!(cd!(bc!(ab!(a)))))))\n case 9:\n return hi!(gh!(fg!(ef!(de!(cd!(bc!(ab!(a))))))))\n default: {\n let ret = arguments[0]\n for (let i = 1; i < arguments.length; i++) {\n ret = arguments[i](ret)\n }\n return ret\n }\n }\n}\n\n/**\n * Performs left-to-right function composition. The first argument may have any arity, the remaining arguments must be unary.\n *\n * See also [`pipe`](#pipe).\n *\n * @example\n * ```ts\n * import { flow } from \"effect/Function\"\n *\n * const len = (s: string): number => s.length\n * const double = (n: number): number => n * 2\n *\n * const f = flow(len, double)\n *\n * assert.strictEqual(f('aaa'), 6)\n * ```\n *\n * @since 2.0.0\n */\nexport function flow<A extends ReadonlyArray<unknown>, B = never>(\n ab: (...a: A) => B\n): (...a: A) => B\nexport function flow<A extends ReadonlyArray<unknown>, B = never, C = never>(\n ab: (...a: A) => B,\n bc: (b: B) => C\n): (...a: A) => C\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never\n>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...a: A) => D\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E\n): (...a: A) => E\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F\n): (...a: A) => F\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G\n): (...a: A) => G\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H\n): (...a: A) => H\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I\n): (...a: A) => I\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J\n): (...a: A) => J\nexport function flow(\n ab: Function,\n bc?: Function,\n cd?: Function,\n de?: Function,\n ef?: Function,\n fg?: Function,\n gh?: Function,\n hi?: Function,\n ij?: Function\n): unknown {\n switch (arguments.length) {\n case 1:\n return ab\n case 2:\n return function(this: unknown) {\n return bc!(ab.apply(this, arguments))\n }\n case 3:\n return function(this: unknown) {\n return cd!(bc!(ab.apply(this, arguments)))\n }\n case 4:\n return function(this: unknown) {\n return de!(cd!(bc!(ab.apply(this, arguments))))\n }\n case 5:\n return function(this: unknown) {\n return ef!(de!(cd!(bc!(ab.apply(this, arguments)))))\n }\n case 6:\n return function(this: unknown) {\n return fg!(ef!(de!(cd!(bc!(ab.apply(this, arguments))))))\n }\n case 7:\n return function(this: unknown) {\n return gh!(fg!(ef!(de!(cd!(bc!(ab.apply(this, arguments)))))))\n }\n case 8:\n return function(this: unknown) {\n return hi!(gh!(fg!(ef!(de!(cd!(bc!(ab.apply(this, arguments))))))))\n }\n case 9:\n return function(this: unknown) {\n return ij!(hi!(gh!(fg!(ef!(de!(cd!(bc!(ab.apply(this, arguments)))))))))\n }\n }\n return\n}\n\n/**\n * Type hole simulation.\n *\n * @since 2.0.0\n */\nexport const hole: <T>() => T = unsafeCoerce(absurd)\n\n/**\n * The SK combinator, also known as the \"S-K combinator\" or \"S-combinator\", is a fundamental combinator in the\n * lambda calculus and the SKI combinator calculus.\n *\n * This function is useful for discarding the first argument passed to it and returning the second argument.\n *\n * @param _ - The first argument to be discarded.\n * @param b - The second argument to be returned.\n *\n * @example\n * ```ts\n * import { SK } from \"effect/Function\";\n *\n * assert.deepStrictEqual(SK(0, \"hello\"), \"hello\")\n * ```\n *\n * @since 2.0.0\n */\nexport const SK = <A, B>(_: A, b: B): B => b\n","/**\n * @since 2.0.0\n */\n\nimport * as Equivalence from \"./Equivalence.js\"\nimport type { LazyArg } from \"./Function.js\"\nimport { constNull, constUndefined, dual, identity } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\nimport type { Inspectable } from \"./Inspectable.js\"\nimport * as doNotation from \"./internal/doNotation.js\"\nimport * as either from \"./internal/either.js\"\nimport type { Option } from \"./Option.js\"\nimport type { Pipeable } from \"./Pipeable.js\"\nimport type { Predicate, Refinement } from \"./Predicate.js\"\nimport { isFunction } from \"./Predicate.js\"\nimport type { Covariant, NoInfer, NotFunction } from \"./Types.js\"\nimport type * as Unify from \"./Unify.js\"\nimport * as Gen from \"./Utils.js\"\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport type Either<R, L = never> = Left<L, R> | Right<L, R>\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport const TypeId: unique symbol = either.TypeId\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport type TypeId = typeof TypeId\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Left<out L, out R> extends Pipeable, Inspectable {\n readonly _tag: \"Left\"\n readonly _op: \"Left\"\n readonly left: L\n readonly [TypeId]: {\n readonly _R: Covariant<R>\n readonly _L: Covariant<L>\n }\n [Unify.typeSymbol]?: unknown\n [Unify.unifySymbol]?: EitherUnify<this>\n [Unify.ignoreSymbol]?: EitherUnifyIgnore\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Right<out L, out R> extends Pipeable, Inspectable {\n readonly _tag: \"Right\"\n readonly _op: \"Right\"\n readonly right: R\n readonly [TypeId]: {\n readonly _R: Covariant<R>\n readonly _L: Covariant<L>\n }\n [Unify.typeSymbol]?: unknown\n [Unify.unifySymbol]?: EitherUnify<this>\n [Unify.ignoreSymbol]?: EitherUnifyIgnore\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface EitherUnify<A extends { [Unify.typeSymbol]?: any }> {\n Either?: () => A[Unify.typeSymbol] extends Either<infer R0, infer L0> | infer _ ? Either<R0, L0> : never\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface EitherUnifyIgnore {}\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface EitherTypeLambda extends TypeLambda {\n readonly type: Either<this[\"Target\"], this[\"Out1\"]>\n}\n\n/**\n * @since 2.0.0\n */\nexport declare namespace Either {\n /**\n * @since 2.0.0\n * @category type-level\n */\n export type Left<T extends Either<any, any>> = [T] extends [Either<infer _A, infer _E>] ? _E : never\n /**\n * @since 2.0.0\n * @category type-level\n */\n export type Right<T extends Either<any, any>> = [T] extends [Either<infer _A, infer _E>] ? _A : never\n}\n\n/**\n * Constructs a new `Either` holding a `Right` value. This usually represents a successful value due to the right bias\n * of this structure.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const right: <R>(right: R) => Either<R> = either.right\n\n/**\n * Constructs a new `Either` holding a `Left` value. This usually represents a failure, due to the right-bias of this\n * structure.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const left: <L>(left: L) => Either<never, L> = either.left\n\n/**\n * Takes a lazy default and a nullable value, if the value is not nully (`null` or `undefined`), turn it into a `Right`, if the value is nully use\n * the provided default as a `Left`.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromNullable(1, () => 'fallback'), Either.right(1))\n * assert.deepStrictEqual(Either.fromNullable(null, () => 'fallback'), Either.left('fallback'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const fromNullable: {\n /**\n * Takes a lazy default and a nullable value, if the value is not nully (`null` or `undefined`), turn it into a `Right`, if the value is nully use\n * the provided default as a `Left`.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromNullable(1, () => 'fallback'), Either.right(1))\n * assert.deepStrictEqual(Either.fromNullable(null, () => 'fallback'), Either.left('fallback'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <R, L>(onNullable: (right: R) => L): (self: R) => Either<NonNullable<R>, L>\n /**\n * Takes a lazy default and a nullable value, if the value is not nully (`null` or `undefined`), turn it into a `Right`, if the value is nully use\n * the provided default as a `Left`.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromNullable(1, () => 'fallback'), Either.right(1))\n * assert.deepStrictEqual(Either.fromNullable(null, () => 'fallback'), Either.left('fallback'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <R, L>(self: R, onNullable: (right: R) => L): Either<NonNullable<R>, L>\n} = dual(\n 2,\n <R, L>(self: R, onNullable: (right: R) => L): Either<NonNullable<R>, L> =>\n self == null ? left(onNullable(self)) : right(self as NonNullable<R>)\n)\n\n/**\n * @example\n * ```ts\n * import { Either, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromOption(Option.some(1), () => 'error'), Either.right(1))\n * assert.deepStrictEqual(Either.fromOption(Option.none(), () => 'error'), Either.left('error'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const fromOption: {\n /**\n * @example\n * ```ts\n * import { Either, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromOption(Option.some(1), () => 'error'), Either.right(1))\n * assert.deepStrictEqual(Either.fromOption(Option.none(), () => 'error'), Either.left('error'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <L>(onNone: () => L): <R>(self: Option<R>) => Either<R, L>\n /**\n * @example\n * ```ts\n * import { Either, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromOption(Option.some(1), () => 'error'), Either.right(1))\n * assert.deepStrictEqual(Either.fromOption(Option.none(), () => 'error'), Either.left('error'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <R, L>(self: Option<R>, onNone: () => L): Either<R, L>\n} = either.fromOption\n\nconst try_: {\n <R, L>(\n options: {\n readonly try: LazyArg<R>\n readonly catch: (error: unknown) => L\n }\n ): Either<R, L>\n <R>(evaluate: LazyArg<R>): Either<R, unknown>\n} = (<R, L>(\n evaluate: LazyArg<R> | {\n readonly try: LazyArg<R>\n readonly catch: (error: unknown) => L\n }\n) => {\n if (isFunction(evaluate)) {\n try {\n return right(evaluate())\n } catch (e) {\n return left(e)\n }\n } else {\n try {\n return right(evaluate.try())\n } catch (e) {\n return left(evaluate.catch(e))\n }\n }\n}) as any\n\nexport {\n /**\n * Imports a synchronous side-effect into a pure `Either` value, translating any\n * thrown exceptions into typed failed eithers creating with `Either.left`.\n *\n * @category constructors\n * @since 2.0.0\n */\n try_ as try\n}\n\n/**\n * Tests if a value is a `Either`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.isEither(Either.right(1)), true)\n * assert.deepStrictEqual(Either.isEither(Either.left(\"a\")), true)\n * assert.deepStrictEqual(Either.isEither({ right: 1 }), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isEither: (input: unknown) => input is Either<unknown, unknown> = either.isEither\n\n/**\n * Determine if a `Either` is a `Left`.\n *\n * @param self - The `Either` to check.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.isLeft(Either.right(1)), false)\n * assert.deepStrictEqual(Either.isLeft(Either.left(\"a\")), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isLeft: <R, L>(self: Either<R, L>) => self is Left<L, R> = either.isLeft\n\n/**\n * Determine if a `Either` is a `Right`.\n *\n * @param self - The `Either` to check.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.isRight(Either.right(1)), true)\n * assert.deepStrictEqual(Either.isRight(Either.left(\"a\")), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isRight: <R, L>(self: Either<R, L>) => self is Right<L, R> = either.isRight\n\n/**\n * Converts a `Either` to an `Option` discarding the `Left`.\n *\n * @example\n * ```ts\n * import { Either, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getRight(Either.right('ok')), Option.some('ok'))\n * assert.deepStrictEqual(Either.getRight(Either.left('err')), Option.none())\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getRight: <R, L>(self: Either<R, L>) => Option<R> = either.getRight\n\n/**\n * Converts a `Either` to an `Option` discarding the value.\n *\n * @example\n * ```ts\n * import { Either, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getLeft(Either.right('ok')), Option.none())\n * assert.deepStrictEqual(Either.getLeft(Either.left('err')), Option.some('err'))\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getLeft: <R, L>(self: Either<R, L>) => Option<L> = either.getLeft\n\n/**\n * @category equivalence\n * @since 2.0.0\n */\nexport const getEquivalence = <R, L>({ left, right }: {\n right: Equivalence.Equivalence<R>\n left: Equivalence.Equivalence<L>\n}): Equivalence.Equivalence<Either<R, L>> =>\n Equivalence.make((x, y) =>\n isLeft(x) ?\n isLeft(y) && left(x.left, y.left) :\n isRight(y) && right(x.right, y.right)\n )\n\n/**\n * @category mapping\n * @since 2.0.0\n */\nexport const mapBoth: {\n /**\n * @category mapping\n * @since 2.0.0\n */\n <L, L2, R, R2>(\n options: {\n readonly onLeft: (left: L) => L2\n readonly onRight: (right: R) => R2\n }\n ): (self: Either<R, L>) => Either<R2, L2>\n /**\n * @category mapping\n * @since 2.0.0\n */\n <L, R, L2, R2>(\n self: Either<R, L>,\n options: {\n readonly onLeft: (left: L) => L2\n readonly onRight: (right: R) => R2\n }\n ): Either<R2, L2>\n} = dual(\n 2,\n <L, R, L2, R2>(self: Either<R, L>, { onLeft, onRight }: {\n readonly onLeft: (left: L) => L2\n readonly onRight: (right: R) => R2\n }): Either<R2, L2> => isLeft(self) ? left(onLeft(self.left)) : right(onRight(self.right))\n)\n\n/**\n * Maps the `Left` side of an `Either` value to a new `Either` value.\n *\n * @param self - The input `Either` value to map.\n * @param f - A transformation function to apply to the `Left` value of the input `Either`.\n *\n * @category mapping\n * @since 2.0.0\n */\nexport const mapLeft: {\n /**\n * Maps the `Left` side of an `Either` value to a new `Either` value.\n *\n * @param self - The input `Either` value to map.\n * @param f - A transformation function to apply to the `Left` value of the input `Either`.\n *\n * @category mapping\n * @since 2.0.0\n */\n <L, L2>(f: (left: L) => L2): <R>(self: Either<R, L>) => Either<R, L2>\n /**\n * Maps the `Left` side of an `Either` value to a new `Either` value.\n *\n * @param self - The input `Either` value to map.\n * @param f - A transformation function to apply to the `Left` value of the input `Either`.\n *\n * @category mapping\n * @since 2.0.0\n */\n <R, L, L2>(self: Either<R, L>, f: (left: L) => L2): Either<R, L2>\n} = dual(\n 2,\n <R, L1, L2>(self: Either<R, L1>, f: (left: L1) => L2): Either<R, L2> =>\n isLeft(self) ? left(f(self.left)) : right(self.right)\n)\n\n/**\n * Maps the `Right` side of an `Either` value to a new `Either` value.\n *\n * @param self - An `Either` to map\n * @param f - The function to map over the value of the `Either`\n *\n * @category mapping\n * @since 2.0.0\n */\nexport const map: {\n /**\n * Maps the `Right` side of an `Either` value to a new `Either` value.\n *\n * @param self - An `Either` to map\n * @param f - The function to map over the value of the `Either`\n *\n * @category mapping\n * @since 2.0.0\n */\n <R, R2>(f: (right: R) => R2): <L>(self: Either<R, L>) => Either<R2, L>\n /**\n * Maps the `Right` side of an `Either` value to a new `Either` value.\n *\n * @param self - An `Either` to map\n * @param f - The function to map over the value of the `Either`\n *\n * @category mapping\n * @since 2.0.0\n */\n <R, L, R2>(self: Either<R, L>, f: (right: R) => R2): Either<R2, L>\n} = dual(\n 2,\n <R1, L, R2>(self: Either<R1, L>, f: (right: R1) => R2): Either<R2, L> =>\n isRight(self) ? right(f(self.right)) : left(self.left)\n)\n\n/**\n * Takes two functions and an `Either` value, if the value is a `Left` the inner value is applied to the `onLeft function,\n * if the value is a `Right` the inner value is applied to the `onRight` function.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const onLeft = (strings: ReadonlyArray<string>): string => `strings: ${strings.join(', ')}`\n *\n * const onRight = (value: number): string => `Ok: ${value}`\n *\n * assert.deepStrictEqual(pipe(Either.right(1), Either.match({ onLeft, onRight })), 'Ok: 1')\n * assert.deepStrictEqual(\n * pipe(Either.left(['string 1', 'string 2']), Either.match({ onLeft, onRight })),\n * 'strings: string 1, string 2'\n * )\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\nexport const match: {\n /**\n * Takes two functions and an `Either` value, if the value is a `Left` the inner value is applied to the `onLeft function,\n * if the value is a `Right` the inner value is applied to the `onRight` function.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const onLeft = (strings: ReadonlyArray<string>): string => `strings: ${strings.join(', ')}`\n *\n * const onRight = (value: number): string => `Ok: ${value}`\n *\n * assert.deepStrictEqual(pipe(Either.right(1), Either.match({ onLeft, onRight })), 'Ok: 1')\n * assert.deepStrictEqual(\n * pipe(Either.left(['string 1', 'string 2']), Either.match({ onLeft, onRight })),\n * 'strings: string 1, string 2'\n * )\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <L, B, R, C = B>(\n options: {\n readonly onLeft: (left: L) => B\n readonly onRight: (right: R) => C\n }\n ): (self: Either<R, L>) => B | C\n /**\n * Takes two functions and an `Either` value, if the value is a `Left` the inner value is applied to the `onLeft function,\n * if the value is a `Right` the inner value is applied to the `onRight` function.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const onLeft = (strings: ReadonlyArray<string>): string => `strings: ${strings.join(', ')}`\n *\n * const onRight = (value: number): string => `Ok: ${value}`\n *\n * assert.deepStrictEqual(pipe(Either.right(1), Either.match({ onLeft, onRight })), 'Ok: 1')\n * assert.deepStrictEqual(\n * pipe(Either.left(['string 1', 'string 2']), Either.match({ onLeft, onRight })),\n * 'strings: string 1, string 2'\n * )\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <R, L, B, C = B>(\n self: Either<R, L>,\n options: {\n readonly onLeft: (left: L) => B\n readonly onRight: (right: R) => C\n }\n ): B | C\n} = dual(\n 2,\n <R, L, B, C = B>(self: Either<R, L>, { onLeft, onRight }: {\n readonly onLeft: (left: L) => B\n readonly onRight: (right: R) => C\n }): B | C => isLeft(self) ? onLeft(self.left) : onRight(self.right)\n)\n\n/**\n * Transforms a `Predicate` function into a `Right` of the input value if the predicate returns `true`\n * or `Left` of the result of the provided function if the predicate returns false\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * 1,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * 0,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @category lifting\n * @since 3.4.0\n */\nexport const liftPredicate: {\n /**\n * Transforms a `Predicate` function into a `Right` of the input value if the predicate returns `true`\n * or `Left` of the result of the provided function if the predicate returns false\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * 1,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * 0,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @category lifting\n * @since 3.4.0\n */\n <A, B extends A, E>(refinement: Refinement<NoInfer<A>, B>, orLeftWith: (a: NoInfer<A>) => E): (a: A) => Either<B, E>\n /**\n * Transforms a `Predicate` function into a `Right` of the input value if the predicate returns `true`\n * or `Left` of the result of the provided function if the predicate returns false\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * 1,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * 0,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @category lifting\n * @since 3.4.0\n */\n <A, E>(predicate: Predicate<NoInfer<A>>, orLeftWith: (a: NoInfer<A>) => E): (a: A) => Either<A, E>\n /**\n * Transforms a `Predicate` function into a `Right` of the input value if the predicate returns `true`\n * or `Left` of the result of the provided function if the predicate returns false\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * 1,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * 0,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @category lifting\n * @since 3.4.0\n */\n <A, E, B extends A>(self: A, refinement: Refinement<A, B>, orLeftWith: (a: A) => E): Either<B, E>\n /**\n * Transforms a `Predicate` function into a `Right` of the input value if the predicate returns `true`\n * or `Left` of the result of the provided function if the predicate returns false\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * 1,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * 0,\n * Either.liftPredicate(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @category lifting\n * @since 3.4.0\n */\n <A, E>(\n self: A,\n predicate: Predicate<NoInfer<A>>,\n orLeftWith: (a: NoInfer<A>) => E\n ): Either<A, E>\n} = dual(\n 3,\n <A, E>(a: A, predicate: Predicate<A>, orLeftWith: (a: A) => E): Either<A, E> =>\n predicate(a) ? right(a) : left(orLeftWith(a))\n)\n\n/**\n * Filter the right value with the provided function.\n * If the predicate fails, set the left value with the result of the provided function.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(1),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(0),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @since 2.0.0\n * @category filtering & conditionals\n */\nexport const filterOrLeft: {\n /**\n * Filter the right value with the provided function.\n * If the predicate fails, set the left value with the result of the provided function.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(1),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(0),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @since 2.0.0\n * @category filtering & conditionals\n */\n <R, B extends R, L2>(\n refinement: Refinement<NoInfer<R>, B>,\n orLeftWith: (right: NoInfer<R>) => L2\n ): <L>(self: Either<R, L>) => Either<B, L2 | L>\n /**\n * Filter the right value with the provided function.\n * If the predicate fails, set the left value with the result of the provided function.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(1),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(0),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @since 2.0.0\n * @category filtering & conditionals\n */\n <R, L2>(\n predicate: Predicate<NoInfer<R>>,\n orLeftWith: (right: NoInfer<R>) => L2\n ): <L>(self: Either<R, L>) => Either<R, L2 | L>\n /**\n * Filter the right value with the provided function.\n * If the predicate fails, set the left value with the result of the provided function.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(1),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(0),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @since 2.0.0\n * @category filtering & conditionals\n */\n <R, L, B extends R, L2>(\n self: Either<R, L>,\n refinement: Refinement<R, B>,\n orLeftWith: (right: R) => L2\n ): Either<B, L | L2>\n /**\n * Filter the right value with the provided function.\n * If the predicate fails, set the left value with the result of the provided function.\n *\n * @example\n * ```ts\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(1),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(0),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @since 2.0.0\n * @category filtering & conditionals\n */\n <R, L, E2>(self: Either<R, L>, predicate: Predicate<R>, orLeftWith: (right: R) => E2): Either<R, L | E2>\n} = dual(3, <R, L, E2>(\n self: Either<R, L>,\n predicate: Predicate<R>,\n orLeftWith: (right: R) => E2\n): Either<R, L | E2> => flatMap(self, (r) => predicate(r) ? right(r) : left(orLeftWith(r))))\n\n/**\n * @category getters\n * @since 2.0.0\n */\nexport const merge: <R, L>(self: Either<R, L>) => L | R = match({\n onLeft: identity,\n onRight: identity\n})\n\n/**\n * Returns the wrapped value if it's a `Right` or a default value if is a `Left`.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrElse(Either.right(1), (error) => error + \"!\"), 1)\n * assert.deepStrictEqual(Either.getOrElse(Either.left(\"not a number\"), (error) => error + \"!\"), \"not a number!\")\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrElse: {\n /**\n * Returns the wrapped value if it's a `Right` or a default value if is a `Left`.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrElse(Either.right(1), (error) => error + \"!\"), 1)\n * assert.deepStrictEqual(Either.getOrElse(Either.left(\"not a number\"), (error) => error + \"!\"), \"not a number!\")\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <L, R2>(onLeft: (left: L) => R2): <R>(self: Either<R, L>) => R2 | R\n /**\n * Returns the wrapped value if it's a `Right` or a default value if is a `Left`.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrElse(Either.right(1), (error) => error + \"!\"), 1)\n * assert.deepStrictEqual(Either.getOrElse(Either.left(\"not a number\"), (error) => error + \"!\"), \"not a number!\")\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <R, L, R2>(self: Either<R, L>, onLeft: (left: L) => R2): R | R2\n} = dual(\n 2,\n <R, L, B>(self: Either<R, L>, onLeft: (left: L) => B): R | B => isLeft(self) ? onLeft(self.left) : self.right\n)\n\n/**\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrNull(Either.right(1)), 1)\n * assert.deepStrictEqual(Either.getOrNull(Either.left(\"a\")), null)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrNull: <R, L>(self: Either<R, L>) => R | null = getOrElse(constNull)\n\n/**\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrUndefined(Either.right(1)), 1)\n * assert.deepStrictEqual(Either.getOrUndefined(Either.left(\"a\")), undefined)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrUndefined: <R, L>(self: Either<R, L>) => R | undefined = getOrElse(constUndefined)\n\n/**\n * Extracts the value of an `Either` or throws if the `Either` is `Left`.\n *\n * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.\n *\n * @param self - The `Either` to extract the value from.\n * @param onLeft - A function that will be called if the `Either` is `Left`. It returns the error to be thrown.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Either.getOrThrowWith(Either.right(1), () => new Error('Unexpected Left')),\n * 1\n * )\n * assert.throws(() => Either.getOrThrowWith(Either.left(\"error\"), () => new Error('Unexpected Left')))\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrThrowWith: {\n /**\n * Extracts the value of an `Either` or throws if the `Either` is `Left`.\n *\n * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.\n *\n * @param self - The `Either` to extract the value from.\n * @param onLeft - A function that will be called if the `Either` is `Left`. It returns the error to be thrown.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Either.getOrThrowWith(Either.right(1), () => new Error('Unexpected Left')),\n * 1\n * )\n * assert.throws(() => Either.getOrThrowWith(Either.left(\"error\"), () => new Error('Unexpected Left')))\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <L>(onLeft: (left: L) => unknown): <A>(self: Either<A, L>) => A\n /**\n * Extracts the value of an `Either` or throws if the `Either` is `Left`.\n *\n * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.\n *\n * @param self - The `Either` to extract the value from.\n * @param onLeft - A function that will be called if the `Either` is `Left`. It returns the error to be thrown.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Either.getOrThrowWith(Either.right(1), () => new Error('Unexpected Left')),\n * 1\n * )\n * assert.throws(() => Either.getOrThrowWith(Either.left(\"error\"), () => new Error('Unexpected Left')))\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <R, L>(self: Either<R, L>, onLeft: (left: L) => unknown): R\n} = dual(2, <R, L>(self: Either<R, L>, onLeft: (left: L) => unknown): R => {\n if (isRight(self)) {\n return self.right\n }\n throw onLeft(self.left)\n})\n\n/**\n * Extracts the value of an `Either` or throws if the `Either` is `Left`.\n *\n * The thrown error is a default error. To configure the error thrown, see {@link getOrThrowWith}.\n *\n * @param self - The `Either` to extract the value from.\n * @throws `Error(\"getOrThrow called on a Left\")`\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrThrow(Either.right(1)), 1)\n * assert.throws(() => Either.getOrThrow(Either.left(\"error\")))\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrThrow: <R, L>(self: Either<R, L>) => R = getOrThrowWith(() =>\n new Error(\"getOrThrow called on a Left\")\n)\n\n/**\n * Returns `self` if it is a `Right` or `that` otherwise.\n *\n * @param self - The input `Either` value to check and potentially return.\n * @param that - A function that takes the error value from `self` (if it's a `Left`) and returns a new `Either` value.\n *\n * @category error handling\n * @since 2.0.0\n */\nexport const orElse: {\n /**\n * Returns `self` if it is a `Right` or `that` otherwise.\n *\n * @param self - The input `Either` value to check and potentially return.\n * @param that - A function that takes the error value from `self` (if it's a `Left`) and returns a new `Either` value.\n *\n * @category error handling\n * @since 2.0.0\n */\n <L, R2, L2>(that: (left: L) => Either<R2, L2>): <R>(self: Either<R, L>) => Either<R | R2, L2>\n /**\n * Returns `self` if it is a `Right` or `that` otherwise.\n *\n * @param self - The input `Either` value to check and potentially return.\n * @param that - A function that takes the error value from `self` (if it's a `Left`) and returns a new `Either` value.\n *\n * @category error handling\n * @since 2.0.0\n */\n <R, L, R2, L2>(self: Either<R, L>, that: (left: L) => Either<R2, L2>): Either<R | R2, L2>\n} = dual(\n 2,\n <R1, L1, R2, L2>(self: Either<R1, L1>, that: (left: L1) => Either<R2, L2>): Either<R1 | R2, L2> =>\n isLeft(self) ? that(self.left) : right(self.right)\n)\n\n/**\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatMap: {\n /**\n * @category sequencing\n * @since 2.0.0\n */\n <R, R2, L2>(f: (right: R) => Either<R2, L2>): <L>(self: Either<R, L>) => Either<R2, L | L2>\n /**\n * @category sequencing\n * @since 2.0.0\n */\n <R, L, R2, L2>(self: Either<R, L>, f: (right: R) => Either<R2, L2>): Either<R2, L | L2>\n} = dual(\n 2,\n <R1, L1, R2, L2>(self: Either<R1, L1>, f: (right: R1) => Either<R2, L2>): Either<R2, L1 | L2> =>\n isLeft(self) ? left(self.left) : f(self.right)\n)\n\n/**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const andThen: {\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, R2, L2>(f: (right: R) => Either<R2, L2>): <L>(self: Either<R, L>) => Either<R2, L | L2>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R2, L2>(f: Either<R2, L2>): <L, R1>(self: Either<R1, L>) => Either<R2, L | L2>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, R2>(f: (right: R) => R2): <L>(self: Either<R, L>) => Either<R2, L>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R2>(right: NotFunction<R2>): <R1, L>(self: Either<R1, L>) => Either<R2, L>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, L, R2, L2>(self: Either<R, L>, f: (right: R) => Either<R2, L2>): Either<R2, L | L2>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, L, R2, L2>(self: Either<R, L>, f: Either<R2, L2>): Either<R2, L | L2>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, L, R2>(self: Either<R, L>, f: (right: R) => R2): Either<R2, L>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, L, R2>(self: Either<R, L>, f: NotFunction<R2>): Either<R2, L>\n} = dual(\n 2,\n <R, L, R2, L2>(self: Either<R, L>, f: (right: R) => Either<R2, L2> | Either<R2, L2>): Either<R2, L | L2> =>\n flatMap(self, (a) => {\n const b = isFunction(f) ? f(a) : f\n return isEither(b) ? b : right(b)\n })\n)\n\n/**\n * @category zipping\n * @since 2.0.0\n */\nexport const zipWith: {\n /**\n * @category zipping\n * @since 2.0.0\n */\n <R2, L2, R, B>(that: Either<R2, L2>, f: (right: R, right2: R2) => B): <L>(self: Either<R, L>) => Either<B, L2 | L>\n /**\n * @category zipping\n * @since 2.0.0\n */\n <R, L, R2, L2, B>(self: Either<R, L>, that: Either<R2, L2>, f: (right: R, right2: R2) => B): Either<B, L | L2>\n} = dual(\n 3,\n <R, L, R2, L2, B>(self: Either<R, L>, that: Either<R2, L2>, f: (right: R, right2: R2) => B): Either<B, L | L2> =>\n flatMap(self, (r) => map(that, (r2) => f(r, r2)))\n)\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const ap: {\n /**\n * @category combining\n * @since 2.0.0\n */\n <R, L2>(that: Either<R, L2>): <R2, L>(self: Either<(right: R) => R2, L>) => Either<R2, L | L2>\n /**\n * @category combining\n * @since 2.0.0\n */\n <R, R2, L, L2>(self: Either<(right: R) => R2, L>, that: Either<R, L2>): Either<R2, L | L2>\n} = dual(\n 2,\n <R, R2, L, L2>(self: Either<(right: R) => R2, L>, that: Either<R, L2>): Either<R2, L | L2> =>\n zipWith(self, that, (f, a) => f(a))\n)\n\n/**\n * Takes a structure of `Either`s and returns an `Either` of values with the same structure.\n *\n * - If a tuple is supplied, then the returned `Either` will contain a tuple with the same length.\n * - If a struct is supplied, then the returned `Either` will contain a struct with the same keys.\n * - If an iterable is supplied, then the returned `Either` will contain an array.\n *\n * @param fields - the struct of `Either`s to be sequenced.\n *\n * @example\n * ```ts\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.all([Either.right(1), Either.right(2)]), Either.right([1, 2]))\n * assert.deepStrictEqual(Either.all({ right: Either.right(1), b: Either.right(\"hello\") }), Either.right({ right: 1, b: \"hello\" }))\n * assert.deepStrictEqual(Either.all({ right: Either.right(1), b: Either.left(\"error\") }), Either.left(\"error\"))\n * ```\n *\n * @category combining\n * @since 2.0.0\n */\n// @ts-expect-error\nexport const all: <const I extends Iterable<Either<any, any>> | Record<string, Either<any, any>>>(\n input: I\n) => [I] extends [ReadonlyArray<Either<any, any>>] ? Either<\n { -readonly [K in keyof I]: [I[K]] extends [Either<infer R, any>] ? R : never },\n I[number] extends never ? never : [I[number]] extends [Either<any, infer L>] ? L : never\n >\n : [I] extends [Iterable<Either<infer R, infer L>>] ? Either<Array<R>, L>\n : Either<\n { -readonly [K in keyof I]: [I[K]] extends [Either<infer R, any>] ? R : never },\n I[keyof I] extends never ? never : [I[keyof I]] extends [Either<any, infer L>] ? L : never\n > = (\n input: Iterable<Either<any, any>> | Record<string, Either<any, any>>\n ): Either<any, any> => {\n if (Symbol.iterator in input) {\n const out: Array<Either<any, any>> = []\n for (const e of (input as Iterable<Either<any, any>>)) {\n if (isLeft(e)) {\n return e\n }\n out.push(e.right)\n }\n return right(out)\n }\n\n const out: Record<string, any> = {}\n for (const key of Object.keys(input)) {\n const e = input[key]\n if (isLeft(e)) {\n return e\n }\n out[key] = e.right\n }\n return right(out)\n }\n\n/**\n * Returns an `Either` that swaps the error/success cases. This allows you to\n * use all methods on the error channel, possibly before flipping back.\n *\n * @since 2.0.0\n * @category mapping\n */\nexport const flip = <R, L>(self: Either<R, L>): Either<L, R> => isLeft(self) ? right(self.left) : left(self.right)\n\nconst adapter = Gen.adapter<EitherTypeLambda>()\n\n/**\n * @category generators\n * @since 2.0.0\n */\nexport const gen: Gen.Gen<EitherTypeLambda, Gen.Adapter<EitherTypeLambda>> = (...args) => {\n const f = (args.length === 1)\n ? args[0]\n : args[1].bind(args[0])\n const iterator = f(adapter)\n let state: IteratorYieldResult<any> | IteratorReturnResult<any> = iterator.next()\n if (state.done) {\n return right(state.value) as any\n } else {\n let current = state.value\n if (Gen.isGenKind(current)) {\n current = current.value\n } else {\n current = Gen.yieldWrapGet(current)\n }\n if (isLeft(current)) {\n return current\n }\n while (!state.done) {\n state = iterator.next(current.right as never)\n if (!state.done) {\n current = state.value\n if (Gen.isGenKind(current)) {\n current = current.value\n } else {\n current = Gen.yieldWrapGet(current)\n }\n if (isLeft(current)) {\n return current\n }\n }\n }\n return right(state.value)\n }\n}\n\n// -------------------------------------------------------------------------------------\n// do notation\n// -------------------------------------------------------------------------------------\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @see {@link bind}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\nexport const Do: Either<{}> = right({})\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\nexport const bind: {\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <N extends string, A extends object, B, L2>(\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => Either<B, L2>\n ): <L1>(self: Either<A, L1>) => Either<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, L1 | L2>\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <A extends object, L1, N extends string, B, L2>(\n self: Either<A, L1>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => Either<B, L2>\n ): Either<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, L1 | L2>\n} = doNotation.bind<EitherTypeLambda>(map, flatMap)\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\nexport const bindTo: {\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <N extends string>(name: N): <R, L>(self: Either<R, L>) => Either<{ [K in N]: R }, L>\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <R, L, N extends string>(self: Either<R, L>, name: N): Either<{ [K in N]: R }, L>\n} = doNotation.bindTo<EitherTypeLambda>(map)\n\nconst let_: {\n <N extends string, R extends object, B>(\n name: Exclude<N, keyof R>,\n f: (r: NoInfer<R>) => B\n ): <L>(self: Either<R, L>) => Either<{ [K in N | keyof R]: K extends keyof R ? R[K] : B }, L>\n <R extends object, L, N extends string, B>(\n self: Either<R, L>,\n name: Exclude<N, keyof R>,\n f: (r: NoInfer<R>) => B\n ): Either<{ [K in N | keyof R]: K extends keyof R ? R[K] : B }, L>\n} = doNotation.let_<EitherTypeLambda>(map)\n\nexport {\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link bind}\n *\n * @example\n * ```ts\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n *\n * ```\n * @category do notation\n * @since 2.0.0\n */\n let_ as let\n}\n","/**\n * This module provides an implementation of the `Equivalence` type class, which defines a binary relation\n * that is reflexive, symmetric, and transitive. In other words, it defines a notion of equivalence between values of a certain type.\n * These properties are also known in mathematics as an \"equivalence relation\".\n *\n * @since 2.0.0\n */\nimport { dual } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\n\n/**\n * @category type class\n * @since 2.0.0\n */\nexport interface Equivalence<in A> {\n (self: A, that: A): boolean\n}\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface EquivalenceTypeLambda extends TypeLambda {\n readonly type: Equivalence<this[\"Target\"]>\n}\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const make = <A>(isEquivalent: (self: A, that: A) => boolean): Equivalence<A> => (self: A, that: A): boolean =>\n self === that || isEquivalent(self, that)\n\nconst isStrictEquivalent = (x: unknown, y: unknown) => x === y\n\n/**\n * Return an `Equivalence` that uses strict equality (===) to compare values.\n *\n * @since 2.0.0\n * @category constructors\n */\nexport const strict: <A>() => Equivalence<A> = () => isStrictEquivalent\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const string: Equivalence<string> = strict()\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const number: Equivalence<number> = strict()\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const boolean: Equivalence<boolean> = strict()\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const bigint: Equivalence<bigint> = strict()\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const symbol: Equivalence<symbol> = strict()\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const combine: {\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(that: Equivalence<A>): (self: Equivalence<A>) => Equivalence<A>\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(self: Equivalence<A>, that: Equivalence<A>): Equivalence<A>\n} = dual(2, <A>(self: Equivalence<A>, that: Equivalence<A>): Equivalence<A> => make((x, y) => self(x, y) && that(x, y)))\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const combineMany: {\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(collection: Iterable<Equivalence<A>>): (self: Equivalence<A>) => Equivalence<A>\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(self: Equivalence<A>, collection: Iterable<Equivalence<A>>): Equivalence<A>\n} = dual(2, <A>(self: Equivalence<A>, collection: Iterable<Equivalence<A>>): Equivalence<A> =>\n make((x, y) => {\n if (!self(x, y)) {\n return false\n }\n for (const equivalence of collection) {\n if (!equivalence(x, y)) {\n return false\n }\n }\n return true\n }))\n\nconst isAlwaysEquivalent: Equivalence<unknown> = (_x, _y) => true\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const combineAll = <A>(collection: Iterable<Equivalence<A>>): Equivalence<A> =>\n combineMany(isAlwaysEquivalent, collection)\n\n/**\n * @category mapping\n * @since 2.0.0\n */\nexport const mapInput: {\n /**\n * @category mapping\n * @since 2.0.0\n */\n <B, A>(f: (b: B) => A): (self: Equivalence<A>) => Equivalence<B>\n /**\n * @category mapping\n * @since 2.0.0\n */\n <A, B>(self: Equivalence<A>, f: (b: B) => A): Equivalence<B>\n} = dual(\n 2,\n <A, B>(self: Equivalence<A>, f: (b: B) => A): Equivalence<B> => make((x, y) => self(f(x), f(y)))\n)\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const Date: Equivalence<Date> = mapInput(number, (date) => date.getTime())\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const product: {\n <B>(that: Equivalence<B>): <A>(self: Equivalence<A>) => Equivalence<readonly [A, B]> // readonly because invariant\n <A, B>(self: Equivalence<A>, that: Equivalence<B>): Equivalence<readonly [A, B]> // readonly because invariant\n} = dual(\n 2,\n <A, B>(self: Equivalence<A>, that: Equivalence<B>): Equivalence<readonly [A, B]> =>\n make(([xa, xb], [ya, yb]) => self(xa, ya) && that(xb, yb))\n)\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const all = <A>(collection: Iterable<Equivalence<A>>): Equivalence<ReadonlyArray<A>> => {\n return make((x, y) => {\n const len = Math.min(x.length, y.length)\n\n let collectionLength = 0\n for (const equivalence of collection) {\n if (collectionLength >= len) {\n break\n }\n if (!equivalence(x[collectionLength], y[collectionLength])) {\n return false\n }\n collectionLength++\n }\n return true\n })\n}\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const productMany = <A>(\n self: Equivalence<A>,\n collection: Iterable<Equivalence<A>>\n): Equivalence<readonly [A, ...Array<A>]> /* readonly because invariant */ => {\n const equivalence = all(collection)\n return make((x, y) => !self(x[0], y[0]) ? false : equivalence(x.slice(1), y.slice(1)))\n}\n\n/**\n * Similar to `Promise.all` but operates on `Equivalence`s.\n *\n * ```\n * [Equivalence<A>, Equivalence<B>, ...] -> Equivalence<[A, B, ...]>\n * ```\n *\n * Given a tuple of `Equivalence`s returns a new `Equivalence` that compares values of a tuple\n * by applying each `Equivalence` to the corresponding element of the tuple.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const tuple = <T extends ReadonlyArray<Equivalence<any>>>(\n ...elements: T\n): Equivalence<Readonly<{ [I in keyof T]: [T[I]] extends [Equivalence<infer A>] ? A : never }>> => all(elements) as any\n\n/**\n * Creates a new `Equivalence` for an array of values based on a given `Equivalence` for the elements of the array.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const array = <A>(item: Equivalence<A>): Equivalence<ReadonlyArray<A>> =>\n make((self, that) => {\n if (self.length !== that.length) {\n return false\n }\n\n for (let i = 0; i < self.length; i++) {\n const isEq = item(self[i], that[i])\n if (!isEq) {\n return false\n }\n }\n\n return true\n })\n\n/**\n * Given a struct of `Equivalence`s returns a new `Equivalence` that compares values of a struct\n * by applying each `Equivalence` to the corresponding property of the struct.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const struct = <R extends Record<string, Equivalence<any>>>(\n fields: R\n): Equivalence<{ readonly [K in keyof R]: [R[K]] extends [Equivalence<infer A>] ? A : never }> => {\n const keys = Object.keys(fields)\n return make((self, that) => {\n for (const key of keys) {\n if (!fields[key](self[key], that[key])) {\n return false\n }\n }\n return true\n })\n}\n","import { dual } from \"../Function.js\"\nimport type { Kind, TypeLambda } from \"../HKT.js\"\nimport type { NoInfer } from \"../Types.js\"\n\ntype Map<F extends TypeLambda> = {\n <A, B>(f: (a: A) => B): <R, O, E>(self: Kind<F, R, O, E, A>) => Kind<F, R, O, E, B>\n <R, O, E, A, B>(self: Kind<F, R, O, E, A>, f: (a: A) => B): Kind<F, R, O, E, B>\n}\n\ntype FlatMap<F extends TypeLambda> = {\n <A, R2, O2, E2, B>(\n f: (a: A) => Kind<F, R2, O2, E2, B>\n ): <R1, O1, E1>(self: Kind<F, R1, O1, E1, A>) => Kind<F, R1 & R2, O1 | O2, E1 | E2, B>\n <R1, O1, E1, A, R2, O2, E2, B>(\n self: Kind<F, R1, O1, E1, A>,\n f: (a: A) => Kind<F, R2, O2, E2, B>\n ): Kind<F, R1 & R2, O1 | O2, E1 | E2, B>\n}\n\n/** @internal */\nexport const let_ = <F extends TypeLambda>(\n map: Map<F>\n): {\n <N extends string, A extends object, B>(\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): <R, O, E>(\n self: Kind<F, R, O, E, A>\n ) => Kind<F, R, O, E, { [K in keyof A | N]: K extends keyof A ? A[K] : B }>\n <R, O, E, A extends object, N extends string, B>(\n self: Kind<F, R, O, E, A>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): Kind<F, R, O, E, { [K in keyof A | N]: K extends keyof A ? A[K] : B }>\n} =>\n dual(3, <R, O, E, A extends object, N extends string, B>(\n self: Kind<F, R, O, E, A>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): Kind<F, R, O, E, { [K in keyof A | N]: K extends keyof A ? A[K] : B }> =>\n map(self, (a) => Object.assign({}, a, { [name]: f(a) }) as any))\n\n/** @internal */\nexport const bindTo = <F extends TypeLambda>(map: Map<F>): {\n <N extends string>(\n name: N\n ): <R, O, E, A>(self: Kind<F, R, O, E, A>) => Kind<F, R, O, E, { [K in N]: A }>\n <R, O, E, A, N extends string>(\n self: Kind<F, R, O, E, A>,\n name: N\n ): Kind<F, R, O, E, { [K in N]: A }>\n} =>\n dual(2, <R, O, E, A, N extends string>(\n self: Kind<F, R, O, E, A>,\n name: N\n ): Kind<F, R, O, E, { [K in N]: A }> => map(self, (a) => ({ [name]: a } as { [K in N]: A })))\n\n/** @internal */\nexport const bind = <F extends TypeLambda>(map: Map<F>, flatMap: FlatMap<F>): {\n <N extends string, A extends object, R2, O2, E2, B>(\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => Kind<F, R2, O2, E2, B>\n ): <R1, O1, E1>(\n self: Kind<F, R1, O1, E1, A>\n ) => Kind<F, R1 & R2, O1 | O2, E1 | E2, { [K in keyof A | N]: K extends keyof A ? A[K] : B }>\n <R1, O1, E1, A extends object, N extends string, R2, O2, E2, B>(\n self: Kind<F, R1, O1, E1, A>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => Kind<F, R2, O2, E2, B>\n ): Kind<F, R1 & R2, O1 | O2, E1 | E2, { [K in keyof A | N]: K extends keyof A ? A[K] : B }>\n} =>\n dual(3, <R1, O1, E1, A, N extends string, R2, O2, E2, B>(\n self: Kind<F, R1, O1, E1, A>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => Kind<F, R2, O2, E2, B>\n ): Kind<F, R1 & R2, O1 | O2, E1 | E2, { [K in keyof A | N]: K extends keyof A ? A[K] : B }> =>\n flatMap(self, (a) =>\n map(f(a), (b) => Object.assign({}, a, { [name]: b }) as { [K in keyof A | N]: K extends keyof A ? A[K] : B })))\n","let moduleVersion = \"3.12.5\"\n\nexport const getCurrentVersion = () => moduleVersion\n\nexport const setCurrentVersion = (version: string) => {\n moduleVersion = version\n}\n","/**\n * The `GlobalValue` module ensures that a single instance of a value is created globally,\n * even when modules are imported multiple times (e.g., due to mixing CommonJS and ESM builds)\n * or during hot-reloading in development environments like Next.js or Remix.\n *\n * It achieves this by using a versioned global store, identified by a unique `Symbol` tied to\n * the current version of the `effect` library. The store holds values that are keyed by an identifier,\n * allowing the reuse of previously computed instances across imports or reloads.\n *\n * This pattern is particularly useful in scenarios where frequent reloading can cause services or\n * single-instance objects to be recreated unnecessarily, such as in development environments with hot-reloading.\n *\n * @since 2.0.0\n */\nimport * as version from \"./internal/version.js\"\n\nconst globalStoreId = `effect/GlobalValue/globalStoreId/${version.getCurrentVersion()}`\n\nlet globalStore: Map<unknown, any>\n\n/**\n * Retrieves or computes a global value associated with the given `id`. If the value for this `id`\n * has already been computed, it will be returned from the global store. If it does not exist yet,\n * the provided `compute` function will be executed to compute the value, store it, and then return it.\n *\n * This ensures that even in cases where the module is imported multiple times (e.g., in mixed environments\n * like CommonJS and ESM, or during hot-reloading in development), the value is computed only once and reused\n * thereafter.\n *\n * @example\n * ```ts\n * import { globalValue } from \"effect/GlobalValue\"\n *\n * // This cache will persist as long as the module is running,\n * // even if reloaded or imported elsewhere\n * const myCache = globalValue(\n * Symbol.for(\"myCache\"),\n * () => new WeakMap<object, number>()\n * )\n * ```\n *\n * @since 2.0.0\n */\nexport const globalValue = <A>(id: unknown, compute: () => A): A => {\n if (!globalStore) {\n // @ts-expect-error\n globalThis[globalStoreId] ??= new Map()\n // @ts-expect-error\n globalStore = globalThis[globalStoreId] as Map<unknown, any>\n }\n if (!globalStore.has(id)) {\n globalStore.set(id, compute())\n }\n return globalStore.get(id)!\n}\n","/**\n * @since 2.0.0\n */\nimport { dual, isFunction as isFunction_ } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\nimport type { TupleOf, TupleOfAtLeast } from \"./Types.js\"\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Predicate<in A> {\n (a: A): boolean\n}\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface PredicateTypeLambda extends TypeLambda {\n readonly type: Predicate<this[\"Target\"]>\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Refinement<in A, out B extends A> {\n (a: A): a is B\n}\n\n/**\n * @since 3.6.0\n * @category type-level\n */\nexport declare namespace Predicate {\n /**\n * @since 3.6.0\n * @category type-level\n */\n export type In<T extends Any> = [T] extends [Predicate<infer _A>] ? _A : never\n /**\n * @since 3.6.0\n * @category type-level\n */\n export type Any = Predicate<never>\n}\n\n/**\n * @since 3.6.0\n * @category type-level\n */\nexport declare namespace Refinement {\n /**\n * @since 3.6.0\n * @category type-level\n */\n export type In<T extends Any> = [T] extends [Refinement<infer _A, infer _>] ? _A : never\n /**\n * @since 3.6.0\n * @category type-level\n */\n export type Out<T extends Any> = [T] extends [Refinement<infer _, infer _B>] ? _B : never\n /**\n * @since 3.6.0\n * @category type-level\n */\n export type Any = Refinement<any, any>\n}\n\n/**\n * Given a `Predicate<A>` returns a `Predicate<B>`\n *\n * @param self - the `Predicate<A>` to be transformed to `Predicate<B>`.\n * @param f - a function to transform `B` to `A`.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const minLength3 = Predicate.mapInput(Number.greaterThan(2), (s: string) => s.length)\n *\n * assert.deepStrictEqual(minLength3(\"a\"), false)\n * assert.deepStrictEqual(minLength3(\"aa\"), false)\n * assert.deepStrictEqual(minLength3(\"aaa\"), true)\n * assert.deepStrictEqual(minLength3(\"aaaa\"), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const mapInput: {\n /**\n * Given a `Predicate<A>` returns a `Predicate<B>`\n *\n * @param self - the `Predicate<A>` to be transformed to `Predicate<B>`.\n * @param f - a function to transform `B` to `A`.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const minLength3 = Predicate.mapInput(Number.greaterThan(2), (s: string) => s.length)\n *\n * assert.deepStrictEqual(minLength3(\"a\"), false)\n * assert.deepStrictEqual(minLength3(\"aa\"), false)\n * assert.deepStrictEqual(minLength3(\"aaa\"), true)\n * assert.deepStrictEqual(minLength3(\"aaaa\"), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <B, A>(f: (b: B) => A): (self: Predicate<A>) => Predicate<B>\n /**\n * Given a `Predicate<A>` returns a `Predicate<B>`\n *\n * @param self - the `Predicate<A>` to be transformed to `Predicate<B>`.\n * @param f - a function to transform `B` to `A`.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const minLength3 = Predicate.mapInput(Number.greaterThan(2), (s: string) => s.length)\n *\n * assert.deepStrictEqual(minLength3(\"a\"), false)\n * assert.deepStrictEqual(minLength3(\"aa\"), false)\n * assert.deepStrictEqual(minLength3(\"aaa\"), true)\n * assert.deepStrictEqual(minLength3(\"aaaa\"), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A, B>(self: Predicate<A>, f: (b: B) => A): Predicate<B>\n} = dual(2, <A, B>(self: Predicate<A>, f: (b: B) => A): Predicate<B> => (b) => self(f(b)))\n\n/**\n * Determine if an `Array` is a tuple with exactly `N` elements, narrowing down the type to `TupleOf`.\n *\n * An `Array` is considered to be a `TupleOf` if its length is exactly `N`.\n *\n * @param self - The `Array` to check.\n * @param n - The exact number of elements that the `Array` should have to be considered a `TupleOf`.\n *\n * @example\n * ```ts\n * import { isTupleOf } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 3), true);\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 2), false);\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 4), false);\n *\n * const arr: number[] = [1, 2, 3];\n * if (isTupleOf(arr, 3)) {\n * console.log(arr);\n * // ^? [number, number, number]\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\nexport const isTupleOf: {\n /**\n * Determine if an `Array` is a tuple with exactly `N` elements, narrowing down the type to `TupleOf`.\n *\n * An `Array` is considered to be a `TupleOf` if its length is exactly `N`.\n *\n * @param self - The `Array` to check.\n * @param n - The exact number of elements that the `Array` should have to be considered a `TupleOf`.\n *\n * @example\n * ```ts\n * import { isTupleOf } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 3), true);\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 2), false);\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 4), false);\n *\n * const arr: number[] = [1, 2, 3];\n * if (isTupleOf(arr, 3)) {\n * console.log(arr);\n * // ^? [number, number, number]\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\n <N extends number>(n: N): <T>(self: ReadonlyArray<T>) => self is TupleOf<N, T>\n /**\n * Determine if an `Array` is a tuple with exactly `N` elements, narrowing down the type to `TupleOf`.\n *\n * An `Array` is considered to be a `TupleOf` if its length is exactly `N`.\n *\n * @param self - The `Array` to check.\n * @param n - The exact number of elements that the `Array` should have to be considered a `TupleOf`.\n *\n * @example\n * ```ts\n * import { isTupleOf } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 3), true);\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 2), false);\n * assert.deepStrictEqual(isTupleOf([1, 2, 3], 4), false);\n *\n * const arr: number[] = [1, 2, 3];\n * if (isTupleOf(arr, 3)) {\n * console.log(arr);\n * // ^? [number, number, number]\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\n <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T>\n} = dual(2, <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T> => self.length === n)\n\n/**\n * Determine if an `Array` is a tuple with at least `N` elements, narrowing down the type to `TupleOfAtLeast`.\n *\n * An `Array` is considered to be a `TupleOfAtLeast` if its length is at least `N`.\n *\n * @param self - The `Array` to check.\n * @param n - The minimum number of elements that the `Array` should have to be considered a `TupleOfAtLeast`.\n *\n * @example\n * ```ts\n * import { isTupleOfAtLeast } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 3), true);\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 2), true);\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 4), false);\n *\n * const arr: number[] = [1, 2, 3, 4];\n * if (isTupleOfAtLeast(arr, 3)) {\n * console.log(arr);\n * // ^? [number, number, number, ...number[]]\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\nexport const isTupleOfAtLeast: {\n /**\n * Determine if an `Array` is a tuple with at least `N` elements, narrowing down the type to `TupleOfAtLeast`.\n *\n * An `Array` is considered to be a `TupleOfAtLeast` if its length is at least `N`.\n *\n * @param self - The `Array` to check.\n * @param n - The minimum number of elements that the `Array` should have to be considered a `TupleOfAtLeast`.\n *\n * @example\n * ```ts\n * import { isTupleOfAtLeast } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 3), true);\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 2), true);\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 4), false);\n *\n * const arr: number[] = [1, 2, 3, 4];\n * if (isTupleOfAtLeast(arr, 3)) {\n * console.log(arr);\n * // ^? [number, number, number, ...number[]]\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\n <N extends number>(n: N): <T>(self: ReadonlyArray<T>) => self is TupleOfAtLeast<N, T>\n /**\n * Determine if an `Array` is a tuple with at least `N` elements, narrowing down the type to `TupleOfAtLeast`.\n *\n * An `Array` is considered to be a `TupleOfAtLeast` if its length is at least `N`.\n *\n * @param self - The `Array` to check.\n * @param n - The minimum number of elements that the `Array` should have to be considered a `TupleOfAtLeast`.\n *\n * @example\n * ```ts\n * import { isTupleOfAtLeast } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 3), true);\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 2), true);\n * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 4), false);\n *\n * const arr: number[] = [1, 2, 3, 4];\n * if (isTupleOfAtLeast(arr, 3)) {\n * console.log(arr);\n * // ^? [number, number, number, ...number[]]\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\n <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOfAtLeast<N, T>\n} = dual(2, <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOfAtLeast<N, T> => self.length >= n)\n\n/**\n * Tests if a value is `truthy`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isTruthy } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTruthy(1), true)\n * assert.deepStrictEqual(isTruthy(0), false)\n * assert.deepStrictEqual(isTruthy(\"\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isTruthy = (input: unknown) => !!input\n\n/**\n * Tests if a value is a `Set`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isSet } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isSet(new Set([1, 2])), true)\n * assert.deepStrictEqual(isSet(new Set()), true)\n * assert.deepStrictEqual(isSet({}), false)\n * assert.deepStrictEqual(isSet(null), false)\n * assert.deepStrictEqual(isSet(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isSet = (input: unknown): input is Set<unknown> => input instanceof Set\n\n/**\n * Tests if a value is a `Map`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isMap } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isMap(new Map()), true)\n * assert.deepStrictEqual(isMap({}), false)\n * assert.deepStrictEqual(isMap(null), false)\n * assert.deepStrictEqual(isMap(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isMap = (input: unknown): input is Map<unknown, unknown> => input instanceof Map\n\n/**\n * Tests if a value is a `string`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isString } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isString(\"a\"), true)\n *\n * assert.deepStrictEqual(isString(1), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isString = (input: unknown): input is string => typeof input === \"string\"\n\n/**\n * Tests if a value is a `number`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isNumber } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNumber(2), true)\n *\n * assert.deepStrictEqual(isNumber(\"2\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNumber = (input: unknown): input is number => typeof input === \"number\"\n\n/**\n * Tests if a value is a `boolean`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isBoolean } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isBoolean(true), true)\n *\n * assert.deepStrictEqual(isBoolean(\"true\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isBoolean = (input: unknown): input is boolean => typeof input === \"boolean\"\n\n/**\n * Tests if a value is a `bigint`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isBigInt } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isBigInt(1n), true)\n *\n * assert.deepStrictEqual(isBigInt(1), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isBigInt = (input: unknown): input is bigint => typeof input === \"bigint\"\n\n/**\n * Tests if a value is a `symbol`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isSymbol } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isSymbol(Symbol.for(\"a\")), true)\n *\n * assert.deepStrictEqual(isSymbol(\"a\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isSymbol = (input: unknown): input is symbol => typeof input === \"symbol\"\n\n/**\n * Tests if a value is a `function`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isFunction } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isFunction(isFunction), true)\n *\n * assert.deepStrictEqual(isFunction(\"function\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isFunction: (input: unknown) => input is Function = isFunction_\n\n/**\n * Tests if a value is `undefined`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isUndefined } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isUndefined(undefined), true)\n *\n * assert.deepStrictEqual(isUndefined(null), false)\n * assert.deepStrictEqual(isUndefined(\"undefined\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isUndefined = (input: unknown): input is undefined => input === undefined\n\n/**\n * Tests if a value is not `undefined`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isNotUndefined } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNotUndefined(null), true)\n * assert.deepStrictEqual(isNotUndefined(\"undefined\"), true)\n *\n * assert.deepStrictEqual(isNotUndefined(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNotUndefined = <A>(input: A): input is Exclude<A, undefined> => input !== undefined\n\n/**\n * Tests if a value is `null`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isNull } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNull(null), true)\n *\n * assert.deepStrictEqual(isNull(undefined), false)\n * assert.deepStrictEqual(isNull(\"null\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNull = (input: unknown): input is null => input === null\n\n/**\n * Tests if a value is not `null`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isNotNull } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNotNull(undefined), true)\n * assert.deepStrictEqual(isNotNull(\"null\"), true)\n *\n * assert.deepStrictEqual(isNotNull(null), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNotNull = <A>(input: A): input is Exclude<A, null> => input !== null\n\n/**\n * A guard that always fails.\n *\n * @param _ - The value to test.\n *\n * @example\n * ```ts\n * import { isNever } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNever(null), false)\n * assert.deepStrictEqual(isNever(undefined), false)\n * assert.deepStrictEqual(isNever({}), false)\n * assert.deepStrictEqual(isNever([]), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNever: (input: unknown) => input is never = (_: unknown): _ is never => false\n\n/**\n * A guard that always succeeds.\n *\n * @param _ - The value to test.\n *\n * @example\n * ```ts\n * import { isUnknown } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isUnknown(null), true)\n * assert.deepStrictEqual(isUnknown(undefined), true)\n *\n * assert.deepStrictEqual(isUnknown({}), true)\n * assert.deepStrictEqual(isUnknown([]), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isUnknown: (input: unknown) => input is unknown = (_): _ is unknown => true\n\n/** @internal */\nexport const isRecordOrArray = (input: unknown): input is { [x: PropertyKey]: unknown } =>\n typeof input === \"object\" && input !== null\n\n/**\n * Tests if a value is an `object`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isObject } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isObject({}), true)\n * assert.deepStrictEqual(isObject([]), true)\n *\n * assert.deepStrictEqual(isObject(null), false)\n * assert.deepStrictEqual(isObject(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isObject = (input: unknown): input is object => isRecordOrArray(input) || isFunction(input)\n\n/**\n * Checks whether a value is an `object` containing a specified property key.\n *\n * @param property - The field to check within the object.\n * @param self - The value to examine.\n *\n * @category guards\n * @since 2.0.0\n */\nexport const hasProperty: {\n /**\n * Checks whether a value is an `object` containing a specified property key.\n *\n * @param property - The field to check within the object.\n * @param self - The value to examine.\n *\n * @category guards\n * @since 2.0.0\n */\n <P extends PropertyKey>(property: P): (self: unknown) => self is { [K in P]: unknown }\n /**\n * Checks whether a value is an `object` containing a specified property key.\n *\n * @param property - The field to check within the object.\n * @param self - The value to examine.\n *\n * @category guards\n * @since 2.0.0\n */\n <P extends PropertyKey>(self: unknown, property: P): self is { [K in P]: unknown }\n} = dual(\n 2,\n <P extends PropertyKey>(self: unknown, property: P): self is { [K in P]: unknown } =>\n isObject(self) && (property in self)\n)\n\n/**\n * Tests if a value is an `object` with a property `_tag` that matches the given tag.\n *\n * @param input - The value to test.\n * @param tag - The tag to test for.\n *\n * @example\n * ```ts\n * import { isTagged } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTagged(1, \"a\"), false)\n * assert.deepStrictEqual(isTagged(null, \"a\"), false)\n * assert.deepStrictEqual(isTagged({}, \"a\"), false)\n * assert.deepStrictEqual(isTagged({ a: \"a\" }, \"a\"), false)\n * assert.deepStrictEqual(isTagged({ _tag: \"a\" }, \"a\"), true)\n * assert.deepStrictEqual(isTagged(\"a\")({ _tag: \"a\" }), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isTagged: {\n /**\n * Tests if a value is an `object` with a property `_tag` that matches the given tag.\n *\n * @param input - The value to test.\n * @param tag - The tag to test for.\n *\n * @example\n * ```ts\n * import { isTagged } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTagged(1, \"a\"), false)\n * assert.deepStrictEqual(isTagged(null, \"a\"), false)\n * assert.deepStrictEqual(isTagged({}, \"a\"), false)\n * assert.deepStrictEqual(isTagged({ a: \"a\" }, \"a\"), false)\n * assert.deepStrictEqual(isTagged({ _tag: \"a\" }, \"a\"), true)\n * assert.deepStrictEqual(isTagged(\"a\")({ _tag: \"a\" }), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\n <K extends string>(tag: K): (self: unknown) => self is { _tag: K }\n /**\n * Tests if a value is an `object` with a property `_tag` that matches the given tag.\n *\n * @param input - The value to test.\n * @param tag - The tag to test for.\n *\n * @example\n * ```ts\n * import { isTagged } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isTagged(1, \"a\"), false)\n * assert.deepStrictEqual(isTagged(null, \"a\"), false)\n * assert.deepStrictEqual(isTagged({}, \"a\"), false)\n * assert.deepStrictEqual(isTagged({ a: \"a\" }, \"a\"), false)\n * assert.deepStrictEqual(isTagged({ _tag: \"a\" }, \"a\"), true)\n * assert.deepStrictEqual(isTagged(\"a\")({ _tag: \"a\" }), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\n <K extends string>(self: unknown, tag: K): self is { _tag: K }\n} = dual(\n 2,\n <K extends string>(self: unknown, tag: K): self is { _tag: K } => hasProperty(self, \"_tag\") && self[\"_tag\"] === tag\n)\n\n/**\n * A guard that succeeds when the input is `null` or `undefined`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isNullable } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNullable(null), true)\n * assert.deepStrictEqual(isNullable(undefined), true)\n *\n * assert.deepStrictEqual(isNullable({}), false)\n * assert.deepStrictEqual(isNullable([]), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNullable = <A>(input: A): input is Extract<A, null | undefined> => input === null || input === undefined\n\n/**\n * A guard that succeeds when the input is not `null` or `undefined`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isNotNullable } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isNotNullable({}), true)\n * assert.deepStrictEqual(isNotNullable([]), true)\n *\n * assert.deepStrictEqual(isNotNullable(null), false)\n * assert.deepStrictEqual(isNotNullable(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNotNullable = <A>(input: A): input is NonNullable<A> => input !== null && input !== undefined\n\n/**\n * A guard that succeeds when the input is an `Error`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isError } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isError(new Error()), true)\n *\n * assert.deepStrictEqual(isError(null), false)\n * assert.deepStrictEqual(isError({}), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isError = (input: unknown): input is Error => input instanceof Error\n\n/**\n * A guard that succeeds when the input is a `Uint8Array`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isUint8Array } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isUint8Array(new Uint8Array()), true)\n *\n * assert.deepStrictEqual(isUint8Array(null), false)\n * assert.deepStrictEqual(isUint8Array({}), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isUint8Array = (input: unknown): input is Uint8Array => input instanceof Uint8Array\n\n/**\n * A guard that succeeds when the input is a `Date`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isDate } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isDate(new Date()), true)\n *\n * assert.deepStrictEqual(isDate(null), false)\n * assert.deepStrictEqual(isDate({}), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isDate = (input: unknown): input is Date => input instanceof Date\n\n/**\n * A guard that succeeds when the input is an `Iterable`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isIterable } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isIterable([]), true)\n * assert.deepStrictEqual(isIterable(new Set()), true)\n *\n * assert.deepStrictEqual(isIterable(null), false)\n * assert.deepStrictEqual(isIterable({}), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isIterable = (input: unknown): input is Iterable<unknown> => hasProperty(input, Symbol.iterator)\n\n/**\n * A guard that succeeds when the input is a record.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isRecord } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isRecord({}), true)\n * assert.deepStrictEqual(isRecord({ a: 1 }), true)\n *\n * assert.deepStrictEqual(isRecord([]), false)\n * assert.deepStrictEqual(isRecord([1, 2, 3]), false)\n * assert.deepStrictEqual(isRecord(null), false)\n * assert.deepStrictEqual(isRecord(undefined), false)\n * assert.deepStrictEqual(isRecord(() => null), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isRecord = (input: unknown): input is { [x: string | symbol]: unknown } =>\n isRecordOrArray(input) && !Array.isArray(input)\n\n/**\n * A guard that succeeds when the input is a readonly record.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isReadonlyRecord } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isReadonlyRecord({}), true)\n * assert.deepStrictEqual(isReadonlyRecord({ a: 1 }), true)\n *\n * assert.deepStrictEqual(isReadonlyRecord([]), false)\n * assert.deepStrictEqual(isReadonlyRecord([1, 2, 3]), false)\n * assert.deepStrictEqual(isReadonlyRecord(null), false)\n * assert.deepStrictEqual(isReadonlyRecord(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isReadonlyRecord: (\n input: unknown\n) => input is { readonly [x: string | symbol]: unknown } = isRecord\n\n/**\n * A guard that succeeds when the input is a Promise.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { isPromise } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isPromise({}), false)\n * assert.deepStrictEqual(isPromise(Promise.resolve(\"hello\")), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isPromise = (\n input: unknown\n): input is Promise<unknown> =>\n hasProperty(input, \"then\") && \"catch\" in input && isFunction(input.then) && isFunction(input.catch)\n\n/**\n * @category guards\n * @since 2.0.0\n */\nexport const isPromiseLike = (\n input: unknown\n): input is PromiseLike<unknown> => hasProperty(input, \"then\") && isFunction(input.then)\n\n/**\n * Tests if a value is a `RegExp`.\n *\n * @param input - The value to test.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * assert.deepStrictEqual(Predicate.isRegExp(/a/), true)\n * assert.deepStrictEqual(Predicate.isRegExp(\"a\"), false)\n * ```\n *\n * @category guards\n * @since 3.9.0\n */\nexport const isRegExp = (input: unknown): input is RegExp => input instanceof RegExp\n\n/**\n * @since 2.0.0\n */\nexport const compose: {\n /**\n * @since 2.0.0\n */\n <A, B extends A, C extends B>(bc: Refinement<B, C>): (ab: Refinement<A, B>) => Refinement<A, C>\n /**\n * @since 2.0.0\n */\n <A, B extends A>(bc: Predicate<NoInfer<B>>): (ab: Refinement<A, B>) => Refinement<A, B>\n /**\n * @since 2.0.0\n */\n <A, B extends A, C extends B>(ab: Refinement<A, B>, bc: Refinement<B, C>): Refinement<A, C>\n /**\n * @since 2.0.0\n */\n <A, B extends A>(ab: Refinement<A, B>, bc: Predicate<NoInfer<B>>): Refinement<A, B>\n} = dual(\n 2,\n <A, B extends A, C extends B>(ab: Refinement<A, B>, bc: Refinement<B, C>): Refinement<A, C> => (a): a is C =>\n ab(a) && bc(a)\n)\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const product =\n <A, B>(self: Predicate<A>, that: Predicate<B>): Predicate<readonly [A, B]> /* readonly because contravariant */ =>\n ([a, b]) => self(a) && that(b)\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const all = <A>(\n collection: Iterable<Predicate<A>>\n): Predicate<ReadonlyArray<A>> => {\n return (as) => {\n let collectionIndex = 0\n for (const p of collection) {\n if (collectionIndex >= as.length) {\n break\n }\n if (p(as[collectionIndex]) === false) {\n return false\n }\n collectionIndex++\n }\n return true\n }\n}\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const productMany = <A>(\n self: Predicate<A>,\n collection: Iterable<Predicate<A>>\n): Predicate<readonly [A, ...Array<A>]> /* readonly because contravariant */ => {\n const rest = all(collection)\n return ([head, ...tail]) => self(head) === false ? false : rest(tail)\n}\n\n/**\n * Similar to `Promise.all` but operates on `Predicate`s.\n *\n * ```\n * [Refinement<A, B>, Refinement<C, D>, ...] -> Refinement<[A, C, ...], [B, D, ...]>\n * [Predicate<A>, Predicate<B>, ...] -> Predicate<[A, B, ...]>\n * [Refinement<A, B>, Predicate<C>, ...] -> Refinement<[A, C, ...], [B, C, ...]>\n * ```\n *\n * @since 2.0.0\n */\nexport const tuple: {\n /**\n * Similar to `Promise.all` but operates on `Predicate`s.\n *\n * ```\n * [Refinement<A, B>, Refinement<C, D>, ...] -> Refinement<[A, C, ...], [B, D, ...]>\n * [Predicate<A>, Predicate<B>, ...] -> Predicate<[A, B, ...]>\n * [Refinement<A, B>, Predicate<C>, ...] -> Refinement<[A, C, ...], [B, C, ...]>\n * ```\n *\n * @since 2.0.0\n */\n <T extends ReadonlyArray<Predicate.Any>>(\n ...elements: T\n ): [Extract<T[number], Refinement.Any>] extends [never] ? Predicate<{ readonly [I in keyof T]: Predicate.In<T[I]> }>\n : Refinement<\n { readonly [I in keyof T]: T[I] extends Refinement.Any ? Refinement.In<T[I]> : Predicate.In<T[I]> },\n { readonly [I in keyof T]: T[I] extends Refinement.Any ? Refinement.Out<T[I]> : Predicate.In<T[I]> }\n >\n} = (...elements: ReadonlyArray<Predicate.Any>) => all(elements) as any\n\n/**\n * ```\n * { ab: Refinement<A, B>; cd: Refinement<C, D>, ... } -> Refinement<{ ab: A; cd: C; ... }, { ab: B; cd: D; ... }>\n * { a: Predicate<A, B>; b: Predicate<B>, ... } -> Predicate<{ a: A; b: B; ... }>\n * { ab: Refinement<A, B>; c: Predicate<C>, ... } -> Refinement<{ ab: A; c: C; ... }, { ab: B; c: С; ... }>\n * ```\n *\n * @since 2.0.0\n */\nexport const struct: {\n /**\n * ```\n * { ab: Refinement<A, B>; cd: Refinement<C, D>, ... } -> Refinement<{ ab: A; cd: C; ... }, { ab: B; cd: D; ... }>\n * { a: Predicate<A, B>; b: Predicate<B>, ... } -> Predicate<{ a: A; b: B; ... }>\n * { ab: Refinement<A, B>; c: Predicate<C>, ... } -> Refinement<{ ab: A; c: C; ... }, { ab: B; c: С; ... }>\n * ```\n *\n * @since 2.0.0\n */\n <R extends Record<string, Predicate.Any>>(\n fields: R\n ): [Extract<R[keyof R], Refinement.Any>] extends [never] ?\n Predicate<{ readonly [K in keyof R]: Predicate.In<R[K]> }> :\n Refinement<\n { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.In<R[K]> : Predicate.In<R[K]> },\n { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.Out<R[K]> : Predicate.In<R[K]> }\n >\n} = (<R extends Record<string, Predicate.Any>>(fields: R) => {\n const keys = Object.keys(fields)\n return (a: Record<string, unknown>) => {\n for (const key of keys) {\n if (!fields[key](a[key] as never)) {\n return false\n }\n }\n return true\n }\n}) as any\n\n/**\n * Negates the result of a given predicate.\n *\n * @param self - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const isPositive = Predicate.not(Number.lessThan(0))\n *\n * assert.deepStrictEqual(isPositive(-1), false)\n * assert.deepStrictEqual(isPositive(0), true)\n * assert.deepStrictEqual(isPositive(1), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const not = <A>(self: Predicate<A>): Predicate<A> => (a) => !self(a)\n\n/**\n * Combines two predicates into a new predicate that returns `true` if at least one of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const nonZero = Predicate.or(Number.lessThan(0), Number.greaterThan(0))\n *\n * assert.deepStrictEqual(nonZero(-1), true)\n * assert.deepStrictEqual(nonZero(0), false)\n * assert.deepStrictEqual(nonZero(1), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const or: {\n /**\n * Combines two predicates into a new predicate that returns `true` if at least one of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const nonZero = Predicate.or(Number.lessThan(0), Number.greaterThan(0))\n *\n * assert.deepStrictEqual(nonZero(-1), true)\n * assert.deepStrictEqual(nonZero(0), false)\n * assert.deepStrictEqual(nonZero(1), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A, C extends A>(that: Refinement<A, C>): <B extends A>(self: Refinement<A, B>) => Refinement<A, B | C>\n /**\n * Combines two predicates into a new predicate that returns `true` if at least one of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const nonZero = Predicate.or(Number.lessThan(0), Number.greaterThan(0))\n *\n * assert.deepStrictEqual(nonZero(-1), true)\n * assert.deepStrictEqual(nonZero(0), false)\n * assert.deepStrictEqual(nonZero(1), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A, B extends A, C extends A>(self: Refinement<A, B>, that: Refinement<A, C>): Refinement<A, B | C>\n /**\n * Combines two predicates into a new predicate that returns `true` if at least one of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const nonZero = Predicate.or(Number.lessThan(0), Number.greaterThan(0))\n *\n * assert.deepStrictEqual(nonZero(-1), true)\n * assert.deepStrictEqual(nonZero(0), false)\n * assert.deepStrictEqual(nonZero(1), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>\n /**\n * Combines two predicates into a new predicate that returns `true` if at least one of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n *\n * const nonZero = Predicate.or(Number.lessThan(0), Number.greaterThan(0))\n *\n * assert.deepStrictEqual(nonZero(-1), true)\n * assert.deepStrictEqual(nonZero(0), false)\n * assert.deepStrictEqual(nonZero(1), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>\n} = dual(2, <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => self(a) || that(a))\n\n/**\n * Combines two predicates into a new predicate that returns `true` if both of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * const minLength = (n: number) => (s: string) => s.length >= n\n * const maxLength = (n: number) => (s: string) => s.length <= n\n *\n * const length = (n: number) => Predicate.and(minLength(n), maxLength(n))\n *\n * assert.deepStrictEqual(length(2)(\"aa\"), true)\n * assert.deepStrictEqual(length(2)(\"a\"), false)\n * assert.deepStrictEqual(length(2)(\"aaa\"), false)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const and: {\n /**\n * Combines two predicates into a new predicate that returns `true` if both of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * const minLength = (n: number) => (s: string) => s.length >= n\n * const maxLength = (n: number) => (s: string) => s.length <= n\n *\n * const length = (n: number) => Predicate.and(minLength(n), maxLength(n))\n *\n * assert.deepStrictEqual(length(2)(\"aa\"), true)\n * assert.deepStrictEqual(length(2)(\"a\"), false)\n * assert.deepStrictEqual(length(2)(\"aaa\"), false)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A, C extends A>(that: Refinement<A, C>): <B extends A>(self: Refinement<A, B>) => Refinement<A, B & C>\n /**\n * Combines two predicates into a new predicate that returns `true` if both of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * const minLength = (n: number) => (s: string) => s.length >= n\n * const maxLength = (n: number) => (s: string) => s.length <= n\n *\n * const length = (n: number) => Predicate.and(minLength(n), maxLength(n))\n *\n * assert.deepStrictEqual(length(2)(\"aa\"), true)\n * assert.deepStrictEqual(length(2)(\"a\"), false)\n * assert.deepStrictEqual(length(2)(\"aaa\"), false)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A, B extends A, C extends A>(self: Refinement<A, B>, that: Refinement<A, C>): Refinement<A, B & C>\n /**\n * Combines two predicates into a new predicate that returns `true` if both of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * const minLength = (n: number) => (s: string) => s.length >= n\n * const maxLength = (n: number) => (s: string) => s.length <= n\n *\n * const length = (n: number) => Predicate.and(minLength(n), maxLength(n))\n *\n * assert.deepStrictEqual(length(2)(\"aa\"), true)\n * assert.deepStrictEqual(length(2)(\"a\"), false)\n * assert.deepStrictEqual(length(2)(\"aaa\"), false)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>\n /**\n * Combines two predicates into a new predicate that returns `true` if both of the predicates returns `true`.\n *\n * @param self - A predicate.\n * @param that - A predicate.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * const minLength = (n: number) => (s: string) => s.length >= n\n * const maxLength = (n: number) => (s: string) => s.length <= n\n *\n * const length = (n: number) => Predicate.and(minLength(n), maxLength(n))\n *\n * assert.deepStrictEqual(length(2)(\"aa\"), true)\n * assert.deepStrictEqual(length(2)(\"a\"), false)\n * assert.deepStrictEqual(length(2)(\"aaa\"), false)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>\n} = dual(2, <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => self(a) && that(a))\n\n/**\n * @category combinators\n * @since 2.0.0\n */\nexport const xor: {\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>\n} = dual(2, <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => self(a) !== that(a))\n\n/**\n * @category combinators\n * @since 2.0.0\n */\nexport const eqv: {\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>\n} = dual(2, <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => self(a) === that(a))\n\n/**\n * Represents the logical implication combinator for predicates. In formal\n * logic, the implication operator `->` denotes that if the first proposition\n * (antecedent) is true, then the second proposition (consequent) must also be\n * true. In simpler terms, `p implies q` can be interpreted as \"if p then q\". If\n * the first predicate holds, then the second predicate must hold\n * for the given context.\n *\n * In practical terms within TypeScript, `p implies q` is equivalent to `!p || (p && q)`.\n *\n * Note that if the antecedent is `false`, the result is `true` by default\n * because the outcome of the consequent cannot be determined.\n *\n * This function is useful in situations where you need to enforce rules or\n * constraints that are contingent on certain conditions.\n * It proves especially helpful in defining property tests.\n *\n * The example below illustrates the transitive property of order using the\n * `implies` function. In simple terms, if `a <= b` and `b <= c`, then `a <= c`\n * must be true.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * type Triple = {\n * readonly a: number\n * readonly b: number\n * readonly c: number\n * }\n *\n * const transitivity = Predicate.implies(\n * // antecedent\n * (input: Triple) => input.a <= input.b && input.b <= input.c,\n * // consequent\n * (input: Triple) => input.a <= input.c\n * )\n *\n * assert.equal(transitivity({ a: 1, b: 2, c: 3 }), true)\n * // antecedent is `false`, so the result is `true`\n * assert.equal(transitivity({ a: 1, b: 0, c: 0 }), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const implies: {\n /**\n * Represents the logical implication combinator for predicates. In formal\n * logic, the implication operator `->` denotes that if the first proposition\n * (antecedent) is true, then the second proposition (consequent) must also be\n * true. In simpler terms, `p implies q` can be interpreted as \"if p then q\". If\n * the first predicate holds, then the second predicate must hold\n * for the given context.\n *\n * In practical terms within TypeScript, `p implies q` is equivalent to `!p || (p && q)`.\n *\n * Note that if the antecedent is `false`, the result is `true` by default\n * because the outcome of the consequent cannot be determined.\n *\n * This function is useful in situations where you need to enforce rules or\n * constraints that are contingent on certain conditions.\n * It proves especially helpful in defining property tests.\n *\n * The example below illustrates the transitive property of order using the\n * `implies` function. In simple terms, if `a <= b` and `b <= c`, then `a <= c`\n * must be true.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * type Triple = {\n * readonly a: number\n * readonly b: number\n * readonly c: number\n * }\n *\n * const transitivity = Predicate.implies(\n * // antecedent\n * (input: Triple) => input.a <= input.b && input.b <= input.c,\n * // consequent\n * (input: Triple) => input.a <= input.c\n * )\n *\n * assert.equal(transitivity({ a: 1, b: 2, c: 3 }), true)\n * // antecedent is `false`, so the result is `true`\n * assert.equal(transitivity({ a: 1, b: 0, c: 0 }), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A>(consequent: Predicate<A>): (antecedent: Predicate<A>) => Predicate<A>\n /**\n * Represents the logical implication combinator for predicates. In formal\n * logic, the implication operator `->` denotes that if the first proposition\n * (antecedent) is true, then the second proposition (consequent) must also be\n * true. In simpler terms, `p implies q` can be interpreted as \"if p then q\". If\n * the first predicate holds, then the second predicate must hold\n * for the given context.\n *\n * In practical terms within TypeScript, `p implies q` is equivalent to `!p || (p && q)`.\n *\n * Note that if the antecedent is `false`, the result is `true` by default\n * because the outcome of the consequent cannot be determined.\n *\n * This function is useful in situations where you need to enforce rules or\n * constraints that are contingent on certain conditions.\n * It proves especially helpful in defining property tests.\n *\n * The example below illustrates the transitive property of order using the\n * `implies` function. In simple terms, if `a <= b` and `b <= c`, then `a <= c`\n * must be true.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n *\n * type Triple = {\n * readonly a: number\n * readonly b: number\n * readonly c: number\n * }\n *\n * const transitivity = Predicate.implies(\n * // antecedent\n * (input: Triple) => input.a <= input.b && input.b <= input.c,\n * // consequent\n * (input: Triple) => input.a <= input.c\n * )\n *\n * assert.equal(transitivity({ a: 1, b: 2, c: 3 }), true)\n * // antecedent is `false`, so the result is `true`\n * assert.equal(transitivity({ a: 1, b: 0, c: 0 }), true)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A>(antecedent: Predicate<A>, consequent: Predicate<A>): Predicate<A>\n} = dual(\n 2,\n <A>(antecedent: Predicate<A>, consequent: Predicate<A>): Predicate<A> => (a) => antecedent(a) ? consequent(a) : true\n)\n\n/**\n * @category combinators\n * @since 2.0.0\n */\nexport const nor: {\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>\n} = dual(\n 2,\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => !(self(a) || that(a))\n)\n\n/**\n * @category combinators\n * @since 2.0.0\n */\nexport const nand: {\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>\n /**\n * @category combinators\n * @since 2.0.0\n */\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>\n} = dual(\n 2,\n <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => !(self(a) && that(a))\n)\n\n/**\n * @category elements\n * @since 2.0.0\n */\nexport const every = <A>(collection: Iterable<Predicate<A>>): Predicate<A> => (a: A) => {\n for (const p of collection) {\n if (!p(a)) {\n return false\n }\n }\n return true\n}\n\n/**\n * @category elements\n * @since 2.0.0\n */\nexport const some = <A>(collection: Iterable<Predicate<A>>): Predicate<A> => (a) => {\n for (const p of collection) {\n if (p(a)) {\n return true\n }\n }\n return false\n}\n","/**\n * @since 2.0.0\n */\n\n/** @internal */\nexport const getBugErrorMessage = (message: string) =>\n `BUG: ${message} - please report an issue at https://github.com/Effect-TS/effect/issues`\n","/**\n * @since 2.0.0\n */\nimport { identity } from \"./Function.js\"\nimport { globalValue } from \"./GlobalValue.js\"\nimport type { Kind, TypeLambda } from \"./HKT.js\"\nimport { getBugErrorMessage } from \"./internal/errors.js\"\nimport { isNullable, isObject } from \"./Predicate.js\"\nimport type * as Types from \"./Types.js\"\n\n/*\n * Copyright 2014 Thom Chiovoloni, released under the MIT license.\n *\n * A random number generator based on the basic implementation of the PCG algorithm,\n * as described here: http://www.pcg-random.org/\n *\n * Adapted for TypeScript from Thom's original code at https://github.com/thomcc/pcg-random\n *\n * forked from https://github.com/frptools\n *\n * @since 2.0.0\n */\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport const GenKindTypeId: unique symbol = Symbol.for(\"effect/Gen/GenKind\")\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport type GenKindTypeId = typeof GenKindTypeId\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface GenKind<F extends TypeLambda, R, O, E, A> extends Variance<F, R, O, E> {\n readonly value: Kind<F, R, O, E, A>\n\n [Symbol.iterator](): IterableIterator<GenKind<F, R, O, E, A>, A>\n}\n\n/**\n * @category predicates\n * @since 3.0.6\n */\nexport const isGenKind = (u: unknown): u is GenKind<any, any, any, any, any> => isObject(u) && GenKindTypeId in u\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport class GenKindImpl<F extends TypeLambda, R, O, E, A> implements GenKind<F, R, O, E, A> {\n constructor(\n /**\n * @since 2.0.0\n */\n readonly value: Kind<F, R, O, E, A>\n ) {}\n\n /**\n * @since 2.0.0\n */\n get _F() {\n return identity\n }\n\n /**\n * @since 2.0.0\n */\n get _R() {\n return (_: R) => _\n }\n\n /**\n * @since 2.0.0\n */\n get _O() {\n return (_: never): O => _\n }\n\n /**\n * @since 2.0.0\n */\n get _E() {\n return (_: never): E => _\n }\n\n /**\n * @since 2.0.0\n */\n readonly [GenKindTypeId]: typeof GenKindTypeId = GenKindTypeId;\n\n /**\n * @since 2.0.0\n */\n [Symbol.iterator](): IterableIterator<GenKind<F, R, O, E, A>, A> {\n return new SingleShotGen<GenKind<F, R, O, E, A>, A>(this as any)\n }\n}\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport class SingleShotGen<T, A> implements IterableIterator<T, A> {\n private called = false\n\n constructor(readonly self: T) {}\n\n /**\n * @since 2.0.0\n */\n next(a: A): IteratorResult<T, A> {\n return this.called ?\n ({\n value: a,\n done: true\n }) :\n (this.called = true,\n ({\n value: this.self,\n done: false\n }))\n }\n\n /**\n * @since 2.0.0\n */\n return(a: A): IteratorResult<T, A> {\n return ({\n value: a,\n done: true\n })\n }\n\n /**\n * @since 2.0.0\n */\n throw(e: unknown): IteratorResult<T, A> {\n throw e\n }\n\n /**\n * @since 2.0.0\n */\n [Symbol.iterator](): IterableIterator<T, A> {\n return new SingleShotGen<T, A>(this.self)\n }\n}\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const makeGenKind = <F extends TypeLambda, R, O, E, A>(\n kind: Kind<F, R, O, E, A>\n): GenKind<F, R, O, E, A> => new GenKindImpl(kind)\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Variance<in out F extends TypeLambda, in R, out O, out E> {\n readonly [GenKindTypeId]: GenKindTypeId\n readonly _F: Types.Invariant<F>\n readonly _R: Types.Contravariant<R>\n readonly _O: Types.Covariant<O>\n readonly _E: Types.Covariant<E>\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Gen<F extends TypeLambda, Z> {\n <Self, K extends Variance<F, any, any, any> | YieldWrap<Kind<F, any, any, any, any>>, A>(\n ...args:\n | [\n self: Self,\n body: (this: Self, resume: Z) => Generator<K, A, never>\n ]\n | [\n body: (resume: Z) => Generator<K, A, never>\n ]\n ): Kind<\n F,\n [K] extends [Variance<F, infer R, any, any>] ? R\n : [K] extends [YieldWrap<Kind<F, infer R, any, any, any>>] ? R\n : never,\n [K] extends [Variance<F, any, infer O, any>] ? O\n : [K] extends [YieldWrap<Kind<F, any, infer O, any, any>>] ? O\n : never,\n [K] extends [Variance<F, any, any, infer E>] ? E\n : [K] extends [YieldWrap<Kind<F, any, any, infer E, any>>] ? E\n : never,\n A\n >\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Adapter<Z extends TypeLambda> {\n <_R, _O, _E, _A>(\n self: Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, _R, _O, _E, _A>(a: A, ab: (a: A) => Kind<Z, _R, _O, _E, _A>): GenKind<Z, _R, _O, _E, _A>\n <A, B, _R, _O, _E, _A>(a: A, ab: (a: A) => B, bc: (b: B) => Kind<Z, _R, _O, _E, _A>): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: F) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (g: H) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => S,\n st: (s: S) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => S,\n st: (s: S) => T,\n tu: (s: T) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n}\n\n/**\n * @category adapters\n * @since 2.0.0\n */\nexport const adapter: <F extends TypeLambda>() => Adapter<F> = () => (function() {\n let x = arguments[0]\n for (let i = 1; i < arguments.length; i++) {\n x = arguments[i](x)\n }\n return new GenKindImpl(x) as any\n})\n\nconst defaultIncHi = 0x14057b7e\nconst defaultIncLo = 0xf767814f\nconst MUL_HI = 0x5851f42d >>> 0\nconst MUL_LO = 0x4c957f2d >>> 0\nconst BIT_53 = 9007199254740992.0\nconst BIT_27 = 134217728.0\n\n/**\n * @category model\n * @since 2.0.0\n */\nexport type PCGRandomState = [number, number, number, number]\n\n/**\n * @category model\n * @since 2.0.0\n */\nexport type OptionalNumber = number | null | undefined\n\n/**\n * PCG is a family of simple fast space-efficient statistically good algorithms\n * for random number generation. Unlike many general-purpose RNGs, they are also\n * hard to predict.\n *\n * @category model\n * @since 2.0.0\n */\nexport class PCGRandom {\n private _state!: Int32Array\n\n /**\n * Creates an instance of PCGRandom.\n *\n * @param seed - The low 32 bits of the seed (0 is used for high 32 bits).\n *\n * @memberOf PCGRandom\n */\n constructor(seed?: OptionalNumber)\n /**\n * Creates an instance of PCGRandom.\n *\n * @param seedHi - The high 32 bits of the seed.\n * @param seedLo - The low 32 bits of the seed.\n * @param inc - The low 32 bits of the incrementer (0 is used for high 32 bits).\n *\n * @memberOf PCGRandom\n */\n constructor(seedHi: OptionalNumber, seedLo: OptionalNumber, inc?: OptionalNumber)\n /**\n * Creates an instance of PCGRandom.\n *\n * @param seedHi - The high 32 bits of the seed.\n * @param seedLo - The low 32 bits of the seed.\n * @param incHi - The high 32 bits of the incrementer.\n * @param incLo - The low 32 bits of the incrementer.\n *\n * @memberOf PCGRandom\n */\n constructor(\n seedHi: OptionalNumber,\n seedLo: OptionalNumber,\n incHi: OptionalNumber,\n incLo: OptionalNumber\n )\n constructor(\n seedHi?: OptionalNumber,\n seedLo?: OptionalNumber,\n incHi?: OptionalNumber,\n incLo?: OptionalNumber\n ) {\n if (isNullable(seedLo) && isNullable(seedHi)) {\n seedLo = (Math.random() * 0xffffffff) >>> 0\n seedHi = 0\n } else if (isNullable(seedLo)) {\n seedLo = seedHi\n seedHi = 0\n }\n if (isNullable(incLo) && isNullable(incHi)) {\n incLo = this._state ? this._state[3] : defaultIncLo\n incHi = this._state ? this._state[2] : defaultIncHi\n } else if (isNullable(incLo)) {\n incLo = <number> incHi\n incHi = 0\n }\n\n this._state = new Int32Array([0, 0, (<number> incHi) >>> 0, ((incLo || 0) | 1) >>> 0])\n this._next()\n add64(\n this._state,\n this._state[0]!,\n this._state[1]!,\n (<number> seedHi) >>> 0,\n (<number> seedLo) >>> 0\n )\n this._next()\n return this\n }\n\n /**\n * Returns a copy of the internal state of this random number generator as a\n * JavaScript Array.\n *\n * @category getters\n * @since 2.0.0\n */\n getState(): PCGRandomState {\n return [this._state[0]!, this._state[1]!, this._state[2]!, this._state[3]!]\n }\n\n /**\n * Restore state previously retrieved using `getState()`.\n *\n * @since 2.0.0\n */\n setState(state: PCGRandomState) {\n this._state[0] = state[0]\n this._state[1] = state[1]\n this._state[2] = state[2]\n this._state[3] = state[3] | 1\n }\n\n /**\n * Get a uniformly distributed 32 bit integer between [0, max).\n *\n * @category getter\n * @since 2.0.0\n */\n integer(max: number) {\n return Math.round(this.number() * Number.MAX_SAFE_INTEGER) % max\n }\n\n /**\n * Get a uniformly distributed IEEE-754 double between 0.0 and 1.0, with\n * 53 bits of precision (every bit of the mantissa is randomized).\n *\n * @category getters\n * @since 2.0.0\n */\n number() {\n const hi = (this._next() & 0x03ffffff) * 1.0\n const lo = (this._next() & 0x07ffffff) * 1.0\n return (hi * BIT_27 + lo) / BIT_53\n }\n\n /** @internal */\n private _next() {\n // save current state (what we'll use for this number)\n const oldHi = this._state[0]! >>> 0\n const oldLo = this._state[1]! >>> 0\n\n // churn LCG.\n mul64(this._state, oldHi, oldLo, MUL_HI, MUL_LO)\n add64(this._state, this._state[0]!, this._state[1]!, this._state[2]!, this._state[3]!)\n\n // get least sig. 32 bits of ((oldstate >> 18) ^ oldstate) >> 27\n let xsHi = oldHi >>> 18\n let xsLo = ((oldLo >>> 18) | (oldHi << 14)) >>> 0\n xsHi = (xsHi ^ oldHi) >>> 0\n xsLo = (xsLo ^ oldLo) >>> 0\n const xorshifted = ((xsLo >>> 27) | (xsHi << 5)) >>> 0\n // rotate xorshifted right a random amount, based on the most sig. 5 bits\n // bits of the old state.\n const rot = oldHi >>> 27\n const rot2 = ((-rot >>> 0) & 31) >>> 0\n return ((xorshifted >>> rot) | (xorshifted << rot2)) >>> 0\n }\n}\n\nfunction mul64(\n out: Int32Array,\n aHi: number,\n aLo: number,\n bHi: number,\n bLo: number\n): void {\n let c1 = ((aLo >>> 16) * (bLo & 0xffff)) >>> 0\n let c0 = ((aLo & 0xffff) * (bLo >>> 16)) >>> 0\n\n let lo = ((aLo & 0xffff) * (bLo & 0xffff)) >>> 0\n let hi = ((aLo >>> 16) * (bLo >>> 16) + ((c0 >>> 16) + (c1 >>> 16))) >>> 0\n\n c0 = (c0 << 16) >>> 0\n lo = (lo + c0) >>> 0\n if ((lo >>> 0) < (c0 >>> 0)) {\n hi = (hi + 1) >>> 0\n }\n\n c1 = (c1 << 16) >>> 0\n lo = (lo + c1) >>> 0\n if ((lo >>> 0) < (c1 >>> 0)) {\n hi = (hi + 1) >>> 0\n }\n\n hi = (hi + Math.imul(aLo, bHi)) >>> 0\n hi = (hi + Math.imul(aHi, bLo)) >>> 0\n\n out[0] = hi\n out[1] = lo\n}\n\n// add two 64 bit numbers (given in parts), and store the result in `out`.\nfunction add64(\n out: Int32Array,\n aHi: number,\n aLo: number,\n bHi: number,\n bLo: number\n): void {\n let hi = (aHi + bHi) >>> 0\n const lo = (aLo + bLo) >>> 0\n if ((lo >>> 0) < (aLo >>> 0)) {\n hi = (hi + 1) | 0\n }\n out[0] = hi\n out[1] = lo\n}\n\n/**\n * @since 3.0.6\n */\nexport const YieldWrapTypeId: unique symbol = Symbol.for(\"effect/Utils/YieldWrap\")\n\n/**\n * @since 3.0.6\n */\nexport class YieldWrap<T> {\n /**\n * @since 3.0.6\n */\n readonly #value: T\n constructor(value: T) {\n this.#value = value\n }\n /**\n * @since 3.0.6\n */\n [YieldWrapTypeId](): T {\n return this.#value\n }\n}\n\n/**\n * @since 3.0.6\n */\nexport function yieldWrapGet<T>(self: YieldWrap<T>): T {\n if (typeof self === \"object\" && self !== null && YieldWrapTypeId in self) {\n return self[YieldWrapTypeId]()\n }\n throw new Error(getBugErrorMessage(\"yieldWrapGet\"))\n}\n\n/**\n * Note: this is an experimental feature made available to allow custom matchers in tests, not to be directly used yet in user code\n *\n * @since 3.1.1\n * @status experimental\n * @category modifiers\n */\nexport const structuralRegionState = globalValue(\n \"effect/Utils/isStructuralRegion\",\n (): { enabled: boolean; tester: ((a: unknown, b: unknown) => boolean) | undefined } => ({\n enabled: false,\n tester: undefined\n })\n)\n\n/**\n * Note: this is an experimental feature made available to allow custom matchers in tests, not to be directly used yet in user code\n *\n * @since 3.1.1\n * @status experimental\n * @category modifiers\n */\nexport const structuralRegion = <A>(body: () => A, tester?: (a: unknown, b: unknown) => boolean): A => {\n const current = structuralRegionState.enabled\n const currentTester = structuralRegionState.tester\n structuralRegionState.enabled = true\n if (tester) {\n structuralRegionState.tester = tester\n }\n try {\n return body()\n } finally {\n structuralRegionState.enabled = current\n structuralRegionState.tester = currentTester\n }\n}\n\nconst tracingFunction = (name: string) => {\n const wrap = {\n [name]<A>(body: () => A) {\n return body()\n }\n }\n return function<A>(fn: () => A): A {\n return wrap[name](fn)\n }\n}\n\n/**\n * @since 3.2.2\n * @status experimental\n * @category tracing\n */\nexport const internalCall = tracingFunction(\"effect_internal_function\")\n\nconst genConstructor = (function*() {}).constructor\n\n/**\n * @since 3.11.0\n */\nexport const isGeneratorFunction = (u: unknown): u is (...args: Array<any>) => Generator<any, any, any> =>\n isObject(u) && u.constructor === genConstructor\n","/**\n * @since 2.0.0\n */\nimport { pipe } from \"./Function.js\"\nimport { globalValue } from \"./GlobalValue.js\"\nimport { hasProperty } from \"./Predicate.js\"\nimport { structuralRegionState } from \"./Utils.js\"\n\n/** @internal */\nconst randomHashCache = globalValue(\n Symbol.for(\"effect/Hash/randomHashCache\"),\n () => new WeakMap<object, number>()\n)\n\n/**\n * @since 2.0.0\n * @category symbols\n */\nexport const symbol: unique symbol = Symbol.for(\"effect/Hash\")\n\n/**\n * @since 2.0.0\n * @category models\n */\nexport interface Hash {\n [symbol](): number\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const hash: <A>(self: A) => number = <A>(self: A) => {\n if (structuralRegionState.enabled === true) {\n return 0\n }\n\n switch (typeof self) {\n case \"number\":\n return number(self)\n case \"bigint\":\n return string(self.toString(10))\n case \"boolean\":\n return string(String(self))\n case \"symbol\":\n return string(String(self))\n case \"string\":\n return string(self)\n case \"undefined\":\n return string(\"undefined\")\n case \"function\":\n case \"object\": {\n if (self === null) {\n return string(\"null\")\n } else if (self instanceof Date) {\n return hash(self.toISOString())\n } else if (isHash(self)) {\n return self[symbol]()\n } else {\n return random(self)\n }\n }\n default:\n throw new Error(\n `BUG: unhandled typeof ${typeof self} - please report an issue at https://github.com/Effect-TS/effect/issues`\n )\n }\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const random: <A extends object>(self: A) => number = (self) => {\n if (!randomHashCache.has(self)) {\n randomHashCache.set(self, number(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)))\n }\n return randomHashCache.get(self)!\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const combine: (b: number) => (self: number) => number = (b) => (self) => (self * 53) ^ b\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const optimize = (n: number): number => (n & 0xbfffffff) | ((n >>> 1) & 0x40000000)\n\n/**\n * @since 2.0.0\n * @category guards\n */\nexport const isHash = (u: unknown): u is Hash => hasProperty(u, symbol)\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const number = (n: number) => {\n if (n !== n || n === Infinity) {\n return 0\n }\n let h = n | 0\n if (h !== n) {\n h ^= n * 0xffffffff\n }\n while (n > 0xffffffff) {\n h ^= n /= 0xffffffff\n }\n return optimize(h)\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const string = (str: string) => {\n let h = 5381, i = str.length\n while (i) {\n h = (h * 33) ^ str.charCodeAt(--i)\n }\n return optimize(h)\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const structureKeys = <A extends object>(o: A, keys: ReadonlyArray<keyof A>) => {\n let h = 12289\n for (let i = 0; i < keys.length; i++) {\n h ^= pipe(string(keys[i]! as string), combine(hash((o as any)[keys[i]!])))\n }\n return optimize(h)\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const structure = <A extends object>(o: A) =>\n structureKeys(o, Object.keys(o) as unknown as ReadonlyArray<keyof A>)\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const array = <A>(arr: ReadonlyArray<A>) => {\n let h = 6151\n for (let i = 0; i < arr.length; i++) {\n h = pipe(h, combine(hash(arr[i])))\n }\n return optimize(h)\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const cached: {\n /**\n * @since 2.0.0\n * @category hashing\n */\n (self: object): (hash: number) => number\n /**\n * @since 2.0.0\n * @category hashing\n */\n (self: object, hash: number): number\n} = function() {\n if (arguments.length === 1) {\n const self = arguments[0] as object\n return function(hash: number) {\n Object.defineProperty(self, symbol, {\n value() {\n return hash\n },\n enumerable: false\n })\n return hash\n } as any\n }\n const self = arguments[0] as object\n const hash = arguments[1] as number\n Object.defineProperty(self, symbol, {\n value() {\n return hash\n },\n enumerable: false\n })\n\n return hash\n}\n","/**\n * @since 2.0.0\n */\nimport type { Equivalence } from \"./Equivalence.js\"\nimport * as Hash from \"./Hash.js\"\nimport { hasProperty } from \"./Predicate.js\"\nimport { structuralRegionState } from \"./Utils.js\"\n\n/**\n * @since 2.0.0\n * @category symbols\n */\nexport const symbol: unique symbol = Symbol.for(\"effect/Equal\")\n\n/**\n * @since 2.0.0\n * @category models\n */\nexport interface Equal extends Hash.Hash {\n [symbol](that: Equal): boolean\n}\n\n/**\n * @since 2.0.0\n * @category equality\n */\nexport function equals<B>(that: B): <A>(self: A) => boolean\nexport function equals<A, B>(self: A, that: B): boolean\nexport function equals(): any {\n if (arguments.length === 1) {\n return (self: unknown) => compareBoth(self, arguments[0])\n }\n return compareBoth(arguments[0], arguments[1])\n}\n\nfunction compareBoth(self: unknown, that: unknown): boolean {\n if (self === that) {\n return true\n }\n const selfType = typeof self\n if (selfType !== typeof that) {\n return false\n }\n if (selfType === \"object\" || selfType === \"function\") {\n if (self !== null && that !== null) {\n if (isEqual(self) && isEqual(that)) {\n if (Hash.hash(self) === Hash.hash(that) && self[symbol](that)) {\n return true\n } else {\n return structuralRegionState.enabled && structuralRegionState.tester\n ? structuralRegionState.tester(self, that)\n : false\n }\n } else if (self instanceof Date && that instanceof Date) {\n return self.toISOString() === that.toISOString()\n }\n }\n if (structuralRegionState.enabled) {\n if (Array.isArray(self) && Array.isArray(that)) {\n return self.length === that.length && self.every((v, i) => compareBoth(v, that[i]))\n }\n if (Object.getPrototypeOf(self) === Object.prototype && Object.getPrototypeOf(self) === Object.prototype) {\n const keysSelf = Object.keys(self as any)\n const keysThat = Object.keys(that as any)\n if (keysSelf.length === keysThat.length) {\n for (const key of keysSelf) {\n // @ts-expect-error\n if (!(key in that && compareBoth(self[key], that[key]))) {\n return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false\n }\n }\n return true\n }\n }\n return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false\n }\n }\n\n return structuralRegionState.enabled && structuralRegionState.tester\n ? structuralRegionState.tester(self, that)\n : false\n}\n\n/**\n * @since 2.0.0\n * @category guards\n */\nexport const isEqual = (u: unknown): u is Equal => hasProperty(u, symbol)\n\n/**\n * @since 2.0.0\n * @category instances\n */\nexport const equivalence: <A>() => Equivalence<A> = () => equals\n","/**\n * @since 2.0.0\n */\nimport type * as FiberRefs from \"./FiberRefs.js\"\nimport { globalValue } from \"./GlobalValue.js\"\nimport { hasProperty, isFunction } from \"./Predicate.js\"\n\n/**\n * @since 2.0.0\n * @category symbols\n */\nexport const NodeInspectSymbol = Symbol.for(\"nodejs.util.inspect.custom\")\n\n/**\n * @since 2.0.0\n * @category symbols\n */\nexport type NodeInspectSymbol = typeof NodeInspectSymbol\n\n/**\n * @since 2.0.0\n * @category models\n */\nexport interface Inspectable {\n toString(): string\n toJSON(): unknown\n [NodeInspectSymbol](): unknown\n}\n\n/**\n * @since 2.0.0\n */\nexport const toJSON = (x: unknown): unknown => {\n try {\n if (\n hasProperty(x, \"toJSON\") && isFunction(x[\"toJSON\"]) &&\n x[\"toJSON\"].length === 0\n ) {\n return x.toJSON()\n } else if (Array.isArray(x)) {\n return x.map(toJSON)\n }\n } catch (_) {\n return {}\n }\n return redact(x)\n}\n\n/**\n * @since 2.0.0\n */\nexport const format = (x: unknown): string => JSON.stringify(x, null, 2)\n\n/**\n * @since 2.0.0\n */\nexport const BaseProto: Inspectable = {\n toJSON() {\n return toJSON(this)\n },\n [NodeInspectSymbol]() {\n return this.toJSON()\n },\n toString() {\n return format(this.toJSON())\n }\n}\n\n/**\n * @since 2.0.0\n */\nexport abstract class Class {\n /**\n * @since 2.0.0\n */\n abstract toJSON(): unknown\n /**\n * @since 2.0.0\n */\n [NodeInspectSymbol]() {\n return this.toJSON()\n }\n /**\n * @since 2.0.0\n */\n toString() {\n return format(this.toJSON())\n }\n}\n\n/**\n * @since 2.0.0\n */\nexport const toStringUnknown = (u: unknown, whitespace: number | string | undefined = 2): string => {\n if (typeof u === \"string\") {\n return u\n }\n try {\n return typeof u === \"object\" ? stringifyCircular(u, whitespace) : String(u)\n } catch (_) {\n return String(u)\n }\n}\n\n/**\n * @since 2.0.0\n */\nexport const stringifyCircular = (obj: unknown, whitespace?: number | string | undefined): string => {\n let cache: Array<unknown> = []\n const retVal = JSON.stringify(\n obj,\n (_key, value) =>\n typeof value === \"object\" && value !== null\n ? cache.includes(value)\n ? undefined // circular reference\n : cache.push(value) && (redactableState.fiberRefs !== undefined && isRedactable(value)\n ? value[symbolRedactable](redactableState.fiberRefs)\n : value)\n : value,\n whitespace\n )\n ;(cache as any) = undefined\n return retVal\n}\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport interface Redactable {\n readonly [symbolRedactable]: (fiberRefs: FiberRefs.FiberRefs) => unknown\n}\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport const symbolRedactable: unique symbol = Symbol.for(\"effect/Inspectable/Redactable\")\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport const isRedactable = (u: unknown): u is Redactable =>\n typeof u === \"object\" && u !== null && symbolRedactable in u\n\nconst redactableState = globalValue(\"effect/Inspectable/redactableState\", () => ({\n fiberRefs: undefined as FiberRefs.FiberRefs | undefined\n}))\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport const withRedactableContext = <A>(context: FiberRefs.FiberRefs, f: () => A): A => {\n const prev = redactableState.fiberRefs\n redactableState.fiberRefs = context\n try {\n return f()\n } finally {\n redactableState.fiberRefs = prev\n }\n}\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport const redact = (u: unknown): unknown => {\n if (isRedactable(u) && redactableState.fiberRefs !== undefined) {\n return u[symbolRedactable](redactableState.fiberRefs)\n }\n return u\n}\n","/**\n * @since 2.0.0\n */\n\n/**\n * @since 2.0.0\n * @category models\n */\nexport interface Pipeable {\n pipe<A>(this: A): A\n pipe<A, B = never>(this: A, ab: (_: A) => B): B\n pipe<A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C\n pipe<A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D\n pipe<A, B = never, C = never, D = never, E = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E\n ): E\n pipe<A, B = never, C = never, D = never, E = never, F = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F\n ): F\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G\n ): G\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H\n ): H\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I\n ): I\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J\n ): J\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K\n ): K\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L\n ): L\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M\n ): M\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N\n ): N\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O\n ): O\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P\n ): P\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q\n ): Q\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R\n ): R\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R,\n rs: (_: R) => S\n ): S\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never,\n T = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R,\n rs: (_: R) => S,\n st: (_: S) => T\n ): T\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never,\n T = never,\n U = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R,\n rs: (_: R) => S,\n st: (_: S) => T,\n tu: (_: T) => U\n ): U\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never,\n T = never,\n U = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R,\n rs: (_: R) => S,\n st: (_: S) => T,\n tu: (_: T) => U\n ): U\n}\n\n/**\n * @since 2.0.0\n */\nexport const pipeArguments = <A>(self: A, args: IArguments): unknown => {\n switch (args.length) {\n case 0:\n return self\n case 1:\n return args[0](self)\n case 2:\n return args[1](args[0](self))\n case 3:\n return args[2](args[1](args[0](self)))\n case 4:\n return args[3](args[2](args[1](args[0](self))))\n case 5:\n return args[4](args[3](args[2](args[1](args[0](self)))))\n case 6:\n return args[5](args[4](args[3](args[2](args[1](args[0](self))))))\n case 7:\n return args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))))\n case 8:\n return args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self))))))))\n case 9:\n return args[8](args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))))))\n default: {\n let ret = self\n for (let i = 0, len = args.length; i < len; i++) {\n ret = args[i](ret)\n }\n return ret\n }\n }\n}\n","/** @internal */\nexport type OP_ASYNC = typeof OP_ASYNC\n\n/** @internal */\nexport const OP_ASYNC = \"Async\" as const\n\n/** @internal */\nexport type OP_COMMIT = typeof OP_COMMIT\n\n/** @internal */\nexport const OP_COMMIT = \"Commit\" as const\n\n/** @internal */\nexport type OP_FAILURE = typeof OP_FAILURE\n\n/** @internal */\nexport const OP_FAILURE = \"Failure\" as const\n\n/** @internal */\nexport type OP_ON_FAILURE = typeof OP_ON_FAILURE\n\n/** @internal */\nexport const OP_ON_FAILURE = \"OnFailure\" as const\n\n/** @internal */\nexport type OP_ON_SUCCESS = typeof OP_ON_SUCCESS\n\n/** @internal */\nexport const OP_ON_SUCCESS = \"OnSuccess\" as const\n\n/** @internal */\nexport type OP_ON_SUCCESS_AND_FAILURE = typeof OP_ON_SUCCESS_AND_FAILURE\n\n/** @internal */\nexport const OP_ON_SUCCESS_AND_FAILURE = \"OnSuccessAndFailure\" as const\n\n/** @internal */\nexport type OP_SUCCESS = typeof OP_SUCCESS\n\n/** @internal */\nexport const OP_SUCCESS = \"Success\" as const\n\n/** @internal */\nexport type OP_SYNC = typeof OP_SYNC\n\n/** @internal */\nexport const OP_SYNC = \"Sync\" as const\n\n/** @internal */\nexport const OP_TAG = \"Tag\" as const\n\n/** @internal */\nexport type OP_TAG = typeof OP_TAG\n\n/** @internal */\nexport type OP_UPDATE_RUNTIME_FLAGS = typeof OP_UPDATE_RUNTIME_FLAGS\n\n/** @internal */\nexport const OP_UPDATE_RUNTIME_FLAGS = \"UpdateRuntimeFlags\" as const\n\n/** @internal */\nexport type OP_WHILE = typeof OP_WHILE\n\n/** @internal */\nexport const OP_WHILE = \"While\" as const\n\n/** @internal */\nexport type OP_ITERATOR = typeof OP_ITERATOR\n\n/** @internal */\nexport const OP_ITERATOR = \"Iterator\" as const\n\n/** @internal */\nexport type OP_WITH_RUNTIME = typeof OP_WITH_RUNTIME\n\n/** @internal */\nexport const OP_WITH_RUNTIME = \"WithRuntime\" as const\n\n/** @internal */\nexport type OP_YIELD = typeof OP_YIELD\n\n/** @internal */\nexport const OP_YIELD = \"Yield\" as const\n\n/** @internal */\nexport type OP_REVERT_FLAGS = typeof OP_REVERT_FLAGS\n\n/** @internal */\nexport const OP_REVERT_FLAGS = \"RevertFlags\" as const\n","import type * as Channel from \"../Channel.js\"\nimport type * as Effect from \"../Effect.js\"\nimport type * as Effectable from \"../Effectable.js\"\nimport * as Equal from \"../Equal.js\"\nimport * as Hash from \"../Hash.js\"\nimport { pipeArguments } from \"../Pipeable.js\"\nimport type * as Sink from \"../Sink.js\"\nimport type * as Stream from \"../Stream.js\"\nimport { SingleShotGen, YieldWrap } from \"../Utils.js\"\nimport * as OpCodes from \"./opCodes/effect.js\"\nimport * as version from \"./version.js\"\n\n/** @internal */\nexport const EffectTypeId: Effect.EffectTypeId = Symbol.for(\"effect/Effect\") as Effect.EffectTypeId\n\n/** @internal */\nexport const StreamTypeId: Stream.StreamTypeId = Symbol.for(\"effect/Stream\") as Stream.StreamTypeId\n\n/** @internal */\nexport const SinkTypeId: Sink.SinkTypeId = Symbol.for(\"effect/Sink\") as Sink.SinkTypeId\n\n/** @internal */\nexport const ChannelTypeId: Channel.ChannelTypeId = Symbol.for(\"effect/Channel\") as Channel.ChannelTypeId\n\n/** @internal */\nexport const effectVariance = {\n /* c8 ignore next */\n _R: (_: never) => _,\n /* c8 ignore next */\n _E: (_: never) => _,\n /* c8 ignore next */\n _A: (_: never) => _,\n\n _V: version.getCurrentVersion()\n}\n\nconst sinkVariance = {\n /* c8 ignore next */\n _A: (_: never) => _,\n /* c8 ignore next */\n _In: (_: unknown) => _,\n /* c8 ignore next */\n _L: (_: never) => _,\n /* c8 ignore next */\n _E: (_: never) => _,\n /* c8 ignore next */\n _R: (_: never) => _\n}\n\nconst channelVariance = {\n /* c8 ignore next */\n _Env: (_: never) => _,\n /* c8 ignore next */\n _InErr: (_: unknown) => _,\n /* c8 ignore next */\n _InElem: (_: unknown) => _,\n /* c8 ignore next */\n _InDone: (_: unknown) => _,\n /* c8 ignore next */\n _OutErr: (_: never) => _,\n /* c8 ignore next */\n _OutElem: (_: never) => _,\n /* c8 ignore next */\n _OutDone: (_: never) => _\n}\n\n/** @internal */\nexport const EffectPrototype: Effect.Effect<never> & Equal.Equal = {\n [EffectTypeId]: effectVariance,\n [StreamTypeId]: effectVariance,\n [SinkTypeId]: sinkVariance,\n [ChannelTypeId]: channelVariance,\n [Equal.symbol](that: any) {\n return this === that\n },\n [Hash.symbol]() {\n return Hash.cached(this, Hash.random(this))\n },\n [Symbol.iterator]() {\n return new SingleShotGen(new YieldWrap(this)) as any\n },\n pipe() {\n return pipeArguments(this, arguments)\n }\n}\n\n/** @internal */\nexport const StructuralPrototype: Equal.Equal = {\n [Hash.symbol]() {\n return Hash.cached(this, Hash.structure(this))\n },\n [Equal.symbol](this: Equal.Equal, that: Equal.Equal) {\n const selfKeys = Object.keys(this)\n const thatKeys = Object.keys(that as object)\n if (selfKeys.length !== thatKeys.length) {\n return false\n }\n for (const key of selfKeys) {\n if (!(key in (that as object) && Equal.equals((this as any)[key], (that as any)[key]))) {\n return false\n }\n }\n return true\n }\n}\n\n/** @internal */\nexport const CommitPrototype: Effect.Effect<never> = {\n ...EffectPrototype,\n _op: OpCodes.OP_COMMIT\n} as any\n\n/** @internal */\nexport const StructuralCommitPrototype: Effect.Effect<never> = {\n ...CommitPrototype,\n ...StructuralPrototype\n} as any\n\n/** @internal */\nexport const Base: Effectable.CommitPrimitive = (function() {\n function Base() {}\n Base.prototype = CommitPrototype\n return Base as any\n})()\n\n/** @internal */\nexport const StructuralBase: Effectable.CommitPrimitive = (function() {\n function Base() {}\n Base.prototype = StructuralCommitPrototype\n return Base as any\n})()\n","/**\n * @since 2.0.0\n */\n\nimport * as Equal from \"../Equal.js\"\nimport * as Hash from \"../Hash.js\"\nimport { format, NodeInspectSymbol, toJSON } from \"../Inspectable.js\"\nimport type * as Option from \"../Option.js\"\nimport { hasProperty } from \"../Predicate.js\"\nimport { EffectPrototype } from \"./effectable.js\"\n\nconst TypeId: Option.TypeId = Symbol.for(\"effect/Option\") as Option.TypeId\n\nconst CommonProto = {\n ...EffectPrototype,\n [TypeId]: {\n _A: (_: never) => _\n },\n [NodeInspectSymbol]<A>(this: Option.Option<A>) {\n return this.toJSON()\n },\n toString<A>(this: Option.Option<A>) {\n return format(this.toJSON())\n }\n}\n\nconst SomeProto = Object.assign(Object.create(CommonProto), {\n _tag: \"Some\",\n _op: \"Some\",\n [Equal.symbol]<A>(this: Option.Some<A>, that: unknown): boolean {\n return isOption(that) && isSome(that) && Equal.equals(this.value, that.value)\n },\n [Hash.symbol]<A>(this: Option.Some<A>) {\n return Hash.cached(this, Hash.combine(Hash.hash(this._tag))(Hash.hash(this.value)))\n },\n toJSON<A>(this: Option.Some<A>) {\n return {\n _id: \"Option\",\n _tag: this._tag,\n value: toJSON(this.value)\n }\n }\n})\n\nconst NoneHash = Hash.hash(\"None\")\nconst NoneProto = Object.assign(Object.create(CommonProto), {\n _tag: \"None\",\n _op: \"None\",\n [Equal.symbol]<A>(this: Option.None<A>, that: unknown): boolean {\n return isOption(that) && isNone(that)\n },\n [Hash.symbol]<A>(this: Option.None<A>) {\n return NoneHash\n },\n toJSON<A>(this: Option.None<A>) {\n return {\n _id: \"Option\",\n _tag: this._tag\n }\n }\n})\n\n/** @internal */\nexport const isOption = (input: unknown): input is Option.Option<unknown> => hasProperty(input, TypeId)\n\n/** @internal */\nexport const isNone = <A>(fa: Option.Option<A>): fa is Option.None<A> => fa._tag === \"None\"\n\n/** @internal */\nexport const isSome = <A>(fa: Option.Option<A>): fa is Option.Some<A> => fa._tag === \"Some\"\n\n/** @internal */\nexport const none: Option.Option<never> = Object.create(NoneProto)\n\n/** @internal */\nexport const some = <A>(value: A): Option.Option<A> => {\n const a = Object.create(SomeProto)\n a.value = value\n return a\n}\n","/**\n * @since 2.0.0\n */\n\nimport type * as Either from \"../Either.js\"\nimport * as Equal from \"../Equal.js\"\nimport { dual } from \"../Function.js\"\nimport * as Hash from \"../Hash.js\"\nimport { format, NodeInspectSymbol, toJSON } from \"../Inspectable.js\"\nimport type { Option } from \"../Option.js\"\nimport { hasProperty } from \"../Predicate.js\"\nimport { EffectPrototype } from \"./effectable.js\"\nimport * as option from \"./option.js\"\n\n/**\n * @internal\n */\nexport const TypeId: Either.TypeId = Symbol.for(\"effect/Either\") as Either.TypeId\n\nconst CommonProto = {\n ...EffectPrototype,\n [TypeId]: {\n _R: (_: never) => _\n },\n [NodeInspectSymbol]<L, R>(this: Either.Either<R, L>) {\n return this.toJSON()\n },\n toString<L, R>(this: Either.Left<L, R>) {\n return format(this.toJSON())\n }\n}\n\nconst RightProto = Object.assign(Object.create(CommonProto), {\n _tag: \"Right\",\n _op: \"Right\",\n [Equal.symbol]<L, R>(this: Either.Right<L, R>, that: unknown): boolean {\n return isEither(that) && isRight(that) && Equal.equals(this.right, that.right)\n },\n [Hash.symbol]<L, R>(this: Either.Right<L, R>) {\n return Hash.combine(Hash.hash(this._tag))(Hash.hash(this.right))\n },\n toJSON<L, R>(this: Either.Right<L, R>) {\n return {\n _id: \"Either\",\n _tag: this._tag,\n right: toJSON(this.right)\n }\n }\n})\n\nconst LeftProto = Object.assign(Object.create(CommonProto), {\n _tag: \"Left\",\n _op: \"Left\",\n [Equal.symbol]<L, R>(this: Either.Left<L, R>, that: unknown): boolean {\n return isEither(that) && isLeft(that) && Equal.equals(this.left, that.left)\n },\n [Hash.symbol]<L, R>(this: Either.Left<L, R>) {\n return Hash.combine(Hash.hash(this._tag))(Hash.hash(this.left))\n },\n toJSON<E, A>(this: Either.Left<E, A>) {\n return {\n _id: \"Either\",\n _tag: this._tag,\n left: toJSON(this.left)\n }\n }\n})\n\n/** @internal */\nexport const isEither = (input: unknown): input is Either.Either<unknown, unknown> => hasProperty(input, TypeId)\n\n/** @internal */\nexport const isLeft = <R, L>(ma: Either.Either<R, L>): ma is Either.Left<L, R> => ma._tag === \"Left\"\n\n/** @internal */\nexport const isRight = <R, L>(ma: Either.Either<R, L>): ma is Either.Right<L, R> => ma._tag === \"Right\"\n\n/** @internal */\nexport const left = <L>(left: L): Either.Either<never, L> => {\n const a = Object.create(LeftProto)\n a.left = left\n return a\n}\n\n/** @internal */\nexport const right = <R>(right: R): Either.Either<R> => {\n const a = Object.create(RightProto)\n a.right = right\n return a\n}\n\n/** @internal */\nexport const getLeft = <R, L>(\n self: Either.Either<R, L>\n): Option<L> => (isRight(self) ? option.none : option.some(self.left))\n\n/** @internal */\nexport const getRight = <R, L>(\n self: Either.Either<R, L>\n): Option<R> => (isLeft(self) ? option.none : option.some(self.right))\n\n/** @internal */\nexport const fromOption: {\n <L>(onNone: () => L): <R>(self: Option<R>) => Either.Either<R, L>\n <R, L>(self: Option<R>, onNone: () => L): Either.Either<R, L>\n} = dual(\n 2,\n <R, L>(self: Option<R>, onNone: () => L): Either.Either<R, L> =>\n option.isNone(self) ? left(onNone()) : right(self.value)\n)\n","/**\n * @since 2.0.0\n */\n\nimport type { NonEmptyArray } from \"../Array.js\"\n\n/** @internal */\nexport const isNonEmptyArray = <A>(self: ReadonlyArray<A>): self is NonEmptyArray<A> => self.length > 0\n","/**\n * This module provides an implementation of the `Order` type class which is used to define a total ordering on some type `A`.\n * An order is defined by a relation `<=`, which obeys the following laws:\n *\n * - either `x <= y` or `y <= x` (totality)\n * - if `x <= y` and `y <= x`, then `x == y` (antisymmetry)\n * - if `x <= y` and `y <= z`, then `x <= z` (transitivity)\n *\n * The truth table for compare is defined as follows:\n *\n * | `x <= y` | `x >= y` | Ordering | |\n * | -------- | -------- | -------- | --------------------- |\n * | `true` | `true` | `0` | corresponds to x == y |\n * | `true` | `false` | `< 0` | corresponds to x < y |\n * | `false` | `true` | `> 0` | corresponds to x > y |\n *\n * @since 2.0.0\n */\nimport { dual } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\n\n/**\n * @category type class\n * @since 2.0.0\n */\nexport interface Order<in A> {\n (self: A, that: A): -1 | 0 | 1\n}\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface OrderTypeLambda extends TypeLambda {\n readonly type: Order<this[\"Target\"]>\n}\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const make = <A>(\n compare: (self: A, that: A) => -1 | 0 | 1\n): Order<A> =>\n(self, that) => self === that ? 0 : compare(self, that)\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const string: Order<string> = make((self, that) => self < that ? -1 : 1)\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const number: Order<number> = make((self, that) => self < that ? -1 : 1)\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const boolean: Order<boolean> = make((self, that) => self < that ? -1 : 1)\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const bigint: Order<bigint> = make((self, that) => self < that ? -1 : 1)\n\n/**\n * @since 2.0.0\n */\nexport const reverse = <A>(O: Order<A>): Order<A> => make((self, that) => O(that, self))\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const combine: {\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(that: Order<A>): (self: Order<A>) => Order<A>\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(self: Order<A>, that: Order<A>): Order<A>\n} = dual(2, <A>(self: Order<A>, that: Order<A>): Order<A> =>\n make((a1, a2) => {\n const out = self(a1, a2)\n if (out !== 0) {\n return out\n }\n return that(a1, a2)\n }))\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const combineMany: {\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(collection: Iterable<Order<A>>): (self: Order<A>) => Order<A>\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(self: Order<A>, collection: Iterable<Order<A>>): Order<A>\n} = dual(2, <A>(self: Order<A>, collection: Iterable<Order<A>>): Order<A> =>\n make((a1, a2) => {\n let out = self(a1, a2)\n if (out !== 0) {\n return out\n }\n for (const O of collection) {\n out = O(a1, a2)\n if (out !== 0) {\n return out\n }\n }\n return out\n }))\n\n/**\n * @since 2.0.0\n */\nexport const empty = <A>(): Order<A> => make(() => 0)\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const combineAll = <A>(collection: Iterable<Order<A>>): Order<A> => combineMany(empty(), collection)\n\n/**\n * @category mapping\n * @since 2.0.0\n */\nexport const mapInput: {\n /**\n * @category mapping\n * @since 2.0.0\n */\n <B, A>(f: (b: B) => A): (self: Order<A>) => Order<B>\n /**\n * @category mapping\n * @since 2.0.0\n */\n <A, B>(self: Order<A>, f: (b: B) => A): Order<B>\n} = dual(\n 2,\n <A, B>(self: Order<A>, f: (b: B) => A): Order<B> => make((b1, b2) => self(f(b1), f(b2)))\n)\n\n/**\n * @category instances\n * @since 2.0.0\n */\nexport const Date: Order<Date> = mapInput(number, (date) => date.getTime())\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const product: {\n <B>(that: Order<B>): <A>(self: Order<A>) => Order<readonly [A, B]> // readonly because invariant\n <A, B>(self: Order<A>, that: Order<B>): Order<readonly [A, B]> // readonly because invariant\n} = dual(2, <A, B>(self: Order<A>, that: Order<B>): Order<readonly [A, B]> =>\n make(([xa, xb], [ya, yb]) => {\n const o = self(xa, ya)\n return o !== 0 ? o : that(xb, yb)\n }))\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const all = <A>(collection: Iterable<Order<A>>): Order<ReadonlyArray<A>> => {\n return make((x, y) => {\n const len = Math.min(x.length, y.length)\n let collectionLength = 0\n for (const O of collection) {\n if (collectionLength >= len) {\n break\n }\n const o = O(x[collectionLength], y[collectionLength])\n if (o !== 0) {\n return o\n }\n collectionLength++\n }\n return 0\n })\n}\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const productMany: {\n <A>(collection: Iterable<Order<A>>): (self: Order<A>) => Order<readonly [A, ...Array<A>]> // readonly because invariant\n <A>(self: Order<A>, collection: Iterable<Order<A>>): Order<readonly [A, ...Array<A>]> // readonly because invariant\n} = dual(2, <A>(self: Order<A>, collection: Iterable<Order<A>>): Order<readonly [A, ...Array<A>]> => {\n const O = all(collection)\n return make((x, y) => {\n const o = self(x[0], y[0])\n return o !== 0 ? o : O(x.slice(1), y.slice(1))\n })\n})\n\n/**\n * Similar to `Promise.all` but operates on `Order`s.\n *\n * ```\n * [Order<A>, Order<B>, ...] -> Order<[A, B, ...]>\n * ```\n *\n * This function creates and returns a new `Order` for a tuple of values based on the given `Order`s for each element in the tuple.\n * The returned `Order` compares two tuples of the same type by applying the corresponding `Order` to each element in the tuple.\n * It is useful when you need to compare two tuples of the same type and you have a specific way of comparing each element\n * of the tuple.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const tuple = <T extends ReadonlyArray<Order<any>>>(\n ...elements: T\n): Order<Readonly<{ [I in keyof T]: [T[I]] extends [Order<infer A>] ? A : never }>> => all(elements) as any\n\n/**\n * This function creates and returns a new `Order` for an array of values based on a given `Order` for the elements of the array.\n * The returned `Order` compares two arrays by applying the given `Order` to each element in the arrays.\n * If all elements are equal, the arrays are then compared based on their length.\n * It is useful when you need to compare two arrays of the same type and you have a specific way of comparing each element of the array.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const array = <A>(O: Order<A>): Order<ReadonlyArray<A>> =>\n make((self, that) => {\n const aLen = self.length\n const bLen = that.length\n const len = Math.min(aLen, bLen)\n for (let i = 0; i < len; i++) {\n const o = O(self[i], that[i])\n if (o !== 0) {\n return o\n }\n }\n return number(aLen, bLen)\n })\n\n/**\n * This function creates and returns a new `Order` for a struct of values based on the given `Order`s\n * for each property in the struct.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const struct = <R extends { readonly [x: string]: Order<any> }>(\n fields: R\n): Order<{ [K in keyof R]: [R[K]] extends [Order<infer A>] ? A : never }> => {\n const keys = Object.keys(fields)\n return make((self, that) => {\n for (const key of keys) {\n const o = fields[key](self[key], that[key])\n if (o !== 0) {\n return o\n }\n }\n return 0\n })\n}\n\n/**\n * Test whether one value is _strictly less than_ another.\n *\n * @since 2.0.0\n */\nexport const lessThan = <A>(O: Order<A>): {\n (that: A): (self: A) => boolean\n (self: A, that: A): boolean\n} => dual(2, (self: A, that: A) => O(self, that) === -1)\n\n/**\n * Test whether one value is _strictly greater than_ another.\n *\n * @since 2.0.0\n */\nexport const greaterThan = <A>(O: Order<A>): {\n (that: A): (self: A) => boolean\n (self: A, that: A): boolean\n} => dual(2, (self: A, that: A) => O(self, that) === 1)\n\n/**\n * Test whether one value is _non-strictly less than_ another.\n *\n * @since 2.0.0\n */\nexport const lessThanOrEqualTo = <A>(O: Order<A>): {\n (that: A): (self: A) => boolean\n (self: A, that: A): boolean\n} => dual(2, (self: A, that: A) => O(self, that) !== 1)\n\n/**\n * Test whether one value is _non-strictly greater than_ another.\n *\n * @since 2.0.0\n */\nexport const greaterThanOrEqualTo = <A>(O: Order<A>): {\n (that: A): (self: A) => boolean\n (self: A, that: A): boolean\n} => dual(2, (self: A, that: A) => O(self, that) !== -1)\n\n/**\n * Take the minimum of two values. If they are considered equal, the first argument is chosen.\n *\n * @since 2.0.0\n */\nexport const min = <A>(O: Order<A>): {\n (that: A): (self: A) => A\n (self: A, that: A): A\n} => dual(2, (self: A, that: A) => self === that || O(self, that) < 1 ? self : that)\n\n/**\n * Take the maximum of two values. If they are considered equal, the first argument is chosen.\n *\n * @since 2.0.0\n */\nexport const max = <A>(O: Order<A>): {\n (that: A): (self: A) => A\n (self: A, that: A): A\n} => dual(2, (self: A, that: A) => self === that || O(self, that) > -1 ? self : that)\n\n/**\n * Clamp a value between a minimum and a maximum.\n *\n * @example\n * ```ts\n * import { Order, Number } from \"effect\"\n *\n * const clamp = Order.clamp(Number.Order)({ minimum: 1, maximum: 5 })\n *\n * assert.equal(clamp(3), 3)\n * assert.equal(clamp(0), 1)\n * assert.equal(clamp(6), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const clamp = <A>(O: Order<A>): {\n (options: {\n minimum: A\n maximum: A\n }): (self: A) => A\n (self: A, options: {\n minimum: A\n maximum: A\n }): A\n} =>\n dual(\n 2,\n (self: A, options: {\n minimum: A\n maximum: A\n }): A => min(O)(options.maximum, max(O)(options.minimum, self))\n )\n\n/**\n * Test whether a value is between a minimum and a maximum (inclusive).\n *\n * @since 2.0.0\n */\nexport const between = <A>(O: Order<A>): {\n (options: {\n minimum: A\n maximum: A\n }): (self: A) => boolean\n (self: A, options: {\n minimum: A\n maximum: A\n }): boolean\n} =>\n dual(\n 2,\n (self: A, options: {\n minimum: A\n maximum: A\n }): boolean => !lessThan(O)(self, options.minimum) && !greaterThan(O)(self, options.maximum)\n )\n","/**\n * @since 2.0.0\n */\nimport type { Either } from \"./Either.js\"\nimport * as Equal from \"./Equal.js\"\nimport * as Equivalence from \"./Equivalence.js\"\nimport type { LazyArg } from \"./Function.js\"\nimport { constNull, constUndefined, dual, identity, isFunction } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\nimport type { Inspectable } from \"./Inspectable.js\"\nimport * as doNotation from \"./internal/doNotation.js\"\nimport * as either from \"./internal/either.js\"\nimport * as option from \"./internal/option.js\"\nimport type { Order } from \"./Order.js\"\nimport * as order from \"./Order.js\"\nimport type { Pipeable } from \"./Pipeable.js\"\nimport type { Predicate, Refinement } from \"./Predicate.js\"\nimport type { Covariant, NoInfer, NotFunction } from \"./Types.js\"\nimport type * as Unify from \"./Unify.js\"\nimport * as Gen from \"./Utils.js\"\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport type Option<A> = None<A> | Some<A>\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport const TypeId: unique symbol = Symbol.for(\"effect/Option\")\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport type TypeId = typeof TypeId\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface None<out A> extends Pipeable, Inspectable {\n readonly _tag: \"None\"\n readonly _op: \"None\"\n readonly [TypeId]: {\n readonly _A: Covariant<A>\n }\n [Unify.typeSymbol]?: unknown\n [Unify.unifySymbol]?: OptionUnify<this>\n [Unify.ignoreSymbol]?: OptionUnifyIgnore\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Some<out A> extends Pipeable, Inspectable {\n readonly _tag: \"Some\"\n readonly _op: \"Some\"\n readonly value: A\n readonly [TypeId]: {\n readonly _A: Covariant<A>\n }\n [Unify.typeSymbol]?: unknown\n [Unify.unifySymbol]?: OptionUnify<this>\n [Unify.ignoreSymbol]?: OptionUnifyIgnore\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface OptionUnify<A extends { [Unify.typeSymbol]?: any }> {\n Option?: () => A[Unify.typeSymbol] extends Option<infer A0> | infer _ ? Option<A0> : never\n}\n\n/**\n * @since 2.0.0\n */\nexport declare namespace Option {\n /**\n * @since 2.0.0\n * @category type-level\n */\n export type Value<T extends Option<any>> = [T] extends [Option<infer _A>] ? _A : never\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface OptionUnifyIgnore {}\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface OptionTypeLambda extends TypeLambda {\n readonly type: Option<this[\"Target\"]>\n}\n\n/**\n * Creates a new `Option` that represents the absence of a value.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const none = <A = never>(): Option<A> => option.none\n\n/**\n * Creates a new `Option` that wraps the given value.\n *\n * @param value - The value to wrap.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const some: <A>(value: A) => Option<A> = option.some\n\n/**\n * Checks if a given value is an `Option` value.\n *\n * @param input - The value to check.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.isOption(Option.some(1)), true)\n * assert.deepStrictEqual(Option.isOption(Option.none()), true)\n * assert.deepStrictEqual(Option.isOption({}), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isOption: (input: unknown) => input is Option<unknown> = option.isOption\n\n/**\n * Determine if a `Option` is a `None`.\n *\n * @param self - The `Option` to check.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.isNone(Option.some(1)), false)\n * assert.deepStrictEqual(Option.isNone(Option.none()), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNone: <A>(self: Option<A>) => self is None<A> = option.isNone\n\n/**\n * Determine if a `Option` is a `Some`.\n *\n * @param self - The `Option` to check.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.isSome(Option.some(1)), true)\n * assert.deepStrictEqual(Option.isSome(Option.none()), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isSome: <A>(self: Option<A>) => self is Some<A> = option.isSome\n\n/**\n * Matches the given `Option` and returns either the provided `onNone` value or the result of the provided `onSome`\n * function when passed the `Option`'s value.\n *\n * @param self - The `Option` to match\n * @param onNone - The value to be returned if the `Option` is `None`\n * @param onSome - The function to be called if the `Option` is `Some`, it will be passed the `Option`'s value and its result will be returned\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(Option.some(1), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),\n * 'a some containing 1'\n * )\n *\n * assert.deepStrictEqual(\n * pipe(Option.none(), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),\n * 'a none'\n * )\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\nexport const match: {\n /**\n * Matches the given `Option` and returns either the provided `onNone` value or the result of the provided `onSome`\n * function when passed the `Option`'s value.\n *\n * @param self - The `Option` to match\n * @param onNone - The value to be returned if the `Option` is `None`\n * @param onSome - The function to be called if the `Option` is `Some`, it will be passed the `Option`'s value and its result will be returned\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(Option.some(1), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),\n * 'a some containing 1'\n * )\n *\n * assert.deepStrictEqual(\n * pipe(Option.none(), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),\n * 'a none'\n * )\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <B, A, C = B>(\n options: {\n readonly onNone: LazyArg<B>\n readonly onSome: (a: A) => C\n }\n ): (self: Option<A>) => B | C\n /**\n * Matches the given `Option` and returns either the provided `onNone` value or the result of the provided `onSome`\n * function when passed the `Option`'s value.\n *\n * @param self - The `Option` to match\n * @param onNone - The value to be returned if the `Option` is `None`\n * @param onSome - The function to be called if the `Option` is `Some`, it will be passed the `Option`'s value and its result will be returned\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(Option.some(1), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),\n * 'a some containing 1'\n * )\n *\n * assert.deepStrictEqual(\n * pipe(Option.none(), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),\n * 'a none'\n * )\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <A, B, C = B>(\n self: Option<A>,\n options: {\n readonly onNone: LazyArg<B>\n readonly onSome: (a: A) => C\n }\n ): B | C\n} = dual(\n 2,\n <A, B, C = B>(self: Option<A>, { onNone, onSome }: {\n readonly onNone: LazyArg<B>\n readonly onSome: (a: A) => C\n }): B | C => isNone(self) ? onNone() : onSome(self.value)\n)\n\n/**\n * Returns a type guard from a `Option` returning function.\n * This function ensures that a type guard definition is type-safe.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const parsePositive = (n: number): Option.Option<number> =>\n * n > 0 ? Option.some(n) : Option.none()\n *\n * const isPositive = Option.toRefinement(parsePositive)\n *\n * assert.deepStrictEqual(isPositive(1), true)\n * assert.deepStrictEqual(isPositive(-1), false)\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const toRefinement = <A, B extends A>(f: (a: A) => Option<B>): (a: A) => a is B => (a: A): a is B => isSome(f(a))\n\n/**\n * Converts an `Iterable` of values into an `Option`. Returns the first value of the `Iterable` wrapped in a `Some`\n * if the `Iterable` is not empty, otherwise returns `None`.\n *\n * @param collection - The `Iterable` to be converted to an `Option`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.fromIterable([1, 2, 3]), Option.some(1))\n * assert.deepStrictEqual(Option.fromIterable([]), Option.none())\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const fromIterable = <A>(collection: Iterable<A>): Option<A> => {\n for (const a of collection) {\n return some(a)\n }\n return none()\n}\n\n/**\n * Converts a `Either` to an `Option` discarding the error.\n *\n * @example\n * ```ts\n * import { Option, Either } from \"effect\"\n *\n * assert.deepStrictEqual(Option.getRight(Either.right('ok')), Option.some('ok'))\n * assert.deepStrictEqual(Option.getRight(Either.left('err')), Option.none())\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const getRight: <R, L>(self: Either<R, L>) => Option<R> = either.getRight\n\n/**\n * Converts a `Either` to an `Option` discarding the value.\n *\n * @example\n * ```ts\n * import { Option, Either } from \"effect\"\n *\n * assert.deepStrictEqual(Option.getLeft(Either.right(\"ok\")), Option.none())\n * assert.deepStrictEqual(Option.getLeft(Either.left(\"a\")), Option.some(\"a\"))\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const getLeft: <R, L>(self: Either<R, L>) => Option<L> = either.getLeft\n\n/**\n * Returns the value of the `Option` if it is `Some`, otherwise returns `onNone`\n *\n * @param self - The `Option` to get the value of.\n * @param onNone - Function that returns the default value to return if the `Option` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(pipe(Option.some(1), Option.getOrElse(() => 0)), 1)\n * assert.deepStrictEqual(pipe(Option.none(), Option.getOrElse(() => 0)), 0)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrElse: {\n /**\n * Returns the value of the `Option` if it is `Some`, otherwise returns `onNone`\n *\n * @param self - The `Option` to get the value of.\n * @param onNone - Function that returns the default value to return if the `Option` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(pipe(Option.some(1), Option.getOrElse(() => 0)), 1)\n * assert.deepStrictEqual(pipe(Option.none(), Option.getOrElse(() => 0)), 0)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <B>(onNone: LazyArg<B>): <A>(self: Option<A>) => B | A\n /**\n * Returns the value of the `Option` if it is `Some`, otherwise returns `onNone`\n *\n * @param self - The `Option` to get the value of.\n * @param onNone - Function that returns the default value to return if the `Option` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(pipe(Option.some(1), Option.getOrElse(() => 0)), 1)\n * assert.deepStrictEqual(pipe(Option.none(), Option.getOrElse(() => 0)), 0)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, onNone: LazyArg<B>): A | B\n} = dual(\n 2,\n <A, B>(self: Option<A>, onNone: LazyArg<B>): A | B => isNone(self) ? onNone() : self.value\n)\n\n/**\n * Returns the provided `Option` `that` if `self` is `None`, otherwise returns `self`.\n *\n * @param self - The first `Option` to be checked.\n * @param that - The `Option` to return if `self` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElse(() => Option.none())\n * ),\n * Option.none()\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElse(() => Option.none())\n * ),\n * Option.some('a')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElse(() => Option.some('b'))\n * ),\n * Option.some('b')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElse(() => Option.some('b'))\n * ),\n * Option.some('a')\n * )\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\nexport const orElse: {\n /**\n * Returns the provided `Option` `that` if `self` is `None`, otherwise returns `self`.\n *\n * @param self - The first `Option` to be checked.\n * @param that - The `Option` to return if `self` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElse(() => Option.none())\n * ),\n * Option.none()\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElse(() => Option.none())\n * ),\n * Option.some('a')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElse(() => Option.some('b'))\n * ),\n * Option.some('b')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElse(() => Option.some('b'))\n * ),\n * Option.some('a')\n * )\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\n <B>(that: LazyArg<Option<B>>): <A>(self: Option<A>) => Option<B | A>\n /**\n * Returns the provided `Option` `that` if `self` is `None`, otherwise returns `self`.\n *\n * @param self - The first `Option` to be checked.\n * @param that - The `Option` to return if `self` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElse(() => Option.none())\n * ),\n * Option.none()\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElse(() => Option.none())\n * ),\n * Option.some('a')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElse(() => Option.some('b'))\n * ),\n * Option.some('b')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElse(() => Option.some('b'))\n * ),\n * Option.some('a')\n * )\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<A | B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<A | B> => isNone(self) ? that() : self\n)\n\n/**\n * Returns the provided default value as `Some` if `self` is `None`, otherwise returns `self`.\n *\n * @param self - The first `Option` to be checked.\n * @param onNone - Function that returns the default value to return if the `Option` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElseSome(() => 'b')\n * ),\n * Option.some('b')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElseSome(() => 'b')\n * ),\n * Option.some('a')\n * )\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\nexport const orElseSome: {\n /**\n * Returns the provided default value as `Some` if `self` is `None`, otherwise returns `self`.\n *\n * @param self - The first `Option` to be checked.\n * @param onNone - Function that returns the default value to return if the `Option` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElseSome(() => 'b')\n * ),\n * Option.some('b')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElseSome(() => 'b')\n * ),\n * Option.some('a')\n * )\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\n <B>(onNone: LazyArg<B>): <A>(self: Option<A>) => Option<B | A>\n /**\n * Returns the provided default value as `Some` if `self` is `None`, otherwise returns `self`.\n *\n * @param self - The first `Option` to be checked.\n * @param onNone - Function that returns the default value to return if the `Option` is `None`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.none(),\n * Option.orElseSome(() => 'b')\n * ),\n * Option.some('b')\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Option.some('a'),\n * Option.orElseSome(() => 'b')\n * ),\n * Option.some('a')\n * )\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, onNone: LazyArg<B>): Option<A | B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, onNone: LazyArg<B>): Option<A | B> => isNone(self) ? some(onNone()) : self\n)\n\n/**\n * Similar to `orElse`, but instead of returning a simple union, it returns an `Either` object,\n * which contains information about which of the two `Option`s has been chosen.\n *\n * This is useful when it's important to know whether the value was retrieved from the first `Option` or the second option.\n *\n * @param self - The first `Option` to be checked.\n * @param that - The second `Option` to be considered if the first `Option` is `None`.\n *\n * @category error handling\n * @since 2.0.0\n */\nexport const orElseEither: {\n /**\n * Similar to `orElse`, but instead of returning a simple union, it returns an `Either` object,\n * which contains information about which of the two `Option`s has been chosen.\n *\n * This is useful when it's important to know whether the value was retrieved from the first `Option` or the second option.\n *\n * @param self - The first `Option` to be checked.\n * @param that - The second `Option` to be considered if the first `Option` is `None`.\n *\n * @category error handling\n * @since 2.0.0\n */\n <B>(that: LazyArg<Option<B>>): <A>(self: Option<A>) => Option<Either<B, A>>\n /**\n * Similar to `orElse`, but instead of returning a simple union, it returns an `Either` object,\n * which contains information about which of the two `Option`s has been chosen.\n *\n * This is useful when it's important to know whether the value was retrieved from the first `Option` or the second option.\n *\n * @param self - The first `Option` to be checked.\n * @param that - The second `Option` to be considered if the first `Option` is `None`.\n *\n * @category error handling\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<Either<B, A>>\n} = dual(\n 2,\n <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<Either<B, A>> =>\n isNone(self) ? map(that(), either.right) : map(self, either.left)\n)\n\n/**\n * Given an `Iterable` collection of `Option`s, returns the first `Some` found in the collection.\n *\n * @param collection - An iterable collection of `Option` to be searched.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.firstSomeOf([Option.none(), Option.some(1), Option.some(2)]), Option.some(1))\n * ```\n *\n * @category error handling\n * @since 2.0.0\n */\nexport const firstSomeOf = <T, C extends Iterable<Option<T>> = Iterable<Option<T>>>(\n collection: C\n): [C] extends [Iterable<Option<infer A>>] ? Option<A> : never => {\n let out: Option<unknown> = none()\n for (out of collection) {\n if (isSome(out)) {\n return out as any\n }\n }\n return out as any\n}\n\n/**\n * Constructs a new `Option` from a nullable type. If the value is `null` or `undefined`, returns `None`, otherwise\n * returns the value wrapped in a `Some`.\n *\n * @param nullableValue - The nullable value to be converted to an `Option`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.fromNullable(undefined), Option.none())\n * assert.deepStrictEqual(Option.fromNullable(null), Option.none())\n * assert.deepStrictEqual(Option.fromNullable(1), Option.some(1))\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const fromNullable = <A>(\n nullableValue: A\n): Option<\n NonNullable<A>\n> => (nullableValue == null ? none() : some(nullableValue as NonNullable<A>))\n\n/**\n * This API is useful for lifting a function that returns `null` or `undefined` into the `Option` context.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const parse = (s: string): number | undefined => {\n * const n = parseFloat(s)\n * return isNaN(n) ? undefined : n\n * }\n *\n * const parseOption = Option.liftNullable(parse)\n *\n * assert.deepStrictEqual(parseOption('1'), Option.some(1))\n * assert.deepStrictEqual(parseOption('not a number'), Option.none())\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const liftNullable = <A extends ReadonlyArray<unknown>, B>(\n f: (...a: A) => B | null | undefined\n): (...a: A) => Option<NonNullable<B>> =>\n(...a) => fromNullable(f(...a))\n\n/**\n * Returns the value of the `Option` if it is a `Some`, otherwise returns `null`.\n *\n * @param self - The `Option` to extract the value from.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.getOrNull(Option.some(1)), 1)\n * assert.deepStrictEqual(Option.getOrNull(Option.none()), null)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrNull: <A>(self: Option<A>) => A | null = getOrElse(constNull)\n\n/**\n * Returns the value of the `Option` if it is a `Some`, otherwise returns `undefined`.\n *\n * @param self - The `Option` to extract the value from.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.getOrUndefined(Option.some(1)), 1)\n * assert.deepStrictEqual(Option.getOrUndefined(Option.none()), undefined)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrUndefined: <A>(self: Option<A>) => A | undefined = getOrElse(constUndefined)\n\n/**\n * A utility function that lifts a function that throws exceptions into a function that returns an `Option`.\n *\n * This function is useful for any function that might throw an exception, allowing the developer to handle\n * the exception in a more functional way.\n *\n * @param f - the function that can throw exceptions.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const parse = Option.liftThrowable(JSON.parse)\n *\n * assert.deepStrictEqual(parse(\"1\"), Option.some(1))\n * assert.deepStrictEqual(parse(\"\"), Option.none())\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const liftThrowable = <A extends ReadonlyArray<unknown>, B>(\n f: (...a: A) => B\n): (...a: A) => Option<B> =>\n(...a) => {\n try {\n return some(f(...a))\n } catch (e) {\n return none()\n }\n}\n\n/**\n * Extracts the value of an `Option` or throws if the `Option` is `None`.\n *\n * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.\n *\n * @param self - The `Option` to extract the value from.\n * @param onNone - A function that will be called if the `Option` is `None`. It returns the error to be thrown.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Option.getOrThrowWith(Option.some(1), () => new Error('Unexpected None')),\n * 1\n * )\n * assert.throws(() => Option.getOrThrowWith(Option.none(), () => new Error('Unexpected None')))\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const getOrThrowWith: {\n /**\n * Extracts the value of an `Option` or throws if the `Option` is `None`.\n *\n * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.\n *\n * @param self - The `Option` to extract the value from.\n * @param onNone - A function that will be called if the `Option` is `None`. It returns the error to be thrown.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Option.getOrThrowWith(Option.some(1), () => new Error('Unexpected None')),\n * 1\n * )\n * assert.throws(() => Option.getOrThrowWith(Option.none(), () => new Error('Unexpected None')))\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\n (onNone: () => unknown): <A>(self: Option<A>) => A\n /**\n * Extracts the value of an `Option` or throws if the `Option` is `None`.\n *\n * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.\n *\n * @param self - The `Option` to extract the value from.\n * @param onNone - A function that will be called if the `Option` is `None`. It returns the error to be thrown.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Option.getOrThrowWith(Option.some(1), () => new Error('Unexpected None')),\n * 1\n * )\n * assert.throws(() => Option.getOrThrowWith(Option.none(), () => new Error('Unexpected None')))\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\n <A>(self: Option<A>, onNone: () => unknown): A\n} = dual(2, <A>(self: Option<A>, onNone: () => unknown): A => {\n if (isSome(self)) {\n return self.value\n }\n throw onNone()\n})\n\n/**\n * Extracts the value of an `Option` or throws if the `Option` is `None`.\n *\n * The thrown error is a default error. To configure the error thrown, see {@link getOrThrowWith}.\n *\n * @param self - The `Option` to extract the value from.\n * @throws `Error(\"getOrThrow called on a None\")`\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.getOrThrow(Option.some(1)), 1)\n * assert.throws(() => Option.getOrThrow(Option.none()))\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const getOrThrow: <A>(self: Option<A>) => A = getOrThrowWith(() => new Error(\"getOrThrow called on a None\"))\n\n/**\n * Maps the `Some` side of an `Option` value to a new `Option` value.\n *\n * @param self - An `Option` to map\n * @param f - The function to map over the value of the `Option`\n *\n * @category mapping\n * @since 2.0.0\n */\nexport const map: {\n /**\n * Maps the `Some` side of an `Option` value to a new `Option` value.\n *\n * @param self - An `Option` to map\n * @param f - The function to map over the value of the `Option`\n *\n * @category mapping\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B): (self: Option<A>) => Option<B>\n /**\n * Maps the `Some` side of an `Option` value to a new `Option` value.\n *\n * @param self - An `Option` to map\n * @param f - The function to map over the value of the `Option`\n *\n * @category mapping\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => B): Option<B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => B): Option<B> => isNone(self) ? none() : some(f(self.value))\n)\n\n/**\n * Maps the `Some` value of this `Option` to the specified constant value.\n *\n * @category mapping\n * @since 2.0.0\n */\nexport const as: {\n /**\n * Maps the `Some` value of this `Option` to the specified constant value.\n *\n * @category mapping\n * @since 2.0.0\n */\n <B>(b: B): <X>(self: Option<X>) => Option<B>\n} = dual(2, <X, B>(self: Option<X>, b: B): Option<B> => map(self, () => b))\n\n/**\n * Maps the `Some` value of this `Option` to the `void` constant value.\n *\n * This is useful when the value of the `Option` is not needed, but the presence or absence of the value is important.\n *\n * @category mapping\n * @since 2.0.0\n */\nexport const asVoid: <_>(self: Option<_>) => Option<void> = as(undefined)\n\nconst void_: Option<void> = some(undefined)\nexport {\n /**\n * @since 2.0.0\n */\n void_ as void\n}\n\n/**\n * Applies a function to the value of an `Option` and flattens the result, if the input is `Some`.\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatMap: {\n /**\n * Applies a function to the value of an `Option` and flattens the result, if the input is `Some`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => Option<B>): (self: Option<A>) => Option<B>\n /**\n * Applies a function to the value of an `Option` and flattens the result, if the input is `Some`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B> => isNone(self) ? none() : f(self.value)\n)\n\n/**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const andThen: {\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => Option<B>): (self: Option<A>) => Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <B>(f: Option<B>): <A>(self: Option<A>) => Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B): (self: Option<A>) => Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <B>(f: NotFunction<B>): <A>(self: Option<A>) => Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: Option<B>): Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => B): Option<B>\n /**\n * Executes a sequence of two `Option`s. The second `Option` can be dependent on the result of the first `Option`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: NotFunction<B>): Option<B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => Option<B> | Option<B>): Option<B> =>\n flatMap(self, (a) => {\n const b = isFunction(f) ? f(a) : f\n return isOption(b) ? b : some(b)\n })\n)\n\n/**\n * This is `flatMap` + `fromNullable`, useful when working with optional values.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * interface Employee {\n * company?: {\n * address?: {\n * street?: {\n * name?: string\n * }\n * }\n * }\n * }\n *\n * const employee1: Employee = { company: { address: { street: { name: 'high street' } } } }\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.some(employee1),\n * Option.flatMapNullable(employee => employee.company?.address?.street?.name),\n * ),\n * Option.some('high street')\n * )\n *\n * const employee2: Employee = { company: { address: { street: {} } } }\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.some(employee2),\n * Option.flatMapNullable(employee => employee.company?.address?.street?.name),\n * ),\n * Option.none()\n * )\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatMapNullable: {\n /**\n * This is `flatMap` + `fromNullable`, useful when working with optional values.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * interface Employee {\n * company?: {\n * address?: {\n * street?: {\n * name?: string\n * }\n * }\n * }\n * }\n *\n * const employee1: Employee = { company: { address: { street: { name: 'high street' } } } }\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.some(employee1),\n * Option.flatMapNullable(employee => employee.company?.address?.street?.name),\n * ),\n * Option.some('high street')\n * )\n *\n * const employee2: Employee = { company: { address: { street: {} } } }\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.some(employee2),\n * Option.flatMapNullable(employee => employee.company?.address?.street?.name),\n * ),\n * Option.none()\n * )\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B | null | undefined): (self: Option<A>) => Option<NonNullable<B>>\n /**\n * This is `flatMap` + `fromNullable`, useful when working with optional values.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * interface Employee {\n * company?: {\n * address?: {\n * street?: {\n * name?: string\n * }\n * }\n * }\n * }\n *\n * const employee1: Employee = { company: { address: { street: { name: 'high street' } } } }\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.some(employee1),\n * Option.flatMapNullable(employee => employee.company?.address?.street?.name),\n * ),\n * Option.some('high street')\n * )\n *\n * const employee2: Employee = { company: { address: { street: {} } } }\n *\n * assert.deepStrictEqual(\n * pipe(\n * Option.some(employee2),\n * Option.flatMapNullable(employee => employee.company?.address?.street?.name),\n * ),\n * Option.none()\n * )\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => B | null | undefined): Option<NonNullable<B>>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => B | null | undefined): Option<NonNullable<B>> =>\n isNone(self) ? none() : fromNullable(f(self.value))\n)\n\n/**\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatten: <A>(self: Option<Option<A>>) => Option<A> = flatMap(identity)\n\n/**\n * @category zipping\n * @since 2.0.0\n */\nexport const zipRight: {\n /**\n * @category zipping\n * @since 2.0.0\n */\n <B>(that: Option<B>): <_>(self: Option<_>) => Option<B>\n /**\n * @category zipping\n * @since 2.0.0\n */\n <X, B>(self: Option<X>, that: Option<B>): Option<B>\n} = dual(2, <X, B>(self: Option<X>, that: Option<B>): Option<B> => flatMap(self, () => that))\n\n/**\n * @category sequencing\n * @since 2.0.0\n */\nexport const composeK: {\n /**\n * @category sequencing\n * @since 2.0.0\n */\n <B, C>(bfc: (b: B) => Option<C>): <A>(afb: (a: A) => Option<B>) => (a: A) => Option<C>\n /**\n * @category sequencing\n * @since 2.0.0\n */\n <A, B, C>(afb: (a: A) => Option<B>, bfc: (b: B) => Option<C>): (a: A) => Option<C>\n} = dual(2, <A, B, C>(afb: (a: A) => Option<B>, bfc: (b: B) => Option<C>) => (a: A): Option<C> => flatMap(afb(a), bfc))\n\n/**\n * Sequences the specified `that` `Option` but ignores its value.\n *\n * It is useful when we want to chain multiple operations, but only care about the result of `self`.\n *\n * @param that - The `Option` that will be ignored in the chain and discarded\n * @param self - The `Option` we care about\n *\n * @category zipping\n * @since 2.0.0\n */\nexport const zipLeft: {\n /**\n * Sequences the specified `that` `Option` but ignores its value.\n *\n * It is useful when we want to chain multiple operations, but only care about the result of `self`.\n *\n * @param that - The `Option` that will be ignored in the chain and discarded\n * @param self - The `Option` we care about\n *\n * @category zipping\n * @since 2.0.0\n */\n <_>(that: Option<_>): <A>(self: Option<A>) => Option<A>\n /**\n * Sequences the specified `that` `Option` but ignores its value.\n *\n * It is useful when we want to chain multiple operations, but only care about the result of `self`.\n *\n * @param that - The `Option` that will be ignored in the chain and discarded\n * @param self - The `Option` we care about\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, X>(self: Option<A>, that: Option<X>): Option<A>\n} = dual(2, <A, X>(self: Option<A>, that: Option<X>): Option<A> => tap(self, () => that))\n\n/**\n * Applies the provided function `f` to the value of the `Option` if it is `Some` and returns the original `Option`\n * unless `f` returns `None`, in which case it returns `None`.\n *\n * This function is useful for performing additional computations on the value of the input `Option` without affecting its value.\n *\n * @param f - Function to apply to the value of the `Option` if it is `Some`\n * @param self - The `Option` to apply the function to\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getInteger = (n: number) => Number.isInteger(n) ? Option.some(n) : Option.none()\n *\n * assert.deepStrictEqual(Option.tap(Option.none(), getInteger), Option.none())\n * assert.deepStrictEqual(Option.tap(Option.some(1), getInteger), Option.some(1))\n * assert.deepStrictEqual(Option.tap(Option.some(1.14), getInteger), Option.none())\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const tap: {\n /**\n * Applies the provided function `f` to the value of the `Option` if it is `Some` and returns the original `Option`\n * unless `f` returns `None`, in which case it returns `None`.\n *\n * This function is useful for performing additional computations on the value of the input `Option` without affecting its value.\n *\n * @param f - Function to apply to the value of the `Option` if it is `Some`\n * @param self - The `Option` to apply the function to\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getInteger = (n: number) => Number.isInteger(n) ? Option.some(n) : Option.none()\n *\n * assert.deepStrictEqual(Option.tap(Option.none(), getInteger), Option.none())\n * assert.deepStrictEqual(Option.tap(Option.some(1), getInteger), Option.some(1))\n * assert.deepStrictEqual(Option.tap(Option.some(1.14), getInteger), Option.none())\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, X>(f: (a: A) => Option<X>): (self: Option<A>) => Option<A>\n /**\n * Applies the provided function `f` to the value of the `Option` if it is `Some` and returns the original `Option`\n * unless `f` returns `None`, in which case it returns `None`.\n *\n * This function is useful for performing additional computations on the value of the input `Option` without affecting its value.\n *\n * @param f - Function to apply to the value of the `Option` if it is `Some`\n * @param self - The `Option` to apply the function to\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getInteger = (n: number) => Number.isInteger(n) ? Option.some(n) : Option.none()\n *\n * assert.deepStrictEqual(Option.tap(Option.none(), getInteger), Option.none())\n * assert.deepStrictEqual(Option.tap(Option.some(1), getInteger), Option.some(1))\n * assert.deepStrictEqual(Option.tap(Option.some(1.14), getInteger), Option.none())\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, X>(self: Option<A>, f: (a: A) => Option<X>): Option<A>\n} = dual(2, <A, X>(self: Option<A>, f: (a: A) => Option<X>): Option<A> => flatMap(self, (a) => map(f(a), () => a)))\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const product = <A, B>(self: Option<A>, that: Option<B>): Option<[A, B]> =>\n isSome(self) && isSome(that) ? some([self.value, that.value]) : none()\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const productMany = <A>(\n self: Option<A>,\n collection: Iterable<Option<A>>\n): Option<[A, ...Array<A>]> => {\n if (isNone(self)) {\n return none()\n }\n const out: [A, ...Array<A>] = [self.value]\n for (const o of collection) {\n if (isNone(o)) {\n return none()\n }\n out.push(o.value)\n }\n return some(out)\n}\n\n/**\n * Takes a structure of `Option`s and returns an `Option` of values with the same structure.\n *\n * - If a tuple is supplied, then the returned `Option` will contain a tuple with the same length.\n * - If a struct is supplied, then the returned `Option` will contain a struct with the same keys.\n * - If an iterable is supplied, then the returned `Option` will contain an array.\n *\n * @param fields - the struct of `Option`s to be sequenced.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.all([Option.some(1), Option.some(2)]), Option.some([1, 2]))\n * assert.deepStrictEqual(Option.all({ a: Option.some(1), b: Option.some(\"hello\") }), Option.some({ a: 1, b: \"hello\" }))\n * assert.deepStrictEqual(Option.all({ a: Option.some(1), b: Option.none() }), Option.none())\n * ```\n *\n * @category combining\n * @since 2.0.0\n */\n// @ts-expect-error\nexport const all: <const I extends Iterable<Option<any>> | Record<string, Option<any>>>(\n input: I\n) => [I] extends [ReadonlyArray<Option<any>>] ? Option<\n { -readonly [K in keyof I]: [I[K]] extends [Option<infer A>] ? A : never }\n >\n : [I] extends [Iterable<Option<infer A>>] ? Option<Array<A>>\n : Option<{ -readonly [K in keyof I]: [I[K]] extends [Option<infer A>] ? A : never }> = (\n input: Iterable<Option<any>> | Record<string, Option<any>>\n ): Option<any> => {\n if (Symbol.iterator in input) {\n const out: Array<Option<any>> = []\n for (const o of (input as Iterable<Option<any>>)) {\n if (isNone(o)) {\n return none()\n }\n out.push(o.value)\n }\n return some(out)\n }\n\n const out: Record<string, any> = {}\n for (const key of Object.keys(input)) {\n const o = input[key]\n if (isNone(o)) {\n return none()\n }\n out[key] = o.value\n }\n return some(out)\n }\n\n/**\n * Zips two `Option` values together using a provided function, returning a new `Option` of the result.\n *\n * @param self - The left-hand side of the zip operation\n * @param that - The right-hand side of the zip operation\n * @param f - The function used to combine the values of the two `Option`s\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * type Complex = [real: number, imaginary: number]\n *\n * const complex = (real: number, imaginary: number): Complex => [real, imaginary]\n *\n * assert.deepStrictEqual(Option.zipWith(Option.none(), Option.none(), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.none(), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.none(), Option.some(1), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.some(2), complex), Option.some([1, 2]))\n *\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), complex)(Option.some(2)), Option.some([2, 1]))\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\nexport const zipWith: {\n /**\n * Zips two `Option` values together using a provided function, returning a new `Option` of the result.\n *\n * @param self - The left-hand side of the zip operation\n * @param that - The right-hand side of the zip operation\n * @param f - The function used to combine the values of the two `Option`s\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * type Complex = [real: number, imaginary: number]\n *\n * const complex = (real: number, imaginary: number): Complex => [real, imaginary]\n *\n * assert.deepStrictEqual(Option.zipWith(Option.none(), Option.none(), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.none(), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.none(), Option.some(1), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.some(2), complex), Option.some([1, 2]))\n *\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), complex)(Option.some(2)), Option.some([2, 1]))\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B, A, C>(that: Option<B>, f: (a: A, b: B) => C): (self: Option<A>) => Option<C>\n /**\n * Zips two `Option` values together using a provided function, returning a new `Option` of the result.\n *\n * @param self - The left-hand side of the zip operation\n * @param that - The right-hand side of the zip operation\n * @param f - The function used to combine the values of the two `Option`s\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * type Complex = [real: number, imaginary: number]\n *\n * const complex = (real: number, imaginary: number): Complex => [real, imaginary]\n *\n * assert.deepStrictEqual(Option.zipWith(Option.none(), Option.none(), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.none(), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.none(), Option.some(1), complex), Option.none())\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), Option.some(2), complex), Option.some([1, 2]))\n *\n * assert.deepStrictEqual(Option.zipWith(Option.some(1), complex)(Option.some(2)), Option.some([2, 1]))\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C>\n} = dual(\n 3,\n <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C> =>\n map(product(self, that), ([a, b]) => f(a, b))\n)\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const ap: {\n /**\n * @category combining\n * @since 2.0.0\n */\n <A>(that: Option<A>): <B>(self: Option<(a: A) => B>) => Option<B>\n /**\n * @category combining\n * @since 2.0.0\n */\n <A, B>(self: Option<(a: A) => B>, that: Option<A>): Option<B>\n} = dual(2, <A, B>(self: Option<(a: A) => B>, that: Option<A>): Option<B> => zipWith(self, that, (f, a) => f(a)))\n\n/**\n * Reduces an `Iterable` of `Option<A>` to a single value of type `B`, elements that are `None` are ignored.\n *\n * @param self - The Iterable of `Option<A>` to be reduced.\n * @param b - The initial value of the accumulator.\n * @param f - The reducing function that takes the current accumulator value and the unwrapped value of an `Option<A>`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const iterable = [Option.some(1), Option.none(), Option.some(2), Option.none()]\n * assert.deepStrictEqual(pipe(iterable, Option.reduceCompact(0, (b, a) => b + a)), 3)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const reduceCompact: {\n /**\n * Reduces an `Iterable` of `Option<A>` to a single value of type `B`, elements that are `None` are ignored.\n *\n * @param self - The Iterable of `Option<A>` to be reduced.\n * @param b - The initial value of the accumulator.\n * @param f - The reducing function that takes the current accumulator value and the unwrapped value of an `Option<A>`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const iterable = [Option.some(1), Option.none(), Option.some(2), Option.none()]\n * assert.deepStrictEqual(pipe(iterable, Option.reduceCompact(0, (b, a) => b + a)), 3)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A) => B): (self: Iterable<Option<A>>) => B\n /**\n * Reduces an `Iterable` of `Option<A>` to a single value of type `B`, elements that are `None` are ignored.\n *\n * @param self - The Iterable of `Option<A>` to be reduced.\n * @param b - The initial value of the accumulator.\n * @param f - The reducing function that takes the current accumulator value and the unwrapped value of an `Option<A>`.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const iterable = [Option.some(1), Option.none(), Option.some(2), Option.none()]\n * assert.deepStrictEqual(pipe(iterable, Option.reduceCompact(0, (b, a) => b + a)), 3)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<Option<A>>, b: B, f: (b: B, a: A) => B): B\n} = dual(\n 3,\n <A, B>(self: Iterable<Option<A>>, b: B, f: (b: B, a: A) => B): B => {\n let out: B = b\n for (const oa of self) {\n if (isSome(oa)) {\n out = f(out, oa.value)\n }\n }\n return out\n }\n)\n\n/**\n * Transforms an `Option` into an `Array`.\n * If the input is `None`, an empty array is returned.\n * If the input is `Some`, the value is wrapped in an array.\n *\n * @param self - The `Option` to convert to an array.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.toArray(Option.some(1)), [1])\n * assert.deepStrictEqual(Option.toArray(Option.none()), [])\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const toArray = <A>(self: Option<A>): Array<A> => isNone(self) ? [] : [self.value]\n\n/**\n * @category filtering\n * @since 2.0.0\n */\nexport const partitionMap: {\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A, B, C>(f: (a: A) => Either<C, B>): (self: Option<A>) => [left: Option<B>, right: Option<C>]\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A, B, C>(self: Option<A>, f: (a: A) => Either<C, B>): [left: Option<B>, right: Option<C>]\n} = dual(2, <A, B, C>(\n self: Option<A>,\n f: (a: A) => Either<C, B>\n): [excluded: Option<B>, satisfying: Option<C>] => {\n if (isNone(self)) {\n return [none(), none()]\n }\n const e = f(self.value)\n return either.isLeft(e) ? [some(e.left), none()] : [none(), some(e.right)]\n})\n\n/**\n * Maps over the value of an `Option` and filters out `None`s.\n *\n * Useful when in addition to filtering you also want to change the type of the `Option`.\n *\n * @param self - The `Option` to map over.\n * @param f - A function to apply to the value of the `Option`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const evenNumber = (n: number) => n % 2 === 0 ? Option.some(n) : Option.none()\n *\n * assert.deepStrictEqual(Option.filterMap(Option.none(), evenNumber), Option.none())\n * assert.deepStrictEqual(Option.filterMap(Option.some(3), evenNumber), Option.none())\n * assert.deepStrictEqual(Option.filterMap(Option.some(2), evenNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const filterMap: {\n /**\n * Maps over the value of an `Option` and filters out `None`s.\n *\n * Useful when in addition to filtering you also want to change the type of the `Option`.\n *\n * @param self - The `Option` to map over.\n * @param f - A function to apply to the value of the `Option`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const evenNumber = (n: number) => n % 2 === 0 ? Option.some(n) : Option.none()\n *\n * assert.deepStrictEqual(Option.filterMap(Option.none(), evenNumber), Option.none())\n * assert.deepStrictEqual(Option.filterMap(Option.some(3), evenNumber), Option.none())\n * assert.deepStrictEqual(Option.filterMap(Option.some(2), evenNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => Option<B>): (self: Option<A>) => Option<B>\n /**\n * Maps over the value of an `Option` and filters out `None`s.\n *\n * Useful when in addition to filtering you also want to change the type of the `Option`.\n *\n * @param self - The `Option` to map over.\n * @param f - A function to apply to the value of the `Option`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const evenNumber = (n: number) => n % 2 === 0 ? Option.some(n) : Option.none()\n *\n * assert.deepStrictEqual(Option.filterMap(Option.none(), evenNumber), Option.none())\n * assert.deepStrictEqual(Option.filterMap(Option.some(3), evenNumber), Option.none())\n * assert.deepStrictEqual(Option.filterMap(Option.some(2), evenNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B> => isNone(self) ? none() : f(self.value)\n)\n\n/**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @param predicate - A predicate function to apply to the `Option` value.\n * @param fb - The `Option` to filter.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // predicate\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(3), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isEven), Option.some(2))\n *\n * // refinement\n * const isNumber = (v: unknown): v is number => typeof v === \"number\"\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some('hello'), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const filter: {\n /**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @param predicate - A predicate function to apply to the `Option` value.\n * @param fb - The `Option` to filter.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // predicate\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(3), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isEven), Option.some(2))\n *\n * // refinement\n * const isNumber = (v: unknown): v is number => typeof v === \"number\"\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some('hello'), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: Option<A>) => Option<B>\n /**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @param predicate - A predicate function to apply to the `Option` value.\n * @param fb - The `Option` to filter.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // predicate\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(3), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isEven), Option.some(2))\n *\n * // refinement\n * const isNumber = (v: unknown): v is number => typeof v === \"number\"\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some('hello'), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A>(predicate: Predicate<NoInfer<A>>): (self: Option<A>) => Option<A>\n /**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @param predicate - A predicate function to apply to the `Option` value.\n * @param fb - The `Option` to filter.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // predicate\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(3), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isEven), Option.some(2))\n *\n * // refinement\n * const isNumber = (v: unknown): v is number => typeof v === \"number\"\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some('hello'), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(self: Option<A>, refinement: Refinement<A, B>): Option<B>\n /**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @param predicate - A predicate function to apply to the `Option` value.\n * @param fb - The `Option` to filter.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // predicate\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(3), isEven), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isEven), Option.some(2))\n *\n * // refinement\n * const isNumber = (v: unknown): v is number => typeof v === \"number\"\n *\n * assert.deepStrictEqual(Option.filter(Option.none(), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some('hello'), isNumber), Option.none())\n * assert.deepStrictEqual(Option.filter(Option.some(2), isNumber), Option.some(2))\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A>(self: Option<A>, predicate: Predicate<A>): Option<A>\n} = dual(\n 2,\n <A>(self: Option<A>, predicate: Predicate<A>): Option<A> =>\n filterMap(self, (b) => (predicate(b) ? option.some(b) : option.none))\n)\n\n/**\n * @example\n * ```ts\n * import { Option, Number } from \"effect\"\n *\n * const isEquivalent = Option.getEquivalence(Number.Equivalence)\n * assert.deepStrictEqual(isEquivalent(Option.none(), Option.none()), true)\n * assert.deepStrictEqual(isEquivalent(Option.none(), Option.some(1)), false)\n * assert.deepStrictEqual(isEquivalent(Option.some(1), Option.none()), false)\n * assert.deepStrictEqual(isEquivalent(Option.some(1), Option.some(2)), false)\n * assert.deepStrictEqual(isEquivalent(Option.some(1), Option.some(1)), true)\n * ```\n *\n * @category equivalence\n * @since 2.0.0\n */\nexport const getEquivalence = <A>(isEquivalent: Equivalence.Equivalence<A>): Equivalence.Equivalence<Option<A>> =>\n Equivalence.make((x, y) => isNone(x) ? isNone(y) : isNone(y) ? false : isEquivalent(x.value, y.value))\n\n/**\n * The `Order` instance allows `Option` values to be compared with\n * `compare`, whenever there is an `Order` instance for\n * the type the `Option` contains.\n *\n * `None` is considered to be less than any `Some` value.\n *\n * @example\n * ```ts\n * import { pipe, Option, Number } from \"effect\"\n *\n * const O = Option.getOrder(Number.Order)\n * assert.deepStrictEqual(O(Option.none(), Option.none()), 0)\n * assert.deepStrictEqual(O(Option.none(), Option.some(1)), -1)\n * assert.deepStrictEqual(O(Option.some(1), Option.none()), 1)\n * assert.deepStrictEqual(O(Option.some(1), Option.some(2)), -1)\n * assert.deepStrictEqual(O(Option.some(1), Option.some(1)), 0)\n * ```\n *\n * @category sorting\n * @since 2.0.0\n */\nexport const getOrder = <A>(O: Order<A>): Order<Option<A>> =>\n order.make((self, that) => isSome(self) ? (isSome(that) ? O(self.value, that.value) : 1) : -1)\n\n/**\n * Lifts a binary function into `Option`.\n *\n * @param f - The function to lift.\n *\n * @category lifting\n * @since 2.0.0\n */\nexport const lift2 = <A, B, C>(f: (a: A, b: B) => C): {\n (that: Option<B>): (self: Option<A>) => Option<C>\n (self: Option<A>, that: Option<B>): Option<C>\n} => dual(2, (self: Option<A>, that: Option<B>): Option<C> => zipWith(self, that, f))\n\n/**\n * Transforms a `Predicate` function into a `Some` of the input value if the predicate returns `true` or `None`\n * if the predicate returns `false`.\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getOption = Option.liftPredicate((n: number) => n >= 0)\n *\n * assert.deepStrictEqual(getOption(-1), Option.none())\n * assert.deepStrictEqual(getOption(1), Option.some(1))\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\nexport const liftPredicate: { // Note: I intentionally avoid using the NoInfer pattern here.\n <A, B extends A>(refinement: Refinement<A, B>): (a: A) => Option<B>\n /**\n * Transforms a `Predicate` function into a `Some` of the input value if the predicate returns `true` or `None`\n * if the predicate returns `false`.\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getOption = Option.liftPredicate((n: number) => n >= 0)\n *\n * assert.deepStrictEqual(getOption(-1), Option.none())\n * assert.deepStrictEqual(getOption(1), Option.some(1))\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\n <B extends A, A = B>(predicate: Predicate<A>): (b: B) => Option<B>\n /**\n * Transforms a `Predicate` function into a `Some` of the input value if the predicate returns `true` or `None`\n * if the predicate returns `false`.\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getOption = Option.liftPredicate((n: number) => n >= 0)\n *\n * assert.deepStrictEqual(getOption(-1), Option.none())\n * assert.deepStrictEqual(getOption(1), Option.some(1))\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\n <A, B extends A>(self: A, refinement: Refinement<A, B>): Option<B>\n /**\n * Transforms a `Predicate` function into a `Some` of the input value if the predicate returns `true` or `None`\n * if the predicate returns `false`.\n *\n * @param predicate - A `Predicate` function that takes in a value of type `A` and returns a boolean.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getOption = Option.liftPredicate((n: number) => n >= 0)\n *\n * assert.deepStrictEqual(getOption(-1), Option.none())\n * assert.deepStrictEqual(getOption(1), Option.some(1))\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\n <B extends A, A = B>(self: B, predicate: Predicate<A>): Option<B>\n} = dual(\n 2,\n <B extends A, A = B>(b: B, predicate: Predicate<A>): Option<B> => predicate(b) ? some(b) : none()\n)\n\n/**\n * Returns a function that checks if a `Option` contains a given value using a provided `isEquivalent` function.\n *\n * @param equivalent - An `Equivalence` instance to compare values of the `Option`.\n * @param self - The `Option` to apply the comparison to.\n * @param a - The value to compare against the `Option`.\n *\n * @example\n * ```ts\n * import { pipe, Option, Number } from \"effect\"\n *\n * assert.deepStrictEqual(pipe(Option.some(2), Option.containsWith(Number.Equivalence)(2)), true)\n * assert.deepStrictEqual(pipe(Option.some(1), Option.containsWith(Number.Equivalence)(2)), false)\n * assert.deepStrictEqual(pipe(Option.none(), Option.containsWith(Number.Equivalence)(2)), false)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const containsWith = <A>(isEquivalent: (self: A, that: A) => boolean): {\n (a: A): (self: Option<A>) => boolean\n (self: Option<A>, a: A): boolean\n} => dual(2, (self: Option<A>, a: A): boolean => isNone(self) ? false : isEquivalent(self.value, a))\n\nconst _equivalence = Equal.equivalence()\n\n/**\n * Returns a function that checks if an `Option` contains a given value using the default `Equivalence`.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const contains: {\n /**\n * Returns a function that checks if an `Option` contains a given value using the default `Equivalence`.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(a: A): (self: Option<A>) => boolean\n /**\n * Returns a function that checks if an `Option` contains a given value using the default `Equivalence`.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Option<A>, a: A): boolean\n} = containsWith(_equivalence)\n\n/**\n * Check if a value in an `Option` type meets a certain predicate.\n *\n * @param self - The `Option` to check.\n * @param predicate - The condition to check.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(pipe(Option.some(2), Option.exists(isEven)), true)\n * assert.deepStrictEqual(pipe(Option.some(1), Option.exists(isEven)), false)\n * assert.deepStrictEqual(pipe(Option.none(), Option.exists(isEven)), false)\n * ```\n *\n * @since 2.0.0\n */\nexport const exists: {\n /**\n * Check if a value in an `Option` type meets a certain predicate.\n *\n * @param self - The `Option` to check.\n * @param predicate - The condition to check.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(pipe(Option.some(2), Option.exists(isEven)), true)\n * assert.deepStrictEqual(pipe(Option.some(1), Option.exists(isEven)), false)\n * assert.deepStrictEqual(pipe(Option.none(), Option.exists(isEven)), false)\n * ```\n *\n * @since 2.0.0\n */\n <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: Option<A>) => self is Option<B>\n /**\n * Check if a value in an `Option` type meets a certain predicate.\n *\n * @param self - The `Option` to check.\n * @param predicate - The condition to check.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(pipe(Option.some(2), Option.exists(isEven)), true)\n * assert.deepStrictEqual(pipe(Option.some(1), Option.exists(isEven)), false)\n * assert.deepStrictEqual(pipe(Option.none(), Option.exists(isEven)), false)\n * ```\n *\n * @since 2.0.0\n */\n <A>(predicate: Predicate<NoInfer<A>>): (self: Option<A>) => boolean\n /**\n * Check if a value in an `Option` type meets a certain predicate.\n *\n * @param self - The `Option` to check.\n * @param predicate - The condition to check.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(pipe(Option.some(2), Option.exists(isEven)), true)\n * assert.deepStrictEqual(pipe(Option.some(1), Option.exists(isEven)), false)\n * assert.deepStrictEqual(pipe(Option.none(), Option.exists(isEven)), false)\n * ```\n *\n * @since 2.0.0\n */\n <A, B extends A>(self: Option<A>, refinement: Refinement<A, B>): self is Option<B>\n /**\n * Check if a value in an `Option` type meets a certain predicate.\n *\n * @param self - The `Option` to check.\n * @param predicate - The condition to check.\n *\n * @example\n * ```ts\n * import { pipe, Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * assert.deepStrictEqual(pipe(Option.some(2), Option.exists(isEven)), true)\n * assert.deepStrictEqual(pipe(Option.some(1), Option.exists(isEven)), false)\n * assert.deepStrictEqual(pipe(Option.none(), Option.exists(isEven)), false)\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Option<A>, predicate: Predicate<A>): boolean\n} = dual(\n 2,\n <A, B extends A>(self: Option<A>, refinement: Refinement<A, B>): self is Option<B> =>\n isNone(self) ? false : refinement(self.value)\n)\n\n// -------------------------------------------------------------------------------------\n// do notation\n// -------------------------------------------------------------------------------------\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\nexport const bindTo: {\n // -------------------------------------------------------------------------------------\n // do notation\n // -------------------------------------------------------------------------------------\n\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <N extends string>(name: N): <A>(self: Option<A>) => Option<{ [K in N]: A }>\n // -------------------------------------------------------------------------------------\n // do notation\n // -------------------------------------------------------------------------------------\n\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <A, N extends string>(self: Option<A>, name: N): Option<{ [K in N]: A }>\n} = doNotation.bindTo<OptionTypeLambda>(map)\n\nconst let_: {\n <N extends string, A extends object, B>(\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): (self: Option<A>) => Option<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n <A extends object, N extends string, B>(\n self: Option<A>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): Option<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n} = doNotation.let_<OptionTypeLambda>(map)\n\nexport {\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link bindTo}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n *\n * ```\n * @category do notation\n * @since 2.0.0\n */\n let_ as let\n}\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\nexport const bind: {\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <N extends string, A extends object, B>(\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => Option<B>\n ): (self: Option<A>) => Option<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\n <A extends object, N extends string, B>(\n self: Option<A>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => Option<B>\n ): Option<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n} = doNotation.bind<OptionTypeLambda>(map, flatMap)\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @category do notation\n * @since 2.0.0\n */\nexport const Do: Option<{}> = some({})\n\nconst adapter = Gen.adapter<OptionTypeLambda>()\n\n/**\n * @category generators\n * @since 2.0.0\n */\nexport const gen: Gen.Gen<OptionTypeLambda, Gen.Adapter<OptionTypeLambda>> = (...args) => {\n let f: any\n if (args.length === 1) {\n f = args[0]\n } else {\n f = args[1].bind(args[0])\n }\n const iterator = f(adapter)\n let state: IteratorYieldResult<any> | IteratorReturnResult<any> = iterator.next()\n if (state.done) {\n return some(state.value)\n } else {\n let current = state.value\n if (Gen.isGenKind(current)) {\n current = current.value\n } else {\n current = Gen.yieldWrapGet(current)\n }\n if (isNone(current)) {\n return current\n }\n while (!state.done) {\n state = iterator.next(current.value as never)\n if (!state.done) {\n current = state.value\n if (Gen.isGenKind(current)) {\n current = current.value\n } else {\n current = Gen.yieldWrapGet(current)\n }\n if (isNone(current)) {\n return current\n }\n }\n }\n return some(state.value)\n }\n}\n","/**\n * This module provides utility functions for working with arrays in TypeScript.\n *\n * @since 2.0.0\n */\n\nimport type { Either as array_ } from \"./Either.js\"\nimport * as E from \"./Either.js\"\nimport * as Equal from \"./Equal.js\"\nimport * as Equivalence from \"./Equivalence.js\"\nimport type { LazyArg } from \"./Function.js\"\nimport { dual, identity } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\nimport * as readonlyArray from \"./internal/array.js\"\nimport * as doNotation from \"./internal/doNotation.js\"\nimport * as EffectIterable from \"./Iterable.js\"\nimport type { Option } from \"./Option.js\"\nimport * as O from \"./Option.js\"\nimport * as Order from \"./Order.js\"\nimport type { Predicate, Refinement } from \"./Predicate.js\"\nimport { isBoolean } from \"./Predicate.js\"\nimport * as Record from \"./Record.js\"\nimport * as Tuple from \"./Tuple.js\"\nimport type { NoInfer } from \"./Types.js\"\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface ReadonlyArrayTypeLambda extends TypeLambda {\n readonly type: ReadonlyArray<this[\"Target\"]>\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport type NonEmptyReadonlyArray<A> = readonly [A, ...Array<A>]\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport type NonEmptyArray<A> = [A, ...Array<A>]\n\n/**\n * Builds a `NonEmptyArray` from an non-empty collection of elements.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.make(1, 2, 3)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const make = <Elements extends NonEmptyArray<any>>(\n ...elements: Elements\n): NonEmptyArray<Elements[number]> => elements\n\n/**\n * Creates a new `Array` of the specified length.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.allocate<number>(3)\n * assert.deepStrictEqual(result.length, 3)\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const allocate = <A = never>(n: number): Array<A | undefined> => new Array(n)\n\n/**\n * Return a `NonEmptyArray` of length `n` with element `i` initialized with `f(i)`.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * @example\n * ```ts\n * import { makeBy } from \"effect/Array\"\n *\n * assert.deepStrictEqual(makeBy(5, n => n * 2), [0, 2, 4, 6, 8])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const makeBy = <A>(n: number, f: (i: number) => A): NonEmptyArray<A> => {\n const max = Math.max(1, Math.floor(n))\n const out = new Array(max)\n for (let i = 0; i < max; i++) {\n out[i] = f(i)\n }\n return out as NonEmptyArray<A>\n}\n\n/**\n * Return a `NonEmptyArray` containing a range of integers, including both endpoints.\n *\n * @example\n * ```ts\n * import { range } from \"effect/Array\"\n *\n * assert.deepStrictEqual(range(1, 3), [1, 2, 3])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const range = (start: number, end: number): NonEmptyArray<number> =>\n start <= end ? makeBy(end - start + 1, (i) => start + i) : [start]\n\n/**\n * Return a `NonEmptyArray` containing a value repeated the specified number of times.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * assert.deepStrictEqual(Array.replicate(\"a\", 3), [\"a\", \"a\", \"a\"])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const replicate: {\n /**\n * Return a `NonEmptyArray` containing a value repeated the specified number of times.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * assert.deepStrictEqual(Array.replicate(\"a\", 3), [\"a\", \"a\", \"a\"])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n (n: number): <A>(a: A) => NonEmptyArray<A>\n /**\n * Return a `NonEmptyArray` containing a value repeated the specified number of times.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * assert.deepStrictEqual(Array.replicate(\"a\", 3), [\"a\", \"a\", \"a\"])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <A>(a: A, n: number): NonEmptyArray<A>\n} = dual(2, <A>(a: A, n: number): NonEmptyArray<A> => makeBy(n, () => a))\n\n/**\n * Creates a new `Array` from an iterable collection of values.\n * If the input is already an array, it returns the input as-is.\n * Otherwise, it converts the iterable collection to an array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const set = new Set([1, 2, 3])\n * const result = Array.fromIterable(set)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const fromIterable = <A>(collection: Iterable<A>): Array<A> =>\n Array.isArray(collection) ? collection : Array.from(collection)\n\n/**\n * Creates a new `Array` from a value that might not be an iterable.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * assert.deepStrictEqual(Array.ensure(\"a\"), [\"a\"])\n * assert.deepStrictEqual(Array.ensure([\"a\"]), [\"a\"])\n * assert.deepStrictEqual(Array.ensure([\"a\", \"b\", \"c\"]), [\"a\", \"b\", \"c\"])\n * ```\n *\n * @category constructors\n * @since 3.3.0\n */\nexport const ensure = <A>(self: ReadonlyArray<A> | A): Array<A> => Array.isArray(self) ? self : [self as A]\n\n/**\n * Takes a record and returns an array of tuples containing its keys and values.\n *\n * @param self - The record to transform.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const x = { a: 1, b: 2, c: 3 }\n * assert.deepStrictEqual(Array.fromRecord(x), [[\"a\", 1], [\"b\", 2], [\"c\", 3]])\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const fromRecord: <K extends string, A>(self: Readonly<Record<K, A>>) => Array<[K, A]> = Record.toEntries\n\n/**\n * Converts an `Option` to an array.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Array.fromOption(Option.some(1)), [1])\n * assert.deepStrictEqual(Array.fromOption(Option.none()), [])\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const fromOption: <A>(self: Option<A>) => Array<A> = O.toArray\n\n/**\n * Matches the elements of an array, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const match = Array.match({\n * onEmpty: () => \"empty\",\n * onNonEmpty: ([head, ...tail]) => `head: ${head}, tail: ${tail.length}`\n * })\n * assert.deepStrictEqual(match([]), \"empty\")\n * assert.deepStrictEqual(match([1, 2, 3]), \"head: 1, tail: 2\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\nexport const match: {\n /**\n * Matches the elements of an array, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const match = Array.match({\n * onEmpty: () => \"empty\",\n * onNonEmpty: ([head, ...tail]) => `head: ${head}, tail: ${tail.length}`\n * })\n * assert.deepStrictEqual(match([]), \"empty\")\n * assert.deepStrictEqual(match([1, 2, 3]), \"head: 1, tail: 2\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <B, A, C = B>(\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (self: NonEmptyReadonlyArray<A>) => C\n }\n ): (self: ReadonlyArray<A>) => B | C\n /**\n * Matches the elements of an array, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const match = Array.match({\n * onEmpty: () => \"empty\",\n * onNonEmpty: ([head, ...tail]) => `head: ${head}, tail: ${tail.length}`\n * })\n * assert.deepStrictEqual(match([]), \"empty\")\n * assert.deepStrictEqual(match([1, 2, 3]), \"head: 1, tail: 2\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <A, B, C = B>(\n self: ReadonlyArray<A>,\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (self: NonEmptyReadonlyArray<A>) => C\n }\n ): B | C\n} = dual(2, <A, B, C = B>(\n self: ReadonlyArray<A>,\n { onEmpty, onNonEmpty }: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (self: NonEmptyReadonlyArray<A>) => C\n }\n): B | C => isNonEmptyReadonlyArray(self) ? onNonEmpty(self) : onEmpty())\n\n/**\n * Matches the elements of an array from the left, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchLeft = Array.matchLeft({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (head, tail) => `head: ${head}, tail: ${tail.length}`\n * })\n * assert.deepStrictEqual(matchLeft([]), \"empty\")\n * assert.deepStrictEqual(matchLeft([1, 2, 3]), \"head: 1, tail: 2\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\nexport const matchLeft: {\n /**\n * Matches the elements of an array from the left, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchLeft = Array.matchLeft({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (head, tail) => `head: ${head}, tail: ${tail.length}`\n * })\n * assert.deepStrictEqual(matchLeft([]), \"empty\")\n * assert.deepStrictEqual(matchLeft([1, 2, 3]), \"head: 1, tail: 2\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <B, A, C = B>(\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (head: A, tail: Array<A>) => C\n }\n ): (self: ReadonlyArray<A>) => B | C\n /**\n * Matches the elements of an array from the left, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchLeft = Array.matchLeft({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (head, tail) => `head: ${head}, tail: ${tail.length}`\n * })\n * assert.deepStrictEqual(matchLeft([]), \"empty\")\n * assert.deepStrictEqual(matchLeft([1, 2, 3]), \"head: 1, tail: 2\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <A, B, C = B>(\n self: ReadonlyArray<A>,\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (head: A, tail: Array<A>) => C\n }\n ): B | C\n} = dual(2, <A, B, C = B>(\n self: ReadonlyArray<A>,\n { onEmpty, onNonEmpty }: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (head: A, tail: Array<A>) => C\n }\n): B | C => isNonEmptyReadonlyArray(self) ? onNonEmpty(headNonEmpty(self), tailNonEmpty(self)) : onEmpty())\n\n/**\n * Matches the elements of an array from the right, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchRight = Array.matchRight({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (init, last) => `init: ${init.length}, last: ${last}`\n * })\n * assert.deepStrictEqual(matchRight([]), \"empty\")\n * assert.deepStrictEqual(matchRight([1, 2, 3]), \"init: 2, last: 3\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\nexport const matchRight: {\n /**\n * Matches the elements of an array from the right, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchRight = Array.matchRight({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (init, last) => `init: ${init.length}, last: ${last}`\n * })\n * assert.deepStrictEqual(matchRight([]), \"empty\")\n * assert.deepStrictEqual(matchRight([1, 2, 3]), \"init: 2, last: 3\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <B, A, C = B>(\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (init: Array<A>, last: A) => C\n }\n ): (self: ReadonlyArray<A>) => B | C\n /**\n * Matches the elements of an array from the right, applying functions to cases of empty and non-empty arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchRight = Array.matchRight({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (init, last) => `init: ${init.length}, last: ${last}`\n * })\n * assert.deepStrictEqual(matchRight([]), \"empty\")\n * assert.deepStrictEqual(matchRight([1, 2, 3]), \"init: 2, last: 3\")\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <A, B, C = B>(\n self: ReadonlyArray<A>,\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (init: Array<A>, last: A) => C\n }\n ): B | C\n} = dual(2, <A, B, C = B>(\n self: ReadonlyArray<A>,\n { onEmpty, onNonEmpty }: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (init: Array<A>, last: A) => C\n }\n): B | C =>\n isNonEmptyReadonlyArray(self) ?\n onNonEmpty(initNonEmpty(self), lastNonEmpty(self)) :\n onEmpty())\n\n/**\n * Prepend an element to the front of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const original = [2, 3, 4];\n * const result = Array.prepend(original, 1);\n * assert.deepStrictEqual(result, [1, 2, 3, 4]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const prepend: {\n /**\n * Prepend an element to the front of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const original = [2, 3, 4];\n * const result = Array.prepend(original, 1);\n * assert.deepStrictEqual(result, [1, 2, 3, 4]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <B>(head: B): <A>(self: Iterable<A>) => NonEmptyArray<A | B>\n /**\n * Prepend an element to the front of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const original = [2, 3, 4];\n * const result = Array.prepend(original, 1);\n * assert.deepStrictEqual(result, [1, 2, 3, 4]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, head: B): NonEmptyArray<A | B>\n} = dual(2, <A, B>(self: Iterable<A>, head: B): NonEmptyArray<A | B> => [head, ...self])\n\n/**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const prefix = [0, 1];\n * const array = [2, 3];\n * const result = Array.prependAll(array, prefix);\n * assert.deepStrictEqual(result, [0, 1, 2, 3]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const prependAll: {\n /**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const prefix = [0, 1];\n * const array = [2, 3];\n * const result = Array.prependAll(array, prefix);\n * assert.deepStrictEqual(result, [0, 1, 2, 3]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <S extends Iterable<any>, T extends Iterable<any>>(\n that: T\n ): (self: S) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>\n /**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const prefix = [0, 1];\n * const array = [2, 3];\n * const result = Array.prependAll(array, prefix);\n * assert.deepStrictEqual(result, [0, 1, 2, 3]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<A | B>\n /**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const prefix = [0, 1];\n * const array = [2, 3];\n * const result = Array.prependAll(array, prefix);\n * assert.deepStrictEqual(result, [0, 1, 2, 3]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, that: Iterable<B>): NonEmptyArray<A | B>\n /**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const prefix = [0, 1];\n * const array = [2, 3];\n * const result = Array.prependAll(array, prefix);\n * assert.deepStrictEqual(result, [0, 1, 2, 3]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B>\n} = dual(\n 2,\n <A>(self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(that).concat(fromIterable(self))\n)\n\n/**\n * Append an element to the end of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const original = [1, 2, 3];\n * const result = Array.append(original, 4);\n * assert.deepStrictEqual(result, [1, 2, 3, 4]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const append: {\n /**\n * Append an element to the end of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const original = [1, 2, 3];\n * const result = Array.append(original, 4);\n * assert.deepStrictEqual(result, [1, 2, 3, 4]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <B>(last: B): <A>(self: Iterable<A>) => NonEmptyArray<A | B>\n /**\n * Append an element to the end of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const original = [1, 2, 3];\n * const result = Array.append(original, 4);\n * assert.deepStrictEqual(result, [1, 2, 3, 4]);\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, last: B): NonEmptyArray<A | B>\n} = dual(2, <A, B>(self: Iterable<A>, last: B): Array<A | B> => [...self, last])\n\n/**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const appendAll: {\n /**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <S extends Iterable<any>, T extends Iterable<any>>(\n that: T\n ): (self: S) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>\n /**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<A | B>\n /**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, that: Iterable<B>): NonEmptyArray<A | B>\n /**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B>\n} = dual(\n 2,\n <A>(self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(self).concat(fromIterable(that))\n)\n\n/**\n * Accumulates values from an `Iterable` starting from the left, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.scan(numbers, 0, (acc, value) => acc + value)\n * assert.deepStrictEqual(result, [0, 1, 3, 6, 10])\n *\n * // Explanation:\n * // This function starts with the initial value (0 in this case)\n * // and adds each element of the array to this accumulator one by one,\n * // keeping track of the cumulative sum after each addition.\n * // Each of these sums is captured in the resulting array.\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const scan: {\n /**\n * Accumulates values from an `Iterable` starting from the left, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.scan(numbers, 0, (acc, value) => acc + value)\n * assert.deepStrictEqual(result, [0, 1, 3, 6, 10])\n *\n * // Explanation:\n * // This function starts with the initial value (0 in this case)\n * // and adds each element of the array to this accumulator one by one,\n * // keeping track of the cumulative sum after each addition.\n * // Each of these sums is captured in the resulting array.\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A) => B): (self: Iterable<A>) => NonEmptyArray<B>\n /**\n * Accumulates values from an `Iterable` starting from the left, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.scan(numbers, 0, (acc, value) => acc + value)\n * assert.deepStrictEqual(result, [0, 1, 3, 6, 10])\n *\n * // Explanation:\n * // This function starts with the initial value (0 in this case)\n * // and adds each element of the array to this accumulator one by one,\n * // keeping track of the cumulative sum after each addition.\n * // Each of these sums is captured in the resulting array.\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B>\n} = dual(3, <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B> => {\n const out: NonEmptyArray<B> = [b]\n let i = 0\n for (const a of self) {\n out[i + 1] = f(out[i], a)\n i++\n }\n return out\n})\n\n/**\n * Accumulates values from an `Iterable` starting from the right, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.scanRight(numbers, 0, (acc, value) => acc + value)\n * assert.deepStrictEqual(result, [10, 9, 7, 4, 0])\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const scanRight: {\n /**\n * Accumulates values from an `Iterable` starting from the right, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.scanRight(numbers, 0, (acc, value) => acc + value)\n * assert.deepStrictEqual(result, [10, 9, 7, 4, 0])\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A) => B): (self: Iterable<A>) => NonEmptyArray<B>\n /**\n * Accumulates values from an `Iterable` starting from the right, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.scanRight(numbers, 0, (acc, value) => acc + value)\n * assert.deepStrictEqual(result, [10, 9, 7, 4, 0])\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B>\n} = dual(3, <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B> => {\n const input = fromIterable(self)\n const out: NonEmptyArray<B> = new Array(input.length + 1) as any\n out[input.length] = b\n for (let i = input.length - 1; i >= 0; i--) {\n out[i] = f(out[i + 1], input[i])\n }\n return out\n})\n\n/**\n * Determine if `unknown` is an Array.\n *\n * @param self - The value to check.\n *\n * @example\n * ```ts\n * import { isArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isArray(null), false);\n * assert.deepStrictEqual(isArray([1, 2, 3]), true);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isArray: {\n /**\n * Determine if `unknown` is an Array.\n *\n * @param self - The value to check.\n *\n * @example\n * ```ts\n * import { isArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isArray(null), false);\n * assert.deepStrictEqual(isArray([1, 2, 3]), true);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\n (self: unknown): self is Array<unknown>\n /**\n * Determine if `unknown` is an Array.\n *\n * @param self - The value to check.\n *\n * @example\n * ```ts\n * import { isArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isArray(null), false);\n * assert.deepStrictEqual(isArray([1, 2, 3]), true);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\n <T>(self: T): self is Extract<T, ReadonlyArray<any>>\n} = Array.isArray\n\n/**\n * Determine if an `Array` is empty narrowing down the type to `[]`.\n *\n * @param self - The `Array` to check.\n *\n * @example\n * ```ts\n * import { isEmptyArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isEmptyArray([]), true);\n * assert.deepStrictEqual(isEmptyArray([1, 2, 3]), false);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isEmptyArray = <A>(self: Array<A>): self is [] => self.length === 0\n\n/**\n * Determine if a `ReadonlyArray` is empty narrowing down the type to `readonly []`.\n *\n * @param self - The `ReadonlyArray` to check.\n *\n * @example\n * ```ts\n * import { isEmptyReadonlyArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isEmptyReadonlyArray([]), true);\n * assert.deepStrictEqual(isEmptyReadonlyArray([1, 2, 3]), false);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isEmptyReadonlyArray: <A>(self: ReadonlyArray<A>) => self is readonly [] = isEmptyArray as any\n\n/**\n * Determine if an `Array` is non empty narrowing down the type to `NonEmptyArray`.\n *\n * An `Array` is considered to be a `NonEmptyArray` if it contains at least one element.\n *\n * @param self - The `Array` to check.\n *\n * @example\n * ```ts\n * import { isNonEmptyArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isNonEmptyArray([]), false);\n * assert.deepStrictEqual(isNonEmptyArray([1, 2, 3]), true);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNonEmptyArray: <A>(self: Array<A>) => self is NonEmptyArray<A> = readonlyArray.isNonEmptyArray\n\n/**\n * Determine if a `ReadonlyArray` is non empty narrowing down the type to `NonEmptyReadonlyArray`.\n *\n * A `ReadonlyArray` is considered to be a `NonEmptyReadonlyArray` if it contains at least one element.\n *\n * @param self - The `ReadonlyArray` to check.\n *\n * @example\n * ```ts\n * import { isNonEmptyReadonlyArray } from \"effect/Array\"\n *\n * assert.deepStrictEqual(isNonEmptyReadonlyArray([]), false);\n * assert.deepStrictEqual(isNonEmptyReadonlyArray([1, 2, 3]), true);\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNonEmptyReadonlyArray: <A>(self: ReadonlyArray<A>) => self is NonEmptyReadonlyArray<A> =\n readonlyArray.isNonEmptyArray\n\n/**\n * Return the number of elements in a `ReadonlyArray`.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const length = <A>(self: ReadonlyArray<A>): number => self.length\n\nconst isOutOfBound = <A>(i: number, as: ReadonlyArray<A>): boolean => i < 0 || i >= as.length\n\nconst clamp = <A>(i: number, as: ReadonlyArray<A>): number => Math.floor(Math.min(Math.max(0, i), as.length))\n\n/**\n * This function provides a safe way to read a value at a particular index from a `ReadonlyArray`.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const get: {\n /**\n * This function provides a safe way to read a value at a particular index from a `ReadonlyArray`.\n *\n * @category getters\n * @since 2.0.0\n */\n (index: number): <A>(self: ReadonlyArray<A>) => Option<A>\n /**\n * This function provides a safe way to read a value at a particular index from a `ReadonlyArray`.\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: ReadonlyArray<A>, index: number): Option<A>\n} = dual(2, <A>(self: ReadonlyArray<A>, index: number): Option<A> => {\n const i = Math.floor(index)\n return isOutOfBound(i, self) ? O.none() : O.some(self[i])\n})\n\n/**\n * Gets an element unsafely, will throw on out of bounds.\n *\n * @since 2.0.0\n * @category unsafe\n */\nexport const unsafeGet: {\n /**\n * Gets an element unsafely, will throw on out of bounds.\n *\n * @since 2.0.0\n * @category unsafe\n */\n (index: number): <A>(self: ReadonlyArray<A>) => A\n /**\n * Gets an element unsafely, will throw on out of bounds.\n *\n * @since 2.0.0\n * @category unsafe\n */\n <A>(self: ReadonlyArray<A>, index: number): A\n} = dual(2, <A>(self: ReadonlyArray<A>, index: number): A => {\n const i = Math.floor(index)\n if (isOutOfBound(i, self)) {\n throw new Error(`Index ${i} out of bounds`)\n }\n return self[i]\n})\n\n/**\n * Return a tuple containing the first element, and a new `Array` of the remaining elements, if any.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.unprepend([1, 2, 3, 4])\n * assert.deepStrictEqual(result, [1, [2, 3, 4]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const unprepend = <A>(\n self: NonEmptyReadonlyArray<A>\n): [firstElement: A, remainingElements: Array<A>] => [headNonEmpty(self), tailNonEmpty(self)]\n\n/**\n * Return a tuple containing a copy of the `NonEmptyReadonlyArray` without its last element, and that last element.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.unappend([1, 2, 3, 4])\n * assert.deepStrictEqual(result, [[1, 2, 3], 4])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const unappend = <A>(\n self: NonEmptyReadonlyArray<A>\n): [arrayWithoutLastElement: Array<A>, lastElement: A] => [initNonEmpty(self), lastNonEmpty(self)]\n\n/**\n * Get the first element of a `ReadonlyArray`, or `None` if the `ReadonlyArray` is empty.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const head: <A>(self: ReadonlyArray<A>) => Option<A> = get(0)\n\n/**\n * Get the first element of a non empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.headNonEmpty([1, 2, 3, 4])\n * assert.deepStrictEqual(result, 1)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const headNonEmpty: <A>(self: NonEmptyReadonlyArray<A>) => A = unsafeGet(0)\n\n/**\n * Get the last element in a `ReadonlyArray`, or `None` if the `ReadonlyArray` is empty.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const last = <A>(self: ReadonlyArray<A>): Option<A> =>\n isNonEmptyReadonlyArray(self) ? O.some(lastNonEmpty(self)) : O.none()\n\n/**\n * Get the last element of a non empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.lastNonEmpty([1, 2, 3, 4])\n * assert.deepStrictEqual(result, 4)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const lastNonEmpty = <A>(self: NonEmptyReadonlyArray<A>): A => self[self.length - 1]\n\n/**\n * Get all but the first element of an `Iterable`, creating a new `Array`, or `None` if the `Iterable` is empty.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const tail = <A>(self: Iterable<A>): Option<Array<A>> => {\n const input = fromIterable(self)\n return isNonEmptyReadonlyArray(input) ? O.some(tailNonEmpty(input)) : O.none()\n}\n\n/**\n * Get all but the first element of a `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.tailNonEmpty([1, 2, 3, 4])\n * assert.deepStrictEqual(result, [2, 3, 4])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const tailNonEmpty = <A>(self: NonEmptyReadonlyArray<A>): Array<A> => self.slice(1)\n\n/**\n * Get all but the last element of an `Iterable`, creating a new `Array`, or `None` if the `Iterable` is empty.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const init = <A>(self: Iterable<A>): Option<Array<A>> => {\n const input = fromIterable(self)\n return isNonEmptyReadonlyArray(input) ? O.some(initNonEmpty(input)) : O.none()\n}\n\n/**\n * Get all but the last element of a non empty array, creating a new array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.initNonEmpty([1, 2, 3, 4])\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const initNonEmpty = <A>(self: NonEmptyReadonlyArray<A>): Array<A> => self.slice(0, -1)\n\n/**\n * Keep only a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.take(numbers, 3)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const take: {\n /**\n * Keep only a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.take(numbers, 3)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Keep only a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.take(numbers, 3)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n return input.slice(0, clamp(n, input))\n})\n\n/**\n * Keep only a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.takeRight(numbers, 3)\n * assert.deepStrictEqual(result, [3, 4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const takeRight: {\n /**\n * Keep only a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.takeRight(numbers, 3)\n * assert.deepStrictEqual(result, [3, 4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Keep only a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.takeRight(numbers, 3)\n * assert.deepStrictEqual(result, [3, 4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n const i = clamp(n, input)\n return i === 0 ? [] : input.slice(-i)\n})\n\n/**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 3, 2, 4, 1, 2]\n * const result = Array.takeWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [1, 3, 2])\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const takeWhile: {\n /**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 3, 2, 4, 1, 2]\n * const result = Array.takeWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [1, 3, 2])\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Array<B>\n /**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 3, 2, 4, 1, 2]\n * const result = Array.takeWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [1, 3, 2])\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Array<A>\n /**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 3, 2, 4, 1, 2]\n * const result = Array.takeWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [1, 3, 2])\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Array<B>\n /**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 3, 2, 4, 1, 2]\n * const result = Array.takeWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [1, 3, 2])\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A>\n} = dual(2, <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A> => {\n let i = 0\n const out: Array<A> = []\n for (const a of self) {\n if (!predicate(a, i)) {\n break\n }\n out.push(a)\n i++\n }\n return out\n})\n\nconst spanIndex = <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): number => {\n let i = 0\n for (const a of self) {\n if (!predicate(a, i)) {\n break\n }\n i++\n }\n return i\n}\n\n/**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const span: {\n /**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\n <A, B extends A>(\n refinement: (a: NoInfer<A>, i: number) => a is B\n ): (self: Iterable<A>) => [init: Array<B>, rest: Array<Exclude<A, B>>]\n /**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => [init: Array<A>, rest: Array<A>]\n /**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\n <A, B extends A>(\n self: Iterable<A>,\n refinement: (a: A, i: number) => a is B\n ): [init: Array<B>, rest: Array<Exclude<A, B>>]\n /**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [init: Array<A>, rest: Array<A>]\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [init: Array<A>, rest: Array<A>] =>\n splitAt(self, spanIndex(self, predicate))\n)\n\n/**\n * Drop a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.drop(numbers, 2)\n * assert.deepStrictEqual(result, [3, 4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const drop: {\n /**\n * Drop a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.drop(numbers, 2)\n * assert.deepStrictEqual(result, [3, 4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Drop a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.drop(numbers, 2)\n * assert.deepStrictEqual(result, [3, 4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n return input.slice(clamp(n, input), input.length)\n})\n\n/**\n * Drop a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.dropRight(numbers, 2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const dropRight: {\n /**\n * Drop a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.dropRight(numbers, 2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Drop a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.dropRight(numbers, 2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n return input.slice(0, input.length - clamp(n, input))\n})\n\n/**\n * Remove the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.dropWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const dropWhile: {\n /**\n * Remove the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.dropWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Array<A>\n /**\n * Remove the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.dropWhile(numbers, x => x < 4)\n * assert.deepStrictEqual(result, [4, 5])\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A>\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A> =>\n fromIterable(self).slice(spanIndex(self, predicate))\n)\n\n/**\n * Return the first index for which a predicate holds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [5, 3, 8, 9]\n * const result = Array.findFirstIndex(numbers, x => x > 5)\n * assert.deepStrictEqual(result, Option.some(2))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findFirstIndex: {\n /**\n * Return the first index for which a predicate holds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [5, 3, 8, 9]\n * const result = Array.findFirstIndex(numbers, x => x > 5)\n * assert.deepStrictEqual(result, Option.some(2))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option<number>\n /**\n * Return the first index for which a predicate holds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [5, 3, 8, 9]\n * const result = Array.findFirstIndex(numbers, x => x > 5)\n * assert.deepStrictEqual(result, Option.some(2))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<number>\n} = dual(2, <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<number> => {\n let i = 0\n for (const a of self) {\n if (predicate(a, i)) {\n return O.some(i)\n }\n i++\n }\n return O.none()\n})\n\n/**\n * Return the last index for which a predicate holds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 3, 8, 9]\n * const result = Array.findLastIndex(numbers, x => x < 5)\n * assert.deepStrictEqual(result, Option.some(1))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findLastIndex: {\n /**\n * Return the last index for which a predicate holds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 3, 8, 9]\n * const result = Array.findLastIndex(numbers, x => x < 5)\n * assert.deepStrictEqual(result, Option.some(1))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option<number>\n /**\n * Return the last index for which a predicate holds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 3, 8, 9]\n * const result = Array.findLastIndex(numbers, x => x < 5)\n * assert.deepStrictEqual(result, Option.some(1))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<number>\n} = dual(2, <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<number> => {\n const input = fromIterable(self)\n for (let i = input.length - 1; i >= 0; i--) {\n if (predicate(input[i], i)) {\n return O.some(i)\n }\n }\n return O.none()\n})\n\n/**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findFirst: {\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(f: (a: NoInfer<A>, i: number) => Option<B>): (self: Iterable<A>) => Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option<A>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findFirst(numbers, x => x > 3)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<A>\n} = EffectIterable.findFirst\n\n/**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findLast: {\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(f: (a: NoInfer<A>, i: number) => Option<B>): (self: Iterable<A>) => Option<B>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Option<B>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option<A>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Option<B>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Option<B>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.findLast(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, Option.some(4))\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<A>\n} = dual(\n 2,\n <A>(self: Iterable<A>, f: ((a: A, i: number) => boolean) | ((a: A, i: number) => Option<A>)): Option<A> => {\n const input = fromIterable(self)\n for (let i = input.length - 1; i >= 0; i--) {\n const a = input[i]\n const o = f(a, i)\n if (isBoolean(o)) {\n if (o) {\n return O.some(a)\n }\n } else {\n if (O.isSome(o)) {\n return o\n }\n }\n }\n return O.none()\n }\n)\n\n/**\n * Insert an element at the specified index, creating a new `NonEmptyArray`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'e']\n * const result = Array.insertAt(letters, 3, 'd')\n * assert.deepStrictEqual(result, Option.some(['a', 'b', 'c', 'd', 'e']))\n * ```\n *\n * @since 2.0.0\n */\nexport const insertAt: {\n /**\n * Insert an element at the specified index, creating a new `NonEmptyArray`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'e']\n * const result = Array.insertAt(letters, 3, 'd')\n * assert.deepStrictEqual(result, Option.some(['a', 'b', 'c', 'd', 'e']))\n * ```\n *\n * @since 2.0.0\n */\n <B>(i: number, b: B): <A>(self: Iterable<A>) => Option<NonEmptyArray<A | B>>\n /**\n * Insert an element at the specified index, creating a new `NonEmptyArray`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'e']\n * const result = Array.insertAt(letters, 3, 'd')\n * assert.deepStrictEqual(result, Option.some(['a', 'b', 'c', 'd', 'e']))\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, i: number, b: B): Option<NonEmptyArray<A | B>>\n} = dual(3, <A, B>(self: Iterable<A>, i: number, b: B): Option<NonEmptyArray<A | B>> => {\n const out: Array<A | B> = Array.from(self)\n // v--- `= self.length` is ok, it means inserting in last position\n if (i < 0 || i > out.length) {\n return O.none()\n }\n out.splice(i, 0, b)\n return O.some(out) as any\n})\n\n/**\n * Change the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.replace(letters, 1, 'z')\n * assert.deepStrictEqual(result, ['a', 'z', 'c', 'd'])\n * ```\n *\n * @since 2.0.0\n */\nexport const replace: {\n /**\n * Change the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.replace(letters, 1, 'z')\n * assert.deepStrictEqual(result, ['a', 'z', 'c', 'd'])\n * ```\n *\n * @since 2.0.0\n */\n <B>(i: number, b: B): <A, S extends Iterable<A> = Iterable<A>>(\n self: S\n ) => ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n /**\n * Change the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.replace(letters, 1, 'z')\n * assert.deepStrictEqual(result, ['a', 'z', 'c', 'd'])\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(\n self: S,\n i: number,\n b: B\n ): ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n} = dual(3, <A, B>(self: Iterable<A>, i: number, b: B): Array<A | B> => modify(self, i, () => b))\n\n/**\n * Replaces an element in an array with the given value, returning an option of the updated array.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.replaceOption(numbers, 1, 4)\n * assert.deepStrictEqual(result, Option.some([1, 4, 3]))\n * ```\n *\n * @since 2.0.0\n */\nexport const replaceOption: {\n /**\n * Replaces an element in an array with the given value, returning an option of the updated array.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.replaceOption(numbers, 1, 4)\n * assert.deepStrictEqual(result, Option.some([1, 4, 3]))\n * ```\n *\n * @since 2.0.0\n */\n <B>(\n i: number,\n b: B\n ): <A, S extends Iterable<A> = Iterable<A>>(self: S) => Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>\n /**\n * Replaces an element in an array with the given value, returning an option of the updated array.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.replaceOption(numbers, 1, 4)\n * assert.deepStrictEqual(result, Option.some([1, 4, 3]))\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(\n self: S,\n i: number,\n b: B\n ): Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>\n} = dual(\n 3,\n <A, B>(self: Iterable<A>, i: number, b: B): Option<Array<A | B>> => modifyOption(self, i, () => b)\n)\n\n/**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.modify(numbers, 2, (n) => n * 2)\n * assert.deepStrictEqual(result, [1, 2, 6, 4])\n * ```\n *\n * @since 2.0.0\n */\nexport const modify: {\n /**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.modify(numbers, 2, (n) => n * 2)\n * assert.deepStrictEqual(result, [1, 2, 6, 4])\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(\n i: number,\n f: (a: ReadonlyArray.Infer<S>) => B\n ): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n /**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.modify(numbers, 2, (n) => n * 2)\n * assert.deepStrictEqual(result, [1, 2, 6, 4])\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(\n self: S,\n i: number,\n f: (a: ReadonlyArray.Infer<S>) => B\n ): ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n} = dual(\n 3,\n <A, B>(self: Iterable<A>, i: number, f: (a: A) => B): Array<A | B> =>\n O.getOrElse(modifyOption(self, i, f), () => Array.from(self))\n)\n\n/**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.modifyOption(numbers, 2, (n) => n * 2)\n * assert.deepStrictEqual(result, Option.some([1, 2, 6, 4]))\n *\n * const outOfBoundsResult = Array.modifyOption(numbers, 5, (n) => n * 2)\n * assert.deepStrictEqual(outOfBoundsResult, Option.none())\n * ```\n *\n * @since 2.0.0\n */\nexport const modifyOption: {\n /**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.modifyOption(numbers, 2, (n) => n * 2)\n * assert.deepStrictEqual(result, Option.some([1, 2, 6, 4]))\n *\n * const outOfBoundsResult = Array.modifyOption(numbers, 5, (n) => n * 2)\n * assert.deepStrictEqual(outOfBoundsResult, Option.none())\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(\n i: number,\n f: (a: ReadonlyArray.Infer<S>) => B\n ): (self: S) => Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>\n /**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.modifyOption(numbers, 2, (n) => n * 2)\n * assert.deepStrictEqual(result, Option.some([1, 2, 6, 4]))\n *\n * const outOfBoundsResult = Array.modifyOption(numbers, 5, (n) => n * 2)\n * assert.deepStrictEqual(outOfBoundsResult, Option.none())\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(\n self: S,\n i: number,\n f: (a: ReadonlyArray.Infer<S>) => B\n ): Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>\n} = dual(3, <A, B>(self: Iterable<A>, i: number, f: (a: A) => B): Option<Array<A | B>> => {\n const out = Array.from(self)\n if (isOutOfBound(i, out)) {\n return O.none()\n }\n const next = f(out[i])\n // @ts-expect-error\n out[i] = next\n return O.some(out)\n})\n\n/**\n * Delete the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.remove(numbers, 2)\n * assert.deepStrictEqual(result, [1, 2, 4])\n *\n * const outOfBoundsResult = Array.remove(numbers, 5)\n * assert.deepStrictEqual(outOfBoundsResult, [1, 2, 3, 4])\n * ```\n *\n * @since 2.0.0\n */\nexport const remove: {\n /**\n * Delete the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.remove(numbers, 2)\n * assert.deepStrictEqual(result, [1, 2, 4])\n *\n * const outOfBoundsResult = Array.remove(numbers, 5)\n * assert.deepStrictEqual(outOfBoundsResult, [1, 2, 3, 4])\n * ```\n *\n * @since 2.0.0\n */\n (i: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Delete the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.remove(numbers, 2)\n * assert.deepStrictEqual(result, [1, 2, 4])\n *\n * const outOfBoundsResult = Array.remove(numbers, 5)\n * assert.deepStrictEqual(outOfBoundsResult, [1, 2, 3, 4])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, i: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, i: number): Array<A> => {\n const out = Array.from(self)\n if (isOutOfBound(i, out)) {\n return out\n }\n out.splice(i, 1)\n return out\n})\n\n/**\n * Reverse an `Iterable`, creating a new `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.reverse(numbers)\n * assert.deepStrictEqual(result, [4, 3, 2, 1])\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const reverse = <S extends Iterable<any> | NonEmptyReadonlyArray<any>>(\n self: S\n): S extends NonEmptyReadonlyArray<infer A> ? NonEmptyArray<A> : S extends Iterable<infer A> ? Array<A> : never =>\n Array.from(self).reverse() as any\n\n/**\n * Create a new array with elements sorted in increasing order based on the specified comparator.\n * If the input is a `NonEmptyReadonlyArray`, the output will also be a `NonEmptyReadonlyArray`.\n *\n * @category sorting\n * @since 2.0.0\n */\nexport const sort: {\n /**\n * Create a new array with elements sorted in increasing order based on the specified comparator.\n * If the input is a `NonEmptyReadonlyArray`, the output will also be a `NonEmptyReadonlyArray`.\n *\n * @category sorting\n * @since 2.0.0\n */\n <B>(\n O: Order.Order<B>\n ): <A extends B, S extends ReadonlyArray<A> | Iterable<A>>(self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * Create a new array with elements sorted in increasing order based on the specified comparator.\n * If the input is a `NonEmptyReadonlyArray`, the output will also be a `NonEmptyReadonlyArray`.\n *\n * @category sorting\n * @since 2.0.0\n */\n <A extends B, B>(self: NonEmptyReadonlyArray<A>, O: Order.Order<B>): NonEmptyArray<A>\n /**\n * Create a new array with elements sorted in increasing order based on the specified comparator.\n * If the input is a `NonEmptyReadonlyArray`, the output will also be a `NonEmptyReadonlyArray`.\n *\n * @category sorting\n * @since 2.0.0\n */\n <A extends B, B>(self: Iterable<A>, O: Order.Order<B>): Array<A>\n} = dual(2, <A extends B, B>(self: Iterable<A>, O: Order.Order<B>): Array<A> => {\n const out = Array.from(self)\n out.sort(O)\n return out\n})\n\n/**\n * Sorts an array based on a provided mapping function and order. The mapping\n * function transforms the elements into a value that can be compared, and the\n * order defines how those values should be sorted.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const strings = [\"aaa\", \"b\", \"cc\"]\n * const result = Array.sortWith(strings, (s) => s.length, Order.number)\n * assert.deepStrictEqual(result, [\"b\", \"cc\", \"aaa\"])\n *\n * // Explanation:\n * // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`\n * // converts each string into its length, and the `Order.number` specifies that the lengths should\n * // be sorted in ascending order.\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\nexport const sortWith: {\n /**\n * Sorts an array based on a provided mapping function and order. The mapping\n * function transforms the elements into a value that can be compared, and the\n * order defines how those values should be sorted.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const strings = [\"aaa\", \"b\", \"cc\"]\n * const result = Array.sortWith(strings, (s) => s.length, Order.number)\n * assert.deepStrictEqual(result, [\"b\", \"cc\", \"aaa\"])\n *\n * // Explanation:\n * // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`\n * // converts each string into its length, and the `Order.number` specifies that the lengths should\n * // be sorted in ascending order.\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <S extends Iterable<any> | NonEmptyReadonlyArray<any>, B>(\n f: (a: ReadonlyArray.Infer<S>) => B,\n order: Order.Order<B>\n ): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * Sorts an array based on a provided mapping function and order. The mapping\n * function transforms the elements into a value that can be compared, and the\n * order defines how those values should be sorted.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const strings = [\"aaa\", \"b\", \"cc\"]\n * const result = Array.sortWith(strings, (s) => s.length, Order.number)\n * assert.deepStrictEqual(result, [\"b\", \"cc\", \"aaa\"])\n *\n * // Explanation:\n * // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`\n * // converts each string into its length, and the `Order.number` specifies that the lengths should\n * // be sorted in ascending order.\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B, O: Order.Order<B>): NonEmptyArray<A>\n /**\n * Sorts an array based on a provided mapping function and order. The mapping\n * function transforms the elements into a value that can be compared, and the\n * order defines how those values should be sorted.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const strings = [\"aaa\", \"b\", \"cc\"]\n * const result = Array.sortWith(strings, (s) => s.length, Order.number)\n * assert.deepStrictEqual(result, [\"b\", \"cc\", \"aaa\"])\n *\n * // Explanation:\n * // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`\n * // converts each string into its length, and the `Order.number` specifies that the lengths should\n * // be sorted in ascending order.\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B>(self: Iterable<A>, f: (a: A) => B, order: Order.Order<B>): Array<A>\n} = dual(\n 3,\n <A, B>(self: Iterable<A>, f: (a: A) => B, order: Order.Order<B>): Array<A> =>\n Array.from(self).map((a) => [a, f(a)] as const).sort((a, b) => order(a[1], b[1])).map((x) => x[0])\n)\n\n/**\n * Sorts the elements of an `Iterable` in increasing order based on the provided\n * orders. The elements are compared using the first order in `orders`, then the\n * second order if the first comparison is equal, and so on.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const users = [\n * { name: \"Alice\", age: 30 },\n * { name: \"Bob\", age: 25 },\n * { name: \"Charlie\", age: 30 }\n * ]\n *\n * const result = Array.sortBy(\n * Order.mapInput(Order.number, (user: (typeof users)[number]) => user.age),\n * Order.mapInput(Order.string, (user: (typeof users)[number]) => user.name)\n * )(users)\n *\n * assert.deepStrictEqual(result, [\n * { name: \"Bob\", age: 25 },\n * { name: \"Alice\", age: 30 },\n * { name: \"Charlie\", age: 30 }\n * ])\n *\n * // Explanation:\n * // The array of users is sorted first by age in ascending order. When ages are equal,\n * // the users are further sorted by name in ascending order.\n * ```\n *\n * @category sorting\n * @since 2.0.0\n */\nexport const sortBy = <S extends Iterable<any> | NonEmptyReadonlyArray<any>>(\n ...orders: ReadonlyArray<Order.Order<ReadonlyArray.Infer<S>>>\n) => {\n const sortByAll = sort(Order.combineAll(orders))\n return (\n self: S\n ): S extends NonEmptyReadonlyArray<infer A> ? NonEmptyArray<A> : S extends Iterable<infer A> ? Array<A> : never => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n return sortByAll(input) as any\n }\n return [] as any\n }\n}\n\n/**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = ['a', 'b']\n * const result = Array.zip(array1, array2)\n * assert.deepStrictEqual(result, [[1, 'a'], [2, 'b']])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\nexport const zip: {\n /**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = ['a', 'b']\n * const result = Array.zip(array1, array2)\n * assert.deepStrictEqual(result, [[1, 'a'], [2, 'b']])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B>(that: NonEmptyReadonlyArray<B>): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<[A, B]>\n /**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = ['a', 'b']\n * const result = Array.zip(array1, array2)\n * assert.deepStrictEqual(result, [[1, 'a'], [2, 'b']])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B>(that: Iterable<B>): <A>(self: Iterable<A>) => Array<[A, B]>\n /**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = ['a', 'b']\n * const result = Array.zip(array1, array2)\n * assert.deepStrictEqual(result, [[1, 'a'], [2, 'b']])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<[A, B]>\n /**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = ['a', 'b']\n * const result = Array.zip(array1, array2)\n * assert.deepStrictEqual(result, [[1, 'a'], [2, 'b']])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<[A, B]>\n} = dual(\n 2,\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<[A, B]> => zipWith(self, that, Tuple.make)\n)\n\n/**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [4, 5, 6]\n * const result = Array.zipWith(array1, array2, (a, b) => a + b)\n * assert.deepStrictEqual(result, [5, 7, 9])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\nexport const zipWith: {\n /**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [4, 5, 6]\n * const result = Array.zipWith(array1, array2, (a, b) => a + b)\n * assert.deepStrictEqual(result, [5, 7, 9])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B, A, C>(that: NonEmptyReadonlyArray<B>, f: (a: A, b: B) => C): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<C>\n /**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [4, 5, 6]\n * const result = Array.zipWith(array1, array2, (a, b) => a + b)\n * assert.deepStrictEqual(result, [5, 7, 9])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Array<C>\n /**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [4, 5, 6]\n * const result = Array.zipWith(array1, array2, (a, b) => a + b)\n * assert.deepStrictEqual(result, [5, 7, 9])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, B, C>(\n self: NonEmptyReadonlyArray<A>,\n that: NonEmptyReadonlyArray<B>,\n f: (a: A, b: B) => C\n ): NonEmptyArray<C>\n /**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [4, 5, 6]\n * const result = Array.zipWith(array1, array2, (a, b) => a + b)\n * assert.deepStrictEqual(result, [5, 7, 9])\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C>\n} = dual(3, <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C> => {\n const as = fromIterable(self)\n const bs = fromIterable(that)\n if (isNonEmptyReadonlyArray(as) && isNonEmptyReadonlyArray(bs)) {\n const out: NonEmptyArray<C> = [f(headNonEmpty(as), headNonEmpty(bs))]\n const len = Math.min(as.length, bs.length)\n for (let i = 1; i < len; i++) {\n out[i] = f(as[i], bs[i])\n }\n return out\n }\n return []\n})\n\n/**\n * This function is the inverse of `zip`. Takes an `Iterable` of pairs and return two corresponding `Array`s.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.unzip([[1, \"a\"], [2, \"b\"], [3, \"c\"]])\n * assert.deepStrictEqual(result, [[1, 2, 3], ['a', 'b', 'c']])\n * ```\n *\n * @since 2.0.0\n */\nexport const unzip: <S extends Iterable<readonly [any, any]> | NonEmptyReadonlyArray<readonly [any, any]>>(\n self: S\n) => S extends NonEmptyReadonlyArray<readonly [infer A, infer B]> ? [NonEmptyArray<A>, NonEmptyArray<B>]\n : S extends Iterable<readonly [infer A, infer B]> ? [Array<A>, Array<B>]\n : never = (<A, B>(self: Iterable<readonly [A, B]>): [Array<A>, Array<B>] => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const fa: NonEmptyArray<A> = [input[0][0]]\n const fb: NonEmptyArray<B> = [input[0][1]]\n for (let i = 1; i < input.length; i++) {\n fa[i] = input[i][0]\n fb[i] = input[i][1]\n }\n return [fa, fb]\n }\n return [[], []]\n }) as any\n\n/**\n * Places an element in between members of an `Iterable`.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.intersperse(numbers, 0)\n * assert.deepStrictEqual(result, [1, 0, 2, 0, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const intersperse: {\n /**\n * Places an element in between members of an `Iterable`.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.intersperse(numbers, 0)\n * assert.deepStrictEqual(result, [1, 0, 2, 0, 3])\n * ```\n *\n * @since 2.0.0\n */\n <B>(middle: B): <S extends Iterable<any>>(self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n /**\n * Places an element in between members of an `Iterable`.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.intersperse(numbers, 0)\n * assert.deepStrictEqual(result, [1, 0, 2, 0, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, middle: B): NonEmptyArray<A | B>\n /**\n * Places an element in between members of an `Iterable`.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.intersperse(numbers, 0)\n * assert.deepStrictEqual(result, [1, 0, 2, 0, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, middle: B): Array<A | B>\n} = dual(2, <A, B>(self: Iterable<A>, middle: B): Array<A | B> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const out: NonEmptyArray<A | B> = [headNonEmpty(input)]\n const tail = tailNonEmpty(input)\n for (let i = 0; i < tail.length; i++) {\n if (i < tail.length) {\n out.push(middle)\n }\n out.push(tail[i])\n }\n return out\n }\n return []\n})\n\n/**\n * Apply a function to the head, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyHead([1, 2, 3], n => n * 10)\n * assert.deepStrictEqual(result, [10, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const modifyNonEmptyHead: {\n /**\n * Apply a function to the head, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyHead([1, 2, 3], n => n * 10)\n * assert.deepStrictEqual(result, [10, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>\n /**\n * Apply a function to the head, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyHead([1, 2, 3], n => n * 10)\n * assert.deepStrictEqual(result, [10, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B): NonEmptyArray<A | B>\n} = dual(\n 2,\n <A, B>(\n self: NonEmptyReadonlyArray<A>,\n f: (a: A) => B\n ): NonEmptyArray<A | B> => [f(headNonEmpty(self)), ...tailNonEmpty(self)]\n)\n\n/**\n * Change the head, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyHead([1, 2, 3], 10)\n * assert.deepStrictEqual(result, [10, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const setNonEmptyHead: {\n /**\n * Change the head, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyHead([1, 2, 3], 10)\n * assert.deepStrictEqual(result, [10, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <B>(b: B): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>\n /**\n * Change the head, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyHead([1, 2, 3], 10)\n * assert.deepStrictEqual(result, [10, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B>\n} = dual(\n 2,\n <A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B> => modifyNonEmptyHead(self, () => b)\n)\n\n/**\n * Apply a function to the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyLast([1, 2, 3], n => n * 2)\n * assert.deepStrictEqual(result, [1, 2, 6])\n * ```\n *\n * @since 2.0.0\n */\nexport const modifyNonEmptyLast: {\n /**\n * Apply a function to the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyLast([1, 2, 3], n => n * 2)\n * assert.deepStrictEqual(result, [1, 2, 6])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>\n /**\n * Apply a function to the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyLast([1, 2, 3], n => n * 2)\n * assert.deepStrictEqual(result, [1, 2, 6])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B): NonEmptyArray<A | B>\n} = dual(\n 2,\n <A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B): NonEmptyArray<A | B> =>\n append(initNonEmpty(self), f(lastNonEmpty(self)))\n)\n\n/**\n * Change the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyLast([1, 2, 3], 4)\n * assert.deepStrictEqual(result, [1, 2, 4])\n * ```\n *\n * @since 2.0.0\n */\nexport const setNonEmptyLast: {\n /**\n * Change the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyLast([1, 2, 3], 4)\n * assert.deepStrictEqual(result, [1, 2, 4])\n * ```\n *\n * @since 2.0.0\n */\n <B>(b: B): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>\n /**\n * Change the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyLast([1, 2, 3], 4)\n * assert.deepStrictEqual(result, [1, 2, 4])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B>\n} = dual(\n 2,\n <A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B> => modifyNonEmptyLast(self, () => b)\n)\n\n/**\n * Rotate an `Iterable` by `n` steps.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.rotate(letters, 2)\n * assert.deepStrictEqual(result, ['c', 'd', 'a', 'b'])\n * ```\n *\n * @since 2.0.0\n */\nexport const rotate: {\n /**\n * Rotate an `Iterable` by `n` steps.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.rotate(letters, 2)\n * assert.deepStrictEqual(result, ['c', 'd', 'a', 'b'])\n * ```\n *\n * @since 2.0.0\n */\n (n: number): <S extends Iterable<any>>(self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * Rotate an `Iterable` by `n` steps.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.rotate(letters, 2)\n * assert.deepStrictEqual(result, ['c', 'd', 'a', 'b'])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, n: number): NonEmptyArray<A>\n /**\n * Rotate an `Iterable` by `n` steps.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.rotate(letters, 2)\n * assert.deepStrictEqual(result, ['c', 'd', 'a', 'b'])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const len = input.length\n const m = Math.round(n) % len\n if (isOutOfBound(Math.abs(m), input) || m === 0) {\n return copy(input)\n }\n if (m < 0) {\n const [f, s] = splitNonEmptyAt(input, -m)\n return appendAll(s, f)\n } else {\n return rotate(self, m - len)\n }\n }\n return []\n})\n\n/**\n * Returns a function that checks if a `ReadonlyArray` contains a given value using a provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const isEquivalent = (a: number, b: number) => a === b\n * const containsNumber = Array.containsWith(isEquivalent)\n * const result = containsNumber(3)(numbers)\n * assert.deepStrictEqual(result, true)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const containsWith = <A>(isEquivalent: (self: A, that: A) => boolean): {\n (a: A): (self: Iterable<A>) => boolean\n (self: Iterable<A>, a: A): boolean\n} =>\n dual(2, (self: Iterable<A>, a: A): boolean => {\n for (const i of self) {\n if (isEquivalent(a, i)) {\n return true\n }\n }\n return false\n })\n\nconst _equivalence = Equal.equivalence()\n\n/**\n * Returns a function that checks if a `ReadonlyArray` contains a given value using the default `Equivalence`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.contains('c')(letters)\n * assert.deepStrictEqual(result, true)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const contains: {\n /**\n * Returns a function that checks if a `ReadonlyArray` contains a given value using the default `Equivalence`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.contains('c')(letters)\n * assert.deepStrictEqual(result, true)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(a: A): (self: Iterable<A>) => boolean\n /**\n * Returns a function that checks if a `ReadonlyArray` contains a given value using the default `Equivalence`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const letters = ['a', 'b', 'c', 'd']\n * const result = Array.contains('c')(letters)\n * assert.deepStrictEqual(result, true)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, a: A): boolean\n} = containsWith(_equivalence)\n\n/**\n * A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for \"chopping\" up the input\n * `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a\n * value and the rest of the `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chop(numbers, (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * assert.deepStrictEqual(result, [2, 4, 6, 8, 10])\n *\n * // Explanation:\n * // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.\n * // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,\n * // resulting in a new array `[2, 4, 6, 8, 10]`.\n * ```\n *\n * @since 2.0.0\n */\nexport const chop: {\n /**\n * A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for \"chopping\" up the input\n * `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a\n * value and the rest of the `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chop(numbers, (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * assert.deepStrictEqual(result, [2, 4, 6, 8, 10])\n *\n * // Explanation:\n * // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.\n * // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,\n * // resulting in a new array `[2, 4, 6, 8, 10]`.\n * ```\n *\n * @since 2.0.0\n */\n <S extends Iterable<any>, B>(\n f: (as: NonEmptyReadonlyArray<ReadonlyArray.Infer<S>>) => readonly [B, ReadonlyArray<ReadonlyArray.Infer<S>>]\n ): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for \"chopping\" up the input\n * `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a\n * value and the rest of the `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chop(numbers, (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * assert.deepStrictEqual(result, [2, 4, 6, 8, 10])\n *\n * // Explanation:\n * // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.\n * // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,\n * // resulting in a new array `[2, 4, 6, 8, 10]`.\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: NonEmptyReadonlyArray<A>,\n f: (as: NonEmptyReadonlyArray<A>) => readonly [B, ReadonlyArray<A>]\n ): NonEmptyArray<B>\n /**\n * A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for \"chopping\" up the input\n * `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a\n * value and the rest of the `Array`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chop(numbers, (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * assert.deepStrictEqual(result, [2, 4, 6, 8, 10])\n *\n * // Explanation:\n * // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.\n * // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,\n * // resulting in a new array `[2, 4, 6, 8, 10]`.\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: Iterable<A>,\n f: (as: NonEmptyReadonlyArray<A>) => readonly [B, ReadonlyArray<A>]\n ): Array<B>\n} = dual(2, <A, B>(\n self: Iterable<A>,\n f: (as: NonEmptyReadonlyArray<A>) => readonly [B, ReadonlyArray<A>]\n): Array<B> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const [b, rest] = f(input)\n const out: NonEmptyArray<B> = [b]\n let next: ReadonlyArray<A> = rest\n while (readonlyArray.isNonEmptyArray(next)) {\n const [b, rest] = f(next)\n out.push(b)\n next = rest\n }\n return out\n }\n return []\n})\n\n/**\n * Splits an `Iterable` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` can be `0`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.splitAt(numbers, 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const splitAt: {\n /**\n * Splits an `Iterable` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` can be `0`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.splitAt(numbers, 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => [beforeIndex: Array<A>, fromIndex: Array<A>]\n /**\n * Splits an `Iterable` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` can be `0`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.splitAt(numbers, 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): [beforeIndex: Array<A>, fromIndex: Array<A>]\n} = dual(2, <A>(self: Iterable<A>, n: number): [Array<A>, Array<A>] => {\n const input = Array.from(self)\n const _n = Math.floor(n)\n if (isNonEmptyReadonlyArray(input)) {\n if (_n >= 1) {\n return splitNonEmptyAt(input, _n)\n }\n return [[], input]\n }\n return [input, []]\n})\n\n/**\n * Splits a `NonEmptyReadonlyArray` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` must be `>= 1`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitNonEmptyAt([\"a\", \"b\", \"c\", \"d\", \"e\"], 3)\n * assert.deepStrictEqual(result, [[\"a\", \"b\", \"c\"], [\"d\", \"e\"]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const splitNonEmptyAt: {\n /**\n * Splits a `NonEmptyReadonlyArray` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` must be `>= 1`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitNonEmptyAt([\"a\", \"b\", \"c\", \"d\", \"e\"], 3)\n * assert.deepStrictEqual(result, [[\"a\", \"b\", \"c\"], [\"d\", \"e\"]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n (n: number): <A>(self: NonEmptyReadonlyArray<A>) => [beforeIndex: NonEmptyArray<A>, fromIndex: Array<A>]\n /**\n * Splits a `NonEmptyReadonlyArray` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` must be `>= 1`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitNonEmptyAt([\"a\", \"b\", \"c\", \"d\", \"e\"], 3)\n * assert.deepStrictEqual(result, [[\"a\", \"b\", \"c\"], [\"d\", \"e\"]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, n: number): [beforeIndex: NonEmptyArray<A>, fromIndex: Array<A>]\n} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, n: number): [NonEmptyArray<A>, Array<A>] => {\n const _n = Math.max(1, Math.floor(n))\n return _n >= self.length ?\n [copy(self), []] :\n [prepend(self.slice(1, _n), headNonEmpty(self)), self.slice(_n)]\n})\n\n/**\n * Splits this iterable into `n` equally sized arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5, 6, 7, 8]\n * const result = Array.split(numbers, 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5, 6], [7, 8]])\n * ```\n *\n * @since 2.0.0\n * @category splitting\n */\nexport const split: {\n /**\n * Splits this iterable into `n` equally sized arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5, 6, 7, 8]\n * const result = Array.split(numbers, 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5, 6], [7, 8]])\n * ```\n *\n * @since 2.0.0\n * @category splitting\n */\n (n: number): <A>(self: Iterable<A>) => Array<Array<A>>\n /**\n * Splits this iterable into `n` equally sized arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5, 6, 7, 8]\n * const result = Array.split(numbers, 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5, 6], [7, 8]])\n * ```\n *\n * @since 2.0.0\n * @category splitting\n */\n <A>(self: Iterable<A>, n: number): Array<Array<A>>\n} = dual(2, <A>(self: Iterable<A>, n: number) => {\n const input = fromIterable(self)\n return chunksOf(input, Math.ceil(input.length / Math.floor(n)))\n})\n\n/**\n * Splits this iterable on the first element that matches this predicate.\n * Returns a tuple containing two arrays: the first one is before the match, and the second one is from the match onward.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.splitWhere(numbers, n => n > 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const splitWhere: {\n /**\n * Splits this iterable on the first element that matches this predicate.\n * Returns a tuple containing two arrays: the first one is before the match, and the second one is from the match onward.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.splitWhere(numbers, n => n > 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(\n predicate: (a: NoInfer<A>, i: number) => boolean\n ): (self: Iterable<A>) => [beforeMatch: Array<A>, fromMatch: Array<A>]\n /**\n * Splits this iterable on the first element that matches this predicate.\n * Returns a tuple containing two arrays: the first one is before the match, and the second one is from the match onward.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.splitWhere(numbers, n => n > 3)\n * assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [beforeMatch: Array<A>, fromMatch: Array<A>]\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [beforeMatch: Array<A>, fromMatch: Array<A>] =>\n span(self, (a: A, i: number) => !predicate(a, i))\n)\n\n/**\n * Copies an array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const copy = Array.copy(numbers)\n * assert.deepStrictEqual(copy, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const copy: {\n /**\n * Copies an array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const copy = Array.copy(numbers)\n * assert.deepStrictEqual(copy, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>): NonEmptyArray<A>\n /**\n * Copies an array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const copy = Array.copy(numbers)\n * assert.deepStrictEqual(copy, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: ReadonlyArray<A>): Array<A>\n} = (<A>(self: ReadonlyArray<A>): Array<A> => self.slice()) as any\n\n/**\n * Pads an array.\n * Returns a new array of length `n` with the elements of `array` followed by `fill` elements if `array` is shorter than `n`.\n * If `array` is longer than `n`, the returned array will be a slice of `array` containing the `n` first elements of `array`.\n * If `n` is less than or equal to 0, the returned array will be an empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const arr = [1, 2, 3]\n * const result = Array.pad(arr, 6, 0)\n * assert.deepStrictEqual(result, [1, 2, 3, 0, 0, 0])\n * ```\n *\n * @since 3.8.4\n */\nexport const pad: {\n /**\n * Pads an array.\n * Returns a new array of length `n` with the elements of `array` followed by `fill` elements if `array` is shorter than `n`.\n * If `array` is longer than `n`, the returned array will be a slice of `array` containing the `n` first elements of `array`.\n * If `n` is less than or equal to 0, the returned array will be an empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const arr = [1, 2, 3]\n * const result = Array.pad(arr, 6, 0)\n * assert.deepStrictEqual(result, [1, 2, 3, 0, 0, 0])\n * ```\n *\n * @since 3.8.4\n */\n <A, T>(n: number, fill: T): (\n self: Array<A>\n ) => Array<A | T>\n /**\n * Pads an array.\n * Returns a new array of length `n` with the elements of `array` followed by `fill` elements if `array` is shorter than `n`.\n * If `array` is longer than `n`, the returned array will be a slice of `array` containing the `n` first elements of `array`.\n * If `n` is less than or equal to 0, the returned array will be an empty array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const arr = [1, 2, 3]\n * const result = Array.pad(arr, 6, 0)\n * assert.deepStrictEqual(result, [1, 2, 3, 0, 0, 0])\n * ```\n *\n * @since 3.8.4\n */\n <A, T>(self: Array<A>, n: number, fill: T): Array<A | T>\n} = dual(3, <A, T>(self: Array<A>, n: number, fill: T): Array<A | T> => {\n if (self.length >= n) {\n return take(self, n)\n }\n return appendAll(\n self,\n makeBy(n - self.length, () => fill)\n )\n})\n\n/**\n * Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of\n * the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive\n * definition of `chunksOf`; it satisfies the property that\n *\n * ```ts\n * chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))\n * ```\n *\n * whenever `n` evenly divides the length of `self`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chunksOf(numbers, 2)\n * assert.deepStrictEqual(result, [[1, 2], [3, 4], [5]])\n *\n * // Explanation:\n * // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.\n * // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,\n * // the last chunk contains the remaining elements.\n * // The result is `[[1, 2], [3, 4], [5]]`.\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const chunksOf: {\n /**\n * Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of\n * the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive\n * definition of `chunksOf`; it satisfies the property that\n *\n * ```ts\n * chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))\n * ```\n *\n * whenever `n` evenly divides the length of `self`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chunksOf(numbers, 2)\n * assert.deepStrictEqual(result, [[1, 2], [3, 4], [5]])\n *\n * // Explanation:\n * // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.\n * // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,\n * // the last chunk contains the remaining elements.\n * // The result is `[[1, 2], [3, 4], [5]]`.\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n (n: number): <S extends Iterable<any>>(\n self: S\n ) => ReadonlyArray.With<S, NonEmptyArray<ReadonlyArray.Infer<S>>>\n /**\n * Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of\n * the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive\n * definition of `chunksOf`; it satisfies the property that\n *\n * ```ts\n * chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))\n * ```\n *\n * whenever `n` evenly divides the length of `self`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chunksOf(numbers, 2)\n * assert.deepStrictEqual(result, [[1, 2], [3, 4], [5]])\n *\n * // Explanation:\n * // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.\n * // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,\n * // the last chunk contains the remaining elements.\n * // The result is `[[1, 2], [3, 4], [5]]`.\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, n: number): NonEmptyArray<NonEmptyArray<A>>\n /**\n * Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of\n * the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive\n * definition of `chunksOf`; it satisfies the property that\n *\n * ```ts\n * chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))\n * ```\n *\n * whenever `n` evenly divides the length of `self`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * const result = Array.chunksOf(numbers, 2)\n * assert.deepStrictEqual(result, [[1, 2], [3, 4], [5]])\n *\n * // Explanation:\n * // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.\n * // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,\n * // the last chunk contains the remaining elements.\n * // The result is `[[1, 2], [3, 4], [5]]`.\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<NonEmptyArray<A>>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<NonEmptyArray<A>> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n return chop(input, splitNonEmptyAt(n))\n }\n return []\n})\n\n/**\n * Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s using the provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.groupWith([\"a\", \"a\", \"b\", \"b\", \"b\", \"c\", \"a\"], (x, y) => x === y)\n * assert.deepStrictEqual(result, [[\"a\", \"a\"], [\"b\", \"b\", \"b\"], [\"c\"], [\"a\"]])\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\nexport const groupWith: {\n /**\n * Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s using the provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.groupWith([\"a\", \"a\", \"b\", \"b\", \"b\", \"c\", \"a\"], (x, y) => x === y)\n * assert.deepStrictEqual(result, [[\"a\", \"a\"], [\"b\", \"b\", \"b\"], [\"c\"], [\"a\"]])\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\n <A>(isEquivalent: (self: A, that: A) => boolean): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<NonEmptyArray<A>>\n /**\n * Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s using the provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.groupWith([\"a\", \"a\", \"b\", \"b\", \"b\", \"c\", \"a\"], (x, y) => x === y)\n * assert.deepStrictEqual(result, [[\"a\", \"a\"], [\"b\", \"b\", \"b\"], [\"c\"], [\"a\"]])\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\n <A>(\n self: NonEmptyReadonlyArray<A>,\n isEquivalent: (self: A, that: A) => boolean\n ): NonEmptyArray<NonEmptyArray<A>>\n} = dual(\n 2,\n <A>(self: NonEmptyReadonlyArray<A>, isEquivalent: (self: A, that: A) => boolean): NonEmptyArray<NonEmptyArray<A>> =>\n chop(self, (as) => {\n const h = headNonEmpty(as)\n const out: NonEmptyArray<A> = [h]\n let i = 1\n for (; i < as.length; i++) {\n const a = as[i]\n if (isEquivalent(a, h)) {\n out.push(a)\n } else {\n break\n }\n }\n return [out, as.slice(i)]\n })\n)\n\n/**\n * Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.group([1, 1, 2, 2, 2, 3, 1])\n * assert.deepStrictEqual(result, [[1, 1], [2, 2, 2], [3], [1]])\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\nexport const group: <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<NonEmptyArray<A>> = groupWith(\n Equal.equivalence()\n)\n\n/**\n * Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning\n * function on each element, and grouping the results according to values returned\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const people = [\n * { name: \"Alice\", group: \"A\" },\n * { name: \"Bob\", group: \"B\" },\n * { name: \"Charlie\", group: \"A\" }\n * ]\n * const result = Array.groupBy(people, person => person.group)\n * assert.deepStrictEqual(result, {\n * A: [{ name: \"Alice\", group: \"A\" }, { name: \"Charlie\", group: \"A\" }],\n * B: [{ name: \"Bob\", group: \"B\" }]\n * })\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\nexport const groupBy: {\n /**\n * Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning\n * function on each element, and grouping the results according to values returned\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const people = [\n * { name: \"Alice\", group: \"A\" },\n * { name: \"Bob\", group: \"B\" },\n * { name: \"Charlie\", group: \"A\" }\n * ]\n * const result = Array.groupBy(people, person => person.group)\n * assert.deepStrictEqual(result, {\n * A: [{ name: \"Alice\", group: \"A\" }, { name: \"Charlie\", group: \"A\" }],\n * B: [{ name: \"Bob\", group: \"B\" }]\n * })\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\n <A, K extends string | symbol>(\n f: (a: A) => K\n ): (self: Iterable<A>) => Record<Record.ReadonlyRecord.NonLiteralKey<K>, NonEmptyArray<A>>\n /**\n * Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning\n * function on each element, and grouping the results according to values returned\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const people = [\n * { name: \"Alice\", group: \"A\" },\n * { name: \"Bob\", group: \"B\" },\n * { name: \"Charlie\", group: \"A\" }\n * ]\n * const result = Array.groupBy(people, person => person.group)\n * assert.deepStrictEqual(result, {\n * A: [{ name: \"Alice\", group: \"A\" }, { name: \"Charlie\", group: \"A\" }],\n * B: [{ name: \"Bob\", group: \"B\" }]\n * })\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\n <A, K extends string | symbol>(\n self: Iterable<A>,\n f: (a: A) => K\n ): Record<Record.ReadonlyRecord.NonLiteralKey<K>, NonEmptyArray<A>>\n} = dual(2, <A, K extends string | symbol>(\n self: Iterable<A>,\n f: (a: A) => K\n): Record<Record.ReadonlyRecord.NonLiteralKey<K>, NonEmptyArray<A>> => {\n const out: Record<string | symbol, NonEmptyArray<A>> = {}\n for (const a of self) {\n const k = f(a)\n if (Object.prototype.hasOwnProperty.call(out, k)) {\n out[k].push(a)\n } else {\n out[k] = [a]\n }\n }\n return out\n})\n\n/**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const union = Array.unionWith(array1, array2, (a, b) => a === b)\n * assert.deepStrictEqual(union, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const unionWith: {\n /**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const union = Array.unionWith(array1, array2, (a, b) => a === b)\n * assert.deepStrictEqual(union, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <S extends Iterable<any>, T extends Iterable<any>>(\n that: T,\n isEquivalent: (self: ReadonlyArray.Infer<S>, that: ReadonlyArray.Infer<T>) => boolean\n ): (self: S) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>\n /**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const union = Array.unionWith(array1, array2, (a, b) => a === b)\n * assert.deepStrictEqual(union, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: NonEmptyReadonlyArray<A>,\n that: Iterable<B>,\n isEquivalent: (self: A, that: B) => boolean\n ): NonEmptyArray<A | B>\n /**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const union = Array.unionWith(array1, array2, (a, b) => a === b)\n * assert.deepStrictEqual(union, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: Iterable<A>,\n that: NonEmptyReadonlyArray<B>,\n isEquivalent: (self: A, that: B) => boolean\n ): NonEmptyArray<A | B>\n /**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const union = Array.unionWith(array1, array2, (a, b) => a === b)\n * assert.deepStrictEqual(union, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: Iterable<A>,\n that: Iterable<B>,\n isEquivalent: (self: A, that: B) => boolean\n ): Array<A | B>\n} = dual(3, <A>(self: Iterable<A>, that: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A> => {\n const a = fromIterable(self)\n const b = fromIterable(that)\n if (isNonEmptyReadonlyArray(a)) {\n if (isNonEmptyReadonlyArray(b)) {\n const dedupe = dedupeWith(isEquivalent)\n return dedupe(appendAll(a, b))\n }\n return a\n }\n return b\n})\n\n/**\n * Creates a union of two arrays, removing duplicates.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const result = Array.union(array1, array2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const union: {\n /**\n * Creates a union of two arrays, removing duplicates.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const result = Array.union(array1, array2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <T extends Iterable<any>>(that: T): <S extends Iterable<any>>(\n self: S\n ) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>\n /**\n * Creates a union of two arrays, removing duplicates.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const result = Array.union(array1, array2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, that: ReadonlyArray<B>): NonEmptyArray<A | B>\n /**\n * Creates a union of two arrays, removing duplicates.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const result = Array.union(array1, array2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: ReadonlyArray<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<A | B>\n /**\n * Creates a union of two arrays, removing duplicates.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [2, 3]\n * const result = Array.union(array1, array2)\n * assert.deepStrictEqual(result, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B>\n} = dual(2, <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B> => unionWith(self, that, _equivalence))\n\n/**\n * Creates an `Array` of unique values that are included in all given `Iterable`s using the provided `isEquivalent` function.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }]\n * const array2 = [{ id: 3 }, { id: 4 }, { id: 1 }]\n * const isEquivalent = (a: { id: number }, b: { id: number }) => a.id === b.id\n * const result = Array.intersectionWith(isEquivalent)(array2)(array1)\n * assert.deepStrictEqual(result, [{ id: 1 }, { id: 3 }])\n * ```\n *\n * @since 2.0.0\n */\nexport const intersectionWith = <A>(isEquivalent: (self: A, that: A) => boolean): {\n (that: Iterable<A>): (self: Iterable<A>) => Array<A>\n (self: Iterable<A>, that: Iterable<A>): Array<A>\n} => {\n const has = containsWith(isEquivalent)\n return dual(\n 2,\n (self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(self).filter((a) => has(that, a))\n )\n}\n\n/**\n * Creates an `Array` of unique values that are included in all given `Iterable`s.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [3, 4, 1]\n * const result = Array.intersection(array1, array2)\n * assert.deepStrictEqual(result, [1, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const intersection: {\n /**\n * Creates an `Array` of unique values that are included in all given `Iterable`s.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [3, 4, 1]\n * const result = Array.intersection(array1, array2)\n * assert.deepStrictEqual(result, [1, 3])\n * ```\n *\n * @since 2.0.0\n */\n <B>(that: Iterable<B>): <A>(self: Iterable<A>) => Array<A & B>\n /**\n * Creates an `Array` of unique values that are included in all given `Iterable`s.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [3, 4, 1]\n * const result = Array.intersection(array1, array2)\n * assert.deepStrictEqual(result, [1, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A & B>\n} = intersectionWith(_equivalence)\n\n/**\n * Creates a `Array` of values not included in the other given `Iterable` using the provided `isEquivalent` function.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [2, 3, 4]\n * const difference = Array.differenceWith<number>((a, b) => a === b)(array1, array2)\n * assert.deepStrictEqual(difference, [1])\n * ```\n *\n * @since 2.0.0\n */\nexport const differenceWith = <A>(isEquivalent: (self: A, that: A) => boolean): {\n (that: Iterable<A>): (self: Iterable<A>) => Array<A>\n (self: Iterable<A>, that: Iterable<A>): Array<A>\n} => {\n const has = containsWith(isEquivalent)\n return dual(\n 2,\n (self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(self).filter((a) => !has(that, a))\n )\n}\n\n/**\n * Creates a `Array` of values not included in the other given `Iterable`.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [2, 3, 4]\n * const difference = Array.difference(array1, array2)\n * assert.deepStrictEqual(difference, [1])\n * ```\n *\n * @since 2.0.0\n */\nexport const difference: {\n /**\n * Creates a `Array` of values not included in the other given `Iterable`.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [2, 3, 4]\n * const difference = Array.difference(array1, array2)\n * assert.deepStrictEqual(difference, [1])\n * ```\n *\n * @since 2.0.0\n */\n <A>(that: Iterable<A>): (self: Iterable<A>) => Array<A>\n /**\n * Creates a `Array` of values not included in the other given `Iterable`.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [2, 3, 4]\n * const difference = Array.difference(array1, array2)\n * assert.deepStrictEqual(difference, [1])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, that: Iterable<A>): Array<A>\n} = differenceWith(_equivalence)\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const empty: <A = never>() => Array<A> = () => []\n\n/**\n * Constructs a new `NonEmptyArray<A>` from the specified value.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const of = <A>(a: A): NonEmptyArray<A> => [a]\n\n/**\n * @since 2.0.0\n */\nexport declare namespace ReadonlyArray {\n /**\n * @since 2.0.0\n */\n export type Infer<S extends Iterable<any>> = S extends ReadonlyArray<infer A> ? A\n : S extends Iterable<infer A> ? A\n : never\n\n /**\n * @since 2.0.0\n */\n export type With<S extends Iterable<any>, A> = S extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>\n : Array<A>\n\n /**\n * @since 2.0.0\n */\n export type OrNonEmpty<\n S extends Iterable<any>,\n T extends Iterable<any>,\n A\n > = S extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>\n : T extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>\n : Array<A>\n\n /**\n * @since 2.0.0\n */\n export type AndNonEmpty<\n S extends Iterable<any>,\n T extends Iterable<any>,\n A\n > = S extends NonEmptyReadonlyArray<any> ? T extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>\n : Array<A>\n : Array<A>\n\n /**\n * @since 2.0.0\n */\n export type Flatten<T extends ReadonlyArray<ReadonlyArray<any>>> = T extends\n NonEmptyReadonlyArray<NonEmptyReadonlyArray<infer A>> ? NonEmptyArray<A>\n : T extends ReadonlyArray<ReadonlyArray<infer A>> ? Array<A>\n : never\n}\n\n/**\n * @category mapping\n * @since 2.0.0\n */\nexport const map: {\n /**\n * @category mapping\n * @since 2.0.0\n */\n <S extends ReadonlyArray<any>, B>(\n f: (a: ReadonlyArray.Infer<S>, i: number) => B\n ): (self: S) => ReadonlyArray.With<S, B>\n /**\n * @category mapping\n * @since 2.0.0\n */\n <S extends ReadonlyArray<any>, B>(self: S, f: (a: ReadonlyArray.Infer<S>, i: number) => B): ReadonlyArray.With<S, B>\n} = dual(2, <A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => B): Array<B> => self.map(f))\n\n/**\n * Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatMap: {\n /**\n * Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <S extends ReadonlyArray<any>, T extends ReadonlyArray<any>>(\n f: (a: ReadonlyArray.Infer<S>, i: number) => T\n ): (self: S) => ReadonlyArray.AndNonEmpty<S, T, ReadonlyArray.Infer<T>>\n /**\n * Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(\n self: NonEmptyReadonlyArray<A>,\n f: (a: A, i: number) => NonEmptyReadonlyArray<B>\n ): NonEmptyArray<B>\n /**\n * Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => ReadonlyArray<B>): Array<B>\n} = dual(\n 2,\n <A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => ReadonlyArray<B>): Array<B> => {\n if (isEmptyReadonlyArray(self)) {\n return []\n }\n const out: Array<B> = []\n for (let i = 0; i < self.length; i++) {\n const inner = f(self[i], i)\n for (let j = 0; j < inner.length; j++) {\n out.push(inner[j])\n }\n }\n return out\n }\n)\n\n/**\n * Combines multiple arrays into a single array by concatenating all elements\n * from each nested array. This function ensures that the structure of nested\n * arrays is collapsed into a single, flat array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\";\n *\n * const nestedArrays = [[1, 2], [], [3, 4], [], [5, 6]]\n * const result = Array.flatten(nestedArrays)\n *\n * assert.deepStrictEqual(result, [1, 2, 3, 4, 5, 6]);\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatten: <S extends ReadonlyArray<ReadonlyArray<any>>>(self: S) => ReadonlyArray.Flatten<S> = flatMap(\n identity\n) as any\n\n/**\n * Applies a function to each element of the `Iterable` and filters based on the result, keeping the transformed values where the function returns `Some`.\n * This method combines filtering and mapping functionalities, allowing transformations and filtering of elements based on a single function pass.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\";\n *\n * const data = [1, 2, 3, 4, 5];\n * const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();\n * const result = Array.filterMap(data, evenSquares);\n *\n * assert.deepStrictEqual(result, [4, 16]);\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const filterMap: {\n /**\n * Applies a function to each element of the `Iterable` and filters based on the result, keeping the transformed values where the function returns `Some`.\n * This method combines filtering and mapping functionalities, allowing transformations and filtering of elements based on a single function pass.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\";\n *\n * const data = [1, 2, 3, 4, 5];\n * const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();\n * const result = Array.filterMap(data, evenSquares);\n *\n * assert.deepStrictEqual(result, [4, 16]);\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(f: (a: A, i: number) => Option<B>): (self: Iterable<A>) => Array<B>\n /**\n * Applies a function to each element of the `Iterable` and filters based on the result, keeping the transformed values where the function returns `Some`.\n * This method combines filtering and mapping functionalities, allowing transformations and filtering of elements based on a single function pass.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\";\n *\n * const data = [1, 2, 3, 4, 5];\n * const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();\n * const result = Array.filterMap(data, evenSquares);\n *\n * assert.deepStrictEqual(result, [4, 16]);\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Array<B>\n} = dual(\n 2,\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Array<B> => {\n const as = fromIterable(self)\n const out: Array<B> = []\n for (let i = 0; i < as.length; i++) {\n const o = f(as[i], i)\n if (O.isSome(o)) {\n out.push(o.value)\n }\n }\n return out\n }\n)\n\n/**\n * Applies a function to each element of the array and filters based on the result, stopping when a condition is not met.\n * This method combines filtering and mapping in a single pass, and short-circuits, i.e., stops processing, as soon as the function returns `None`.\n * This is useful when you need to transform an array but only up to the point where a certain condition holds true.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\";\n *\n * const data = [2, 4, 5];\n * const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();\n * const result = Array.filterMapWhile(data, toSquareTillOdd);\n *\n * assert.deepStrictEqual(result, [4, 16]);\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const filterMapWhile: {\n /**\n * Applies a function to each element of the array and filters based on the result, stopping when a condition is not met.\n * This method combines filtering and mapping in a single pass, and short-circuits, i.e., stops processing, as soon as the function returns `None`.\n * This is useful when you need to transform an array but only up to the point where a certain condition holds true.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\";\n *\n * const data = [2, 4, 5];\n * const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();\n * const result = Array.filterMapWhile(data, toSquareTillOdd);\n *\n * assert.deepStrictEqual(result, [4, 16]);\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(f: (a: A, i: number) => Option<B>): (self: Iterable<A>) => Array<B>\n /**\n * Applies a function to each element of the array and filters based on the result, stopping when a condition is not met.\n * This method combines filtering and mapping in a single pass, and short-circuits, i.e., stops processing, as soon as the function returns `None`.\n * This is useful when you need to transform an array but only up to the point where a certain condition holds true.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\";\n *\n * const data = [2, 4, 5];\n * const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();\n * const result = Array.filterMapWhile(data, toSquareTillOdd);\n *\n * assert.deepStrictEqual(result, [4, 16]);\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Array<B>\n} = dual(2, <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>) => {\n let i = 0\n const out: Array<B> = []\n for (const a of self) {\n const b = f(a, i)\n if (O.isSome(b)) {\n out.push(b.value)\n } else {\n break\n }\n i++\n }\n return out\n})\n\n/**\n * Applies a function to each element of the `Iterable`, categorizing the results into two separate arrays.\n * This function is particularly useful for operations where each element can result in two possible types,\n * and you want to separate these types into different collections. For instance, separating validation results\n * into successes and failures.\n *\n * @example\n * ```ts\n * import { Array, Either } from \"effect\";\n *\n * const data = [1, 2, 3, 4, 5]\n * const isEven = (x: number) => x % 2 === 0\n * const partitioned = Array.partitionMap(data, x =>\n * isEven(x) ? Either.right(x) : Either.left(x)\n * )\n *\n * assert.deepStrictEqual(partitioned, [\n * [1, 3, 5],\n * [2, 4]\n * ])\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const partitionMap: {\n /**\n * Applies a function to each element of the `Iterable`, categorizing the results into two separate arrays.\n * This function is particularly useful for operations where each element can result in two possible types,\n * and you want to separate these types into different collections. For instance, separating validation results\n * into successes and failures.\n *\n * @example\n * ```ts\n * import { Array, Either } from \"effect\";\n *\n * const data = [1, 2, 3, 4, 5]\n * const isEven = (x: number) => x % 2 === 0\n * const partitioned = Array.partitionMap(data, x =>\n * isEven(x) ? Either.right(x) : Either.left(x)\n * )\n *\n * assert.deepStrictEqual(partitioned, [\n * [1, 3, 5],\n * [2, 4]\n * ])\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B, C>(f: (a: A, i: number) => array_<C, B>): (self: Iterable<A>) => [left: Array<B>, right: Array<C>]\n /**\n * Applies a function to each element of the `Iterable`, categorizing the results into two separate arrays.\n * This function is particularly useful for operations where each element can result in two possible types,\n * and you want to separate these types into different collections. For instance, separating validation results\n * into successes and failures.\n *\n * @example\n * ```ts\n * import { Array, Either } from \"effect\";\n *\n * const data = [1, 2, 3, 4, 5]\n * const isEven = (x: number) => x % 2 === 0\n * const partitioned = Array.partitionMap(data, x =>\n * isEven(x) ? Either.right(x) : Either.left(x)\n * )\n *\n * assert.deepStrictEqual(partitioned, [\n * [1, 3, 5],\n * [2, 4]\n * ])\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B, C>(self: Iterable<A>, f: (a: A, i: number) => array_<C, B>): [left: Array<B>, right: Array<C>]\n} = dual(\n 2,\n <A, B, C>(self: Iterable<A>, f: (a: A, i: number) => array_<C, B>): [left: Array<B>, right: Array<C>] => {\n const left: Array<B> = []\n const right: Array<C> = []\n const as = fromIterable(self)\n for (let i = 0; i < as.length; i++) {\n const e = f(as[i], i)\n if (E.isLeft(e)) {\n left.push(e.left)\n } else {\n right.push(e.right)\n }\n }\n return [left, right]\n }\n)\n\n/**\n * Retrieves the `Some` values from an `Iterable` of `Option`s, collecting them into an array.\n *\n * @example\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Array.getSomes([Option.some(1), Option.none(), Option.some(2)]),\n * [1, 2]\n * )\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n\nexport const getSomes: <T extends Iterable<Option<X>>, X = any>(\n self: T\n) => Array<Option.Value<ReadonlyArray.Infer<T>>> = filterMap(identity as any)\n\n/**\n * Retrieves the `Left` values from an `Iterable` of `Either`s, collecting them into an array.\n *\n * @example\n * ```ts\n * import { Array, Either } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Array.getLefts([Either.right(1), Either.left(\"err\"), Either.right(2)]),\n * [\"err\"]\n * )\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const getLefts = <T extends Iterable<array_<any, any>>>(self: T): Array<array_.Left<ReadonlyArray.Infer<T>>> => {\n const out: Array<any> = []\n for (const a of self) {\n if (E.isLeft(a)) {\n out.push(a.left)\n }\n }\n\n return out\n}\n\n/**\n * Retrieves the `Right` values from an `Iterable` of `Either`s, collecting them into an array.\n *\n * @example\n * ```ts\n * import { Array, Either } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Array.getRights([Either.right(1), Either.left(\"err\"), Either.right(2)]),\n * [1, 2]\n * )\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const getRights = <T extends Iterable<array_<any, any>>>(\n self: T\n): Array<array_.Right<ReadonlyArray.Infer<T>>> => {\n const out: Array<any> = []\n for (const a of self) {\n if (E.isRight(a)) {\n out.push(a.right)\n }\n }\n\n return out\n}\n\n/**\n * @category filtering\n * @since 2.0.0\n */\nexport const filter: {\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Array<B>\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Array<A>\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Array<B>\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A>\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A> => {\n const as = fromIterable(self)\n const out: Array<A> = []\n for (let i = 0; i < as.length; i++) {\n if (predicate(as[i], i)) {\n out.push(as[i])\n }\n }\n return out\n }\n)\n\n/**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const partition: {\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (\n self: Iterable<A>\n ) => [excluded: Array<Exclude<A, B>>, satisfying: Array<B>]\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * @category filtering\n * @since 2.0.0\n */\n <A>(\n predicate: (a: NoInfer<A>, i: number) => boolean\n ): (self: Iterable<A>) => [excluded: Array<A>, satisfying: Array<A>]\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(\n self: Iterable<A>,\n refinement: (a: A, i: number) => a is B\n ): [excluded: Array<Exclude<A, B>>, satisfying: Array<B>]\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * @category filtering\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [excluded: Array<A>, satisfying: Array<A>]\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [excluded: Array<A>, satisfying: Array<A>] => {\n const left: Array<A> = []\n const right: Array<A> = []\n const as = fromIterable(self)\n for (let i = 0; i < as.length; i++) {\n if (predicate(as[i], i)) {\n right.push(as[i])\n } else {\n left.push(as[i])\n }\n }\n return [left, right]\n }\n)\n\n/**\n * Separates an `Iterable` into two arrays based on a predicate.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.partition(numbers, n => n % 2 === 0)\n * assert.deepStrictEqual(result, [[1, 3], [2, 4]])\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const separate: <T extends Iterable<array_<any, any>>>(\n self: T\n) => [Array<array_.Left<ReadonlyArray.Infer<T>>>, Array<array_.Right<ReadonlyArray.Infer<T>>>] = partitionMap(\n identity\n)\n\n/**\n * Reduces an array from the left.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.reduce(numbers, 0, (acc, n) => acc + n)\n * assert.deepStrictEqual(result, 6)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const reduce: {\n /**\n * Reduces an array from the left.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.reduce(numbers, 0, (acc, n) => acc + n)\n * assert.deepStrictEqual(result, 6)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Iterable<A>) => B\n /**\n * Reduces an array from the left.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.reduce(numbers, 0, (acc, n) => acc + n)\n * assert.deepStrictEqual(result, 6)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B\n} = dual(\n 3,\n <B, A>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B =>\n fromIterable(self).reduce((b, a, i) => f(b, a, i), b)\n)\n\n/**\n * Reduces an array from the right.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.reduceRight(numbers, 0, (acc, n) => acc + n)\n * assert.deepStrictEqual(result, 6)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const reduceRight: {\n /**\n * Reduces an array from the right.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.reduceRight(numbers, 0, (acc, n) => acc + n)\n * assert.deepStrictEqual(result, 6)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Iterable<A>) => B\n /**\n * Reduces an array from the right.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.reduceRight(numbers, 0, (acc, n) => acc + n)\n * assert.deepStrictEqual(result, 6)\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B\n} = dual(\n 3,\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B =>\n fromIterable(self).reduceRight((b, a, i) => f(b, a, i), b)\n)\n\n/**\n * Lifts a predicate into an array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n * const to = Array.liftPredicate(isEven)\n * assert.deepStrictEqual(to(1), [])\n * assert.deepStrictEqual(to(2), [2])\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\nexport const liftPredicate: { // Note: I intentionally avoid using the NoInfer pattern here.\n <A, B extends A>(refinement: Refinement<A, B>): (a: A) => Array<B>\n /**\n * Lifts a predicate into an array.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n * const to = Array.liftPredicate(isEven)\n * assert.deepStrictEqual(to(1), [])\n * assert.deepStrictEqual(to(2), [2])\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\n <A>(predicate: Predicate<A>): <B extends A>(b: B) => Array<B>\n} = <A>(predicate: Predicate<A>) => <B extends A>(b: B): Array<B> => predicate(b) ? [b] : []\n\n/**\n * @category lifting\n * @since 2.0.0\n */\nexport const liftOption = <A extends Array<unknown>, B>(\n f: (...a: A) => Option<B>\n) =>\n(...a: A): Array<B> => fromOption(f(...a))\n\n/**\n * @category conversions\n * @since 2.0.0\n */\nexport const fromNullable = <A>(a: A): Array<NonNullable<A>> => a == null ? empty() : [a as NonNullable<A>]\n\n/**\n * @category lifting\n * @since 2.0.0\n */\nexport const liftNullable = <A extends Array<unknown>, B>(\n f: (...a: A) => B | null | undefined\n): (...a: A) => Array<NonNullable<B>> =>\n(...a) => fromNullable(f(...a))\n\n/**\n * Maps over an array and flattens the result, removing null and undefined values.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.flatMapNullable(numbers, n => (n % 2 === 0 ? null : n))\n * assert.deepStrictEqual(result, [1, 3])\n *\n * // Explanation:\n * // The array of numbers [1, 2, 3] is mapped with a function that returns null for even numbers\n * // and the number itself for odd numbers. The resulting array [1, null, 3] is then flattened\n * // to remove null values, resulting in [1, 3].\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatMapNullable: {\n /**\n * Maps over an array and flattens the result, removing null and undefined values.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.flatMapNullable(numbers, n => (n % 2 === 0 ? null : n))\n * assert.deepStrictEqual(result, [1, 3])\n *\n * // Explanation:\n * // The array of numbers [1, 2, 3] is mapped with a function that returns null for even numbers\n * // and the number itself for odd numbers. The resulting array [1, null, 3] is then flattened\n * // to remove null values, resulting in [1, 3].\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B | null | undefined): (self: ReadonlyArray<A>) => Array<NonNullable<B>>\n /**\n * Maps over an array and flattens the result, removing null and undefined values.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.flatMapNullable(numbers, n => (n % 2 === 0 ? null : n))\n * assert.deepStrictEqual(result, [1, 3])\n *\n * // Explanation:\n * // The array of numbers [1, 2, 3] is mapped with a function that returns null for even numbers\n * // and the number itself for odd numbers. The resulting array [1, null, 3] is then flattened\n * // to remove null values, resulting in [1, 3].\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: ReadonlyArray<A>, f: (a: A) => B | null | undefined): Array<NonNullable<B>>\n} = dual(\n 2,\n <A, B>(self: ReadonlyArray<A>, f: (a: A) => B | null | undefined): Array<NonNullable<B>> =>\n flatMap(self, (a) => fromNullable(f(a)))\n)\n\n/**\n * Lifts a function that returns an `Either` into a function that returns an array.\n * If the `Either` is a left, it returns an empty array.\n * If the `Either` is a right, it returns an array with the right value.\n *\n * @example\n * ```ts\n * import { Array, Either } from \"effect\"\n *\n * const parseNumber = (s: string): Either.Either<number, Error> =>\n * isNaN(Number(s)) ? Either.left(new Error(\"Not a number\")) : Either.right(Number(s))\n *\n * const liftedParseNumber = Array.liftEither(parseNumber)\n *\n * const result1 = liftedParseNumber(\"42\")\n * assert.deepStrictEqual(result1, [42])\n *\n * const result2 = liftedParseNumber(\"not a number\")\n * assert.deepStrictEqual(result2, [])\n *\n * // Explanation:\n * // The function parseNumber is lifted to return an array.\n * // When parsing \"42\", it returns an Either.left with the number 42, resulting in [42].\n * // When parsing \"not a number\", it returns an Either.right with an error, resulting in an empty array [].\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\nexport const liftEither = <A extends Array<unknown>, E, B>(\n f: (...a: A) => array_<B, E>\n) =>\n(...a: A): Array<B> => {\n const e = f(...a)\n return E.isLeft(e) ? [] : [e.right]\n}\n\n/**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const every: {\n /**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(\n refinement: (a: NoInfer<A>, i: number) => a is B\n ): (self: ReadonlyArray<A>) => self is ReadonlyArray<B>\n /**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: ReadonlyArray<A>) => boolean\n /**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(self: ReadonlyArray<A>, refinement: (a: A, i: number) => a is B): self is ReadonlyArray<B>\n /**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): boolean\n} = dual(\n 2,\n <A, B extends A>(self: ReadonlyArray<A>, refinement: (a: A, i: number) => a is B): self is ReadonlyArray<B> =>\n self.every(refinement)\n)\n\n/**\n * Check if a predicate holds true for some `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const some: {\n /**\n * Check if a predicate holds true for some `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: ReadonlyArray<A>) => self is NonEmptyReadonlyArray<A>\n /**\n * Check if a predicate holds true for some `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): self is NonEmptyReadonlyArray<A>\n} = dual(\n 2,\n <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): self is NonEmptyReadonlyArray<A> =>\n self.some(predicate)\n)\n\n/**\n * Extends an array with a function that maps each subarray to a value.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.extend(numbers, as => as.length)\n * assert.deepStrictEqual(result, [3, 2, 1])\n *\n * // Explanation:\n * // The function maps each subarray starting from each element to its length.\n * // The subarrays are: [1, 2, 3], [2, 3], [3].\n * // The lengths are: 3, 2, 1.\n * // Therefore, the result is [3, 2, 1].\n * ```\n *\n * @since 2.0.0\n */\nexport const extend: {\n /**\n * Extends an array with a function that maps each subarray to a value.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.extend(numbers, as => as.length)\n * assert.deepStrictEqual(result, [3, 2, 1])\n *\n * // Explanation:\n * // The function maps each subarray starting from each element to its length.\n * // The subarrays are: [1, 2, 3], [2, 3], [3].\n * // The lengths are: 3, 2, 1.\n * // Therefore, the result is [3, 2, 1].\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(f: (as: ReadonlyArray<A>) => B): (self: ReadonlyArray<A>) => Array<B>\n /**\n * Extends an array with a function that maps each subarray to a value.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.extend(numbers, as => as.length)\n * assert.deepStrictEqual(result, [3, 2, 1])\n *\n * // Explanation:\n * // The function maps each subarray starting from each element to its length.\n * // The subarrays are: [1, 2, 3], [2, 3], [3].\n * // The lengths are: 3, 2, 1.\n * // Therefore, the result is [3, 2, 1].\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: ReadonlyArray<A>, f: (as: ReadonlyArray<A>) => B): Array<B>\n} = dual(\n 2,\n <A, B>(self: ReadonlyArray<A>, f: (as: ReadonlyArray<A>) => B): Array<B> => self.map((_, i, as) => f(as.slice(i)))\n)\n\n/**\n * Finds the minimum element in an array based on a comparator.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const min = Array.min([3, 1, 2], Order.number)\n * assert.deepStrictEqual(min, 1)\n * ```\n *\n * @since 2.0.0\n */\nexport const min: {\n /**\n * Finds the minimum element in an array based on a comparator.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const min = Array.min([3, 1, 2], Order.number)\n * assert.deepStrictEqual(min, 1)\n * ```\n *\n * @since 2.0.0\n */\n <A>(O: Order.Order<A>): (self: NonEmptyReadonlyArray<A>) => A\n /**\n * Finds the minimum element in an array based on a comparator.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const min = Array.min([3, 1, 2], Order.number)\n * assert.deepStrictEqual(min, 1)\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A\n} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A => self.reduce(Order.min(O)))\n\n/**\n * Finds the maximum element in an array based on a comparator.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const max = Array.max([3, 1, 2], Order.number)\n * assert.deepStrictEqual(max, 3)\n * ```\n *\n * @since 2.0.0\n */\nexport const max: {\n /**\n * Finds the maximum element in an array based on a comparator.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const max = Array.max([3, 1, 2], Order.number)\n * assert.deepStrictEqual(max, 3)\n * ```\n *\n * @since 2.0.0\n */\n <A>(O: Order.Order<A>): (self: NonEmptyReadonlyArray<A>) => A\n /**\n * Finds the maximum element in an array based on a comparator.\n *\n * @example\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const max = Array.max([3, 1, 2], Order.number)\n * assert.deepStrictEqual(max, 3)\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A\n} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A => self.reduce(Order.max(O)))\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const unfold = <B, A>(b: B, f: (b: B) => Option<readonly [A, B]>): Array<A> => {\n const out: Array<A> = []\n let next: B = b\n let o: Option<readonly [A, B]>\n while (O.isSome(o = f(next))) {\n const [a, b] = o.value\n out.push(a)\n next = b\n }\n return out\n}\n\n/**\n * This function creates and returns a new `Order` for an array of values based on a given `Order` for the elements of the array.\n * The returned `Order` compares two arrays by applying the given `Order` to each element in the arrays.\n * If all elements are equal, the arrays are then compared based on their length.\n * It is useful when you need to compare two arrays of the same type and you have a specific way of comparing each element of the array.\n *\n * @category instances\n * @since 2.0.0\n */\nexport const getOrder: <A>(O: Order.Order<A>) => Order.Order<ReadonlyArray<A>> = Order.array\n\n/**\n * Creates an equivalence relation for arrays.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers1 = [1, 2, 3]\n * const numbers2 = [1, 2, 3]\n * const eq = Array.getEquivalence<number>((a, b) => a === b)\n * assert.deepStrictEqual(eq(numbers1, numbers2), true)\n * ```\n *\n * @category instances\n * @since 2.0.0\n */\nexport const getEquivalence: <A>(\n isEquivalent: Equivalence.Equivalence<A>\n) => Equivalence.Equivalence<ReadonlyArray<A>> = Equivalence.array\n\n/**\n * Performs a side-effect for each element of the `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * Array.forEach(numbers, n => console.log(n)) // 1, 2, 3\n * ```\n *\n * @since 2.0.0\n */\nexport const forEach: {\n /**\n * Performs a side-effect for each element of the `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * Array.forEach(numbers, n => console.log(n)) // 1, 2, 3\n * ```\n *\n * @since 2.0.0\n */\n <A>(f: (a: A, i: number) => void): (self: Iterable<A>) => void\n /**\n * Performs a side-effect for each element of the `Iterable`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * Array.forEach(numbers, n => console.log(n)) // 1, 2, 3\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, f: (a: A, i: number) => void): void\n} = dual(2, <A>(self: Iterable<A>, f: (a: A, i: number) => void): void => fromIterable(self).forEach((a, i) => f(a, i)))\n\n/**\n * Remove duplicates from an `Iterable` using the provided `isEquivalent` function,\n * preserving the order of the first occurrence of each element.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 2, 3, 3, 3]\n * const unique = Array.dedupeWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const dedupeWith: {\n /**\n * Remove duplicates from an `Iterable` using the provided `isEquivalent` function,\n * preserving the order of the first occurrence of each element.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 2, 3, 3, 3]\n * const unique = Array.dedupeWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <S extends Iterable<any>>(\n isEquivalent: (self: ReadonlyArray.Infer<S>, that: ReadonlyArray.Infer<S>) => boolean\n ): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * Remove duplicates from an `Iterable` using the provided `isEquivalent` function,\n * preserving the order of the first occurrence of each element.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 2, 3, 3, 3]\n * const unique = Array.dedupeWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A>(\n self: NonEmptyReadonlyArray<A>,\n isEquivalent: (self: A, that: A) => boolean\n ): NonEmptyArray<A>\n /**\n * Remove duplicates from an `Iterable` using the provided `isEquivalent` function,\n * preserving the order of the first occurrence of each element.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 2, 3, 3, 3]\n * const unique = Array.dedupeWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A>\n} = dual(\n 2,\n <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const out: NonEmptyArray<A> = [headNonEmpty(input)]\n const rest = tailNonEmpty(input)\n for (const r of rest) {\n if (out.every((a) => !isEquivalent(r, a))) {\n out.push(r)\n }\n }\n return out\n }\n return []\n }\n)\n\n/**\n * Remove duplicates from an `Iterable`, preserving the order of the first occurrence of each element.\n * The equivalence used to compare elements is provided by `Equal.equivalence()` from the `Equal` module.\n *\n * @since 2.0.0\n */\nexport const dedupe = <S extends Iterable<any> | NonEmptyReadonlyArray<any>>(\n self: S\n): S extends NonEmptyReadonlyArray<infer A> ? NonEmptyArray<A> : S extends Iterable<infer A> ? Array<A> : never =>\n dedupeWith(self, Equal.equivalence()) as any\n\n/**\n * Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 1, 2, 2, 3, 3]\n * const unique = Array.dedupeAdjacentWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const dedupeAdjacentWith: {\n /**\n * Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 1, 2, 2, 3, 3]\n * const unique = Array.dedupeAdjacentWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A>(isEquivalent: (self: A, that: A) => boolean): (self: Iterable<A>) => Array<A>\n /**\n * Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 1, 2, 2, 3, 3]\n * const unique = Array.dedupeAdjacentWith(numbers, (a, b) => a === b)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A>\n} = dual(2, <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A> => {\n const out: Array<A> = []\n let lastA: O.Option<A> = O.none()\n for (const a of self) {\n if (O.isNone(lastA) || !isEquivalent(a, lastA.value)) {\n out.push(a)\n lastA = O.some(a)\n }\n }\n return out\n})\n\n/**\n * Deduplicates adjacent elements that are identical.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 1, 2, 2, 3, 3]\n * const unique = Array.dedupeAdjacent(numbers)\n * assert.deepStrictEqual(unique, [1, 2, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const dedupeAdjacent: <A>(self: Iterable<A>) => Array<A> = dedupeAdjacentWith(Equal.equivalence())\n\n/**\n * Joins the elements together with \"sep\" in the middle.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const strings = [\"a\", \"b\", \"c\"]\n * const joined = Array.join(strings, \"-\")\n * assert.deepStrictEqual(joined, \"a-b-c\")\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\nexport const join: {\n /**\n * Joins the elements together with \"sep\" in the middle.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const strings = [\"a\", \"b\", \"c\"]\n * const joined = Array.join(strings, \"-\")\n * assert.deepStrictEqual(joined, \"a-b-c\")\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\n (sep: string): (self: Iterable<string>) => string\n /**\n * Joins the elements together with \"sep\" in the middle.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const strings = [\"a\", \"b\", \"c\"]\n * const joined = Array.join(strings, \"-\")\n * assert.deepStrictEqual(joined, \"a-b-c\")\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\n (self: Iterable<string>, sep: string): string\n} = dual(2, (self: Iterable<string>, sep: string): string => fromIterable(self).join(sep))\n\n/**\n * Statefully maps over the chunk, producing new elements of type `B`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.mapAccum(numbers, 0, (acc, n) => [acc + n, acc + n])\n * assert.deepStrictEqual(result, [6, [1, 3, 6]])\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\nexport const mapAccum: {\n /**\n * Statefully maps over the chunk, producing new elements of type `B`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.mapAccum(numbers, 0, (acc, n) => [acc + n, acc + n])\n * assert.deepStrictEqual(result, [6, [1, 3, 6]])\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\n <S, A, B, I extends Iterable<A> = Iterable<A>>(\n s: S,\n f: (s: S, a: ReadonlyArray.Infer<I>, i: number) => readonly [S, B]\n ): (self: I) => [state: S, mappedArray: ReadonlyArray.With<I, B>]\n /**\n * Statefully maps over the chunk, producing new elements of type `B`.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3]\n * const result = Array.mapAccum(numbers, 0, (acc, n) => [acc + n, acc + n])\n * assert.deepStrictEqual(result, [6, [1, 3, 6]])\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\n <S, A, B, I extends Iterable<A> = Iterable<A>>(\n self: I,\n s: S,\n f: (s: S, a: ReadonlyArray.Infer<I>, i: number) => readonly [S, B]\n ): [state: S, mappedArray: ReadonlyArray.With<I, B>]\n} = dual(\n 3,\n <S, A, B>(self: Iterable<A>, s: S, f: (s: S, a: A, i: number) => [S, B]): [state: S, mappedArray: Array<B>] => {\n let i = 0\n let s1 = s\n const out: Array<B> = []\n for (const a of self) {\n const r = f(s1, a, i)\n s1 = r[0]\n out.push(r[1])\n i++\n }\n return [s1, out]\n }\n)\n\n/**\n * Zips this chunk crosswise with the specified chunk using the specified combiner.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [\"a\", \"b\"]\n * const product = Array.cartesianWith(array1, array2, (a, b) => `${a}-${b}`)\n * assert.deepStrictEqual(product, [\"1-a\", \"1-b\", \"2-a\", \"2-b\"])\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\nexport const cartesianWith: {\n /**\n * Zips this chunk crosswise with the specified chunk using the specified combiner.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [\"a\", \"b\"]\n * const product = Array.cartesianWith(array1, array2, (a, b) => `${a}-${b}`)\n * assert.deepStrictEqual(product, [\"1-a\", \"1-b\", \"2-a\", \"2-b\"])\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B, C>(that: ReadonlyArray<B>, f: (a: A, b: B) => C): (self: ReadonlyArray<A>) => Array<C>\n /**\n * Zips this chunk crosswise with the specified chunk using the specified combiner.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [\"a\", \"b\"]\n * const product = Array.cartesianWith(array1, array2, (a, b) => `${a}-${b}`)\n * assert.deepStrictEqual(product, [\"1-a\", \"1-b\", \"2-a\", \"2-b\"])\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B, C>(self: ReadonlyArray<A>, that: ReadonlyArray<B>, f: (a: A, b: B) => C): Array<C>\n} = dual(\n 3,\n <A, B, C>(self: ReadonlyArray<A>, that: ReadonlyArray<B>, f: (a: A, b: B) => C): Array<C> =>\n flatMap(self, (a) => map(that, (b) => f(a, b)))\n)\n\n/**\n * Zips this chunk crosswise with the specified chunk.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [\"a\", \"b\"]\n * const product = Array.cartesian(array1, array2)\n * assert.deepStrictEqual(product, [[1, \"a\"], [1, \"b\"], [2, \"a\"], [2, \"b\"]])\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\nexport const cartesian: {\n /**\n * Zips this chunk crosswise with the specified chunk.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [\"a\", \"b\"]\n * const product = Array.cartesian(array1, array2)\n * assert.deepStrictEqual(product, [[1, \"a\"], [1, \"b\"], [2, \"a\"], [2, \"b\"]])\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <B>(that: ReadonlyArray<B>): <A>(self: ReadonlyArray<A>) => Array<[A, B]>\n /**\n * Zips this chunk crosswise with the specified chunk.\n *\n * @example\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2]\n * const array2 = [\"a\", \"b\"]\n * const product = Array.cartesian(array1, array2)\n * assert.deepStrictEqual(product, [[1, \"a\"], [1, \"b\"], [2, \"a\"], [2, \"b\"]])\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B>(self: ReadonlyArray<A>, that: ReadonlyArray<B>): Array<[A, B]>\n} = dual(\n 2,\n <A, B>(self: ReadonlyArray<A>, that: ReadonlyArray<B>): Array<[A, B]> => cartesianWith(self, that, (a, b) => [a, b])\n)\n\n// -------------------------------------------------------------------------------------\n// do notation\n// -------------------------------------------------------------------------------------\n\n/**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\nexport const Do: ReadonlyArray<{}> = of({})\n\n/**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\nexport const bind: {\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\n <A extends object, N extends string, B>(tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): (\n self: ReadonlyArray<A>\n ) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\n <A extends object, N extends string, B>(\n self: ReadonlyArray<A>,\n tag: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => ReadonlyArray<B>\n ): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n} = doNotation.bind<ReadonlyArrayTypeLambda>(map, flatMap) as any\n\n/**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\nexport const bindTo: {\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\n <N extends string>(tag: N): <A>(self: ReadonlyArray<A>) => Array<{ [K in N]: A }>\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @category do notation\n * @since 3.2.0\n */\n <A, N extends string>(self: ReadonlyArray<A>, tag: N): Array<{ [K in N]: A }>\n} = doNotation.bindTo<ReadonlyArrayTypeLambda>(map) as any\n\nconst let_: {\n <N extends string, B, A extends object>(\n tag: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): (self: ReadonlyArray<A>) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n <N extends string, A extends object, B>(\n self: ReadonlyArray<A>,\n tag: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n} = doNotation.let_<ReadonlyArrayTypeLambda>(map) as any\n\nexport {\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @see {@link bindTo}\n * @see {@link bind}\n * @see {@link Do}\n *\n * @example\n * ```ts\n * import { Array as Arr, pipe } from \"effect\"\n * const doResult = pipe(\n * Arr.Do,\n * Arr.bind(\"x\", () => [1, 3, 5]),\n * Arr.bind(\"y\", () => [2, 4, 6]),\n * Arr.filter(({ x, y }) => x < y), // condition\n * Arr.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n *\n * ```\n * @category do notation\n * @since 3.2.0\n */\n let_ as let\n}\n","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 * as Nano from \"../core/Nano.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\n/**\n * Collects the given node and all its ancestor nodes that fully contain the specified TextRange.\n *\n * This function starts from the provided node and traverses up the AST, collecting\n * the node itself and its ancestors that encompass the given range.\n *\n * @param node - The starting AST node.\n * @param textRange - The range of text to use for filtering nodes.\n * @returns An array of `ts.Node` objects that fully contain the specified range.\n */\nfunction collectSelfAndAncestorNodesInRange(\n node: ts.Node,\n textRange: ts.TextRange\n): Nano.Nano<Array<ts.Node>> {\n return Nano.sync(() => {\n let result = ReadonlyArray.empty<ts.Node>()\n let parent = node\n while (parent) {\n if (parent.end >= textRange.end) {\n result = pipe(result, ReadonlyArray.append(parent))\n }\n parent = parent.parent\n }\n return result\n })\n}\n\n/**\n * Collects the node at the given position and all its ancestor nodes\n * that fully contain the specified TextRange.\n *\n * This function starts from the closest token at the given position\n * and traverses up the AST, collecting nodes that encompass the range.\n *\n * @param sourceFile - The TypeScript SourceFile to search within.\n * @param textRange - The range of text to use for filtering nodes.\n * @returns An array of `ts.Node` containing the range.\n */\nexport const getAncestorNodesInRange = Nano.fn(\"AST.getAncestorNodesInRange\")(function*(\n sourceFile: ts.SourceFile,\n textRange: ts.TextRange\n) {\n const nodeAtPosition = yield* Nano.option(findNodeAtPosition(sourceFile, textRange.pos))\n if (Option.isNone(nodeAtPosition)) return ReadonlyArray.empty<ts.Node>()\n return yield* collectSelfAndAncestorNodesInRange(nodeAtPosition.value, textRange)\n})\n\nexport class NodeNotFoundError {\n readonly _tag = \"@effect/language-service/NodeNotFoundError\"\n}\n\n/**\n * Finds the deepest AST node at the specified position within the given SourceFile.\n *\n * This function traverses the AST to locate the node that contains the given position.\n * If multiple nodes overlap the position, it returns the most specific (deepest) node.\n *\n * @param sourceFile - The TypeScript SourceFile to search within.\n * @param position - The position in the file to locate the node for.\n * @returns The deepest `ts.Node` found at the specified position.\n * If no node is found, it fails with a `NodeNotFoundError`.\n */\nconst findNodeAtPosition = Nano.fn(\"AST.findNodeAtPosition\")(function*(\n sourceFile: ts.SourceFile,\n position: number\n) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n function find(node: ts.Node): ts.Node | undefined {\n if (position >= node.getStart() && position < node.getEnd()) {\n // If the position is within this node, keep traversing its children\n return ts.forEachChild(node, find) || node\n }\n return undefined\n }\n\n const result = find(sourceFile)\n if (!result) return yield* Nano.fail(new NodeNotFoundError())\n\n return result\n})\n\nexport const getCommentAtPosition = Nano.fn(\"TypeScriptApi.getCommentAtPosition\")(function*(\n sourceFile: ts.SourceFile,\n pos: number\n) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const token = yield* findNodeAtPosition(sourceFile, pos)\n\n if (\n token === undefined || token.kind === ts.SyntaxKind.JsxText ||\n pos >= token.end - (ts.tokenToString(token.kind) || \"\").length\n ) {\n return yield* Nano.fail(new NodeNotFoundError())\n }\n const startPos = token.pos === 0 ? (ts.getShebang(sourceFile.text) || \"\").length : token.pos\n\n if (startPos === 0) return yield* Nano.fail(new NodeNotFoundError())\n\n const result = ts.forEachTrailingCommentRange(sourceFile.text, startPos, isCommentInRange, pos) ||\n ts.forEachLeadingCommentRange(sourceFile.text, startPos, isCommentInRange, pos)\n\n if (!result) return yield* Nano.fail(new NodeNotFoundError())\n\n return result\n})\n\nfunction isCommentInRange(\n pos: number,\n end: number,\n kind: ts.CommentKind,\n _nl: boolean,\n at: number\n): ts.CommentRange | undefined {\n return at >= pos && at < end ? { pos, end, kind } : undefined\n}\n\n/**\n * Ensures value is a text range\n */\nexport function toTextRange(positionOrRange: number | ts.TextRange): ts.TextRange {\n return typeof positionOrRange === \"number\"\n ? { end: positionOrRange, pos: positionOrRange }\n : positionOrRange\n}\n\nexport function isNodeInRange(textRange: ts.TextRange) {\n return (node: ts.Node) => node.pos <= textRange.pos && node.end >= textRange.end\n}\n\nexport const transformAsyncAwaitToEffectGen = Nano.fn(\"AST.transformAsyncAwaitToEffectGen\")(\n function*(\n node: ts.FunctionDeclaration | ts.ArrowFunction | ts.FunctionExpression,\n effectModuleName: string,\n onAwait: (expression: ts.Expression) => ts.Expression\n ) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n function visitor(_: ts.Node): ts.Node {\n if (ts.isAwaitExpression(_)) {\n const expression = ts.visitEachChild(_.expression, visitor, ts.nullTransformationContext)\n\n return ts.factory.createYieldExpression(\n ts.factory.createToken(ts.SyntaxKind.AsteriskToken),\n onAwait(expression)\n )\n }\n return ts.visitEachChild(_, visitor, ts.nullTransformationContext)\n }\n const generatorBody = visitor(node.body!)\n\n const effectGenCallExp = yield* createEffectGenCallExpression(effectModuleName, generatorBody)\n\n let currentFlags = ts.getCombinedModifierFlags(node)\n currentFlags &= ~ts.ModifierFlags.Async\n const newModifiers = ts.factory.createModifiersFromModifierFlags(currentFlags)\n\n if (ts.isArrowFunction(node)) {\n return ts.factory.createArrowFunction(\n newModifiers,\n node.typeParameters,\n node.parameters,\n undefined,\n node.equalsGreaterThanToken,\n effectGenCallExp\n )\n }\n\n const newBody = ts.factory.createBlock([\n ts.factory.createReturnStatement(effectGenCallExp)\n ])\n\n if (ts.isFunctionDeclaration(node)) {\n return ts.factory.createFunctionDeclaration(\n newModifiers,\n node.asteriskToken,\n node.name,\n node.typeParameters,\n node.parameters,\n undefined,\n newBody\n )\n }\n return ts.factory.createFunctionExpression(\n newModifiers,\n node.asteriskToken,\n node.name,\n node.typeParameters,\n node.parameters,\n undefined,\n newBody\n )\n }\n)\n\nexport const addReturnTypeAnnotation = Nano.fn(\"AST.addReturnTypeAnnotation\")(function*(\n sourceFile: ts.SourceFile,\n declaration:\n | ts.FunctionDeclaration\n | ts.FunctionExpression\n | ts.ArrowFunction\n | ts.MethodDeclaration,\n typeNode: ts.TypeNode\n) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const changes = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile)\n const needParens = ts.isArrowFunction(declaration) && closeParen === undefined\n const endNode = needParens ? declaration.parameters[0] : closeParen\n if (endNode) {\n if (needParens) {\n changes.insertNodeBefore(\n sourceFile,\n endNode,\n ts.factory.createToken(ts.SyntaxKind.OpenParenToken)\n )\n changes.insertNodeAfter(\n sourceFile,\n endNode,\n ts.factory.createToken(ts.SyntaxKind.CloseParenToken)\n )\n }\n changes.insertNodeAt(sourceFile, endNode.end, typeNode, { prefix: \": \" })\n }\n})\n\nexport const removeReturnTypeAnnotation = Nano.fn(\"AST.removeReturnTypeAnnotation\")(function*(\n sourceFile: ts.SourceFile,\n declaration:\n | ts.FunctionDeclaration\n | ts.FunctionExpression\n | ts.ArrowFunction\n | ts.MethodDeclaration\n) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const changes = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n const closeParen = ts.findChildOfKind(declaration, ts.SyntaxKind.CloseParenToken, sourceFile)\n const needParens = ts.isArrowFunction(declaration) && closeParen === undefined\n const endNode = needParens ? declaration.parameters[0] : closeParen\n if (endNode && declaration.type) {\n changes.deleteRange(sourceFile, { pos: endNode.end, end: declaration.type.end })\n }\n})\n\nexport class ImportModuleIdentifierNotFoundError {\n readonly _tag = \"@effect/language-service/ImportModuleIdentifierNotFoundError\"\n}\n\nexport const findImportedModuleIdentifier = Nano.fn(\"AST.findImportedModuleIdentifier\")(\n function*<E = never, R = never>(\n sourceFile: ts.SourceFile,\n test: (\n node: ts.Node,\n fromModule: ts.Expression,\n importProperty: Option.Option<ts.ModuleExportName>\n ) => Nano.Nano<boolean, E, R>\n ) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n for (const statement of sourceFile.statements) {\n if (!ts.isImportDeclaration(statement)) continue\n const importClause = statement.importClause\n if (!importClause) continue\n const namedBindings = importClause.namedBindings\n if (!namedBindings) continue\n if (ts.isNamespaceImport(namedBindings)) {\n if (yield* test(namedBindings.name, statement.moduleSpecifier, Option.none())) {\n return (namedBindings.name)\n }\n } else if (ts.isNamedImports(namedBindings)) {\n for (const importSpecifier of namedBindings.elements) {\n const importProperty = Option.fromNullable(importSpecifier.propertyName).pipe(\n Option.orElse(() => Option.some(importSpecifier.name))\n )\n if (yield* test(importSpecifier.name, statement.moduleSpecifier, importProperty)) {\n return (importSpecifier.name)\n }\n }\n }\n }\n return yield* Nano.fail(new ImportModuleIdentifierNotFoundError())\n }\n)\n\nexport function findImportedModuleIdentifierByPackageAndNameOrBarrel(\n sourceFile: ts.SourceFile,\n packageName: string,\n moduleName: string\n) {\n return findImportedModuleIdentifier(\n sourceFile,\n Nano.fn(\n \"AST.findImportedModuleIdentifierByPackageAndNameOrBarrel.findImportedModuleIdentifier\"\n )(function*(_, fromModule, importProperty) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n // import * as Module from \"package/module\"\n if (\n Option.isNone(importProperty) && ts.isStringLiteral(fromModule) &&\n fromModule.text === packageName + \"/\" + moduleName\n ) {\n return true\n }\n // import { Module } from \"package\"\n // or\n // import { Module as M } from \"package\"\n if (\n Option.isSome(importProperty) && ts.isIdentifier(importProperty.value) &&\n importProperty.value.text === moduleName && ts.isStringLiteral(fromModule) &&\n fromModule.text === packageName\n ) {\n return true\n }\n return false\n })\n )\n}\n\nexport const simplifyTypeNode = Nano.fn(\"AST.simplifyTypeNode\")(function*(typeNode: ts.TypeNode) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n function collectCallable(\n typeNode: ts.TypeNode\n ): Option.Option<Array<ts.CallSignatureDeclaration>> {\n // (() => 1) -> skip to inner node\n if (ts.isParenthesizedTypeNode(typeNode)) return collectCallable(typeNode.type)\n // () => 1 -> convert to call signature\n if (ts.isFunctionTypeNode(typeNode)) {\n return Option.some([\n ts.factory.createCallSignature(typeNode.typeParameters, typeNode.parameters, typeNode.type)\n ])\n }\n // { ... } -> if every member is callsignature, return a merge of all of those\n if (ts.isTypeLiteralNode(typeNode)) {\n const allCallSignatures = typeNode.members.every(ts.isCallSignatureDeclaration)\n if (allCallSignatures) {\n return Option.some(typeNode.members as any as Array<ts.CallSignatureDeclaration>)\n }\n }\n // ... & ... -> if both are callable, return merge of both\n if (ts.isIntersectionTypeNode(typeNode)) {\n const members = typeNode.types.map((node) => collectCallable(node))\n if (members.every(Option.isSome)) {\n return Option.some(members.map((_) => Option.isSome(_) ? _.value : []).flat())\n }\n }\n\n return Option.none()\n }\n\n const callSignatures = collectCallable(typeNode)\n if (Option.isSome(callSignatures) && callSignatures.value.length > 1) {\n return ts.factory.createTypeLiteralNode(callSignatures.value)\n }\n return typeNode\n})\n\nexport const tryPreserveDeclarationSemantics = Nano.fn(\"AST.tryPreserveDeclarationSemantics\")(\n function*(nodeToReplace: ts.Node, node: ts.Node) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n // new node should be an expression!\n if (!ts.isExpression(node)) return node\n // ok, we need to replace. is that a method or a function?\n if (ts.isFunctionDeclaration(nodeToReplace)) {\n // I need a name!!!\n if (!nodeToReplace.name) return node\n return ts.factory.createVariableStatement(\n nodeToReplace.modifiers,\n ts.factory.createVariableDeclarationList(\n [ts.factory.createVariableDeclaration(\n nodeToReplace.name,\n undefined,\n undefined,\n node\n )],\n ts.NodeFlags.Const\n )\n )\n } else if (ts.isMethodDeclaration(nodeToReplace)) {\n return ts.factory.createPropertyDeclaration(\n nodeToReplace.modifiers,\n nodeToReplace.name,\n undefined,\n undefined,\n node\n )\n }\n // I don't know what else to do!\n return node\n }\n)\n\nexport const parseDataForExtendsClassCompletion = Nano.fn(\n \"AST.parseDataForExtendsClassCompletion\"\n)(function*(\n sourceFile: ts.SourceFile,\n position: number\n) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n // first, we find the preceding token\n const precedingToken = ts.findPrecedingToken(position, sourceFile, undefined, true)\n if (!precedingToken) return Option.none()\n\n let accessedObject = precedingToken\n let replacementSpan = ts.createTextSpan(position, 0)\n let outerNode: ts.Node = precedingToken\n if (\n ts.isIdentifier(precedingToken) && precedingToken.parent &&\n ts.isPropertyAccessExpression(precedingToken.parent)\n ) {\n // we are in a \"extends Schema.Tag|\"\n replacementSpan = ts.createTextSpan(\n precedingToken.parent.getStart(sourceFile),\n precedingToken.end - precedingToken.parent.getStart(sourceFile)\n )\n accessedObject = precedingToken.parent.expression\n outerNode = precedingToken.parent\n } else if (\n ts.isToken(precedingToken) && precedingToken.kind === ts.SyntaxKind.DotToken &&\n ts.isPropertyAccessExpression(precedingToken.parent)\n ) {\n // we are in a \"extends Schema.|\"\n replacementSpan = ts.createTextSpan(\n precedingToken.parent.getStart(sourceFile),\n precedingToken.end - precedingToken.parent.getStart(sourceFile)\n )\n accessedObject = precedingToken.parent.expression\n outerNode = precedingToken.parent\n } else if (ts.isIdentifier(precedingToken) && precedingToken.parent) {\n // we are in a \"extends Schema|\"\n replacementSpan = ts.createTextSpan(\n precedingToken.getStart(sourceFile),\n precedingToken.end - precedingToken.getStart(sourceFile)\n )\n accessedObject = precedingToken\n outerNode = precedingToken\n } else {\n return Option.none()\n }\n\n if (!ts.isIdentifier(accessedObject)) return Option.none()\n\n // go up allowed nodes until we find the class declaration\n let classDeclaration: ts.Node = outerNode.parent\n while (\n ts.isExpressionWithTypeArguments(classDeclaration) || ts.isHeritageClause(classDeclaration)\n ) {\n if (!classDeclaration.parent) break\n classDeclaration = classDeclaration.parent\n }\n if (!ts.isClassDeclaration(classDeclaration)) return Option.none()\n if (!classDeclaration.name) return Option.none()\n\n return Option.some(\n { accessedObject, classDeclaration, className: classDeclaration.name, replacementSpan } as const\n )\n})\n\nconst createEffectGenCallExpression = Nano.fn(\"AST.createEffectGenCallExpression\")(function*(\n effectModuleIdentifierName: string,\n node: ts.Node\n) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const generator = ts.factory.createFunctionExpression(\n undefined,\n ts.factory.createToken(ts.SyntaxKind.AsteriskToken),\n undefined,\n [],\n [],\n undefined,\n node as any // NOTE(mattia): intended, to use same routine for both ConciseBody and Body\n )\n\n return ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectModuleIdentifierName),\n \"gen\"\n ),\n undefined,\n [generator]\n )\n})\n\nexport const createEffectGenCallExpressionWithBlock = Nano.fn(\n \"AST.createEffectGenCallExpressionWithBlock\"\n)(function*(\n effectModuleIdentifierName: string,\n statement: ts.Statement | Array<ts.Statement>\n) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n return yield* createEffectGenCallExpression(\n effectModuleIdentifierName,\n ts.factory.createBlock(Array.isArray(statement) ? statement : [statement], false)\n )\n})\n\nexport const createReturnYieldStarStatement = Nano.fn(\"AST.createReturnYieldStarStatement\")(\n function*(expr: ts.Expression) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n return ts.factory.createReturnStatement(\n ts.factory.createYieldExpression(\n ts.factory.createToken(ts.SyntaxKind.AsteriskToken),\n expr\n )\n )\n }\n)\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport 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 AST from \"../core/AST\"\nimport * as LSP from \"../core/LSP\"\nimport * as Nano from \"../core/Nano\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi\"\n\nexport const contextSelfInClasses = LSP.createCompletion({\n name: \"effect/contextSelfInClasses\",\n apply: Nano.fn(\"contextSelfInClasses\")(function*(sourceFile, position) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const maybeInfos = yield* AST.parseDataForExtendsClassCompletion(sourceFile, position)\n if (Option.isNone(maybeInfos)) return []\n const { accessedObject, className, replacementSpan } = maybeInfos.value\n\n // first, given the position, we go back\n const contextName = yield* Nano.option(\n AST.findImportedModuleIdentifierByPackageAndNameOrBarrel(\n sourceFile,\n \"effect\",\n \"Context\"\n )\n )\n const contextIdentifier = Option.match(contextName, {\n onNone: () => \"Context\",\n onSome: (_) => _.text\n })\n\n // ensure accessed is an identifier\n if (contextIdentifier !== accessedObject.text) return []\n const name = className.text\n\n return [{\n name: `Tag(\"${name}\")`,\n kind: ts.ScriptElementKind.constElement,\n insertText: `${contextIdentifier}.Tag(\"${name}\")<${name}, ${\"${0}\"}>(){}`,\n replacementSpan,\n isSnippet: true\n }] satisfies Array<LSP.CompletionEntryDefinition>\n })\n})\n","import * as Option from \"effect/Option\"\nimport * as AST from \"../core/AST\"\nimport * as LSP from \"../core/LSP\"\nimport * as Nano from \"../core/Nano\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi\"\n\nexport const effectDataClasses = LSP.createCompletion({\n name: \"effect/effectDataClasses\",\n apply: Nano.fn(\"effectDataClasses\")(function*(sourceFile, position) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const maybeInfos = yield* AST.parseDataForExtendsClassCompletion(sourceFile, position)\n if (Option.isNone(maybeInfos)) return []\n const { accessedObject, className, replacementSpan } = maybeInfos.value\n\n // first, given the position, we go back\n const dataName = yield* Nano.option(\n AST.findImportedModuleIdentifierByPackageAndNameOrBarrel(\n sourceFile,\n \"effect\",\n \"Data\"\n )\n )\n const effectDataIdentifier = Option.match(dataName, {\n onNone: () => \"Data\",\n onSome: (_) => _.text\n })\n\n // ensure accessed is an identifier\n if (effectDataIdentifier !== accessedObject.text) return []\n const name = className.text\n\n return [{\n name: `TaggedError(\"${name}\")`,\n kind: ts.ScriptElementKind.constElement,\n insertText: `${effectDataIdentifier}.TaggedError(\"${name}\")<{${\"${0}\"}}>{}`,\n replacementSpan,\n isSnippet: true\n }, {\n name: `TaggedClass(\"${name}\")`,\n kind: ts.ScriptElementKind.constElement,\n insertText: `${effectDataIdentifier}.TaggedClass(\"${name}\")<{${\"${0}\"}}>{}`,\n replacementSpan,\n isSnippet: true\n }] satisfies Array<LSP.CompletionEntryDefinition>\n })\n})\n","import * as Option from \"effect/Option\"\nimport * as AST from \"../core/AST\"\nimport * as LSP from \"../core/LSP\"\nimport * as Nano from \"../core/Nano\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi\"\n\nexport const effectSchemaSelfInClasses = LSP.createCompletion({\n name: \"effect/effectSchemaSelfInClasses\",\n apply: Nano.fn(\"effectSchemaSelfInClasses\")(function*(sourceFile, position) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const maybeInfos = yield* AST.parseDataForExtendsClassCompletion(sourceFile, position)\n if (Option.isNone(maybeInfos)) return []\n const { accessedObject, className, replacementSpan } = maybeInfos.value\n\n // first, given the position, we go back\n const effectSchemaName = yield* Nano.option(\n AST.findImportedModuleIdentifierByPackageAndNameOrBarrel(\n sourceFile,\n \"effect\",\n \"Schema\"\n )\n )\n const schemaIdentifier = Option.match(effectSchemaName, {\n onNone: () => \"Schema\",\n onSome: (_) => _.text\n })\n\n // ensure accessed is an identifier\n if (schemaIdentifier !== accessedObject.text) return []\n const name = className.text\n\n return [{\n name: `Class<${name}>`,\n kind: ts.ScriptElementKind.constElement,\n insertText: `${schemaIdentifier}.Class<${name}>(\"${name}\")({${\"${0}\"}}){}`,\n replacementSpan,\n isSnippet: true\n }, {\n name: `TaggedError<${name}>`,\n kind: ts.ScriptElementKind.constElement,\n insertText: `${schemaIdentifier}.TaggedError<${name}>(\"${name}\")(\"${name}\", {${\"${0}\"}}){}`,\n replacementSpan,\n isSnippet: true\n }, {\n name: `TaggedClass<${name}>`,\n kind: ts.ScriptElementKind.constElement,\n insertText: `${schemaIdentifier}.TaggedClass<${name}>(\"${name}\")(\"${name}\", {${\"${0}\"}}){}`,\n replacementSpan,\n isSnippet: true\n }, {\n name: `TaggedRequest<${name}>`,\n kind: ts.ScriptElementKind.constElement,\n insertText: `${schemaIdentifier}.TaggedRequest<${name}>(\"${name}\")(\"${name}\", {${\"${0}\"}}){}`,\n replacementSpan,\n isSnippet: true\n }] satisfies Array<LSP.CompletionEntryDefinition>\n })\n})\n","import * as Option from \"effect/Option\"\nimport * as AST from \"../core/AST\"\nimport * as LSP from \"../core/LSP\"\nimport * as Nano from \"../core/Nano\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi\"\n\nexport const effectSelfInClasses = LSP.createCompletion({\n name: \"effect/effectSelfInClasses\",\n apply: Nano.fn(\"effectSelfInClasses\")(function*(sourceFile, position) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const maybeInfos = yield* AST.parseDataForExtendsClassCompletion(sourceFile, position)\n if (Option.isNone(maybeInfos)) return []\n const { accessedObject, className, replacementSpan } = maybeInfos.value\n\n // first, given the position, we go back\n const effectName = yield* Nano.option(\n AST.findImportedModuleIdentifierByPackageAndNameOrBarrel(\n sourceFile,\n \"effect\",\n \"Effect\"\n )\n )\n const effectIdentifier = Option.match(effectName, {\n onNone: () => \"Effect\",\n onSome: (_) => _.text\n })\n\n // ensure accessed is an identifier\n if (effectIdentifier !== accessedObject.text) return []\n const name = className.text\n\n return [{\n name: `Service<${name}>`,\n kind: ts.ScriptElementKind.constElement,\n insertText: `${effectIdentifier}.Service<${name}>()(\"${name}\", {${\"${0}\"}}){}`,\n replacementSpan,\n isSnippet: true\n }] satisfies Array<LSP.CompletionEntryDefinition>\n })\n})\n","import { contextSelfInClasses } from \"./completions/contextSelfInClasses.js\"\nimport { effectDataClasses } from \"./completions/effectDataClasses.js\"\nimport { effectSchemaSelfInClasses } from \"./completions/effectSchemaSelfInClasses.js\"\nimport { effectSelfInClasses } from \"./completions/effectSelfInClasses.js\"\n\nexport const completions = [\n effectSchemaSelfInClasses,\n effectSelfInClasses,\n contextSelfInClasses,\n effectDataClasses\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 ts.forEachChild(node, appendNodeToVisit)\n continue\n }\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 ts.forEachChild(node, appendNodeToVisit)\n continue\n }\n }\n }\n }\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 ts.forEachChild(node, appendNodeToVisit)\n continue\n }\n }\n } else if (ts.isArrowFunction(node) && ts.isExpression(node.body)) {\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 appendNodeToVisit(body)\n continue\n }\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","import * as ReadonlyArray from \"effect/Array\"\nimport * as Eq from \"effect/Equivalence\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as AST from \"./core/AST.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\nconst SymbolDisplayPartEq = Eq.make<ts.SymbolDisplayPart>((fa, fb) =>\n fa.kind === fb.kind && fa.text === fb.text\n)\n\nconst JSDocTagInfoEq = Eq.make<ts.JSDocTagInfo>((fa, fb) =>\n fa.name === fb.name && typeof fa.text === typeof fb.text &&\n (typeof fa.text !== \"undefined\" ? Eq.array(SymbolDisplayPartEq)(fa.text!, fb.text!) : true)\n)\n\nexport function dedupeJsDocTags(quickInfo: ts.QuickInfo | undefined): ts.QuickInfo | undefined {\n if (!quickInfo) return quickInfo\n if (quickInfo.tags) {\n return {\n ...quickInfo,\n tags: ReadonlyArray.dedupeWith(quickInfo.tags, JSDocTagInfoEq)\n }\n }\n return quickInfo\n}\n\nfunction formatTypeForQuickInfo(channelType: ts.Type, channelName: string) {\n return Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n const stringRepresentation = typeChecker.typeToString(\n channelType,\n undefined,\n ts.TypeFormatFlags.NoTruncation\n )\n return `type ${channelName} = ${stringRepresentation}`\n })\n}\n\nexport function prependEffectTypeArguments(\n sourceFile: ts.SourceFile,\n position: number,\n quickInfo: ts.QuickInfo | undefined\n) {\n return pipe(\n Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n // find the node we are hovering\n const maybeNode = pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, AST.toTextRange(position)),\n ReadonlyArray.head\n )\n if (Option.isNone(maybeNode)) return quickInfo\n const node = maybeNode.value\n\n const hasTruncationHappened = quickInfo &&\n ts.displayPartsToString(quickInfo.displayParts).indexOf(\"...\") > -1\n\n // if we are hovering a \"yield*\" and there are no quickinfo,\n // we try to parse the effect type\n // otherwise if no truncation has happened, do nothing\n const nodeForType =\n (!quickInfo && ts.isYieldExpression(node) && node.asteriskToken && node.expression)\n ? node.expression\n : (hasTruncationHappened ? node : undefined)\n\n // we have no node to get type from\n if (!nodeForType) return quickInfo\n\n const effectType = yield* TypeParser.effectType(\n typeChecker.getTypeAtLocation(nodeForType),\n nodeForType\n )\n\n const effectTypeArgsDocumentation: Array<ts.SymbolDisplayPart> = [{\n kind: \"text\",\n text: (\n \"```ts\\n\" +\n \"/* Effect Type Parameters */\\n\" +\n (yield* formatTypeForQuickInfo(effectType.A, \"Success\")) +\n \"\\n\" +\n (yield* formatTypeForQuickInfo(effectType.E, \"Failure\")) +\n \"\\n\" +\n (yield* formatTypeForQuickInfo(effectType.R, \"Requirements\")) +\n \"\\n```\\n\"\n )\n }]\n\n // there are cases where we create it from scratch\n if (!quickInfo) {\n const start = node.getStart()\n const end = node.getEnd()\n return {\n kind: ts.ScriptElementKind.callSignatureElement,\n kindModifiers: \"\",\n textSpan: { start, length: end - start },\n documentation: effectTypeArgsDocumentation\n } satisfies ts.QuickInfo\n }\n\n if (quickInfo.documentation) {\n return {\n ...quickInfo,\n documentation: effectTypeArgsDocumentation.concat(quickInfo.documentation)\n }\n }\n\n return {\n ...quickInfo,\n documentation: effectTypeArgsDocumentation\n }\n }),\n Nano.orElse(() => Nano.succeed(quickInfo))\n )\n}\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as AST from \"../core/AST.js\"\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 asyncAwaitToGen = LSP.createRefactor({\n name: \"effect/asyncAwaitToGen\",\n description: \"Convert to Effect.gen\",\n apply: Nano.fn(\"asyncAwaitToGen.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n const maybeNode = pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.filter((node) =>\n ts.isFunctionDeclaration(node) || ts.isArrowFunction(node) ||\n ts.isFunctionExpression(node)\n ),\n ReadonlyArray.filter((node) => !!node.body),\n ReadonlyArray.filter((node) =>\n !!(ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Async)\n ),\n ReadonlyArray.head\n )\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const node = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.asyncAwaitToGen\",\n description: \"Rewrite to Effect.gen\",\n apply: pipe(\n Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n const effectModuleIdentifierName = Option.match(\n yield* Nano.option(\n AST.findImportedModuleIdentifier(\n sourceFile,\n (node) =>\n pipe(\n TypeParser.importedEffectModule(node),\n Nano.option,\n Nano.map(Option.isSome)\n )\n )\n ),\n {\n onNone: () => \"Effect\",\n onSome: (node) => node.text\n }\n )\n\n const newDeclaration = yield* AST.transformAsyncAwaitToEffectGen(\n node,\n effectModuleIdentifierName,\n (expression) =>\n ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectModuleIdentifierName),\n \"promise\"\n ),\n undefined,\n [\n ts.factory.createArrowFunction(\n undefined,\n undefined,\n [],\n undefined,\n undefined,\n expression\n )\n ]\n )\n )\n\n changeTracker.replaceNode(sourceFile, node, newDeclaration)\n }),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts),\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, typeChecker)\n )\n })\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as AST from \"../core/AST.js\"\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 asyncAwaitToGenTryPromise = LSP.createRefactor({\n name: \"effect/asyncAwaitToGenTryPromise\",\n description: \"Convert to Effect.gen with failures\",\n apply: Nano.fn(\"asyncAwaitToGenTryPromise.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n const maybeNode = pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.filter(\n (node) =>\n ts.isFunctionDeclaration(node) || ts.isArrowFunction(node) ||\n ts.isFunctionExpression(node)\n ),\n ReadonlyArray.filter((node) => !!node.body),\n ReadonlyArray.filter((node) =>\n !!(ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Async)\n ),\n ReadonlyArray.head\n )\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const node = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.asyncAwaitToGenTryPromise\",\n description: \"Rewrite to Effect.gen with failures\",\n apply: pipe(\n Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n const effectModuleIdentifierName = Option.match(\n yield* Nano.option(\n AST.findImportedModuleIdentifier(\n sourceFile,\n (node) =>\n pipe(\n TypeParser.importedEffectModule(node),\n Nano.option,\n Nano.map(Option.isSome)\n )\n )\n ),\n {\n onNone: () => \"Effect\",\n onSome: (node) => node.text\n }\n )\n\n let errorCount = 0\n\n function createErrorADT() {\n errorCount++\n return ts.factory.createObjectLiteralExpression([\n ts.factory.createPropertyAssignment(\n \"_tag\",\n ts.factory.createAsExpression(\n ts.factory.createStringLiteral(\"Error\" + errorCount),\n ts.factory.createTypeReferenceNode(\"const\")\n )\n ),\n ts.factory.createShorthandPropertyAssignment(\"error\")\n ])\n }\n\n const newDeclaration = yield* AST.transformAsyncAwaitToEffectGen(\n node,\n effectModuleIdentifierName,\n (expression) =>\n ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectModuleIdentifierName),\n \"tryPromise\"\n ),\n undefined,\n [\n ts.factory.createObjectLiteralExpression([\n ts.factory.createPropertyAssignment(\n ts.factory.createIdentifier(\"try\"),\n ts.factory.createArrowFunction(\n undefined,\n undefined,\n [],\n undefined,\n undefined,\n expression\n )\n ),\n ts.factory.createPropertyAssignment(\n ts.factory.createIdentifier(\"catch\"),\n ts.factory.createArrowFunction(\n undefined,\n undefined,\n [ts.factory.createParameterDeclaration(undefined, undefined, \"error\")],\n undefined,\n undefined,\n createErrorADT()\n )\n )\n ])\n ]\n )\n )\n\n changeTracker.replaceNode(sourceFile, node, newDeclaration)\n }),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts),\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, typeChecker)\n )\n })\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as AST from \"../core/AST.js\"\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 effectGenToFn = LSP.createRefactor({\n name: \"effect/effectGenToFn\",\n description: \"Convert to Effect.fn\",\n apply: Nano.fn(\"effectGenToFn.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const parseEffectGenNode = Nano.fn(\"asyncAwaitToGen.apply\")(function*(node: ts.Node) {\n // check if the node is a Effect.gen(...)\n const effectGen = yield* TypeParser.effectGen(node)\n // if parent is a Effect.gen(...).pipe(...) we then move the pipe tot the new Effect.fn\n let pipeArgs = ts.factory.createNodeArray<ts.Expression>([])\n let nodeToReplace = node.parent\n if (\n ts.isPropertyAccessExpression(node.parent) && node.parent.name.text === \"pipe\" &&\n ts.isCallExpression(node.parent.parent)\n ) {\n pipeArgs = node.parent.parent.arguments\n nodeToReplace = node.parent.parent.parent\n }\n // then we iterate upwards until we find the function declaration\n while (nodeToReplace) {\n // if arrow function, exit\n if (\n ts.isArrowFunction(nodeToReplace) || ts.isFunctionDeclaration(nodeToReplace) ||\n ts.isMethodDeclaration(nodeToReplace)\n ) {\n return ({ ...effectGen, pipeArgs, nodeToReplace })\n }\n // concise body go up\n if (ts.isConciseBody(nodeToReplace) || ts.isReturnStatement(nodeToReplace)) {\n nodeToReplace = nodeToReplace.parent\n continue\n }\n // function body with only one statement, go up\n if (ts.isBlock(nodeToReplace) && nodeToReplace.statements.length === 1) {\n nodeToReplace = nodeToReplace.parent\n continue\n }\n // exit\n break\n }\n return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n })\n\n const maybeNode = yield* pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.map(parseEffectGenNode),\n Nano.firstSuccessOf,\n Nano.option\n )\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const { effectModule, generatorFunction, nodeToReplace, pipeArgs } = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.effectGenToFn\",\n description: \"Convert to Effect.fn\",\n apply: pipe(\n Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n // if we have a name in the function declaration,\n // we call Effect.fn with the name\n const effectFn = nodeToReplace.name && ts.isIdentifier(nodeToReplace.name) ?\n ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n effectModule,\n \"fn\"\n ),\n undefined,\n [ts.factory.createStringLiteral(nodeToReplace.name.text)]\n ) :\n ts.factory.createPropertyAccessExpression(\n effectModule,\n \"fn\"\n )\n // append the generator and pipe arguments to the Effect.fn call\n const effectFnCallWithGenerator = ts.factory.createCallExpression(\n effectFn,\n undefined,\n [ts.factory.createFunctionExpression(\n undefined,\n ts.factory.createToken(ts.SyntaxKind.AsteriskToken),\n undefined,\n nodeToReplace.typeParameters,\n nodeToReplace.parameters,\n nodeToReplace.type,\n generatorFunction.body\n ) as ts.Expression].concat(pipeArgs)\n )\n changeTracker.replaceNode(\n sourceFile,\n nodeToReplace,\n yield* AST.tryPreserveDeclarationSemantics(nodeToReplace, effectFnCallWithGenerator)\n )\n }),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts)\n )\n })\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as AST from \"../core/AST.js\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const functionToArrow = LSP.createRefactor({\n name: \"effect/functionToArrow\",\n description: \"Convert to arrow\",\n apply: Nano.fn(\"functionToArrow.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const maybeNode = pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.filter((_) => ts.isFunctionDeclaration(_) || ts.isMethodDeclaration(_)),\n ReadonlyArray.filter((_) => !!_.body),\n ReadonlyArray.filter((_) => !!_.name && AST.isNodeInRange(textRange)(_.name)),\n ReadonlyArray.head\n )\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const node = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.functionToArrow\",\n description: \"Convert to arrow\",\n apply: pipe(\n Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n const body = node.body!\n let newBody: ts.ConciseBody = ts.factory.createBlock(body.statements)\n if (body.statements.length === 1) {\n const statement = body.statements[0]\n if (statement && ts.isReturnStatement(statement) && statement.expression) {\n newBody = statement.expression!\n }\n }\n\n let arrowFlags = ts.getCombinedModifierFlags(node)\n arrowFlags &= ~ts.ModifierFlags.Export\n arrowFlags &= ~ts.ModifierFlags.Default\n const arrowModifiers = ts.factory.createModifiersFromModifierFlags(arrowFlags)\n\n const arrowFunction = ts.factory.createArrowFunction(\n arrowModifiers,\n node.typeParameters,\n node.parameters,\n undefined,\n ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),\n newBody\n )\n\n const newDeclaration: ts.Node = yield* AST.tryPreserveDeclarationSemantics(\n node,\n arrowFunction\n )\n changeTracker.replaceNode(sourceFile, node, newDeclaration, {\n leadingTriviaOption: ts.textChanges.LeadingTriviaOption.IncludeAll,\n trailingTriviaOption: ts.textChanges.TrailingTriviaOption.Exclude\n })\n }),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts)\n )\n })\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as AST from \"../core/AST.js\"\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 _findSchemaVariableDeclaration = Nano.fn(\n \"makeSchemaOpaque._findSchemaVariableDeclaration\"\n)(\n function*(sourceFile: ts.SourceFile, textRange: ts.TextRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n const findSchema = Nano.fn(\"makeSchemaOpaque.apply.findSchema\")(\n function*(node: ts.Node) {\n if (!ts.isVariableDeclaration(node)) {\n return yield* Nano.fail(\"parent should be variable declaration\")\n }\n const identifier = node.name\n if (!ts.isIdentifier(identifier)) return yield* Nano.fail(\"name should be an identifier\")\n const initializer = node.initializer\n if (!initializer) return yield* Nano.fail(\"should have an initializer\")\n\n const variableDeclarationList = node.parent\n if (!variableDeclarationList || !ts.isVariableDeclarationList(variableDeclarationList)) {\n return yield* Nano.fail(\"parent is not a variable declaration list\")\n }\n\n const variableStatement = variableDeclarationList.parent\n if (!variableStatement || !ts.isVariableStatement(variableStatement)) {\n return yield* Nano.fail(\"parent not variable declaration statement\")\n }\n\n const type = typeChecker.getTypeAtLocation(initializer)\n const types = yield* TypeParser.effectSchemaType(type, initializer)\n\n return { identifier, variableStatement, variableDeclarationList, types }\n }\n )\n\n return yield* pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.map(findSchema),\n Nano.firstSuccessOf,\n Nano.option\n )\n }\n)\n\nexport const _createOpaqueTypes = Nano.fn(\"_createOpaqueTypes\")(function*(\n effectSchemaName: string,\n inferFromName: string,\n typeA: ts.Type,\n opaqueTypeName: string,\n typeE: ts.Type,\n opaqueEncodedName: string,\n opaqueContextName: string\n) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n // opaque type\n const opaqueInferred = ts.factory.createExpressionWithTypeArguments(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectSchemaName),\n ts.factory.createIdentifier(\"Schema\")\n ),\n ts.factory.createIdentifier(\"Type\")\n ),\n [ts.factory.createTypeQueryNode(\n ts.factory.createIdentifier(inferFromName)\n )]\n )\n const opaqueType = typeA.isUnion() ?\n ts.factory.createTypeAliasDeclaration(\n [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n opaqueTypeName,\n [],\n opaqueInferred\n ) :\n ts.factory.createInterfaceDeclaration(\n [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n opaqueTypeName,\n undefined,\n [ts.factory.createHeritageClause(\n ts.SyntaxKind.ExtendsKeyword,\n [opaqueInferred]\n )],\n []\n )\n // encoded type\n const encodedInferred = ts.factory.createExpressionWithTypeArguments(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectSchemaName),\n ts.factory.createIdentifier(\"Schema\")\n ),\n ts.factory.createIdentifier(\"Encoded\")\n ),\n [ts.factory.createTypeQueryNode(\n ts.factory.createIdentifier(inferFromName)\n )]\n )\n const encodedType = typeE.isUnion() ?\n ts.factory.createTypeAliasDeclaration(\n [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n opaqueEncodedName,\n [],\n encodedInferred\n ) :\n ts.factory.createInterfaceDeclaration(\n [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n opaqueEncodedName,\n undefined,\n [ts.factory.createHeritageClause(\n ts.SyntaxKind.ExtendsKeyword,\n [encodedInferred]\n )],\n []\n )\n\n // context\n const contextInferred = ts.factory.createExpressionWithTypeArguments(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectSchemaName),\n ts.factory.createIdentifier(\"Schema\")\n ),\n ts.factory.createIdentifier(\"Context\")\n ),\n [ts.factory.createTypeQueryNode(\n ts.factory.createIdentifier(inferFromName)\n )]\n )\n const contextType = ts.factory.createTypeAliasDeclaration(\n [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n opaqueContextName,\n [],\n contextInferred\n )\n\n return { contextType, encodedType, opaqueType }\n})\n\nexport const makeSchemaOpaque = LSP.createRefactor({\n name: \"effect/makeSchemaOpaque\",\n description: \"Make Schema opaque\",\n apply: Nano.fn(\"makeSchemaOpaque.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const maybeNode = yield* _findSchemaVariableDeclaration(sourceFile, textRange)\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n\n const { identifier, types, variableDeclarationList, variableStatement } = maybeNode.value\n\n return {\n kind: \"refactor.rewrite.effect.makeSchemaOpaque\",\n description: `Make Schema opaque`,\n apply: pipe(\n Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n const effectSchemaName = Option.match(\n yield* Nano.option(\n AST.findImportedModuleIdentifierByPackageAndNameOrBarrel(\n sourceFile,\n \"effect\",\n \"Schema\"\n )\n ),\n {\n onNone: () => \"Schema\",\n onSome: (_) => _.text\n }\n )\n const newIdentifier = ts.factory.createIdentifier(identifier.text + \"_\")\n const { contextType, encodedType, opaqueType } = yield* _createOpaqueTypes(\n effectSchemaName,\n newIdentifier.text,\n types.A,\n identifier.text,\n types.I,\n identifier.text + \"Encoded\",\n identifier.text + \"Context\"\n )\n\n changeTracker.replaceNode(\n sourceFile,\n identifier,\n newIdentifier\n )\n changeTracker.insertNodeAfter(sourceFile, variableStatement, opaqueType)\n changeTracker.insertNodeAfter(sourceFile, variableStatement, encodedType)\n changeTracker.insertNodeAfter(sourceFile, variableStatement, contextType)\n\n // insert new declaration\n const newSchemaType = ts.factory.createTypeReferenceNode(\n ts.factory.createQualifiedName(\n ts.factory.createIdentifier(effectSchemaName),\n ts.factory.createIdentifier(\"Schema\")\n ),\n [\n ts.factory.createTypeReferenceNode(opaqueType.name),\n ts.factory.createTypeReferenceNode(encodedType.name),\n ts.factory.createTypeReferenceNode(contextType.name)\n ]\n )\n const newConstDeclaration = ts.factory.createVariableStatement(\n variableStatement.modifiers,\n ts.factory.createVariableDeclarationList(\n [ts.factory.createVariableDeclaration(\n identifier.text,\n undefined,\n newSchemaType,\n ts.factory.createIdentifier(newIdentifier.text)\n )],\n variableDeclarationList.flags\n )\n )\n\n changeTracker.insertNodeAfter(sourceFile, variableStatement, newConstDeclaration)\n changeTracker.insertText(sourceFile, variableStatement.end, \"\\n\")\n }),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts)\n )\n }\n })\n})\n","import { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as AST from \"../core/AST.js\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport { _createOpaqueTypes, _findSchemaVariableDeclaration } from \"./makeSchemaOpaque.js\"\n\nexport const makeSchemaOpaqueWithNs = LSP.createRefactor({\n name: \"effect/makeSchemaOpaqueWithNs\",\n description: \"Make Schema opaque with namespace\",\n apply: Nano.fn(\"makeSchemaOpaqueWithNs.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const maybeNode = yield* _findSchemaVariableDeclaration(sourceFile, textRange)\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n\n const { identifier, types, variableDeclarationList, variableStatement } = maybeNode.value\n\n return {\n kind: \"refactor.rewrite.effect.makeSchemaOpaqueWithNs\",\n description: `Make Schema opaque with namespace`,\n apply: pipe(\n Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n const effectSchemaName = Option.match(\n yield* Nano.option(\n AST.findImportedModuleIdentifierByPackageAndNameOrBarrel(\n sourceFile,\n \"effect\",\n \"Schema\"\n )\n ),\n {\n onNone: () => \"Schema\",\n onSome: (_) => _.text\n }\n )\n const newIdentifier = ts.factory.createIdentifier(identifier.text + \"_\")\n const { contextType, encodedType, opaqueType } = yield* _createOpaqueTypes(\n effectSchemaName,\n newIdentifier.text,\n types.A,\n identifier.text,\n types.I,\n \"Encoded\",\n \"Context\"\n )\n\n const namespace = ts.factory.createModuleDeclaration(\n [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n ts.factory.createIdentifier(identifier.text),\n ts.factory.createModuleBlock([\n encodedType,\n contextType\n ]),\n ts.NodeFlags.Namespace\n )\n\n changeTracker.replaceNode(\n sourceFile,\n identifier,\n newIdentifier\n )\n changeTracker.insertNodeAfter(sourceFile, variableStatement, opaqueType)\n changeTracker.insertNodeAfter(sourceFile, variableStatement, namespace)\n\n // insert new declaration\n const newSchemaType = ts.factory.createTypeReferenceNode(\n ts.factory.createQualifiedName(\n ts.factory.createIdentifier(effectSchemaName),\n ts.factory.createIdentifier(\"Schema\")\n ),\n [\n ts.factory.createTypeReferenceNode(opaqueType.name),\n ts.factory.createTypeReferenceNode(\n ts.factory.createQualifiedName(\n ts.factory.createIdentifier(namespace.name.text),\n encodedType.name\n )\n ),\n ts.factory.createTypeReferenceNode(ts.factory.createQualifiedName(\n ts.factory.createIdentifier(namespace.name.text),\n contextType.name\n ))\n ]\n )\n const newConstDeclaration = ts.factory.createVariableStatement(\n variableStatement.modifiers,\n ts.factory.createVariableDeclarationList(\n [ts.factory.createVariableDeclaration(\n identifier.text,\n undefined,\n newSchemaType,\n ts.factory.createIdentifier(newIdentifier.text)\n )],\n variableDeclarationList.flags\n )\n )\n\n changeTracker.insertNodeAfter(sourceFile, variableStatement, newConstDeclaration)\n changeTracker.insertText(sourceFile, variableStatement.end, \"\\n\")\n }),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts)\n )\n }\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as AST from \"../core/AST.js\"\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\"\n\nexport const pipeableToDatafirst = LSP.createRefactor({\n name: \"effect/pipeableToDatafirst\",\n description: \"Rewrite to datafirst\",\n apply: Nano.fn(\"pipeableToDatafirst.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n function isPipeCall(node: ts.Node): node is ts.CallExpression {\n if (!ts.isCallExpression(node)) return false\n const expression = node.expression\n if (!ts.isIdentifier(expression)) return false\n if (expression.text !== \"pipe\") return false\n return true\n }\n\n function asDataFirstExpression(\n node: ts.Node,\n self: ts.Expression\n ): Option.Option<ts.CallExpression> {\n if (!ts.isCallExpression(node)) return Option.none()\n const signature = typeChecker.getResolvedSignature(node)\n if (!signature) return Option.none()\n const callSignatures = typeChecker.getTypeAtLocation(node.expression).getCallSignatures()\n for (let i = 0; i < callSignatures.length; i++) {\n const callSignature = callSignatures[i]\n if (callSignature.parameters.length === node.arguments.length + 1) {\n return Option.some(\n ts.factory.createCallExpression(\n node.expression,\n [],\n [self].concat(node.arguments)\n )\n )\n }\n }\n return Option.none()\n }\n\n const maybeNode = pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.filter(isPipeCall),\n ReadonlyArray.filter((node) => AST.isNodeInRange(textRange)(node.expression)),\n ReadonlyArray.filter(\n (node) => node.arguments.length > 0\n ),\n ReadonlyArray.map((node) => {\n let newNode = node.arguments[0]\n let didSomething = false\n for (let i = 1; i < node.arguments.length; i++) {\n const arg = node.arguments[i]\n const a = asDataFirstExpression(arg, newNode)\n if (Option.isSome(a)) {\n // use found datafirst\n newNode = a.value\n didSomething = true\n } else {\n if (isPipeCall(newNode)) {\n // avoid nested pipe(a, pipe(b, c))\n newNode = ts.factory.createCallExpression(\n ts.factory.createIdentifier(\"pipe\"),\n [],\n newNode.arguments.concat([arg])\n )\n } else {\n // no datafirst, keep pipeable\n newNode = ts.factory.createCallExpression(ts.factory.createIdentifier(\"pipe\"), [], [\n newNode,\n arg\n ])\n }\n }\n }\n return didSomething ? Option.some([node, newNode] as const) : Option.none()\n }),\n ReadonlyArray.filter(Option.isSome),\n ReadonlyArray.map((_) => _.value),\n ReadonlyArray.head\n )\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const [node, newNode] = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.pipeableToDatafirst\",\n description: \"Rewrite to datafirst\",\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n changeTracker.replaceNode(sourceFile, node, newNode)\n })\n })\n })\n})\n","import { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as AST from \"../core/AST.js\"\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\n/**\n * Refactor to remove unnecessary `Effect.gen` calls.\n *\n * This refactor identifies `Effect.gen` calls that are redundant because they only wrap\n * a single `yield*` statement returning an `Effect`. In such cases, the `Effect.gen` wrapper\n * can be removed, and the inner `Effect` can be returned directly.\n *\n * The function works by analyzing the AST within the specified `textRange` to locate\n * `Effect.gen` calls. It checks if the body of the generator function contains only a single\n * `yield*` statement that directly returns an `Effect`. If such a pattern is found, the\n * `Effect.gen` wrapper is replaced with the inner `Effect`.\n *\n * @example\n * Input:\n * ```ts\n * const result = Effect.gen(function* () {\n * return yield* Effect.succeed(42)\n * })\n * ```\n * Output:\n * ```ts\n * const result = Effect.succeed(42)\n * ```\n *\n * @param ts - The TypeScript API.\n * @param program - The TypeScript program instance, used for type checking.\n * @returns A refactor function that takes a `SourceFile` and a `TextRange`, analyzes the AST,\n * and applies the refactor if applicable.\n */\nexport const removeUnnecessaryEffectGen = LSP.createRefactor({\n name: \"effect/removeUnnecessaryEffectGen\",\n description: \"Remove unnecessary Effect.gen\",\n apply: Nano.fn(\"removeUnnecessaryEffectGen.apply\")(function*(sourceFile, textRange) {\n for (\n const nodeToReplace of yield* AST.getAncestorNodesInRange(sourceFile, textRange)\n ) {\n const maybeNode = yield* pipe(\n TypeParser.effectGen(nodeToReplace),\n Nano.flatMap(({ body }) => TypeParser.returnYieldEffectBlock(body)),\n Nano.option\n )\n\n if (Option.isNone(maybeNode)) continue\n const returnedYieldedEffect = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.removeUnnecessaryEffectGen\",\n description: \"Remove unnecessary Effect.gen\",\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n changeTracker.replaceNode(sourceFile, nodeToReplace, returnedYieldedEffect)\n })\n })\n }\n\n return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as AST from \"../core/AST.js\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const toggleLazyConst = LSP.createRefactor({\n name: \"effect/toggleLazyConst\",\n description: \"Toggle lazy const\",\n apply: Nano.fn(\"toggleLazyConst.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const maybeNode = pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.filter(ts.isVariableDeclaration),\n ReadonlyArray.filter((node) => AST.isNodeInRange(textRange)(node.name)),\n ReadonlyArray.filter((node) =>\n !!node.initializer &&\n !(ts.isArrowFunction(node.initializer) && ts.isBlock(node.initializer.body))\n ),\n ReadonlyArray.head\n )\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const node = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.toggleLazyConst\",\n description: \"Toggle lazy const\",\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n const initializer = node.initializer!\n\n if (ts.isArrowFunction(initializer) && initializer.parameters.length === 0) {\n // delete eventual closing bracked\n changeTracker.deleteRange(sourceFile, {\n pos: initializer.body.end,\n end: initializer.end\n })\n // remove () => {\n changeTracker.deleteRange(sourceFile, {\n pos: initializer.pos,\n end: initializer.body.pos\n })\n return\n }\n\n // adds () => before\n changeTracker.insertText(sourceFile, initializer.pos, \" () =>\")\n })\n })\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as AST from \"../core/AST.js\"\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\"\n\nexport const toggleReturnTypeAnnotation = LSP.createRefactor({\n name: \"effect/toggleReturnTypeAnnotation\",\n description: \"Toggle return type annotation\",\n apply: Nano.fn(\"toggleReturnTypeAnnotation.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n const maybeNode = pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.filter((node) =>\n ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) ||\n ts.isArrowFunction(node) || ts.isMethodDeclaration(node)\n ),\n ReadonlyArray.head\n )\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const node = maybeNode.value\n\n if (node.type) {\n return ({\n kind: \"refactor.rewrite.effect.toggleReturnTypeAnnotation\",\n description: \"Toggle return type annotation\",\n apply: pipe(\n AST.removeReturnTypeAnnotation(sourceFile, node),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts)\n )\n })\n }\n\n const returnType = yield* Nano.option(TypeCheckerApi.getInferredReturnType(node))\n if (Option.isNone(returnType)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n\n const returnTypeNode = typeChecker.typeToTypeNode(\n returnType.value,\n node,\n ts.NodeBuilderFlags.NoTruncation\n )\n\n if (!returnTypeNode) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n\n return ({\n kind: \"refactor.rewrite.effect.toggleReturnTypeAnnotation\",\n description: \"Toggle return type annotation\",\n apply: pipe(\n AST.addReturnTypeAnnotation(\n sourceFile,\n node,\n yield* AST.simplifyTypeNode(returnTypeNode)\n ),\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, typeChecker),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts)\n )\n })\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as AST from \"../core/AST.js\"\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\"\n\nexport const toggleTypeAnnotation = LSP.createRefactor({\n name: \"effect/toggleTypeAnnotation\",\n description: \"Toggle type annotation\",\n apply: Nano.fn(\"toggleTypeAnnotation.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n const maybeNode = pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.filter((node) =>\n ts.isVariableDeclaration(node) || ts.isPropertyDeclaration(node)\n ),\n ReadonlyArray.filter((node) => AST.isNodeInRange(textRange)(node.name)),\n ReadonlyArray.filter((node) => !!node.initializer),\n ReadonlyArray.head\n )\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const node = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.toggleTypeAnnotation\",\n description: \"Toggle type annotation\",\n apply: pipe(\n Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n if (node.type) {\n changeTracker.deleteRange(sourceFile, { pos: node.name.end, end: node.type.end })\n return\n }\n\n const initializer = node.initializer!\n const initializerType = typeChecker.getTypeAtLocation(initializer)\n const initializerTypeNode = Option.fromNullable(typeChecker.typeToTypeNode(\n initializerType,\n node,\n ts.NodeBuilderFlags.NoTruncation\n )).pipe(\n Option.orElse(() =>\n Option.fromNullable(typeChecker.typeToTypeNode(\n initializerType,\n undefined,\n ts.NodeBuilderFlags.NoTruncation\n ))\n ),\n Option.getOrUndefined\n )\n if (initializerTypeNode) {\n changeTracker.insertNodeAt(\n sourceFile,\n node.name.end,\n yield* AST.simplifyTypeNode(initializerTypeNode),\n {\n prefix: \": \"\n }\n )\n }\n }),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts)\n )\n })\n })\n})\n","import * as Array from \"effect/Array\"\nimport { identity, pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as AST from \"../core/AST\"\nimport * as Nano from \"../core/Nano\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi\"\n\nexport class TypeParametersNotSupportedError {\n readonly _tag = \"@effect/language-service/TypeParametersNotSupportedError\"\n constructor(\n readonly node: ts.Node\n ) {\n }\n\n toString() {\n return `Could not process types with type parameters.`\n }\n}\n\nexport class OnlyLiteralPropertiesSupportedError {\n readonly _tag = \"@effect/language-service/OnlyLiteralPropertiesSupportedError\"\n constructor(\n readonly node: ts.Node\n ) {\n }\n\n toString() {\n return `Could not process ${this.node.getText()} as only literal properties are supported.`\n }\n}\n\nexport class RequiredExplicitTypesError {\n readonly _tag = \"@effect/language-service/RequiredExplicitTypesError\"\n constructor(\n readonly node: ts.Node\n ) {\n }\n toString() {\n return `Could not process ${this.node.getText()} as only explicit types are supported.`\n }\n}\n\nexport class IndexSignatureWithMoreThanOneParameterError {\n readonly _tag = \"@effect/language-service/IndexSignatureWithMoreThanOneParameterError\"\n constructor(\n readonly node: ts.Node\n ) {\n }\n toString() {\n return `Could not process ${this.node.getText()} as only index signatures with one parameter are supported.`\n }\n}\n\ninterface SchemaGenContext {\n sourceFile: ts.SourceFile\n ts: TypeScriptApi.TypeScriptApi\n createApiPropertyAccess(apiName: string): ts.PropertyAccessExpression\n createApiCall(apiName: string, args: Array<ts.Expression>): ts.CallExpression\n entityNameToDataTypeName(name: ts.EntityName): Option.Option<string>\n}\nconst SchemaGenContext = Nano.Tag<SchemaGenContext>(\"SchemaGenContext\")\n\nexport const makeSchemaGenContext = Nano.fn(\"SchemaGen.makeSchemaGenContext\")(function*(\n sourceFile: ts.SourceFile\n) {\n const effectSchemaIdentifier = pipe(\n yield* Nano.option(\n AST.findImportedModuleIdentifierByPackageAndNameOrBarrel(sourceFile, \"effect\", \"Schema\")\n ),\n Option.match({\n onNone: () => \"Schema\",\n onSome: (_) => _.text\n })\n )\n\n const moduleToImportedName: Record<string, string> = {}\n for (const moduleName of [\"Option\", \"Either\", \"Chunk\", \"Duration\"]) {\n const importedName = yield* Nano.option(\n AST.findImportedModuleIdentifierByPackageAndNameOrBarrel(sourceFile, \"effect\", moduleName)\n )\n if (Option.isSome(importedName)) moduleToImportedName[moduleName] = importedName.value.text\n }\n\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n return {\n sourceFile,\n createApiPropertyAccess: (apiName) =>\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectSchemaIdentifier),\n apiName\n ),\n createApiCall: (apiName, args) =>\n ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectSchemaIdentifier),\n apiName\n ),\n [],\n args\n ),\n entityNameToDataTypeName: (name) => {\n if (ts.isIdentifier(name)) {\n switch (name.text) {\n case \"Date\":\n case \"Pick\":\n case \"Omit\":\n case \"Record\":\n return Option.some(name.text)\n case \"ReadonlyArray\":\n case \"Array\":\n return Option.some(\"Array\")\n }\n return Option.none()\n }\n if (!ts.isIdentifier(name.left)) return Option.none()\n for (const moduleName in moduleToImportedName) {\n if (name.left.text === moduleToImportedName[moduleName] && name.right.text === moduleName) {\n return Option.some(moduleName)\n }\n }\n return Option.none()\n },\n ts\n } satisfies SchemaGenContext\n})\n\nconst typeEntityNameToNode: (\n entityName: ts.EntityName\n) => Nano.Nano<ts.Identifier | ts.PropertyAccessExpression, never, SchemaGenContext> = Nano.fn(\n \"SchemaGen.typeEntityNameToNode\"\n)(\n function*(entityName: ts.EntityName) {\n const { ts } = yield* Nano.service(SchemaGenContext)\n if (ts.isIdentifier(entityName)) return ts.factory.createIdentifier(entityName.text)\n const left = yield* typeEntityNameToNode(entityName.left)\n return ts.factory.createPropertyAccessExpression(\n left,\n ts.factory.createIdentifier(entityName.right.text)\n )\n }\n)\n\nconst parseAllLiterals: (\n node: ts.TypeNode\n) => Nano.Nano<\n Array<ts.StringLiteral | ts.NumericLiteral | ts.NullLiteral | ts.TrueLiteral | ts.FalseLiteral>,\n ts.TypeNode,\n SchemaGenContext\n> = Nano\n .fn(\n \"SchemaGen.parseAllLiterals\"\n )(\n function*(node: ts.TypeNode) {\n const { ts } = yield* Nano.service(SchemaGenContext)\n if (ts.isLiteralTypeNode(node)) {\n switch (node.literal.kind) {\n case ts.SyntaxKind.StringLiteral:\n return [ts.factory.createStringLiteral(node.literal.text)]\n case ts.SyntaxKind.NumericLiteral:\n return [ts.factory.createNumericLiteral(node.literal.text)]\n case ts.SyntaxKind.TrueKeyword:\n return [ts.factory.createTrue()]\n case ts.SyntaxKind.FalseKeyword:\n return [ts.factory.createFalse()]\n }\n }\n if (ts.isUnionTypeNode(node)) {\n return Array.flatten(yield* Nano.all(...node.types.map((_) => parseAllLiterals(_))))\n }\n if (ts.isParenthesizedTypeNode(node)) {\n return yield* parseAllLiterals(node.type)\n }\n return yield* Nano.fail(node)\n }\n )\n\nconst createUnsupportedNodeComment = (\n ts: TypeScriptApi.TypeScriptApi,\n sourceFile: ts.SourceFile,\n node: ts.Node\n) =>\n ts.addSyntheticTrailingComment(\n ts.factory.createIdentifier(\"\"),\n ts.SyntaxKind.MultiLineCommentTrivia,\n \" Not supported conversion: \" + node.getText(sourceFile) + \" \"\n )\n\nexport const processNode = (\n node: ts.Node\n): Nano.Nano<\n ts.Expression,\n | RequiredExplicitTypesError\n | TypeParametersNotSupportedError\n | OnlyLiteralPropertiesSupportedError\n | IndexSignatureWithMoreThanOneParameterError,\n TypeScriptApi.TypeScriptApi | SchemaGenContext\n> =>\n Nano.gen(function*() {\n const { createApiCall, createApiPropertyAccess, entityNameToDataTypeName, sourceFile, ts } =\n yield* Nano.service(\n SchemaGenContext\n )\n // string | number | boolean | undefined | void | never\n switch (node.kind) {\n case ts.SyntaxKind.AnyKeyword:\n return createApiPropertyAccess(\"Any\")\n case ts.SyntaxKind.NeverKeyword:\n return createApiPropertyAccess(\"Never\")\n case ts.SyntaxKind.UnknownKeyword:\n return createApiPropertyAccess(\"Unknown\")\n case ts.SyntaxKind.VoidKeyword:\n return createApiPropertyAccess(\"Void\")\n case ts.SyntaxKind.NullKeyword:\n return createApiPropertyAccess(\"Null\")\n case ts.SyntaxKind.UndefinedKeyword:\n return createApiPropertyAccess(\"Undefined\")\n case ts.SyntaxKind.StringKeyword:\n return createApiPropertyAccess(\"String\")\n case ts.SyntaxKind.NumberKeyword:\n return createApiPropertyAccess(\"Number\")\n case ts.SyntaxKind.BooleanKeyword:\n return createApiPropertyAccess(\"Boolean\")\n case ts.SyntaxKind.BigIntKeyword:\n return createApiPropertyAccess(\"BigInt\")\n }\n // null and other literals\n if (ts.isLiteralTypeNode(node)) {\n if (node.literal.kind === ts.SyntaxKind.NullKeyword) return createApiPropertyAccess(\"Null\")\n const literalMembers = yield* Nano.option(parseAllLiterals(node))\n if (Option.isSome(literalMembers)) return createApiCall(\"Literal\", literalMembers.value)\n }\n // A | B\n if (ts.isUnionTypeNode(node)) {\n // \"a\" | \"b\" can be optimized into a single Schema.Literal(\"a\", \"b\")\n const allLiterals = yield* Nano.option(parseAllLiterals(node))\n if (Option.isSome(allLiterals)) return createApiCall(\"Literal\", allLiterals.value)\n // regular union\n const members = yield* Nano.all(...node.types.map((_) => processNode(_)))\n return createApiCall(\"Union\", members)\n }\n // {a: 1} & {b: 2} & {c: 3}\n if (ts.isIntersectionTypeNode(node)) {\n const [firstSchema, ...otherSchemas] = yield* Nano.all(\n ...node.types.map((_) => processNode(_))\n )\n if (otherSchemas.length === 0) return firstSchema\n return ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n firstSchema,\n \"pipe\"\n ),\n [],\n otherSchemas.map((_) => createApiCall(\"extend\", [_]))\n )\n }\n // keyof A\n if (ts.isTypeOperatorNode(node)) {\n if (node.operator === ts.SyntaxKind.KeyOfKeyword) {\n return createApiCall(\"keyof\", [yield* processNode(node.type)])\n } else if (node.operator === ts.SyntaxKind.ReadonlyKeyword) {\n return yield* processNode(node.type)\n }\n }\n // string[]\n if (ts.isArrayTypeNode(node)) {\n const typeSchema = yield* processNode(node.elementType)\n return createApiCall(\"Array\", [typeSchema])\n }\n // { a: string, b: boolean }\n if (ts.isTypeLiteralNode(node)) {\n const { properties, records } = yield* processMembers(node.members)\n\n return createApiCall(\n \"Struct\",\n [ts.factory.createObjectLiteralExpression(properties, true)].concat(records)\n )\n }\n // type reference\n if (ts.isTypeReferenceNode(node)) {\n const parsedName = entityNameToDataTypeName(node.typeName)\n if (Option.isSome(parsedName)) {\n switch (parsedName.value) {\n case \"Duration\":\n case \"Date\":\n return createApiPropertyAccess(parsedName.value)\n case \"Option\":\n case \"Chunk\":\n case \"Array\": {\n const elements = yield* Nano.all(\n ...(node.typeArguments ? node.typeArguments.map(processNode) : [])\n )\n return createApiCall(parsedName.value, elements)\n }\n case \"Record\": {\n const elements = yield* Nano.all(\n ...(node.typeArguments ? node.typeArguments.map(processNode) : [])\n )\n if (elements.length >= 2) {\n return createApiCall(parsedName.value, [\n ts.factory.createObjectLiteralExpression([\n ts.factory.createPropertyAssignment(\"key\", elements[0]),\n ts.factory.createPropertyAssignment(\"value\", elements[1])\n ])\n ])\n }\n return createUnsupportedNodeComment(ts, sourceFile, node)\n }\n case \"Either\": {\n const elements = yield* Nano.all(\n ...(node.typeArguments ? node.typeArguments.map(processNode) : [])\n )\n if (elements.length >= 2) {\n return createApiCall(parsedName.value, [\n ts.factory.createObjectLiteralExpression([\n ts.factory.createPropertyAssignment(\"right\", elements[0]),\n ts.factory.createPropertyAssignment(\"left\", elements[1])\n ])\n ])\n }\n return createUnsupportedNodeComment(ts, sourceFile, node)\n }\n case \"Pick\":\n case \"Omit\": {\n const typeArguments = Array.fromIterable(node.typeArguments || [])\n if (typeArguments.length !== 2) {\n return createUnsupportedNodeComment(ts, sourceFile, node)\n }\n const baseType = yield* processNode(typeArguments[0])\n const stringLiteralArguments = yield* Nano.option(parseAllLiterals(typeArguments[1]))\n\n if (Option.isNone(stringLiteralArguments)) {\n return createUnsupportedNodeComment(ts, sourceFile, node)\n }\n return ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n baseType,\n \"pipe\"\n ),\n [],\n [createApiCall(parsedName.value.toLowerCase(), stringLiteralArguments.value)]\n )\n }\n }\n }\n }\n // type reference\n if (ts.isTypeReferenceNode(node)) {\n if (!(node.typeArguments && node.typeArguments.length > 0)) {\n return yield* typeEntityNameToNode(node.typeName)\n }\n }\n\n // wtf\n return createUnsupportedNodeComment(ts, sourceFile, node)\n })\n\nconst processMembers = Nano.fn(\n \"SchemaGen.processMembers\"\n)(\n function*(members: ts.NodeArray<ts.TypeElement>) {\n const { createApiCall, ts } = yield* Nano.service(\n SchemaGenContext\n )\n\n const properties: Array<ts.PropertyAssignment> = []\n for (const propertySignature of members.filter(ts.isPropertySignature)) {\n const name = propertySignature.name\n if (!(ts.isIdentifier(name) || ts.isStringLiteral(name))) {\n return yield* Nano.fail(new OnlyLiteralPropertiesSupportedError(propertySignature))\n }\n if (!propertySignature.type) {\n return yield* Nano.fail(new RequiredExplicitTypesError(propertySignature))\n }\n const propertyAssignment = pipe(\n yield* processNode(propertySignature.type),\n propertySignature.questionToken ? (_) => createApiCall(\"optional\", [_]) : identity,\n (_) => ts.factory.createPropertyAssignment(name, _)\n )\n\n properties.push(propertyAssignment)\n }\n\n const records: Array<ts.ObjectLiteralExpression> = []\n for (const indexSignature of members.filter(ts.isIndexSignatureDeclaration)) {\n if (indexSignature.parameters.length !== 1) {\n return yield* Nano.fail(new IndexSignatureWithMoreThanOneParameterError(indexSignature))\n }\n const parameter = indexSignature.parameters[0]\n if (!parameter.type) return yield* Nano.fail(new RequiredExplicitTypesError(parameter))\n const parameterType = parameter.type\n const key = yield* processNode(parameterType)\n const value = yield* processNode(indexSignature.type)\n records.push(\n ts.factory.createObjectLiteralExpression([\n ts.factory.createPropertyAssignment(\"key\", key),\n ts.factory.createPropertyAssignment(\"value\", value)\n ])\n )\n }\n\n return { properties, records }\n }\n)\n\nconst processInterfaceDeclaration = Nano.fn(\"SchemaGen.processInterfaceDeclaration\")(\n function*(node: ts.InterfaceDeclaration, preferClass: boolean) {\n if (node.typeParameters && node.typeParameters.length > 0) {\n return yield* Nano.fail(new TypeParametersNotSupportedError(node))\n }\n const { createApiCall, ts } = yield* Nano.service(\n SchemaGenContext\n )\n\n const { properties, records } = yield* processMembers(node.members)\n\n if (preferClass && records.length === 0) {\n return yield* createExportSchemaClassDeclaration(node.name.text, properties)\n }\n\n const schemaStruct = createApiCall(\n \"Struct\",\n [ts.factory.createObjectLiteralExpression(properties, true)].concat(records)\n )\n\n return yield* createExportVariableDeclaration(node.name.text, schemaStruct)\n }\n)\n\nconst processTypeAliasDeclaration = Nano.fn(\"SchemaGen.processInterfaceDeclaration\")(\n function*(node: ts.TypeAliasDeclaration, preferClass: boolean) {\n const { ts } = yield* Nano.service(SchemaGenContext)\n\n if (node.typeParameters && node.typeParameters.length > 0) {\n return yield* Nano.fail(new TypeParametersNotSupportedError(node))\n }\n\n if (preferClass && ts.isTypeLiteralNode(node.type)) {\n const { properties, records } = yield* processMembers(node.type.members)\n if (records.length === 0) {\n return yield* createExportSchemaClassDeclaration(node.name.text, properties)\n }\n }\n\n const effectSchema = yield* processNode(node.type)\n\n return yield* createExportVariableDeclaration(node.name.text, effectSchema)\n }\n)\n\nconst createExportVariableDeclaration = Nano.fn(\"SchemaGen.createExportVariableDeclaration\")(\n function*(\n name: string,\n initializer: ts.Expression\n ) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n return ts.factory.createVariableStatement(\n [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n ts.factory.createVariableDeclarationList([\n ts.factory.createVariableDeclaration(\n ts.factory.createIdentifier(name),\n undefined,\n undefined,\n initializer\n )\n ], ts.NodeFlags.Const)\n )\n }\n)\n\nconst createExportSchemaClassDeclaration = Nano.fn(\"SchemaGen.createExportSchemaClassDeclaration\")(\n function*(\n name: string,\n members: Array<ts.PropertyAssignment>\n ) {\n const { createApiPropertyAccess } = yield* Nano.service(SchemaGenContext)\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n return ts.factory.createClassDeclaration(\n [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n ts.factory.createIdentifier(name),\n [],\n [ts.factory.createHeritageClause(\n ts.SyntaxKind.ExtendsKeyword,\n [\n ts.factory.createExpressionWithTypeArguments(\n ts.factory.createCallExpression(\n ts.factory.createCallExpression(\n createApiPropertyAccess(\"Class\"),\n [ts.factory.createTypeReferenceNode(\n name\n )],\n [ts.factory.createStringLiteral(name)]\n ),\n [],\n [ts.factory.createObjectLiteralExpression(\n members,\n true\n )]\n ),\n []\n )\n ]\n )],\n []\n )\n }\n)\n\nexport const process = Nano.fn(\"SchemaGen.process\")(\n function*(\n sourceFile: ts.SourceFile,\n node: ts.InterfaceDeclaration | ts.TypeAliasDeclaration,\n preferClass: boolean\n ) {\n const ctx = yield* makeSchemaGenContext(sourceFile)\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n return yield* pipe(\n ts.isInterfaceDeclaration(node)\n ? processInterfaceDeclaration(node, preferClass)\n : processTypeAliasDeclaration(node, preferClass),\n Nano.provideService(SchemaGenContext, ctx)\n )\n }\n)\n\nexport const findNodeToProcess = Nano.fn(\"SchemaGen.findNodeToProcess\")(\n function*(sourceFile: ts.SourceFile, textRange: ts.TextRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n return pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n Array.filter((node) => ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node)),\n Array.filter((node) => AST.isNodeInRange(textRange)(node.name)),\n Array.filter((node) => (node.typeParameters || []).length === 0),\n Array.head\n )\n }\n)\n\nexport const applyAtNode = Nano.fn(\"SchemaGen.applyAtNode\")(\n function*(\n sourceFile: ts.SourceFile,\n node: ts.TypeAliasDeclaration | ts.InterfaceDeclaration,\n preferClass: boolean\n ) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n const newNode = yield* pipe(\n process(sourceFile, node, preferClass),\n Nano.orElse((error) =>\n Nano.succeed(ts.addSyntheticLeadingComment(\n ts.factory.createIdentifier(\"\"),\n ts.SyntaxKind.MultiLineCommentTrivia,\n \" \" + String(error) + \" \",\n true\n ))\n )\n )\n changeTracker.insertNodeBefore(sourceFile, node, newNode, true, {\n leadingTriviaOption: ts.textChanges.LeadingTriviaOption.StartLine\n })\n }\n)\n","import { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as SchemaGen from \"../utils/SchemaGen.js\"\n\nexport const typeToEffectSchema = LSP.createRefactor({\n name: \"effect/typeToEffectSchema\",\n description: \"Refactor to Schema\",\n apply: Nano.fn(\"typeToEffectSchema.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const maybeNode = yield* SchemaGen.findNodeToProcess(sourceFile, textRange)\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const node = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.typeToEffectSchema\",\n description: \"Refactor to Schema\",\n apply: pipe(\n SchemaGen.applyAtNode(sourceFile, node, false),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts)\n )\n })\n })\n})\n","import { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as SchemaGen from \"../utils/SchemaGen.js\"\n\nexport const typeToEffectSchemaClass = LSP.createRefactor({\n name: \"effect/typeToEffectSchemaClass\",\n description: \"Refactor to Schema.Class\",\n apply: Nano.fn(\"typeToEffectSchemaClass.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n\n const maybeNode = yield* SchemaGen.findNodeToProcess(sourceFile, textRange)\n\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n const node = maybeNode.value\n\n return ({\n kind: \"refactor.rewrite.effect.typeToEffectSchemaClass\",\n description: \"Refactor to Schema.Class\",\n apply: pipe(\n SchemaGen.applyAtNode(sourceFile, node, true),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts)\n )\n })\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as AST from \"../core/AST.js\"\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 wrapWithEffectGen = LSP.createRefactor({\n name: \"effect/wrapWithEffectGen\",\n description: \"Wrap with Effect.gen\",\n apply: Nano.fn(\"wrapWithEffectGen.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n const findEffectToWrap = Nano.fn(\"wrapWithEffectGen.apply.findEffectToWrap\")(\n function*(node: ts.Node) {\n if (!ts.isExpression(node)) return yield* Nano.fail(\"is not an expression\")\n\n const parent = node.parent\n if (\n parent != null && ts.isVariableDeclaration(parent) && parent.initializer !== node\n ) return yield* Nano.fail(\"is LHS of variable declaration\")\n\n const type = typeChecker.getTypeAtLocation(node)\n yield* TypeParser.effectType(type, node)\n\n return node\n }\n )\n\n const maybeNode = yield* pipe(\n yield* AST.getAncestorNodesInRange(sourceFile, textRange),\n ReadonlyArray.map(findEffectToWrap),\n Nano.firstSuccessOf,\n Nano.option\n )\n if (Option.isNone(maybeNode)) return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n\n return {\n kind: \"refactor.rewrite.effect.wrapWithEffectGen\",\n description: `Wrap with Effect.gen`,\n apply: pipe(\n Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n const effectGen = yield* pipe(\n AST.createEffectGenCallExpressionWithBlock(\n yield* getEffectModuleIdentifierName(sourceFile),\n yield* AST.createReturnYieldStarStatement(maybeNode.value)\n )\n )\n\n changeTracker.replaceNode(sourceFile, maybeNode.value, effectGen)\n }),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts),\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, typeChecker)\n )\n }\n })\n})\n\nexport const getEffectModuleIdentifierName = Nano.fn(\"getEffectModuleIdentifierName\")(\n function*(sourceFile: ts.SourceFile) {\n return Option.match(\n yield* Nano.option(\n AST.findImportedModuleIdentifier(\n sourceFile,\n (node) =>\n pipe(\n TypeParser.importedEffectModule(node),\n Nano.option,\n Nano.map(Option.isSome)\n )\n )\n ),\n {\n onNone: () => \"Effect\",\n onSome: (node) => node.text\n }\n )\n }\n)\n","import * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const wrapWithPipe = LSP.createRefactor({\n name: \"effect/wrapWithPipe\",\n description: \"Wrap with pipe\",\n apply: Nano.fn(\"wrapWithPipe.apply\")(function*(sourceFile, textRange) {\n if (textRange.end - textRange.pos === 0) {\n return yield* Nano.fail(new LSP.RefactorNotApplicableError())\n }\n\n return ({\n kind: \"refactor.rewrite.effect.wrapWithPipe\",\n description: `Wrap with pipe(...)`,\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n changeTracker.insertText(sourceFile, textRange.pos, \"pipe(\")\n changeTracker.insertText(sourceFile, textRange.end, \")\")\n })\n })\n })\n})\n","import { asyncAwaitToGen } from \"./refactors/asyncAwaitToGen.js\"\nimport { asyncAwaitToGenTryPromise } from \"./refactors/asyncAwaitToGenTryPromise.js\"\nimport { effectGenToFn } from \"./refactors/effectGenToFn.js\"\nimport { functionToArrow } from \"./refactors/functionToArrow.js\"\nimport { makeSchemaOpaque } from \"./refactors/makeSchemaOpaque.js\"\nimport { makeSchemaOpaqueWithNs } from \"./refactors/makeSchemaOpaqueWithNs.js\"\nimport { pipeableToDatafirst } from \"./refactors/pipeableToDatafirst.js\"\nimport { removeUnnecessaryEffectGen } from \"./refactors/removeUnnecessaryEffectGen.js\"\nimport { toggleLazyConst } from \"./refactors/toggleLazyConst.js\"\nimport { toggleReturnTypeAnnotation } from \"./refactors/toggleReturnTypeAnnotation.js\"\nimport { toggleTypeAnnotation } from \"./refactors/toggleTypeAnnotation.js\"\nimport { typeToEffectSchema } from \"./refactors/typeToEffectSchema.js\"\nimport { typeToEffectSchemaClass } from \"./refactors/typeToEffectSchemaClass.js\"\nimport { wrapWithEffectGen } from \"./refactors/wrapWithEffectGen.js\"\nimport { wrapWithPipe } from \"./refactors/wrapWithPipe.js\"\n\nexport const refactors = [\n asyncAwaitToGen,\n asyncAwaitToGenTryPromise,\n functionToArrow,\n typeToEffectSchema,\n typeToEffectSchemaClass,\n makeSchemaOpaque,\n makeSchemaOpaqueWithNs,\n pipeableToDatafirst,\n removeUnnecessaryEffectGen,\n toggleLazyConst,\n toggleReturnTypeAnnotation,\n toggleTypeAnnotation,\n wrapWithEffectGen,\n wrapWithPipe,\n effectGenToFn\n]\n","import { Either } from \"effect\"\nimport { pipe } from \"effect/Function\"\nimport type ts from \"typescript\"\nimport { completions } from \"./completions.js\"\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 { diagnostics } from \"./diagnostics.js\"\nimport { dedupeJsDocTags, prependEffectTypeArguments } from \"./quickinfo.js\"\nimport { refactors } from \"./refactors.js\"\n\nconst init = (\n modules: {\n typescript: typeof ts\n }\n) => {\n function create(info: ts.server.PluginCreateInfo) {\n const languageService = info.languageService\n const pluginOptions: LSP.PluginOptions = LSP.parsePluginOptions(info.config)\n\n // this is nothing more than an hack. Seems like vscode and other editors do not\n // support new error codes in diagnostics. Because they somehow rely on looking into\n // typescript.codefixes object. SO ONLY OPTION here is to register fake codefix.\n // by hooking into the codefixes object and registering a fake codefix.\n\n const diagnosticsErrorCodes = diagnostics.map((diagnostic) => diagnostic.code)\n try {\n ;(modules.typescript as any).codefix.registerCodeFix({\n errorCodes: diagnosticsErrorCodes,\n getCodeActions: () => undefined\n })\n // eslint-disable-next-line no-empty\n } catch (_) {}\n\n // create the proxy\n const proxy: ts.LanguageService = Object.create(null)\n for (const k of Object.keys(languageService) as Array<keyof ts.LanguageService>) {\n // @ts-expect-error\n proxy[k] = (...args: Array<{}>) => languageService[k]!.apply(languageService, args)\n }\n\n const effectCodeFixesForFile = new Map<\n string,\n Array<LSP.ApplicableDiagnosticDefinitionFixWithPositionAndCode>\n >()\n proxy.getSemanticDiagnostics = (fileName, ...args) => {\n const applicableDiagnostics = languageService.getSemanticDiagnostics(fileName, ...args)\n const program = languageService.getProgram()\n\n if (pluginOptions.diagnostics && program) {\n effectCodeFixesForFile.delete(fileName)\n const sourceFile = program.getSourceFile(fileName)\n\n if (sourceFile) {\n return pipe(\n LSP.getSemanticDiagnosticsWithCodeFixes(diagnostics, sourceFile),\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(TypeScriptApi.TypeScriptApi, modules.typescript),\n Nano.provideService(LSP.PluginOptions, pluginOptions),\n Nano.run,\n Either.map(({ codeFixes, diagnostics }) => {\n effectCodeFixesForFile.set(fileName, codeFixes)\n return diagnostics.concat(applicableDiagnostics)\n }),\n Either.getOrElse(() => applicableDiagnostics)\n )\n }\n }\n\n return applicableDiagnostics\n }\n\n proxy.getSupportedCodeFixes = (...args) =>\n languageService.getSupportedCodeFixes(...args).concat(\n diagnosticsErrorCodes.map((_) => \"\" + _)\n )\n\n proxy.getCodeFixesAtPosition = (\n fileName,\n start,\n end,\n errorCodes,\n formatOptions,\n preferences,\n ...args\n ) => {\n const applicableCodeFixes = languageService.getCodeFixesAtPosition(\n fileName,\n start,\n end,\n errorCodes,\n formatOptions,\n preferences,\n ...args\n )\n\n return pipe(\n Nano.sync(() => {\n const effectCodeFixes: Array<ts.CodeFixAction> = []\n const applicableFixes = (effectCodeFixesForFile.get(fileName) || []).filter((_) =>\n _.start === start && _.end === end && errorCodes.indexOf(_.code) > -1\n )\n\n const formatContext = modules.typescript.formatting.getFormatContext(\n formatOptions,\n info.languageServiceHost\n )\n\n for (const applicableFix of applicableFixes) {\n const changes = modules.typescript.textChanges.ChangeTracker.with(\n {\n formatContext,\n host: info.languageServiceHost,\n preferences: preferences || {}\n },\n (changeTracker) =>\n pipe(\n applicableFix.apply,\n Nano.provideService(TypeScriptApi.ChangeTracker, changeTracker),\n Nano.run\n )\n )\n effectCodeFixes.push({\n fixName: applicableFix.fixName,\n description: applicableFix.description,\n changes\n })\n }\n\n return effectCodeFixes\n }),\n Nano.run,\n Either.map((effectCodeFixes) => applicableCodeFixes.concat(effectCodeFixes)),\n Either.getOrElse(() => applicableCodeFixes)\n )\n }\n\n proxy.getApplicableRefactors = (...args) => {\n const applicableRefactors = languageService.getApplicableRefactors(...args)\n const [fileName, positionOrRange] = args\n const program = languageService.getProgram()\n\n if (program) {\n const sourceFile = program.getSourceFile(fileName)\n if (sourceFile) {\n return pipe(\n LSP.getApplicableRefactors(refactors, sourceFile, positionOrRange),\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, program.getTypeChecker()),\n Nano.provideService(\n TypeCheckerApi.TypeCheckerApiCache,\n TypeCheckerApi.makeTypeCheckerApiCache()\n ),\n Nano.provideService(TypeScriptApi.TypeScriptApi, modules.typescript),\n Nano.provideService(LSP.PluginOptions, pluginOptions),\n Nano.run,\n Either.map((effectRefactors) => applicableRefactors.concat(effectRefactors)),\n Either.getOrElse(() => applicableRefactors)\n )\n }\n }\n return applicableRefactors\n }\n\n proxy.getEditsForRefactor = (\n fileName,\n formatOptions,\n positionOrRange,\n refactorName,\n actionName,\n preferences,\n ...args\n ) => {\n const program = languageService.getProgram()\n if (program) {\n const sourceFile = program.getSourceFile(fileName)\n if (sourceFile) {\n const result = pipe(\n Nano.gen(function*() {\n const applicableRefactor = yield* LSP.getEditsForRefactor(\n refactors,\n sourceFile,\n positionOrRange,\n refactorName\n )\n\n const formatContext = modules.typescript.formatting.getFormatContext(\n formatOptions,\n info.languageServiceHost\n )\n\n const edits = modules.typescript.textChanges.ChangeTracker.with(\n {\n formatContext,\n host: info.languageServiceHost,\n preferences: preferences || {}\n },\n (changeTracker) =>\n pipe(\n applicableRefactor.apply,\n Nano.provideService(TypeScriptApi.ChangeTracker, changeTracker),\n Nano.run\n )\n )\n\n return { edits } as ts.RefactorEditInfo\n }),\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, program.getTypeChecker()),\n Nano.provideService(\n TypeCheckerApi.TypeCheckerApiCache,\n TypeCheckerApi.makeTypeCheckerApiCache()\n ),\n Nano.provideService(TypeScriptApi.TypeScriptApi, modules.typescript),\n Nano.provideService(LSP.PluginOptions, pluginOptions),\n Nano.run\n )\n\n if (Either.isRight(result)) return result.right\n }\n }\n\n return languageService.getEditsForRefactor(\n fileName,\n formatOptions,\n positionOrRange,\n refactorName,\n actionName,\n preferences,\n ...args\n )\n }\n\n proxy.getQuickInfoAtPosition = (fileName, position, ...args) => {\n const quickInfo = languageService.getQuickInfoAtPosition(fileName, position, ...args)\n\n if (pluginOptions.quickinfo) {\n const dedupedTagsQuickInfo = dedupeJsDocTags(quickInfo)\n\n const program = languageService.getProgram()\n if (program) {\n const sourceFile = program.getSourceFile(fileName)\n if (sourceFile) {\n return pipe(\n prependEffectTypeArguments(\n sourceFile,\n position,\n dedupedTagsQuickInfo\n ),\n Nano.provideService(TypeScriptApi.TypeScriptProgram, program),\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, program.getTypeChecker()),\n Nano.provideService(TypeScriptApi.TypeScriptApi, modules.typescript),\n Nano.provideService(LSP.PluginOptions, pluginOptions),\n Nano.run,\n Either.getOrElse(() => dedupedTagsQuickInfo)\n )\n }\n }\n\n return dedupedTagsQuickInfo\n }\n\n return quickInfo\n }\n\n proxy.getCompletionsAtPosition = (fileName, position, options, formattingSettings, ...args) => {\n const applicableCompletions = languageService.getCompletionsAtPosition(\n fileName,\n position,\n options,\n formattingSettings,\n ...args\n )\n\n if (pluginOptions.completions) {\n const program = languageService.getProgram()\n if (program) {\n const sourceFile = program.getSourceFile(fileName)\n if (sourceFile) {\n return pipe(\n LSP.getCompletionsAtPosition(\n completions,\n sourceFile,\n position,\n options,\n formattingSettings\n ),\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(TypeScriptApi.TypeScriptApi, modules.typescript),\n Nano.provideService(LSP.PluginOptions, pluginOptions),\n Nano.run,\n Either.map((effectCompletions) => (applicableCompletions\n ? {\n ...applicableCompletions,\n entries: effectCompletions.concat(applicableCompletions.entries)\n }\n : (effectCompletions.length > 0 ?\n ({\n entries: effectCompletions,\n isGlobalCompletion: false,\n isMemberCompletion: false,\n isNewIdentifierLocation: false\n }) satisfies ts.CompletionInfo :\n undefined))\n ),\n Either.getOrElse(() => applicableCompletions)\n )\n }\n }\n }\n\n return applicableCompletions\n }\n\n return proxy\n }\n\n return { create }\n}\n\nmodule.exports = init\n"],"mappings":";;;;;;;;AA6BO,IAAMA,aAAcC,WAAsC,OAAOA,UAAU;AA6C3E,IAAMC,OA+FT,SAASC,OAAOC,MAAI;AACtB,MAAI,OAAOD,UAAU,YAAY;AAC/B,WAAO,WAAA;AACL,UAAIA,MAAME,SAAS,GAAG;AAEpB,eAAOD,KAAKE,MAAM,MAAMD,SAAS;MACnC;AACA,aAASE,UAAcH,KAAKG,MAAM,GAAGF,SAAS;IAChD;EACF;AAEA,UAAQF,OAAK;IACX,KAAK;IACL,KAAK;AACH,YAAM,IAAIK,WAAW,iBAAiBL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kBACpB,oBAAoB;AAAA,kBACpB,yBAAyB;AAAA,gBAC3B,IACA;AAAA,cACJ;AAAA,cACA,eAAO,UAAU,MAAM,qBAAqB;AAAA,YAC9C;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AAEA,SAAO,EAAE,OAAO;AAClB;AAEA,OAAO,UAAU;","names":["isFunction","input","dual","arity","body","arguments","apply","self","RangeError","a","b","length","c","d","e","args","identity","a","constant","value","constNull","constant","constUndefined","undefined","pipe","a","ab","bc","cd","de","ef","fg","gh","hi","arguments","length","ret","i","TypeId","bind","bindTo","fromOption","getLeft","getRight","isEither","isLeft","isRight","left","let_","right","make","isEquivalent","self","that","array","item","make","self","that","length","i","isEq","let_","map","dual","self","name","f","a","Object","assign","bindTo","bind","flatMap","b","moduleVersion","getCurrentVersion","globalStoreId","version","getCurrentVersion","globalStore","globalValue","id","compute","globalThis","Map","has","set","get","isFunction","isFunction_","isRecordOrArray","input","isObject","isFunction","hasProperty","dual","self","property","getBugErrorMessage","message","GenKindTypeId","Symbol","for","isGenKind","u","isObject","GenKindImpl","value","constructor","_F","identity","_R","_","_O","_E","iterator","SingleShotGen","self","called","next","a","done","return","throw","e","adapter","x","arguments","i","length","GenKindImpl","MUL_HI","MUL_LO","YieldWrapTypeId","Symbol","for","YieldWrap","constructor","value","yieldWrapGet","self","Error","getBugErrorMessage","structuralRegionState","globalValue","enabled","tester","undefined","genConstructor","constructor","randomHashCache","globalValue","Symbol","for","WeakMap","symbol","hash","self","structuralRegionState","enabled","number","string","toString","String","Date","toISOString","isHash","random","Error","has","set","Math","floor","Number","MAX_SAFE_INTEGER","get","combine","b","optimize","n","u","hasProperty","Infinity","h","str","i","length","charCodeAt","structureKeys","o","keys","pipe","structure","Object","cached","arguments","length","self","hash","Object","defineProperty","symbol","value","enumerable","symbol","Symbol","for","equals","arguments","length","self","compareBoth","that","selfType","isEqual","hash","structuralRegionState","enabled","tester","Date","toISOString","Array","isArray","every","v","i","Object","getPrototypeOf","prototype","keysSelf","keys","keysThat","key","u","hasProperty","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","getLeft","self","none","some","getRight","fromOption","dual","onNone","isNone","value","TypeId","right","left","fromNullable","dual","self","onNullable","fromOption","try_","evaluate","isFunction","e","try","catch","isEither","isLeft","isRight","getRight","getLeft","getEquivalence","left","right","make","x","y","mapBoth","dual","self","onLeft","onRight","mapLeft","f","map","match","liftPredicate","a","predicate","orLeftWith","filterOrLeft","flatMap","r","merge","identity","getOrElse","getOrNull","constNull","getOrUndefined","constUndefined","getOrThrowWith","getOrThrow","Error","orElse","that","andThen","b","isFunction","zipWith","r2","ap","all","input","Symbol","iterator","out","e","push","key","Object","keys","flip","adapter","Gen","gen","args","length","bind","state","next","done","value","current","isGenKind","yieldWrapGet","Do","doNotation","bindTo","let_","isNonEmptyArray","self","length","make","compare","self","that","none","some","isNone","isSome","match","dual","self","onNone","onSome","value","getOrElse","dual","self","onNone","isNone","value","orElse","that","fromNullable","nullableValue","none","some","getOrUndefined","getOrElse","constUndefined","fromIterable","collection","Array","isArray","from","append","dual","self","last","isArray","Array","isEmptyArray","self","length","isEmptyReadonlyArray","isNonEmptyReadonlyArray","isNonEmptyArray","isOutOfBound","i","as","length","get","dual","self","index","i","Math","floor","isOutOfBound","none","some","unsafeGet","Error","head","get","headNonEmpty","unsafeGet","tailNonEmpty","self","slice","sort","dual","self","O","out","Array","from","empty","map","dual","self","f","flatMap","isEmptyReadonlyArray","out","i","length","inner","j","push","flatten","identity","filter","dual","self","predicate","as","fromIterable","out","i","length","push","dedupeWith","dual","self","isEquivalent","input","fromIterable","isNonEmptyReadonlyArray","out","headNonEmpty","rest","tailNonEmpty","r","every","a","push","make","run","left","right","flatMap","map","orElse","arr","gen","some","none","all","isNone","none","fromNullable","orElse","some","isSome","typeNode","isSome","map","refactors","refactor","completions","match","flatMap","isNone","match","isNone","match","isNone","match","isNone","match","gen","make","symbol","isSome","isSome","isSome","orElse","isNone","orElse","orElse","orElse","isSome","gen","flatMap","isSome","gen","gen","isNone","effectType","orElse","node","isNone","gen","match","map","isSome","node","isNone","gen","match","map","isSome","effectGen","pipeArgs","nodeToReplace","map","isNone","gen","isNone","gen","map","isNone","gen","match","isNone","gen","match","node","none","some","map","newNode","isSome","isNone","gen","flatMap","isNone","gen","node","isNone","gen","node","isNone","node","isNone","gen","fromNullable","orElse","getOrUndefined","match","isSome","some","none","left","all","gen","isNone","orElse","isNone","isNone","map","isNone","gen","effectGen","match","isSome","gen","diagnostics","gen"]}