@effect/language-service 0.33.0 → 0.33.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/README.md +3 -2
- package/index.js +5 -25
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/transform.js +36 -25
- package/transform.js.map +1 -1
package/transform.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/transform.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/Function.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/GlobalValue.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/Predicate.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/internal/errors.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/Utils.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/Hash.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/Equal.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/Inspectable.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/Pipeable.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/internal/opCodes/effect.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/internal/version.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/internal/effectable.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/internal/option.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/internal/either.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/Either.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/internal/array.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/Order.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/Option.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/Array.ts","../src/core/Nano.ts","../src/core/LanguageServicePluginOptions.ts","../src/core/TypeScriptApi.ts","../src/core/TypeScriptUtils.ts","../src/core/LSP.ts","../src/core/TypeCheckerApi.ts","../src/core/TypeParser.ts","../src/diagnostics/classSelfMismatch.ts","../src/diagnostics/duplicatePackage.ts","../src/diagnostics/effectInVoidSuccess.ts","../src/diagnostics/floatingEffect.ts","../src/diagnostics/genericEffectServices.ts","../src/diagnostics/importFromBarrel.ts","../src/diagnostics/leakingRequirements.ts","../src/diagnostics/missingEffectContext.ts","../src/diagnostics/missingEffectError.ts","../src/diagnostics/missingEffectServiceDependency.ts","../src/diagnostics/missingReturnYieldStar.ts","../src/diagnostics/missingStarInYieldEffectGen.ts","../src/diagnostics/multipleEffectProvide.ts","../src/refactors/writeTagClassAccessors.ts","../src/codegens/accessors.ts","../src/codegens.ts","../src/diagnostics/outdatedEffectCodegen.ts","../src/diagnostics/returnEffectInGen.ts","../src/diagnostics/scopeInLayerEffect.ts","../src/diagnostics/strictBooleanExpressions.ts","../src/diagnostics/tryCatchInEffectGen.ts","../src/diagnostics/unnecessaryEffectGen.ts","../src/diagnostics/unnecessaryPipe.ts","../src/diagnostics/unnecessaryPipeChain.ts","../src/diagnostics/unsupportedServiceAccessors.ts","../src/diagnostics.ts"],"sourcesContent":["import * as Array from \"effect/Array\"\nimport * as Either from \"effect/Either\"\nimport { pipe } from \"effect/Function\"\nimport type { PluginConfig, TransformerExtras } from \"ts-patch\"\nimport type * as ts from \"typescript\"\nimport * as LanguageServicePluginOptions from \"./core/LanguageServicePluginOptions\"\nimport * as LSP from \"./core/LSP\"\nimport * as Nano from \"./core/Nano\"\nimport * as TypeCheckerApi from \"./core/TypeCheckerApi\"\nimport * as TypeParser from \"./core/TypeParser\"\nimport * as TypeScriptApi from \"./core/TypeScriptApi\"\nimport * as TypeScriptUtils from \"./core/TypeScriptUtils\"\nimport { diagnostics } from \"./diagnostics\"\n\nexport default function(\n program: ts.Program,\n pluginConfig: PluginConfig,\n { addDiagnostic, ts: tsInstance }: TransformerExtras\n) {\n return (_: ts.TransformationContext) => {\n return (sourceFile: ts.SourceFile) => {\n // run the diagnostics and pipe them into addDiagnostic\n pipe(\n LSP.getSemanticDiagnosticsWithCodeFixes(diagnostics, sourceFile),\n TypeParser.nanoLayer,\n TypeScriptUtils.nanoLayer,\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, program.getTypeChecker()),\n Nano.provideService(TypeScriptApi.TypeScriptProgram, program),\n Nano.provideService(TypeScriptApi.TypeScriptApi, tsInstance),\n Nano.provideService(\n LanguageServicePluginOptions.LanguageServicePluginOptions,\n LanguageServicePluginOptions.parse(pluginConfig)\n ),\n Nano.run,\n Either.map((_) => _.diagnostics),\n Either.map(\n Array.filter((_) =>\n _.category === tsInstance.DiagnosticCategory.Error ||\n _.category === tsInstance.DiagnosticCategory.Warning\n )\n ),\n Either.getOrElse(() => []),\n Array.map(addDiagnostic)\n )\n\n // do not transform source ccde\n return sourceFile\n }\n }\n}\n","/**\n * @since 2.0.0\n */\nimport type { TypeLambda } from \"./HKT.js\"\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface FunctionTypeLambda extends TypeLambda {\n readonly type: (a: this[\"In\"]) => this[\"Target\"]\n}\n\n/**\n * Tests if a value is a `function`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isFunction } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isFunction(isFunction), true)\n * assert.deepStrictEqual(isFunction(\"function\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isFunction = (input: unknown): input is Function => typeof input === \"function\"\n\n/**\n * Creates a function that can be used in a data-last (aka `pipe`able) or\n * data-first style.\n *\n * The first parameter to `dual` is either the arity of the uncurried function\n * or a predicate that determines if the function is being used in a data-first\n * or data-last style.\n *\n * Using the arity is the most common use case, but there are some cases where\n * you may want to use a predicate. For example, if you have a function that\n * takes an optional argument, you can use a predicate to determine if the\n * function is being used in a data-first or data-last style.\n *\n * You can pass either the arity of the uncurried function or a predicate\n * which determines if the function is being used in a data-first or\n * data-last style.\n *\n * **Example** (Using arity to determine data-first or data-last style)\n *\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * const sum = dual<\n * (that: number) => (self: number) => number,\n * (self: number, that: number) => number\n * >(2, (self, that) => self + that)\n *\n * console.log(sum(2, 3)) // 5\n * console.log(pipe(2, sum(3))) // 5\n * ```\n *\n * **Example** (Using call signatures to define the overloads)\n *\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * const sum: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual(2, (self: number, that: number): number => self + that)\n *\n * console.log(sum(2, 3)) // 5\n * console.log(pipe(2, sum(3))) // 5\n * ```\n *\n * **Example** (Using a predicate to determine data-first or data-last style)\n *\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * const sum = dual<\n * (that: number) => (self: number) => number,\n * (self: number, that: number) => number\n * >(\n * (args) => args.length === 2,\n * (self, that) => self + that\n * )\n *\n * console.log(sum(2, 3)) // 5\n * console.log(pipe(2, sum(3))) // 5\n * ```\n *\n * @since 2.0.0\n */\nexport const dual: {\n /**\n * Creates a function that can be used in a data-last (aka `pipe`able) or\n * data-first style.\n *\n * The first parameter to `dual` is either the arity of the uncurried function\n * or a predicate that determines if the function is being used in a data-first\n * or data-last style.\n *\n * Using the arity is the most common use case, but there are some cases where\n * you may want to use a predicate. For example, if you have a function that\n * takes an optional argument, you can use a predicate to determine if the\n * function is being used in a data-first or data-last style.\n *\n * You can pass either the arity of the uncurried function or a predicate\n * which determines if the function is being used in a data-first or\n * data-last style.\n *\n * **Example** (Using arity to determine data-first or data-last style)\n *\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * const sum = dual<\n * (that: number) => (self: number) => number,\n * (self: number, that: number) => number\n * >(2, (self, that) => self + that)\n *\n * console.log(sum(2, 3)) // 5\n * console.log(pipe(2, sum(3))) // 5\n * ```\n *\n * **Example** (Using call signatures to define the overloads)\n *\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * const sum: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual(2, (self: number, that: number): number => self + that)\n *\n * console.log(sum(2, 3)) // 5\n * console.log(pipe(2, sum(3))) // 5\n * ```\n *\n * **Example** (Using a predicate to determine data-first or data-last style)\n *\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * const sum = dual<\n * (that: number) => (self: number) => number,\n * (self: number, that: number) => number\n * >(\n * (args) => args.length === 2,\n * (self, that) => self + that\n * )\n *\n * console.log(sum(2, 3)) // 5\n * console.log(pipe(2, sum(3))) // 5\n * ```\n *\n * @since 2.0.0\n */\n <DataLast extends (...args: Array<any>) => any, DataFirst extends (...args: Array<any>) => any>(arity: Parameters<DataFirst>[\"length\"], body: DataFirst): DataLast & DataFirst\n /**\n * Creates a function that can be used in a data-last (aka `pipe`able) or\n * data-first style.\n *\n * The first parameter to `dual` is either the arity of the uncurried function\n * or a predicate that determines if the function is being used in a data-first\n * or data-last style.\n *\n * Using the arity is the most common use case, but there are some cases where\n * you may want to use a predicate. For example, if you have a function that\n * takes an optional argument, you can use a predicate to determine if the\n * function is being used in a data-first or data-last style.\n *\n * You can pass either the arity of the uncurried function or a predicate\n * which determines if the function is being used in a data-first or\n * data-last style.\n *\n * **Example** (Using arity to determine data-first or data-last style)\n *\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * const sum = dual<\n * (that: number) => (self: number) => number,\n * (self: number, that: number) => number\n * >(2, (self, that) => self + that)\n *\n * console.log(sum(2, 3)) // 5\n * console.log(pipe(2, sum(3))) // 5\n * ```\n *\n * **Example** (Using call signatures to define the overloads)\n *\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * const sum: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual(2, (self: number, that: number): number => self + that)\n *\n * console.log(sum(2, 3)) // 5\n * console.log(pipe(2, sum(3))) // 5\n * ```\n *\n * **Example** (Using a predicate to determine data-first or data-last style)\n *\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * const sum = dual<\n * (that: number) => (self: number) => number,\n * (self: number, that: number) => number\n * >(\n * (args) => args.length === 2,\n * (self, that) => self + that\n * )\n *\n * console.log(sum(2, 3)) // 5\n * console.log(pipe(2, sum(3))) // 5\n * ```\n *\n * @since 2.0.0\n */\n <DataLast extends (...args: Array<any>) => any, DataFirst extends (...args: Array<any>) => any>(isDataFirst: (args: IArguments) => boolean, body: DataFirst): DataLast & DataFirst\n} = function(arity, body) {\n if (typeof arity === \"function\") {\n return function() {\n if (arity(arguments)) {\n // @ts-expect-error\n return body.apply(this, arguments)\n }\n return ((self: any) => body(self, ...arguments)) as any\n }\n }\n\n switch (arity) {\n case 0:\n case 1:\n throw new RangeError(`Invalid arity ${arity}`)\n\n case 2:\n return function(a, b) {\n if (arguments.length >= 2) {\n return body(a, b)\n }\n return function(self: any) {\n return body(self, a)\n }\n }\n\n case 3:\n return function(a, b, c) {\n if (arguments.length >= 3) {\n return body(a, b, c)\n }\n return function(self: any) {\n return body(self, a, b)\n }\n }\n\n case 4:\n return function(a, b, c, d) {\n if (arguments.length >= 4) {\n return body(a, b, c, d)\n }\n return function(self: any) {\n return body(self, a, b, c)\n }\n }\n\n case 5:\n return function(a, b, c, d, e) {\n if (arguments.length >= 5) {\n return body(a, b, c, d, e)\n }\n return function(self: any) {\n return body(self, a, b, c, d)\n }\n }\n\n default:\n return function() {\n if (arguments.length >= arity) {\n // @ts-expect-error\n return body.apply(this, arguments)\n }\n const args = arguments\n return function(self: any) {\n return body(self, ...args)\n }\n }\n }\n}\n/**\n * Apply a function to given values.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, apply } from \"effect/Function\"\n * import { length } from \"effect/String\"\n *\n * assert.deepStrictEqual(pipe(length, apply(\"hello\")), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const apply = <A extends ReadonlyArray<unknown>>(...a: A) => <B>(self: (...a: A) => B): B => self(...a)\n\n/**\n * A lazy argument.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { LazyArg, constant } from \"effect/Function\"\n *\n * const constNull: LazyArg<null> = constant(null)\n * ```\n *\n * @since 2.0.0\n */\nexport interface LazyArg<A> {\n (): A\n}\n\n/**\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { FunctionN } from \"effect/Function\"\n *\n * const sum: FunctionN<[number, number], number> = (a, b) => a + b\n * ```\n *\n * @since 2.0.0\n */\nexport interface FunctionN<A extends ReadonlyArray<unknown>, B> {\n (...args: A): B\n}\n\n/**\n * The identity function, i.e. A function that returns its input argument.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { identity } from \"effect/Function\"\n *\n * assert.deepStrictEqual(identity(5), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const identity = <A>(a: A): A => a\n\n/**\n * A function that ensures that the type of an expression matches some type,\n * without changing the resulting type of that expression.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { satisfies } from \"effect/Function\"\n *\n * const test1 = satisfies<number>()(5 as const)\n * //^? const test: 5\n * // @ts-expect-error\n * const test2 = satisfies<string>()(5)\n * //^? Argument of type 'number' is not assignable to parameter of type 'string'\n *\n * assert.deepStrictEqual(satisfies<number>()(5), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const satisfies = <A>() => <B extends A>(b: B) => b\n\n/**\n * Casts the result to the specified type.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { unsafeCoerce, identity } from \"effect/Function\"\n *\n * assert.deepStrictEqual(unsafeCoerce, identity)\n * ```\n *\n * @since 2.0.0\n */\nexport const unsafeCoerce: <A, B>(a: A) => B = identity as any\n\n/**\n * Creates a constant value that never changes.\n *\n * This is useful when you want to pass a value to a higher-order function (a function that takes another function as its argument)\n * and want that inner function to always use the same value, no matter how many times it is called.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { constant } from \"effect/Function\"\n *\n * const constNull = constant(null)\n *\n * assert.deepStrictEqual(constNull(), null)\n * assert.deepStrictEqual(constNull(), null)\n * ```\n *\n * @since 2.0.0\n */\nexport const constant = <A>(value: A): LazyArg<A> => () => value\n\n/**\n * A thunk that returns always `true`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { constTrue } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constTrue(), true)\n * ```\n *\n * @since 2.0.0\n */\nexport const constTrue: LazyArg<boolean> = constant(true)\n\n/**\n * A thunk that returns always `false`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { constFalse } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constFalse(), false)\n * ```\n *\n * @since 2.0.0\n */\nexport const constFalse: LazyArg<boolean> = constant(false)\n\n/**\n * A thunk that returns always `null`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { constNull } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constNull(), null)\n * ```\n *\n * @since 2.0.0\n */\nexport const constNull: LazyArg<null> = constant(null)\n\n/**\n * A thunk that returns always `undefined`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { constUndefined } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constUndefined(), undefined)\n * ```\n *\n * @since 2.0.0\n */\nexport const constUndefined: LazyArg<undefined> = constant(undefined)\n\n/**\n * A thunk that returns always `void`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { constVoid } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constVoid(), undefined)\n * ```\n *\n * @since 2.0.0\n */\nexport const constVoid: LazyArg<void> = constUndefined\n\n/**\n * Reverses the order of arguments for a curried function.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { flip } from \"effect/Function\"\n *\n * const f = (a: number) => (b: string) => a - b.length\n *\n * assert.deepStrictEqual(flip(f)('aaa')(2), -1)\n * ```\n *\n * @since 2.0.0\n */\nexport const flip = <A extends Array<unknown>, B extends Array<unknown>, C>(\n f: (...a: A) => (...b: B) => C\n): (...b: B) => (...a: A) => C =>\n(...b) =>\n(...a) => f(...a)(...b)\n\n/**\n * Composes two functions, `ab` and `bc` into a single function that takes in an argument `a` of type `A` and returns a result of type `C`.\n * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { compose } from \"effect/Function\"\n *\n * const increment = (n: number) => n + 1;\n * const square = (n: number) => n * n;\n *\n * assert.strictEqual(compose(increment, square)(2), 9);\n * ```\n *\n * @since 2.0.0\n */\nexport const compose: {\n /**\n * Composes two functions, `ab` and `bc` into a single function that takes in an argument `a` of type `A` and returns a result of type `C`.\n * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { compose } from \"effect/Function\"\n *\n * const increment = (n: number) => n + 1;\n * const square = (n: number) => n * n;\n *\n * assert.strictEqual(compose(increment, square)(2), 9);\n * ```\n *\n * @since 2.0.0\n */\n <B, C>(bc: (b: B) => C): <A>(self: (a: A) => B) => (a: A) => C\n /**\n * Composes two functions, `ab` and `bc` into a single function that takes in an argument `a` of type `A` and returns a result of type `C`.\n * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { compose } from \"effect/Function\"\n *\n * const increment = (n: number) => n + 1;\n * const square = (n: number) => n * n;\n *\n * assert.strictEqual(compose(increment, square)(2), 9);\n * ```\n *\n * @since 2.0.0\n */\n <A, B, C>(self: (a: A) => B, bc: (b: B) => C): (a: A) => C\n} = dual(2, <A, B, C>(ab: (a: A) => B, bc: (b: B) => C): (a: A) => C => (a) => bc(ab(a)))\n\n/**\n * The `absurd` function is a stub for cases where a value of type `never` is encountered in your code,\n * meaning that it should be impossible for this code to be executed.\n *\n * This function is particularly useful when it's necessary to specify that certain cases are impossible.\n *\n * @since 2.0.0\n */\nexport const absurd = <A>(_: never): A => {\n throw new Error(\"Called `absurd` function which should be uncallable\")\n}\n\n/**\n * Creates a version of this function: instead of `n` arguments, it accepts a single tuple argument.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { tupled } from \"effect/Function\"\n *\n * const sumTupled = tupled((x: number, y: number): number => x + y)\n *\n * assert.deepStrictEqual(sumTupled([1, 2]), 3)\n * ```\n *\n * @since 2.0.0\n */\nexport const tupled = <A extends ReadonlyArray<unknown>, B>(f: (...a: A) => B): (a: A) => B => (a) => f(...a)\n\n/**\n * Inverse function of `tupled`\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { untupled } from \"effect/Function\"\n *\n * const getFirst = untupled(<A, B>(tuple: [A, B]): A => tuple[0])\n *\n * assert.deepStrictEqual(getFirst(1, 2), 1)\n * ```\n *\n * @since 2.0.0\n */\nexport const untupled = <A extends ReadonlyArray<unknown>, B>(f: (a: A) => B): (...a: A) => B => (...a) => f(a)\n\n/**\n * Pipes the value of an expression into a pipeline of functions.\n *\n * **Details**\n *\n * The `pipe` function is a utility that allows us to compose functions in a\n * readable and sequential manner. It takes the output of one function and\n * passes it as the input to the next function in the pipeline. This enables us\n * to build complex transformations by chaining multiple functions together.\n *\n * ```ts skip-type-checking\n * import { pipe } from \"effect\"\n *\n * const result = pipe(input, func1, func2, ..., funcN)\n * ```\n *\n * In this syntax, `input` is the initial value, and `func1`, `func2`, ...,\n * `funcN` are the functions to be applied in sequence. The result of each\n * function becomes the input for the next function, and the final result is\n * returned.\n *\n * Here's an illustration of how `pipe` works:\n *\n * ```\n * ┌───────┐ ┌───────┐ ┌───────┐ ┌───────┐ ┌───────┐ ┌────────┐\n * │ input │───►│ func1 │───►│ func2 │───►│ ... │───►│ funcN │───►│ result │\n * └───────┘ └───────┘ └───────┘ └───────┘ └───────┘ └────────┘\n * ```\n *\n * It's important to note that functions passed to `pipe` must have a **single\n * argument** because they are only called with a single argument.\n *\n * **When to Use**\n *\n * This is useful in combination with data-last functions as a simulation of\n * methods:\n *\n * ```ts skip-type-checking\n * as.map(f).filter(g)\n * ```\n *\n * becomes:\n *\n * ```ts skip-type-checking\n * import { pipe, Array } from \"effect\"\n *\n * pipe(as, Array.map(f), Array.filter(g))\n * ```\n *\n * **Example** (Chaining Arithmetic Operations)\n *\n * ```ts\n * import { pipe } from \"effect\"\n *\n * // Define simple arithmetic operations\n * const increment = (x: number) => x + 1\n * const double = (x: number) => x * 2\n * const subtractTen = (x: number) => x - 10\n *\n * // Sequentially apply these operations using `pipe`\n * const result = pipe(5, increment, double, subtractTen)\n *\n * console.log(result)\n * // Output: 2\n * ```\n *\n * @since 2.0.0\n */\nexport function pipe<A>(a: A): A\nexport function pipe<A, B = never>(a: A, ab: (a: A) => B): B\nexport function pipe<A, B = never, C = never>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C\n): C\nexport function pipe<A, B = never, C = never, D = never>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D\n): D\nexport function pipe<A, B = never, C = never, D = never, E = never>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E\n): E\nexport function pipe<A, B = never, C = never, D = never, E = never, F = never>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F\n): F\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G\n): G\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H\n): H\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I\n): I\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J\n): J\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K\n): K\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L\n): L\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M\n): M\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N\n): N\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O\n): O\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P\n): P\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q\n): Q\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R\n): R\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => S\n): S\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never,\n T = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => S,\n st: (s: S) => T\n): T\nexport function pipe(\n a: unknown,\n ab?: Function,\n bc?: Function,\n cd?: Function,\n de?: Function,\n ef?: Function,\n fg?: Function,\n gh?: Function,\n hi?: Function\n): unknown {\n switch (arguments.length) {\n case 1:\n return a\n case 2:\n return ab!(a)\n case 3:\n return bc!(ab!(a))\n case 4:\n return cd!(bc!(ab!(a)))\n case 5:\n return de!(cd!(bc!(ab!(a))))\n case 6:\n return ef!(de!(cd!(bc!(ab!(a)))))\n case 7:\n return fg!(ef!(de!(cd!(bc!(ab!(a))))))\n case 8:\n return gh!(fg!(ef!(de!(cd!(bc!(ab!(a)))))))\n case 9:\n return hi!(gh!(fg!(ef!(de!(cd!(bc!(ab!(a))))))))\n default: {\n let ret = arguments[0]\n for (let i = 1; i < arguments.length; i++) {\n ret = arguments[i](ret)\n }\n return ret\n }\n }\n}\n\n/**\n * Performs left-to-right function composition. The first argument may have any arity, the remaining arguments must be unary.\n *\n * See also [`pipe`](#pipe).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { flow } from \"effect/Function\"\n *\n * const len = (s: string): number => s.length\n * const double = (n: number): number => n * 2\n *\n * const f = flow(len, double)\n *\n * assert.strictEqual(f('aaa'), 6)\n * ```\n *\n * @since 2.0.0\n */\nexport function flow<A extends ReadonlyArray<unknown>, B = never>(\n ab: (...a: A) => B\n): (...a: A) => B\nexport function flow<A extends ReadonlyArray<unknown>, B = never, C = never>(\n ab: (...a: A) => B,\n bc: (b: B) => C\n): (...a: A) => C\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never\n>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...a: A) => D\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E\n): (...a: A) => E\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F\n): (...a: A) => F\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G\n): (...a: A) => G\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H\n): (...a: A) => H\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I\n): (...a: A) => I\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J\n): (...a: A) => J\nexport function flow(\n ab: Function,\n bc?: Function,\n cd?: Function,\n de?: Function,\n ef?: Function,\n fg?: Function,\n gh?: Function,\n hi?: Function,\n ij?: Function\n): unknown {\n switch (arguments.length) {\n case 1:\n return ab\n case 2:\n return function(this: unknown) {\n return bc!(ab.apply(this, arguments))\n }\n case 3:\n return function(this: unknown) {\n return cd!(bc!(ab.apply(this, arguments)))\n }\n case 4:\n return function(this: unknown) {\n return de!(cd!(bc!(ab.apply(this, arguments))))\n }\n case 5:\n return function(this: unknown) {\n return ef!(de!(cd!(bc!(ab.apply(this, arguments)))))\n }\n case 6:\n return function(this: unknown) {\n return fg!(ef!(de!(cd!(bc!(ab.apply(this, arguments))))))\n }\n case 7:\n return function(this: unknown) {\n return gh!(fg!(ef!(de!(cd!(bc!(ab.apply(this, arguments)))))))\n }\n case 8:\n return function(this: unknown) {\n return hi!(gh!(fg!(ef!(de!(cd!(bc!(ab.apply(this, arguments))))))))\n }\n case 9:\n return function(this: unknown) {\n return ij!(hi!(gh!(fg!(ef!(de!(cd!(bc!(ab.apply(this, arguments)))))))))\n }\n }\n return\n}\n\n/**\n * Type hole simulation.\n *\n * @since 2.0.0\n */\nexport const hole: <T>() => T = unsafeCoerce(absurd)\n\n/**\n * The SK combinator, also known as the \"S-K combinator\" or \"S-combinator\", is a fundamental combinator in the\n * lambda calculus and the SKI combinator calculus.\n *\n * This function is useful for discarding the first argument passed to it and returning the second argument.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { SK } from \"effect/Function\";\n *\n * assert.deepStrictEqual(SK(0, \"hello\"), \"hello\")\n * ```\n *\n * @since 2.0.0\n */\nexport const SK = <A, B>(_: A, b: B): B => b\n","/**\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 */\nconst globalStoreId = `effect/GlobalValue`\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 * This module provides a collection of functions for working with predicates and refinements.\n *\n * A `Predicate<A>` is a function that takes a value of type `A` and returns a boolean.\n * It is used to check if a value satisfies a certain condition.\n *\n * A `Refinement<A, B>` is a special type of predicate that not only checks a condition\n * but also provides a type guard, allowing TypeScript to narrow the type of the input\n * value from `A` to a more specific type `B` within a conditional block.\n *\n * The module includes:\n * - Basic predicates and refinements for common types (e.g., `isString`, `isNumber`).\n * - Combinators to create new predicates from existing ones (e.g., `and`, `or`, `not`).\n * - Advanced combinators for working with data structures (e.g., `tuple`, `struct`).\n * - Type-level utilities for inspecting predicate and refinement types.\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 * Represents a function that takes a value of type `A` and returns `true` if the value\n * satisfies some condition, `false` otherwise.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n * import * as assert from \"node:assert\"\n *\n * const isEven: Predicate.Predicate<number> = (n) => n % 2 === 0\n *\n * assert.strictEqual(isEven(2), true)\n * assert.strictEqual(isEven(3), false)\n * ```\n *\n * @category models\n * @since 2.0.0\n */\nexport interface Predicate<in A> {\n (a: A): boolean\n}\n\n/**\n * A `TypeLambda` for `Predicate`. This is used to support higher-kinded types\n * and allows `Predicate` to be used in generic contexts within the `effect` ecosystem.\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 * Represents a function that serves as a type guard.\n *\n * A `Refinement<A, B>` is a function that takes a value of type `A` and returns a\n * type predicate `a is B`, where `B` is a subtype of `A`. If the function returns\n * `true`, TypeScript will narrow the type of the input variable to `B`.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n * import * as assert from \"node:assert\"\n *\n * const isString: Predicate.Refinement<unknown, string> = (u): u is string => typeof u === \"string\"\n *\n * const value: unknown = \"hello\"\n *\n * if (isString(value)) {\n * // value is now known to be a string\n * assert.strictEqual(value.toUpperCase(), \"HELLO\")\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 * A namespace for type-level utilities for `Predicate`.\n *\n * @since 3.6.0\n * @category type-level\n */\nexport declare namespace Predicate {\n /**\n * Extracts the input type `A` from a `Predicate<A>`.\n *\n * @example\n * ```ts\n * import { type Predicate } from \"effect\"\n *\n * type T = Predicate.Predicate.In<Predicate.Predicate<string>> // T is string\n * ```\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 * A type representing any `Predicate`.\n *\n * @since 3.6.0\n * @category type-level\n */\n export type Any = Predicate<never>\n}\n\n/**\n * A namespace for type-level utilities for `Refinement`.\n *\n * @since 3.6.0\n * @category type-level\n */\nexport declare namespace Refinement {\n /**\n * Extracts the input type `A` from a `Refinement<A, B>`.\n *\n * @example\n * ```ts\n * import { type Predicate } from \"effect\"\n *\n * type IsString = Predicate.Refinement<unknown, string>\n * type T = Predicate.Refinement.In<IsString> // T is unknown\n * ```\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 * Extracts the output (refined) type `B` from a `Refinement<A, B>`.\n *\n * @example\n * ```ts\n * import { type Predicate } from \"effect\"\n *\n * type IsString = Predicate.Refinement<unknown, string>\n * type T = Predicate.Refinement.Out<IsString> // T is string\n * ```\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 * A type representing any `Refinement`.\n *\n * @since 3.6.0\n * @category type-level\n */\n export type Any = Refinement<any, any>\n}\n\n/**\n * Transforms a `Predicate<A>` into a `Predicate<B>` by applying a function `(b: B) => A`\n * to the input before passing it to the predicate. This is also known as \"contramap\" or\n * \"pre-composition\".\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n * import * as assert from \"node:assert\"\n *\n * // A predicate on numbers\n * const isPositive: Predicate.Predicate<number> = Number.greaterThan(0)\n *\n * // A function from `string` to `number`\n * const stringLength = (s: string): number => s.length\n *\n * // Create a new predicate on strings by mapping the input\n * const hasPositiveLength = Predicate.mapInput(isPositive, stringLength)\n *\n * assert.strictEqual(hasPositiveLength(\"hello\"), true)\n * assert.strictEqual(hasPositiveLength(\"\"), false)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const mapInput: {\n /**\n * Transforms a `Predicate<A>` into a `Predicate<B>` by applying a function `(b: B) => A`\n * to the input before passing it to the predicate. This is also known as \"contramap\" or\n * \"pre-composition\".\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n * import * as assert from \"node:assert\"\n *\n * // A predicate on numbers\n * const isPositive: Predicate.Predicate<number> = Number.greaterThan(0)\n *\n * // A function from `string` to `number`\n * const stringLength = (s: string): number => s.length\n *\n * // Create a new predicate on strings by mapping the input\n * const hasPositiveLength = Predicate.mapInput(isPositive, stringLength)\n *\n * assert.strictEqual(hasPositiveLength(\"hello\"), true)\n * assert.strictEqual(hasPositiveLength(\"\"), false)\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 * Transforms a `Predicate<A>` into a `Predicate<B>` by applying a function `(b: B) => A`\n * to the input before passing it to the predicate. This is also known as \"contramap\" or\n * \"pre-composition\".\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n * import * as assert from \"node:assert\"\n *\n * // A predicate on numbers\n * const isPositive: Predicate.Predicate<number> = Number.greaterThan(0)\n *\n * // A function from `string` to `number`\n * const stringLength = (s: string): number => s.length\n *\n * // Create a new predicate on strings by mapping the input\n * const hasPositiveLength = Predicate.mapInput(isPositive, stringLength)\n *\n * assert.strictEqual(hasPositiveLength(\"hello\"), true)\n * assert.strictEqual(hasPositiveLength(\"\"), false)\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 * A refinement that checks if a `ReadonlyArray<T>` is a tuple with exactly `N` elements.\n * If the check is successful, the type is narrowed to `TupleOf<N, T>`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isTupleOf } from \"effect/Predicate\"\n *\n * const isTupleOf3 = isTupleOf(3)\n *\n * assert.strictEqual(isTupleOf3([1, 2, 3]), true);\n * assert.strictEqual(isTupleOf3([1, 2]), false);\n *\n * const arr: number[] = [1, 2, 3];\n * if (isTupleOf(arr, 3)) {\n * // The type of arr is now [number, number, number]\n * const [a, b, c] = arr;\n * assert.deepStrictEqual([a, b, c], [1, 2, 3])\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\nexport const isTupleOf: {\n /**\n * A refinement that checks if a `ReadonlyArray<T>` is a tuple with exactly `N` elements.\n * If the check is successful, the type is narrowed to `TupleOf<N, T>`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isTupleOf } from \"effect/Predicate\"\n *\n * const isTupleOf3 = isTupleOf(3)\n *\n * assert.strictEqual(isTupleOf3([1, 2, 3]), true);\n * assert.strictEqual(isTupleOf3([1, 2]), false);\n *\n * const arr: number[] = [1, 2, 3];\n * if (isTupleOf(arr, 3)) {\n * // The type of arr is now [number, number, number]\n * const [a, b, c] = arr;\n * assert.deepStrictEqual([a, b, c], [1, 2, 3])\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 * A refinement that checks if a `ReadonlyArray<T>` is a tuple with exactly `N` elements.\n * If the check is successful, the type is narrowed to `TupleOf<N, T>`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isTupleOf } from \"effect/Predicate\"\n *\n * const isTupleOf3 = isTupleOf(3)\n *\n * assert.strictEqual(isTupleOf3([1, 2, 3]), true);\n * assert.strictEqual(isTupleOf3([1, 2]), false);\n *\n * const arr: number[] = [1, 2, 3];\n * if (isTupleOf(arr, 3)) {\n * // The type of arr is now [number, number, number]\n * const [a, b, c] = arr;\n * assert.deepStrictEqual([a, b, c], [1, 2, 3])\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 * A refinement that checks if a `ReadonlyArray<T>` is a tuple with at least `N` elements.\n * If the check is successful, the type is narrowed to `TupleOfAtLeast<N, T>`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isTupleOfAtLeast } from \"effect/Predicate\"\n *\n * const isTupleOfAtLeast3 = isTupleOfAtLeast(3)\n *\n * assert.strictEqual(isTupleOfAtLeast3([1, 2, 3]), true);\n * assert.strictEqual(isTupleOfAtLeast3([1, 2, 3, 4]), true);\n * assert.strictEqual(isTupleOfAtLeast3([1, 2]), false);\n *\n * const arr: number[] = [1, 2, 3, 4];\n * if (isTupleOfAtLeast(arr, 3)) {\n * // The type of arr is now [number, number, number, ...number[]]\n * const [a, b, c] = arr;\n * assert.deepStrictEqual([a, b, c], [1, 2, 3])\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\nexport const isTupleOfAtLeast: {\n /**\n * A refinement that checks if a `ReadonlyArray<T>` is a tuple with at least `N` elements.\n * If the check is successful, the type is narrowed to `TupleOfAtLeast<N, T>`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isTupleOfAtLeast } from \"effect/Predicate\"\n *\n * const isTupleOfAtLeast3 = isTupleOfAtLeast(3)\n *\n * assert.strictEqual(isTupleOfAtLeast3([1, 2, 3]), true);\n * assert.strictEqual(isTupleOfAtLeast3([1, 2, 3, 4]), true);\n * assert.strictEqual(isTupleOfAtLeast3([1, 2]), false);\n *\n * const arr: number[] = [1, 2, 3, 4];\n * if (isTupleOfAtLeast(arr, 3)) {\n * // The type of arr is now [number, number, number, ...number[]]\n * const [a, b, c] = arr;\n * assert.deepStrictEqual([a, b, c], [1, 2, 3])\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 * A refinement that checks if a `ReadonlyArray<T>` is a tuple with at least `N` elements.\n * If the check is successful, the type is narrowed to `TupleOfAtLeast<N, T>`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isTupleOfAtLeast } from \"effect/Predicate\"\n *\n * const isTupleOfAtLeast3 = isTupleOfAtLeast(3)\n *\n * assert.strictEqual(isTupleOfAtLeast3([1, 2, 3]), true);\n * assert.strictEqual(isTupleOfAtLeast3([1, 2, 3, 4]), true);\n * assert.strictEqual(isTupleOfAtLeast3([1, 2]), false);\n *\n * const arr: number[] = [1, 2, 3, 4];\n * if (isTupleOfAtLeast(arr, 3)) {\n * // The type of arr is now [number, number, number, ...number[]]\n * const [a, b, c] = arr;\n * assert.deepStrictEqual([a, b, c], [1, 2, 3])\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 * A predicate that checks if a value is \"truthy\" in JavaScript.\n * Fails for `false`, `0`, `-0`, `0n`, `\"\"`, `null`, `undefined`, and `NaN`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isTruthy } from \"effect/Predicate\"\n *\n * assert.strictEqual(isTruthy(1), true)\n * assert.strictEqual(isTruthy(\"hello\"), true)\n * assert.strictEqual(isTruthy({}), true)\n *\n * assert.strictEqual(isTruthy(0), false)\n * assert.strictEqual(isTruthy(\"\"), false)\n * assert.strictEqual(isTruthy(null), false)\n * assert.strictEqual(isTruthy(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isTruthy = (input: unknown) => !!input\n\n/**\n * A refinement that checks if a value is a `Set`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isSet } from \"effect/Predicate\"\n *\n * assert.strictEqual(isSet(new Set([1, 2])), true)\n * assert.strictEqual(isSet(new Set()), true)\n *\n * assert.strictEqual(isSet({}), false)\n * assert.strictEqual(isSet([1, 2]), 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 * A refinement that checks if a value is a `Map`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isMap } from \"effect/Predicate\"\n *\n * assert.strictEqual(isMap(new Map()), true)\n *\n * assert.strictEqual(isMap({}), false)\n * assert.strictEqual(isMap(new Set()), 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 * A refinement that checks if a value is a `string`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isString } from \"effect/Predicate\"\n *\n * assert.strictEqual(isString(\"hello\"), true)\n * assert.strictEqual(isString(\"\"), true)\n *\n * assert.strictEqual(isString(123), false)\n * assert.strictEqual(isString(null), 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 * A refinement that checks if a value is a `number`. Note that this\n * check returns `false` for `NaN`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isNumber } from \"effect/Predicate\"\n *\n * assert.strictEqual(isNumber(123), true)\n * assert.strictEqual(isNumber(0), true)\n * assert.strictEqual(isNumber(-1.5), true)\n *\n * assert.strictEqual(isNumber(\"123\"), false)\n * assert.strictEqual(isNumber(NaN), false) // Special case: NaN is a number type but returns 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 * A refinement that checks if a value is a `boolean`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isBoolean } from \"effect/Predicate\"\n *\n * assert.strictEqual(isBoolean(true), true)\n * assert.strictEqual(isBoolean(false), true)\n *\n * assert.strictEqual(isBoolean(\"true\"), false)\n * assert.strictEqual(isBoolean(0), 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 * A refinement that checks if a value is a `bigint`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isBigInt } from \"effect/Predicate\"\n *\n * assert.strictEqual(isBigInt(1n), true)\n *\n * assert.strictEqual(isBigInt(1), false)\n * assert.strictEqual(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 * A refinement that checks if a value is a `symbol`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isSymbol } from \"effect/Predicate\"\n *\n * assert.strictEqual(isSymbol(Symbol.for(\"a\")), true)\n *\n * assert.strictEqual(isSymbol(\"a\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isSymbol = (input: unknown): input is symbol => typeof input === \"symbol\"\n\n// TODO: make public\n/**\n * A refinement that checks if a value is a valid `PropertyKey` (a `string`, `number`, or `symbol`).\n * @internal\n */\nexport const isPropertyKey = (u: unknown): u is PropertyKey => isString(u) || isNumber(u) || isSymbol(u)\n\n/**\n * A refinement that checks if a value is a `Function`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isFunction } from \"effect/Predicate\"\n *\n * assert.strictEqual(isFunction(() => {}), true)\n * assert.strictEqual(isFunction(isFunction), true)\n *\n * assert.strictEqual(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 * A refinement that checks if a value is `undefined`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isUndefined } from \"effect/Predicate\"\n *\n * assert.strictEqual(isUndefined(undefined), true)\n *\n * assert.strictEqual(isUndefined(null), false)\n * assert.strictEqual(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 * A refinement that checks if a value is not `undefined`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isNotUndefined } from \"effect/Predicate\"\n *\n * assert.strictEqual(isNotUndefined(null), true)\n * assert.strictEqual(isNotUndefined(\"value\"), true)\n *\n * assert.strictEqual(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 * A refinement that checks if a value is `null`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isNull } from \"effect/Predicate\"\n *\n * assert.strictEqual(isNull(null), true)\n *\n * assert.strictEqual(isNull(undefined), false)\n * assert.strictEqual(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 * A refinement that checks if a value is not `null`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isNotNull } from \"effect/Predicate\"\n *\n * assert.strictEqual(isNotNull(undefined), true)\n * assert.strictEqual(isNotNull(\"value\"), true)\n *\n * assert.strictEqual(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 refinement that always returns `false`. The type is narrowed to `never`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isNever } from \"effect/Predicate\"\n *\n * assert.strictEqual(isNever(1), false)\n * assert.strictEqual(isNever(null), false)\n * assert.strictEqual(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 refinement that always returns `true`. The type is narrowed to `unknown`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isUnknown } from \"effect/Predicate\"\n *\n * assert.strictEqual(isUnknown(1), true)\n * assert.strictEqual(isUnknown(null), true)\n * assert.strictEqual(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/**\n * Checks if the input is an object or an array.\n * @internal\n */\nexport const isRecordOrArray = (input: unknown): input is { [x: PropertyKey]: unknown } =>\n typeof input === \"object\" && input !== null\n\n/**\n * A refinement that checks if a value is an `object`. Note that in JavaScript,\n * arrays and functions are also considered objects.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isObject } from \"effect/Predicate\"\n *\n * assert.strictEqual(isObject({}), true)\n * assert.strictEqual(isObject([]), true)\n * assert.strictEqual(isObject(() => {}), true)\n *\n * assert.strictEqual(isObject(null), false)\n * assert.strictEqual(isObject(\"hello\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n * @see isRecord to check for plain objects (excluding arrays and functions).\n */\nexport const isObject = (input: unknown): input is object => isRecordOrArray(input) || isFunction(input)\n\n/**\n * A refinement that checks if a value is an object-like value and has a specific property key.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { hasProperty } from \"effect/Predicate\"\n *\n * assert.strictEqual(hasProperty({ a: 1 }, \"a\"), true)\n * assert.strictEqual(hasProperty({ a: 1 }, \"b\"), false)\n *\n * const value: unknown = { name: \"Alice\" };\n * if (hasProperty(value, \"name\")) {\n * // The type of `value` is narrowed to `{ name: unknown }`\n * // and we can safely access `value.name`\n * console.log(value.name)\n * }\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const hasProperty: {\n /**\n * A refinement that checks if a value is an object-like value and has a specific property key.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { hasProperty } from \"effect/Predicate\"\n *\n * assert.strictEqual(hasProperty({ a: 1 }, \"a\"), true)\n * assert.strictEqual(hasProperty({ a: 1 }, \"b\"), false)\n *\n * const value: unknown = { name: \"Alice\" };\n * if (hasProperty(value, \"name\")) {\n * // The type of `value` is narrowed to `{ name: unknown }`\n * // and we can safely access `value.name`\n * console.log(value.name)\n * }\n * ```\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 * A refinement that checks if a value is an object-like value and has a specific property key.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { hasProperty } from \"effect/Predicate\"\n *\n * assert.strictEqual(hasProperty({ a: 1 }, \"a\"), true)\n * assert.strictEqual(hasProperty({ a: 1 }, \"b\"), false)\n *\n * const value: unknown = { name: \"Alice\" };\n * if (hasProperty(value, \"name\")) {\n * // The type of `value` is narrowed to `{ name: unknown }`\n * // and we can safely access `value.name`\n * console.log(value.name)\n * }\n * ```\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 * A refinement that checks if a value is an object with a `_tag` property\n * that matches the given tag. This is a powerful tool for working with\n * discriminated union types.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isTagged } from \"effect/Predicate\"\n *\n * type Shape = { _tag: \"circle\"; radius: number } | { _tag: \"square\"; side: number }\n *\n * const isCircle = isTagged(\"circle\")\n *\n * const shape1: Shape = { _tag: \"circle\", radius: 10 }\n * const shape2: Shape = { _tag: \"square\", side: 5 }\n *\n * assert.strictEqual(isCircle(shape1), true)\n * assert.strictEqual(isCircle(shape2), false)\n *\n * if (isCircle(shape1)) {\n * // shape1 is now narrowed to { _tag: \"circle\"; radius: number }\n * assert.strictEqual(shape1.radius, 10)\n * }\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isTagged: {\n /**\n * A refinement that checks if a value is an object with a `_tag` property\n * that matches the given tag. This is a powerful tool for working with\n * discriminated union types.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isTagged } from \"effect/Predicate\"\n *\n * type Shape = { _tag: \"circle\"; radius: number } | { _tag: \"square\"; side: number }\n *\n * const isCircle = isTagged(\"circle\")\n *\n * const shape1: Shape = { _tag: \"circle\", radius: 10 }\n * const shape2: Shape = { _tag: \"square\", side: 5 }\n *\n * assert.strictEqual(isCircle(shape1), true)\n * assert.strictEqual(isCircle(shape2), false)\n *\n * if (isCircle(shape1)) {\n * // shape1 is now narrowed to { _tag: \"circle\"; radius: number }\n * assert.strictEqual(shape1.radius, 10)\n * }\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 * A refinement that checks if a value is an object with a `_tag` property\n * that matches the given tag. This is a powerful tool for working with\n * discriminated union types.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isTagged } from \"effect/Predicate\"\n *\n * type Shape = { _tag: \"circle\"; radius: number } | { _tag: \"square\"; side: number }\n *\n * const isCircle = isTagged(\"circle\")\n *\n * const shape1: Shape = { _tag: \"circle\", radius: 10 }\n * const shape2: Shape = { _tag: \"square\", side: 5 }\n *\n * assert.strictEqual(isCircle(shape1), true)\n * assert.strictEqual(isCircle(shape2), false)\n *\n * if (isCircle(shape1)) {\n * // shape1 is now narrowed to { _tag: \"circle\"; radius: number }\n * assert.strictEqual(shape1.radius, 10)\n * }\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 refinement that checks if a value is either `null` or `undefined`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isNullable } from \"effect/Predicate\"\n *\n * assert.strictEqual(isNullable(null), true)\n * assert.strictEqual(isNullable(undefined), true)\n *\n * assert.strictEqual(isNullable(0), false)\n * assert.strictEqual(isNullable(\"\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n * @see isNotNullable\n */\nexport const isNullable = <A>(input: A): input is Extract<A, null | undefined> => input === null || input === undefined\n\n/**\n * A refinement that checks if a value is neither `null` nor `undefined`.\n * The type is narrowed to `NonNullable<A>`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isNotNullable } from \"effect/Predicate\"\n *\n * assert.strictEqual(isNotNullable(0), true)\n * assert.strictEqual(isNotNullable(\"hello\"), true)\n *\n * assert.strictEqual(isNotNullable(null), false)\n * assert.strictEqual(isNotNullable(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n * @see isNullable\n */\nexport const isNotNullable = <A>(input: A): input is NonNullable<A> => input !== null && input !== undefined\n\n/**\n * A refinement that checks if a value is an instance of `Error`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isError } from \"effect/Predicate\"\n *\n * assert.strictEqual(isError(new Error(\"boom\")), true)\n * assert.strictEqual(isError(new TypeError(\"boom\")), true)\n *\n * assert.strictEqual(isError({ message: \"boom\" }), false)\n * assert.strictEqual(isError(\"boom\"), 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 refinement that checks if a value is a `Uint8Array`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isUint8Array } from \"effect/Predicate\"\n *\n * assert.strictEqual(isUint8Array(new Uint8Array()), true)\n *\n * assert.strictEqual(isUint8Array(new Uint16Array()), false)\n * assert.strictEqual(isUint8Array([1, 2, 3]), 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 refinement that checks if a value is a `Date` object.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isDate } from \"effect/Predicate\"\n *\n * assert.strictEqual(isDate(new Date()), true)\n *\n * assert.strictEqual(isDate(Date.now()), false) // `Date.now()` returns a number\n * assert.strictEqual(isDate(\"2023-01-01\"), 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 refinement that checks if a value is an `Iterable`.\n * Many built-in types are iterable, such as `Array`, `string`, `Map`, and `Set`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isIterable } from \"effect/Predicate\"\n *\n * assert.strictEqual(isIterable([]), true)\n * assert.strictEqual(isIterable(\"hello\"), true)\n * assert.strictEqual(isIterable(new Set()), true)\n *\n * assert.strictEqual(isIterable({}), false)\n * assert.strictEqual(isIterable(123), 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 refinement that checks if a value is a record (i.e., a plain object).\n * This check returns `false` for arrays, `null`, and functions.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isRecord } from \"effect/Predicate\"\n *\n * assert.strictEqual(isRecord({}), true)\n * assert.strictEqual(isRecord({ a: 1 }), true)\n *\n * assert.strictEqual(isRecord([]), false)\n * assert.strictEqual(isRecord(new Date()), false)\n * assert.strictEqual(isRecord(null), false)\n * assert.strictEqual(isRecord(() => null), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n * @see isObject\n */\nexport const isRecord = (input: unknown): input is { [x: string | symbol]: unknown } =>\n isRecordOrArray(input) && !Array.isArray(input)\n\n/**\n * A refinement that checks if a value is a readonly record (i.e., a plain object).\n * This check returns `false` for arrays, `null`, and functions.\n *\n * This is an alias for `isRecord`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isReadonlyRecord } from \"effect/Predicate\"\n *\n * assert.strictEqual(isReadonlyRecord({}), true)\n * assert.strictEqual(isReadonlyRecord({ a: 1 }), true)\n *\n * assert.strictEqual(isReadonlyRecord([]), false)\n * assert.strictEqual(isReadonlyRecord(null), 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 refinement that checks if a value is a `Promise`. It performs a duck-typing check\n * for `.then` and `.catch` methods.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isPromise } from \"effect/Predicate\"\n *\n * assert.strictEqual(isPromise(Promise.resolve(1)), true)\n * assert.strictEqual(isPromise(new Promise(() => {})), true)\n *\n * assert.strictEqual(isPromise({ then() {} }), false) // Missing .catch\n * assert.strictEqual(isPromise({}), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n * @see isPromiseLike\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 * A refinement that checks if a value is `PromiseLike`. It performs a duck-typing\n * check for a `.then` method.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isPromiseLike } from \"effect/Predicate\"\n *\n * assert.strictEqual(isPromiseLike(Promise.resolve(1)), true)\n * assert.strictEqual(isPromiseLike({ then: () => {} }), true)\n *\n * assert.strictEqual(isPromiseLike({}), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n * @see isPromise\n */\nexport const isPromiseLike = (\n input: unknown\n): input is PromiseLike<unknown> => hasProperty(input, \"then\") && isFunction(input.then)\n\n/**\n * A refinement that checks if a value is a `RegExp`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * assert.strictEqual(Predicate.isRegExp(/a/), true)\n * assert.strictEqual(Predicate.isRegExp(new RegExp(\"a\")), true)\n *\n * assert.strictEqual(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 * Composes a `Refinement` with another `Refinement` or `Predicate`.\n *\n * This can be used to chain checks. The first refinement is applied, and if it\n * passes, the second check is applied to the same value, potentially refining\n * the type further.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n * import * as assert from \"node:assert\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const minLength = (n: number) => (s: string): boolean => s.length >= n\n *\n * // Create a refinement that checks for a string with a minimum length of 3\n * const isLongString = Predicate.compose(isString, minLength(3))\n *\n * let value: unknown = \"hello\"\n *\n * assert.strictEqual(isLongString(value), true)\n * if (isLongString(value)) {\n * // value is narrowed to string\n * assert.strictEqual(value.toUpperCase(), \"HELLO\")\n * }\n * assert.strictEqual(isLongString(\"hi\"), false)\n * ```\n *\n * @since 2.0.0\n */\nexport const compose: {\n /**\n * Composes a `Refinement` with another `Refinement` or `Predicate`.\n *\n * This can be used to chain checks. The first refinement is applied, and if it\n * passes, the second check is applied to the same value, potentially refining\n * the type further.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n * import * as assert from \"node:assert\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const minLength = (n: number) => (s: string): boolean => s.length >= n\n *\n * // Create a refinement that checks for a string with a minimum length of 3\n * const isLongString = Predicate.compose(isString, minLength(3))\n *\n * let value: unknown = \"hello\"\n *\n * assert.strictEqual(isLongString(value), true)\n * if (isLongString(value)) {\n * // value is narrowed to string\n * assert.strictEqual(value.toUpperCase(), \"HELLO\")\n * }\n * assert.strictEqual(isLongString(\"hi\"), false)\n * ```\n *\n * @since 2.0.0\n */\n <A, B extends A, C extends B, D extends C>(bc: Refinement<C, D>): (ab: Refinement<A, B>) => Refinement<A, D>\n /**\n * Composes a `Refinement` with another `Refinement` or `Predicate`.\n *\n * This can be used to chain checks. The first refinement is applied, and if it\n * passes, the second check is applied to the same value, potentially refining\n * the type further.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n * import * as assert from \"node:assert\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const minLength = (n: number) => (s: string): boolean => s.length >= n\n *\n * // Create a refinement that checks for a string with a minimum length of 3\n * const isLongString = Predicate.compose(isString, minLength(3))\n *\n * let value: unknown = \"hello\"\n *\n * assert.strictEqual(isLongString(value), true)\n * if (isLongString(value)) {\n * // value is narrowed to string\n * assert.strictEqual(value.toUpperCase(), \"HELLO\")\n * }\n * assert.strictEqual(isLongString(\"hi\"), false)\n * ```\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 * Composes a `Refinement` with another `Refinement` or `Predicate`.\n *\n * This can be used to chain checks. The first refinement is applied, and if it\n * passes, the second check is applied to the same value, potentially refining\n * the type further.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n * import * as assert from \"node:assert\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const minLength = (n: number) => (s: string): boolean => s.length >= n\n *\n * // Create a refinement that checks for a string with a minimum length of 3\n * const isLongString = Predicate.compose(isString, minLength(3))\n *\n * let value: unknown = \"hello\"\n *\n * assert.strictEqual(isLongString(value), true)\n * if (isLongString(value)) {\n * // value is narrowed to string\n * assert.strictEqual(value.toUpperCase(), \"HELLO\")\n * }\n * assert.strictEqual(isLongString(\"hi\"), false)\n * ```\n *\n * @since 2.0.0\n */\n <A, B extends A, C extends B, D extends C>(ab: Refinement<A, B>, bc: Refinement<C, D>): Refinement<A, D>\n /**\n * Composes a `Refinement` with another `Refinement` or `Predicate`.\n *\n * This can be used to chain checks. The first refinement is applied, and if it\n * passes, the second check is applied to the same value, potentially refining\n * the type further.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n * import * as assert from \"node:assert\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const minLength = (n: number) => (s: string): boolean => s.length >= n\n *\n * // Create a refinement that checks for a string with a minimum length of 3\n * const isLongString = Predicate.compose(isString, minLength(3))\n *\n * let value: unknown = \"hello\"\n *\n * assert.strictEqual(isLongString(value), true)\n * if (isLongString(value)) {\n * // value is narrowed to string\n * assert.strictEqual(value.toUpperCase(), \"HELLO\")\n * }\n * assert.strictEqual(isLongString(\"hi\"), false)\n * ```\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, D extends C>(ab: Refinement<A, B>, bc: Refinement<C, D>): Refinement<A, D> =>\n (a): a is D => ab(a) && bc(a as C)\n)\n\n/**\n * Combines two predicates to test a tuple of two values. The first predicate tests the\n * first element of the tuple, and the second predicate tests the second element.\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 * Takes an iterable of predicates and returns a new predicate that tests an array of values.\n * The new predicate returns `true` if each predicate at a given index is satisfied by the\n * value at the same index in the array. The check stops at the length of the shorter of\n * the two iterables (predicates or values).\n *\n * @category combining\n * @since 2.0.0\n * @see tuple for a more powerful, variadic version.\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 * Combines a predicate for a single value and an iterable of predicates for the rest of an array.\n * Useful for checking the head and tail of an array separately.\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 * Combines an array of predicates into a single predicate that tests an array of values.\n * This function is highly type-aware and will produce a `Refinement` if any of the provided\n * predicates are `Refinement`s, allowing for powerful type-narrowing of tuples.\n *\n * - If all predicates are `Predicate<T>`, the result is `Predicate<[T, T, ...]>`.\n * - If any predicate is a `Refinement<A, B>`, the result is a `Refinement` that narrows\n * the input tuple type to a more specific tuple type.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const isNumber = (u: unknown): u is number => typeof u === \"number\"\n *\n * // Create a refinement for a [string, number] tuple\n * const isStringNumberTuple = Predicate.tuple(isString, isNumber)\n *\n * const value: [unknown, unknown] = [\"hello\", 123]\n * if (isStringNumberTuple(value)) {\n * // value is narrowed to [string, number]\n * const [s, n] = value\n * assert.strictEqual(s.toUpperCase(), \"HELLO\")\n * assert.strictEqual(n.toFixed(2), \"123.00\")\n * }\n * assert.strictEqual(isStringNumberTuple([\"hello\", \"123\"]), false)\n * ```\n *\n * @since 2.0.0\n */\nexport const tuple: {\n /**\n * Combines an array of predicates into a single predicate that tests an array of values.\n * This function is highly type-aware and will produce a `Refinement` if any of the provided\n * predicates are `Refinement`s, allowing for powerful type-narrowing of tuples.\n *\n * - If all predicates are `Predicate<T>`, the result is `Predicate<[T, T, ...]>`.\n * - If any predicate is a `Refinement<A, B>`, the result is a `Refinement` that narrows\n * the input tuple type to a more specific tuple type.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const isNumber = (u: unknown): u is number => typeof u === \"number\"\n *\n * // Create a refinement for a [string, number] tuple\n * const isStringNumberTuple = Predicate.tuple(isString, isNumber)\n *\n * const value: [unknown, unknown] = [\"hello\", 123]\n * if (isStringNumberTuple(value)) {\n * // value is narrowed to [string, number]\n * const [s, n] = value\n * assert.strictEqual(s.toUpperCase(), \"HELLO\")\n * assert.strictEqual(n.toFixed(2), \"123.00\")\n * }\n * assert.strictEqual(isStringNumberTuple([\"hello\", \"123\"]), false)\n * ```\n *\n * @since 2.0.0\n */\n <T extends ReadonlyArray<Predicate.Any>>(...elements: T): [Extract<T[number], Refinement.Any>] extends [never] ? Predicate<{ readonly [I in keyof T]: Predicate.In<T[I]> }>\n : Refinement<\n { readonly [I in keyof T]: T[I] extends Refinement.Any ? Refinement.In<T[I]> : Predicate.In<T[I]> },\n { readonly [I in keyof T]: T[I] extends Refinement.Any ? Refinement.Out<T[I]> : Predicate.In<T[I]> }\n >\n} = (...elements: ReadonlyArray<Predicate.Any>) => all(elements) as any\n\n/**\n * Combines a record of predicates into a single predicate that tests a record of values.\n * This function is highly type-aware and will produce a `Refinement` if any of the provided\n * predicates are `Refinement`s, allowing for powerful type-narrowing of structs.\n *\n * - If all predicates are `Predicate<T>`, the result is `Predicate<{ k: T, ... }>`.\n * - If any predicate is a `Refinement<A, B>`, the result is a `Refinement` that narrows\n * the input record type to a more specific record type.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const isNumber = (u: unknown): u is number => typeof u === \"number\"\n *\n * const personPredicate = Predicate.struct({\n * name: isString,\n * age: isNumber\n * })\n *\n * const value: { name: unknown; age: unknown } = { name: \"Alice\", age: 30 }\n * if (personPredicate(value)) {\n * // value is narrowed to { name: string; age: number }\n * assert.strictEqual(value.name.toUpperCase(), \"ALICE\")\n * assert.strictEqual(value.age.toFixed(0), \"30\")\n * }\n * assert.strictEqual(personPredicate({ name: \"Bob\", age: \"40\" }), false)\n * ```\n *\n * @since 2.0.0\n */\nexport const struct: {\n /**\n * Combines a record of predicates into a single predicate that tests a record of values.\n * This function is highly type-aware and will produce a `Refinement` if any of the provided\n * predicates are `Refinement`s, allowing for powerful type-narrowing of structs.\n *\n * - If all predicates are `Predicate<T>`, the result is `Predicate<{ k: T, ... }>`.\n * - If any predicate is a `Refinement<A, B>`, the result is a `Refinement` that narrows\n * the input record type to a more specific record type.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const isNumber = (u: unknown): u is number => typeof u === \"number\"\n *\n * const personPredicate = Predicate.struct({\n * name: isString,\n * age: isNumber\n * })\n *\n * const value: { name: unknown; age: unknown } = { name: \"Alice\", age: 30 }\n * if (personPredicate(value)) {\n * // value is narrowed to { name: string; age: number }\n * assert.strictEqual(value.name.toUpperCase(), \"ALICE\")\n * assert.strictEqual(value.age.toFixed(0), \"30\")\n * }\n * assert.strictEqual(personPredicate({ name: \"Bob\", age: \"40\" }), false)\n * ```\n *\n * @since 2.0.0\n */\n <R extends Record<string, Predicate.Any>>(fields: R): [Extract<R[keyof R], Refinement.Any>] extends [never] ?\n Predicate<{ readonly [K in keyof R]: Predicate.In<R[K]> }> :\n Refinement<\n { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.In<R[K]> : Predicate.In<R[K]> },\n { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.Out<R[K]> : Predicate.In<R[K]> }\n >\n} = (<R extends Record<string, Predicate.Any>>(fields: R) => {\n const keys = Object.keys(fields)\n return (a: Record<string, unknown>) => {\n for (const key of keys) {\n if (!fields[key](a[key] as never)) {\n return false\n }\n }\n return true\n }\n}) as any\n\n/**\n * Returns a new predicate that is the logical negation of the given predicate.\n *\n * **Note**: If the input is a `Refinement`, the resulting predicate will be a\n * simple `Predicate`, as TypeScript cannot infer the negative type.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate, Number } from \"effect\"\n *\n * const isNonPositive = Predicate.not(Number.greaterThan(0))\n *\n * assert.strictEqual(isNonPositive(-1), true)\n * assert.strictEqual(isNonPositive(0), true)\n * assert.strictEqual(isNonPositive(1), false)\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 with a logical \"OR\". The resulting predicate returns `true`\n * if at least one of the predicates returns `true`.\n *\n * If both predicates are `Refinement`s, the resulting predicate is a `Refinement` to the\n * union of their target types (`B | C`).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const isNumber = (u: unknown): u is number => typeof u === \"number\"\n *\n * const isStringOrNumber = Predicate.or(isString, isNumber)\n *\n * assert.strictEqual(isStringOrNumber(\"hello\"), true)\n * assert.strictEqual(isStringOrNumber(123), true)\n * assert.strictEqual(isStringOrNumber(null), false)\n *\n * const value: unknown = \"world\"\n * if (isStringOrNumber(value)) {\n * // value is narrowed to string | number\n * console.log(value)\n * }\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const or: {\n /**\n * Combines two predicates with a logical \"OR\". The resulting predicate returns `true`\n * if at least one of the predicates returns `true`.\n *\n * If both predicates are `Refinement`s, the resulting predicate is a `Refinement` to the\n * union of their target types (`B | C`).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const isNumber = (u: unknown): u is number => typeof u === \"number\"\n *\n * const isStringOrNumber = Predicate.or(isString, isNumber)\n *\n * assert.strictEqual(isStringOrNumber(\"hello\"), true)\n * assert.strictEqual(isStringOrNumber(123), true)\n * assert.strictEqual(isStringOrNumber(null), false)\n *\n * const value: unknown = \"world\"\n * if (isStringOrNumber(value)) {\n * // value is narrowed to string | number\n * console.log(value)\n * }\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 with a logical \"OR\". The resulting predicate returns `true`\n * if at least one of the predicates returns `true`.\n *\n * If both predicates are `Refinement`s, the resulting predicate is a `Refinement` to the\n * union of their target types (`B | C`).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const isNumber = (u: unknown): u is number => typeof u === \"number\"\n *\n * const isStringOrNumber = Predicate.or(isString, isNumber)\n *\n * assert.strictEqual(isStringOrNumber(\"hello\"), true)\n * assert.strictEqual(isStringOrNumber(123), true)\n * assert.strictEqual(isStringOrNumber(null), false)\n *\n * const value: unknown = \"world\"\n * if (isStringOrNumber(value)) {\n * // value is narrowed to string | number\n * console.log(value)\n * }\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 with a logical \"OR\". The resulting predicate returns `true`\n * if at least one of the predicates returns `true`.\n *\n * If both predicates are `Refinement`s, the resulting predicate is a `Refinement` to the\n * union of their target types (`B | C`).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const isNumber = (u: unknown): u is number => typeof u === \"number\"\n *\n * const isStringOrNumber = Predicate.or(isString, isNumber)\n *\n * assert.strictEqual(isStringOrNumber(\"hello\"), true)\n * assert.strictEqual(isStringOrNumber(123), true)\n * assert.strictEqual(isStringOrNumber(null), false)\n *\n * const value: unknown = \"world\"\n * if (isStringOrNumber(value)) {\n * // value is narrowed to string | number\n * console.log(value)\n * }\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 with a logical \"OR\". The resulting predicate returns `true`\n * if at least one of the predicates returns `true`.\n *\n * If both predicates are `Refinement`s, the resulting predicate is a `Refinement` to the\n * union of their target types (`B | C`).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const isNumber = (u: unknown): u is number => typeof u === \"number\"\n *\n * const isStringOrNumber = Predicate.or(isString, isNumber)\n *\n * assert.strictEqual(isStringOrNumber(\"hello\"), true)\n * assert.strictEqual(isStringOrNumber(123), true)\n * assert.strictEqual(isStringOrNumber(null), false)\n *\n * const value: unknown = \"world\"\n * if (isStringOrNumber(value)) {\n * // value is narrowed to string | number\n * console.log(value)\n * }\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 with a logical \"AND\". The resulting predicate returns `true`\n * only if both of the predicates return `true`.\n *\n * If both predicates are `Refinement`s, the resulting predicate is a `Refinement` to the\n * intersection of their target types (`B & C`).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * type Person = { name: string }\n * type Employee = { id: number }\n *\n * const hasName = (u: unknown): u is Person => Predicate.hasProperty(u, \"name\") && typeof (u as any).name === \"string\"\n * const hasId = (u: unknown): u is Employee => Predicate.hasProperty(u, \"id\") && typeof (u as any).id === \"number\"\n *\n * const isPersonAndEmployee = Predicate.and(hasName, hasId)\n *\n * const val: unknown = { name: \"Alice\", id: 123 }\n * if (isPersonAndEmployee(val)) {\n * // val is narrowed to Person & Employee\n * assert.strictEqual(val.name, \"Alice\")\n * assert.strictEqual(val.id, 123)\n * }\n *\n * assert.strictEqual(isPersonAndEmployee({ name: \"Bob\" }), false) // Missing id\n * assert.strictEqual(isPersonAndEmployee({ id: 456 }), false) // Missing name\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const and: {\n /**\n * Combines two predicates with a logical \"AND\". The resulting predicate returns `true`\n * only if both of the predicates return `true`.\n *\n * If both predicates are `Refinement`s, the resulting predicate is a `Refinement` to the\n * intersection of their target types (`B & C`).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * type Person = { name: string }\n * type Employee = { id: number }\n *\n * const hasName = (u: unknown): u is Person => Predicate.hasProperty(u, \"name\") && typeof (u as any).name === \"string\"\n * const hasId = (u: unknown): u is Employee => Predicate.hasProperty(u, \"id\") && typeof (u as any).id === \"number\"\n *\n * const isPersonAndEmployee = Predicate.and(hasName, hasId)\n *\n * const val: unknown = { name: \"Alice\", id: 123 }\n * if (isPersonAndEmployee(val)) {\n * // val is narrowed to Person & Employee\n * assert.strictEqual(val.name, \"Alice\")\n * assert.strictEqual(val.id, 123)\n * }\n *\n * assert.strictEqual(isPersonAndEmployee({ name: \"Bob\" }), false) // Missing id\n * assert.strictEqual(isPersonAndEmployee({ id: 456 }), false) // Missing name\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 with a logical \"AND\". The resulting predicate returns `true`\n * only if both of the predicates return `true`.\n *\n * If both predicates are `Refinement`s, the resulting predicate is a `Refinement` to the\n * intersection of their target types (`B & C`).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * type Person = { name: string }\n * type Employee = { id: number }\n *\n * const hasName = (u: unknown): u is Person => Predicate.hasProperty(u, \"name\") && typeof (u as any).name === \"string\"\n * const hasId = (u: unknown): u is Employee => Predicate.hasProperty(u, \"id\") && typeof (u as any).id === \"number\"\n *\n * const isPersonAndEmployee = Predicate.and(hasName, hasId)\n *\n * const val: unknown = { name: \"Alice\", id: 123 }\n * if (isPersonAndEmployee(val)) {\n * // val is narrowed to Person & Employee\n * assert.strictEqual(val.name, \"Alice\")\n * assert.strictEqual(val.id, 123)\n * }\n *\n * assert.strictEqual(isPersonAndEmployee({ name: \"Bob\" }), false) // Missing id\n * assert.strictEqual(isPersonAndEmployee({ id: 456 }), false) // Missing name\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 with a logical \"AND\". The resulting predicate returns `true`\n * only if both of the predicates return `true`.\n *\n * If both predicates are `Refinement`s, the resulting predicate is a `Refinement` to the\n * intersection of their target types (`B & C`).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * type Person = { name: string }\n * type Employee = { id: number }\n *\n * const hasName = (u: unknown): u is Person => Predicate.hasProperty(u, \"name\") && typeof (u as any).name === \"string\"\n * const hasId = (u: unknown): u is Employee => Predicate.hasProperty(u, \"id\") && typeof (u as any).id === \"number\"\n *\n * const isPersonAndEmployee = Predicate.and(hasName, hasId)\n *\n * const val: unknown = { name: \"Alice\", id: 123 }\n * if (isPersonAndEmployee(val)) {\n * // val is narrowed to Person & Employee\n * assert.strictEqual(val.name, \"Alice\")\n * assert.strictEqual(val.id, 123)\n * }\n *\n * assert.strictEqual(isPersonAndEmployee({ name: \"Bob\" }), false) // Missing id\n * assert.strictEqual(isPersonAndEmployee({ id: 456 }), false) // Missing name\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 with a logical \"AND\". The resulting predicate returns `true`\n * only if both of the predicates return `true`.\n *\n * If both predicates are `Refinement`s, the resulting predicate is a `Refinement` to the\n * intersection of their target types (`B & C`).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * type Person = { name: string }\n * type Employee = { id: number }\n *\n * const hasName = (u: unknown): u is Person => Predicate.hasProperty(u, \"name\") && typeof (u as any).name === \"string\"\n * const hasId = (u: unknown): u is Employee => Predicate.hasProperty(u, \"id\") && typeof (u as any).id === \"number\"\n *\n * const isPersonAndEmployee = Predicate.and(hasName, hasId)\n *\n * const val: unknown = { name: \"Alice\", id: 123 }\n * if (isPersonAndEmployee(val)) {\n * // val is narrowed to Person & Employee\n * assert.strictEqual(val.name, \"Alice\")\n * assert.strictEqual(val.id, 123)\n * }\n *\n * assert.strictEqual(isPersonAndEmployee({ name: \"Bob\" }), false) // Missing id\n * assert.strictEqual(isPersonAndEmployee({ id: 456 }), false) // Missing name\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 with a logical \"XOR\" (exclusive OR). The resulting predicate\n * returns `true` if one of the predicates returns `true`, but not both.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isPositive = (n: number) => n > 0\n * const isEven = (n: number) => n % 2 === 0\n *\n * const isPositiveXorEven = Predicate.xor(isPositive, isEven)\n *\n * assert.strictEqual(isPositiveXorEven(4), false) // both true -> false\n * assert.strictEqual(isPositiveXorEven(3), true) // one true -> true\n * assert.strictEqual(isPositiveXorEven(-2), true) // one true -> true\n * assert.strictEqual(isPositiveXorEven(-1), false) // both false -> false\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const xor: {\n /**\n * Combines two predicates with a logical \"XOR\" (exclusive OR). The resulting predicate\n * returns `true` if one of the predicates returns `true`, but not both.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isPositive = (n: number) => n > 0\n * const isEven = (n: number) => n % 2 === 0\n *\n * const isPositiveXorEven = Predicate.xor(isPositive, isEven)\n *\n * assert.strictEqual(isPositiveXorEven(4), false) // both true -> false\n * assert.strictEqual(isPositiveXorEven(3), true) // one true -> true\n * assert.strictEqual(isPositiveXorEven(-2), true) // one true -> true\n * assert.strictEqual(isPositiveXorEven(-1), false) // both false -> 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 with a logical \"XOR\" (exclusive OR). The resulting predicate\n * returns `true` if one of the predicates returns `true`, but not both.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isPositive = (n: number) => n > 0\n * const isEven = (n: number) => n % 2 === 0\n *\n * const isPositiveXorEven = Predicate.xor(isPositive, isEven)\n *\n * assert.strictEqual(isPositiveXorEven(4), false) // both true -> false\n * assert.strictEqual(isPositiveXorEven(3), true) // one true -> true\n * assert.strictEqual(isPositiveXorEven(-2), true) // one true -> true\n * assert.strictEqual(isPositiveXorEven(-1), false) // both false -> 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 * Combines two predicates with a logical \"EQV\" (equivalence). The resulting predicate\n * returns `true` if both predicates return the same boolean value (both `true` or both `false`).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isPositive = (n: number) => n > 0\n * const isEven = (n: number) => n % 2 === 0\n *\n * const isPositiveEqvEven = Predicate.eqv(isPositive, isEven)\n *\n * assert.strictEqual(isPositiveEqvEven(4), true) // both true -> true\n * assert.strictEqual(isPositiveEqvEven(3), false) // different -> false\n * assert.strictEqual(isPositiveEqvEven(-2), false) // different -> false\n * assert.strictEqual(isPositiveEqvEven(-1), true) // both false -> true\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const eqv: {\n /**\n * Combines two predicates with a logical \"EQV\" (equivalence). The resulting predicate\n * returns `true` if both predicates return the same boolean value (both `true` or both `false`).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isPositive = (n: number) => n > 0\n * const isEven = (n: number) => n % 2 === 0\n *\n * const isPositiveEqvEven = Predicate.eqv(isPositive, isEven)\n *\n * assert.strictEqual(isPositiveEqvEven(4), true) // both true -> true\n * assert.strictEqual(isPositiveEqvEven(3), false) // different -> false\n * assert.strictEqual(isPositiveEqvEven(-2), false) // different -> false\n * assert.strictEqual(isPositiveEqvEven(-1), true) // both false -> 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 with a logical \"EQV\" (equivalence). The resulting predicate\n * returns `true` if both predicates return the same boolean value (both `true` or both `false`).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isPositive = (n: number) => n > 0\n * const isEven = (n: number) => n % 2 === 0\n *\n * const isPositiveEqvEven = Predicate.eqv(isPositive, isEven)\n *\n * assert.strictEqual(isPositiveEqvEven(4), true) // both true -> true\n * assert.strictEqual(isPositiveEqvEven(3), false) // different -> false\n * assert.strictEqual(isPositiveEqvEven(-2), false) // different -> false\n * assert.strictEqual(isPositiveEqvEven(-1), true) // both false -> 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 * Creates a predicate that represents a logical \"if-then\" rule.\n *\n * Think of it as a conditional promise: **\"If `antecedent` holds true, then I promise `consequent` will also be true.\"**\n *\n * This function is invaluable for defining complex validation logic where one condition dictates another.\n *\n * ### How It Works\n *\n * The rule only fails (returns `false`) when the \"if\" part is `true`, but the \"then\" part is `false`.\n * In all other cases, the promise is considered kept, and the result is `true`.\n *\n * This includes the concept of **\"vacuous truth\"**: if the \"if\" part is `false`, the rule doesn't apply,\n * so the promise isn't broken, and the result is `true`. (e.g., \"If it rains, I'll bring an umbrella.\"\n * If it doesn't rain, you haven't broken your promise, no matter what).\n *\n * ### Key Details\n *\n * - **Logical Equivalence**: `implies(p, q)` is the same as `not(p).or(q)`, or simply `!p || q`\n * in plain JavaScript. This can be a helpful way to reason about its behavior.\n *\n * - **Type-Safety Warning**: This function always returns a `Predicate`, never a type-narrowing\n * `Refinement`. A `true` result doesn't guarantee the `consequent` passed (it could be `true`\n * simply because the `antecedent` was `false`), so it cannot be used to safely narrow a type.\n *\n * @example\n * ```ts\n * // Rule: A user can only be an admin if they also belong to the \"staff\" group.\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * type User = {\n * isStaff: boolean\n * isAdmin: boolean\n * }\n *\n * const isValidUserPermission = Predicate.implies(\n * // antecedent: \"if\" the user is an admin...\n * (user: User) => user.isAdmin,\n * // consequent: \"then\" they must be staff.\n * (user: User) => user.isStaff\n * )\n *\n * // A non-admin who is not staff. Rule doesn't apply (antecedent is false).\n * assert.strictEqual(isValidUserPermission({ isStaff: false, isAdmin: false }), true)\n *\n * // A staff member who is not an admin. Rule doesn't apply (antecedent is false).\n * assert.strictEqual(isValidUserPermission({ isStaff: true, isAdmin: false }), true)\n *\n * // An admin who is also staff. The rule was followed.\n * assert.strictEqual(isValidUserPermission({ isStaff: true, isAdmin: true }), true)\n *\n * // An admin who is NOT staff. The rule was broken!\n * assert.strictEqual(isValidUserPermission({ isStaff: false, isAdmin: true }), false)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const implies: {\n /**\n * Creates a predicate that represents a logical \"if-then\" rule.\n *\n * Think of it as a conditional promise: **\"If `antecedent` holds true, then I promise `consequent` will also be true.\"**\n *\n * This function is invaluable for defining complex validation logic where one condition dictates another.\n *\n * ### How It Works\n *\n * The rule only fails (returns `false`) when the \"if\" part is `true`, but the \"then\" part is `false`.\n * In all other cases, the promise is considered kept, and the result is `true`.\n *\n * This includes the concept of **\"vacuous truth\"**: if the \"if\" part is `false`, the rule doesn't apply,\n * so the promise isn't broken, and the result is `true`. (e.g., \"If it rains, I'll bring an umbrella.\"\n * If it doesn't rain, you haven't broken your promise, no matter what).\n *\n * ### Key Details\n *\n * - **Logical Equivalence**: `implies(p, q)` is the same as `not(p).or(q)`, or simply `!p || q`\n * in plain JavaScript. This can be a helpful way to reason about its behavior.\n *\n * - **Type-Safety Warning**: This function always returns a `Predicate`, never a type-narrowing\n * `Refinement`. A `true` result doesn't guarantee the `consequent` passed (it could be `true`\n * simply because the `antecedent` was `false`), so it cannot be used to safely narrow a type.\n *\n * @example\n * ```ts\n * // Rule: A user can only be an admin if they also belong to the \"staff\" group.\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * type User = {\n * isStaff: boolean\n * isAdmin: boolean\n * }\n *\n * const isValidUserPermission = Predicate.implies(\n * // antecedent: \"if\" the user is an admin...\n * (user: User) => user.isAdmin,\n * // consequent: \"then\" they must be staff.\n * (user: User) => user.isStaff\n * )\n *\n * // A non-admin who is not staff. Rule doesn't apply (antecedent is false).\n * assert.strictEqual(isValidUserPermission({ isStaff: false, isAdmin: false }), true)\n *\n * // A staff member who is not an admin. Rule doesn't apply (antecedent is false).\n * assert.strictEqual(isValidUserPermission({ isStaff: true, isAdmin: false }), true)\n *\n * // An admin who is also staff. The rule was followed.\n * assert.strictEqual(isValidUserPermission({ isStaff: true, isAdmin: true }), true)\n *\n * // An admin who is NOT staff. The rule was broken!\n * assert.strictEqual(isValidUserPermission({ isStaff: false, isAdmin: true }), false)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A>(consequent: Predicate<A>): (antecedent: Predicate<A>) => Predicate<A>\n /**\n * Creates a predicate that represents a logical \"if-then\" rule.\n *\n * Think of it as a conditional promise: **\"If `antecedent` holds true, then I promise `consequent` will also be true.\"**\n *\n * This function is invaluable for defining complex validation logic where one condition dictates another.\n *\n * ### How It Works\n *\n * The rule only fails (returns `false`) when the \"if\" part is `true`, but the \"then\" part is `false`.\n * In all other cases, the promise is considered kept, and the result is `true`.\n *\n * This includes the concept of **\"vacuous truth\"**: if the \"if\" part is `false`, the rule doesn't apply,\n * so the promise isn't broken, and the result is `true`. (e.g., \"If it rains, I'll bring an umbrella.\"\n * If it doesn't rain, you haven't broken your promise, no matter what).\n *\n * ### Key Details\n *\n * - **Logical Equivalence**: `implies(p, q)` is the same as `not(p).or(q)`, or simply `!p || q`\n * in plain JavaScript. This can be a helpful way to reason about its behavior.\n *\n * - **Type-Safety Warning**: This function always returns a `Predicate`, never a type-narrowing\n * `Refinement`. A `true` result doesn't guarantee the `consequent` passed (it could be `true`\n * simply because the `antecedent` was `false`), so it cannot be used to safely narrow a type.\n *\n * @example\n * ```ts\n * // Rule: A user can only be an admin if they also belong to the \"staff\" group.\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * type User = {\n * isStaff: boolean\n * isAdmin: boolean\n * }\n *\n * const isValidUserPermission = Predicate.implies(\n * // antecedent: \"if\" the user is an admin...\n * (user: User) => user.isAdmin,\n * // consequent: \"then\" they must be staff.\n * (user: User) => user.isStaff\n * )\n *\n * // A non-admin who is not staff. Rule doesn't apply (antecedent is false).\n * assert.strictEqual(isValidUserPermission({ isStaff: false, isAdmin: false }), true)\n *\n * // A staff member who is not an admin. Rule doesn't apply (antecedent is false).\n * assert.strictEqual(isValidUserPermission({ isStaff: true, isAdmin: false }), true)\n *\n * // An admin who is also staff. The rule was followed.\n * assert.strictEqual(isValidUserPermission({ isStaff: true, isAdmin: true }), true)\n *\n * // An admin who is NOT staff. The rule was broken!\n * assert.strictEqual(isValidUserPermission({ isStaff: false, isAdmin: true }), false)\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 * Combines two predicates with a logical \"NOR\" (negated OR). The resulting predicate\n * returns `true` only if both predicates return `false`.\n * This is equivalent to `not(or(p, q))`.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const nor: {\n /**\n * Combines two predicates with a logical \"NOR\" (negated OR). The resulting predicate\n * returns `true` only if both predicates return `false`.\n * This is equivalent to `not(or(p, q))`.\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 with a logical \"NOR\" (negated OR). The resulting predicate\n * returns `true` only if both predicates return `false`.\n * This is equivalent to `not(or(p, q))`.\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 * Combines two predicates with a logical \"NAND\" (negated AND). The resulting predicate\n * returns `true` if at least one of the predicates returns `false`.\n * This is equivalent to `not(and(p, q))`.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const nand: {\n /**\n * Combines two predicates with a logical \"NAND\" (negated AND). The resulting predicate\n * returns `true` if at least one of the predicates returns `false`.\n * This is equivalent to `not(and(p, q))`.\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 with a logical \"NAND\" (negated AND). The resulting predicate\n * returns `true` if at least one of the predicates returns `false`.\n * This is equivalent to `not(and(p, q))`.\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 * Takes an iterable of predicates and returns a new predicate. The new predicate\n * returns `true` if all predicates in the collection return `true` for a given value.\n *\n * This is like `Array.prototype.every` but for a collection of predicates.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isPositive = (n: number) => n > 0\n * const isEven = (n: number) => n % 2 === 0\n *\n * const isPositiveAndEven = Predicate.every([isPositive, isEven])\n *\n * assert.strictEqual(isPositiveAndEven(4), true)\n * assert.strictEqual(isPositiveAndEven(3), false)\n * assert.strictEqual(isPositiveAndEven(-2), false)\n * ```\n *\n * @category elements\n * @since 2.0.0\n * @see some\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 * Takes an iterable of predicates and returns a new predicate. The new predicate\n * returns `true` if at least one predicate in the collection returns `true` for a given value.\n *\n * This is like `Array.prototype.some` but for a collection of predicates.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isNegative = (n: number) => n < 0\n * const isOdd = (n: number) => n % 2 !== 0\n *\n * const isNegativeOrOdd = Predicate.some([isNegative, isOdd])\n *\n * assert.strictEqual(isNegativeOrOdd(-2), true) // isNegative is true\n * assert.strictEqual(isNegativeOrOdd(3), true) // isOdd is true\n * assert.strictEqual(isNegativeOrOdd(4), false) // both are false\n * ```\n *\n * @category elements\n * @since 2.0.0\n * @see every\n */\nexport const some = <A>(collection: Iterable<Predicate<A>>): Predicate<A> => (a) => {\n for (const p of collection) {\n if (p(a)) {\n return true\n }\n }\n return false\n}\n","/**\n * @since 2.0.0\n */\n\n/** @internal */\nexport const getBugErrorMessage = (message: string) =>\n `BUG: ${message} - please report an issue at https://github.com/Effect-TS/effect/issues`\n","/**\n * @since 2.0.0\n */\nimport { identity } from \"./Function.js\"\nimport { globalValue } from \"./GlobalValue.js\"\nimport type { Kind, TypeLambda } from \"./HKT.js\"\nimport { getBugErrorMessage } from \"./internal/errors.js\"\nimport { isNullable, isObject } from \"./Predicate.js\"\nimport type * as Types from \"./Types.js\"\n\n/*\n * Copyright 2014 Thom Chiovoloni, released under the MIT license.\n *\n * A random number generator based on the basic implementation of the PCG algorithm,\n * as described here: http://www.pcg-random.org/\n *\n * Adapted for TypeScript from Thom's original code at https://github.com/thomcc/pcg-random\n *\n * forked from https://github.com/frptools\n *\n * @since 2.0.0\n */\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport const GenKindTypeId: unique symbol = Symbol.for(\"effect/Gen/GenKind\")\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport type GenKindTypeId = typeof GenKindTypeId\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface GenKind<F extends TypeLambda, R, O, E, A> extends Variance<F, R, O, E> {\n readonly value: Kind<F, R, O, E, A>\n\n [Symbol.iterator](): IterableIterator<GenKind<F, R, O, E, A>, A>\n}\n\n/**\n * @category predicates\n * @since 3.0.6\n */\nexport const isGenKind = (u: unknown): u is GenKind<any, any, any, any, any> => isObject(u) && GenKindTypeId in u\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport class GenKindImpl<F extends TypeLambda, R, O, E, A> implements GenKind<F, R, O, E, A> {\n constructor(\n /**\n * @since 2.0.0\n */\n readonly value: Kind<F, R, O, E, A>\n ) {}\n\n /**\n * @since 2.0.0\n */\n get _F() {\n return identity\n }\n\n /**\n * @since 2.0.0\n */\n get _R() {\n return (_: R) => _\n }\n\n /**\n * @since 2.0.0\n */\n get _O() {\n return (_: never): O => _\n }\n\n /**\n * @since 2.0.0\n */\n get _E() {\n return (_: never): E => _\n }\n\n /**\n * @since 2.0.0\n */\n readonly [GenKindTypeId]: typeof GenKindTypeId = GenKindTypeId;\n\n /**\n * @since 2.0.0\n */\n [Symbol.iterator](): IterableIterator<GenKind<F, R, O, E, A>, A> {\n return new SingleShotGen<GenKind<F, R, O, E, A>, A>(this as any)\n }\n}\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport class SingleShotGen<T, A> implements IterableIterator<T, A> {\n private called = false\n\n constructor(readonly self: T) {}\n\n /**\n * @since 2.0.0\n */\n next(a: A): IteratorResult<T, A> {\n return this.called ?\n ({\n value: a,\n done: true\n }) :\n (this.called = true,\n ({\n value: this.self,\n done: false\n }))\n }\n\n /**\n * @since 2.0.0\n */\n return(a: A): IteratorResult<T, A> {\n return ({\n value: a,\n done: true\n })\n }\n\n /**\n * @since 2.0.0\n */\n throw(e: unknown): IteratorResult<T, A> {\n throw e\n }\n\n /**\n * @since 2.0.0\n */\n [Symbol.iterator](): IterableIterator<T, A> {\n return new SingleShotGen<T, A>(this.self)\n }\n}\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const makeGenKind = <F extends TypeLambda, R, O, E, A>(\n kind: Kind<F, R, O, E, A>\n): GenKind<F, R, O, E, A> => new GenKindImpl(kind)\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Variance<in out F extends TypeLambda, in R, out O, out E> {\n readonly [GenKindTypeId]: GenKindTypeId\n readonly _F: Types.Invariant<F>\n readonly _R: Types.Contravariant<R>\n readonly _O: Types.Covariant<O>\n readonly _E: Types.Covariant<E>\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Gen<F extends TypeLambda, Z> {\n <Self, K extends Variance<F, any, any, any> | YieldWrap<Kind<F, any, any, any, any>>, A>(\n ...args:\n | [\n self: Self,\n body: (this: Self, resume: Z) => Generator<K, A, never>\n ]\n | [\n body: (resume: Z) => Generator<K, A, never>\n ]\n ): Kind<\n F,\n [K] extends [Variance<F, infer R, any, any>] ? R\n : [K] extends [YieldWrap<Kind<F, infer R, any, any, any>>] ? R\n : never,\n [K] extends [Variance<F, any, infer O, any>] ? O\n : [K] extends [YieldWrap<Kind<F, any, infer O, any, any>>] ? O\n : never,\n [K] extends [Variance<F, any, any, infer E>] ? E\n : [K] extends [YieldWrap<Kind<F, any, any, infer E, any>>] ? E\n : never,\n A\n >\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Adapter<Z extends TypeLambda> {\n <_R, _O, _E, _A>(\n self: Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, _R, _O, _E, _A>(a: A, ab: (a: A) => Kind<Z, _R, _O, _E, _A>): GenKind<Z, _R, _O, _E, _A>\n <A, B, _R, _O, _E, _A>(a: A, ab: (a: A) => B, bc: (b: B) => Kind<Z, _R, _O, _E, _A>): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: F) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (g: H) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => S,\n st: (s: S) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => S,\n st: (s: S) => T,\n tu: (s: T) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n}\n\n/**\n * @category adapters\n * @since 2.0.0\n */\nexport const adapter: <F extends TypeLambda>() => Adapter<F> = () => (function() {\n let x = arguments[0]\n for (let i = 1; i < arguments.length; i++) {\n x = arguments[i](x)\n }\n return new GenKindImpl(x) as any\n})\n\nconst defaultIncHi = 0x14057b7e\nconst defaultIncLo = 0xf767814f\nconst MUL_HI = 0x5851f42d >>> 0\nconst MUL_LO = 0x4c957f2d >>> 0\nconst BIT_53 = 9007199254740992.0\nconst BIT_27 = 134217728.0\n\n/**\n * @category model\n * @since 2.0.0\n */\nexport type PCGRandomState = [number, number, number, number]\n\n/**\n * @category model\n * @since 2.0.0\n */\nexport type OptionalNumber = number | null | undefined\n\n/**\n * PCG is a family of simple fast space-efficient statistically good algorithms\n * for random number generation. Unlike many general-purpose RNGs, they are also\n * hard to predict.\n *\n * @category model\n * @since 2.0.0\n */\nexport class PCGRandom {\n private _state!: Int32Array\n\n /**\n * Creates an instance of PCGRandom.\n *\n * - `seed` - The low 32 bits of the seed (0 is used for high 32 bits).\n *\n * @memberOf PCGRandom\n */\n constructor(seed?: OptionalNumber)\n /**\n * Creates an instance of PCGRandom.\n *\n * - `seedHi` - The high 32 bits of the seed.\n * - `seedLo` - The low 32 bits of the seed.\n * - `inc` - The low 32 bits of the incrementer (0 is used for high 32 bits).\n *\n * @memberOf PCGRandom\n */\n constructor(seedHi: OptionalNumber, seedLo: OptionalNumber, inc?: OptionalNumber)\n /**\n * Creates an instance of PCGRandom.\n *\n * - `seedHi` - The high 32 bits of the seed.\n * - `seedLo` - The low 32 bits of the seed.\n * - `incHi` - The high 32 bits of the incrementer.\n * - `incLo` - The low 32 bits of the incrementer.\n *\n * @memberOf PCGRandom\n */\n constructor(\n seedHi: OptionalNumber,\n seedLo: OptionalNumber,\n incHi: OptionalNumber,\n incLo: OptionalNumber\n )\n constructor(\n seedHi?: OptionalNumber,\n seedLo?: OptionalNumber,\n incHi?: OptionalNumber,\n incLo?: OptionalNumber\n ) {\n if (isNullable(seedLo) && isNullable(seedHi)) {\n seedLo = (Math.random() * 0xffffffff) >>> 0\n seedHi = 0\n } else if (isNullable(seedLo)) {\n seedLo = seedHi\n seedHi = 0\n }\n if (isNullable(incLo) && isNullable(incHi)) {\n incLo = this._state ? this._state[3] : defaultIncLo\n incHi = this._state ? this._state[2] : defaultIncHi\n } else if (isNullable(incLo)) {\n incLo = <number> incHi\n incHi = 0\n }\n\n this._state = new Int32Array([0, 0, (<number> incHi) >>> 0, ((incLo || 0) | 1) >>> 0])\n this._next()\n add64(\n this._state,\n this._state[0]!,\n this._state[1]!,\n (<number> seedHi) >>> 0,\n (<number> seedLo) >>> 0\n )\n this._next()\n return this\n }\n\n /**\n * Returns a copy of the internal state of this random number generator as a\n * JavaScript Array.\n *\n * @category getters\n * @since 2.0.0\n */\n getState(): PCGRandomState {\n return [this._state[0]!, this._state[1]!, this._state[2]!, this._state[3]!]\n }\n\n /**\n * Restore state previously retrieved using `getState()`.\n *\n * @since 2.0.0\n */\n setState(state: PCGRandomState) {\n this._state[0] = state[0]\n this._state[1] = state[1]\n this._state[2] = state[2]\n this._state[3] = state[3] | 1\n }\n\n /**\n * Get a uniformly distributed 32 bit integer between [0, max).\n *\n * @category getter\n * @since 2.0.0\n */\n integer(max: number) {\n return Math.round(this.number() * Number.MAX_SAFE_INTEGER) % max\n }\n\n /**\n * Get a uniformly distributed IEEE-754 double between 0.0 and 1.0, with\n * 53 bits of precision (every bit of the mantissa is randomized).\n *\n * @category getters\n * @since 2.0.0\n */\n number() {\n const hi = (this._next() & 0x03ffffff) * 1.0\n const lo = (this._next() & 0x07ffffff) * 1.0\n return (hi * BIT_27 + lo) / BIT_53\n }\n\n /** @internal */\n private _next() {\n // save current state (what we'll use for this number)\n const oldHi = this._state[0]! >>> 0\n const oldLo = this._state[1]! >>> 0\n\n // churn LCG.\n mul64(this._state, oldHi, oldLo, MUL_HI, MUL_LO)\n add64(this._state, this._state[0]!, this._state[1]!, this._state[2]!, this._state[3]!)\n\n // get least sig. 32 bits of ((oldstate >> 18) ^ oldstate) >> 27\n let xsHi = oldHi >>> 18\n let xsLo = ((oldLo >>> 18) | (oldHi << 14)) >>> 0\n xsHi = (xsHi ^ oldHi) >>> 0\n xsLo = (xsLo ^ oldLo) >>> 0\n const xorshifted = ((xsLo >>> 27) | (xsHi << 5)) >>> 0\n // rotate xorshifted right a random amount, based on the most sig. 5 bits\n // bits of the old state.\n const rot = oldHi >>> 27\n const rot2 = ((-rot >>> 0) & 31) >>> 0\n return ((xorshifted >>> rot) | (xorshifted << rot2)) >>> 0\n }\n}\n\nfunction mul64(\n out: Int32Array,\n aHi: number,\n aLo: number,\n bHi: number,\n bLo: number\n): void {\n let c1 = ((aLo >>> 16) * (bLo & 0xffff)) >>> 0\n let c0 = ((aLo & 0xffff) * (bLo >>> 16)) >>> 0\n\n let lo = ((aLo & 0xffff) * (bLo & 0xffff)) >>> 0\n let hi = ((aLo >>> 16) * (bLo >>> 16) + ((c0 >>> 16) + (c1 >>> 16))) >>> 0\n\n c0 = (c0 << 16) >>> 0\n lo = (lo + c0) >>> 0\n if ((lo >>> 0) < (c0 >>> 0)) {\n hi = (hi + 1) >>> 0\n }\n\n c1 = (c1 << 16) >>> 0\n lo = (lo + c1) >>> 0\n if ((lo >>> 0) < (c1 >>> 0)) {\n hi = (hi + 1) >>> 0\n }\n\n hi = (hi + Math.imul(aLo, bHi)) >>> 0\n hi = (hi + Math.imul(aHi, bLo)) >>> 0\n\n out[0] = hi\n out[1] = lo\n}\n\n// add two 64 bit numbers (given in parts), and store the result in `out`.\nfunction add64(\n out: Int32Array,\n aHi: number,\n aLo: number,\n bHi: number,\n bLo: number\n): void {\n let hi = (aHi + bHi) >>> 0\n const lo = (aLo + bLo) >>> 0\n if ((lo >>> 0) < (aLo >>> 0)) {\n hi = (hi + 1) | 0\n }\n out[0] = hi\n out[1] = lo\n}\n\n/**\n * @since 3.0.6\n */\nexport const YieldWrapTypeId: unique symbol = Symbol.for(\"effect/Utils/YieldWrap\")\n\n/**\n * @since 3.0.6\n */\nexport class YieldWrap<T> {\n /**\n * @since 3.0.6\n */\n readonly #value: T\n constructor(value: T) {\n this.#value = value\n }\n /**\n * @since 3.0.6\n */\n [YieldWrapTypeId](): T {\n return this.#value\n }\n}\n\n/**\n * @since 3.0.6\n */\nexport function yieldWrapGet<T>(self: YieldWrap<T>): T {\n if (typeof self === \"object\" && self !== null && YieldWrapTypeId in self) {\n return self[YieldWrapTypeId]()\n }\n throw new Error(getBugErrorMessage(\"yieldWrapGet\"))\n}\n\n/**\n * Note: this is an experimental feature made available to allow custom matchers in tests, not to be directly used yet in user code\n *\n * @since 3.1.1\n * @status experimental\n * @category modifiers\n */\nexport const structuralRegionState = globalValue(\n \"effect/Utils/isStructuralRegion\",\n (): { enabled: boolean; tester: ((a: unknown, b: unknown) => boolean) | undefined } => ({\n enabled: false,\n tester: undefined\n })\n)\n\n/**\n * Note: this is an experimental feature made available to allow custom matchers in tests, not to be directly used yet in user code\n *\n * @since 3.1.1\n * @status experimental\n * @category modifiers\n */\nexport const structuralRegion = <A>(body: () => A, tester?: (a: unknown, b: unknown) => boolean): A => {\n const current = structuralRegionState.enabled\n const currentTester = structuralRegionState.tester\n structuralRegionState.enabled = true\n if (tester) {\n structuralRegionState.tester = tester\n }\n try {\n return body()\n } finally {\n structuralRegionState.enabled = current\n structuralRegionState.tester = currentTester\n }\n}\n\nconst standard = {\n effect_internal_function: <A>(body: () => A) => {\n return body()\n }\n}\n\nconst forced = {\n effect_internal_function: <A>(body: () => A) => {\n try {\n return body()\n } finally {\n //\n }\n }\n}\n\nconst isNotOptimizedAway =\n standard.effect_internal_function(() => new Error().stack)?.includes(\"effect_internal_function\") === true\n\n/**\n * @since 3.2.2\n * @status experimental\n * @category tracing\n */\nexport const internalCall = isNotOptimizedAway ? standard.effect_internal_function : forced.effect_internal_function\n\nconst genConstructor = (function*() {}).constructor\n\n/**\n * @since 3.11.0\n */\nexport const isGeneratorFunction = (u: unknown): u is (...args: Array<any>) => Generator<any, any, any> =>\n isObject(u) && u.constructor === genConstructor\n","/**\n * @since 2.0.0\n */\nimport { pipe } from \"./Function.js\"\nimport { globalValue } from \"./GlobalValue.js\"\nimport { hasProperty } from \"./Predicate.js\"\nimport { structuralRegionState } from \"./Utils.js\"\n\n/** @internal */\nconst randomHashCache = globalValue(\n Symbol.for(\"effect/Hash/randomHashCache\"),\n () => new WeakMap<object, number>()\n)\n\n/**\n * @since 2.0.0\n * @category symbols\n */\nexport const symbol: unique symbol = Symbol.for(\"effect/Hash\")\n\n/**\n * @since 2.0.0\n * @category models\n */\nexport interface Hash {\n [symbol](): number\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const hash: <A>(self: A) => number = <A>(self: A) => {\n if (structuralRegionState.enabled === true) {\n return 0\n }\n\n switch (typeof self) {\n case \"number\":\n return number(self)\n case \"bigint\":\n return string(self.toString(10))\n case \"boolean\":\n return string(String(self))\n case \"symbol\":\n return string(String(self))\n case \"string\":\n return string(self)\n case \"undefined\":\n return string(\"undefined\")\n case \"function\":\n case \"object\": {\n if (self === null) {\n return string(\"null\")\n } else if (self instanceof Date) {\n return hash(self.toISOString())\n } else if (self instanceof URL) {\n return hash(self.href)\n } else if (isHash(self)) {\n return self[symbol]()\n } else {\n return random(self)\n }\n }\n default:\n throw new Error(\n `BUG: unhandled typeof ${typeof self} - please report an issue at https://github.com/Effect-TS/effect/issues`\n )\n }\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const random: <A extends object>(self: A) => number = (self) => {\n if (!randomHashCache.has(self)) {\n randomHashCache.set(self, number(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)))\n }\n return randomHashCache.get(self)!\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const combine: (b: number) => (self: number) => number = (b) => (self) => (self * 53) ^ b\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const optimize = (n: number): number => (n & 0xbfffffff) | ((n >>> 1) & 0x40000000)\n\n/**\n * @since 2.0.0\n * @category guards\n */\nexport const isHash = (u: unknown): u is Hash => hasProperty(u, symbol)\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const number = (n: number) => {\n if (n !== n || n === Infinity) {\n return 0\n }\n let h = n | 0\n if (h !== n) {\n h ^= n * 0xffffffff\n }\n while (n > 0xffffffff) {\n h ^= n /= 0xffffffff\n }\n return optimize(h)\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const string = (str: string) => {\n let h = 5381, i = str.length\n while (i) {\n h = (h * 33) ^ str.charCodeAt(--i)\n }\n return optimize(h)\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const structureKeys = <A extends object>(o: A, keys: ReadonlyArray<keyof A>) => {\n let h = 12289\n for (let i = 0; i < keys.length; i++) {\n h ^= pipe(string(keys[i]! as string), combine(hash((o as any)[keys[i]!])))\n }\n return optimize(h)\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const structure = <A extends object>(o: A) =>\n structureKeys(o, Object.keys(o) as unknown as ReadonlyArray<keyof A>)\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const array = <A>(arr: ReadonlyArray<A>) => {\n let h = 6151\n for (let i = 0; i < arr.length; i++) {\n h = pipe(h, combine(hash(arr[i])))\n }\n return optimize(h)\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const cached: {\n /**\n * @since 2.0.0\n * @category hashing\n */\n (self: object): (hash: number) => number\n /**\n * @since 2.0.0\n * @category hashing\n */\n (self: object, hash: number): number\n} = function() {\n if (arguments.length === 1) {\n const self = arguments[0] as object\n return function(hash: number) {\n Object.defineProperty(self, symbol, {\n value() {\n return hash\n },\n enumerable: false\n })\n return hash\n } as any\n }\n const self = arguments[0] as object\n const hash = arguments[1] as number\n Object.defineProperty(self, symbol, {\n value() {\n return hash\n },\n enumerable: false\n })\n\n return hash\n}\n","/**\n * @since 2.0.0\n */\nimport type { Equivalence } from \"./Equivalence.js\"\nimport * as Hash from \"./Hash.js\"\nimport { hasProperty } from \"./Predicate.js\"\nimport { structuralRegionState } from \"./Utils.js\"\n\n/**\n * @since 2.0.0\n * @category symbols\n */\nexport const symbol: unique symbol = Symbol.for(\"effect/Equal\")\n\n/**\n * @since 2.0.0\n * @category models\n */\nexport interface Equal extends Hash.Hash {\n [symbol](that: Equal): boolean\n}\n\n/**\n * @since 2.0.0\n * @category equality\n */\nexport function equals<B>(that: B): <A>(self: A) => boolean\nexport function equals<A, B>(self: A, that: B): boolean\nexport function equals(): any {\n if (arguments.length === 1) {\n return (self: unknown) => compareBoth(self, arguments[0])\n }\n return compareBoth(arguments[0], arguments[1])\n}\n\nfunction compareBoth(self: unknown, that: unknown): boolean {\n if (self === that) {\n return true\n }\n const selfType = typeof self\n if (selfType !== typeof that) {\n return false\n }\n if (selfType === \"object\" || selfType === \"function\") {\n if (self !== null && that !== null) {\n if (isEqual(self) && isEqual(that)) {\n if (Hash.hash(self) === Hash.hash(that) && self[symbol](that)) {\n return true\n } else {\n return structuralRegionState.enabled && structuralRegionState.tester\n ? structuralRegionState.tester(self, that)\n : false\n }\n } else if (self instanceof Date && that instanceof Date) {\n return self.toISOString() === that.toISOString()\n } else if (self instanceof URL && that instanceof URL) {\n return self.href === that.href\n }\n }\n if (structuralRegionState.enabled) {\n if (Array.isArray(self) && Array.isArray(that)) {\n return self.length === that.length && self.every((v, i) => compareBoth(v, that[i]))\n }\n if (Object.getPrototypeOf(self) === Object.prototype && Object.getPrototypeOf(self) === Object.prototype) {\n const keysSelf = Object.keys(self as any)\n const keysThat = Object.keys(that as any)\n if (keysSelf.length === keysThat.length) {\n for (const key of keysSelf) {\n // @ts-expect-error\n if (!(key in that && compareBoth(self[key], that[key]))) {\n return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false\n }\n }\n return true\n }\n }\n return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false\n }\n }\n\n return structuralRegionState.enabled && structuralRegionState.tester\n ? structuralRegionState.tester(self, that)\n : false\n}\n\n/**\n * @since 2.0.0\n * @category guards\n */\nexport const isEqual = (u: unknown): u is Equal => hasProperty(u, symbol)\n\n/**\n * @since 2.0.0\n * @category instances\n */\nexport const equivalence: <A>() => Equivalence<A> = () => equals\n","/**\n * @since 2.0.0\n */\nimport type * as FiberRefs from \"./FiberRefs.js\"\nimport { globalValue } from \"./GlobalValue.js\"\nimport { hasProperty, isFunction } from \"./Predicate.js\"\n\n/**\n * @since 2.0.0\n * @category symbols\n */\nexport const NodeInspectSymbol = Symbol.for(\"nodejs.util.inspect.custom\")\n\n/**\n * @since 2.0.0\n * @category symbols\n */\nexport type NodeInspectSymbol = typeof NodeInspectSymbol\n\n/**\n * @since 2.0.0\n * @category models\n */\nexport interface Inspectable {\n toString(): string\n toJSON(): unknown\n [NodeInspectSymbol](): unknown\n}\n\n/**\n * @since 2.0.0\n */\nexport const toJSON = (x: unknown): unknown => {\n try {\n if (\n hasProperty(x, \"toJSON\") && isFunction(x[\"toJSON\"]) &&\n x[\"toJSON\"].length === 0\n ) {\n return x.toJSON()\n } else if (Array.isArray(x)) {\n return x.map(toJSON)\n }\n } catch {\n return {}\n }\n return redact(x)\n}\n\n/**\n * @since 2.0.0\n */\nexport const format = (x: unknown): string => JSON.stringify(x, null, 2)\n\n/**\n * @since 2.0.0\n */\nexport const BaseProto: Inspectable = {\n toJSON() {\n return toJSON(this)\n },\n [NodeInspectSymbol]() {\n return this.toJSON()\n },\n toString() {\n return format(this.toJSON())\n }\n}\n\n/**\n * @since 2.0.0\n */\nexport abstract class Class {\n /**\n * @since 2.0.0\n */\n abstract toJSON(): unknown\n /**\n * @since 2.0.0\n */\n [NodeInspectSymbol]() {\n return this.toJSON()\n }\n /**\n * @since 2.0.0\n */\n toString() {\n return format(this.toJSON())\n }\n}\n\n/**\n * @since 2.0.0\n */\nexport const toStringUnknown = (u: unknown, whitespace: number | string | undefined = 2): string => {\n if (typeof u === \"string\") {\n return u\n }\n try {\n return typeof u === \"object\" ? stringifyCircular(u, whitespace) : String(u)\n } catch {\n return String(u)\n }\n}\n\n/**\n * @since 2.0.0\n */\nexport const stringifyCircular = (obj: unknown, whitespace?: number | string | undefined): string => {\n let cache: Array<unknown> = []\n const retVal = JSON.stringify(\n obj,\n (_key, value) =>\n typeof value === \"object\" && value !== null\n ? cache.includes(value)\n ? undefined // circular reference\n : cache.push(value) && (redactableState.fiberRefs !== undefined && isRedactable(value)\n ? value[symbolRedactable](redactableState.fiberRefs)\n : value)\n : value,\n whitespace\n )\n ;(cache as any) = undefined\n return retVal\n}\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport interface Redactable {\n readonly [symbolRedactable]: (fiberRefs: FiberRefs.FiberRefs) => unknown\n}\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport const symbolRedactable: unique symbol = Symbol.for(\"effect/Inspectable/Redactable\")\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport const isRedactable = (u: unknown): u is Redactable =>\n typeof u === \"object\" && u !== null && symbolRedactable in u\n\nconst redactableState = globalValue(\"effect/Inspectable/redactableState\", () => ({\n fiberRefs: undefined as FiberRefs.FiberRefs | undefined\n}))\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport const withRedactableContext = <A>(context: FiberRefs.FiberRefs, f: () => A): A => {\n const prev = redactableState.fiberRefs\n redactableState.fiberRefs = context\n try {\n return f()\n } finally {\n redactableState.fiberRefs = prev\n }\n}\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport const redact = (u: unknown): unknown => {\n if (isRedactable(u) && redactableState.fiberRefs !== undefined) {\n return u[symbolRedactable](redactableState.fiberRefs)\n }\n return u\n}\n","/**\n * @since 2.0.0\n */\n\nimport type { Ctor } from \"./Types.js\"\n\n/**\n * @since 2.0.0\n * @category Models\n */\nexport interface Pipeable {\n pipe<A>(this: A): A\n pipe<A, B = never>(this: A, ab: (_: A) => B): B\n pipe<A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C\n pipe<A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D\n pipe<A, B = never, C = never, D = never, E = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E\n ): E\n pipe<A, B = never, C = never, D = never, E = never, F = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F\n ): F\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G\n ): G\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H\n ): H\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I\n ): I\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J\n ): J\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K\n ): K\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L\n ): L\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M\n ): M\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N\n ): N\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O\n ): O\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P\n ): P\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q\n ): Q\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R\n ): R\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R,\n rs: (_: R) => S\n ): S\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never,\n T = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R,\n rs: (_: R) => S,\n st: (_: S) => T\n ): T\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never,\n T = never,\n U = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R,\n rs: (_: R) => S,\n st: (_: S) => T,\n tu: (_: T) => U\n ): U\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never,\n T = never,\n U = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R,\n rs: (_: R) => S,\n st: (_: S) => T,\n tu: (_: T) => U\n ): U\n}\n\n/**\n * @since 2.0.0\n */\nexport const pipeArguments = <A>(self: A, args: IArguments): unknown => {\n switch (args.length) {\n case 0:\n return self\n case 1:\n return args[0](self)\n case 2:\n return args[1](args[0](self))\n case 3:\n return args[2](args[1](args[0](self)))\n case 4:\n return args[3](args[2](args[1](args[0](self))))\n case 5:\n return args[4](args[3](args[2](args[1](args[0](self)))))\n case 6:\n return args[5](args[4](args[3](args[2](args[1](args[0](self))))))\n case 7:\n return args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))))\n case 8:\n return args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self))))))))\n case 9:\n return args[8](args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))))))\n default: {\n let ret = self\n for (let i = 0, len = args.length; i < len; i++) {\n ret = args[i](ret)\n }\n return ret\n }\n }\n}\n\n/**\n * @since 3.15.0\n * @category Models\n */\nexport interface PipeableConstructor {\n new(...args: Array<any>): Pipeable\n}\n\n/**\n * @since 3.15.0\n * @category Prototypes\n */\nexport const Prototype: Pipeable = {\n pipe() {\n return pipeArguments(this, arguments)\n }\n}\n\nconst Base: PipeableConstructor = (function() {\n function PipeableBase() {}\n PipeableBase.prototype = Prototype\n return PipeableBase as any\n})()\n\n/**\n * @since 3.15.0\n * @category Constructors\n */\nexport const Class: {\n /**\n * @since 3.15.0\n * @category Constructors\n */\n (): PipeableConstructor\n /**\n * @since 3.15.0\n * @category Constructors\n */\n <TBase extends Ctor>(klass: TBase): TBase & PipeableConstructor\n} = (klass?: Ctor) =>\n klass ?\n class extends klass {\n pipe() {\n return pipeArguments(this, arguments)\n }\n }\n : Base\n","/** @internal */\nexport type OP_ASYNC = typeof OP_ASYNC\n\n/** @internal */\nexport const OP_ASYNC = \"Async\" as const\n\n/** @internal */\nexport type OP_COMMIT = typeof OP_COMMIT\n\n/** @internal */\nexport const OP_COMMIT = \"Commit\" as const\n\n/** @internal */\nexport type OP_FAILURE = typeof OP_FAILURE\n\n/** @internal */\nexport const OP_FAILURE = \"Failure\" as const\n\n/** @internal */\nexport type OP_ON_FAILURE = typeof OP_ON_FAILURE\n\n/** @internal */\nexport const OP_ON_FAILURE = \"OnFailure\" as const\n\n/** @internal */\nexport type OP_ON_SUCCESS = typeof OP_ON_SUCCESS\n\n/** @internal */\nexport const OP_ON_SUCCESS = \"OnSuccess\" as const\n\n/** @internal */\nexport type OP_ON_SUCCESS_AND_FAILURE = typeof OP_ON_SUCCESS_AND_FAILURE\n\n/** @internal */\nexport const OP_ON_SUCCESS_AND_FAILURE = \"OnSuccessAndFailure\" as const\n\n/** @internal */\nexport type OP_SUCCESS = typeof OP_SUCCESS\n\n/** @internal */\nexport const OP_SUCCESS = \"Success\" as const\n\n/** @internal */\nexport type OP_SYNC = typeof OP_SYNC\n\n/** @internal */\nexport const OP_SYNC = \"Sync\" as const\n\n/** @internal */\nexport const OP_TAG = \"Tag\" as const\n\n/** @internal */\nexport type OP_TAG = typeof OP_TAG\n\n/** @internal */\nexport type OP_UPDATE_RUNTIME_FLAGS = typeof OP_UPDATE_RUNTIME_FLAGS\n\n/** @internal */\nexport const OP_UPDATE_RUNTIME_FLAGS = \"UpdateRuntimeFlags\" as const\n\n/** @internal */\nexport type OP_WHILE = typeof OP_WHILE\n\n/** @internal */\nexport const OP_WHILE = \"While\" as const\n\n/** @internal */\nexport type OP_ITERATOR = typeof OP_ITERATOR\n\n/** @internal */\nexport const OP_ITERATOR = \"Iterator\" as const\n\n/** @internal */\nexport type OP_WITH_RUNTIME = typeof OP_WITH_RUNTIME\n\n/** @internal */\nexport const OP_WITH_RUNTIME = \"WithRuntime\" as const\n\n/** @internal */\nexport type OP_YIELD = typeof OP_YIELD\n\n/** @internal */\nexport const OP_YIELD = \"Yield\" as const\n\n/** @internal */\nexport type OP_REVERT_FLAGS = typeof OP_REVERT_FLAGS\n\n/** @internal */\nexport const OP_REVERT_FLAGS = \"RevertFlags\" as const\n","let moduleVersion = \"3.17.1\"\n\nexport const getCurrentVersion = () => moduleVersion\n\nexport const setCurrentVersion = (version: string) => {\n moduleVersion = version\n}\n","import type * as Channel from \"../Channel.js\"\nimport type * as Effect from \"../Effect.js\"\nimport type * as Effectable from \"../Effectable.js\"\nimport * as Equal from \"../Equal.js\"\nimport * as Hash from \"../Hash.js\"\nimport { pipeArguments } from \"../Pipeable.js\"\nimport type * as Sink from \"../Sink.js\"\nimport type * as Stream from \"../Stream.js\"\nimport { SingleShotGen, YieldWrap } from \"../Utils.js\"\nimport * as OpCodes from \"./opCodes/effect.js\"\nimport * as version from \"./version.js\"\n\n/** @internal */\nexport const EffectTypeId: Effect.EffectTypeId = Symbol.for(\"effect/Effect\") as Effect.EffectTypeId\n\n/** @internal */\nexport const StreamTypeId: Stream.StreamTypeId = Symbol.for(\"effect/Stream\") as Stream.StreamTypeId\n\n/** @internal */\nexport const SinkTypeId: Sink.SinkTypeId = Symbol.for(\"effect/Sink\") as Sink.SinkTypeId\n\n/** @internal */\nexport const ChannelTypeId: Channel.ChannelTypeId = Symbol.for(\"effect/Channel\") as Channel.ChannelTypeId\n\n/** @internal */\nexport const effectVariance = {\n /* c8 ignore next */\n _R: (_: never) => _,\n /* c8 ignore next */\n _E: (_: never) => _,\n /* c8 ignore next */\n _A: (_: never) => _,\n\n _V: version.getCurrentVersion()\n}\n\nconst sinkVariance = {\n /* c8 ignore next */\n _A: (_: never) => _,\n /* c8 ignore next */\n _In: (_: unknown) => _,\n /* c8 ignore next */\n _L: (_: never) => _,\n /* c8 ignore next */\n _E: (_: never) => _,\n /* c8 ignore next */\n _R: (_: never) => _\n}\n\nconst channelVariance = {\n /* c8 ignore next */\n _Env: (_: never) => _,\n /* c8 ignore next */\n _InErr: (_: unknown) => _,\n /* c8 ignore next */\n _InElem: (_: unknown) => _,\n /* c8 ignore next */\n _InDone: (_: unknown) => _,\n /* c8 ignore next */\n _OutErr: (_: never) => _,\n /* c8 ignore next */\n _OutElem: (_: never) => _,\n /* c8 ignore next */\n _OutDone: (_: never) => _\n}\n\n/** @internal */\nexport const EffectPrototype: Effect.Effect<never> & Equal.Equal = {\n [EffectTypeId]: effectVariance,\n [StreamTypeId]: effectVariance,\n [SinkTypeId]: sinkVariance,\n [ChannelTypeId]: channelVariance,\n [Equal.symbol](that: any) {\n return this === that\n },\n [Hash.symbol]() {\n return Hash.cached(this, Hash.random(this))\n },\n [Symbol.iterator]() {\n return new SingleShotGen(new YieldWrap(this)) as any\n },\n pipe() {\n return pipeArguments(this, arguments)\n }\n}\n\n/** @internal */\nexport const StructuralPrototype: Equal.Equal = {\n [Hash.symbol]() {\n return Hash.cached(this, Hash.structure(this))\n },\n [Equal.symbol](this: Equal.Equal, that: Equal.Equal) {\n const selfKeys = Object.keys(this)\n const thatKeys = Object.keys(that as object)\n if (selfKeys.length !== thatKeys.length) {\n return false\n }\n for (const key of selfKeys) {\n if (!(key in (that as object) && Equal.equals((this as any)[key], (that as any)[key]))) {\n return false\n }\n }\n return true\n }\n}\n\n/** @internal */\nexport const CommitPrototype: Effect.Effect<never> = {\n ...EffectPrototype,\n _op: OpCodes.OP_COMMIT\n} as any\n\n/** @internal */\nexport const StructuralCommitPrototype: Effect.Effect<never> = {\n ...CommitPrototype,\n ...StructuralPrototype\n} as any\n\n/** @internal */\nexport const Base: Effectable.CommitPrimitive = (function() {\n function Base() {}\n Base.prototype = CommitPrototype\n return Base as any\n})()\n\n/** @internal */\nexport const StructuralBase: Effectable.CommitPrimitive = (function() {\n function Base() {}\n Base.prototype = StructuralCommitPrototype\n return Base as any\n})()\n","/**\n * @since 2.0.0\n */\n\nimport * as Equal from \"../Equal.js\"\nimport * as Hash from \"../Hash.js\"\nimport { format, NodeInspectSymbol, toJSON } from \"../Inspectable.js\"\nimport type * as Option from \"../Option.js\"\nimport { hasProperty } from \"../Predicate.js\"\nimport { EffectPrototype } from \"./effectable.js\"\n\nconst TypeId: Option.TypeId = Symbol.for(\"effect/Option\") as Option.TypeId\n\nconst CommonProto = {\n ...EffectPrototype,\n [TypeId]: {\n _A: (_: never) => _\n },\n [NodeInspectSymbol]<A>(this: Option.Option<A>) {\n return this.toJSON()\n },\n toString<A>(this: Option.Option<A>) {\n return format(this.toJSON())\n }\n}\n\nconst SomeProto = Object.assign(Object.create(CommonProto), {\n _tag: \"Some\",\n _op: \"Some\",\n [Equal.symbol]<A>(this: Option.Some<A>, that: unknown): boolean {\n return isOption(that) && isSome(that) && Equal.equals(this.value, that.value)\n },\n [Hash.symbol]<A>(this: Option.Some<A>) {\n return Hash.cached(this, Hash.combine(Hash.hash(this._tag))(Hash.hash(this.value)))\n },\n toJSON<A>(this: Option.Some<A>) {\n return {\n _id: \"Option\",\n _tag: this._tag,\n value: toJSON(this.value)\n }\n }\n})\n\nconst NoneHash = Hash.hash(\"None\")\nconst NoneProto = Object.assign(Object.create(CommonProto), {\n _tag: \"None\",\n _op: \"None\",\n [Equal.symbol]<A>(this: Option.None<A>, that: unknown): boolean {\n return isOption(that) && isNone(that)\n },\n [Hash.symbol]<A>(this: Option.None<A>) {\n return NoneHash\n },\n toJSON<A>(this: Option.None<A>) {\n return {\n _id: \"Option\",\n _tag: this._tag\n }\n }\n})\n\n/** @internal */\nexport const isOption = (input: unknown): input is Option.Option<unknown> => hasProperty(input, TypeId)\n\n/** @internal */\nexport const isNone = <A>(fa: Option.Option<A>): fa is Option.None<A> => fa._tag === \"None\"\n\n/** @internal */\nexport const isSome = <A>(fa: Option.Option<A>): fa is Option.Some<A> => fa._tag === \"Some\"\n\n/** @internal */\nexport const none: Option.Option<never> = Object.create(NoneProto)\n\n/** @internal */\nexport const some = <A>(value: A): Option.Option<A> => {\n const a = Object.create(SomeProto)\n a.value = value\n return a\n}\n","/**\n * @since 2.0.0\n */\n\nimport type * as Either from \"../Either.js\"\nimport * as Equal from \"../Equal.js\"\nimport { dual } from \"../Function.js\"\nimport * as Hash from \"../Hash.js\"\nimport { format, NodeInspectSymbol, toJSON } from \"../Inspectable.js\"\nimport type { Option } from \"../Option.js\"\nimport { hasProperty } from \"../Predicate.js\"\nimport { EffectPrototype } from \"./effectable.js\"\nimport * as option from \"./option.js\"\n\n/**\n * @internal\n */\nexport const TypeId: Either.TypeId = Symbol.for(\"effect/Either\") as Either.TypeId\n\nconst CommonProto = {\n ...EffectPrototype,\n [TypeId]: {\n _R: (_: never) => _\n },\n [NodeInspectSymbol]<L, R>(this: Either.Either<R, L>) {\n return this.toJSON()\n },\n toString<L, R>(this: Either.Left<L, R>) {\n return format(this.toJSON())\n }\n}\n\nconst RightProto = Object.assign(Object.create(CommonProto), {\n _tag: \"Right\",\n _op: \"Right\",\n [Equal.symbol]<L, R>(this: Either.Right<L, R>, that: unknown): boolean {\n return isEither(that) && isRight(that) && Equal.equals(this.right, that.right)\n },\n [Hash.symbol]<L, R>(this: Either.Right<L, R>) {\n return Hash.combine(Hash.hash(this._tag))(Hash.hash(this.right))\n },\n toJSON<L, R>(this: Either.Right<L, R>) {\n return {\n _id: \"Either\",\n _tag: this._tag,\n right: toJSON(this.right)\n }\n }\n})\n\nconst LeftProto = Object.assign(Object.create(CommonProto), {\n _tag: \"Left\",\n _op: \"Left\",\n [Equal.symbol]<L, R>(this: Either.Left<L, R>, that: unknown): boolean {\n return isEither(that) && isLeft(that) && Equal.equals(this.left, that.left)\n },\n [Hash.symbol]<L, R>(this: Either.Left<L, R>) {\n return Hash.combine(Hash.hash(this._tag))(Hash.hash(this.left))\n },\n toJSON<E, A>(this: Either.Left<E, A>) {\n return {\n _id: \"Either\",\n _tag: this._tag,\n left: toJSON(this.left)\n }\n }\n})\n\n/** @internal */\nexport const isEither = (input: unknown): input is Either.Either<unknown, unknown> => hasProperty(input, TypeId)\n\n/** @internal */\nexport const isLeft = <R, L>(ma: Either.Either<R, L>): ma is Either.Left<L, R> => ma._tag === \"Left\"\n\n/** @internal */\nexport const isRight = <R, L>(ma: Either.Either<R, L>): ma is Either.Right<L, R> => ma._tag === \"Right\"\n\n/** @internal */\nexport const left = <L>(left: L): Either.Either<never, L> => {\n const a = Object.create(LeftProto)\n a.left = left\n return a\n}\n\n/** @internal */\nexport const right = <R>(right: R): Either.Either<R> => {\n const a = Object.create(RightProto)\n a.right = right\n return a\n}\n\n/** @internal */\nexport const getLeft = <R, L>(\n self: Either.Either<R, L>\n): Option<L> => (isRight(self) ? option.none : option.some(self.left))\n\n/** @internal */\nexport const getRight = <R, L>(\n self: Either.Either<R, L>\n): Option<R> => (isLeft(self) ? option.none : option.some(self.right))\n\n/** @internal */\nexport const fromOption: {\n <L>(onNone: () => L): <R>(self: Option<R>) => Either.Either<R, L>\n <R, L>(self: Option<R>, onNone: () => L): Either.Either<R, L>\n} = dual(\n 2,\n <R, L>(self: Option<R>, onNone: () => L): Either.Either<R, L> =>\n option.isNone(self) ? left(onNone()) : right(self.value)\n)\n","/**\n * @since 2.0.0\n */\n\nimport * as Equivalence from \"./Equivalence.js\"\nimport type { LazyArg } from \"./Function.js\"\nimport { constNull, constUndefined, dual, identity } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\nimport type { Inspectable } from \"./Inspectable.js\"\nimport * as doNotation from \"./internal/doNotation.js\"\nimport * as either from \"./internal/either.js\"\nimport * as option_ from \"./internal/option.js\"\nimport type { Option } from \"./Option.js\"\nimport type { Pipeable } from \"./Pipeable.js\"\nimport type { Predicate, Refinement } from \"./Predicate.js\"\nimport { isFunction } from \"./Predicate.js\"\nimport type { Covariant, NoInfer, NotFunction } from \"./Types.js\"\nimport type * as Unify from \"./Unify.js\"\nimport * as Gen from \"./Utils.js\"\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport type Either<R, L = never> = Left<L, R> | Right<L, R>\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport const TypeId: unique symbol = either.TypeId\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport type TypeId = typeof TypeId\n\n// TODO(4.0): flip the order of the type parameters\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Left<out L, out R> extends Pipeable, Inspectable {\n readonly _tag: \"Left\"\n readonly _op: \"Left\"\n readonly left: L\n readonly [TypeId]: {\n readonly _R: Covariant<R>\n readonly _L: Covariant<L>\n }\n [Unify.typeSymbol]?: unknown\n [Unify.unifySymbol]?: EitherUnify<this>\n [Unify.ignoreSymbol]?: EitherUnifyIgnore\n}\n\n// TODO(4.0): flip the order of the type parameters\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Right<out L, out R> extends Pipeable, Inspectable {\n readonly _tag: \"Right\"\n readonly _op: \"Right\"\n readonly right: R\n readonly [TypeId]: {\n readonly _R: Covariant<R>\n readonly _L: Covariant<L>\n }\n [Unify.typeSymbol]?: unknown\n [Unify.unifySymbol]?: EitherUnify<this>\n [Unify.ignoreSymbol]?: EitherUnifyIgnore\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface EitherUnify<A extends { [Unify.typeSymbol]?: any }> {\n Either?: () => A[Unify.typeSymbol] extends Either<infer R0, infer L0> | infer _ ? Either<R0, L0> : never\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface EitherUnifyIgnore {}\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface EitherTypeLambda extends TypeLambda {\n readonly type: Either<this[\"Target\"], this[\"Out1\"]>\n}\n\n/**\n * @since 2.0.0\n */\nexport declare namespace Either {\n /**\n * @since 2.0.0\n * @category type-level\n */\n export type Left<T extends Either<any, any>> = [T] extends [Either<infer _A, infer _E>] ? _E : never\n /**\n * @since 2.0.0\n * @category type-level\n */\n export type Right<T extends Either<any, any>> = [T] extends [Either<infer _A, infer _E>] ? _A : never\n}\n\n/**\n * Constructs a new `Either` holding a `Right` value. This usually represents a successful value due to the right bias\n * of this structure.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const right: <R>(right: R) => Either<R> = either.right\n\nconst void_: Either<void> = right(void 0)\nexport {\n /**\n * @category constructors\n * @since 3.13.0\n */\n void_ as void\n}\n\n/**\n * Constructs a new `Either` holding a `Left` value. This usually represents a failure, due to the right-bias of this\n * structure.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const left: <L>(left: L) => Either<never, L> = either.left\n\n/**\n * Takes a lazy default and a nullable value, if the value is not nully (`null` or `undefined`), turn it into a `Right`, if the value is nully use\n * the provided default as a `Left`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromNullable(1, () => 'fallback'), Either.right(1))\n * assert.deepStrictEqual(Either.fromNullable(null, () => 'fallback'), Either.left('fallback'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const fromNullable: {\n /**\n * Takes a lazy default and a nullable value, if the value is not nully (`null` or `undefined`), turn it into a `Right`, if the value is nully use\n * the provided default as a `Left`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromNullable(1, () => 'fallback'), Either.right(1))\n * assert.deepStrictEqual(Either.fromNullable(null, () => 'fallback'), Either.left('fallback'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <R, L>(onNullable: (right: R) => L): (self: R) => Either<NonNullable<R>, L>\n /**\n * Takes a lazy default and a nullable value, if the value is not nully (`null` or `undefined`), turn it into a `Right`, if the value is nully use\n * the provided default as a `Left`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromNullable(1, () => 'fallback'), Either.right(1))\n * assert.deepStrictEqual(Either.fromNullable(null, () => 'fallback'), Either.left('fallback'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <R, L>(self: R, onNullable: (right: R) => L): Either<NonNullable<R>, L>\n} = dual(\n 2,\n <R, L>(self: R, onNullable: (right: R) => L): Either<NonNullable<R>, L> =>\n self == null ? left(onNullable(self)) : right(self)\n)\n\n/**\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromOption(Option.some(1), () => 'error'), Either.right(1))\n * assert.deepStrictEqual(Either.fromOption(Option.none(), () => 'error'), Either.left('error'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const fromOption: {\n /**\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromOption(Option.some(1), () => 'error'), Either.right(1))\n * assert.deepStrictEqual(Either.fromOption(Option.none(), () => 'error'), Either.left('error'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <L>(onNone: () => L): <R>(self: Option<R>) => Either<R, L>\n /**\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromOption(Option.some(1), () => 'error'), Either.right(1))\n * assert.deepStrictEqual(Either.fromOption(Option.none(), () => 'error'), Either.left('error'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <R, L>(self: Option<R>, onNone: () => L): Either<R, L>\n} = either.fromOption\n\nconst try_: {\n <R, L>(\n options: {\n readonly try: LazyArg<R>\n readonly catch: (error: unknown) => L\n }\n ): Either<R, L>\n <R>(evaluate: LazyArg<R>): Either<R, unknown>\n} = (<R, L>(\n evaluate: LazyArg<R> | {\n readonly try: LazyArg<R>\n readonly catch: (error: unknown) => L\n }\n) => {\n if (isFunction(evaluate)) {\n try {\n return right(evaluate())\n } catch (e) {\n return left(e)\n }\n } else {\n try {\n return right(evaluate.try())\n } catch (e) {\n return left(evaluate.catch(e))\n }\n }\n}) as any\n\nexport {\n /**\n * Imports a synchronous side-effect into a pure `Either` value, translating any\n * thrown exceptions into typed failed eithers creating with `Either.left`.\n *\n * @category constructors\n * @since 2.0.0\n */\n try_ as try\n}\n\n/**\n * Tests if a value is a `Either`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.isEither(Either.right(1)), true)\n * assert.deepStrictEqual(Either.isEither(Either.left(\"a\")), true)\n * assert.deepStrictEqual(Either.isEither({ right: 1 }), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isEither: (input: unknown) => input is Either<unknown, unknown> = either.isEither\n\n/**\n * Determine if a `Either` is a `Left`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.isLeft(Either.right(1)), false)\n * assert.deepStrictEqual(Either.isLeft(Either.left(\"a\")), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isLeft: <R, L>(self: Either<R, L>) => self is Left<L, R> = either.isLeft\n\n/**\n * Determine if a `Either` is a `Right`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.isRight(Either.right(1)), true)\n * assert.deepStrictEqual(Either.isRight(Either.left(\"a\")), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isRight: <R, L>(self: Either<R, L>) => self is Right<L, R> = either.isRight\n\n/**\n * Converts a `Either` to an `Option` discarding the `Left`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getRight(Either.right('ok')), Option.some('ok'))\n * assert.deepStrictEqual(Either.getRight(Either.left('err')), Option.none())\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getRight: <R, L>(self: Either<R, L>) => Option<R> = either.getRight\n\n/**\n * Converts a `Either` to an `Option` discarding the value.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getLeft(Either.right('ok')), Option.none())\n * assert.deepStrictEqual(Either.getLeft(Either.left('err')), Option.some('err'))\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getLeft: <R, L>(self: Either<R, L>) => Option<L> = either.getLeft\n\n/**\n * @category equivalence\n * @since 2.0.0\n */\nexport const getEquivalence = <R, L>({ left, right }: {\n right: Equivalence.Equivalence<R>\n left: Equivalence.Equivalence<L>\n}): Equivalence.Equivalence<Either<R, L>> =>\n Equivalence.make((x, y) =>\n isLeft(x) ?\n isLeft(y) && left(x.left, y.left) :\n isRight(y) && right(x.right, y.right)\n )\n\n/**\n * @category mapping\n * @since 2.0.0\n */\nexport const mapBoth: {\n /**\n * @category mapping\n * @since 2.0.0\n */\n <L, L2, R, R2>(\n options: {\n readonly onLeft: (left: L) => L2\n readonly onRight: (right: R) => R2\n }\n ): (self: Either<R, L>) => Either<R2, L2>\n /**\n * @category mapping\n * @since 2.0.0\n */\n <L, R, L2, R2>(\n self: Either<R, L>,\n options: {\n readonly onLeft: (left: L) => L2\n readonly onRight: (right: R) => R2\n }\n ): Either<R2, L2>\n} = dual(\n 2,\n <L, R, L2, R2>(self: Either<R, L>, { onLeft, onRight }: {\n readonly onLeft: (left: L) => L2\n readonly onRight: (right: R) => R2\n }): Either<R2, L2> => isLeft(self) ? left(onLeft(self.left)) : right(onRight(self.right))\n)\n\n/**\n * Maps the `Left` side of an `Either` value to a new `Either` value.\n *\n * @category mapping\n * @since 2.0.0\n */\nexport const mapLeft: {\n /**\n * Maps the `Left` side of an `Either` value to a new `Either` value.\n *\n * @category mapping\n * @since 2.0.0\n */\n <L, L2>(f: (left: L) => L2): <R>(self: Either<R, L>) => Either<R, L2>\n /**\n * Maps the `Left` side of an `Either` value to a new `Either` value.\n *\n * @category mapping\n * @since 2.0.0\n */\n <R, L, L2>(self: Either<R, L>, f: (left: L) => L2): Either<R, L2>\n} = dual(\n 2,\n <R, L1, L2>(self: Either<R, L1>, f: (left: L1) => L2): Either<R, L2> =>\n isLeft(self) ? left(f(self.left)) : right(self.right)\n)\n\n/**\n * Maps the `Right` side of an `Either` value to a new `Either` value.\n *\n * @category mapping\n * @since 2.0.0\n */\nexport const map: {\n /**\n * Maps the `Right` side of an `Either` value to a new `Either` value.\n *\n * @category mapping\n * @since 2.0.0\n */\n <R, R2>(f: (right: R) => R2): <L>(self: Either<R, L>) => Either<R2, L>\n /**\n * Maps the `Right` side of an `Either` value to a new `Either` value.\n *\n * @category mapping\n * @since 2.0.0\n */\n <R, L, R2>(self: Either<R, L>, f: (right: R) => R2): Either<R2, L>\n} = dual(\n 2,\n <R1, L, R2>(self: Either<R1, L>, f: (right: R1) => R2): Either<R2, L> =>\n isRight(self) ? right(f(self.right)) : left(self.left)\n)\n\n/**\n * Takes two functions and an `Either` value, if the value is a `Left` the inner value is applied to the `onLeft function,\n * if the value is a `Right` the inner value is applied to the `onRight` function.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const onLeft = (strings: ReadonlyArray<string>): string => `strings: ${strings.join(', ')}`\n *\n * const onRight = (value: number): string => `Ok: ${value}`\n *\n * assert.deepStrictEqual(pipe(Either.right(1), Either.match({ onLeft, onRight })), 'Ok: 1')\n * assert.deepStrictEqual(\n * pipe(Either.left(['string 1', 'string 2']), Either.match({ onLeft, onRight })),\n * 'strings: string 1, string 2'\n * )\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\nexport const match: {\n /**\n * Takes two functions and an `Either` value, if the value is a `Left` the inner value is applied to the `onLeft function,\n * if the value is a `Right` the inner value is applied to the `onRight` function.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const onLeft = (strings: ReadonlyArray<string>): string => `strings: ${strings.join(', ')}`\n *\n * const onRight = (value: number): string => `Ok: ${value}`\n *\n * assert.deepStrictEqual(pipe(Either.right(1), Either.match({ onLeft, onRight })), 'Ok: 1')\n * assert.deepStrictEqual(\n * pipe(Either.left(['string 1', 'string 2']), Either.match({ onLeft, onRight })),\n * 'strings: string 1, string 2'\n * )\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <L, B, R, C = B>(\n options: {\n readonly onLeft: (left: L) => B\n readonly onRight: (right: R) => C\n }\n ): (self: Either<R, L>) => B | C\n /**\n * Takes two functions and an `Either` value, if the value is a `Left` the inner value is applied to the `onLeft function,\n * if the value is a `Right` the inner value is applied to the `onRight` function.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const onLeft = (strings: ReadonlyArray<string>): string => `strings: ${strings.join(', ')}`\n *\n * const onRight = (value: number): string => `Ok: ${value}`\n *\n * assert.deepStrictEqual(pipe(Either.right(1), Either.match({ onLeft, onRight })), 'Ok: 1')\n * assert.deepStrictEqual(\n * pipe(Either.left(['string 1', 'string 2']), Either.match({ onLeft, onRight })),\n * 'strings: string 1, string 2'\n * )\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <R, L, B, C = B>(\n self: Either<R, L>,\n options: {\n readonly onLeft: (left: L) => B\n readonly onRight: (right: R) => C\n }\n ): B | C\n} = dual(\n 2,\n <R, L, B, C = B>(self: Either<R, L>, { onLeft, onRight }: {\n readonly onLeft: (left: L) => B\n readonly onRight: (right: R) => C\n }): B | C => isLeft(self) ? onLeft(self.left) : onRight(self.right)\n)\n\n/**\n * Transforms a `Predicate` function into a `Right` of the input value if the predicate returns `true`\n * or `Left` of the result of the provided function if the predicate returns false\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n * const isPositiveEither = Either.liftPredicate(isPositive, n => `${n} is not positive`)\n *\n * assert.deepStrictEqual(\n * isPositiveEither(1),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * isPositiveEither(0),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @category lifting\n * @since 3.4.0\n */\nexport const liftPredicate: {\n /**\n * Transforms a `Predicate` function into a `Right` of the input value if the predicate returns `true`\n * or `Left` of the result of the provided function if the predicate returns false\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n * const isPositiveEither = Either.liftPredicate(isPositive, n => `${n} is not positive`)\n *\n * assert.deepStrictEqual(\n * isPositiveEither(1),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * isPositiveEither(0),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @category lifting\n * @since 3.4.0\n */\n <A, B extends A, E>(refinement: Refinement<A, B>, orLeftWith: (a: A) => E): (a: A) => Either<B, E>\n /**\n * Transforms a `Predicate` function into a `Right` of the input value if the predicate returns `true`\n * or `Left` of the result of the provided function if the predicate returns false\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n * const isPositiveEither = Either.liftPredicate(isPositive, n => `${n} is not positive`)\n *\n * assert.deepStrictEqual(\n * isPositiveEither(1),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * isPositiveEither(0),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @category lifting\n * @since 3.4.0\n */\n <B extends A, E, A = B>(predicate: Predicate<A>, orLeftWith: (a: A) => E): (a: B) => Either<B, E>\n /**\n * Transforms a `Predicate` function into a `Right` of the input value if the predicate returns `true`\n * or `Left` of the result of the provided function if the predicate returns false\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n * const isPositiveEither = Either.liftPredicate(isPositive, n => `${n} is not positive`)\n *\n * assert.deepStrictEqual(\n * isPositiveEither(1),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * isPositiveEither(0),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @category lifting\n * @since 3.4.0\n */\n <A, E, B extends A>(self: A, refinement: Refinement<A, B>, orLeftWith: (a: A) => E): Either<B, E>\n /**\n * Transforms a `Predicate` function into a `Right` of the input value if the predicate returns `true`\n * or `Left` of the result of the provided function if the predicate returns false\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n * const isPositiveEither = Either.liftPredicate(isPositive, n => `${n} is not positive`)\n *\n * assert.deepStrictEqual(\n * isPositiveEither(1),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * isPositiveEither(0),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @category lifting\n * @since 3.4.0\n */\n <B extends A, E, A = B>(self: B, predicate: Predicate<A>, orLeftWith: (a: A) => E): Either<B, E>\n} = dual(\n 3,\n <A, E>(a: A, predicate: Predicate<A>, orLeftWith: (a: A) => E): Either<A, E> =>\n predicate(a) ? right(a) : left(orLeftWith(a))\n)\n\n/**\n * Filter the right value with the provided function.\n * If the predicate fails, set the left value with the result of the provided function.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(1),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(0),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @since 2.0.0\n * @category filtering & conditionals\n */\nexport const filterOrLeft: {\n /**\n * Filter the right value with the provided function.\n * If the predicate fails, set the left value with the result of the provided function.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(1),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(0),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @since 2.0.0\n * @category filtering & conditionals\n */\n <R, B extends R, L2>(\n refinement: Refinement<NoInfer<R>, B>,\n orLeftWith: (right: NoInfer<R>) => L2\n ): <L>(self: Either<R, L>) => Either<B, L2 | L>\n /**\n * Filter the right value with the provided function.\n * If the predicate fails, set the left value with the result of the provided function.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(1),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(0),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @since 2.0.0\n * @category filtering & conditionals\n */\n <R, L2>(predicate: Predicate<NoInfer<R>>, orLeftWith: (right: NoInfer<R>) => L2): <L>(self: Either<R, L>) => Either<R, L2 | L>\n /**\n * Filter the right value with the provided function.\n * If the predicate fails, set the left value with the result of the provided function.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(1),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(0),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @since 2.0.0\n * @category filtering & conditionals\n */\n <R, L, B extends R, L2>(\n self: Either<R, L>,\n refinement: Refinement<R, B>,\n orLeftWith: (right: R) => L2\n ): Either<B, L | L2>\n /**\n * Filter the right value with the provided function.\n * If the predicate fails, set the left value with the result of the provided function.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(1),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(0),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @since 2.0.0\n * @category filtering & conditionals\n */\n <R, L, E2>(self: Either<R, L>, predicate: Predicate<R>, orLeftWith: (right: R) => E2): Either<R, L | E2>\n} = dual(3, <R, L, E2>(\n self: Either<R, L>,\n predicate: Predicate<R>,\n orLeftWith: (right: R) => E2\n): Either<R, L | E2> => flatMap(self, (r) => predicate(r) ? right(r) : left(orLeftWith(r))))\n\n/**\n * @category getters\n * @since 2.0.0\n */\nexport const merge: <R, L>(self: Either<R, L>) => L | R = match({\n onLeft: identity,\n onRight: identity\n})\n\n/**\n * Returns the wrapped value if it's a `Right` or a default value if is a `Left`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrElse(Either.right(1), (error) => error + \"!\"), 1)\n * assert.deepStrictEqual(Either.getOrElse(Either.left(\"not a number\"), (error) => error + \"!\"), \"not a number!\")\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrElse: {\n /**\n * Returns the wrapped value if it's a `Right` or a default value if is a `Left`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrElse(Either.right(1), (error) => error + \"!\"), 1)\n * assert.deepStrictEqual(Either.getOrElse(Either.left(\"not a number\"), (error) => error + \"!\"), \"not a number!\")\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <L, R2>(onLeft: (left: L) => R2): <R>(self: Either<R, L>) => R2 | R\n /**\n * Returns the wrapped value if it's a `Right` or a default value if is a `Left`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrElse(Either.right(1), (error) => error + \"!\"), 1)\n * assert.deepStrictEqual(Either.getOrElse(Either.left(\"not a number\"), (error) => error + \"!\"), \"not a number!\")\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <R, L, R2>(self: Either<R, L>, onLeft: (left: L) => R2): R | R2\n} = dual(\n 2,\n <R, L, B>(self: Either<R, L>, onLeft: (left: L) => B): R | B => isLeft(self) ? onLeft(self.left) : self.right\n)\n\n/**\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrNull(Either.right(1)), 1)\n * assert.deepStrictEqual(Either.getOrNull(Either.left(\"a\")), null)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrNull: <R, L>(self: Either<R, L>) => R | null = getOrElse(constNull)\n\n/**\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrUndefined(Either.right(1)), 1)\n * assert.deepStrictEqual(Either.getOrUndefined(Either.left(\"a\")), undefined)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrUndefined: <R, L>(self: Either<R, L>) => R | undefined = getOrElse(constUndefined)\n\n/**\n * Extracts the value of an `Either` or throws if the `Either` is `Left`.\n *\n * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Either.getOrThrowWith(Either.right(1), () => new Error('Unexpected Left')),\n * 1\n * )\n * assert.throws(() => Either.getOrThrowWith(Either.left(\"error\"), () => new Error('Unexpected Left')))\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrThrowWith: {\n /**\n * Extracts the value of an `Either` or throws if the `Either` is `Left`.\n *\n * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Either.getOrThrowWith(Either.right(1), () => new Error('Unexpected Left')),\n * 1\n * )\n * assert.throws(() => Either.getOrThrowWith(Either.left(\"error\"), () => new Error('Unexpected Left')))\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <L>(onLeft: (left: L) => unknown): <A>(self: Either<A, L>) => A\n /**\n * Extracts the value of an `Either` or throws if the `Either` is `Left`.\n *\n * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Either.getOrThrowWith(Either.right(1), () => new Error('Unexpected Left')),\n * 1\n * )\n * assert.throws(() => Either.getOrThrowWith(Either.left(\"error\"), () => new Error('Unexpected Left')))\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <R, L>(self: Either<R, L>, onLeft: (left: L) => unknown): R\n} = dual(2, <R, L>(self: Either<R, L>, onLeft: (left: L) => unknown): R => {\n if (isRight(self)) {\n return self.right\n }\n throw onLeft(self.left)\n})\n\n// TODO(4.0): by default should throw `L` (i.e getOrThrowWith with the identity function)\n/**\n * Extracts the value of an `Either` or throws if the `Either` is `Left`.\n *\n * The thrown error is a default error. To configure the error thrown, see {@link getOrThrowWith}.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrThrow(Either.right(1)), 1)\n * assert.throws(() => Either.getOrThrow(Either.left(\"error\")))\n * ```\n *\n * @throws `Error(\"getOrThrow called on a Left\")`\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrThrow: <R, L>(self: Either<R, L>) => R = getOrThrowWith(() =>\n new Error(\"getOrThrow called on a Left\")\n)\n\n/**\n * Returns `self` if it is a `Right` or `that` otherwise.\n *\n * @category error handling\n * @since 2.0.0\n */\nexport const orElse: {\n /**\n * Returns `self` if it is a `Right` or `that` otherwise.\n *\n * @category error handling\n * @since 2.0.0\n */\n <L, R2, L2>(that: (left: L) => Either<R2, L2>): <R>(self: Either<R, L>) => Either<R | R2, L2>\n /**\n * Returns `self` if it is a `Right` or `that` otherwise.\n *\n * @category error handling\n * @since 2.0.0\n */\n <R, L, R2, L2>(self: Either<R, L>, that: (left: L) => Either<R2, L2>): Either<R | R2, L2>\n} = dual(\n 2,\n <R1, L1, R2, L2>(self: Either<R1, L1>, that: (left: L1) => Either<R2, L2>): Either<R1 | R2, L2> =>\n isLeft(self) ? that(self.left) : right(self.right)\n)\n\n/**\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatMap: {\n /**\n * @category sequencing\n * @since 2.0.0\n */\n <R, R2, L2>(f: (right: R) => Either<R2, L2>): <L>(self: Either<R, L>) => Either<R2, L | L2>\n /**\n * @category sequencing\n * @since 2.0.0\n */\n <R, L, R2, L2>(self: Either<R, L>, f: (right: R) => Either<R2, L2>): Either<R2, L | L2>\n} = dual(\n 2,\n <R1, L1, R2, L2>(self: Either<R1, L1>, f: (right: R1) => Either<R2, L2>): Either<R2, L1 | L2> =>\n isLeft(self) ? left(self.left) : f(self.right)\n)\n\n/**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const andThen: {\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, R2, L2>(f: (right: R) => Either<R2, L2>): <L>(self: Either<R, L>) => Either<R2, L | L2>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R2, L2>(f: Either<R2, L2>): <L, R1>(self: Either<R1, L>) => Either<R2, L | L2>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, R2>(f: (right: R) => R2): <L>(self: Either<R, L>) => Either<R2, L>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R2>(right: NotFunction<R2>): <R1, L>(self: Either<R1, L>) => Either<R2, L>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, L, R2, L2>(self: Either<R, L>, f: (right: R) => Either<R2, L2>): Either<R2, L | L2>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, L, R2, L2>(self: Either<R, L>, f: Either<R2, L2>): Either<R2, L | L2>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, L, R2>(self: Either<R, L>, f: (right: R) => R2): Either<R2, L>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, L, R2>(self: Either<R, L>, f: NotFunction<R2>): Either<R2, L>\n} = dual(\n 2,\n <R, L, R2, L2>(self: Either<R, L>, f: (right: R) => Either<R2, L2> | Either<R2, L2>): Either<R2, L | L2> =>\n flatMap(self, (a) => {\n const b = isFunction(f) ? f(a) : f\n return isEither(b) ? b : right(b)\n })\n)\n\n/**\n * @category zipping\n * @since 2.0.0\n */\nexport const zipWith: {\n /**\n * @category zipping\n * @since 2.0.0\n */\n <R2, L2, R, B>(that: Either<R2, L2>, f: (right: R, right2: R2) => B): <L>(self: Either<R, L>) => Either<B, L2 | L>\n /**\n * @category zipping\n * @since 2.0.0\n */\n <R, L, R2, L2, B>(self: Either<R, L>, that: Either<R2, L2>, f: (right: R, right2: R2) => B): Either<B, L | L2>\n} = dual(\n 3,\n <R, L, R2, L2, B>(self: Either<R, L>, that: Either<R2, L2>, f: (right: R, right2: R2) => B): Either<B, L | L2> =>\n flatMap(self, (r) => map(that, (r2) => f(r, r2)))\n)\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const ap: {\n /**\n * @category combining\n * @since 2.0.0\n */\n <R, L2>(that: Either<R, L2>): <R2, L>(self: Either<(right: R) => R2, L>) => Either<R2, L | L2>\n /**\n * @category combining\n * @since 2.0.0\n */\n <R, R2, L, L2>(self: Either<(right: R) => R2, L>, that: Either<R, L2>): Either<R2, L | L2>\n} = dual(\n 2,\n <R, R2, L, L2>(self: Either<(right: R) => R2, L>, that: Either<R, L2>): Either<R2, L | L2> =>\n zipWith(self, that, (f, a) => f(a))\n)\n\n/**\n * Takes a structure of `Either`s and returns an `Either` of values with the same structure.\n *\n * - If a tuple is supplied, then the returned `Either` will contain a tuple with the same length.\n * - If a struct is supplied, then the returned `Either` will contain a struct with the same keys.\n * - If an iterable is supplied, then the returned `Either` will contain an array.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.all([Either.right(1), Either.right(2)]), Either.right([1, 2]))\n * assert.deepStrictEqual(Either.all({ right: Either.right(1), b: Either.right(\"hello\") }), Either.right({ right: 1, b: \"hello\" }))\n * assert.deepStrictEqual(Either.all({ right: Either.right(1), b: Either.left(\"error\") }), Either.left(\"error\"))\n * ```\n *\n * @category combining\n * @since 2.0.0\n */\n// @ts-expect-error\nexport const all: <const I extends Iterable<Either<any, any>> | Record<string, Either<any, any>>>(\n input: I\n) => [I] extends [ReadonlyArray<Either<any, any>>] ? Either<\n { -readonly [K in keyof I]: [I[K]] extends [Either<infer R, any>] ? R : never },\n I[number] extends never ? never : [I[number]] extends [Either<any, infer L>] ? L : never\n >\n : [I] extends [Iterable<Either<infer R, infer L>>] ? Either<Array<R>, L>\n : Either<\n { -readonly [K in keyof I]: [I[K]] extends [Either<infer R, any>] ? R : never },\n I[keyof I] extends never ? never : [I[keyof I]] extends [Either<any, infer L>] ? L : never\n > = (\n input: Iterable<Either<any, any>> | Record<string, Either<any, any>>\n ): Either<any, any> => {\n if (Symbol.iterator in input) {\n const out: Array<Either<any, any>> = []\n for (const e of input) {\n if (isLeft(e)) {\n return e\n }\n out.push(e.right)\n }\n return right(out)\n }\n\n const out: Record<string, any> = {}\n for (const key of Object.keys(input)) {\n const e = input[key]\n if (isLeft(e)) {\n return e\n }\n out[key] = e.right\n }\n return right(out)\n }\n\n/**\n * Returns an `Either` that swaps the error/success cases. This allows you to\n * use all methods on the error channel, possibly before flipping back.\n *\n * @since 2.0.0\n * @category mapping\n */\nexport const flip = <R, L>(self: Either<R, L>): Either<L, R> => isLeft(self) ? right(self.left) : left(self.right)\n\nconst adapter = Gen.adapter<EitherTypeLambda>()\n\n/**\n * @category generators\n * @since 2.0.0\n */\nexport const gen: Gen.Gen<EitherTypeLambda, Gen.Adapter<EitherTypeLambda>> = (...args) => {\n const f = args.length === 1 ? args[0] : args[1].bind(args[0])\n const iterator = f(adapter)\n let state: IteratorResult<any> = iterator.next()\n while (!state.done) {\n const current = Gen.isGenKind(state.value)\n ? state.value.value\n : Gen.yieldWrapGet(state.value)\n if (isLeft(current)) {\n return current\n }\n state = iterator.next(current.right as never)\n }\n return right(state.value) as any\n}\n\n// -------------------------------------------------------------------------------------\n// do notation\n// -------------------------------------------------------------------------------------\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link bind}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 2.0.0\n */\nexport const Do: Either<{}> = right({})\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 2.0.0\n */\nexport const bind: {\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 2.0.0\n */\n <N extends string, A extends object, B, L2>(name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Either<B, L2>): <L1>(self: Either<A, L1>) => Either<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, L1 | L2>\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 2.0.0\n */\n <A extends object, L1, N extends string, B, L2>(\n self: Either<A, L1>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => Either<B, L2>\n ): Either<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, L1 | L2>\n} = doNotation.bind<EitherTypeLambda>(map, flatMap)\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 2.0.0\n */\nexport const bindTo: {\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 2.0.0\n */\n <N extends string>(name: N): <R, L>(self: Either<R, L>) => Either<{ [K in N]: R }, L>\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 2.0.0\n */\n <R, L, N extends string>(self: Either<R, L>, name: N): Either<{ [K in N]: R }, L>\n} = doNotation.bindTo<EitherTypeLambda>(map)\n\nconst let_: {\n <N extends string, R extends object, B>(\n name: Exclude<N, keyof R>,\n f: (r: NoInfer<R>) => B\n ): <L>(self: Either<R, L>) => Either<{ [K in N | keyof R]: K extends keyof R ? R[K] : B }, L>\n <R extends object, L, N extends string, B>(\n self: Either<R, L>,\n name: Exclude<N, keyof R>,\n f: (r: NoInfer<R>) => B\n ): Either<{ [K in N | keyof R]: K extends keyof R ? R[K] : B }, L>\n} = doNotation.let_<EitherTypeLambda>(map)\n\nexport {\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link bind}\n *\n * @category do notation\n * @since 2.0.0\n */\n let_ as let\n}\n\n/**\n * Converts an `Option` of an `Either` into an `Either` of an `Option`.\n *\n * **Details**\n *\n * This function transforms an `Option<Either<A, E>>` into an\n * `Either<Option<A>, E>`. If the `Option` is `None`, the resulting `Either`\n * will be a `Right` with a `None` value. If the `Option` is `Some`, the\n * inner `Either` will be executed, and its result wrapped in a `Some`.\n *\n * @example\n * ```ts\n * import { Effect, Either, Option } from \"effect\"\n *\n * // ┌─── Option<Either<number, never>>\n * // ▼\n * const maybe = Option.some(Either.right(42))\n *\n * // ┌─── Either<Option<number>, never, never>\n * // ▼\n * const result = Either.transposeOption(maybe)\n *\n * console.log(Effect.runSync(result))\n * // Output: { _id: 'Option', _tag: 'Some', value: 42 }\n * ```\n *\n * @since 3.14.0\n * @category Optional Wrapping & Unwrapping\n */\nexport const transposeOption = <A = never, E = never>(\n self: Option<Either<A, E>>\n): Either<Option<A>, E> => {\n return option_.isNone(self) ? right(option_.none) : map(self.value, option_.some)\n}\n\n/**\n * Applies an `Either` on an `Option` and transposes the result.\n *\n * **Details**\n *\n * If the `Option` is `None`, the resulting `Either` will immediately succeed with a `Right` value of `None`.\n * If the `Option` is `Some`, the transformation function will be applied to the inner value, and its result wrapped in a `Some`.\n *\n * @example\n * ```ts\n * import { Either, Option, pipe } from \"effect\"\n *\n * // ┌─── Either<Option<number>, never>>\n * // ▼\n * const noneResult = pipe(\n * Option.none(),\n * Either.transposeMapOption(() => Either.right(42)) // will not be executed\n * )\n * console.log(noneResult)\n * // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'None' } }\n *\n * // ┌─── Either<Option<number>, never>>\n * // ▼\n * const someRightResult = pipe(\n * Option.some(42),\n * Either.transposeMapOption((value) => Either.right(value * 2))\n * )\n * console.log(someRightResult)\n * // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'Some', value: 84 } }\n * ```\n *\n * @since 3.15.0\n * @category Optional Wrapping & Unwrapping\n */\nexport const transposeMapOption = dual<\n /**\n * Applies an `Either` on an `Option` and transposes the result.\n *\n * **Details**\n *\n * If the `Option` is `None`, the resulting `Either` will immediately succeed with a `Right` value of `None`.\n * If the `Option` is `Some`, the transformation function will be applied to the inner value, and its result wrapped in a `Some`.\n *\n * @example\n * ```ts\n * import { Either, Option, pipe } from \"effect\"\n *\n * // ┌─── Either<Option<number>, never>>\n * // ▼\n * const noneResult = pipe(\n * Option.none(),\n * Either.transposeMapOption(() => Either.right(42)) // will not be executed\n * )\n * console.log(noneResult)\n * // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'None' } }\n *\n * // ┌─── Either<Option<number>, never>>\n * // ▼\n * const someRightResult = pipe(\n * Option.some(42),\n * Either.transposeMapOption((value) => Either.right(value * 2))\n * )\n * console.log(someRightResult)\n * // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'Some', value: 84 } }\n * ```\n *\n * @since 3.15.0\n * @category Optional Wrapping & Unwrapping\n */\n <A, B, E = never>(f: (self: A) => Either<B, E>) => (self: Option<A>) => Either<Option<B>, E>,\n /**\n * Applies an `Either` on an `Option` and transposes the result.\n *\n * **Details**\n *\n * If the `Option` is `None`, the resulting `Either` will immediately succeed with a `Right` value of `None`.\n * If the `Option` is `Some`, the transformation function will be applied to the inner value, and its result wrapped in a `Some`.\n *\n * @example\n * ```ts\n * import { Either, Option, pipe } from \"effect\"\n *\n * // ┌─── Either<Option<number>, never>>\n * // ▼\n * const noneResult = pipe(\n * Option.none(),\n * Either.transposeMapOption(() => Either.right(42)) // will not be executed\n * )\n * console.log(noneResult)\n * // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'None' } }\n *\n * // ┌─── Either<Option<number>, never>>\n * // ▼\n * const someRightResult = pipe(\n * Option.some(42),\n * Either.transposeMapOption((value) => Either.right(value * 2))\n * )\n * console.log(someRightResult)\n * // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'Some', value: 84 } }\n * ```\n *\n * @since 3.15.0\n * @category Optional Wrapping & Unwrapping\n */\n <A, B, E = never>(self: Option<A>, f: (self: A) => Either<B, E>) => Either<Option<B>, E>\n>(2, (self, f) => option_.isNone(self) ? right(option_.none) : map(f(self.value), option_.some))\n","/**\n * @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 * as assert from \"node:assert\"\n * import { Order, Number } from \"effect\"\n *\n * const clamp = Order.clamp(Number.Order)({ minimum: 1, maximum: 5 })\n *\n * assert.equal(clamp(3), 3)\n * assert.equal(clamp(0), 1)\n * assert.equal(clamp(6), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const clamp = <A>(O: Order<A>): {\n (options: {\n minimum: A\n maximum: A\n }): (self: A) => A\n (self: A, options: {\n minimum: A\n maximum: A\n }): A\n} =>\n dual(\n 2,\n (self: A, options: {\n minimum: A\n maximum: A\n }): A => min(O)(options.maximum, max(O)(options.minimum, self))\n )\n\n/**\n * Test whether a value is between a minimum and a maximum (inclusive).\n *\n * @since 2.0.0\n */\nexport const between = <A>(O: Order<A>): {\n (options: {\n minimum: A\n maximum: A\n }): (self: A) => boolean\n (self: A, options: {\n minimum: A\n maximum: A\n }): boolean\n} =>\n dual(\n 2,\n (self: A, options: {\n minimum: A\n maximum: A\n }): boolean => !lessThan(O)(self, options.minimum) && !greaterThan(O)(self, options.maximum)\n )\n","/**\n * @since 2.0.0\n */\nimport type { Either } from \"./Either.js\"\nimport * as Equal from \"./Equal.js\"\nimport * as Equivalence from \"./Equivalence.js\"\nimport type { LazyArg } from \"./Function.js\"\nimport { constNull, constUndefined, dual, identity, isFunction } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\nimport type { Inspectable } from \"./Inspectable.js\"\nimport * as doNotation from \"./internal/doNotation.js\"\nimport * as either from \"./internal/either.js\"\nimport * as option from \"./internal/option.js\"\nimport type { Order } from \"./Order.js\"\nimport * as order from \"./Order.js\"\nimport type { Pipeable } from \"./Pipeable.js\"\nimport type { Predicate, Refinement } from \"./Predicate.js\"\nimport type { Covariant, NoInfer, NotFunction } from \"./Types.js\"\nimport type * as Unify from \"./Unify.js\"\nimport * as Gen from \"./Utils.js\"\n\n/**\n * The `Option` data type represents optional values. An `Option<A>` can either\n * be `Some<A>`, containing a value of type `A`, or `None`, representing the\n * absence of a value.\n *\n * **When to Use**\n *\n * You can use `Option` in scenarios like:\n *\n * - Using it for initial values\n * - Returning values from functions that are not defined for all possible\n * inputs (referred to as “partial functions”)\n * - Managing optional fields in data structures\n * - Handling optional function arguments\n *\n * @category Models\n * @since 2.0.0\n */\nexport type Option<A> = None<A> | Some<A>\n\n/**\n * @category Symbols\n * @since 2.0.0\n */\nexport const TypeId: unique symbol = Symbol.for(\"effect/Option\")\n\n/**\n * @category Symbols\n * @since 2.0.0\n */\nexport type TypeId = typeof TypeId\n\n/**\n * @category Models\n * @since 2.0.0\n */\nexport interface None<out A> extends Pipeable, Inspectable {\n readonly _tag: \"None\"\n readonly _op: \"None\"\n readonly [TypeId]: {\n readonly _A: Covariant<A>\n }\n [Unify.typeSymbol]?: unknown\n [Unify.unifySymbol]?: OptionUnify<this>\n [Unify.ignoreSymbol]?: OptionUnifyIgnore\n}\n\n/**\n * @category Models\n * @since 2.0.0\n */\nexport interface Some<out A> extends Pipeable, Inspectable {\n readonly _tag: \"Some\"\n readonly _op: \"Some\"\n readonly value: A\n readonly [TypeId]: {\n readonly _A: Covariant<A>\n }\n [Unify.typeSymbol]?: unknown\n [Unify.unifySymbol]?: OptionUnify<this>\n [Unify.ignoreSymbol]?: OptionUnifyIgnore\n}\n\n/**\n * @category Models\n * @since 2.0.0\n */\nexport interface OptionUnify<A extends { [Unify.typeSymbol]?: any }> {\n Option?: () => A[Unify.typeSymbol] extends Option<infer A0> | infer _ ? Option<A0> : never\n}\n\n/**\n * @since 2.0.0\n */\nexport declare namespace Option {\n /**\n * Extracts the type of the value contained in an `Option`.\n *\n * **Example** (Getting the Value Type of an Option)\n *\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Declare an Option holding a string\n * declare const myOption: Option.Option<string>\n *\n * // Extract the type of the value within the Option\n * //\n * // ┌─── string\n * // ▼\n * type MyType = Option.Option.Value<typeof myOption>\n * ```\n *\n * @since 2.0.0\n * @category Type-level Utils\n */\n export type Value<T extends Option<any>> = [T] extends [Option<infer _A>] ? _A : never\n}\n\n/**\n * @category Models\n * @since 2.0.0\n */\nexport interface OptionUnifyIgnore {}\n\n/**\n * @category Type Lambdas\n * @since 2.0.0\n */\nexport interface OptionTypeLambda extends TypeLambda {\n readonly type: Option<this[\"Target\"]>\n}\n\n/**\n * Represents the absence of a value by creating an empty `Option`.\n *\n * `Option.none` returns an `Option<never>`, which is a subtype of `Option<A>`.\n * This means you can use it in place of any `Option<A>` regardless of the type\n * `A`.\n *\n * **Example** (Creating an Option with No Value)\n *\n * ```ts\n * import { Option } from \"effect\"\n *\n * // An Option holding no value\n * //\n * // ┌─── Option<never>\n * // ▼\n * const noValue = Option.none()\n *\n * console.log(noValue)\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @see {@link some} for the opposite operation.\n *\n * @category Constructors\n * @since 2.0.0\n */\nexport const none = <A = never>(): Option<A> => option.none\n\n/**\n * Wraps the given value into an `Option` to represent its presence.\n *\n * **Example** (Creating an Option with a Value)\n *\n * ```ts\n * import { Option } from \"effect\"\n *\n * // An Option holding the number 1\n * //\n * // ┌─── Option<number>\n * // ▼\n * const value = Option.some(1)\n *\n * console.log(value)\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n * ```\n *\n * @see {@link none} for the opposite operation.\n *\n * @category Constructors\n * @since 2.0.0\n */\nexport const some: <A>(value: A) => Option<A> = option.some\n\n/**\n * Determines whether the given value is an `Option`.\n *\n * **Details**\n *\n * This function checks if a value is an instance of `Option`. It returns `true`\n * if the value is either `Option.some` or `Option.none`, and `false` otherwise.\n * This is particularly useful when working with unknown values or when you need\n * to ensure type safety in your code.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.isOption(Option.some(1)))\n * // Output: true\n *\n * console.log(Option.isOption(Option.none()))\n * // Output: true\n *\n * console.log(Option.isOption({}))\n * // Output: false\n * ```\n *\n * @category Guards\n * @since 2.0.0\n */\nexport const isOption: (input: unknown) => input is Option<unknown> = option.isOption\n\n/**\n * Checks whether an `Option` represents the absence of a value (`None`).\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.isNone(Option.some(1)))\n * // Output: false\n *\n * console.log(Option.isNone(Option.none()))\n * // Output: true\n * ```\n *\n * @see {@link isSome} for the opposite check.\n *\n * @category Guards\n * @since 2.0.0\n */\nexport const isNone: <A>(self: Option<A>) => self is None<A> = option.isNone\n\n/**\n * Checks whether an `Option` contains a value (`Some`).\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.isSome(Option.some(1)))\n * // Output: true\n *\n * console.log(Option.isSome(Option.none()))\n * // Output: false\n * ```\n *\n * @see {@link isNone} for the opposite check.\n *\n * @category Guards\n * @since 2.0.0\n */\nexport const isSome: <A>(self: Option<A>) => self is Some<A> = option.isSome\n\n/**\n * Performs pattern matching on an `Option` to handle both `Some` and `None`\n * cases.\n *\n * **Details**\n *\n * This function allows you to match against an `Option` and handle both\n * scenarios: when the `Option` is `None` (i.e., contains no value), and when\n * the `Option` is `Some` (i.e., contains a value). It executes one of the\n * provided functions based on the case:\n *\n * - If the `Option` is `None`, the `onNone` function is executed and its result\n * is returned.\n * - If the `Option` is `Some`, the `onSome` function is executed with the\n * contained value, and its result is returned.\n *\n * This function provides a concise and functional way to handle optional values\n * without resorting to `if` or manual checks, making your code more declarative\n * and readable.\n *\n * **Example** (Pattern Matching with Option)\n *\n * ```ts\n * import { Option } from \"effect\"\n *\n * const foo = Option.some(1)\n *\n * const message = Option.match(foo, {\n * onNone: () => \"Option is empty\",\n * onSome: (value) => `Option has a value: ${value}`\n * })\n *\n * console.log(message)\n * // Output: \"Option has a value: 1\"\n * ```\n *\n * @category Pattern matching\n * @since 2.0.0\n */\nexport const match: {\n /**\n * Performs pattern matching on an `Option` to handle both `Some` and `None`\n * cases.\n *\n * **Details**\n *\n * This function allows you to match against an `Option` and handle both\n * scenarios: when the `Option` is `None` (i.e., contains no value), and when\n * the `Option` is `Some` (i.e., contains a value). It executes one of the\n * provided functions based on the case:\n *\n * - If the `Option` is `None`, the `onNone` function is executed and its result\n * is returned.\n * - If the `Option` is `Some`, the `onSome` function is executed with the\n * contained value, and its result is returned.\n *\n * This function provides a concise and functional way to handle optional values\n * without resorting to `if` or manual checks, making your code more declarative\n * and readable.\n *\n * **Example** (Pattern Matching with Option)\n *\n * ```ts\n * import { Option } from \"effect\"\n *\n * const foo = Option.some(1)\n *\n * const message = Option.match(foo, {\n * onNone: () => \"Option is empty\",\n * onSome: (value) => `Option has a value: ${value}`\n * })\n *\n * console.log(message)\n * // Output: \"Option has a value: 1\"\n * ```\n *\n * @category Pattern matching\n * @since 2.0.0\n */\n <B, A, C = B>(\n options: {\n readonly onNone: LazyArg<B>\n readonly onSome: (a: A) => C\n }\n ): (self: Option<A>) => B | C\n /**\n * Performs pattern matching on an `Option` to handle both `Some` and `None`\n * cases.\n *\n * **Details**\n *\n * This function allows you to match against an `Option` and handle both\n * scenarios: when the `Option` is `None` (i.e., contains no value), and when\n * the `Option` is `Some` (i.e., contains a value). It executes one of the\n * provided functions based on the case:\n *\n * - If the `Option` is `None`, the `onNone` function is executed and its result\n * is returned.\n * - If the `Option` is `Some`, the `onSome` function is executed with the\n * contained value, and its result is returned.\n *\n * This function provides a concise and functional way to handle optional values\n * without resorting to `if` or manual checks, making your code more declarative\n * and readable.\n *\n * **Example** (Pattern Matching with Option)\n *\n * ```ts\n * import { Option } from \"effect\"\n *\n * const foo = Option.some(1)\n *\n * const message = Option.match(foo, {\n * onNone: () => \"Option is empty\",\n * onSome: (value) => `Option has a value: ${value}`\n * })\n *\n * console.log(message)\n * // Output: \"Option has a value: 1\"\n * ```\n *\n * @category Pattern matching\n * @since 2.0.0\n */\n <A, B, C = B>(\n self: Option<A>,\n options: {\n readonly onNone: LazyArg<B>\n readonly onSome: (a: A) => C\n }\n ): B | C\n} = dual(\n 2,\n <A, B, C = B>(self: Option<A>, { onNone, onSome }: {\n readonly onNone: LazyArg<B>\n readonly onSome: (a: A) => C\n }): B | C => isNone(self) ? onNone() : onSome(self.value)\n)\n\n/**\n * Converts an `Option`-returning function into a type guard.\n *\n * **Details**\n *\n * This function transforms a function that returns an `Option` into a type\n * guard, ensuring type safety when validating or narrowing types. The returned\n * type guard function checks whether the input satisfies the condition defined\n * in the original `Option`-returning function.\n *\n * If the original function returns `Option.some`, the type guard evaluates to\n * `true`, confirming the input is of the desired type. If the function returns\n * `Option.none`, the type guard evaluates to `false`.\n *\n * This utility is especially useful for validating types in union types,\n * filtering arrays, or ensuring safe handling of specific subtypes.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * type MyData = string | number\n *\n * const parseString = (data: MyData): Option.Option<string> =>\n * typeof data === \"string\" ? Option.some(data) : Option.none()\n *\n * // ┌─── (a: MyData) => a is string\n * // ▼\n * const isString = Option.toRefinement(parseString)\n *\n * console.log(isString(\"a\"))\n * // Output: true\n *\n * console.log(isString(1))\n * // Output: false\n * ```\n *\n * @category Conversions\n * @since 2.0.0\n */\nexport const toRefinement = <A, B extends A>(f: (a: A) => Option<B>): (a: A) => a is B => (a: A): a is B => isSome(f(a))\n\n/**\n * Converts an `Iterable` into an `Option`, wrapping the first element if it\n * exists.\n *\n * **Details**\n *\n * This function takes an `Iterable` (e.g., an array, a generator, or any object\n * implementing the `Iterable` interface) and returns an `Option` based on its\n * content:\n *\n * - If the `Iterable` contains at least one element, the first element is\n * wrapped in a `Some` and returned.\n * - If the `Iterable` is empty, `None` is returned, representing the absence of\n * a value.\n *\n * This utility is useful for safely handling collections that might be empty,\n * ensuring you explicitly handle both cases where a value exists or doesn't.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.fromIterable([1, 2, 3]))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(Option.fromIterable([]))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Constructors\n * @since 2.0.0\n */\nexport const fromIterable = <A>(collection: Iterable<A>): Option<A> => {\n for (const a of collection) {\n return some(a)\n }\n return none()\n}\n\n/**\n * Converts an `Either` into an `Option` by discarding the error and extracting\n * the right value.\n *\n * **Details**\n *\n * This function takes an `Either` and returns an `Option` based on its value:\n *\n * - If the `Either` is a `Right`, its value is wrapped in a `Some` and\n * returned.\n * - If the `Either` is a `Left`, the error is discarded, and `None` is\n * returned.\n *\n * This is particularly useful when you only care about the success case\n * (`Right`) of an `Either` and want to handle the result using `Option`. By\n * using this function, you can convert `Either` into a simpler structure for\n * cases where error handling is not required.\n *\n * @example\n * ```ts\n * import { Either, Option } from \"effect\"\n *\n * console.log(Option.getRight(Either.right(\"ok\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'ok' }\n *\n * console.log(Option.getRight(Either.left(\"err\")))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @see {@link getLeft} for the opposite operation.\n *\n * @category Conversions\n * @since 2.0.0\n */\nexport const getRight: <R, L>(self: Either<R, L>) => Option<R> = either.getRight\n\n/**\n * Converts an `Either` into an `Option` by discarding the right value and\n * extracting the left value.\n *\n * **Details**\n *\n * This function transforms an `Either` into an `Option` as follows:\n *\n * - If the `Either` is a `Left`, its value is wrapped in a `Some` and returned.\n * - If the `Either` is a `Right`, the value is discarded, and `None` is\n * returned.\n *\n * This utility is useful when you only care about the error case (`Left`) of an\n * `Either` and want to handle it as an `Option`. By discarding the right value,\n * it simplifies error-focused workflows.\n *\n * @example\n * ```ts\n * import { Either, Option } from \"effect\"\n *\n * console.log(Option.getLeft(Either.right(\"ok\")))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(Option.getLeft(Either.left(\"err\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'err' }\n * ```\n *\n * @see {@link getRight} for the opposite operation.\n *\n * @category Conversions\n * @since 2.0.0\n */\nexport const getLeft: <R, L>(self: Either<R, L>) => Option<L> = either.getLeft\n\n/**\n * Returns the value contained in the `Option` if it is `Some`, otherwise\n * evaluates and returns the result of `onNone`.\n *\n * **Details**\n *\n * This function allows you to provide a fallback value or computation for when\n * an `Option` is `None`. If the `Option` contains a value (`Some`), that value\n * is returned. If it is empty (`None`), the `onNone` function is executed, and\n * its result is returned instead.\n *\n * This utility is helpful for safely handling `Option` values by ensuring you\n * always receive a meaningful result, whether or not the `Option` contains a\n * value. It is particularly useful for providing default values or alternative\n * logic when working with optional values.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.some(1).pipe(Option.getOrElse(() => 0)))\n * // Output: 1\n *\n * console.log(Option.none().pipe(Option.getOrElse(() => 0)))\n * // Output: 0\n * ```\n *\n * @see {@link getOrNull} for a version that returns `null` instead of executing a function.\n * @see {@link getOrUndefined} for a version that returns `undefined` instead of executing a function.\n *\n * @category Getters\n * @since 2.0.0\n */\nexport const getOrElse: {\n /**\n * Returns the value contained in the `Option` if it is `Some`, otherwise\n * evaluates and returns the result of `onNone`.\n *\n * **Details**\n *\n * This function allows you to provide a fallback value or computation for when\n * an `Option` is `None`. If the `Option` contains a value (`Some`), that value\n * is returned. If it is empty (`None`), the `onNone` function is executed, and\n * its result is returned instead.\n *\n * This utility is helpful for safely handling `Option` values by ensuring you\n * always receive a meaningful result, whether or not the `Option` contains a\n * value. It is particularly useful for providing default values or alternative\n * logic when working with optional values.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.some(1).pipe(Option.getOrElse(() => 0)))\n * // Output: 1\n *\n * console.log(Option.none().pipe(Option.getOrElse(() => 0)))\n * // Output: 0\n * ```\n *\n * @see {@link getOrNull} for a version that returns `null` instead of executing a function.\n * @see {@link getOrUndefined} for a version that returns `undefined` instead of executing a function.\n *\n * @category Getters\n * @since 2.0.0\n */\n <B>(onNone: LazyArg<B>): <A>(self: Option<A>) => B | A\n /**\n * Returns the value contained in the `Option` if it is `Some`, otherwise\n * evaluates and returns the result of `onNone`.\n *\n * **Details**\n *\n * This function allows you to provide a fallback value or computation for when\n * an `Option` is `None`. If the `Option` contains a value (`Some`), that value\n * is returned. If it is empty (`None`), the `onNone` function is executed, and\n * its result is returned instead.\n *\n * This utility is helpful for safely handling `Option` values by ensuring you\n * always receive a meaningful result, whether or not the `Option` contains a\n * value. It is particularly useful for providing default values or alternative\n * logic when working with optional values.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.some(1).pipe(Option.getOrElse(() => 0)))\n * // Output: 1\n *\n * console.log(Option.none().pipe(Option.getOrElse(() => 0)))\n * // Output: 0\n * ```\n *\n * @see {@link getOrNull} for a version that returns `null` instead of executing a function.\n * @see {@link getOrUndefined} for a version that returns `undefined` instead of executing a function.\n *\n * @category Getters\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, onNone: LazyArg<B>): A | B\n} = dual(\n 2,\n <A, B>(self: Option<A>, onNone: LazyArg<B>): A | B => isNone(self) ? onNone() : self.value\n)\n\n/**\n * Returns the provided `Option` `that` if the current `Option` (`self`) is\n * `None`; otherwise, it returns `self`.\n *\n * **Details**\n *\n * This function provides a fallback mechanism for `Option` values. If the\n * current `Option` is `None` (i.e., it contains no value), the `that` function\n * is evaluated, and its resulting `Option` is returned. If the current `Option`\n * is `Some` (i.e., it contains a value), the original `Option` is returned\n * unchanged.\n *\n * This is particularly useful for chaining fallback values or computations,\n * allowing you to provide alternative `Option` values when the first one is\n * empty.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.none().pipe(Option.orElse(() => Option.none())))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(Option.some(\"a\").pipe(Option.orElse(() => Option.none())))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n *\n * console.log(Option.none().pipe(Option.orElse(() => Option.some(\"b\"))))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'b' }\n *\n * console.log(Option.some(\"a\").pipe(Option.orElse(() => Option.some(\"b\"))))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n * ```\n *\n * @category Error handling\n * @since 2.0.0\n */\nexport const orElse: {\n /**\n * Returns the provided `Option` `that` if the current `Option` (`self`) is\n * `None`; otherwise, it returns `self`.\n *\n * **Details**\n *\n * This function provides a fallback mechanism for `Option` values. If the\n * current `Option` is `None` (i.e., it contains no value), the `that` function\n * is evaluated, and its resulting `Option` is returned. If the current `Option`\n * is `Some` (i.e., it contains a value), the original `Option` is returned\n * unchanged.\n *\n * This is particularly useful for chaining fallback values or computations,\n * allowing you to provide alternative `Option` values when the first one is\n * empty.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.none().pipe(Option.orElse(() => Option.none())))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(Option.some(\"a\").pipe(Option.orElse(() => Option.none())))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n *\n * console.log(Option.none().pipe(Option.orElse(() => Option.some(\"b\"))))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'b' }\n *\n * console.log(Option.some(\"a\").pipe(Option.orElse(() => Option.some(\"b\"))))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n * ```\n *\n * @category Error handling\n * @since 2.0.0\n */\n <B>(that: LazyArg<Option<B>>): <A>(self: Option<A>) => Option<B | A>\n /**\n * Returns the provided `Option` `that` if the current `Option` (`self`) is\n * `None`; otherwise, it returns `self`.\n *\n * **Details**\n *\n * This function provides a fallback mechanism for `Option` values. If the\n * current `Option` is `None` (i.e., it contains no value), the `that` function\n * is evaluated, and its resulting `Option` is returned. If the current `Option`\n * is `Some` (i.e., it contains a value), the original `Option` is returned\n * unchanged.\n *\n * This is particularly useful for chaining fallback values or computations,\n * allowing you to provide alternative `Option` values when the first one is\n * empty.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.none().pipe(Option.orElse(() => Option.none())))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(Option.some(\"a\").pipe(Option.orElse(() => Option.none())))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n *\n * console.log(Option.none().pipe(Option.orElse(() => Option.some(\"b\"))))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'b' }\n *\n * console.log(Option.some(\"a\").pipe(Option.orElse(() => Option.some(\"b\"))))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n * ```\n *\n * @category Error handling\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<A | B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<A | B> => isNone(self) ? that() : self\n)\n\n/**\n * Returns the provided default value wrapped in `Some` if the current `Option`\n * (`self`) is `None`; otherwise, returns `self`.\n *\n * **Details**\n *\n * This function provides a way to supply a default value for cases where an\n * `Option` is `None`. If the current `Option` is empty (`None`), the `onNone`\n * function is executed to compute the default value, which is then wrapped in a\n * `Some`. If the current `Option` contains a value (`Some`), it is returned as\n * is.\n *\n * This is particularly useful for handling optional values where a fallback\n * default needs to be provided explicitly in case of absence.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.none().pipe(Option.orElseSome(() => \"b\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'b' }\n *\n * console.log(Option.some(\"a\").pipe(Option.orElseSome(() => \"b\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n * ```\n *\n * @category Error handling\n * @since 2.0.0\n */\nexport const orElseSome: {\n /**\n * Returns the provided default value wrapped in `Some` if the current `Option`\n * (`self`) is `None`; otherwise, returns `self`.\n *\n * **Details**\n *\n * This function provides a way to supply a default value for cases where an\n * `Option` is `None`. If the current `Option` is empty (`None`), the `onNone`\n * function is executed to compute the default value, which is then wrapped in a\n * `Some`. If the current `Option` contains a value (`Some`), it is returned as\n * is.\n *\n * This is particularly useful for handling optional values where a fallback\n * default needs to be provided explicitly in case of absence.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.none().pipe(Option.orElseSome(() => \"b\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'b' }\n *\n * console.log(Option.some(\"a\").pipe(Option.orElseSome(() => \"b\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n * ```\n *\n * @category Error handling\n * @since 2.0.0\n */\n <B>(onNone: LazyArg<B>): <A>(self: Option<A>) => Option<B | A>\n /**\n * Returns the provided default value wrapped in `Some` if the current `Option`\n * (`self`) is `None`; otherwise, returns `self`.\n *\n * **Details**\n *\n * This function provides a way to supply a default value for cases where an\n * `Option` is `None`. If the current `Option` is empty (`None`), the `onNone`\n * function is executed to compute the default value, which is then wrapped in a\n * `Some`. If the current `Option` contains a value (`Some`), it is returned as\n * is.\n *\n * This is particularly useful for handling optional values where a fallback\n * default needs to be provided explicitly in case of absence.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.none().pipe(Option.orElseSome(() => \"b\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'b' }\n *\n * console.log(Option.some(\"a\").pipe(Option.orElseSome(() => \"b\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n * ```\n *\n * @category Error handling\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, onNone: LazyArg<B>): Option<A | B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, onNone: LazyArg<B>): Option<A | B> => isNone(self) ? some(onNone()) : self\n)\n\n/**\n * Similar to {@link orElse}, but returns an `Either` wrapped in an `Option` to\n * indicate the source of the value.\n *\n * **Details**\n *\n * This function allows you to provide a fallback `Option` in case the current\n * `Option` (`self`) is `None`. However, unlike `orElse`, it returns the value\n * wrapped in an `Either` object, providing additional information about where\n * the value came from:\n *\n * - If the value is from the fallback `Option` (`that`), it is wrapped in an\n * `Either.right`.\n * - If the value is from the original `Option` (`self`), it is wrapped in an\n * `Either.left`.\n *\n * This is especially useful when you need to differentiate between values\n * originating from the primary `Option` and those coming from the fallback,\n * while still maintaining the `Option`-style handling.\n *\n * @category Error handling\n * @since 2.0.0\n */\nexport const orElseEither: {\n /**\n * Similar to {@link orElse}, but returns an `Either` wrapped in an `Option` to\n * indicate the source of the value.\n *\n * **Details**\n *\n * This function allows you to provide a fallback `Option` in case the current\n * `Option` (`self`) is `None`. However, unlike `orElse`, it returns the value\n * wrapped in an `Either` object, providing additional information about where\n * the value came from:\n *\n * - If the value is from the fallback `Option` (`that`), it is wrapped in an\n * `Either.right`.\n * - If the value is from the original `Option` (`self`), it is wrapped in an\n * `Either.left`.\n *\n * This is especially useful when you need to differentiate between values\n * originating from the primary `Option` and those coming from the fallback,\n * while still maintaining the `Option`-style handling.\n *\n * @category Error handling\n * @since 2.0.0\n */\n <B>(that: LazyArg<Option<B>>): <A>(self: Option<A>) => Option<Either<B, A>>\n /**\n * Similar to {@link orElse}, but returns an `Either` wrapped in an `Option` to\n * indicate the source of the value.\n *\n * **Details**\n *\n * This function allows you to provide a fallback `Option` in case the current\n * `Option` (`self`) is `None`. However, unlike `orElse`, it returns the value\n * wrapped in an `Either` object, providing additional information about where\n * the value came from:\n *\n * - If the value is from the fallback `Option` (`that`), it is wrapped in an\n * `Either.right`.\n * - If the value is from the original `Option` (`self`), it is wrapped in an\n * `Either.left`.\n *\n * This is especially useful when you need to differentiate between values\n * originating from the primary `Option` and those coming from the fallback,\n * while still maintaining the `Option`-style handling.\n *\n * @category Error handling\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<Either<B, A>>\n} = dual(\n 2,\n <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<Either<B, A>> =>\n isNone(self) ? map(that(), either.right) : map(self, either.left)\n)\n\n/**\n * Returns the first `Some` value found in an `Iterable` collection of\n * `Option`s, or `None` if no `Some` is found.\n *\n * **Details**\n *\n * This function iterates over a collection of `Option` values and returns the\n * first `Some` it encounters. If the collection contains only `None` values,\n * the result will also be `None`. This utility is useful for efficiently\n * finding the first valid value in a sequence of potentially empty or invalid\n * options.\n *\n * The iteration stops as soon as a `Some` is found, making this function\n * efficient for large collections.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.firstSomeOf([\n * Option.none(),\n * Option.some(1),\n * Option.some(2)\n * ]))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n * ```\n *\n * @category Error handling\n * @since 2.0.0\n */\nexport const firstSomeOf = <T, C extends Iterable<Option<T>> = Iterable<Option<T>>>(\n collection: C\n): [C] extends [Iterable<Option<infer A>>] ? Option<A> : never => {\n let out: Option<unknown> = none()\n for (out of collection) {\n if (isSome(out)) {\n return out as any\n }\n }\n return out as any\n}\n\n/**\n * Converts a nullable value into an `Option`. Returns `None` if the value is\n * `null` or `undefined`, otherwise wraps the value in a `Some`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.fromNullable(undefined))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(Option.fromNullable(null))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(Option.fromNullable(1))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n * ```\n *\n * @category Conversions\n * @since 2.0.0\n */\nexport const fromNullable = <A>(\n nullableValue: A\n): Option<NonNullable<A>> => (nullableValue == null ? none() : some(nullableValue as NonNullable<A>))\n\n/**\n * Lifts a function that returns `null` or `undefined` into the `Option`\n * context.\n *\n * **Details**\n *\n * This function takes a function `f` that might return `null` or `undefined`\n * and transforms it into a function that returns an `Option`. The resulting\n * function will return:\n * - `Some` if the original function produces a non-null, non-undefined value.\n * - `None` if the original function produces `null` or `undefined`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const parse = (s: string): number | undefined => {\n * const n = parseFloat(s)\n * return isNaN(n) ? undefined : n\n * }\n *\n * const parseOption = Option.liftNullable(parse)\n *\n * console.log(parseOption(\"1\"))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(parseOption(\"not a number\"))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Conversions\n * @since 2.0.0\n */\nexport const liftNullable = <A extends ReadonlyArray<unknown>, B>(\n f: (...a: A) => B | null | undefined\n): (...a: A) => Option<NonNullable<B>> =>\n(...a) => fromNullable(f(...a))\n\n/**\n * Returns the value contained in the `Option` if it is `Some`; otherwise,\n * returns `null`.\n *\n * **Details**\n *\n * This function provides a way to extract the value of an `Option` while\n * falling back to `null` if the `Option` is `None`.\n *\n * It is particularly useful in scenarios where `null` is an acceptable\n * placeholder for the absence of a value, such as when interacting with APIs or\n * systems that use `null` as a default for missing values.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.getOrNull(Option.some(1)))\n * // Output: 1\n *\n * console.log(Option.getOrNull(Option.none()))\n * // Output: null\n * ```\n *\n * @category Getters\n * @since 2.0.0\n */\nexport const getOrNull: <A>(self: Option<A>) => A | null = getOrElse(constNull)\n\n/**\n * Returns the value contained in the `Option` if it is `Some`; otherwise,\n * returns `undefined`.\n *\n * **Details**\n *\n * This function provides a way to extract the value of an `Option` while\n * falling back to `undefined` if the `Option` is `None`.\n *\n * It is particularly useful in scenarios where `undefined` is an acceptable\n * placeholder for the absence of a value, such as when interacting with APIs or\n * systems that use `undefined` as a default for missing values.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.getOrUndefined(Option.some(1)))\n * // Output: 1\n *\n * console.log(Option.getOrUndefined(Option.none()))\n * // Output: undefined\n * ```\n *\n * @category Getters\n * @since 2.0.0\n */\nexport const getOrUndefined: <A>(self: Option<A>) => A | undefined = getOrElse(constUndefined)\n\n/**\n * Lifts a function that throws exceptions into a function that returns an\n * `Option`.\n *\n * **Details**\n *\n * This utility function takes a function `f` that might throw an exception and\n * transforms it into a safer function that returns an `Option`. If the original\n * function executes successfully, the result is wrapped in a `Some`. If an\n * exception is thrown, the result is `None`, allowing the developer to handle\n * errors in a functional, type-safe way.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const parse = Option.liftThrowable(JSON.parse)\n *\n * console.log(parse(\"1\"))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(parse(\"\"))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Conversions\n * @since 2.0.0\n */\nexport const liftThrowable = <A extends ReadonlyArray<unknown>, B>(\n f: (...a: A) => B\n): (...a: A) => Option<B> =>\n(...a) => {\n try {\n return some(f(...a))\n } catch {\n return none()\n }\n}\n\n/**\n * Extracts the value of an `Option` or throws an error if the `Option` is\n * `None`, using a custom error factory.\n *\n * **Details**\n *\n * This function allows you to extract the value of an `Option` when it is\n * `Some`. If the `Option` is `None`, it throws an error generated by the\n * provided `onNone` function. This utility is particularly useful when you need\n * a fail-fast behavior for empty `Option` values and want to provide a custom\n * error message or object.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Option.getOrThrowWith(Option.some(1), () => new Error('Unexpected None')),\n * 1\n * )\n * assert.throws(() => Option.getOrThrowWith(Option.none(), () => new Error('Unexpected None')))\n * ```\n *\n * @see {@link getOrThrow} for a version that throws a default error.\n *\n * @category Conversions\n * @since 2.0.0\n */\nexport const getOrThrowWith: {\n /**\n * Extracts the value of an `Option` or throws an error if the `Option` is\n * `None`, using a custom error factory.\n *\n * **Details**\n *\n * This function allows you to extract the value of an `Option` when it is\n * `Some`. If the `Option` is `None`, it throws an error generated by the\n * provided `onNone` function. This utility is particularly useful when you need\n * a fail-fast behavior for empty `Option` values and want to provide a custom\n * error message or object.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Option.getOrThrowWith(Option.some(1), () => new Error('Unexpected None')),\n * 1\n * )\n * assert.throws(() => Option.getOrThrowWith(Option.none(), () => new Error('Unexpected None')))\n * ```\n *\n * @see {@link getOrThrow} for a version that throws a default error.\n *\n * @category Conversions\n * @since 2.0.0\n */\n (onNone: () => unknown): <A>(self: Option<A>) => A\n /**\n * Extracts the value of an `Option` or throws an error if the `Option` is\n * `None`, using a custom error factory.\n *\n * **Details**\n *\n * This function allows you to extract the value of an `Option` when it is\n * `Some`. If the `Option` is `None`, it throws an error generated by the\n * provided `onNone` function. This utility is particularly useful when you need\n * a fail-fast behavior for empty `Option` values and want to provide a custom\n * error message or object.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Option.getOrThrowWith(Option.some(1), () => new Error('Unexpected None')),\n * 1\n * )\n * assert.throws(() => Option.getOrThrowWith(Option.none(), () => new Error('Unexpected None')))\n * ```\n *\n * @see {@link getOrThrow} for a version that throws a default error.\n *\n * @category Conversions\n * @since 2.0.0\n */\n <A>(self: Option<A>, onNone: () => unknown): A\n} = dual(2, <A>(self: Option<A>, onNone: () => unknown): A => {\n if (isSome(self)) {\n return self.value\n }\n throw onNone()\n})\n\n/**\n * Extracts the value of an `Option` or throws a default error if the `Option`\n * is `None`.\n *\n * **Details**\n *\n * This function extracts the value from an `Option` if it is `Some`. If the\n * `Option` is `None`, it throws a default error. It is useful for fail-fast\n * scenarios where the absence of a value is treated as an exceptional case and\n * a default error is sufficient.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.getOrThrow(Option.some(1)), 1)\n * assert.throws(() => Option.getOrThrow(Option.none()))\n * ```\n *\n * @see {@link getOrThrowWith} for a version that allows you to provide a custom error.\n *\n * @category Conversions\n * @since 2.0.0\n */\nexport const getOrThrow: <A>(self: Option<A>) => A = getOrThrowWith(() => new Error(\"getOrThrow called on a None\"))\n\n/**\n * Transforms the value inside a `Some` to a new value using the provided\n * function, while leaving `None` unchanged.\n *\n * **Details**\n *\n * This function applies a mapping function `f` to the value inside an `Option`\n * if it is a `Some`. If the `Option` is `None`, it remains unchanged. The\n * result is a new `Option` with the transformed value (if it was a `Some`) or\n * still `None`.\n *\n * This utility is particularly useful for chaining transformations in a\n * functional way without needing to manually handle `None` cases.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Mapping over a `Some`\n * const someValue = Option.some(2)\n *\n * console.log(Option.map(someValue, (n) => n * 2))\n * // Output: { _id: 'Option', _tag: 'Some', value: 4 }\n *\n * // Mapping over a `None`\n * const noneValue = Option.none<number>()\n *\n * console.log(Option.map(noneValue, (n) => n * 2))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Mapping\n * @since 2.0.0\n */\nexport const map: {\n /**\n * Transforms the value inside a `Some` to a new value using the provided\n * function, while leaving `None` unchanged.\n *\n * **Details**\n *\n * This function applies a mapping function `f` to the value inside an `Option`\n * if it is a `Some`. If the `Option` is `None`, it remains unchanged. The\n * result is a new `Option` with the transformed value (if it was a `Some`) or\n * still `None`.\n *\n * This utility is particularly useful for chaining transformations in a\n * functional way without needing to manually handle `None` cases.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Mapping over a `Some`\n * const someValue = Option.some(2)\n *\n * console.log(Option.map(someValue, (n) => n * 2))\n * // Output: { _id: 'Option', _tag: 'Some', value: 4 }\n *\n * // Mapping over a `None`\n * const noneValue = Option.none<number>()\n *\n * console.log(Option.map(noneValue, (n) => n * 2))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Mapping\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B): (self: Option<A>) => Option<B>\n /**\n * Transforms the value inside a `Some` to a new value using the provided\n * function, while leaving `None` unchanged.\n *\n * **Details**\n *\n * This function applies a mapping function `f` to the value inside an `Option`\n * if it is a `Some`. If the `Option` is `None`, it remains unchanged. The\n * result is a new `Option` with the transformed value (if it was a `Some`) or\n * still `None`.\n *\n * This utility is particularly useful for chaining transformations in a\n * functional way without needing to manually handle `None` cases.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Mapping over a `Some`\n * const someValue = Option.some(2)\n *\n * console.log(Option.map(someValue, (n) => n * 2))\n * // Output: { _id: 'Option', _tag: 'Some', value: 4 }\n *\n * // Mapping over a `None`\n * const noneValue = Option.none<number>()\n *\n * console.log(Option.map(noneValue, (n) => n * 2))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Mapping\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => B): Option<B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => B): Option<B> => isNone(self) ? none() : some(f(self.value))\n)\n\n/**\n * Replaces the value inside a `Some` with the specified constant value, leaving\n * `None` unchanged.\n *\n * **Details**\n *\n * This function transforms an `Option` by replacing the value inside a `Some`\n * with the given constant value `b`. If the `Option` is `None`, it remains\n * unchanged.\n *\n * This is useful when you want to preserve the presence of a value (`Some`) but\n * replace its content with a fixed value.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Replacing the value of a `Some`\n * const someValue = Option.some(42)\n *\n * console.log(Option.as(someValue, \"new value\"))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'new value' }\n *\n * // Replacing a `None` (no effect)\n * const noneValue = Option.none<number>()\n *\n * console.log(Option.as(noneValue, \"new value\"))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Mapping\n * @since 2.0.0\n */\nexport const as: {\n /**\n * Replaces the value inside a `Some` with the specified constant value, leaving\n * `None` unchanged.\n *\n * **Details**\n *\n * This function transforms an `Option` by replacing the value inside a `Some`\n * with the given constant value `b`. If the `Option` is `None`, it remains\n * unchanged.\n *\n * This is useful when you want to preserve the presence of a value (`Some`) but\n * replace its content with a fixed value.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Replacing the value of a `Some`\n * const someValue = Option.some(42)\n *\n * console.log(Option.as(someValue, \"new value\"))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'new value' }\n *\n * // Replacing a `None` (no effect)\n * const noneValue = Option.none<number>()\n *\n * console.log(Option.as(noneValue, \"new value\"))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Mapping\n * @since 2.0.0\n */\n <B>(b: B): <X>(self: Option<X>) => Option<B>\n /**\n * Replaces the value inside a `Some` with the specified constant value, leaving\n * `None` unchanged.\n *\n * **Details**\n *\n * This function transforms an `Option` by replacing the value inside a `Some`\n * with the given constant value `b`. If the `Option` is `None`, it remains\n * unchanged.\n *\n * This is useful when you want to preserve the presence of a value (`Some`) but\n * replace its content with a fixed value.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Replacing the value of a `Some`\n * const someValue = Option.some(42)\n *\n * console.log(Option.as(someValue, \"new value\"))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'new value' }\n *\n * // Replacing a `None` (no effect)\n * const noneValue = Option.none<number>()\n *\n * console.log(Option.as(noneValue, \"new value\"))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Mapping\n * @since 2.0.0\n */\n <X, B>(self: Option<X>, b: B): Option<B>\n} = dual(2, <X, B>(self: Option<X>, b: B): Option<B> => map(self, () => b))\n\n/**\n * Replaces the value inside a `Some` with the constant value `void`, leaving\n * `None` unchanged.\n *\n * **Details**\n *\n * This function transforms an `Option` by replacing the value inside a `Some`\n * with `void`. If the `Option` is `None`, it remains unchanged.\n *\n * This is particularly useful in scenarios where the presence or absence of a\n * value is significant, but the actual content of the value is irrelevant.\n *\n * @category Mapping\n * @since 2.0.0\n */\nexport const asVoid: <_>(self: Option<_>) => Option<void> = as(undefined)\n\nconst void_: Option<void> = some(undefined)\nexport {\n /**\n * @since 2.0.0\n */\n void_ as void\n}\n\n/**\n * Applies a function to the value of a `Some` and flattens the resulting\n * `Option`. If the input is `None`, it remains `None`.\n *\n * **Details**\n *\n * This function allows you to chain computations that return `Option` values.\n * If the input `Option` is `Some`, the provided function `f` is applied to the\n * contained value, and the resulting `Option` is returned. If the input is\n * `None`, the function is not applied, and the result remains `None`.\n *\n * This utility is particularly useful for sequencing operations that may fail\n * or produce optional results, enabling clean and concise workflows for\n * handling such cases.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * interface Address {\n * readonly city: string\n * readonly street: Option.Option<string>\n * }\n *\n * interface User {\n * readonly id: number\n * readonly username: string\n * readonly email: Option.Option<string>\n * readonly address: Option.Option<Address>\n * }\n *\n * const user: User = {\n * id: 1,\n * username: \"john_doe\",\n * email: Option.some(\"john.doe@example.com\"),\n * address: Option.some({\n * city: \"New York\",\n * street: Option.some(\"123 Main St\")\n * })\n * }\n *\n * // Use flatMap to extract the street value\n * const street = user.address.pipe(\n * Option.flatMap((address) => address.street)\n * )\n *\n * console.log(street)\n * // Output: { _id: 'Option', _tag: 'Some', value: '123 Main St' }\n * ```\n *\n * @category Sequencing\n * @since 2.0.0\n */\nexport const flatMap: {\n /**\n * Applies a function to the value of a `Some` and flattens the resulting\n * `Option`. If the input is `None`, it remains `None`.\n *\n * **Details**\n *\n * This function allows you to chain computations that return `Option` values.\n * If the input `Option` is `Some`, the provided function `f` is applied to the\n * contained value, and the resulting `Option` is returned. If the input is\n * `None`, the function is not applied, and the result remains `None`.\n *\n * This utility is particularly useful for sequencing operations that may fail\n * or produce optional results, enabling clean and concise workflows for\n * handling such cases.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * interface Address {\n * readonly city: string\n * readonly street: Option.Option<string>\n * }\n *\n * interface User {\n * readonly id: number\n * readonly username: string\n * readonly email: Option.Option<string>\n * readonly address: Option.Option<Address>\n * }\n *\n * const user: User = {\n * id: 1,\n * username: \"john_doe\",\n * email: Option.some(\"john.doe@example.com\"),\n * address: Option.some({\n * city: \"New York\",\n * street: Option.some(\"123 Main St\")\n * })\n * }\n *\n * // Use flatMap to extract the street value\n * const street = user.address.pipe(\n * Option.flatMap((address) => address.street)\n * )\n *\n * console.log(street)\n * // Output: { _id: 'Option', _tag: 'Some', value: '123 Main St' }\n * ```\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => Option<B>): (self: Option<A>) => Option<B>\n /**\n * Applies a function to the value of a `Some` and flattens the resulting\n * `Option`. If the input is `None`, it remains `None`.\n *\n * **Details**\n *\n * This function allows you to chain computations that return `Option` values.\n * If the input `Option` is `Some`, the provided function `f` is applied to the\n * contained value, and the resulting `Option` is returned. If the input is\n * `None`, the function is not applied, and the result remains `None`.\n *\n * This utility is particularly useful for sequencing operations that may fail\n * or produce optional results, enabling clean and concise workflows for\n * handling such cases.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * interface Address {\n * readonly city: string\n * readonly street: Option.Option<string>\n * }\n *\n * interface User {\n * readonly id: number\n * readonly username: string\n * readonly email: Option.Option<string>\n * readonly address: Option.Option<Address>\n * }\n *\n * const user: User = {\n * id: 1,\n * username: \"john_doe\",\n * email: Option.some(\"john.doe@example.com\"),\n * address: Option.some({\n * city: \"New York\",\n * street: Option.some(\"123 Main St\")\n * })\n * }\n *\n * // Use flatMap to extract the street value\n * const street = user.address.pipe(\n * Option.flatMap((address) => address.street)\n * )\n *\n * console.log(street)\n * // Output: { _id: 'Option', _tag: 'Some', value: '123 Main St' }\n * ```\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B> => isNone(self) ? none() : f(self.value)\n)\n\n/**\n * Chains two `Option`s together. The second `Option` can either be a static\n * value or depend on the result of the first `Option`.\n *\n * **Details**\n *\n * This function enables sequencing of two `Option` computations. If the first\n * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can\n * either:\n *\n * - Be a static `Option` value.\n * - Be a function that produces an `Option`, optionally based on the value of\n * the first `Option`.\n *\n * If the first `Option` is `None`, the function skips the evaluation of the\n * second `Option` and directly returns `None`.\n *\n * @category Sequencing\n * @since 2.0.0\n */\nexport const andThen: {\n /**\n * Chains two `Option`s together. The second `Option` can either be a static\n * value or depend on the result of the first `Option`.\n *\n * **Details**\n *\n * This function enables sequencing of two `Option` computations. If the first\n * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can\n * either:\n *\n * - Be a static `Option` value.\n * - Be a function that produces an `Option`, optionally based on the value of\n * the first `Option`.\n *\n * If the first `Option` is `None`, the function skips the evaluation of the\n * second `Option` and directly returns `None`.\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => Option<B>): (self: Option<A>) => Option<B>\n /**\n * Chains two `Option`s together. The second `Option` can either be a static\n * value or depend on the result of the first `Option`.\n *\n * **Details**\n *\n * This function enables sequencing of two `Option` computations. If the first\n * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can\n * either:\n *\n * - Be a static `Option` value.\n * - Be a function that produces an `Option`, optionally based on the value of\n * the first `Option`.\n *\n * If the first `Option` is `None`, the function skips the evaluation of the\n * second `Option` and directly returns `None`.\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <B>(f: Option<B>): <A>(self: Option<A>) => Option<B>\n /**\n * Chains two `Option`s together. The second `Option` can either be a static\n * value or depend on the result of the first `Option`.\n *\n * **Details**\n *\n * This function enables sequencing of two `Option` computations. If the first\n * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can\n * either:\n *\n * - Be a static `Option` value.\n * - Be a function that produces an `Option`, optionally based on the value of\n * the first `Option`.\n *\n * If the first `Option` is `None`, the function skips the evaluation of the\n * second `Option` and directly returns `None`.\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B): (self: Option<A>) => Option<B>\n /**\n * Chains two `Option`s together. The second `Option` can either be a static\n * value or depend on the result of the first `Option`.\n *\n * **Details**\n *\n * This function enables sequencing of two `Option` computations. If the first\n * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can\n * either:\n *\n * - Be a static `Option` value.\n * - Be a function that produces an `Option`, optionally based on the value of\n * the first `Option`.\n *\n * If the first `Option` is `None`, the function skips the evaluation of the\n * second `Option` and directly returns `None`.\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <B>(f: NotFunction<B>): <A>(self: Option<A>) => Option<B>\n /**\n * Chains two `Option`s together. The second `Option` can either be a static\n * value or depend on the result of the first `Option`.\n *\n * **Details**\n *\n * This function enables sequencing of two `Option` computations. If the first\n * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can\n * either:\n *\n * - Be a static `Option` value.\n * - Be a function that produces an `Option`, optionally based on the value of\n * the first `Option`.\n *\n * If the first `Option` is `None`, the function skips the evaluation of the\n * second `Option` and directly returns `None`.\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B>\n /**\n * Chains two `Option`s together. The second `Option` can either be a static\n * value or depend on the result of the first `Option`.\n *\n * **Details**\n *\n * This function enables sequencing of two `Option` computations. If the first\n * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can\n * either:\n *\n * - Be a static `Option` value.\n * - Be a function that produces an `Option`, optionally based on the value of\n * the first `Option`.\n *\n * If the first `Option` is `None`, the function skips the evaluation of the\n * second `Option` and directly returns `None`.\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: Option<B>): Option<B>\n /**\n * Chains two `Option`s together. The second `Option` can either be a static\n * value or depend on the result of the first `Option`.\n *\n * **Details**\n *\n * This function enables sequencing of two `Option` computations. If the first\n * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can\n * either:\n *\n * - Be a static `Option` value.\n * - Be a function that produces an `Option`, optionally based on the value of\n * the first `Option`.\n *\n * If the first `Option` is `None`, the function skips the evaluation of the\n * second `Option` and directly returns `None`.\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => B): Option<B>\n /**\n * Chains two `Option`s together. The second `Option` can either be a static\n * value or depend on the result of the first `Option`.\n *\n * **Details**\n *\n * This function enables sequencing of two `Option` computations. If the first\n * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can\n * either:\n *\n * - Be a static `Option` value.\n * - Be a function that produces an `Option`, optionally based on the value of\n * the first `Option`.\n *\n * If the first `Option` is `None`, the function skips the evaluation of the\n * second `Option` and directly returns `None`.\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: NotFunction<B>): Option<B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => Option<B> | Option<B>): Option<B> =>\n flatMap(self, (a) => {\n const b = isFunction(f) ? f(a) : f\n return isOption(b) ? b : some(b)\n })\n)\n\n/**\n * Combines `flatMap` and `fromNullable`, transforming the value inside a `Some`\n * using a function that may return `null` or `undefined`.\n *\n * **Details**\n *\n * This function applies a transformation function `f` to the value inside a\n * `Some`. The function `f` may return a value, `null`, or `undefined`. If `f`\n * returns a value, it is wrapped in a `Some`. If `f` returns `null` or\n * `undefined`, the result is `None`. If the input `Option` is `None`, the\n * function is not applied, and `None` is returned.\n *\n * This utility is particularly useful when working with deeply nested optional\n * values or chaining computations that may result in `null` or `undefined` at\n * some point.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * interface Employee {\n * company?: {\n * address?: {\n * street?: {\n * name?: string\n * }\n * }\n * }\n * }\n *\n * const employee1: Employee = { company: { address: { street: { name: \"high street\" } } } }\n *\n * // Extracting a deeply nested property\n * console.log(\n * Option.some(employee1)\n * .pipe(Option.flatMapNullable((employee) => employee.company?.address?.street?.name))\n * )\n * // Output: { _id: 'Option', _tag: 'Some', value: 'high street' }\n *\n * const employee2: Employee = { company: { address: { street: {} } } }\n *\n * // Property does not exist\n * console.log(\n * Option.some(employee2)\n * .pipe(Option.flatMapNullable((employee) => employee.company?.address?.street?.name))\n * )\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Sequencing\n * @since 2.0.0\n */\nexport const flatMapNullable: {\n /**\n * Combines `flatMap` and `fromNullable`, transforming the value inside a `Some`\n * using a function that may return `null` or `undefined`.\n *\n * **Details**\n *\n * This function applies a transformation function `f` to the value inside a\n * `Some`. The function `f` may return a value, `null`, or `undefined`. If `f`\n * returns a value, it is wrapped in a `Some`. If `f` returns `null` or\n * `undefined`, the result is `None`. If the input `Option` is `None`, the\n * function is not applied, and `None` is returned.\n *\n * This utility is particularly useful when working with deeply nested optional\n * values or chaining computations that may result in `null` or `undefined` at\n * some point.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * interface Employee {\n * company?: {\n * address?: {\n * street?: {\n * name?: string\n * }\n * }\n * }\n * }\n *\n * const employee1: Employee = { company: { address: { street: { name: \"high street\" } } } }\n *\n * // Extracting a deeply nested property\n * console.log(\n * Option.some(employee1)\n * .pipe(Option.flatMapNullable((employee) => employee.company?.address?.street?.name))\n * )\n * // Output: { _id: 'Option', _tag: 'Some', value: 'high street' }\n *\n * const employee2: Employee = { company: { address: { street: {} } } }\n *\n * // Property does not exist\n * console.log(\n * Option.some(employee2)\n * .pipe(Option.flatMapNullable((employee) => employee.company?.address?.street?.name))\n * )\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B | null | undefined): (self: Option<A>) => Option<NonNullable<B>>\n /**\n * Combines `flatMap` and `fromNullable`, transforming the value inside a `Some`\n * using a function that may return `null` or `undefined`.\n *\n * **Details**\n *\n * This function applies a transformation function `f` to the value inside a\n * `Some`. The function `f` may return a value, `null`, or `undefined`. If `f`\n * returns a value, it is wrapped in a `Some`. If `f` returns `null` or\n * `undefined`, the result is `None`. If the input `Option` is `None`, the\n * function is not applied, and `None` is returned.\n *\n * This utility is particularly useful when working with deeply nested optional\n * values or chaining computations that may result in `null` or `undefined` at\n * some point.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * interface Employee {\n * company?: {\n * address?: {\n * street?: {\n * name?: string\n * }\n * }\n * }\n * }\n *\n * const employee1: Employee = { company: { address: { street: { name: \"high street\" } } } }\n *\n * // Extracting a deeply nested property\n * console.log(\n * Option.some(employee1)\n * .pipe(Option.flatMapNullable((employee) => employee.company?.address?.street?.name))\n * )\n * // Output: { _id: 'Option', _tag: 'Some', value: 'high street' }\n *\n * const employee2: Employee = { company: { address: { street: {} } } }\n *\n * // Property does not exist\n * console.log(\n * Option.some(employee2)\n * .pipe(Option.flatMapNullable((employee) => employee.company?.address?.street?.name))\n * )\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => B | null | undefined): Option<NonNullable<B>>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => B | null | undefined): Option<NonNullable<B>> =>\n isNone(self) ? none() : fromNullable(f(self.value))\n)\n\n/**\n * Flattens an `Option` of `Option` into a single `Option`.\n *\n * **Details**\n *\n * This function takes an `Option` that wraps another `Option` and flattens it\n * into a single `Option`. If the outer `Option` is `Some`, the function\n * extracts the inner `Option`. If the outer `Option` is `None`, the result\n * remains `None`.\n *\n * This is useful for simplifying nested `Option` structures that may arise\n * during functional operations.\n *\n * @category Sequencing\n * @since 2.0.0\n */\nexport const flatten: <A>(self: Option<Option<A>>) => Option<A> = flatMap(identity)\n\n/**\n * Combines two `Option`s, keeping the value from the second `Option` if both\n * are `Some`.\n *\n * **Details**\n *\n * This function takes two `Option`s and returns the second one if the first is\n * `Some`. If the first `Option` is `None`, the result will also be `None`,\n * regardless of the second `Option`. It effectively \"zips\" the two `Option`s\n * while discarding the value from the first `Option`.\n *\n * This is particularly useful when sequencing computations where the result of\n * the first computation is not needed, and you only care about the result of\n * the second computation.\n *\n * @category Zipping\n * @since 2.0.0\n */\nexport const zipRight: {\n /**\n * Combines two `Option`s, keeping the value from the second `Option` if both\n * are `Some`.\n *\n * **Details**\n *\n * This function takes two `Option`s and returns the second one if the first is\n * `Some`. If the first `Option` is `None`, the result will also be `None`,\n * regardless of the second `Option`. It effectively \"zips\" the two `Option`s\n * while discarding the value from the first `Option`.\n *\n * This is particularly useful when sequencing computations where the result of\n * the first computation is not needed, and you only care about the result of\n * the second computation.\n *\n * @category Zipping\n * @since 2.0.0\n */\n <B>(that: Option<B>): <_>(self: Option<_>) => Option<B>\n /**\n * Combines two `Option`s, keeping the value from the second `Option` if both\n * are `Some`.\n *\n * **Details**\n *\n * This function takes two `Option`s and returns the second one if the first is\n * `Some`. If the first `Option` is `None`, the result will also be `None`,\n * regardless of the second `Option`. It effectively \"zips\" the two `Option`s\n * while discarding the value from the first `Option`.\n *\n * This is particularly useful when sequencing computations where the result of\n * the first computation is not needed, and you only care about the result of\n * the second computation.\n *\n * @category Zipping\n * @since 2.0.0\n */\n <X, B>(self: Option<X>, that: Option<B>): Option<B>\n} = dual(2, <X, B>(self: Option<X>, that: Option<B>): Option<B> => flatMap(self, () => that))\n\n/**\n * Combines two `Option`s, keeping the value from the first `Option` if both are\n * `Some`.\n *\n * **Details**\n *\n * This function takes two `Option`s and returns the first one if it is `Some`.\n * If either the first `Option` or the second `Option` is `None`, the result\n * will be `None`. This operation \"zips\" the two `Option`s while discarding the\n * value from the second `Option`.\n *\n * This is useful when sequencing computations where the second `Option`\n * represents a dependency or condition that must hold, but its value is\n * irrelevant.\n *\n * @category Zipping\n * @since 2.0.0\n */\nexport const zipLeft: {\n /**\n * Combines two `Option`s, keeping the value from the first `Option` if both are\n * `Some`.\n *\n * **Details**\n *\n * This function takes two `Option`s and returns the first one if it is `Some`.\n * If either the first `Option` or the second `Option` is `None`, the result\n * will be `None`. This operation \"zips\" the two `Option`s while discarding the\n * value from the second `Option`.\n *\n * This is useful when sequencing computations where the second `Option`\n * represents a dependency or condition that must hold, but its value is\n * irrelevant.\n *\n * @category Zipping\n * @since 2.0.0\n */\n <_>(that: Option<_>): <A>(self: Option<A>) => Option<A>\n /**\n * Combines two `Option`s, keeping the value from the first `Option` if both are\n * `Some`.\n *\n * **Details**\n *\n * This function takes two `Option`s and returns the first one if it is `Some`.\n * If either the first `Option` or the second `Option` is `None`, the result\n * will be `None`. This operation \"zips\" the two `Option`s while discarding the\n * value from the second `Option`.\n *\n * This is useful when sequencing computations where the second `Option`\n * represents a dependency or condition that must hold, but its value is\n * irrelevant.\n *\n * @category Zipping\n * @since 2.0.0\n */\n <A, X>(self: Option<A>, that: Option<X>): Option<A>\n} = dual(2, <A, X>(self: Option<A>, that: Option<X>): Option<A> => tap(self, () => that))\n\n/**\n * Composes two functions that return `Option` values, creating a new function\n * that chains them together.\n *\n * **Details**\n *\n * This function allows you to compose two computations, each represented by a\n * function that returns an `Option`. The result of the first function is passed\n * to the second function if it is `Some`. If the first function returns `None`,\n * the composed function short-circuits and returns `None` without invoking the\n * second function.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const parse = (s: string): Option.Option<number> => isNaN(Number(s)) ? Option.none() : Option.some(Number(s))\n *\n * const double = (n: number): Option.Option<number> => n > 0 ? Option.some(n * 2) : Option.none()\n *\n * const parseAndDouble = Option.composeK(parse, double)\n *\n * console.log(parseAndDouble(\"42\"))\n * // Output: { _id: 'Option', _tag: 'Some', value: 84 }\n *\n * console.log(parseAndDouble(\"not a number\"))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Sequencing\n * @since 2.0.0\n */\nexport const composeK: {\n /**\n * Composes two functions that return `Option` values, creating a new function\n * that chains them together.\n *\n * **Details**\n *\n * This function allows you to compose two computations, each represented by a\n * function that returns an `Option`. The result of the first function is passed\n * to the second function if it is `Some`. If the first function returns `None`,\n * the composed function short-circuits and returns `None` without invoking the\n * second function.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const parse = (s: string): Option.Option<number> => isNaN(Number(s)) ? Option.none() : Option.some(Number(s))\n *\n * const double = (n: number): Option.Option<number> => n > 0 ? Option.some(n * 2) : Option.none()\n *\n * const parseAndDouble = Option.composeK(parse, double)\n *\n * console.log(parseAndDouble(\"42\"))\n * // Output: { _id: 'Option', _tag: 'Some', value: 84 }\n *\n * console.log(parseAndDouble(\"not a number\"))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <B, C>(bfc: (b: B) => Option<C>): <A>(afb: (a: A) => Option<B>) => (a: A) => Option<C>\n /**\n * Composes two functions that return `Option` values, creating a new function\n * that chains them together.\n *\n * **Details**\n *\n * This function allows you to compose two computations, each represented by a\n * function that returns an `Option`. The result of the first function is passed\n * to the second function if it is `Some`. If the first function returns `None`,\n * the composed function short-circuits and returns `None` without invoking the\n * second function.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const parse = (s: string): Option.Option<number> => isNaN(Number(s)) ? Option.none() : Option.some(Number(s))\n *\n * const double = (n: number): Option.Option<number> => n > 0 ? Option.some(n * 2) : Option.none()\n *\n * const parseAndDouble = Option.composeK(parse, double)\n *\n * console.log(parseAndDouble(\"42\"))\n * // Output: { _id: 'Option', _tag: 'Some', value: 84 }\n *\n * console.log(parseAndDouble(\"not a number\"))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, B, C>(afb: (a: A) => Option<B>, bfc: (b: B) => Option<C>): (a: A) => Option<C>\n} = dual(2, <A, B, C>(afb: (a: A) => Option<B>, bfc: (b: B) => Option<C>) => (a: A): Option<C> => flatMap(afb(a), bfc))\n\n/**\n * Applies the provided function `f` to the value of the `Option` if it is\n * `Some` and returns the original `Option`, unless `f` returns `None`, in which\n * case it returns `None`.\n *\n * **Details**\n *\n * This function allows you to perform additional computations on the value of\n * an `Option` without modifying its original value. If the `Option` is `Some`,\n * the provided function `f` is executed with the value, and its result\n * determines whether the original `Option` is returned (`Some`) or the result\n * is `None` if `f` returns `None`. If the input `Option` is `None`, the\n * function is not executed, and `None` is returned.\n *\n * This is particularly useful for applying side conditions or performing\n * validation checks while retaining the original `Option`'s value.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getInteger = (n: number) => Number.isInteger(n) ? Option.some(n) : Option.none()\n *\n * console.log(Option.tap(Option.none(), getInteger))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(Option.tap(Option.some(1), getInteger))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(Option.tap(Option.some(1.14), getInteger))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Sequencing\n * @since 2.0.0\n */\nexport const tap: {\n /**\n * Applies the provided function `f` to the value of the `Option` if it is\n * `Some` and returns the original `Option`, unless `f` returns `None`, in which\n * case it returns `None`.\n *\n * **Details**\n *\n * This function allows you to perform additional computations on the value of\n * an `Option` without modifying its original value. If the `Option` is `Some`,\n * the provided function `f` is executed with the value, and its result\n * determines whether the original `Option` is returned (`Some`) or the result\n * is `None` if `f` returns `None`. If the input `Option` is `None`, the\n * function is not executed, and `None` is returned.\n *\n * This is particularly useful for applying side conditions or performing\n * validation checks while retaining the original `Option`'s value.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getInteger = (n: number) => Number.isInteger(n) ? Option.some(n) : Option.none()\n *\n * console.log(Option.tap(Option.none(), getInteger))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(Option.tap(Option.some(1), getInteger))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(Option.tap(Option.some(1.14), getInteger))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, X>(f: (a: A) => Option<X>): (self: Option<A>) => Option<A>\n /**\n * Applies the provided function `f` to the value of the `Option` if it is\n * `Some` and returns the original `Option`, unless `f` returns `None`, in which\n * case it returns `None`.\n *\n * **Details**\n *\n * This function allows you to perform additional computations on the value of\n * an `Option` without modifying its original value. If the `Option` is `Some`,\n * the provided function `f` is executed with the value, and its result\n * determines whether the original `Option` is returned (`Some`) or the result\n * is `None` if `f` returns `None`. If the input `Option` is `None`, the\n * function is not executed, and `None` is returned.\n *\n * This is particularly useful for applying side conditions or performing\n * validation checks while retaining the original `Option`'s value.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getInteger = (n: number) => Number.isInteger(n) ? Option.some(n) : Option.none()\n *\n * console.log(Option.tap(Option.none(), getInteger))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(Option.tap(Option.some(1), getInteger))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(Option.tap(Option.some(1.14), getInteger))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, X>(self: Option<A>, f: (a: A) => Option<X>): Option<A>\n} = dual(2, <A, X>(self: Option<A>, f: (a: A) => Option<X>): Option<A> => flatMap(self, (a) => map(f(a), () => a)))\n\n/**\n * Combines two `Option` values into a single `Option` containing a tuple of\n * their values if both are `Some`.\n *\n * **Details**\n *\n * This function takes two `Option`s and combines their values into a tuple `[A,\n * B]` if both are `Some`. If either of the `Option`s is `None`, the result is\n * `None`. This is particularly useful for combining multiple `Option` values\n * into a single one, ensuring both contain valid values.\n *\n * @category Combining\n * @since 2.0.0\n */\nexport const product = <A, B>(self: Option<A>, that: Option<B>): Option<[A, B]> =>\n isSome(self) && isSome(that) ? some([self.value, that.value]) : none()\n\n/**\n * Combines an `Option` with a collection of `Option`s into a single `Option`\n * containing a tuple of their values if all are `Some`.\n *\n * **Details**\n *\n * This function takes a primary `Option` and a collection of `Option`s and\n * combines their values into a tuple `[A, ...Array<A>]` if all are `Some`. If\n * the primary `Option` or any `Option` in the collection is `None`, the result\n * is `None`.\n *\n * @category Combining\n * @since 2.0.0\n */\nexport const productMany = <A>(\n self: Option<A>,\n collection: Iterable<Option<A>>\n): Option<[A, ...Array<A>]> => {\n if (isNone(self)) {\n return none()\n }\n const out: [A, ...Array<A>] = [self.value]\n for (const o of collection) {\n if (isNone(o)) {\n return none()\n }\n out.push(o.value)\n }\n return some(out)\n}\n\n/**\n * Combines a structure of `Option`s into a single `Option` containing the\n * values with the same structure.\n *\n * **Details**\n *\n * This function takes a structure of `Option`s (a tuple, struct, or iterable)\n * and produces a single `Option` that contains the values from the input\n * structure if all `Option`s are `Some`. If any `Option` in the input is\n * `None`, the result is `None`. The structure of the input is preserved in the\n * output.\n *\n * - If the input is a tuple (e.g., an array), the result will be an `Option`\n * containing a tuple with the same length.\n * - If the input is a struct (e.g., an object), the result will be an `Option`\n * containing a struct with the same keys.\n * - If the input is an iterable, the result will be an `Option` containing an\n * array.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const maybeName: Option.Option<string> = Option.some(\"John\")\n * const maybeAge: Option.Option<number> = Option.some(25)\n *\n * // ┌─── Option<[string, number]>\n * // ▼\n * const tuple = Option.all([maybeName, maybeAge])\n * console.log(tuple)\n * // Output:\n * // { _id: 'Option', _tag: 'Some', value: [ 'John', 25 ] }\n *\n * // ┌─── Option<{ name: string; age: number; }>\n * // ▼\n * const struct = Option.all({ name: maybeName, age: maybeAge })\n * console.log(struct)\n * // Output:\n * // { _id: 'Option', _tag: 'Some', value: { name: 'John', age: 25 } }\n * ```\n *\n * @category Combining\n * @since 2.0.0\n */\n// @ts-expect-error\nexport const all: <const I extends Iterable<Option<any>> | Record<string, Option<any>>>(\n input: I\n) => [I] extends [ReadonlyArray<Option<any>>] ? Option<\n { -readonly [K in keyof I]: [I[K]] extends [Option<infer A>] ? A : never }\n >\n : [I] extends [Iterable<Option<infer A>>] ? Option<Array<A>>\n : Option<{ -readonly [K in keyof I]: [I[K]] extends [Option<infer A>] ? A : never }> = (\n input: Iterable<Option<any>> | Record<string, Option<any>>\n ): Option<any> => {\n if (Symbol.iterator in input) {\n const out: Array<Option<any>> = []\n for (const o of (input as Iterable<Option<any>>)) {\n if (isNone(o)) {\n return none()\n }\n out.push(o.value)\n }\n return some(out)\n }\n\n const out: Record<string, any> = {}\n for (const key of Object.keys(input)) {\n const o = input[key]\n if (isNone(o)) {\n return none()\n }\n out[key] = o.value\n }\n return some(out)\n }\n\n/**\n * Combines two `Option` values into a new `Option` by applying a provided\n * function to their values.\n *\n * **Details**\n *\n * This function takes two `Option` values (`self` and `that`) and a combining\n * function `f`. If both `Option` values are `Some`, the function `f` is applied\n * to their values, and the result is wrapped in a new `Some`. If either\n * `Option` is `None`, the result is `None`.\n *\n * This utility is useful for combining two optional computations into a single\n * result while maintaining type safety and avoiding explicit checks for `None`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const maybeName: Option.Option<string> = Option.some(\"John\")\n * const maybeAge: Option.Option<number> = Option.some(25)\n *\n * // Combine the name and age into a person object\n * const person = Option.zipWith(maybeName, maybeAge, (name, age) => ({\n * name: name.toUpperCase(),\n * age\n * }))\n *\n * console.log(person)\n * // Output:\n * // { _id: 'Option', _tag: 'Some', value: { name: 'JOHN', age: 25 } }\n * ```\n *\n * @category Zipping\n * @since 2.0.0\n */\nexport const zipWith: {\n /**\n * Combines two `Option` values into a new `Option` by applying a provided\n * function to their values.\n *\n * **Details**\n *\n * This function takes two `Option` values (`self` and `that`) and a combining\n * function `f`. If both `Option` values are `Some`, the function `f` is applied\n * to their values, and the result is wrapped in a new `Some`. If either\n * `Option` is `None`, the result is `None`.\n *\n * This utility is useful for combining two optional computations into a single\n * result while maintaining type safety and avoiding explicit checks for `None`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const maybeName: Option.Option<string> = Option.some(\"John\")\n * const maybeAge: Option.Option<number> = Option.some(25)\n *\n * // Combine the name and age into a person object\n * const person = Option.zipWith(maybeName, maybeAge, (name, age) => ({\n * name: name.toUpperCase(),\n * age\n * }))\n *\n * console.log(person)\n * // Output:\n * // { _id: 'Option', _tag: 'Some', value: { name: 'JOHN', age: 25 } }\n * ```\n *\n * @category Zipping\n * @since 2.0.0\n */\n <B, A, C>(that: Option<B>, f: (a: A, b: B) => C): (self: Option<A>) => Option<C>\n /**\n * Combines two `Option` values into a new `Option` by applying a provided\n * function to their values.\n *\n * **Details**\n *\n * This function takes two `Option` values (`self` and `that`) and a combining\n * function `f`. If both `Option` values are `Some`, the function `f` is applied\n * to their values, and the result is wrapped in a new `Some`. If either\n * `Option` is `None`, the result is `None`.\n *\n * This utility is useful for combining two optional computations into a single\n * result while maintaining type safety and avoiding explicit checks for `None`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const maybeName: Option.Option<string> = Option.some(\"John\")\n * const maybeAge: Option.Option<number> = Option.some(25)\n *\n * // Combine the name and age into a person object\n * const person = Option.zipWith(maybeName, maybeAge, (name, age) => ({\n * name: name.toUpperCase(),\n * age\n * }))\n *\n * console.log(person)\n * // Output:\n * // { _id: 'Option', _tag: 'Some', value: { name: 'JOHN', age: 25 } }\n * ```\n *\n * @category Zipping\n * @since 2.0.0\n */\n <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C>\n} = dual(\n 3,\n <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C> =>\n map(product(self, that), ([a, b]) => f(a, b))\n)\n\n/**\n * Applies a function inside a `Some` to a value inside another `Some`,\n * combining them into a new `Option`.\n *\n * **Details**\n *\n * This function allows you to apply a function wrapped in an `Option` (`self`)\n * to a value wrapped in another `Option` (`that`). If both `Option`s are\n * `Some`, the function is applied to the value, and the result is wrapped in a\n * new `Some`. If either `Option` is `None`, the result is `None`.\n *\n * @category Combining\n * @since 2.0.0\n */\nexport const ap: {\n /**\n * Applies a function inside a `Some` to a value inside another `Some`,\n * combining them into a new `Option`.\n *\n * **Details**\n *\n * This function allows you to apply a function wrapped in an `Option` (`self`)\n * to a value wrapped in another `Option` (`that`). If both `Option`s are\n * `Some`, the function is applied to the value, and the result is wrapped in a\n * new `Some`. If either `Option` is `None`, the result is `None`.\n *\n * @category Combining\n * @since 2.0.0\n */\n <A>(that: Option<A>): <B>(self: Option<(a: A) => B>) => Option<B>\n /**\n * Applies a function inside a `Some` to a value inside another `Some`,\n * combining them into a new `Option`.\n *\n * **Details**\n *\n * This function allows you to apply a function wrapped in an `Option` (`self`)\n * to a value wrapped in another `Option` (`that`). If both `Option`s are\n * `Some`, the function is applied to the value, and the result is wrapped in a\n * new `Some`. If either `Option` is `None`, the result is `None`.\n *\n * @category Combining\n * @since 2.0.0\n */\n <A, B>(self: Option<(a: A) => B>, that: Option<A>): Option<B>\n} = dual(2, <A, B>(self: Option<(a: A) => B>, that: Option<A>): Option<B> => zipWith(self, that, (f, a) => f(a)))\n\n/**\n * Reduces an `Iterable` of `Option<A>` to a single value of type `B`, ignoring\n * elements that are `None`.\n *\n * **Details**\n *\n * This function takes an initial value of type `B` and a reducing function `f`\n * that combines the accumulator with values of type `A`. It processes an\n * iterable of `Option<A>`, applying `f` only to the `Some` values while\n * ignoring the `None` values. The result is a single value of type `B`.\n *\n * This utility is particularly useful for aggregating values from an iterable\n * of `Option`s while skipping the absent (`None`) values.\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const iterable = [Option.some(1), Option.none(), Option.some(2), Option.none()]\n *\n * console.log(pipe(iterable, Option.reduceCompact(0, (b, a) => b + a)))\n * // Output: 3\n * ```\n *\n * @category Reducing\n * @since 2.0.0\n */\nexport const reduceCompact: {\n /**\n * Reduces an `Iterable` of `Option<A>` to a single value of type `B`, ignoring\n * elements that are `None`.\n *\n * **Details**\n *\n * This function takes an initial value of type `B` and a reducing function `f`\n * that combines the accumulator with values of type `A`. It processes an\n * iterable of `Option<A>`, applying `f` only to the `Some` values while\n * ignoring the `None` values. The result is a single value of type `B`.\n *\n * This utility is particularly useful for aggregating values from an iterable\n * of `Option`s while skipping the absent (`None`) values.\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const iterable = [Option.some(1), Option.none(), Option.some(2), Option.none()]\n *\n * console.log(pipe(iterable, Option.reduceCompact(0, (b, a) => b + a)))\n * // Output: 3\n * ```\n *\n * @category Reducing\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A) => B): (self: Iterable<Option<A>>) => B\n /**\n * Reduces an `Iterable` of `Option<A>` to a single value of type `B`, ignoring\n * elements that are `None`.\n *\n * **Details**\n *\n * This function takes an initial value of type `B` and a reducing function `f`\n * that combines the accumulator with values of type `A`. It processes an\n * iterable of `Option<A>`, applying `f` only to the `Some` values while\n * ignoring the `None` values. The result is a single value of type `B`.\n *\n * This utility is particularly useful for aggregating values from an iterable\n * of `Option`s while skipping the absent (`None`) values.\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const iterable = [Option.some(1), Option.none(), Option.some(2), Option.none()]\n *\n * console.log(pipe(iterable, Option.reduceCompact(0, (b, a) => b + a)))\n * // Output: 3\n * ```\n *\n * @category Reducing\n * @since 2.0.0\n */\n <A, B>(self: Iterable<Option<A>>, b: B, f: (b: B, a: A) => B): B\n} = dual(\n 3,\n <A, B>(self: Iterable<Option<A>>, b: B, f: (b: B, a: A) => B): B => {\n let out: B = b\n for (const oa of self) {\n if (isSome(oa)) {\n out = f(out, oa.value)\n }\n }\n return out\n }\n)\n\n/**\n * Converts an `Option` into an `Array`.\n * If the input is `None`, an empty array is returned.\n * If the input is `Some`, its value is wrapped in a single-element array.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.toArray(Option.some(1)))\n * // Output: [1]\n *\n * console.log(Option.toArray(Option.none()))\n * // Output: []\n * ```\n *\n * @category Conversions\n * @since 2.0.0\n */\nexport const toArray = <A>(self: Option<A>): Array<A> => isNone(self) ? [] : [self.value]\n\n/**\n * Splits an `Option` into two `Option`s based on the result of a mapping\n * function that produces an `Either`.\n *\n * **Details**\n *\n * This function takes an `Option` and a mapping function `f` that converts its\n * value into an `Either`. It returns a tuple of two `Option`s:\n *\n * - The first `Option` (`left`) contains the value from the `Left` side of the\n * `Either` if it exists, otherwise `None`.\n * - The second `Option` (`right`) contains the value from the `Right` side of\n * the `Either` if it exists, otherwise `None`.\n *\n * If the input `Option` is `None`, both returned `Option`s are `None`.\n *\n * This utility is useful for filtering and categorizing the contents of an\n * `Option` based on a bifurcating computation.\n *\n * @category Filtering\n * @since 2.0.0\n */\nexport const partitionMap: {\n /**\n * Splits an `Option` into two `Option`s based on the result of a mapping\n * function that produces an `Either`.\n *\n * **Details**\n *\n * This function takes an `Option` and a mapping function `f` that converts its\n * value into an `Either`. It returns a tuple of two `Option`s:\n *\n * - The first `Option` (`left`) contains the value from the `Left` side of the\n * `Either` if it exists, otherwise `None`.\n * - The second `Option` (`right`) contains the value from the `Right` side of\n * the `Either` if it exists, otherwise `None`.\n *\n * If the input `Option` is `None`, both returned `Option`s are `None`.\n *\n * This utility is useful for filtering and categorizing the contents of an\n * `Option` based on a bifurcating computation.\n *\n * @category Filtering\n * @since 2.0.0\n */\n <A, B, C>(f: (a: A) => Either<C, B>): (self: Option<A>) => [left: Option<B>, right: Option<C>]\n /**\n * Splits an `Option` into two `Option`s based on the result of a mapping\n * function that produces an `Either`.\n *\n * **Details**\n *\n * This function takes an `Option` and a mapping function `f` that converts its\n * value into an `Either`. It returns a tuple of two `Option`s:\n *\n * - The first `Option` (`left`) contains the value from the `Left` side of the\n * `Either` if it exists, otherwise `None`.\n * - The second `Option` (`right`) contains the value from the `Right` side of\n * the `Either` if it exists, otherwise `None`.\n *\n * If the input `Option` is `None`, both returned `Option`s are `None`.\n *\n * This utility is useful for filtering and categorizing the contents of an\n * `Option` based on a bifurcating computation.\n *\n * @category Filtering\n * @since 2.0.0\n */\n <A, B, C>(self: Option<A>, f: (a: A) => Either<C, B>): [left: Option<B>, right: Option<C>]\n} = dual(2, <A, B, C>(\n self: Option<A>,\n f: (a: A) => Either<C, B>\n): [excluded: Option<B>, satisfying: Option<C>] => {\n if (isNone(self)) {\n return [none(), none()]\n }\n const e = f(self.value)\n return either.isLeft(e) ? [some(e.left), none()] : [none(), some(e.right)]\n})\n\n// TODO(4.0): remove?\n/**\n * Alias of {@link flatMap}.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Transform and filter numbers\n * const transformEven = (n: Option.Option<number>): Option.Option<string> =>\n * Option.filterMap(n, (n) => (n % 2 === 0 ? Option.some(`Even: ${n}`) : Option.none()))\n *\n * console.log(transformEven(Option.none()))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(transformEven(Option.some(1)))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(transformEven(Option.some(2)))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'Even: 2' }\n * ```\n *\n * @category Filtering\n * @since 2.0.0\n */\nexport const filterMap: {\n // TODO(4.0): remove?\n /**\n * Alias of {@link flatMap}.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Transform and filter numbers\n * const transformEven = (n: Option.Option<number>): Option.Option<string> =>\n * Option.filterMap(n, (n) => (n % 2 === 0 ? Option.some(`Even: ${n}`) : Option.none()))\n *\n * console.log(transformEven(Option.none()))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(transformEven(Option.some(1)))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(transformEven(Option.some(2)))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'Even: 2' }\n * ```\n *\n * @category Filtering\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => Option<B>): (self: Option<A>) => Option<B>\n // TODO(4.0): remove?\n /**\n * Alias of {@link flatMap}.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Transform and filter numbers\n * const transformEven = (n: Option.Option<number>): Option.Option<string> =>\n * Option.filterMap(n, (n) => (n % 2 === 0 ? Option.some(`Even: ${n}`) : Option.none()))\n *\n * console.log(transformEven(Option.none()))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(transformEven(Option.some(1)))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(transformEven(Option.some(2)))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'Even: 2' }\n * ```\n *\n * @category Filtering\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B>\n} = flatMap\n\n/**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const removeEmptyString = (input: Option.Option<string>) =>\n * Option.filter(input, (value) => value !== \"\")\n *\n * console.log(removeEmptyString(Option.none()))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"\")))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"a\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n * ```\n *\n * @category Filtering\n * @since 2.0.0\n */\nexport const filter: {\n /**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const removeEmptyString = (input: Option.Option<string>) =>\n * Option.filter(input, (value) => value !== \"\")\n *\n * console.log(removeEmptyString(Option.none()))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"\")))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"a\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n * ```\n *\n * @category Filtering\n * @since 2.0.0\n */\n <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: Option<A>) => Option<B>\n /**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const removeEmptyString = (input: Option.Option<string>) =>\n * Option.filter(input, (value) => value !== \"\")\n *\n * console.log(removeEmptyString(Option.none()))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"\")))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"a\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n * ```\n *\n * @category Filtering\n * @since 2.0.0\n */\n <A>(predicate: Predicate<NoInfer<A>>): (self: Option<A>) => Option<A>\n /**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const removeEmptyString = (input: Option.Option<string>) =>\n * Option.filter(input, (value) => value !== \"\")\n *\n * console.log(removeEmptyString(Option.none()))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"\")))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"a\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n * ```\n *\n * @category Filtering\n * @since 2.0.0\n */\n <A, B extends A>(self: Option<A>, refinement: Refinement<A, B>): Option<B>\n /**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const removeEmptyString = (input: Option.Option<string>) =>\n * Option.filter(input, (value) => value !== \"\")\n *\n * console.log(removeEmptyString(Option.none()))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"\")))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"a\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n * ```\n *\n * @category Filtering\n * @since 2.0.0\n */\n <A>(self: Option<A>, predicate: Predicate<A>): Option<A>\n} = dual(\n 2,\n <A>(self: Option<A>, predicate: Predicate<A>): Option<A> =>\n filterMap(self, (b) => (predicate(b) ? option.some(b) : option.none))\n)\n\n/**\n * Creates an `Equivalence` instance for comparing `Option` values, using a\n * provided `Equivalence` for the inner type.\n *\n * **Details**\n *\n * This function takes an `Equivalence` instance for a specific type `A` and\n * produces an `Equivalence` instance for `Option<A>`. The resulting\n * `Equivalence` determines whether two `Option` values are equivalent:\n *\n * - Two `None`s are considered equivalent.\n * - A `Some` and a `None` are not equivalent.\n * - Two `Some` values are equivalent if their inner values are equivalent\n * according to the provided `Equivalence`.\n *\n * **Example** (Comparing Optional Numbers for Equivalence)\n *\n * ```ts\n * import { Number, Option } from \"effect\"\n *\n * const isEquivalent = Option.getEquivalence(Number.Equivalence)\n *\n * console.log(isEquivalent(Option.none(), Option.none()))\n * // Output: true\n *\n * console.log(isEquivalent(Option.none(), Option.some(1)))\n * // Output: false\n *\n * console.log(isEquivalent(Option.some(1), Option.none()))\n * // Output: false\n *\n * console.log(isEquivalent(Option.some(1), Option.some(2)))\n * // Output: false\n *\n * console.log(isEquivalent(Option.some(1), Option.some(1)))\n * // Output: true\n * ```\n *\n * @category Equivalence\n * @since 2.0.0\n */\nexport const getEquivalence = <A>(isEquivalent: Equivalence.Equivalence<A>): Equivalence.Equivalence<Option<A>> =>\n Equivalence.make((x, y) => isNone(x) ? isNone(y) : isNone(y) ? false : isEquivalent(x.value, y.value))\n\n/**\n * Creates an `Order` instance for comparing `Option` values, using a provided\n * `Order` for the inner type.\n *\n * **Details**\n *\n * This function produces an `Order` instance for `Option<A>`, allowing `Option`\n * values to be compared:\n *\n * - `None` is always considered less than any `Some` value.\n * - If both are `Some`, their inner values are compared using the provided\n * `Order` instance.\n *\n * @example\n * ```ts\n * import { Number, Option } from \"effect\"\n *\n * const order = Option.getOrder(Number.Order)\n *\n * console.log(order(Option.none(), Option.none()))\n * // Output: 0\n *\n * console.log(order(Option.none(), Option.some(1)))\n * // Output: -1\n *\n * console.log(order(Option.some(1), Option.none()))\n * // Output: 1\n *\n * console.log(order(Option.some(1), Option.some(2)))\n * // Output: -1\n *\n * console.log(order(Option.some(1), Option.some(1)))\n * // Output: 0\n * ```\n *\n * @category Sorting\n * @since 2.0.0\n */\nexport const getOrder = <A>(O: Order<A>): Order<Option<A>> =>\n order.make((self, that) => isSome(self) ? (isSome(that) ? O(self.value, that.value) : 1) : -1)\n\n/**\n * Lifts a binary function to work with `Option` values, allowing the function\n * to operate on two `Option`s.\n *\n * **Details**\n *\n * This function takes a binary function `f` and returns a new function that\n * applies `f` to the values of two `Option`s (`self` and `that`). If both\n * `Option`s are `Some`, the binary function `f` is applied to their values, and\n * the result is wrapped in a new `Some`. If either `Option` is `None`, the\n * result is `None`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // A binary function to add two numbers\n * const add = (a: number, b: number): number => a + b\n *\n * // Lift the `add` function to work with `Option` values\n * const addOptions = Option.lift2(add)\n *\n * // Both `Option`s are `Some`\n * console.log(addOptions(Option.some(2), Option.some(3)))\n * // Output: { _id: 'Option', _tag: 'Some', value: 5 }\n *\n * // One `Option` is `None`\n * console.log(addOptions(Option.some(2), Option.none()))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Lifting\n * @since 2.0.0\n */\nexport const lift2 = <A, B, C>(f: (a: A, b: B) => C): {\n (that: Option<B>): (self: Option<A>) => Option<C>\n (self: Option<A>, that: Option<B>): Option<C>\n} => dual(2, (self: Option<A>, that: Option<B>): Option<C> => zipWith(self, that, f))\n\n/**\n * Lifts a `Predicate` or `Refinement` into the `Option` context, returning a\n * `Some` of the input value if the predicate is satisfied, or `None` otherwise.\n *\n * **Details**\n *\n * This function transforms a `Predicate` (or a more specific `Refinement`) into\n * a function that produces an `Option`. If the predicate evaluates to `true`,\n * the input value is wrapped in a `Some`. If the predicate evaluates to\n * `false`, the result is `None`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Check if a number is positive\n * const isPositive = (n: number) => n > 0\n *\n * // ┌─── (b: number) => Option<number>\n * // ▼\n * const parsePositive = Option.liftPredicate(isPositive)\n *\n * console.log(parsePositive(1))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(parsePositive(-1))\n * // OUtput: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Lifting\n * @since 2.0.0\n */\nexport const liftPredicate: { // Note: I intentionally avoid using the NoInfer pattern here.\n <A, B extends A>(refinement: Refinement<A, B>): (a: A) => Option<B>\n /**\n * Lifts a `Predicate` or `Refinement` into the `Option` context, returning a\n * `Some` of the input value if the predicate is satisfied, or `None` otherwise.\n *\n * **Details**\n *\n * This function transforms a `Predicate` (or a more specific `Refinement`) into\n * a function that produces an `Option`. If the predicate evaluates to `true`,\n * the input value is wrapped in a `Some`. If the predicate evaluates to\n * `false`, the result is `None`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Check if a number is positive\n * const isPositive = (n: number) => n > 0\n *\n * // ┌─── (b: number) => Option<number>\n * // ▼\n * const parsePositive = Option.liftPredicate(isPositive)\n *\n * console.log(parsePositive(1))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(parsePositive(-1))\n * // OUtput: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Lifting\n * @since 2.0.0\n */\n <B extends A, A = B>(predicate: Predicate<A>): (b: B) => Option<B>\n /**\n * Lifts a `Predicate` or `Refinement` into the `Option` context, returning a\n * `Some` of the input value if the predicate is satisfied, or `None` otherwise.\n *\n * **Details**\n *\n * This function transforms a `Predicate` (or a more specific `Refinement`) into\n * a function that produces an `Option`. If the predicate evaluates to `true`,\n * the input value is wrapped in a `Some`. If the predicate evaluates to\n * `false`, the result is `None`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Check if a number is positive\n * const isPositive = (n: number) => n > 0\n *\n * // ┌─── (b: number) => Option<number>\n * // ▼\n * const parsePositive = Option.liftPredicate(isPositive)\n *\n * console.log(parsePositive(1))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(parsePositive(-1))\n * // OUtput: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Lifting\n * @since 2.0.0\n */\n <A, B extends A>(self: A, refinement: Refinement<A, B>): Option<B>\n /**\n * Lifts a `Predicate` or `Refinement` into the `Option` context, returning a\n * `Some` of the input value if the predicate is satisfied, or `None` otherwise.\n *\n * **Details**\n *\n * This function transforms a `Predicate` (or a more specific `Refinement`) into\n * a function that produces an `Option`. If the predicate evaluates to `true`,\n * the input value is wrapped in a `Some`. If the predicate evaluates to\n * `false`, the result is `None`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Check if a number is positive\n * const isPositive = (n: number) => n > 0\n *\n * // ┌─── (b: number) => Option<number>\n * // ▼\n * const parsePositive = Option.liftPredicate(isPositive)\n *\n * console.log(parsePositive(1))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(parsePositive(-1))\n * // OUtput: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Lifting\n * @since 2.0.0\n */\n <B extends A, A = B>(self: B, predicate: Predicate<A>): Option<B>\n} = dual(\n 2,\n <B extends A, A = B>(b: B, predicate: Predicate<A>): Option<B> => predicate(b) ? some(b) : none()\n)\n\n/**\n * Returns a function that checks if an `Option` contains a specified value,\n * using a provided equivalence function.\n *\n * **Details**\n *\n * This function allows you to check whether an `Option` contains a specific\n * value. It uses an equivalence function `isEquivalent` to compare the value\n * inside the `Option` to the provided value. If the `Option` is `Some` and the\n * equivalence function returns `true`, the result is `true`. If the `Option` is\n * `None` or the values are not equivalent, the result is `false`.\n *\n * @example\n * ```ts\n * import { Number, Option } from \"effect\"\n *\n * const contains = Option.containsWith(Number.Equivalence)\n *\n * console.log(Option.some(2).pipe(contains(2)))\n * // Output: true\n *\n * console.log(Option.some(1).pipe(contains(2)))\n * // Output: false\n *\n * console.log(Option.none().pipe(contains(2)))\n * // Output: false\n * ```\n *\n * @see {@link contains} for a version that uses the default `Equivalence`.\n *\n * @category Elements\n * @since 2.0.0\n */\nexport const containsWith = <A>(isEquivalent: (self: A, that: A) => boolean): {\n (a: A): (self: Option<A>) => boolean\n (self: Option<A>, a: A): boolean\n} => dual(2, (self: Option<A>, a: A): boolean => isNone(self) ? false : isEquivalent(self.value, a))\n\nconst _equivalence = Equal.equivalence()\n\n/**\n * Returns a function that checks if an `Option` contains a specified value\n * using the default `Equivalence`.\n *\n * **Details**\n *\n * This function allows you to check whether an `Option` contains a specific\n * value. It uses the default `Equivalence` for equality comparison. If the\n * `Option` is `Some` and its value is equivalent to the provided value, the\n * result is `true`. If the `Option` is `None` or the values are not equivalent,\n * the result is `false`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.some(2).pipe(Option.contains(2)))\n * // Output: true\n *\n * console.log(Option.some(1).pipe(Option.contains(2)))\n * // Output: false\n *\n * console.log(Option.none().pipe(Option.contains(2)))\n * // Output: false\n * ```\n *\n * @see {@link containsWith} for a version that allows you to specify a custom equivalence function.\n *\n * @category Elements\n * @since 2.0.0\n */\nexport const contains: {\n /**\n * Returns a function that checks if an `Option` contains a specified value\n * using the default `Equivalence`.\n *\n * **Details**\n *\n * This function allows you to check whether an `Option` contains a specific\n * value. It uses the default `Equivalence` for equality comparison. If the\n * `Option` is `Some` and its value is equivalent to the provided value, the\n * result is `true`. If the `Option` is `None` or the values are not equivalent,\n * the result is `false`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.some(2).pipe(Option.contains(2)))\n * // Output: true\n *\n * console.log(Option.some(1).pipe(Option.contains(2)))\n * // Output: false\n *\n * console.log(Option.none().pipe(Option.contains(2)))\n * // Output: false\n * ```\n *\n * @see {@link containsWith} for a version that allows you to specify a custom equivalence function.\n *\n * @category Elements\n * @since 2.0.0\n */\n <A>(a: A): (self: Option<A>) => boolean\n /**\n * Returns a function that checks if an `Option` contains a specified value\n * using the default `Equivalence`.\n *\n * **Details**\n *\n * This function allows you to check whether an `Option` contains a specific\n * value. It uses the default `Equivalence` for equality comparison. If the\n * `Option` is `Some` and its value is equivalent to the provided value, the\n * result is `true`. If the `Option` is `None` or the values are not equivalent,\n * the result is `false`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.some(2).pipe(Option.contains(2)))\n * // Output: true\n *\n * console.log(Option.some(1).pipe(Option.contains(2)))\n * // Output: false\n *\n * console.log(Option.none().pipe(Option.contains(2)))\n * // Output: false\n * ```\n *\n * @see {@link containsWith} for a version that allows you to specify a custom equivalence function.\n *\n * @category Elements\n * @since 2.0.0\n */\n <A>(self: Option<A>, a: A): boolean\n} = containsWith(_equivalence)\n\n/**\n * Checks if a value in an `Option` satisfies a given predicate or refinement.\n *\n * **Details**\n *\n * This function allows you to check if a value inside a `Some` meets a\n * specified condition. If the `Option` is `None`, the result is `false`. If the\n * `Option` is `Some`, the provided predicate or refinement is applied to the\n * value:\n *\n * - If the condition is met, the result is `true`.\n * - If the condition is not met, the result is `false`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * console.log(Option.some(2).pipe(Option.exists(isEven)))\n * // Output: true\n *\n * console.log(Option.some(1).pipe(Option.exists(isEven)))\n * // Output: false\n *\n * console.log(Option.none().pipe(Option.exists(isEven)))\n * // Output: false\n * ```\n *\n * @category Elements\n * @since 2.0.0\n */\nexport const exists: {\n /**\n * Checks if a value in an `Option` satisfies a given predicate or refinement.\n *\n * **Details**\n *\n * This function allows you to check if a value inside a `Some` meets a\n * specified condition. If the `Option` is `None`, the result is `false`. If the\n * `Option` is `Some`, the provided predicate or refinement is applied to the\n * value:\n *\n * - If the condition is met, the result is `true`.\n * - If the condition is not met, the result is `false`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * console.log(Option.some(2).pipe(Option.exists(isEven)))\n * // Output: true\n *\n * console.log(Option.some(1).pipe(Option.exists(isEven)))\n * // Output: false\n *\n * console.log(Option.none().pipe(Option.exists(isEven)))\n * // Output: false\n * ```\n *\n * @category Elements\n * @since 2.0.0\n */\n <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: Option<A>) => self is Option<B>\n /**\n * Checks if a value in an `Option` satisfies a given predicate or refinement.\n *\n * **Details**\n *\n * This function allows you to check if a value inside a `Some` meets a\n * specified condition. If the `Option` is `None`, the result is `false`. If the\n * `Option` is `Some`, the provided predicate or refinement is applied to the\n * value:\n *\n * - If the condition is met, the result is `true`.\n * - If the condition is not met, the result is `false`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * console.log(Option.some(2).pipe(Option.exists(isEven)))\n * // Output: true\n *\n * console.log(Option.some(1).pipe(Option.exists(isEven)))\n * // Output: false\n *\n * console.log(Option.none().pipe(Option.exists(isEven)))\n * // Output: false\n * ```\n *\n * @category Elements\n * @since 2.0.0\n */\n <A>(predicate: Predicate<NoInfer<A>>): (self: Option<A>) => boolean\n /**\n * Checks if a value in an `Option` satisfies a given predicate or refinement.\n *\n * **Details**\n *\n * This function allows you to check if a value inside a `Some` meets a\n * specified condition. If the `Option` is `None`, the result is `false`. If the\n * `Option` is `Some`, the provided predicate or refinement is applied to the\n * value:\n *\n * - If the condition is met, the result is `true`.\n * - If the condition is not met, the result is `false`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * console.log(Option.some(2).pipe(Option.exists(isEven)))\n * // Output: true\n *\n * console.log(Option.some(1).pipe(Option.exists(isEven)))\n * // Output: false\n *\n * console.log(Option.none().pipe(Option.exists(isEven)))\n * // Output: false\n * ```\n *\n * @category Elements\n * @since 2.0.0\n */\n <A, B extends A>(self: Option<A>, refinement: Refinement<A, B>): self is Option<B>\n /**\n * Checks if a value in an `Option` satisfies a given predicate or refinement.\n *\n * **Details**\n *\n * This function allows you to check if a value inside a `Some` meets a\n * specified condition. If the `Option` is `None`, the result is `false`. If the\n * `Option` is `Some`, the provided predicate or refinement is applied to the\n * value:\n *\n * - If the condition is met, the result is `true`.\n * - If the condition is not met, the result is `false`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * console.log(Option.some(2).pipe(Option.exists(isEven)))\n * // Output: true\n *\n * console.log(Option.some(1).pipe(Option.exists(isEven)))\n * // Output: false\n *\n * console.log(Option.none().pipe(Option.exists(isEven)))\n * // Output: false\n * ```\n *\n * @category Elements\n * @since 2.0.0\n */\n <A>(self: Option<A>, predicate: Predicate<A>): boolean\n} = dual(\n 2,\n <A, B extends A>(self: Option<A>, refinement: Refinement<A, B>): self is Option<B> =>\n isNone(self) ? false : refinement(self.value)\n)\n\n// -------------------------------------------------------------------------------------\n// do notation\n// -------------------------------------------------------------------------------------\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @category Do notation\n * @since 2.0.0\n */\nexport const bindTo: {\n // -------------------------------------------------------------------------------------\n // do notation\n // -------------------------------------------------------------------------------------\n\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @category Do notation\n * @since 2.0.0\n */\n <N extends string>(name: N): <A>(self: Option<A>) => Option<{ [K in N]: A }>\n // -------------------------------------------------------------------------------------\n // do notation\n // -------------------------------------------------------------------------------------\n\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @category Do notation\n * @since 2.0.0\n */\n <A, N extends string>(self: Option<A>, name: N): Option<{ [K in N]: A }>\n} = doNotation.bindTo<OptionTypeLambda>(map)\n\nconst let_: {\n <N extends string, A extends object, B>(\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): (self: Option<A>) => Option<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n <A extends object, N extends string, B>(\n self: Option<A>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): Option<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n} = doNotation.let_<OptionTypeLambda>(map)\n\nexport {\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link bindTo}\n *\n * @category Do notation\n * @since 2.0.0\n */\n let_ as let\n}\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @category Do notation\n * @since 2.0.0\n */\nexport const bind: {\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @category Do notation\n * @since 2.0.0\n */\n <N extends string, A extends object, B>(name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Option<B>): (self: Option<A>) => Option<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @category Do notation\n * @since 2.0.0\n */\n <A extends object, N extends string, B>(\n self: Option<A>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => Option<B>\n ): Option<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n} = doNotation.bind<OptionTypeLambda>(map, flatMap)\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link bindTo}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @category Do notation\n * @since 2.0.0\n */\nexport const Do: Option<{}> = some({})\n\nconst adapter = Gen.adapter<OptionTypeLambda>()\n\n/**\n * Similar to `Effect.gen`, `Option.gen` provides a more readable,\n * generator-based syntax for working with `Option` values, making code that\n * involves `Option` easier to write and understand. This approach is similar to\n * using `async/await` but tailored for `Option`.\n *\n * **Example** (Using `Option.gen` to Create a Combined Value)\n *\n * ```ts\n * import { Option } from \"effect\"\n *\n * const maybeName: Option.Option<string> = Option.some(\"John\")\n * const maybeAge: Option.Option<number> = Option.some(25)\n *\n * const person = Option.gen(function* () {\n * const name = (yield* maybeName).toUpperCase()\n * const age = yield* maybeAge\n * return { name, age }\n * })\n *\n * console.log(person)\n * // Output:\n * // { _id: 'Option', _tag: 'Some', value: { name: 'JOHN', age: 25 } }\n * ```\n *\n * @category Generators\n * @since 2.0.0\n */\nexport const gen: Gen.Gen<OptionTypeLambda, Gen.Adapter<OptionTypeLambda>> = (...args) => {\n const f = args.length === 1 ? args[0] : args[1].bind(args[0])\n const iterator = f(adapter)\n let state: IteratorResult<any> = iterator.next()\n while (!state.done) {\n const current = Gen.isGenKind(state.value)\n ? state.value.value\n : Gen.yieldWrapGet(state.value)\n if (isNone(current)) {\n return current\n }\n state = iterator.next(current.value as never)\n }\n return some(state.value)\n}\n\n/**\n * Merges two optional values, applying a function if both exist.\n * Unlike {@link zipWith}, this function returns `None` only if both inputs are `None`.\n *\n * @internal\n */\nexport const mergeWith = <A>(f: (a1: A, a2: A) => A) => (o1: Option<A>, o2: Option<A>): Option<A> => {\n if (isNone(o1)) {\n return o2\n } else if (isNone(o2)) {\n return o1\n }\n return some(f(o1.value, o2.value))\n}\n","/**\n * This module provides utility functions for working with arrays in TypeScript.\n *\n * @since 2.0.0\n */\n\nimport * as Either from \"./Either.js\"\nimport * as Equal from \"./Equal.js\"\nimport * as Equivalence from \"./Equivalence.js\"\nimport type { LazyArg } from \"./Function.js\"\nimport { dual, identity } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\nimport * as internalArray from \"./internal/array.js\"\nimport * as internalDoNotation from \"./internal/doNotation.js\"\nimport * as moduleIterable from \"./Iterable.js\"\nimport * as Option from \"./Option.js\"\nimport * as Order from \"./Order.js\"\nimport * as Predicate from \"./Predicate.js\"\nimport * as Record from \"./Record.js\"\nimport * as Tuple from \"./Tuple.js\"\nimport type { NoInfer } from \"./Types.js\"\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface ReadonlyArrayTypeLambda extends TypeLambda {\n readonly type: ReadonlyArray<this[\"Target\"]>\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport type NonEmptyReadonlyArray<A> = readonly [A, ...Array<A>]\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport type NonEmptyArray<A> = [A, ...Array<A>]\n\n/**\n * Builds a `NonEmptyArray` from an non-empty collection of elements.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.make(1, 2, 3)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const make = <Elements extends NonEmptyArray<any>>(\n ...elements: Elements\n): NonEmptyArray<Elements[number]> => elements\n\n/**\n * Creates a new `Array` of the specified length.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.allocate<number>(3)\n * console.log(result) // [ <3 empty items> ]\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const allocate = <A = never>(n: number): Array<A | undefined> => new Array(n)\n\n/**\n * Return a `NonEmptyArray` of length `n` with element `i` initialized with `f(i)`.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * **Example**\n *\n * ```ts\n * import { makeBy } from \"effect/Array\"\n *\n * const result = makeBy(5, n => n * 2)\n * console.log(result) // [0, 2, 4, 6, 8]\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const makeBy: {\n /**\n * Return a `NonEmptyArray` of length `n` with element `i` initialized with `f(i)`.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * **Example**\n *\n * ```ts\n * import { makeBy } from \"effect/Array\"\n *\n * const result = makeBy(5, n => n * 2)\n * console.log(result) // [0, 2, 4, 6, 8]\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <A>(f: (i: number) => A): (n: number) => NonEmptyArray<A>\n /**\n * Return a `NonEmptyArray` of length `n` with element `i` initialized with `f(i)`.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * **Example**\n *\n * ```ts\n * import { makeBy } from \"effect/Array\"\n *\n * const result = makeBy(5, n => n * 2)\n * console.log(result) // [0, 2, 4, 6, 8]\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <A>(n: number, f: (i: number) => A): NonEmptyArray<A>\n} = dual(2, <A>(n: number, f: (i: number) => A) => {\n const max = Math.max(1, Math.floor(n))\n const out = new Array(max)\n for (let i = 0; i < max; i++) {\n out[i] = f(i)\n }\n return out as NonEmptyArray<A>\n})\n\n/**\n * Return a `NonEmptyArray` containing a range of integers, including both endpoints.\n *\n * **Example**\n *\n * ```ts\n * import { range } from \"effect/Array\"\n *\n * const result = range(1, 3)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const range = (start: number, end: number): NonEmptyArray<number> =>\n start <= end ? makeBy(end - start + 1, (i) => start + i) : [start]\n\n/**\n * Return a `NonEmptyArray` containing a value repeated the specified number of times.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.replicate(\"a\", 3)\n * console.log(result) // [\"a\", \"a\", \"a\"]\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const replicate: {\n /**\n * Return a `NonEmptyArray` containing a value repeated the specified number of times.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.replicate(\"a\", 3)\n * console.log(result) // [\"a\", \"a\", \"a\"]\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n (n: number): <A>(a: A) => NonEmptyArray<A>\n /**\n * Return a `NonEmptyArray` containing a value repeated the specified number of times.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.replicate(\"a\", 3)\n * console.log(result) // [\"a\", \"a\", \"a\"]\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <A>(a: A, n: number): NonEmptyArray<A>\n} = dual(2, <A>(a: A, n: number): NonEmptyArray<A> => makeBy(n, () => a))\n\n/**\n * Creates a new `Array` from an iterable collection of values.\n * If the input is already an array, it returns the input as-is.\n * Otherwise, it converts the iterable collection to an array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.fromIterable(new Set([1, 2, 3]))\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const fromIterable = <A>(collection: Iterable<A>): Array<A> =>\n Array.isArray(collection) ? collection : Array.from(collection)\n\n/**\n * Creates a new `Array` from a value that might not be an iterable.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * console.log(Array.ensure(\"a\")) // [\"a\"]\n * console.log(Array.ensure([\"a\"])) // [\"a\"]\n * console.log(Array.ensure([\"a\", \"b\", \"c\"])) // [\"a\", \"b\", \"c\"]\n * ```\n *\n * @category constructors\n * @since 3.3.0\n */\nexport const ensure = <A>(self: ReadonlyArray<A> | A): Array<A> => Array.isArray(self) ? self : [self as A]\n\n/**\n * Takes a record and returns an array of tuples containing its keys and values.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.fromRecord({ a: 1, b: 2, c: 3 })\n * console.log(result) // [[\"a\", 1], [\"b\", 2], [\"c\", 3]]\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const fromRecord: <K extends string, A>(self: Readonly<Record<K, A>>) => Array<[K, A]> = Record.toEntries\n\n/**\n * Converts an `Option` to an array.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * console.log(Array.fromOption(Option.some(1))) // [1]\n * console.log(Array.fromOption(Option.none())) // []\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const fromOption: <A>(self: Option.Option<A>) => Array<A> = Option.toArray\n\n/**\n * Matches the elements of an array, applying functions to cases of empty and non-empty arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const match = Array.match({\n * onEmpty: () => \"empty\",\n * onNonEmpty: ([head, ...tail]) => `head: ${head}, tail: ${tail.length}`\n * })\n * console.log(match([])) // \"empty\"\n * console.log(match([1, 2, 3])) // \"head: 1, tail: 2\"\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\nexport const match: {\n /**\n * Matches the elements of an array, applying functions to cases of empty and non-empty arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const match = Array.match({\n * onEmpty: () => \"empty\",\n * onNonEmpty: ([head, ...tail]) => `head: ${head}, tail: ${tail.length}`\n * })\n * console.log(match([])) // \"empty\"\n * console.log(match([1, 2, 3])) // \"head: 1, tail: 2\"\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <B, A, C = B>(\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (self: NonEmptyReadonlyArray<A>) => C\n }\n ): (self: ReadonlyArray<A>) => B | C\n /**\n * Matches the elements of an array, applying functions to cases of empty and non-empty arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const match = Array.match({\n * onEmpty: () => \"empty\",\n * onNonEmpty: ([head, ...tail]) => `head: ${head}, tail: ${tail.length}`\n * })\n * console.log(match([])) // \"empty\"\n * console.log(match([1, 2, 3])) // \"head: 1, tail: 2\"\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <A, B, C = B>(\n self: ReadonlyArray<A>,\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (self: NonEmptyReadonlyArray<A>) => C\n }\n ): B | C\n} = dual(2, <A, B, C = B>(\n self: ReadonlyArray<A>,\n { onEmpty, onNonEmpty }: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (self: NonEmptyReadonlyArray<A>) => C\n }\n): B | C => isNonEmptyReadonlyArray(self) ? onNonEmpty(self) : onEmpty())\n\n/**\n * Matches the elements of an array from the left, applying functions to cases of empty and non-empty arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchLeft = Array.matchLeft({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (head, tail) => `head: ${head}, tail: ${tail.length}`\n * })\n * console.log(matchLeft([])) // \"empty\"\n * console.log(matchLeft([1, 2, 3])) // \"head: 1, tail: 2\"\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\nexport const matchLeft: {\n /**\n * Matches the elements of an array from the left, applying functions to cases of empty and non-empty arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchLeft = Array.matchLeft({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (head, tail) => `head: ${head}, tail: ${tail.length}`\n * })\n * console.log(matchLeft([])) // \"empty\"\n * console.log(matchLeft([1, 2, 3])) // \"head: 1, tail: 2\"\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <B, A, C = B>(\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (head: A, tail: Array<A>) => C\n }\n ): (self: ReadonlyArray<A>) => B | C\n /**\n * Matches the elements of an array from the left, applying functions to cases of empty and non-empty arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchLeft = Array.matchLeft({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (head, tail) => `head: ${head}, tail: ${tail.length}`\n * })\n * console.log(matchLeft([])) // \"empty\"\n * console.log(matchLeft([1, 2, 3])) // \"head: 1, tail: 2\"\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <A, B, C = B>(\n self: ReadonlyArray<A>,\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (head: A, tail: Array<A>) => C\n }\n ): B | C\n} = dual(2, <A, B, C = B>(\n self: ReadonlyArray<A>,\n { onEmpty, onNonEmpty }: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (head: A, tail: Array<A>) => C\n }\n): B | C => isNonEmptyReadonlyArray(self) ? onNonEmpty(headNonEmpty(self), tailNonEmpty(self)) : onEmpty())\n\n/**\n * Matches the elements of an array from the right, applying functions to cases of empty and non-empty arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchRight = Array.matchRight({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (init, last) => `init: ${init.length}, last: ${last}`\n * })\n * console.log(matchRight([])) // \"empty\"\n * console.log(matchRight([1, 2, 3])) // \"init: 2, last: 3\"\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\nexport const matchRight: {\n /**\n * Matches the elements of an array from the right, applying functions to cases of empty and non-empty arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchRight = Array.matchRight({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (init, last) => `init: ${init.length}, last: ${last}`\n * })\n * console.log(matchRight([])) // \"empty\"\n * console.log(matchRight([1, 2, 3])) // \"init: 2, last: 3\"\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <B, A, C = B>(\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (init: Array<A>, last: A) => C\n }\n ): (self: ReadonlyArray<A>) => B | C\n /**\n * Matches the elements of an array from the right, applying functions to cases of empty and non-empty arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchRight = Array.matchRight({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (init, last) => `init: ${init.length}, last: ${last}`\n * })\n * console.log(matchRight([])) // \"empty\"\n * console.log(matchRight([1, 2, 3])) // \"init: 2, last: 3\"\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <A, B, C = B>(\n self: ReadonlyArray<A>,\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (init: Array<A>, last: A) => C\n }\n ): B | C\n} = dual(2, <A, B, C = B>(\n self: ReadonlyArray<A>,\n { onEmpty, onNonEmpty }: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (init: Array<A>, last: A) => C\n }\n): B | C =>\n isNonEmptyReadonlyArray(self) ?\n onNonEmpty(initNonEmpty(self), lastNonEmpty(self)) :\n onEmpty())\n\n/**\n * Prepend an element to the front of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.prepend([2, 3, 4], 1)\n * console.log(result) // [1, 2, 3, 4]\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const prepend: {\n /**\n * Prepend an element to the front of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.prepend([2, 3, 4], 1)\n * console.log(result) // [1, 2, 3, 4]\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <B>(head: B): <A>(self: Iterable<A>) => NonEmptyArray<A | B>\n /**\n * Prepend an element to the front of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.prepend([2, 3, 4], 1)\n * console.log(result) // [1, 2, 3, 4]\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, head: B): NonEmptyArray<A | B>\n} = dual(2, <A, B>(self: Iterable<A>, head: B): NonEmptyArray<A | B> => [head, ...self])\n\n/**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.prependAll([2, 3], [0, 1])\n * console.log(result) // [0, 1, 2, 3]\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const prependAll: {\n /**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.prependAll([2, 3], [0, 1])\n * console.log(result) // [0, 1, 2, 3]\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <S extends Iterable<any>, T extends Iterable<any>>(that: T): (self: S) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>\n /**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.prependAll([2, 3], [0, 1])\n * console.log(result) // [0, 1, 2, 3]\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<A | B>\n /**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.prependAll([2, 3], [0, 1])\n * console.log(result) // [0, 1, 2, 3]\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, that: Iterable<B>): NonEmptyArray<A | B>\n /**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.prependAll([2, 3], [0, 1])\n * console.log(result) // [0, 1, 2, 3]\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B>\n} = dual(\n 2,\n <A>(self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(that).concat(fromIterable(self))\n)\n\n/**\n * Append an element to the end of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.append([1, 2, 3], 4);\n * console.log(result) // [1, 2, 3, 4]\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const append: {\n /**\n * Append an element to the end of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.append([1, 2, 3], 4);\n * console.log(result) // [1, 2, 3, 4]\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <B>(last: B): <A>(self: Iterable<A>) => NonEmptyArray<A | B>\n /**\n * Append an element to the end of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.append([1, 2, 3], 4);\n * console.log(result) // [1, 2, 3, 4]\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, last: B): NonEmptyArray<A | B>\n} = dual(2, <A, B>(self: Iterable<A>, last: B): Array<A | B> => [...self, last])\n\n/**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const appendAll: {\n /**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <S extends Iterable<any>, T extends Iterable<any>>(that: T): (self: S) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>\n /**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<A | B>\n /**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, that: Iterable<B>): NonEmptyArray<A | B>\n /**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B>\n} = dual(\n 2,\n <A>(self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(self).concat(fromIterable(that))\n)\n\n/**\n * Accumulates values from an `Iterable` starting from the left, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.scan([1, 2, 3, 4], 0, (acc, value) => acc + value)\n * console.log(result) // [0, 1, 3, 6, 10]\n *\n * // Explanation:\n * // This function starts with the initial value (0 in this case)\n * // and adds each element of the array to this accumulator one by one,\n * // keeping track of the cumulative sum after each addition.\n * // Each of these sums is captured in the resulting array.\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const scan: {\n /**\n * Accumulates values from an `Iterable` starting from the left, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.scan([1, 2, 3, 4], 0, (acc, value) => acc + value)\n * console.log(result) // [0, 1, 3, 6, 10]\n *\n * // Explanation:\n * // This function starts with the initial value (0 in this case)\n * // and adds each element of the array to this accumulator one by one,\n * // keeping track of the cumulative sum after each addition.\n * // Each of these sums is captured in the resulting array.\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A) => B): (self: Iterable<A>) => NonEmptyArray<B>\n /**\n * Accumulates values from an `Iterable` starting from the left, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.scan([1, 2, 3, 4], 0, (acc, value) => acc + value)\n * console.log(result) // [0, 1, 3, 6, 10]\n *\n * // Explanation:\n * // This function starts with the initial value (0 in this case)\n * // and adds each element of the array to this accumulator one by one,\n * // keeping track of the cumulative sum after each addition.\n * // Each of these sums is captured in the resulting array.\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B>\n} = dual(3, <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B> => {\n const out: NonEmptyArray<B> = [b]\n let i = 0\n for (const a of self) {\n out[i + 1] = f(out[i], a)\n i++\n }\n return out\n})\n\n/**\n * Accumulates values from an `Iterable` starting from the right, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.scanRight([1, 2, 3, 4], 0, (acc, value) => acc + value)\n * console.log(result) // [10, 9, 7, 4, 0]\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const scanRight: {\n /**\n * Accumulates values from an `Iterable` starting from the right, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.scanRight([1, 2, 3, 4], 0, (acc, value) => acc + value)\n * console.log(result) // [10, 9, 7, 4, 0]\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A) => B): (self: Iterable<A>) => NonEmptyArray<B>\n /**\n * Accumulates values from an `Iterable` starting from the right, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.scanRight([1, 2, 3, 4], 0, (acc, value) => acc + value)\n * console.log(result) // [10, 9, 7, 4, 0]\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B>\n} = dual(3, <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B> => {\n const input = fromIterable(self)\n const out: NonEmptyArray<B> = new Array(input.length + 1) as any\n out[input.length] = b\n for (let i = input.length - 1; i >= 0; i--) {\n out[i] = f(out[i + 1], input[i])\n }\n return out\n})\n\n/**\n * Determine if `unknown` is an Array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * console.log(Array.isArray(null)) // false\n * console.log(Array.isArray([1, 2, 3])) // true\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isArray: {\n /**\n * Determine if `unknown` is an Array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * console.log(Array.isArray(null)) // false\n * console.log(Array.isArray([1, 2, 3])) // true\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\n (self: unknown): self is Array<unknown>\n /**\n * Determine if `unknown` is an Array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * console.log(Array.isArray(null)) // false\n * console.log(Array.isArray([1, 2, 3])) // true\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\n <T>(self: T): self is Extract<T, ReadonlyArray<any>>\n} = Array.isArray\n\n/**\n * Determine if an `Array` is empty narrowing down the type to `[]`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * console.log(Array.isEmptyArray([])) // true\n * console.log(Array.isEmptyArray([1, 2, 3])) // false\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isEmptyArray = <A>(self: Array<A>): self is [] => self.length === 0\n\n/**\n * Determine if a `ReadonlyArray` is empty narrowing down the type to `readonly []`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * console.log(Array.isEmptyReadonlyArray([])) // true\n * console.log(Array.isEmptyReadonlyArray([1, 2, 3])) // false\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isEmptyReadonlyArray: <A>(self: ReadonlyArray<A>) => self is readonly [] = isEmptyArray as any\n\n/**\n * Determine if an `Array` is non empty narrowing down the type to `NonEmptyArray`.\n *\n * An `Array` is considered to be a `NonEmptyArray` if it contains at least one element.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * console.log(Array.isNonEmptyArray([])) // false\n * console.log(Array.isNonEmptyArray([1, 2, 3])) // true\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNonEmptyArray: <A>(self: Array<A>) => self is NonEmptyArray<A> = internalArray.isNonEmptyArray\n\n/**\n * Determine if a `ReadonlyArray` is non empty narrowing down the type to `NonEmptyReadonlyArray`.\n *\n * A `ReadonlyArray` is considered to be a `NonEmptyReadonlyArray` if it contains at least one element.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * console.log(Array.isNonEmptyReadonlyArray([])) // false\n * console.log(Array.isNonEmptyReadonlyArray([1, 2, 3])) // true\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNonEmptyReadonlyArray: <A>(self: ReadonlyArray<A>) => self is NonEmptyReadonlyArray<A> =\n internalArray.isNonEmptyArray\n\n/**\n * Return the number of elements in a `ReadonlyArray`.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const length = <A>(self: ReadonlyArray<A>): number => self.length\n\nconst isOutOfBounds = <A>(i: number, as: ReadonlyArray<A>): boolean => i < 0 || i >= as.length\n\nconst clamp = <A>(i: number, as: ReadonlyArray<A>): number => Math.floor(Math.min(Math.max(0, i), as.length))\n\n/**\n * This function provides a safe way to read a value at a particular index from a `ReadonlyArray`.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const get: {\n /**\n * This function provides a safe way to read a value at a particular index from a `ReadonlyArray`.\n *\n * @category getters\n * @since 2.0.0\n */\n (index: number): <A>(self: ReadonlyArray<A>) => Option.Option<A>\n /**\n * This function provides a safe way to read a value at a particular index from a `ReadonlyArray`.\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: ReadonlyArray<A>, index: number): Option.Option<A>\n} = dual(2, <A>(self: ReadonlyArray<A>, index: number): Option.Option<A> => {\n const i = Math.floor(index)\n return isOutOfBounds(i, self) ? Option.none() : Option.some(self[i])\n})\n\n/**\n * Gets an element unsafely, will throw on out of bounds.\n *\n * @since 2.0.0\n * @category unsafe\n */\nexport const unsafeGet: {\n /**\n * Gets an element unsafely, will throw on out of bounds.\n *\n * @since 2.0.0\n * @category unsafe\n */\n (index: number): <A>(self: ReadonlyArray<A>) => A\n /**\n * Gets an element unsafely, will throw on out of bounds.\n *\n * @since 2.0.0\n * @category unsafe\n */\n <A>(self: ReadonlyArray<A>, index: number): A\n} = dual(2, <A>(self: ReadonlyArray<A>, index: number): A => {\n const i = Math.floor(index)\n if (isOutOfBounds(i, self)) {\n throw new Error(`Index ${i} out of bounds`)\n }\n return self[i]\n})\n\n/**\n * Return a tuple containing the first element, and a new `Array` of the remaining elements, if any.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.unprepend([1, 2, 3, 4])\n * console.log(result) // [1, [2, 3, 4]]\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const unprepend = <A>(\n self: NonEmptyReadonlyArray<A>\n): [firstElement: A, remainingElements: Array<A>] => [headNonEmpty(self), tailNonEmpty(self)]\n\n/**\n * Return a tuple containing a copy of the `NonEmptyReadonlyArray` without its last element, and that last element.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.unappend([1, 2, 3, 4])\n * console.log(result) // [[1, 2, 3], 4]\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const unappend = <A>(\n self: NonEmptyReadonlyArray<A>\n): [arrayWithoutLastElement: Array<A>, lastElement: A] => [initNonEmpty(self), lastNonEmpty(self)]\n\n/**\n * Get the first element of a `ReadonlyArray`, or `None` if the `ReadonlyArray` is empty.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const head: <A>(self: ReadonlyArray<A>) => Option.Option<A> = get(0)\n\n/**\n * Get the first element of a non empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.headNonEmpty([1, 2, 3, 4])\n * console.log(result) // 1\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const headNonEmpty: <A>(self: NonEmptyReadonlyArray<A>) => A = unsafeGet(0)\n\n/**\n * Get the last element in a `ReadonlyArray`, or `None` if the `ReadonlyArray` is empty.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const last = <A>(self: ReadonlyArray<A>): Option.Option<A> =>\n isNonEmptyReadonlyArray(self) ? Option.some(lastNonEmpty(self)) : Option.none()\n\n/**\n * Get the last element of a non empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.lastNonEmpty([1, 2, 3, 4])\n * console.log(result) // 4\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const lastNonEmpty = <A>(self: NonEmptyReadonlyArray<A>): A => self[self.length - 1]\n\n/**\n * Get all but the first element of an `Iterable`, creating a new `Array`, or `None` if the `Iterable` is empty.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const tail = <A>(self: Iterable<A>): Option.Option<Array<A>> => {\n const input = fromIterable(self)\n return isNonEmptyReadonlyArray(input) ? Option.some(tailNonEmpty(input)) : Option.none()\n}\n\n/**\n * Get all but the first element of a `NonEmptyReadonlyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.tailNonEmpty([1, 2, 3, 4])\n * console.log(result) // [2, 3, 4]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const tailNonEmpty = <A>(self: NonEmptyReadonlyArray<A>): Array<A> => self.slice(1)\n\n/**\n * Get all but the last element of an `Iterable`, creating a new `Array`, or `None` if the `Iterable` is empty.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const init = <A>(self: Iterable<A>): Option.Option<Array<A>> => {\n const input = fromIterable(self)\n return isNonEmptyReadonlyArray(input) ? Option.some(initNonEmpty(input)) : Option.none()\n}\n\n/**\n * Get all but the last element of a non empty array, creating a new array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.initNonEmpty([1, 2, 3, 4])\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const initNonEmpty = <A>(self: NonEmptyReadonlyArray<A>): Array<A> => self.slice(0, -1)\n\n/**\n * Keep only a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.take([1, 2, 3, 4, 5], 3)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const take: {\n /**\n * Keep only a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.take([1, 2, 3, 4, 5], 3)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Keep only a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.take([1, 2, 3, 4, 5], 3)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n return input.slice(0, clamp(n, input))\n})\n\n/**\n * Keep only a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.takeRight([1, 2, 3, 4, 5], 3)\n * console.log(result) // [3, 4, 5]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const takeRight: {\n /**\n * Keep only a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.takeRight([1, 2, 3, 4, 5], 3)\n * console.log(result) // [3, 4, 5]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Keep only a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.takeRight([1, 2, 3, 4, 5], 3)\n * console.log(result) // [3, 4, 5]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n const i = clamp(n, input)\n return i === 0 ? [] : input.slice(-i)\n})\n\n/**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.takeWhile([1, 3, 2, 4, 1, 2], x => x < 4)\n * console.log(result) // [1, 3, 2]\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const takeWhile: {\n /**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.takeWhile([1, 3, 2, 4, 1, 2], x => x < 4)\n * console.log(result) // [1, 3, 2]\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Array<B>\n /**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.takeWhile([1, 3, 2, 4, 1, 2], x => x < 4)\n * console.log(result) // [1, 3, 2]\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Array<A>\n /**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.takeWhile([1, 3, 2, 4, 1, 2], x => x < 4)\n * console.log(result) // [1, 3, 2]\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Array<B>\n /**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.takeWhile([1, 3, 2, 4, 1, 2], x => x < 4)\n * console.log(result) // [1, 3, 2]\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A>\n} = dual(2, <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A> => {\n let i = 0\n const out: Array<A> = []\n for (const a of self) {\n if (!predicate(a, i)) {\n break\n }\n out.push(a)\n i++\n }\n return out\n})\n\nconst spanIndex = <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): number => {\n let i = 0\n for (const a of self) {\n if (!predicate(a, i)) {\n break\n }\n i++\n }\n return i\n}\n\n/**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const span: {\n /**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => [init: Array<B>, rest: Array<Exclude<A, B>>]\n /**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => [init: Array<A>, rest: Array<A>]\n /**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): [init: Array<B>, rest: Array<Exclude<A, B>>]\n /**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [init: Array<A>, rest: Array<A>]\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [init: Array<A>, rest: Array<A>] =>\n splitAt(self, spanIndex(self, predicate))\n)\n\n/**\n * Drop a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.drop([1, 2, 3, 4, 5], 2)\n * console.log(result) // [3, 4, 5]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const drop: {\n /**\n * Drop a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.drop([1, 2, 3, 4, 5], 2)\n * console.log(result) // [3, 4, 5]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Drop a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.drop([1, 2, 3, 4, 5], 2)\n * console.log(result) // [3, 4, 5]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n return input.slice(clamp(n, input), input.length)\n})\n\n/**\n * Drop a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dropRight([1, 2, 3, 4, 5], 2)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const dropRight: {\n /**\n * Drop a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dropRight([1, 2, 3, 4, 5], 2)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Drop a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dropRight([1, 2, 3, 4, 5], 2)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n return input.slice(0, input.length - clamp(n, input))\n})\n\n/**\n * Remove the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dropWhile([1, 2, 3, 4, 5], x => x < 4)\n * console.log(result) // [4, 5]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const dropWhile: {\n /**\n * Remove the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dropWhile([1, 2, 3, 4, 5], x => x < 4)\n * console.log(result) // [4, 5]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Array<A>\n /**\n * Remove the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dropWhile([1, 2, 3, 4, 5], x => x < 4)\n * console.log(result) // [4, 5]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A>\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A> =>\n fromIterable(self).slice(spanIndex(self, predicate))\n)\n\n/**\n * Return the first index for which a predicate holds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirstIndex([5, 3, 8, 9], x => x > 5)\n * console.log(result) // Option.some(2)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findFirstIndex: {\n /**\n * Return the first index for which a predicate holds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirstIndex([5, 3, 8, 9], x => x > 5)\n * console.log(result) // Option.some(2)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option.Option<number>\n /**\n * Return the first index for which a predicate holds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirstIndex([5, 3, 8, 9], x => x > 5)\n * console.log(result) // Option.some(2)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option.Option<number>\n} = dual(2, <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option.Option<number> => {\n let i = 0\n for (const a of self) {\n if (predicate(a, i)) {\n return Option.some(i)\n }\n i++\n }\n return Option.none()\n})\n\n/**\n * Return the last index for which a predicate holds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLastIndex([1, 3, 8, 9], x => x < 5)\n * console.log(result) // Option.some(1)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findLastIndex: {\n /**\n * Return the last index for which a predicate holds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLastIndex([1, 3, 8, 9], x => x < 5)\n * console.log(result) // Option.some(1)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option.Option<number>\n /**\n * Return the last index for which a predicate holds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLastIndex([1, 3, 8, 9], x => x < 5)\n * console.log(result) // Option.some(1)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option.Option<number>\n} = dual(2, <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option.Option<number> => {\n const input = fromIterable(self)\n for (let i = input.length - 1; i >= 0; i--) {\n if (predicate(input[i], i)) {\n return Option.some(i)\n }\n }\n return Option.none()\n})\n\n/**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirst([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findFirst: {\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirst([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(f: (a: NoInfer<A>, i: number) => Option.Option<B>): (self: Iterable<A>) => Option.Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirst([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Option.Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirst([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option.Option<A>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirst([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option.Option<B>): Option.Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirst([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Option.Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirst([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option.Option<A>\n} = moduleIterable.findFirst\n\n/**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLast([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findLast: {\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLast([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(f: (a: NoInfer<A>, i: number) => Option.Option<B>): (self: Iterable<A>) => Option.Option<B>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLast([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Option.Option<B>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLast([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option.Option<A>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLast([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option.Option<B>): Option.Option<B>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLast([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Option.Option<B>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLast([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option.Option<A>\n} = dual(\n 2,\n <A>(\n self: Iterable<A>,\n f: ((a: A, i: number) => boolean) | ((a: A, i: number) => Option.Option<A>)\n ): Option.Option<A> => {\n const input = fromIterable(self)\n for (let i = input.length - 1; i >= 0; i--) {\n const a = input[i]\n const o = f(a, i)\n if (Predicate.isBoolean(o)) {\n if (o) {\n return Option.some(a)\n }\n } else {\n if (Option.isSome(o)) {\n return o\n }\n }\n }\n return Option.none()\n }\n)\n\n/**\n * Returns a tuple of the first element that satisfies the specified\n * predicate and its index, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirstWithIndex([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some([4, 3])\n * ```\n *\n * @category elements\n * @since 3.17.0\n */\nexport const findFirstWithIndex: {\n /**\n * Returns a tuple of the first element that satisfies the specified\n * predicate and its index, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirstWithIndex([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some([4, 3])\n * ```\n *\n * @category elements\n * @since 3.17.0\n */\n <A, B>(f: (a: NoInfer<A>, i: number) => Option.Option<B>): (self: Iterable<A>) => Option.Option<[B, number]>\n /**\n * Returns a tuple of the first element that satisfies the specified\n * predicate and its index, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirstWithIndex([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some([4, 3])\n * ```\n *\n * @category elements\n * @since 3.17.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Option.Option<[B, number]>\n /**\n * Returns a tuple of the first element that satisfies the specified\n * predicate and its index, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirstWithIndex([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some([4, 3])\n * ```\n *\n * @category elements\n * @since 3.17.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option.Option<[A, number]>\n /**\n * Returns a tuple of the first element that satisfies the specified\n * predicate and its index, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirstWithIndex([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some([4, 3])\n * ```\n *\n * @category elements\n * @since 3.17.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option.Option<B>): Option.Option<[B, number]>\n /**\n * Returns a tuple of the first element that satisfies the specified\n * predicate and its index, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirstWithIndex([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some([4, 3])\n * ```\n *\n * @category elements\n * @since 3.17.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Option.Option<[B, number]>\n /**\n * Returns a tuple of the first element that satisfies the specified\n * predicate and its index, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirstWithIndex([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some([4, 3])\n * ```\n *\n * @category elements\n * @since 3.17.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option.Option<[A, number]>\n} = dual(\n 2,\n <A>(\n self: Iterable<A>,\n f: ((a: A, i: number) => boolean) | ((a: A, i: number) => Option.Option<A>)\n ): Option.Option<[A, number]> => {\n let i = 0\n for (const a of self) {\n const o = f(a, i)\n if (Predicate.isBoolean(o)) {\n if (o) {\n return Option.some([a, i])\n }\n } else {\n if (Option.isSome(o)) {\n return Option.some([o.value, i])\n }\n }\n i++\n }\n return Option.none()\n }\n)\n\n/**\n * Counts all the element of the given array that pass the given predicate\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.countBy([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(result) // 2\n * ```\n *\n * @category folding\n * @since 3.16.0\n */\nexport const countBy: {\n /**\n * Counts all the element of the given array that pass the given predicate\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.countBy([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(result) // 2\n * ```\n *\n * @category folding\n * @since 3.16.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => number\n /**\n * Counts all the element of the given array that pass the given predicate\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.countBy([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(result) // 2\n * ```\n *\n * @category folding\n * @since 3.16.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): number\n} = dual(\n 2,\n <A>(\n self: Iterable<A>,\n f: (a: A, i: number) => boolean\n ): number => {\n let count = 0\n const as = fromIterable(self)\n for (let i = 0; i < as.length; i++) {\n const a = as[i]\n if (f(a, i)) {\n count++\n }\n }\n return count\n }\n)\n\n/**\n * Insert an element at the specified index, creating a new `NonEmptyArray`,\n * or return `None` if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.insertAt(['a', 'b', 'c', 'e'], 3, 'd')\n * console.log(result) // Option.some(['a', 'b', 'c', 'd', 'e'])\n * ```\n *\n * @since 2.0.0\n */\nexport const insertAt: {\n /**\n * Insert an element at the specified index, creating a new `NonEmptyArray`,\n * or return `None` if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.insertAt(['a', 'b', 'c', 'e'], 3, 'd')\n * console.log(result) // Option.some(['a', 'b', 'c', 'd', 'e'])\n * ```\n *\n * @since 2.0.0\n */\n <B>(i: number, b: B): <A>(self: Iterable<A>) => Option.Option<NonEmptyArray<A | B>>\n /**\n * Insert an element at the specified index, creating a new `NonEmptyArray`,\n * or return `None` if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.insertAt(['a', 'b', 'c', 'e'], 3, 'd')\n * console.log(result) // Option.some(['a', 'b', 'c', 'd', 'e'])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, i: number, b: B): Option.Option<NonEmptyArray<A | B>>\n} = dual(3, <A, B>(self: Iterable<A>, i: number, b: B): Option.Option<NonEmptyArray<A | B>> => {\n const out: Array<A | B> = Array.from(self)\n // v--- `= self.length` is ok, it means inserting in last position\n if (i < 0 || i > out.length) {\n return Option.none()\n }\n out.splice(i, 0, b)\n return Option.some(out) as any\n})\n\n/**\n * Change the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.replace(['a', 'b', 'c', 'd'], 1, 'z')\n * console.log(result) // ['a', 'z', 'c', 'd']\n * ```\n *\n * @since 2.0.0\n */\nexport const replace: {\n /**\n * Change the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.replace(['a', 'b', 'c', 'd'], 1, 'z')\n * console.log(result) // ['a', 'z', 'c', 'd']\n * ```\n *\n * @since 2.0.0\n */\n <B>(i: number, b: B): <A, S extends Iterable<A> = Iterable<A>>(\n self: S\n ) => ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n /**\n * Change the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.replace(['a', 'b', 'c', 'd'], 1, 'z')\n * console.log(result) // ['a', 'z', 'c', 'd']\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(self: S, i: number, b: B): ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n} = dual(3, <A, B>(self: Iterable<A>, i: number, b: B): Array<A | B> => modify(self, i, () => b))\n\n/**\n * Replaces an element in an array with the given value, returning an option of the updated array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.replaceOption([1, 2, 3], 1, 4)\n * console.log(result) // Option.some([1, 4, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const replaceOption: {\n /**\n * Replaces an element in an array with the given value, returning an option of the updated array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.replaceOption([1, 2, 3], 1, 4)\n * console.log(result) // Option.some([1, 4, 3])\n * ```\n *\n * @since 2.0.0\n */\n <B>(i: number, b: B): <A, S extends Iterable<A> = Iterable<A>>(\n self: S\n ) => Option.Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>\n /**\n * Replaces an element in an array with the given value, returning an option of the updated array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.replaceOption([1, 2, 3], 1, 4)\n * console.log(result) // Option.some([1, 4, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(self: S, i: number, b: B): Option.Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>\n} = dual(\n 3,\n <A, B>(self: Iterable<A>, i: number, b: B): Option.Option<Array<A | B>> => modifyOption(self, i, () => b)\n)\n\n/**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modify([1, 2, 3, 4], 2, (n) => n * 2)\n * console.log(result) // [1, 2, 6, 4]\n * ```\n *\n * @since 2.0.0\n */\nexport const modify: {\n /**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modify([1, 2, 3, 4], 2, (n) => n * 2)\n * console.log(result) // [1, 2, 6, 4]\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(i: number, f: (a: ReadonlyArray.Infer<S>) => B): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n /**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modify([1, 2, 3, 4], 2, (n) => n * 2)\n * console.log(result) // [1, 2, 6, 4]\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(self: S, i: number, f: (a: ReadonlyArray.Infer<S>) => B): ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n} = dual(\n 3,\n <A, B>(self: Iterable<A>, i: number, f: (a: A) => B): Array<A | B> => {\n const out: Array<A | B> = Array.from(self)\n if (isOutOfBounds(i, out)) {\n return out\n }\n const b = f(out[i] as A)\n out[i] = b\n return out\n }\n)\n\n/**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return `None` if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const input = [1, 2, 3, 4]\n * const result = Array.modifyOption(input, 2, (n) => n * 2)\n * console.log(result) // Option.some([1, 2, 6, 4])\n *\n * const outOfBoundsResult = Array.modifyOption(input, 5, (n) => n * 2)\n * console.log(outOfBoundsResult) // Option.none()\n * ```\n *\n * @since 2.0.0\n */\nexport const modifyOption: {\n /**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return `None` if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const input = [1, 2, 3, 4]\n * const result = Array.modifyOption(input, 2, (n) => n * 2)\n * console.log(result) // Option.some([1, 2, 6, 4])\n *\n * const outOfBoundsResult = Array.modifyOption(input, 5, (n) => n * 2)\n * console.log(outOfBoundsResult) // Option.none()\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(i: number, f: (a: ReadonlyArray.Infer<S>) => B): (self: S) => Option.Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>\n /**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return `None` if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const input = [1, 2, 3, 4]\n * const result = Array.modifyOption(input, 2, (n) => n * 2)\n * console.log(result) // Option.some([1, 2, 6, 4])\n *\n * const outOfBoundsResult = Array.modifyOption(input, 5, (n) => n * 2)\n * console.log(outOfBoundsResult) // Option.none()\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(self: S, i: number, f: (a: ReadonlyArray.Infer<S>) => B): Option.Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>\n} = dual(3, <A, B>(self: Iterable<A>, i: number, f: (a: A) => B): Option.Option<Array<A | B>> => {\n const arr = fromIterable(self)\n if (isOutOfBounds(i, arr)) {\n return Option.none()\n }\n const out: Array<A | B> = Array.isArray(self) ? self.slice() : arr\n const b = f(arr[i])\n out[i] = b\n return Option.some(out)\n})\n\n/**\n * Delete the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const input = [1, 2, 3, 4]\n * const result = Array.remove(input, 2)\n * console.log(result) // [1, 2, 4]\n *\n * const outOfBoundsResult = Array.remove(input, 5)\n * console.log(outOfBoundsResult) // [1, 2, 3, 4]\n * ```\n *\n * @since 2.0.0\n */\nexport const remove: {\n /**\n * Delete the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const input = [1, 2, 3, 4]\n * const result = Array.remove(input, 2)\n * console.log(result) // [1, 2, 4]\n *\n * const outOfBoundsResult = Array.remove(input, 5)\n * console.log(outOfBoundsResult) // [1, 2, 3, 4]\n * ```\n *\n * @since 2.0.0\n */\n (i: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Delete the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const input = [1, 2, 3, 4]\n * const result = Array.remove(input, 2)\n * console.log(result) // [1, 2, 4]\n *\n * const outOfBoundsResult = Array.remove(input, 5)\n * console.log(outOfBoundsResult) // [1, 2, 3, 4]\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, i: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, i: number): Array<A> => {\n const out = Array.from(self)\n if (isOutOfBounds(i, out)) {\n return out\n }\n out.splice(i, 1)\n return out\n})\n\n/**\n * Delete the element at the specified index, creating a new `Array`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.removeOption(numbers, 2)\n * assert.deepStrictEqual(result, Option.some([1, 2, 4]))\n *\n * const outOfBoundsResult = Array.removeOption(numbers, 5)\n * assert.deepStrictEqual(outOfBoundsResult, Option.none())\n * ```\n *\n * @since 3.16.0\n */\nexport const removeOption: {\n /**\n * Delete the element at the specified index, creating a new `Array`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.removeOption(numbers, 2)\n * assert.deepStrictEqual(result, Option.some([1, 2, 4]))\n *\n * const outOfBoundsResult = Array.removeOption(numbers, 5)\n * assert.deepStrictEqual(outOfBoundsResult, Option.none())\n * ```\n *\n * @since 3.16.0\n */\n (i: number): <A>(self: Iterable<A>) => Option.Option<Array<A>>\n /**\n * Delete the element at the specified index, creating a new `Array`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.removeOption(numbers, 2)\n * assert.deepStrictEqual(result, Option.some([1, 2, 4]))\n *\n * const outOfBoundsResult = Array.removeOption(numbers, 5)\n * assert.deepStrictEqual(outOfBoundsResult, Option.none())\n * ```\n *\n * @since 3.16.0\n */\n <A>(self: Iterable<A>, i: number): Option.Option<Array<A>>\n} = dual(2, <A>(self: Iterable<A>, i: number): Option.Option<Array<A>> => {\n const arr = fromIterable(self)\n if (isOutOfBounds(i, arr)) {\n return Option.none()\n }\n const out = Array.isArray(self) ? self.slice() : arr\n out.splice(i, 1)\n return Option.some(out)\n})\n\n/**\n * Reverse an `Iterable`, creating a new `Array`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.reverse([1, 2, 3, 4])\n * console.log(result) // [4, 3, 2, 1]\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const reverse = <S extends Iterable<any>>(\n self: S\n): S extends NonEmptyReadonlyArray<infer A> ? NonEmptyArray<A> : S extends Iterable<infer A> ? Array<A> : never =>\n Array.from(self).reverse() as any\n\n/**\n * Create a new array with elements sorted in increasing order based on the specified comparator.\n * If the input is a `NonEmptyReadonlyArray`, the output will also be a `NonEmptyReadonlyArray`.\n *\n * @category sorting\n * @since 2.0.0\n */\nexport const sort: {\n /**\n * Create a new array with elements sorted in increasing order based on the specified comparator.\n * If the input is a `NonEmptyReadonlyArray`, the output will also be a `NonEmptyReadonlyArray`.\n *\n * @category sorting\n * @since 2.0.0\n */\n <B>(O: Order.Order<B>): <A extends B, S extends Iterable<A>>(self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * Create a new array with elements sorted in increasing order based on the specified comparator.\n * If the input is a `NonEmptyReadonlyArray`, the output will also be a `NonEmptyReadonlyArray`.\n *\n * @category sorting\n * @since 2.0.0\n */\n <A extends B, B>(self: NonEmptyReadonlyArray<A>, O: Order.Order<B>): NonEmptyArray<A>\n /**\n * Create a new array with elements sorted in increasing order based on the specified comparator.\n * If the input is a `NonEmptyReadonlyArray`, the output will also be a `NonEmptyReadonlyArray`.\n *\n * @category sorting\n * @since 2.0.0\n */\n <A extends B, B>(self: Iterable<A>, O: Order.Order<B>): Array<A>\n} = dual(2, <A extends B, B>(self: Iterable<A>, O: Order.Order<B>): Array<A> => {\n const out = Array.from(self)\n out.sort(O)\n return out\n})\n\n/**\n * Sorts an array based on a provided mapping function and order. The mapping\n * function transforms the elements into a value that can be compared, and the\n * order defines how those values should be sorted.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.sortWith([\"aaa\", \"b\", \"cc\"], (s) => s.length, Order.number)\n * console.log(result) // [\"b\", \"cc\", \"aaa\"]\n *\n * // Explanation:\n * // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`\n * // converts each string into its length, and the `Order.number` specifies that the lengths should\n * // be sorted in ascending order.\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\nexport const sortWith: {\n /**\n * Sorts an array based on a provided mapping function and order. The mapping\n * function transforms the elements into a value that can be compared, and the\n * order defines how those values should be sorted.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.sortWith([\"aaa\", \"b\", \"cc\"], (s) => s.length, Order.number)\n * console.log(result) // [\"b\", \"cc\", \"aaa\"]\n *\n * // Explanation:\n * // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`\n * // converts each string into its length, and the `Order.number` specifies that the lengths should\n * // be sorted in ascending order.\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <S extends Iterable<any>, B>(f: (a: ReadonlyArray.Infer<S>) => B, order: Order.Order<B>): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * Sorts an array based on a provided mapping function and order. The mapping\n * function transforms the elements into a value that can be compared, and the\n * order defines how those values should be sorted.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.sortWith([\"aaa\", \"b\", \"cc\"], (s) => s.length, Order.number)\n * console.log(result) // [\"b\", \"cc\", \"aaa\"]\n *\n * // Explanation:\n * // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`\n * // converts each string into its length, and the `Order.number` specifies that the lengths should\n * // be sorted in ascending order.\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B, O: Order.Order<B>): NonEmptyArray<A>\n /**\n * Sorts an array based on a provided mapping function and order. The mapping\n * function transforms the elements into a value that can be compared, and the\n * order defines how those values should be sorted.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.sortWith([\"aaa\", \"b\", \"cc\"], (s) => s.length, Order.number)\n * console.log(result) // [\"b\", \"cc\", \"aaa\"]\n *\n * // Explanation:\n * // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`\n * // converts each string into its length, and the `Order.number` specifies that the lengths should\n * // be sorted in ascending order.\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B>(self: Iterable<A>, f: (a: A) => B, order: Order.Order<B>): Array<A>\n} = dual(\n 3,\n <A, B>(self: Iterable<A>, f: (a: A) => B, order: Order.Order<B>): Array<A> =>\n Array.from(self).map((a) => [a, f(a)] as const).sort(([, a], [, b]) => order(a, b)).map(([_]) => _)\n)\n\n/**\n * Sorts the elements of an `Iterable` in increasing order based on the provided\n * orders. The elements are compared using the first order in `orders`, then the\n * second order if the first comparison is equal, and so on.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Order, pipe } from \"effect\"\n *\n * const users = [\n * { name: \"Alice\", age: 30 },\n * { name: \"Bob\", age: 25 },\n * { name: \"Charlie\", age: 30 }\n * ]\n *\n * const result = pipe(\n * users,\n * Array.sortBy(\n * Order.mapInput(Order.number, (user: (typeof users)[number]) => user.age),\n * Order.mapInput(Order.string, (user: (typeof users)[number]) => user.name)\n * )\n * )\n *\n * console.log(result)\n * // [\n * // { name: \"Bob\", age: 25 },\n * // { name: \"Alice\", age: 30 },\n * // { name: \"Charlie\", age: 30 }\n * // ]\n *\n * // Explanation:\n * // The array of users is sorted first by age in ascending order. When ages are equal,\n * // the users are further sorted by name in ascending order.\n * ```\n *\n * @category sorting\n * @since 2.0.0\n */\nexport const sortBy = <S extends Iterable<any>>(\n ...orders: ReadonlyArray<Order.Order<ReadonlyArray.Infer<S>>>\n) => {\n const sortByAll = sort(Order.combineAll(orders))\n return (\n self: S\n ): S extends NonEmptyReadonlyArray<infer A> ? NonEmptyArray<A> : S extends Iterable<infer A> ? Array<A> : never => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n return sortByAll(input) as any\n }\n return [] as any\n }\n}\n\n/**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zip([1, 2, 3], ['a', 'b'])\n * console.log(result) // [[1, 'a'], [2, 'b']]\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\nexport const zip: {\n /**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zip([1, 2, 3], ['a', 'b'])\n * console.log(result) // [[1, 'a'], [2, 'b']]\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B>(that: NonEmptyReadonlyArray<B>): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<[A, B]>\n /**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zip([1, 2, 3], ['a', 'b'])\n * console.log(result) // [[1, 'a'], [2, 'b']]\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B>(that: Iterable<B>): <A>(self: Iterable<A>) => Array<[A, B]>\n /**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zip([1, 2, 3], ['a', 'b'])\n * console.log(result) // [[1, 'a'], [2, 'b']]\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<[A, B]>\n /**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zip([1, 2, 3], ['a', 'b'])\n * console.log(result) // [[1, 'a'], [2, 'b']]\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<[A, B]>\n} = dual(\n 2,\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<[A, B]> => zipWith(self, that, Tuple.make)\n)\n\n/**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zipWith([1, 2, 3], [4, 5, 6], (a, b) => a + b)\n * console.log(result) // [5, 7, 9]\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\nexport const zipWith: {\n /**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zipWith([1, 2, 3], [4, 5, 6], (a, b) => a + b)\n * console.log(result) // [5, 7, 9]\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B, A, C>(that: NonEmptyReadonlyArray<B>, f: (a: A, b: B) => C): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<C>\n /**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zipWith([1, 2, 3], [4, 5, 6], (a, b) => a + b)\n * console.log(result) // [5, 7, 9]\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Array<C>\n /**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zipWith([1, 2, 3], [4, 5, 6], (a, b) => a + b)\n * console.log(result) // [5, 7, 9]\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, B, C>(\n self: NonEmptyReadonlyArray<A>,\n that: NonEmptyReadonlyArray<B>,\n f: (a: A, b: B) => C\n ): NonEmptyArray<C>\n /**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zipWith([1, 2, 3], [4, 5, 6], (a, b) => a + b)\n * console.log(result) // [5, 7, 9]\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C>\n} = dual(3, <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C> => {\n const as = fromIterable(self)\n const bs = fromIterable(that)\n if (isNonEmptyReadonlyArray(as) && isNonEmptyReadonlyArray(bs)) {\n const out: NonEmptyArray<C> = [f(headNonEmpty(as), headNonEmpty(bs))]\n const len = Math.min(as.length, bs.length)\n for (let i = 1; i < len; i++) {\n out[i] = f(as[i], bs[i])\n }\n return out\n }\n return []\n})\n\n/**\n * This function is the inverse of `zip`. Takes an `Iterable` of pairs and return two corresponding `Array`s.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.unzip([[1, \"a\"], [2, \"b\"], [3, \"c\"]])\n * console.log(result) // [[1, 2, 3], ['a', 'b', 'c']]\n * ```\n *\n * @since 2.0.0\n */\nexport const unzip: <S extends Iterable<readonly [any, any]>>(\n self: S\n) => S extends NonEmptyReadonlyArray<readonly [infer A, infer B]> ? [NonEmptyArray<A>, NonEmptyArray<B>]\n : S extends Iterable<readonly [infer A, infer B]> ? [Array<A>, Array<B>]\n : never = (<A, B>(self: Iterable<readonly [A, B]>): [Array<A>, Array<B>] => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const fa: NonEmptyArray<A> = [input[0][0]]\n const fb: NonEmptyArray<B> = [input[0][1]]\n for (let i = 1; i < input.length; i++) {\n fa[i] = input[i][0]\n fb[i] = input[i][1]\n }\n return [fa, fb]\n }\n return [[], []]\n }) as any\n\n/**\n * Places an element in between members of an `Iterable`.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.intersperse([1, 2, 3], 0)\n * console.log(result) // [1, 0, 2, 0, 3]\n * ```\n *\n * @since 2.0.0\n */\nexport const intersperse: {\n /**\n * Places an element in between members of an `Iterable`.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.intersperse([1, 2, 3], 0)\n * console.log(result) // [1, 0, 2, 0, 3]\n * ```\n *\n * @since 2.0.0\n */\n <B>(middle: B): <S extends Iterable<any>>(self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n /**\n * Places an element in between members of an `Iterable`.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.intersperse([1, 2, 3], 0)\n * console.log(result) // [1, 0, 2, 0, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, middle: B): NonEmptyArray<A | B>\n /**\n * Places an element in between members of an `Iterable`.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.intersperse([1, 2, 3], 0)\n * console.log(result) // [1, 0, 2, 0, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, middle: B): Array<A | B>\n} = dual(2, <A, B>(self: Iterable<A>, middle: B): Array<A | B> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const out: NonEmptyArray<A | B> = [headNonEmpty(input)]\n const tail = tailNonEmpty(input)\n for (let i = 0; i < tail.length; i++) {\n if (i < tail.length) {\n out.push(middle)\n }\n out.push(tail[i])\n }\n return out\n }\n return []\n})\n\n/**\n * Apply a function to the head, creating a new `NonEmptyReadonlyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyHead([1, 2, 3], n => n * 10)\n * console.log(result) // [10, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\nexport const modifyNonEmptyHead: {\n /**\n * Apply a function to the head, creating a new `NonEmptyReadonlyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyHead([1, 2, 3], n => n * 10)\n * console.log(result) // [10, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>\n /**\n * Apply a function to the head, creating a new `NonEmptyReadonlyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyHead([1, 2, 3], n => n * 10)\n * console.log(result) // [10, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B): NonEmptyArray<A | B>\n} = dual(\n 2,\n <A, B>(\n self: NonEmptyReadonlyArray<A>,\n f: (a: A) => B\n ): NonEmptyArray<A | B> => [f(headNonEmpty(self)), ...tailNonEmpty(self)]\n)\n\n/**\n * Change the head, creating a new `NonEmptyReadonlyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyHead([1, 2, 3], 10)\n * console.log(result) // [10, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\nexport const setNonEmptyHead: {\n /**\n * Change the head, creating a new `NonEmptyReadonlyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyHead([1, 2, 3], 10)\n * console.log(result) // [10, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <B>(b: B): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>\n /**\n * Change the head, creating a new `NonEmptyReadonlyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyHead([1, 2, 3], 10)\n * console.log(result) // [10, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B>\n} = dual(\n 2,\n <A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B> => modifyNonEmptyHead(self, () => b)\n)\n\n/**\n * Apply a function to the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyLast([1, 2, 3], n => n * 2)\n * console.log(result) // [1, 2, 6]\n * ```\n *\n * @since 2.0.0\n */\nexport const modifyNonEmptyLast: {\n /**\n * Apply a function to the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyLast([1, 2, 3], n => n * 2)\n * console.log(result) // [1, 2, 6]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>\n /**\n * Apply a function to the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyLast([1, 2, 3], n => n * 2)\n * console.log(result) // [1, 2, 6]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B): NonEmptyArray<A | B>\n} = dual(\n 2,\n <A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B): NonEmptyArray<A | B> =>\n append(initNonEmpty(self), f(lastNonEmpty(self)))\n)\n\n/**\n * Change the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyLast([1, 2, 3], 4)\n * console.log(result) // [1, 2, 4]\n * ```\n *\n * @since 2.0.0\n */\nexport const setNonEmptyLast: {\n /**\n * Change the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyLast([1, 2, 3], 4)\n * console.log(result) // [1, 2, 4]\n * ```\n *\n * @since 2.0.0\n */\n <B>(b: B): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>\n /**\n * Change the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyLast([1, 2, 3], 4)\n * console.log(result) // [1, 2, 4]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B>\n} = dual(\n 2,\n <A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B> => modifyNonEmptyLast(self, () => b)\n)\n\n/**\n * Rotate an `Iterable` by `n` steps.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.rotate(['a', 'b', 'c', 'd', 'e'], 2)\n * console.log(result) // [ 'd', 'e', 'a', 'b', 'c' ]\n * ```\n *\n * @since 2.0.0\n */\nexport const rotate: {\n /**\n * Rotate an `Iterable` by `n` steps.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.rotate(['a', 'b', 'c', 'd', 'e'], 2)\n * console.log(result) // [ 'd', 'e', 'a', 'b', 'c' ]\n * ```\n *\n * @since 2.0.0\n */\n (n: number): <S extends Iterable<any>>(self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * Rotate an `Iterable` by `n` steps.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.rotate(['a', 'b', 'c', 'd', 'e'], 2)\n * console.log(result) // [ 'd', 'e', 'a', 'b', 'c' ]\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, n: number): NonEmptyArray<A>\n /**\n * Rotate an `Iterable` by `n` steps.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.rotate(['a', 'b', 'c', 'd', 'e'], 2)\n * console.log(result) // [ 'd', 'e', 'a', 'b', 'c' ]\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const len = input.length\n const m = Math.round(n) % len\n if (isOutOfBounds(Math.abs(m), input) || m === 0) {\n return copy(input)\n }\n if (m < 0) {\n const [f, s] = splitNonEmptyAt(input, -m)\n return appendAll(s, f)\n } else {\n return rotate(self, m - len)\n }\n }\n return []\n})\n\n/**\n * Returns a function that checks if a `ReadonlyArray` contains a given value using a provided `isEquivalent` function.\n *\n * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const isEquivalent = (a: number, b: number) => a === b\n * const containsNumber = Array.containsWith(isEquivalent)\n * const result = pipe([1, 2, 3, 4], containsNumber(3))\n * console.log(result) // true\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const containsWith = <A>(isEquivalent: (self: A, that: A) => boolean): {\n (a: A): (self: Iterable<A>) => boolean\n (self: Iterable<A>, a: A): boolean\n} =>\n dual(2, (self: Iterable<A>, a: A): boolean => {\n for (const i of self) {\n if (isEquivalent(a, i)) {\n return true\n }\n }\n return false\n })\n\nconst _equivalence = Equal.equivalence()\n\n/**\n * Returns a function that checks if a `ReadonlyArray` contains a given value using the default `Equivalence`.\n *\n * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const result = pipe(['a', 'b', 'c', 'd'], Array.contains('c'))\n * console.log(result) // true\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const contains: {\n /**\n * Returns a function that checks if a `ReadonlyArray` contains a given value using the default `Equivalence`.\n *\n * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const result = pipe(['a', 'b', 'c', 'd'], Array.contains('c'))\n * console.log(result) // true\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(a: A): (self: Iterable<A>) => boolean\n /**\n * Returns a function that checks if a `ReadonlyArray` contains a given value using the default `Equivalence`.\n *\n * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const result = pipe(['a', 'b', 'c', 'd'], Array.contains('c'))\n * console.log(result) // true\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, a: A): boolean\n} = containsWith(_equivalence)\n\n/**\n * A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for \"chopping\" up the input\n * `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a\n * value and the rest of the `Array`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.chop([1, 2, 3, 4, 5], (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * console.log(result) // [2, 4, 6, 8, 10]\n *\n * // Explanation:\n * // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.\n * // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,\n * // resulting in a new array `[2, 4, 6, 8, 10]`.\n * ```\n *\n * @since 2.0.0\n */\nexport const chop: {\n /**\n * A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for \"chopping\" up the input\n * `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a\n * value and the rest of the `Array`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.chop([1, 2, 3, 4, 5], (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * console.log(result) // [2, 4, 6, 8, 10]\n *\n * // Explanation:\n * // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.\n * // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,\n * // resulting in a new array `[2, 4, 6, 8, 10]`.\n * ```\n *\n * @since 2.0.0\n */\n <S extends Iterable<any>, B>(\n f: (as: NonEmptyReadonlyArray<ReadonlyArray.Infer<S>>) => readonly [B, ReadonlyArray<ReadonlyArray.Infer<S>>]\n ): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for \"chopping\" up the input\n * `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a\n * value and the rest of the `Array`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.chop([1, 2, 3, 4, 5], (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * console.log(result) // [2, 4, 6, 8, 10]\n *\n * // Explanation:\n * // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.\n * // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,\n * // resulting in a new array `[2, 4, 6, 8, 10]`.\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: NonEmptyReadonlyArray<A>,\n f: (as: NonEmptyReadonlyArray<A>) => readonly [B, ReadonlyArray<A>]\n ): NonEmptyArray<B>\n /**\n * A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for \"chopping\" up the input\n * `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a\n * value and the rest of the `Array`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.chop([1, 2, 3, 4, 5], (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * console.log(result) // [2, 4, 6, 8, 10]\n *\n * // Explanation:\n * // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.\n * // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,\n * // resulting in a new array `[2, 4, 6, 8, 10]`.\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: Iterable<A>,\n f: (as: NonEmptyReadonlyArray<A>) => readonly [B, ReadonlyArray<A>]\n ): Array<B>\n} = dual(2, <A, B>(\n self: Iterable<A>,\n f: (as: NonEmptyReadonlyArray<A>) => readonly [B, ReadonlyArray<A>]\n): Array<B> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const [b, rest] = f(input)\n const out: NonEmptyArray<B> = [b]\n let next: ReadonlyArray<A> = rest\n while (internalArray.isNonEmptyArray(next)) {\n const [b, rest] = f(next)\n out.push(b)\n next = rest\n }\n return out\n }\n return []\n})\n\n/**\n * Splits an `Iterable` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` can be `0`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitAt([1, 2, 3, 4, 5], 3)\n * console.log(result) // [[1, 2, 3], [4, 5]]\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const splitAt: {\n /**\n * Splits an `Iterable` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` can be `0`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitAt([1, 2, 3, 4, 5], 3)\n * console.log(result) // [[1, 2, 3], [4, 5]]\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => [beforeIndex: Array<A>, fromIndex: Array<A>]\n /**\n * Splits an `Iterable` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` can be `0`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitAt([1, 2, 3, 4, 5], 3)\n * console.log(result) // [[1, 2, 3], [4, 5]]\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): [beforeIndex: Array<A>, fromIndex: Array<A>]\n} = dual(2, <A>(self: Iterable<A>, n: number): [Array<A>, Array<A>] => {\n const input = Array.from(self)\n const _n = Math.floor(n)\n if (isNonEmptyReadonlyArray(input)) {\n if (_n >= 1) {\n return splitNonEmptyAt(input, _n)\n }\n return [[], input]\n }\n return [input, []]\n})\n\n/**\n * Splits a `NonEmptyReadonlyArray` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` must be `>= 1`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitNonEmptyAt([\"a\", \"b\", \"c\", \"d\", \"e\"], 3)\n * console.log(result) // [[\"a\", \"b\", \"c\"], [\"d\", \"e\"]]\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const splitNonEmptyAt: {\n /**\n * Splits a `NonEmptyReadonlyArray` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` must be `>= 1`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitNonEmptyAt([\"a\", \"b\", \"c\", \"d\", \"e\"], 3)\n * console.log(result) // [[\"a\", \"b\", \"c\"], [\"d\", \"e\"]]\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n (n: number): <A>(self: NonEmptyReadonlyArray<A>) => [beforeIndex: NonEmptyArray<A>, fromIndex: Array<A>]\n /**\n * Splits a `NonEmptyReadonlyArray` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` must be `>= 1`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitNonEmptyAt([\"a\", \"b\", \"c\", \"d\", \"e\"], 3)\n * console.log(result) // [[\"a\", \"b\", \"c\"], [\"d\", \"e\"]]\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, n: number): [beforeIndex: NonEmptyArray<A>, fromIndex: Array<A>]\n} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, n: number): [NonEmptyArray<A>, Array<A>] => {\n const _n = Math.max(1, Math.floor(n))\n return _n >= self.length ?\n [copy(self), []] :\n [prepend(self.slice(1, _n), headNonEmpty(self)), self.slice(_n)]\n})\n\n/**\n * Splits this iterable into `n` equally sized arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.split([1, 2, 3, 4, 5, 6, 7, 8], 3)\n * console.log(result) // [[1, 2, 3], [4, 5, 6], [7, 8]]\n * ```\n *\n * @since 2.0.0\n * @category splitting\n */\nexport const split: {\n /**\n * Splits this iterable into `n` equally sized arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.split([1, 2, 3, 4, 5, 6, 7, 8], 3)\n * console.log(result) // [[1, 2, 3], [4, 5, 6], [7, 8]]\n * ```\n *\n * @since 2.0.0\n * @category splitting\n */\n (n: number): <A>(self: Iterable<A>) => Array<Array<A>>\n /**\n * Splits this iterable into `n` equally sized arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.split([1, 2, 3, 4, 5, 6, 7, 8], 3)\n * console.log(result) // [[1, 2, 3], [4, 5, 6], [7, 8]]\n * ```\n *\n * @since 2.0.0\n * @category splitting\n */\n <A>(self: Iterable<A>, n: number): Array<Array<A>>\n} = dual(2, <A>(self: Iterable<A>, n: number) => {\n const input = fromIterable(self)\n return chunksOf(input, Math.ceil(input.length / Math.floor(n)))\n})\n\n/**\n * Splits this iterable on the first element that matches this predicate.\n * Returns a tuple containing two arrays: the first one is before the match, and the second one is from the match onward.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitWhere([1, 2, 3, 4, 5], n => n > 3)\n * console.log(result) // [[1, 2, 3], [4, 5]]\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const splitWhere: {\n /**\n * Splits this iterable on the first element that matches this predicate.\n * Returns a tuple containing two arrays: the first one is before the match, and the second one is from the match onward.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitWhere([1, 2, 3, 4, 5], n => n > 3)\n * console.log(result) // [[1, 2, 3], [4, 5]]\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => [beforeMatch: Array<A>, fromMatch: Array<A>]\n /**\n * Splits this iterable on the first element that matches this predicate.\n * Returns a tuple containing two arrays: the first one is before the match, and the second one is from the match onward.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitWhere([1, 2, 3, 4, 5], n => n > 3)\n * console.log(result) // [[1, 2, 3], [4, 5]]\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [beforeMatch: Array<A>, fromMatch: Array<A>]\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [beforeMatch: Array<A>, fromMatch: Array<A>] =>\n span(self, (a: A, i: number) => !predicate(a, i))\n)\n\n/**\n * Copies an array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.copy([1, 2, 3])\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\nexport const copy: {\n /**\n * Copies an array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.copy([1, 2, 3])\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>): NonEmptyArray<A>\n /**\n * Copies an array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.copy([1, 2, 3])\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: ReadonlyArray<A>): Array<A>\n} = (<A>(self: ReadonlyArray<A>): Array<A> => self.slice()) as any\n\n/**\n * Pads an array.\n * Returns a new array of length `n` with the elements of `array` followed by `fill` elements if `array` is shorter than `n`.\n * If `array` is longer than `n`, the returned array will be a slice of `array` containing the `n` first elements of `array`.\n * If `n` is less than or equal to 0, the returned array will be an empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.pad([1, 2, 3], 6, 0)\n * console.log(result) // [1, 2, 3, 0, 0, 0]\n * ```\n *\n * @since 3.8.4\n */\nexport const pad: {\n /**\n * Pads an array.\n * Returns a new array of length `n` with the elements of `array` followed by `fill` elements if `array` is shorter than `n`.\n * If `array` is longer than `n`, the returned array will be a slice of `array` containing the `n` first elements of `array`.\n * If `n` is less than or equal to 0, the returned array will be an empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.pad([1, 2, 3], 6, 0)\n * console.log(result) // [1, 2, 3, 0, 0, 0]\n * ```\n *\n * @since 3.8.4\n */\n <A, T>(n: number, fill: T): (\n self: Array<A>\n ) => Array<A | T>\n /**\n * Pads an array.\n * Returns a new array of length `n` with the elements of `array` followed by `fill` elements if `array` is shorter than `n`.\n * If `array` is longer than `n`, the returned array will be a slice of `array` containing the `n` first elements of `array`.\n * If `n` is less than or equal to 0, the returned array will be an empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.pad([1, 2, 3], 6, 0)\n * console.log(result) // [1, 2, 3, 0, 0, 0]\n * ```\n *\n * @since 3.8.4\n */\n <A, T>(self: Array<A>, n: number, fill: T): Array<A | T>\n} = dual(3, <A, T>(self: Array<A>, n: number, fill: T): Array<A | T> => {\n if (self.length >= n) {\n return take(self, n)\n }\n return appendAll(\n self,\n makeBy(n - self.length, () => fill)\n )\n})\n\n/**\n * Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of\n * the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive\n * definition of `chunksOf`; it satisfies the property that\n *\n * ```ts skip-type-checking\n * chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))\n * ```\n *\n * whenever `n` evenly divides the length of `self`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.chunksOf([1, 2, 3, 4, 5], 2)\n * console.log(result) // [[1, 2], [3, 4], [5]]\n *\n * // Explanation:\n * // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.\n * // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,\n * // the last chunk contains the remaining elements.\n * // The result is `[[1, 2], [3, 4], [5]]`.\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const chunksOf: {\n /**\n * Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of\n * the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive\n * definition of `chunksOf`; it satisfies the property that\n *\n * ```ts skip-type-checking\n * chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))\n * ```\n *\n * whenever `n` evenly divides the length of `self`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.chunksOf([1, 2, 3, 4, 5], 2)\n * console.log(result) // [[1, 2], [3, 4], [5]]\n *\n * // Explanation:\n * // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.\n * // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,\n * // the last chunk contains the remaining elements.\n * // The result is `[[1, 2], [3, 4], [5]]`.\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n (n: number): <S extends Iterable<any>>(\n self: S\n ) => ReadonlyArray.With<S, NonEmptyArray<ReadonlyArray.Infer<S>>>\n /**\n * Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of\n * the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive\n * definition of `chunksOf`; it satisfies the property that\n *\n * ```ts skip-type-checking\n * chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))\n * ```\n *\n * whenever `n` evenly divides the length of `self`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.chunksOf([1, 2, 3, 4, 5], 2)\n * console.log(result) // [[1, 2], [3, 4], [5]]\n *\n * // Explanation:\n * // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.\n * // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,\n * // the last chunk contains the remaining elements.\n * // The result is `[[1, 2], [3, 4], [5]]`.\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, n: number): NonEmptyArray<NonEmptyArray<A>>\n /**\n * Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of\n * the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive\n * definition of `chunksOf`; it satisfies the property that\n *\n * ```ts skip-type-checking\n * chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))\n * ```\n *\n * whenever `n` evenly divides the length of `self`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.chunksOf([1, 2, 3, 4, 5], 2)\n * console.log(result) // [[1, 2], [3, 4], [5]]\n *\n * // Explanation:\n * // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.\n * // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,\n * // the last chunk contains the remaining elements.\n * // The result is `[[1, 2], [3, 4], [5]]`.\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<NonEmptyArray<A>>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<NonEmptyArray<A>> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n return chop(input, splitNonEmptyAt(n))\n }\n return []\n})\n\n/**\n * Creates sliding windows of size `n` from an `Iterable`.\n * If the number of elements is less than `n` or if `n` is not greater than zero,\n * an empty array is returned.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * assert.deepStrictEqual(Array.window(numbers, 3), [[1, 2, 3], [2, 3, 4], [3, 4, 5]])\n * assert.deepStrictEqual(Array.window(numbers, 6), [])\n * ```\n *\n * @category splitting\n * @since 3.13.2\n */\nexport const window: {\n /**\n * Creates sliding windows of size `n` from an `Iterable`.\n * If the number of elements is less than `n` or if `n` is not greater than zero,\n * an empty array is returned.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * assert.deepStrictEqual(Array.window(numbers, 3), [[1, 2, 3], [2, 3, 4], [3, 4, 5]])\n * assert.deepStrictEqual(Array.window(numbers, 6), [])\n * ```\n *\n * @category splitting\n * @since 3.13.2\n */\n (n: number): <A>(self: Iterable<A>) => Array<Array<A>>\n /**\n * Creates sliding windows of size `n` from an `Iterable`.\n * If the number of elements is less than `n` or if `n` is not greater than zero,\n * an empty array is returned.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * assert.deepStrictEqual(Array.window(numbers, 3), [[1, 2, 3], [2, 3, 4], [3, 4, 5]])\n * assert.deepStrictEqual(Array.window(numbers, 6), [])\n * ```\n *\n * @category splitting\n * @since 3.13.2\n */\n <A>(self: Iterable<A>, n: number): Array<Array<A>>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<Array<A>> => {\n const input = fromIterable(self)\n if (n > 0 && isNonEmptyReadonlyArray(input)) {\n return Array.from(\n { length: input.length - (n - 1) },\n (_, index) => input.slice(index, index + n)\n )\n }\n return []\n})\n\n/**\n * Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s using the provided `isEquivalent` function.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.groupWith([\"a\", \"a\", \"b\", \"b\", \"b\", \"c\", \"a\"], (x, y) => x === y)\n * console.log(result) // [[\"a\", \"a\"], [\"b\", \"b\", \"b\"], [\"c\"], [\"a\"]]\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\nexport const groupWith: {\n /**\n * Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s using the provided `isEquivalent` function.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.groupWith([\"a\", \"a\", \"b\", \"b\", \"b\", \"c\", \"a\"], (x, y) => x === y)\n * console.log(result) // [[\"a\", \"a\"], [\"b\", \"b\", \"b\"], [\"c\"], [\"a\"]]\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\n <A>(isEquivalent: (self: A, that: A) => boolean): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<NonEmptyArray<A>>\n /**\n * Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s using the provided `isEquivalent` function.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.groupWith([\"a\", \"a\", \"b\", \"b\", \"b\", \"c\", \"a\"], (x, y) => x === y)\n * console.log(result) // [[\"a\", \"a\"], [\"b\", \"b\", \"b\"], [\"c\"], [\"a\"]]\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\n <A>(\n self: NonEmptyReadonlyArray<A>,\n isEquivalent: (self: A, that: A) => boolean\n ): NonEmptyArray<NonEmptyArray<A>>\n} = dual(\n 2,\n <A>(self: NonEmptyReadonlyArray<A>, isEquivalent: (self: A, that: A) => boolean): NonEmptyArray<NonEmptyArray<A>> =>\n chop(self, (as) => {\n const h = headNonEmpty(as)\n const out: NonEmptyArray<A> = [h]\n let i = 1\n for (; i < as.length; i++) {\n const a = as[i]\n if (isEquivalent(a, h)) {\n out.push(a)\n } else {\n break\n }\n }\n return [out, as.slice(i)]\n })\n)\n\n/**\n * Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.group([1, 1, 2, 2, 2, 3, 1])\n * console.log(result) // [[1, 1], [2, 2, 2], [3], [1]]\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\nexport const group: <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<NonEmptyArray<A>> = groupWith(\n Equal.equivalence()\n)\n\n/**\n * Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning\n * function on each element, and grouping the results according to values returned\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const people = [\n * { name: \"Alice\", group: \"A\" },\n * { name: \"Bob\", group: \"B\" },\n * { name: \"Charlie\", group: \"A\" }\n * ]\n *\n * const result = Array.groupBy(people, person => person.group)\n * console.log(result)\n * // {\n * // A: [{ name: \"Alice\", group: \"A\" }, { name: \"Charlie\", group: \"A\" }],\n * // B: [{ name: \"Bob\", group: \"B\" }]\n * // }\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\nexport const groupBy: {\n /**\n * Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning\n * function on each element, and grouping the results according to values returned\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const people = [\n * { name: \"Alice\", group: \"A\" },\n * { name: \"Bob\", group: \"B\" },\n * { name: \"Charlie\", group: \"A\" }\n * ]\n *\n * const result = Array.groupBy(people, person => person.group)\n * console.log(result)\n * // {\n * // A: [{ name: \"Alice\", group: \"A\" }, { name: \"Charlie\", group: \"A\" }],\n * // B: [{ name: \"Bob\", group: \"B\" }]\n * // }\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\n <A, K extends string | symbol>(f: (a: A) => K): (self: Iterable<A>) => Record<Record.ReadonlyRecord.NonLiteralKey<K>, NonEmptyArray<A>>\n /**\n * Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning\n * function on each element, and grouping the results according to values returned\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const people = [\n * { name: \"Alice\", group: \"A\" },\n * { name: \"Bob\", group: \"B\" },\n * { name: \"Charlie\", group: \"A\" }\n * ]\n *\n * const result = Array.groupBy(people, person => person.group)\n * console.log(result)\n * // {\n * // A: [{ name: \"Alice\", group: \"A\" }, { name: \"Charlie\", group: \"A\" }],\n * // B: [{ name: \"Bob\", group: \"B\" }]\n * // }\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\n <A, K extends string | symbol>(self: Iterable<A>, f: (a: A) => K): Record<Record.ReadonlyRecord.NonLiteralKey<K>, NonEmptyArray<A>>\n} = dual(2, <A, K extends string | symbol>(\n self: Iterable<A>,\n f: (a: A) => K\n): Record<Record.ReadonlyRecord.NonLiteralKey<K>, NonEmptyArray<A>> => {\n const out: Record<string | symbol, NonEmptyArray<A>> = {}\n for (const a of self) {\n const k = f(a)\n if (Object.prototype.hasOwnProperty.call(out, k)) {\n out[k].push(a)\n } else {\n out[k] = [a]\n }\n }\n return out\n})\n\n/**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const union = Array.unionWith([1, 2], [2, 3], (a, b) => a === b)\n * console.log(union) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\nexport const unionWith: {\n /**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const union = Array.unionWith([1, 2], [2, 3], (a, b) => a === b)\n * console.log(union) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <S extends Iterable<any>, T extends Iterable<any>>(\n that: T,\n isEquivalent: (self: ReadonlyArray.Infer<S>, that: ReadonlyArray.Infer<T>) => boolean\n ): (self: S) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>\n /**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const union = Array.unionWith([1, 2], [2, 3], (a, b) => a === b)\n * console.log(union) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: NonEmptyReadonlyArray<A>,\n that: Iterable<B>,\n isEquivalent: (self: A, that: B) => boolean\n ): NonEmptyArray<A | B>\n /**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const union = Array.unionWith([1, 2], [2, 3], (a, b) => a === b)\n * console.log(union) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: Iterable<A>,\n that: NonEmptyReadonlyArray<B>,\n isEquivalent: (self: A, that: B) => boolean\n ): NonEmptyArray<A | B>\n /**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const union = Array.unionWith([1, 2], [2, 3], (a, b) => a === b)\n * console.log(union) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: Iterable<A>,\n that: Iterable<B>,\n isEquivalent: (self: A, that: B) => boolean\n ): Array<A | B>\n} = dual(3, <A>(self: Iterable<A>, that: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A> => {\n const a = fromIterable(self)\n const b = fromIterable(that)\n if (isNonEmptyReadonlyArray(a)) {\n if (isNonEmptyReadonlyArray(b)) {\n const dedupe = dedupeWith(isEquivalent)\n return dedupe(appendAll(a, b))\n }\n return a\n }\n return b\n})\n\n/**\n * Creates a union of two arrays, removing duplicates.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.union([1, 2], [2, 3])\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\nexport const union: {\n /**\n * Creates a union of two arrays, removing duplicates.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.union([1, 2], [2, 3])\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <T extends Iterable<any>>(that: T): <S extends Iterable<any>>(\n self: S\n ) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>\n /**\n * Creates a union of two arrays, removing duplicates.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.union([1, 2], [2, 3])\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, that: ReadonlyArray<B>): NonEmptyArray<A | B>\n /**\n * Creates a union of two arrays, removing duplicates.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.union([1, 2], [2, 3])\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: ReadonlyArray<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<A | B>\n /**\n * Creates a union of two arrays, removing duplicates.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.union([1, 2], [2, 3])\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B>\n} = dual(2, <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B> => unionWith(self, that, _equivalence))\n\n/**\n * Creates an `Array` of unique values that are included in all given `Iterable`s using the provided `isEquivalent` function.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }]\n * const array2 = [{ id: 3 }, { id: 4 }, { id: 1 }]\n * const isEquivalent = (a: { id: number }, b: { id: number }) => a.id === b.id\n * const result = Array.intersectionWith(isEquivalent)(array2)(array1)\n * console.log(result) // [{ id: 1 }, { id: 3 }]\n * ```\n *\n * @since 2.0.0\n */\nexport const intersectionWith = <A>(isEquivalent: (self: A, that: A) => boolean): {\n (that: Iterable<A>): (self: Iterable<A>) => Array<A>\n (self: Iterable<A>, that: Iterable<A>): Array<A>\n} => {\n const has = containsWith(isEquivalent)\n return dual(\n 2,\n (self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(self).filter((a) => has(that, a))\n )\n}\n\n/**\n * Creates an `Array` of unique values that are included in all given `Iterable`s.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.intersection([1, 2, 3], [3, 4, 1])\n * console.log(result) // [1, 3]\n * ```\n *\n * @since 2.0.0\n */\nexport const intersection: {\n /**\n * Creates an `Array` of unique values that are included in all given `Iterable`s.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.intersection([1, 2, 3], [3, 4, 1])\n * console.log(result) // [1, 3]\n * ```\n *\n * @since 2.0.0\n */\n <B>(that: Iterable<B>): <A>(self: Iterable<A>) => Array<A & B>\n /**\n * Creates an `Array` of unique values that are included in all given `Iterable`s.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.intersection([1, 2, 3], [3, 4, 1])\n * console.log(result) // [1, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A & B>\n} = intersectionWith(_equivalence)\n\n/**\n * Creates a `Array` of values not included in the other given `Iterable` using the provided `isEquivalent` function.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [2, 3, 4]\n * const difference = Array.differenceWith<number>((a, b) => a === b)(array1, array2)\n * console.log(difference) // [1]\n * ```\n *\n * @since 2.0.0\n */\nexport const differenceWith = <A>(isEquivalent: (self: A, that: A) => boolean): {\n (that: Iterable<A>): (self: Iterable<A>) => Array<A>\n (self: Iterable<A>, that: Iterable<A>): Array<A>\n} => {\n const has = containsWith(isEquivalent)\n return dual(\n 2,\n (self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(self).filter((a) => !has(that, a))\n )\n}\n\n/**\n * Creates a `Array` of values not included in the other given `Iterable`.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const difference = Array.difference([1, 2, 3], [2, 3, 4])\n * console.log(difference) // [1]\n * ```\n *\n * @since 2.0.0\n */\nexport const difference: {\n /**\n * Creates a `Array` of values not included in the other given `Iterable`.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const difference = Array.difference([1, 2, 3], [2, 3, 4])\n * console.log(difference) // [1]\n * ```\n *\n * @since 2.0.0\n */\n <A>(that: Iterable<A>): (self: Iterable<A>) => Array<A>\n /**\n * Creates a `Array` of values not included in the other given `Iterable`.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const difference = Array.difference([1, 2, 3], [2, 3, 4])\n * console.log(difference) // [1]\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, that: Iterable<A>): Array<A>\n} = differenceWith(_equivalence)\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const empty: <A = never>() => Array<A> = () => []\n\n/**\n * Constructs a new `NonEmptyArray<A>` from the specified value.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const of = <A>(a: A): NonEmptyArray<A> => [a]\n\n/**\n * @since 2.0.0\n */\nexport declare namespace ReadonlyArray {\n /**\n * @since 2.0.0\n */\n export type Infer<S extends Iterable<any>> = S extends ReadonlyArray<infer A> ? A\n : S extends Iterable<infer A> ? A\n : never\n\n /**\n * @since 2.0.0\n */\n export type With<S extends Iterable<any>, A> = S extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>\n : Array<A>\n\n /**\n * @since 2.0.0\n */\n export type OrNonEmpty<\n S extends Iterable<any>,\n T extends Iterable<any>,\n A\n > = S extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>\n : T extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>\n : Array<A>\n\n /**\n * @since 2.0.0\n */\n export type AndNonEmpty<\n S extends Iterable<any>,\n T extends Iterable<any>,\n A\n > = S extends NonEmptyReadonlyArray<any> ? T extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>\n : Array<A>\n : Array<A>\n\n /**\n * @since 2.0.0\n */\n export type Flatten<T extends ReadonlyArray<ReadonlyArray<any>>> = T extends\n NonEmptyReadonlyArray<NonEmptyReadonlyArray<infer A>> ? NonEmptyArray<A>\n : T extends ReadonlyArray<ReadonlyArray<infer A>> ? Array<A>\n : never\n}\n\n/**\n * @category mapping\n * @since 2.0.0\n */\nexport const map: {\n /**\n * @category mapping\n * @since 2.0.0\n */\n <S extends ReadonlyArray<any>, B>(f: (a: ReadonlyArray.Infer<S>, i: number) => B): (self: S) => ReadonlyArray.With<S, B>\n /**\n * @category mapping\n * @since 2.0.0\n */\n <S extends ReadonlyArray<any>, B>(self: S, f: (a: ReadonlyArray.Infer<S>, i: number) => B): ReadonlyArray.With<S, B>\n} = dual(2, <A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => B): Array<B> => self.map(f))\n\n/**\n * Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatMap: {\n /**\n * Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <S extends ReadonlyArray<any>, T extends ReadonlyArray<any>>(f: (a: ReadonlyArray.Infer<S>, i: number) => T): (self: S) => ReadonlyArray.AndNonEmpty<S, T, ReadonlyArray.Infer<T>>\n /**\n * Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(\n self: NonEmptyReadonlyArray<A>,\n f: (a: A, i: number) => NonEmptyReadonlyArray<B>\n ): NonEmptyArray<B>\n /**\n * Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => ReadonlyArray<B>): Array<B>\n} = dual(\n 2,\n <A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => ReadonlyArray<B>): Array<B> => {\n if (isEmptyReadonlyArray(self)) {\n return []\n }\n const out: Array<B> = []\n for (let i = 0; i < self.length; i++) {\n const inner = f(self[i], i)\n for (let j = 0; j < inner.length; j++) {\n out.push(inner[j])\n }\n }\n return out\n }\n)\n\n/**\n * Combines multiple arrays into a single array by concatenating all elements\n * from each nested array. This function ensures that the structure of nested\n * arrays is collapsed into a single, flat array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.flatten([[1, 2], [], [3, 4], [], [5, 6]])\n * console.log(result) // [1, 2, 3, 4, 5, 6]\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatten: <S extends ReadonlyArray<ReadonlyArray<any>>>(self: S) => ReadonlyArray.Flatten<S> = flatMap(\n identity\n) as any\n\n/**\n * Applies a function to each element of the `Iterable` and filters based on the result, keeping the transformed values where the function returns `Some`.\n * This method combines filtering and mapping functionalities, allowing transformations and filtering of elements based on a single function pass.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none()\n *\n * const result = Array.filterMap([1, 2, 3, 4, 5], evenSquares);\n * console.log(result) // [4, 16]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const filterMap: {\n /**\n * Applies a function to each element of the `Iterable` and filters based on the result, keeping the transformed values where the function returns `Some`.\n * This method combines filtering and mapping functionalities, allowing transformations and filtering of elements based on a single function pass.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none()\n *\n * const result = Array.filterMap([1, 2, 3, 4, 5], evenSquares);\n * console.log(result) // [4, 16]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(f: (a: A, i: number) => Option.Option<B>): (self: Iterable<A>) => Array<B>\n /**\n * Applies a function to each element of the `Iterable` and filters based on the result, keeping the transformed values where the function returns `Some`.\n * This method combines filtering and mapping functionalities, allowing transformations and filtering of elements based on a single function pass.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none()\n *\n * const result = Array.filterMap([1, 2, 3, 4, 5], evenSquares);\n * console.log(result) // [4, 16]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option.Option<B>): Array<B>\n} = dual(\n 2,\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option.Option<B>): Array<B> => {\n const as = fromIterable(self)\n const out: Array<B> = []\n for (let i = 0; i < as.length; i++) {\n const o = f(as[i], i)\n if (Option.isSome(o)) {\n out.push(o.value)\n }\n }\n return out\n }\n)\n\n/**\n * Applies a function to each element of the array and filters based on the result, stopping when a condition is not met.\n * This method combines filtering and mapping in a single pass, and short-circuits, i.e., stops processing, as soon as the function returns `None`.\n * This is useful when you need to transform an array but only up to the point where a certain condition holds true.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none()\n *\n * const result = Array.filterMapWhile([2, 4, 5], toSquareTillOdd)\n * console.log(result) // [4, 16]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const filterMapWhile: {\n /**\n * Applies a function to each element of the array and filters based on the result, stopping when a condition is not met.\n * This method combines filtering and mapping in a single pass, and short-circuits, i.e., stops processing, as soon as the function returns `None`.\n * This is useful when you need to transform an array but only up to the point where a certain condition holds true.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none()\n *\n * const result = Array.filterMapWhile([2, 4, 5], toSquareTillOdd)\n * console.log(result) // [4, 16]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(f: (a: A, i: number) => Option.Option<B>): (self: Iterable<A>) => Array<B>\n /**\n * Applies a function to each element of the array and filters based on the result, stopping when a condition is not met.\n * This method combines filtering and mapping in a single pass, and short-circuits, i.e., stops processing, as soon as the function returns `None`.\n * This is useful when you need to transform an array but only up to the point where a certain condition holds true.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none()\n *\n * const result = Array.filterMapWhile([2, 4, 5], toSquareTillOdd)\n * console.log(result) // [4, 16]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option.Option<B>): Array<B>\n} = dual(2, <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option.Option<B>) => {\n let i = 0\n const out: Array<B> = []\n for (const a of self) {\n const b = f(a, i)\n if (Option.isSome(b)) {\n out.push(b.value)\n } else {\n break\n }\n i++\n }\n return out\n})\n\n/**\n * Applies a function to each element of the `Iterable`, categorizing the results into two separate arrays.\n * This function is particularly useful for operations where each element can result in two possible types,\n * and you want to separate these types into different collections. For instance, separating validation results\n * into successes and failures.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Either } from \"effect\";\n *\n * const isEven = (x: number) => x % 2 === 0\n *\n * const result = Array.partitionMap([1, 2, 3, 4, 5], x =>\n * isEven(x) ? Either.right(x) : Either.left(x)\n * )\n * console.log(result)\n * // [\n * // [1, 3, 5],\n * // [2, 4]\n * // ]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const partitionMap: {\n /**\n * Applies a function to each element of the `Iterable`, categorizing the results into two separate arrays.\n * This function is particularly useful for operations where each element can result in two possible types,\n * and you want to separate these types into different collections. For instance, separating validation results\n * into successes and failures.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Either } from \"effect\";\n *\n * const isEven = (x: number) => x % 2 === 0\n *\n * const result = Array.partitionMap([1, 2, 3, 4, 5], x =>\n * isEven(x) ? Either.right(x) : Either.left(x)\n * )\n * console.log(result)\n * // [\n * // [1, 3, 5],\n * // [2, 4]\n * // ]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B, C>(f: (a: A, i: number) => Either.Either<C, B>): (self: Iterable<A>) => [left: Array<B>, right: Array<C>]\n /**\n * Applies a function to each element of the `Iterable`, categorizing the results into two separate arrays.\n * This function is particularly useful for operations where each element can result in two possible types,\n * and you want to separate these types into different collections. For instance, separating validation results\n * into successes and failures.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Either } from \"effect\";\n *\n * const isEven = (x: number) => x % 2 === 0\n *\n * const result = Array.partitionMap([1, 2, 3, 4, 5], x =>\n * isEven(x) ? Either.right(x) : Either.left(x)\n * )\n * console.log(result)\n * // [\n * // [1, 3, 5],\n * // [2, 4]\n * // ]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B, C>(self: Iterable<A>, f: (a: A, i: number) => Either.Either<C, B>): [left: Array<B>, right: Array<C>]\n} = dual(\n 2,\n <A, B, C>(self: Iterable<A>, f: (a: A, i: number) => Either.Either<C, B>): [left: Array<B>, right: Array<C>] => {\n const left: Array<B> = []\n const right: Array<C> = []\n const as = fromIterable(self)\n for (let i = 0; i < as.length; i++) {\n const e = f(as[i], i)\n if (Either.isLeft(e)) {\n left.push(e.left)\n } else {\n right.push(e.right)\n }\n }\n return [left, right]\n }\n)\n\n/**\n * Retrieves the `Some` values from an `Iterable` of `Option`s, collecting them into an array.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const result = Array.getSomes([Option.some(1), Option.none(), Option.some(2)])\n * console.log(result) // [1, 2]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n\nexport const getSomes: <T extends Iterable<Option.Option<X>>, X = any>(\n self: T\n) => Array<Option.Option.Value<ReadonlyArray.Infer<T>>> = filterMap(identity as any)\n\n/**\n * Retrieves the `Left` values from an `Iterable` of `Either`s, collecting them into an array.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Either } from \"effect\"\n *\n * const result = Array.getLefts([Either.right(1), Either.left(\"err\"), Either.right(2)])\n * console.log(result) // [\"err\"]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const getLefts = <T extends Iterable<Either.Either<any, any>>>(\n self: T\n): Array<Either.Either.Left<ReadonlyArray.Infer<T>>> => {\n const out: Array<any> = []\n for (const a of self) {\n if (Either.isLeft(a)) {\n out.push(a.left)\n }\n }\n\n return out\n}\n\n/**\n * Retrieves the `Right` values from an `Iterable` of `Either`s, collecting them into an array.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Either } from \"effect\"\n *\n * const result = Array.getRights([Either.right(1), Either.left(\"err\"), Either.right(2)])\n * console.log(result) // [1, 2]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const getRights = <T extends Iterable<Either.Either<any, any>>>(\n self: T\n): Array<Either.Either.Right<ReadonlyArray.Infer<T>>> => {\n const out: Array<any> = []\n for (const a of self) {\n if (Either.isRight(a)) {\n out.push(a.right)\n }\n }\n\n return out\n}\n\n/**\n * @category filtering\n * @since 2.0.0\n */\nexport const filter: {\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Array<B>\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Array<A>\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Array<B>\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A>\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A> => {\n const as = fromIterable(self)\n const out: Array<A> = []\n for (let i = 0; i < as.length; i++) {\n if (predicate(as[i], i)) {\n out.push(as[i])\n }\n }\n return out\n }\n)\n\n/**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.partition([1, 2, 3, 4], n => n % 2 === 0)\n * console.log(result) // [[1, 3], [2, 4]]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const partition: {\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.partition([1, 2, 3, 4], n => n % 2 === 0)\n * console.log(result) // [[1, 3], [2, 4]]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (\n self: Iterable<A>\n ) => [excluded: Array<Exclude<A, B>>, satisfying: Array<B>]\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.partition([1, 2, 3, 4], n => n % 2 === 0)\n * console.log(result) // [[1, 3], [2, 4]]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => [excluded: Array<A>, satisfying: Array<A>]\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.partition([1, 2, 3, 4], n => n % 2 === 0)\n * console.log(result) // [[1, 3], [2, 4]]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): [excluded: Array<Exclude<A, B>>, satisfying: Array<B>]\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.partition([1, 2, 3, 4], n => n % 2 === 0)\n * console.log(result) // [[1, 3], [2, 4]]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [excluded: Array<A>, satisfying: Array<A>]\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [excluded: Array<A>, satisfying: Array<A>] => {\n const left: Array<A> = []\n const right: Array<A> = []\n const as = fromIterable(self)\n for (let i = 0; i < as.length; i++) {\n if (predicate(as[i], i)) {\n right.push(as[i])\n } else {\n left.push(as[i])\n }\n }\n return [left, right]\n }\n)\n\n/**\n * Separates an `Iterable` into two arrays based on a predicate.\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const separate: <T extends Iterable<Either.Either<any, any>>>(\n self: T\n) => [Array<Either.Either.Left<ReadonlyArray.Infer<T>>>, Array<Either.Either.Right<ReadonlyArray.Infer<T>>>] =\n partitionMap(identity)\n\n/**\n * Reduces an array from the left.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.reduce([1, 2, 3], 0, (acc, n) => acc + n)\n * console.log(result) // 6\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const reduce: {\n /**\n * Reduces an array from the left.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.reduce([1, 2, 3], 0, (acc, n) => acc + n)\n * console.log(result) // 6\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Iterable<A>) => B\n /**\n * Reduces an array from the left.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.reduce([1, 2, 3], 0, (acc, n) => acc + n)\n * console.log(result) // 6\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B\n} = dual(\n 3,\n <B, A>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B =>\n fromIterable(self).reduce((b, a, i) => f(b, a, i), b)\n)\n\n/**\n * Reduces an array from the right.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.reduceRight([1, 2, 3], 0, (acc, n) => acc + n)\n * console.log(result) // 6\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const reduceRight: {\n /**\n * Reduces an array from the right.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.reduceRight([1, 2, 3], 0, (acc, n) => acc + n)\n * console.log(result) // 6\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Iterable<A>) => B\n /**\n * Reduces an array from the right.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.reduceRight([1, 2, 3], 0, (acc, n) => acc + n)\n * console.log(result) // 6\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B\n} = dual(\n 3,\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B =>\n fromIterable(self).reduceRight((b, a, i) => f(b, a, i), b)\n)\n\n/**\n * Lifts a predicate into an array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n * const to = Array.liftPredicate(isEven)\n * console.log(to(1)) // []\n * console.log(to(2)) // [2]\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\nexport const liftPredicate: { // Note: I intentionally avoid using the NoInfer pattern here.\n <A, B extends A>(refinement: Predicate.Refinement<A, B>): (a: A) => Array<B>\n /**\n * Lifts a predicate into an array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n * const to = Array.liftPredicate(isEven)\n * console.log(to(1)) // []\n * console.log(to(2)) // [2]\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\n <A>(predicate: Predicate.Predicate<A>): <B extends A>(b: B) => Array<B>\n} = <A>(predicate: Predicate.Predicate<A>) => <B extends A>(b: B): Array<B> => predicate(b) ? [b] : []\n\n/**\n * @category lifting\n * @since 2.0.0\n */\nexport const liftOption = <A extends Array<unknown>, B>(\n f: (...a: A) => Option.Option<B>\n) =>\n(...a: A): Array<B> => fromOption(f(...a))\n\n/**\n * @category conversions\n * @since 2.0.0\n */\nexport const fromNullable = <A>(a: A): Array<NonNullable<A>> => a == null ? empty() : [a as NonNullable<A>]\n\n/**\n * @category lifting\n * @since 2.0.0\n */\nexport const liftNullable = <A extends Array<unknown>, B>(\n f: (...a: A) => B | null | undefined\n): (...a: A) => Array<NonNullable<B>> =>\n(...a) => fromNullable(f(...a))\n\n/**\n * Maps over an array and flattens the result, removing null and undefined values.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.flatMapNullable([1, 2, 3], n => (n % 2 === 0 ? null : n))\n * console.log(result) // [1, 3]\n *\n * // Explanation:\n * // The array of numbers [1, 2, 3] is mapped with a function that returns null for even numbers\n * // and the number itself for odd numbers. The resulting array [1, null, 3] is then flattened\n * // to remove null values, resulting in [1, 3].\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatMapNullable: {\n /**\n * Maps over an array and flattens the result, removing null and undefined values.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.flatMapNullable([1, 2, 3], n => (n % 2 === 0 ? null : n))\n * console.log(result) // [1, 3]\n *\n * // Explanation:\n * // The array of numbers [1, 2, 3] is mapped with a function that returns null for even numbers\n * // and the number itself for odd numbers. The resulting array [1, null, 3] is then flattened\n * // to remove null values, resulting in [1, 3].\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B | null | undefined): (self: ReadonlyArray<A>) => Array<NonNullable<B>>\n /**\n * Maps over an array and flattens the result, removing null and undefined values.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.flatMapNullable([1, 2, 3], n => (n % 2 === 0 ? null : n))\n * console.log(result) // [1, 3]\n *\n * // Explanation:\n * // The array of numbers [1, 2, 3] is mapped with a function that returns null for even numbers\n * // and the number itself for odd numbers. The resulting array [1, null, 3] is then flattened\n * // to remove null values, resulting in [1, 3].\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: ReadonlyArray<A>, f: (a: A) => B | null | undefined): Array<NonNullable<B>>\n} = dual(\n 2,\n <A, B>(self: ReadonlyArray<A>, f: (a: A) => B | null | undefined): Array<NonNullable<B>> =>\n flatMap(self, (a) => fromNullable(f(a)))\n)\n\n/**\n * Lifts a function that returns an `Either` into a function that returns an array.\n * If the `Either` is a left, it returns an empty array.\n * If the `Either` is a right, it returns an array with the right value.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Either } from \"effect\"\n *\n * const parseNumber = (s: string): Either.Either<number, Error> =>\n * isNaN(Number(s)) ? Either.left(new Error(\"Not a number\")) : Either.right(Number(s))\n *\n * const liftedParseNumber = Array.liftEither(parseNumber)\n *\n * const result1 = liftedParseNumber(\"42\")\n * console.log(result1) // [42]\n *\n * const result2 = liftedParseNumber(\"not a number\")\n * console.log(result2) // []\n *\n * // Explanation:\n * // The function parseNumber is lifted to return an array.\n * // When parsing \"42\", it returns an Either.left with the number 42, resulting in [42].\n * // When parsing \"not a number\", it returns an Either.right with an error, resulting in an empty array [].\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\nexport const liftEither = <A extends Array<unknown>, E, B>(\n f: (...a: A) => Either.Either<B, E>\n) =>\n(...a: A): Array<B> => {\n const e = f(...a)\n return Either.isLeft(e) ? [] : [e.right]\n}\n\n/**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const every: {\n /**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: ReadonlyArray<A>) => self is ReadonlyArray<B>\n /**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: ReadonlyArray<A>) => boolean\n /**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(self: ReadonlyArray<A>, refinement: (a: A, i: number) => a is B): self is ReadonlyArray<B>\n /**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): boolean\n} = dual(\n 2,\n <A, B extends A>(self: ReadonlyArray<A>, refinement: (a: A, i: number) => a is B): self is ReadonlyArray<B> =>\n self.every(refinement)\n)\n\n/**\n * Check if a predicate holds true for some `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const some: {\n /**\n * Check if a predicate holds true for some `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: ReadonlyArray<A>) => self is NonEmptyReadonlyArray<A>\n /**\n * Check if a predicate holds true for some `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): self is NonEmptyReadonlyArray<A>\n} = dual(\n 2,\n <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): self is NonEmptyReadonlyArray<A> =>\n self.some(predicate)\n)\n\n/**\n * Extends an array with a function that maps each subarray to a value.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.extend([1, 2, 3], as => as.length)\n * console.log(result) // [3, 2, 1]\n *\n * // Explanation:\n * // The function maps each subarray starting from each element to its length.\n * // The subarrays are: [1, 2, 3], [2, 3], [3].\n * // The lengths are: 3, 2, 1.\n * // Therefore, the result is [3, 2, 1].\n * ```\n *\n * @since 2.0.0\n */\nexport const extend: {\n /**\n * Extends an array with a function that maps each subarray to a value.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.extend([1, 2, 3], as => as.length)\n * console.log(result) // [3, 2, 1]\n *\n * // Explanation:\n * // The function maps each subarray starting from each element to its length.\n * // The subarrays are: [1, 2, 3], [2, 3], [3].\n * // The lengths are: 3, 2, 1.\n * // Therefore, the result is [3, 2, 1].\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(f: (as: ReadonlyArray<A>) => B): (self: ReadonlyArray<A>) => Array<B>\n /**\n * Extends an array with a function that maps each subarray to a value.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.extend([1, 2, 3], as => as.length)\n * console.log(result) // [3, 2, 1]\n *\n * // Explanation:\n * // The function maps each subarray starting from each element to its length.\n * // The subarrays are: [1, 2, 3], [2, 3], [3].\n * // The lengths are: 3, 2, 1.\n * // Therefore, the result is [3, 2, 1].\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: ReadonlyArray<A>, f: (as: ReadonlyArray<A>) => B): Array<B>\n} = dual(\n 2,\n <A, B>(self: ReadonlyArray<A>, f: (as: ReadonlyArray<A>) => B): Array<B> => self.map((_, i, as) => f(as.slice(i)))\n)\n\n/**\n * Finds the minimum element in an array based on a comparator.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.min([3, 1, 2], Order.number)\n * console.log(result) // 1\n * ```\n *\n * @since 2.0.0\n */\nexport const min: {\n /**\n * Finds the minimum element in an array based on a comparator.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.min([3, 1, 2], Order.number)\n * console.log(result) // 1\n * ```\n *\n * @since 2.0.0\n */\n <A>(O: Order.Order<A>): (self: NonEmptyReadonlyArray<A>) => A\n /**\n * Finds the minimum element in an array based on a comparator.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.min([3, 1, 2], Order.number)\n * console.log(result) // 1\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A\n} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A => self.reduce(Order.min(O)))\n\n/**\n * Finds the maximum element in an array based on a comparator.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.max([3, 1, 2], Order.number)\n * console.log(result) // 3\n * ```\n *\n * @since 2.0.0\n */\nexport const max: {\n /**\n * Finds the maximum element in an array based on a comparator.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.max([3, 1, 2], Order.number)\n * console.log(result) // 3\n * ```\n *\n * @since 2.0.0\n */\n <A>(O: Order.Order<A>): (self: NonEmptyReadonlyArray<A>) => A\n /**\n * Finds the maximum element in an array based on a comparator.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.max([3, 1, 2], Order.number)\n * console.log(result) // 3\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A\n} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A => self.reduce(Order.max(O)))\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const unfold = <B, A>(b: B, f: (b: B) => Option.Option<readonly [A, B]>): Array<A> => {\n const out: Array<A> = []\n let next: B = b\n let o: Option.Option<readonly [A, B]>\n while (Option.isSome(o = f(next))) {\n const [a, b] = o.value\n out.push(a)\n next = b\n }\n return out\n}\n\n/**\n * This function creates and returns a new `Order` for an array of values based on a given `Order` for the elements of the array.\n * The returned `Order` compares two arrays by applying the given `Order` to each element in the arrays.\n * If all elements are equal, the arrays are then compared based on their length.\n * It is useful when you need to compare two arrays of the same type and you have a specific way of comparing each element of the array.\n *\n * @category instances\n * @since 2.0.0\n */\nexport const getOrder: <A>(O: Order.Order<A>) => Order.Order<ReadonlyArray<A>> = Order.array\n\n/**\n * Creates an equivalence relation for arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const eq = Array.getEquivalence<number>((a, b) => a === b)\n * console.log(eq([1, 2, 3], [1, 2, 3])) // true\n * ```\n *\n * @category instances\n * @since 2.0.0\n */\nexport const getEquivalence: <A>(\n isEquivalent: Equivalence.Equivalence<A>\n) => Equivalence.Equivalence<ReadonlyArray<A>> = Equivalence.array\n\n/**\n * Performs a side-effect for each element of the `Iterable`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * Array.forEach([1, 2, 3], n => console.log(n)) // 1, 2, 3\n * ```\n *\n * @since 2.0.0\n */\nexport const forEach: {\n /**\n * Performs a side-effect for each element of the `Iterable`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * Array.forEach([1, 2, 3], n => console.log(n)) // 1, 2, 3\n * ```\n *\n * @since 2.0.0\n */\n <A>(f: (a: A, i: number) => void): (self: Iterable<A>) => void\n /**\n * Performs a side-effect for each element of the `Iterable`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * Array.forEach([1, 2, 3], n => console.log(n)) // 1, 2, 3\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, f: (a: A, i: number) => void): void\n} = dual(2, <A>(self: Iterable<A>, f: (a: A, i: number) => void): void => fromIterable(self).forEach((a, i) => f(a, i)))\n\n/**\n * Remove duplicates from an `Iterable` using the provided `isEquivalent` function,\n * preserving the order of the first occurrence of each element.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dedupeWith([1, 2, 2, 3, 3, 3], (a, b) => a === b)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\nexport const dedupeWith: {\n /**\n * Remove duplicates from an `Iterable` using the provided `isEquivalent` function,\n * preserving the order of the first occurrence of each element.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dedupeWith([1, 2, 2, 3, 3, 3], (a, b) => a === b)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <S extends Iterable<any>>(\n isEquivalent: (self: ReadonlyArray.Infer<S>, that: ReadonlyArray.Infer<S>) => boolean\n ): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * Remove duplicates from an `Iterable` using the provided `isEquivalent` function,\n * preserving the order of the first occurrence of each element.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dedupeWith([1, 2, 2, 3, 3, 3], (a, b) => a === b)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A>(\n self: NonEmptyReadonlyArray<A>,\n isEquivalent: (self: A, that: A) => boolean\n ): NonEmptyArray<A>\n /**\n * Remove duplicates from an `Iterable` using the provided `isEquivalent` function,\n * preserving the order of the first occurrence of each element.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dedupeWith([1, 2, 2, 3, 3, 3], (a, b) => a === b)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A>\n} = dual(\n 2,\n <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const out: NonEmptyArray<A> = [headNonEmpty(input)]\n const rest = tailNonEmpty(input)\n for (const r of rest) {\n if (out.every((a) => !isEquivalent(r, a))) {\n out.push(r)\n }\n }\n return out\n }\n return []\n }\n)\n\n/**\n * Remove duplicates from an `Iterable`, preserving the order of the first occurrence of each element.\n * The equivalence used to compare elements is provided by `Equal.equivalence()` from the `Equal` module.\n *\n * @since 2.0.0\n */\nexport const dedupe = <S extends Iterable<any>>(\n self: S\n): S extends NonEmptyReadonlyArray<infer A> ? NonEmptyArray<A> : S extends Iterable<infer A> ? Array<A> : never =>\n dedupeWith(self, Equal.equivalence()) as any\n\n/**\n * Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dedupeAdjacentWith([1, 1, 2, 2, 3, 3], (a, b) => a === b)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\nexport const dedupeAdjacentWith: {\n /**\n * Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dedupeAdjacentWith([1, 1, 2, 2, 3, 3], (a, b) => a === b)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A>(isEquivalent: (self: A, that: A) => boolean): (self: Iterable<A>) => Array<A>\n /**\n * Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dedupeAdjacentWith([1, 1, 2, 2, 3, 3], (a, b) => a === b)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A>\n} = dual(2, <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A> => {\n const out: Array<A> = []\n let lastA: Option.Option<A> = Option.none()\n for (const a of self) {\n if (Option.isNone(lastA) || !isEquivalent(a, lastA.value)) {\n out.push(a)\n lastA = Option.some(a)\n }\n }\n return out\n})\n\n/**\n * Deduplicates adjacent elements that are identical.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dedupeAdjacent([1, 1, 2, 2, 3, 3])\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\nexport const dedupeAdjacent: <A>(self: Iterable<A>) => Array<A> = dedupeAdjacentWith(Equal.equivalence())\n\n/**\n * Joins the elements together with \"sep\" in the middle.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const strings = [\"a\", \"b\", \"c\"]\n * const joined = Array.join(strings, \"-\")\n * console.log(joined) // \"a-b-c\"\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\nexport const join: {\n /**\n * Joins the elements together with \"sep\" in the middle.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const strings = [\"a\", \"b\", \"c\"]\n * const joined = Array.join(strings, \"-\")\n * console.log(joined) // \"a-b-c\"\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\n (sep: string): (self: Iterable<string>) => string\n /**\n * Joins the elements together with \"sep\" in the middle.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const strings = [\"a\", \"b\", \"c\"]\n * const joined = Array.join(strings, \"-\")\n * console.log(joined) // \"a-b-c\"\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\n (self: Iterable<string>, sep: string): string\n} = dual(2, (self: Iterable<string>, sep: string): string => fromIterable(self).join(sep))\n\n/**\n * Statefully maps over the chunk, producing new elements of type `B`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.mapAccum([1, 2, 3], 0, (acc, n) => [acc + n, acc + n])\n * console.log(result) // [6, [1, 3, 6]]\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\nexport const mapAccum: {\n /**\n * Statefully maps over the chunk, producing new elements of type `B`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.mapAccum([1, 2, 3], 0, (acc, n) => [acc + n, acc + n])\n * console.log(result) // [6, [1, 3, 6]]\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\n <S, A, B, I extends Iterable<A> = Iterable<A>>(s: S, f: (s: S, a: ReadonlyArray.Infer<I>, i: number) => readonly [S, B]): (self: I) => [state: S, mappedArray: ReadonlyArray.With<I, B>]\n /**\n * Statefully maps over the chunk, producing new elements of type `B`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.mapAccum([1, 2, 3], 0, (acc, n) => [acc + n, acc + n])\n * console.log(result) // [6, [1, 3, 6]]\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\n <S, A, B, I extends Iterable<A> = Iterable<A>>(\n self: I,\n s: S,\n f: (s: S, a: ReadonlyArray.Infer<I>, i: number) => readonly [S, B]\n ): [state: S, mappedArray: ReadonlyArray.With<I, B>]\n} = dual(\n 3,\n <S, A, B>(self: Iterable<A>, s: S, f: (s: S, a: A, i: number) => [S, B]): [state: S, mappedArray: Array<B>] => {\n let i = 0\n let s1 = s\n const out: Array<B> = []\n for (const a of self) {\n const r = f(s1, a, i)\n s1 = r[0]\n out.push(r[1])\n i++\n }\n return [s1, out]\n }\n)\n\n/**\n * Zips this chunk crosswise with the specified chunk using the specified combiner.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.cartesianWith([1, 2], [\"a\", \"b\"], (a, b) => `${a}-${b}`)\n * console.log(result) // [\"1-a\", \"1-b\", \"2-a\", \"2-b\"]\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\nexport const cartesianWith: {\n /**\n * Zips this chunk crosswise with the specified chunk using the specified combiner.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.cartesianWith([1, 2], [\"a\", \"b\"], (a, b) => `${a}-${b}`)\n * console.log(result) // [\"1-a\", \"1-b\", \"2-a\", \"2-b\"]\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B, C>(that: ReadonlyArray<B>, f: (a: A, b: B) => C): (self: ReadonlyArray<A>) => Array<C>\n /**\n * Zips this chunk crosswise with the specified chunk using the specified combiner.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.cartesianWith([1, 2], [\"a\", \"b\"], (a, b) => `${a}-${b}`)\n * console.log(result) // [\"1-a\", \"1-b\", \"2-a\", \"2-b\"]\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B, C>(self: ReadonlyArray<A>, that: ReadonlyArray<B>, f: (a: A, b: B) => C): Array<C>\n} = dual(\n 3,\n <A, B, C>(self: ReadonlyArray<A>, that: ReadonlyArray<B>, f: (a: A, b: B) => C): Array<C> =>\n flatMap(self, (a) => map(that, (b) => f(a, b)))\n)\n\n/**\n * Zips this chunk crosswise with the specified chunk.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.cartesian([1, 2], [\"a\", \"b\"])\n * console.log(result) // [[1, \"a\"], [1, \"b\"], [2, \"a\"], [2, \"b\"]]\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\nexport const cartesian: {\n /**\n * Zips this chunk crosswise with the specified chunk.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.cartesian([1, 2], [\"a\", \"b\"])\n * console.log(result) // [[1, \"a\"], [1, \"b\"], [2, \"a\"], [2, \"b\"]]\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <B>(that: ReadonlyArray<B>): <A>(self: ReadonlyArray<A>) => Array<[A, B]>\n /**\n * Zips this chunk crosswise with the specified chunk.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.cartesian([1, 2], [\"a\", \"b\"])\n * console.log(result) // [[1, \"a\"], [1, \"b\"], [2, \"a\"], [2, \"b\"]]\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B>(self: ReadonlyArray<A>, that: ReadonlyArray<B>): Array<[A, B]>\n} = dual(\n 2,\n <A, B>(self: ReadonlyArray<A>, that: ReadonlyArray<B>): Array<[A, B]> => cartesianWith(self, that, (a, b) => [a, b])\n)\n\n// -------------------------------------------------------------------------------------\n// do notation\n// -------------------------------------------------------------------------------------\n\n/**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const doResult = pipe(\n * Array.Do,\n * Array.bind(\"x\", () => [1, 3, 5]),\n * Array.bind(\"y\", () => [2, 4, 6]),\n * Array.filter(({ x, y }) => x < y), // condition\n * Array.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * console.log(doResult) // [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]]\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @see {@link bindTo}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 3.2.0\n */\nexport const Do: ReadonlyArray<{}> = of({})\n\n/**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const doResult = pipe(\n * Array.Do,\n * Array.bind(\"x\", () => [1, 3, 5]),\n * Array.bind(\"y\", () => [2, 4, 6]),\n * Array.filter(({ x, y }) => x < y), // condition\n * Array.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * console.log(doResult) // [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]]\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 3.2.0\n */\nexport const bind: {\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const doResult = pipe(\n * Array.Do,\n * Array.bind(\"x\", () => [1, 3, 5]),\n * Array.bind(\"y\", () => [2, 4, 6]),\n * Array.filter(({ x, y }) => x < y), // condition\n * Array.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * console.log(doResult) // [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]]\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 3.2.0\n */\n <A extends object, N extends string, B>(tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): (\n self: ReadonlyArray<A>\n ) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const doResult = pipe(\n * Array.Do,\n * Array.bind(\"x\", () => [1, 3, 5]),\n * Array.bind(\"y\", () => [2, 4, 6]),\n * Array.filter(({ x, y }) => x < y), // condition\n * Array.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * console.log(doResult) // [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]]\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 3.2.0\n */\n <A extends object, N extends string, B>(\n self: ReadonlyArray<A>,\n tag: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => ReadonlyArray<B>\n ): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n} = internalDoNotation.bind<ReadonlyArrayTypeLambda>(map, flatMap) as any\n\n/**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const doResult = pipe(\n * Array.Do,\n * Array.bind(\"x\", () => [1, 3, 5]),\n * Array.bind(\"y\", () => [2, 4, 6]),\n * Array.filter(({ x, y }) => x < y), // condition\n * Array.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * console.log(doResult) // [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]]\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 3.2.0\n */\nexport const bindTo: {\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const doResult = pipe(\n * Array.Do,\n * Array.bind(\"x\", () => [1, 3, 5]),\n * Array.bind(\"y\", () => [2, 4, 6]),\n * Array.filter(({ x, y }) => x < y), // condition\n * Array.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * console.log(doResult) // [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]]\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 3.2.0\n */\n <N extends string>(tag: N): <A>(self: ReadonlyArray<A>) => Array<{ [K in N]: A }>\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const doResult = pipe(\n * Array.Do,\n * Array.bind(\"x\", () => [1, 3, 5]),\n * Array.bind(\"y\", () => [2, 4, 6]),\n * Array.filter(({ x, y }) => x < y), // condition\n * Array.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * console.log(doResult) // [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]]\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 3.2.0\n */\n <A, N extends string>(self: ReadonlyArray<A>, tag: N): Array<{ [K in N]: A }>\n} = internalDoNotation.bindTo<ReadonlyArrayTypeLambda>(map) as any\n\nconst let_: {\n <N extends string, B, A extends object>(\n tag: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): (self: ReadonlyArray<A>) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n <N extends string, A extends object, B>(\n self: ReadonlyArray<A>,\n tag: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n} = internalDoNotation.let_<ReadonlyArrayTypeLambda>(map) as any\n\nexport {\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const doResult = pipe(\n * Array.Do,\n * Array.bind(\"x\", () => [1, 3, 5]),\n * Array.bind(\"y\", () => [2, 4, 6]),\n * Array.filter(({ x, y }) => x < y), // condition\n * Array.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * console.log(doResult) // [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]]\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n *\n * ```\n *\n * @see {@link bindTo}\n * @see {@link bind}\n * @see {@link Do}\n *\n * @category do notation\n * @since 3.2.0\n */\n let_ as let\n}\n","import * as Either from \"effect/Either\"\nimport { dual } from \"effect/Function\"\nimport type { TypeLambda } from \"effect/HKT\"\nimport * as Option from \"effect/Option\"\nimport * as Gen from \"effect/Utils\"\n\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\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\nconst evaluate = Symbol.for(\"Nano.evaluate\")\nconst contA = Symbol.for(\"Nano.contA\")\ntype contA = typeof contA\nconst contE = Symbol.for(\"Nano.contE\")\ntype contE = typeof contE\nconst contAll = Symbol.for(\"Nano.contAll\")\ntype contAll = typeof contAll\nconst NanoYield = Symbol.for(\"Nano.yield\")\ntype NanoYield = typeof NanoYield\nconst args = Symbol.for(\"Nano.args\")\ntype args = typeof args\n\nexport class NanoDefectException {\n readonly _tag = \"@effect/language-service/NanoDefectException\"\n constructor(\n readonly message: unknown\n ) {}\n}\n\ninterface NanoPrimitive {\n [args]?: any\n [contA]?: (value: any, fiber: NanoFiber) => NanoPrimitive | NanoYield\n [contE]?: (value: any, fiber: NanoFiber) => NanoPrimitive | NanoYield\n [contAll]?: (fiber: NanoFiber) => NanoPrimitive | NanoYield\n [evaluate]: (fiber: NanoFiber) => NanoPrimitive | NanoYield\n [Symbol.iterator](): NanoIterator<Nano<any, any, any>>\n}\n\ntype NanoExit =\n & NanoPrimitive\n & ({\n _tag: \"Success\"\n value: any\n } | {\n _tag: \"Failure\"\n value: any\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> extends NanoPrimitive {\n readonly \"~nano.success\": A\n readonly \"~nano.error\": E\n readonly \"~nano.requirements\": R\n [Symbol.iterator](): NanoIterator<Nano<A, E, R>>\n}\n\nconst PrimitiveProto: Pick<NanoPrimitive, typeof Symbol.iterator> = {\n [Symbol.iterator]() {\n return new Gen.SingleShotGen(new Gen.YieldWrap(this as any as Nano<any, any, any>))\n }\n}\n\nconst SucceedProto: NanoPrimitive & NanoExit = {\n ...PrimitiveProto,\n _tag: \"Success\",\n get value() {\n return this[args]\n },\n [evaluate](fiber: NanoFiber) {\n const cont = fiber.getCont(contA)\n return cont ? cont[contA](this[args], fiber) : fiber.yieldWith(this)\n }\n}\nexport const succeed: <A>(value: A) => Nano<A, never, never> = <A>(value: A) => {\n const nano = Object.create(SucceedProto)\n nano[args] = value\n return nano\n}\n\nconst FailureProto: NanoPrimitive & NanoExit = {\n ...PrimitiveProto,\n _tag: \"Failure\",\n get value() {\n return this[args]\n },\n [evaluate](fiber: NanoFiber) {\n const cont = fiber.getCont(contE)\n return cont ? cont[contE](this[args], fiber) : fiber.yieldWith(this)\n }\n}\nexport const fail: <E>(error: E) => Nano<never, E, never> = <E>(error: E) => {\n const nano = Object.create(FailureProto)\n nano[args] = error\n return nano\n}\n\nconst SuspendProto: NanoPrimitive = {\n ...PrimitiveProto,\n [evaluate]() {\n return this[args]()\n }\n}\nexport const suspend: <A, E, R>(fn: () => Nano<A, E, R>) => Nano<A, E, R> = <A, E, R>(fn: () => Nano<A, E, R>) => {\n const nano = Object.create(SuspendProto)\n nano[args] = fn\n return nano\n}\n\nclass NanoFiber {\n readonly _stack: Array<NanoPrimitive> = []\n _yielded: NanoExit | undefined = undefined\n _services: Record<string, any> = {}\n _cache: Record<string, WeakMap<any, any>> = {}\n\n runLoop(nano: Nano<any, any, any>) {\n let current: NanoPrimitive | NanoYield = nano\n while (true) {\n current = (current as any)[evaluate](this)\n if (current === NanoYield) {\n return this._yielded\n }\n }\n }\n\n getCont<S extends contA | contE>(this: NanoFiber, symbol: S):\n | (NanoPrimitive & Record<S, (value: any, fiber: NanoFiber) => NanoPrimitive>)\n | undefined\n {\n while (true) {\n const op = this._stack.pop()\n if (!op) return undefined\n const cont = op[contAll] && op[contAll](this)\n if (cont) return { [symbol]: cont } as any\n if (op[symbol]) return op as any\n }\n }\n\n yieldWith(this: NanoFiber, value: NanoExit): NanoYield {\n this._yielded = value\n return NanoYield\n }\n}\n\nexport const unsafeRun = <A, E>(nano: Nano<A, E, never>): Either.Either<A, E | NanoDefectException> => {\n const fiber = new NanoFiber()\n const result = fiber.runLoop(nano)!\n if (result._tag === \"Success\") {\n return Either.right(result.value)\n }\n return Either.left(result.value)\n}\n\nexport const run = <A, E>(nano: Nano<A, E, never>): Either.Either<A, E | NanoDefectException> => {\n try {\n return unsafeRun(nano)\n } catch (e) {\n return Either.left(new NanoDefectException(e))\n }\n}\n\nconst OnSuccessProto: NanoPrimitive = {\n ...PrimitiveProto,\n [evaluate](fiber: NanoFiber) {\n fiber._stack.push(this)\n return this[args]\n }\n}\n\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 const nano = Object.create(OnSuccessProto)\n nano[args] = fa\n nano[contA] = f\n return nano\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) => flatMap(fa, (_) => succeed(f(_))))\n\nconst SyncProto: NanoPrimitive = {\n ...PrimitiveProto,\n [evaluate](fiber) {\n const value = this[args]()\n const cont = fiber.getCont(contA)\n return cont\n ? cont[contA](value, fiber)\n : fiber.yieldWith(succeed(value) as any)\n }\n}\n\nexport const sync = <A>(f: () => A): Nano<A, never, never> => {\n const nano = Object.create(SyncProto)\n nano[args] = f\n return nano\n}\n\nexport const void_ = succeed(undefined)\n\nconst FromIteratorProto: NanoPrimitive = {\n ...PrimitiveProto,\n [contA](value, fiber) {\n const state = this[args][0].next(value)\n if (state.done) return succeed(state.value)\n fiber._stack.push(this)\n return Gen.yieldWrapGet(state.value)\n },\n [evaluate](this: any, fiber: NanoFiber) {\n return this[contA](this[args][1], fiber)\n }\n}\n\nconst unsafeFromIterator = (\n iterator: Iterator<Gen.YieldWrap<Nano<any, any, any>>>,\n initial?: undefined\n) => {\n const nano = Object.create(FromIteratorProto)\n nano[args] = [iterator, initial]\n return nano\n}\n\nexport const gen = <Eff extends Gen.YieldWrap<Nano<any, any, any>>, AEff>(\n ...args: [body: () => Generator<Eff, AEff, never>]\n): Nano<\n AEff,\n [Eff] extends [never] ? never\n : [Eff] extends [Gen.YieldWrap<Nano<infer _A, infer E, infer _R>>] ? E\n : never,\n [Eff] extends [never] ? never\n : [Eff] extends [Gen.YieldWrap<Nano<infer _A, infer _E, infer R>>] ? R\n : never\n> => suspend(() => unsafeFromIterator(args[0]()))\n\nexport const fn = (_: string) =>\n<Eff extends Gen.YieldWrap<Nano<any, any, any>>, AEff, Args extends Array<any>>(\n body: (...args: Args) => Generator<Eff, AEff, never>\n) =>\n(...args: Args): Nano<\n AEff,\n [Eff] extends [never] ? never\n : [Eff] extends [Gen.YieldWrap<Nano<infer _A, infer E, infer _R>>] ? E\n : never,\n [Eff] extends [never] ? never\n : [Eff] extends [Gen.YieldWrap<Nano<infer _A, infer _E, infer R>>] ? R\n : never\n> => suspend(() => unsafeFromIterator(body(...args)))\n\nconst MatchProto: NanoPrimitive = {\n ...PrimitiveProto,\n [evaluate](fiber) {\n fiber._stack.push(this)\n return this[args]\n }\n}\n\nexport const match = <A, B, E, R, C, E2, R2, E3, R3>(\n fa: Nano<A, E, R>,\n opts: {\n onSuccess: (a: A) => Nano<B, E2, R2>\n onFailure: (e: E) => Nano<C, E3, R3>\n }\n): Nano<B, E | E2 | E3, R | R2 | R3> => {\n const nano = Object.create(MatchProto)\n nano[args] = fa\n nano[contA] = opts.onSuccess\n nano[contE] = opts.onFailure\n return nano\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>): Nano<A | B, E2, R | R2> => {\n const nano = Object.create(MatchProto)\n nano[args] = fa\n nano[contE] = f\n return nano\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\nconst ProvideServiceProto: NanoPrimitive = {\n ...PrimitiveProto,\n [evaluate](fiber) {\n const prevServices = fiber._services\n const [fa, tag, value]: [Nano<any, any, any>, NanoTag<any>, any] = this[args]\n fiber._services = {\n ...fiber._services,\n [tag.key]: value\n }\n return match(fa, {\n onSuccess: (_) => {\n fiber._services = prevServices\n return succeed(_)\n },\n onFailure: (_) => {\n fiber._services = prevServices\n return fail(_)\n }\n })\n }\n}\n\nexport const provideService = <I extends NanoTag<any>>(\n tag: I,\n value: I[\"~nano.requirements\"]\n) =>\n<A, E, R>(fa: Nano<A, E, R>): Nano<A, E, Exclude<R, I[\"~nano.requirements\"]>> => {\n const nano = Object.create(ProvideServiceProto)\n nano[args] = [fa, tag, value]\n return nano\n}\n\nconst ServiceProto: NanoPrimitive = {\n ...PrimitiveProto,\n [evaluate](fiber) {\n const tag: NanoTag<any> = this[args]\n if (tag.key in fiber._services) {\n const value = fiber._services[tag.key]\n const cont = fiber.getCont(contA)\n return cont ? cont[contA](value, fiber) : fiber.yieldWith(succeed(value) as any)\n }\n const cont = fiber.getCont(contE)\n return cont\n ? cont[contE](tag, fiber)\n : fiber.yieldWith(fail(new NanoDefectException(`Service ${tag.key} not found`)) as any)\n }\n}\n\nexport const service = <I extends NanoTag<any>>(\n tag: I\n): Nano<I[\"~nano.requirements\"], never, I[\"~nano.requirements\"]> => {\n const nano = Object.create(ServiceProto)\n nano[args] = tag\n return nano\n}\n\nconst CachedProto: NanoPrimitive = {\n ...PrimitiveProto,\n [evaluate](fiber) {\n const [fa, type, key]: [Nano<any, any, any>, string, any] = this[args]\n const cache = fiber._cache[type] || new WeakMap<any, any>()\n fiber._cache[type] = cache\n const cached = cache.get(key)\n if (cached) return cached\n return match(fa, {\n onSuccess: (_) => {\n cache.set(key, succeed(_))\n return succeed(_)\n },\n onFailure: (_) => {\n cache.set(key, fail(_))\n return fail(_)\n }\n })\n }\n}\n\nexport function cachedBy<P extends Array<any>, A, E, R>(\n fa: (...p: P) => Nano<A, E, R>,\n type: string,\n lookupKey: (...p: P) => object\n) {\n return (...p: P): Nano<A, E, R> => {\n const nano = Object.create(CachedProto)\n nano[args] = [fa(...p), type, lookupKey(...p)]\n return nano\n }\n}\n\nexport const option = <A, E, R>(fa: Nano<A, E, R>): Nano<Option.Option<A>, never, R> => {\n const nano = Object.create(MatchProto)\n nano[args] = fa\n nano[contA] = (_: A) => succeed(Option.some(_))\n nano[contE] = (_: E | NanoDefectException) => _ instanceof NanoDefectException ? fail(_) : succeed(Option.none())\n return nano\n}\n\nexport const ignore = <A, E, R>(fa: Nano<A, E, R>): Nano<void, never, R> => {\n const nano = Object.create(MatchProto)\n nano[args] = fa\n nano[contA] = (_: A) => void_\n nano[contE] = (_: E | NanoDefectException) => _ instanceof NanoDefectException ? fail(_) : void_\n return nano\n}\n\nexport const all: <A extends Array<Nano<any, any, any>>>(\n ...args: A\n) => Nano<Array<A[number][\"~nano.success\"]>, A[number][\"~nano.error\"], A[number][\"~nano.requirements\"]> = fn(\"all\")(\n function*<A extends Array<Nano<any, any, any>>>(\n ...args: A\n ) {\n const results = [] as Array<A[number][\"~nano.success\"]>\n for (const fa of args) {\n const result = yield* fa\n results.push(result)\n }\n return results\n }\n)\n\nexport const getTimings = () => [] as Array<string>\n","import { isArray } from \"effect/Array\"\nimport * as Array from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport { hasProperty, isBoolean, isObject, isRecord, isString } from \"effect/Predicate\"\nimport * as Nano from \"./Nano\"\n\nexport type DiagnosticSeverity = \"error\" | \"warning\" | \"message\" | \"suggestion\"\n\nexport interface LanguageServicePluginOptions {\n refactors: boolean\n diagnostics: boolean\n diagnosticSeverity: Record<string, DiagnosticSeverity | \"off\">\n quickinfoEffectParameters: \"always\" | \"never\" | \"whentruncated\"\n quickinfo: boolean\n completions: boolean\n goto: boolean\n inlays: boolean\n allowedDuplicatedPackages: Array<string>\n namespaceImportPackages: Array<string>\n topLevelNamedReexports: \"ignore\" | \"follow\"\n barrelImportPackages: Array<string>\n}\n\nexport const LanguageServicePluginOptions = Nano.Tag<LanguageServicePluginOptions>(\"PluginOptions\")\n\nfunction parseDiagnosticSeverity(config: Record<PropertyKey, unknown>): Record<string, DiagnosticSeverity | \"off\"> {\n if (!isRecord(config)) return {}\n return Object.fromEntries(\n pipe(\n Object.entries(config),\n Array.filter(([key, value]) => isString(key) && isString(value)),\n Array.map(([key, value]) => [String(key).toLowerCase(), String(value).toLowerCase()]),\n Array.filter(([_, value]) =>\n value === \"off\" || value === \"error\" || value === \"warning\" || value === \"message\" || value === \"suggestion\"\n )\n )\n )\n}\n\nexport const defaults: LanguageServicePluginOptions = {\n refactors: true,\n diagnostics: true,\n diagnosticSeverity: {},\n quickinfo: true,\n quickinfoEffectParameters: \"whentruncated\",\n completions: true,\n goto: true,\n inlays: true,\n allowedDuplicatedPackages: [],\n namespaceImportPackages: [],\n barrelImportPackages: [],\n topLevelNamedReexports: \"ignore\"\n}\n\nexport function parse(config: any): LanguageServicePluginOptions {\n return {\n refactors: isObject(config) && hasProperty(config, \"refactors\") && isBoolean(config.refactors)\n ? config.refactors\n : defaults.refactors,\n diagnostics: isObject(config) && hasProperty(config, \"diagnostics\") && isBoolean(config.diagnostics)\n ? config.diagnostics\n : defaults.diagnostics,\n diagnosticSeverity:\n isObject(config) && hasProperty(config, \"diagnosticSeverity\") && isRecord(config.diagnosticSeverity)\n ? parseDiagnosticSeverity(config.diagnosticSeverity)\n : defaults.diagnosticSeverity,\n quickinfo: isObject(config) && hasProperty(config, \"quickinfo\") && isBoolean(config.quickinfo)\n ? config.quickinfo\n : defaults.quickinfo,\n quickinfoEffectParameters: isObject(config) && hasProperty(config, \"quickinfoEffectParameters\") &&\n isString(config.quickinfoEffectParameters) &&\n [\"always\", \"never\", \"whentruncated\"].includes(config.quickinfoEffectParameters.toLowerCase())\n ? config.quickinfoEffectParameters.toLowerCase() as \"always\" | \"never\" | \"whentruncated\"\n : defaults.quickinfoEffectParameters,\n completions: isObject(config) && hasProperty(config, \"completions\") && isBoolean(config.completions)\n ? config.completions\n : defaults.completions,\n goto: isObject(config) && hasProperty(config, \"goto\") && isBoolean(config.goto)\n ? config.goto\n : defaults.goto,\n inlays: isObject(config) && hasProperty(config, \"inlays\") && isBoolean(config.inlays)\n ? config.inlays\n : defaults.inlays,\n allowedDuplicatedPackages: isObject(config) && hasProperty(config, \"allowedDuplicatedPackages\") &&\n isArray(config.allowedDuplicatedPackages) && config.allowedDuplicatedPackages.every(isString)\n ? config.allowedDuplicatedPackages.map((_) => _.toLowerCase())\n : defaults.allowedDuplicatedPackages,\n namespaceImportPackages: isObject(config) && hasProperty(config, \"namespaceImportPackages\") &&\n isArray(config.namespaceImportPackages) && config.namespaceImportPackages.every(isString)\n ? config.namespaceImportPackages.map((_) => _.toLowerCase())\n : defaults.namespaceImportPackages,\n barrelImportPackages: isObject(config) && hasProperty(config, \"barrelImportPackages\") &&\n isArray(config.barrelImportPackages) && config.barrelImportPackages.every(isString)\n ? config.barrelImportPackages.map((_) => _.toLowerCase())\n : defaults.barrelImportPackages,\n topLevelNamedReexports: isObject(config) && hasProperty(config, \"topLevelNamedReexports\") &&\n isString(config.topLevelNamedReexports) &&\n [\"ignore\", \"follow\"].includes(config.topLevelNamedReexports.toLowerCase())\n ? config.topLevelNamedReexports.toLowerCase() as \"ignore\" | \"follow\"\n : defaults.topLevelNamedReexports\n }\n}\n","import type ts from \"typescript\"\nimport * as Nano from \"../core/Nano.js\"\n\ndeclare module \"typescript\" {\n export function insertImports(\n changes: textChanges.ChangeTracker,\n sourceFile: ts.SourceFile,\n imports: ts.ImportDeclaration,\n blankLineBetween: boolean,\n preferences: ts.UserPreferences\n ): void\n\n const nullTransformationContext: ts.TransformationContext\n\n export namespace formatting {\n interface FormattingHost {\n getNewLine?(): string\n }\n\n export interface FormatContext {\n readonly options: ts.FormatCodeSettings\n readonly getRules: unknown\n }\n\n function getFormatContext(options: ts.FormatCodeSettings, host: FormattingHost): FormatContext\n }\n\n export type TextChangesContext = any\n\n export namespace textChanges {\n export interface ChangeNodeOptions extends ConfigurableStartEnd, InsertNodeOptions {}\n export enum LeadingTriviaOption {\n /** Exclude all leading trivia (use getStart()) */\n Exclude = 0,\n /** Include leading trivia and,\n * if there are no line breaks between the node and the previous token,\n * include all trivia between the node and the previous token\n */\n IncludeAll = 1,\n /**\n * Include attached JSDoc comments\n */\n JSDoc = 2,\n /**\n * Only delete trivia on the same line as getStart().\n * Used to avoid deleting leading comments\n */\n StartLine = 3\n }\n export enum TrailingTriviaOption {\n /** Exclude all trailing trivia (use getEnd()) */\n Exclude = 0,\n /** Doesn't include whitespace, but does strip comments */\n ExcludeWhitespace = 1,\n /** Include trailing trivia */\n Include = 2\n }\n export interface ConfigurableStart {\n leadingTriviaOption?: LeadingTriviaOption\n }\n export interface ConfigurableEnd {\n trailingTriviaOption?: TrailingTriviaOption\n }\n export interface InsertNodeOptions {\n /**\n * Text to be inserted before the new node\n */\n prefix?: string\n /**\n * Text to be inserted after the new node\n */\n suffix?: string\n /**\n * Text of inserted node will be formatted with this indentation, otherwise indentation will be inferred from the old node\n */\n indentation?: number\n /**\n * Text of inserted node will be formatted with this delta, otherwise delta will be inferred from the new node kind\n */\n delta?: number\n }\n export interface ConfigurableStartEnd extends ConfigurableStart, ConfigurableEnd {\n }\n export class ChangeTracker {\n static with(\n context: ts.TextChangesContext,\n cb: (tracker: ChangeTracker) => void\n ): Array<ts.FileTextChanges>\n delete(\n sourceFile: ts.SourceFile,\n node: ts.Node | ts.NodeArray<ts.TypeParameterDeclaration>\n ): void\n deleteRange(sourceFile: ts.SourceFile, range: ts.TextRange): void\n replaceNode(\n sourceFile: ts.SourceFile,\n oldNode: ts.Node,\n newNode: ts.Node,\n options?: ts.textChanges.ChangeNodeOptions\n ): void\n insertNodeAt(\n sourceFile: ts.SourceFile,\n pos: number,\n newNode: ts.Node,\n options?: ts.textChanges.InsertNodeOptions\n ): void\n insertNodeBefore(\n sourceFile: ts.SourceFile,\n before: ts.Node,\n newNode: ts.Node,\n blankLineBetween?: boolean,\n options?: ConfigurableStartEnd\n ): void\n insertNodeAfter(sourceFile: ts.SourceFile, after: ts.Node, newNode: ts.Node): void\n insertText(sourceFile: ts.SourceFile, pos: number, text: string): void\n insertCommentBeforeLine(\n sourceFile: ts.SourceFile,\n lineNumber: number,\n position: number,\n commentText: string\n ): void\n }\n export function applyChanges(text: string, changes: ReadonlyArray<ts.TextChange>): string\n }\n\n export function findPrecedingToken(\n position: number,\n sourceFile: ts.SourceFileLike,\n startNode: ts.Node,\n excludeJsdoc?: boolean\n ): ts.Node | undefined\n export function findPrecedingToken(\n position: number,\n sourceFile: ts.SourceFile,\n startNode?: ts.Node,\n excludeJsdoc?: boolean\n ): ts.Node | undefined\n function findChildOfKind<T extends ts.Node>(\n n: ts.Node,\n kind: T[\"kind\"],\n sourceFile: ts.SourceFileLike\n ): T | undefined\n\n export function isMemberName(node: ts.Node): node is ts.MemberName\n export function isKeyword(token: ts.SyntaxKind): token is ts.KeywordSyntaxKind\n\n export interface TypeChecker {\n isTypeAssignableTo(source: ts.Type, target: ts.Type): boolean\n getUnionType(types: ReadonlyArray<ts.Type>): ts.Type\n }\n}\n\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 Array from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport { hasProperty, isFunction, isObject, isString } from \"effect/Predicate\"\nimport type ts from \"typescript\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport interface ModuleWithPackageInfo {\n name: string\n version: string\n hasEffectInPeerDependencies: boolean\n contents: any\n packageDirectory: string\n referencedPackages: Array<string>\n exportsKeys: Array<string>\n}\n\nexport interface TypeScriptUtils {\n parsePackageContentNameAndVersionFromScope: (v: unknown) => ModuleWithPackageInfo | undefined\n findNodeWithLeadingCommentAtPosition: (\n sourceFile: ts.SourceFile,\n position: number\n ) => { node: ts.Node; commentRange: ts.CommentRange } | undefined\n getCommentAtPosition: (sourceFile: ts.SourceFile, pos: number) => ts.CommentRange | undefined\n makeGetModuleSpecifier: () =>\n | ((\n compilerOptions: ts.CompilerOptions,\n importingSourceFile: ts.SourceFile,\n importingSourceFileName: string,\n toFileName: string,\n host: any,\n options?: any\n ) => string)\n | undefined\n resolveModulePattern: (sourceFile: ts.SourceFile, pattern: string) => Array<string>\n getAncestorNodesInRange: (sourceFile: ts.SourceFile, textRange: ts.TextRange) => Array<ts.Node>\n findImportedModuleIdentifierByPackageAndNameOrBarrel: (\n sourceFile: ts.SourceFile,\n packageName: string,\n moduleName: string\n ) => string | undefined\n simplifyTypeNode: (typeNode: ts.TypeNode) => ts.TypeNode\n createEffectGenCallExpressionWithBlock: (\n effectModuleIdentifierName: string,\n statement: ts.Statement | Array<ts.Statement>\n ) => ts.CallExpression\n createReturnYieldStarStatement: (\n expr: ts.Expression\n ) => ts.ReturnStatement\n transformAsyncAwaitToEffectGen: (\n node: ts.FunctionDeclaration | ts.ArrowFunction | ts.FunctionExpression,\n effectModuleName: string,\n onAwait: (expression: ts.Expression) => ts.Expression\n ) => ts.Node\n tryPreserveDeclarationSemantics: (\n nodeToReplace: ts.Node,\n node: ts.Node\n ) => ts.Node\n isNodeInRange: (textRange: ts.TextRange) => (node: ts.Node) => boolean\n toTextRange: (position: number) => ts.TextRange\n parseDataForExtendsClassCompletion: (sourceFile: ts.SourceFile, position: number) => {\n accessedObject: ts.Identifier\n classDeclaration: ts.ClassDeclaration\n className: ts.Identifier\n replacementSpan: ts.TextSpan\n } | undefined\n parseAccessedExpressionForCompletion: (sourceFile: ts.SourceFile, position: number) => {\n accessedObject: ts.Node\n outerNode: ts.Node\n replacementSpan: ts.TextSpan\n } | undefined\n findNodeAtPositionIncludingTrivia: (\n sourceFile: ts.SourceFile,\n position: number\n ) => ts.Node | undefined\n}\nexport const TypeScriptUtils = Nano.Tag<TypeScriptUtils>(\"TypeScriptUtils\")\n\nexport const nanoLayer = <A, E, R>(\n fa: Nano.Nano<A, E, R>\n) =>\n pipe(\n Nano.service(TypeScriptApi.TypeScriptApi),\n Nano.flatMap((ts) => pipe(fa, Nano.provideService(TypeScriptUtils, makeTypeScriptUtils(ts))))\n )\n\nexport function makeTypeScriptUtils(ts: TypeScriptApi.TypeScriptApi): TypeScriptUtils {\n /**\n * Parse internal package info from a scope\n */\n function parsePackageContentNameAndVersionFromScope(v: unknown): ModuleWithPackageInfo | undefined {\n if (!isObject(v)) return\n if (!hasProperty(v, \"packageJsonScope\")) return\n if (!v.packageJsonScope) return\n const packageJsonScope = v.packageJsonScope\n if (!hasProperty(packageJsonScope, \"contents\")) return\n if (!hasProperty(packageJsonScope.contents, \"packageJsonContent\")) return\n const packageJsonContent = packageJsonScope.contents.packageJsonContent\n if (!hasProperty(packageJsonContent, \"name\")) return\n if (!hasProperty(packageJsonContent, \"version\")) return\n if (!hasProperty(packageJsonScope, \"packageDirectory\")) return\n if (!isString(packageJsonScope.packageDirectory)) return\n const { name, version } = packageJsonContent\n if (!isString(name)) return\n if (!isString(version)) return\n const hasEffectInPeerDependencies = hasProperty(packageJsonContent, \"peerDependencies\") &&\n isObject(packageJsonContent.peerDependencies) &&\n hasProperty(packageJsonContent.peerDependencies, \"effect\")\n\n const referencedPackages = Object.keys({\n ...(hasProperty(packageJsonContent, \"dependencies\") && isObject(packageJsonContent.dependencies)\n ? packageJsonContent.dependencies\n : {}),\n ...(hasProperty(packageJsonContent, \"peerDependencies\") && isObject(packageJsonContent.peerDependencies)\n ? packageJsonContent.peerDependencies\n : {}),\n ...(hasProperty(packageJsonContent, \"devDependencies\") && isObject(packageJsonContent.devDependencies)\n ? packageJsonContent.devDependencies\n : {})\n })\n\n const exportsKeys = Object.keys(\n hasProperty(packageJsonContent, \"exports\") && isObject(packageJsonContent.exports)\n ? packageJsonContent.exports\n : {}\n )\n\n return {\n name: name.toLowerCase(),\n version: version.toLowerCase(),\n hasEffectInPeerDependencies,\n contents: packageJsonContent,\n packageDirectory: packageJsonScope.packageDirectory,\n referencedPackages,\n exportsKeys\n }\n }\n\n function resolveModulePattern(sourceFile: ts.SourceFile, pattern: string) {\n if (pattern.indexOf(\"*\") === -1) return [pattern.toLowerCase()]\n const packageJsonScope = parsePackageContentNameAndVersionFromScope(sourceFile)\n const referencedPackages: Array<string> = []\n for (const statement of sourceFile.statements) {\n if (ts.isImportDeclaration(statement) && ts.isStringLiteral(statement.moduleSpecifier)) {\n const moduleSpecifier = statement.moduleSpecifier.text.toLowerCase()\n const packageName = moduleSpecifier.startsWith(\"@\")\n ? moduleSpecifier.split(\"/\", 2).join(\"/\")\n : moduleSpecifier.split(\"/\", 1).join(\"/\")\n referencedPackages.push(packageName)\n }\n }\n return pipe(\n referencedPackages.concat(packageJsonScope?.referencedPackages || []),\n Array.dedupe,\n Array.map((packageName) => packageName.toLowerCase()),\n Array.filter((packageName) =>\n pattern.endsWith(\"*\") &&\n packageName.startsWith(pattern.toLowerCase().substring(0, pattern.length - 1))\n )\n )\n }\n\n function makeGetModuleSpecifier() {\n if (\n !(hasProperty(ts, \"moduleSpecifiers\") && hasProperty(ts.moduleSpecifiers, \"getModuleSpecifier\") &&\n isFunction(ts.moduleSpecifiers.getModuleSpecifier))\n ) return\n const _internal = ts.moduleSpecifiers.getModuleSpecifier\n return (\n compilerOptions: ts.CompilerOptions,\n importingSourceFile: ts.SourceFile,\n importingSourceFileName: string,\n toFileName: string,\n host: any,\n options?: any\n ): string => {\n return _internal(\n compilerOptions,\n importingSourceFile,\n importingSourceFileName,\n toFileName,\n host,\n options\n )\n }\n }\n\n function findNodeWithLeadingCommentAtPosition(sourceFile: ts.SourceFile, position: number) {\n const sourceText = sourceFile.text\n let result: { node: ts.Node; commentRange: ts.CommentRange } | undefined\n\n function find(node: ts.Node) {\n // Check leading comments\n const leading = ts.getLeadingCommentRanges(sourceText, node.getFullStart())\n if (leading) {\n for (const commentRange of leading) {\n if (commentRange.pos <= position && position < commentRange.end) {\n // we found the comment\n result = { node, commentRange }\n return\n }\n }\n }\n // Continue traversing only if the position is within this node\n if (node.getFullStart() <= position && position < node.getEnd()) {\n node.forEachChild(find)\n }\n }\n find(sourceFile)\n return result\n }\n\n /**\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 function collectSelfAndAncestorNodesInRange(\n node: ts.Node,\n textRange: ts.TextRange\n ): Array<ts.Node> {\n let result = Array.empty<ts.Node>()\n let parent = node\n while (parent) {\n if (parent.end >= textRange.end) {\n result = pipe(result, Array.append(parent))\n }\n parent = parent.parent\n }\n return result\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 function findNodeAtPosition(\n sourceFile: ts.SourceFile,\n position: number\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 return find(sourceFile)\n }\n\n function findNodeAtPositionIncludingTrivia(\n sourceFile: ts.SourceFile,\n position: number\n ) {\n function find(node: ts.Node): ts.Node | undefined {\n if (position >= node.pos && position < node.end) {\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 return find(sourceFile)\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 */\n function getAncestorNodesInRange(\n sourceFile: ts.SourceFile,\n textRange: ts.TextRange\n ) {\n const nodeAtPosition = findNodeAtPosition(sourceFile, textRange.pos)\n if (!nodeAtPosition) return Array.empty<ts.Node>()\n return collectSelfAndAncestorNodesInRange(nodeAtPosition, textRange)\n }\n\n function getCommentAtPosition(\n sourceFile: ts.SourceFile,\n pos: number\n ) {\n const token = findNodeAtPositionIncludingTrivia(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\n }\n const startPos = token.pos === 0 ? (ts.getShebang(sourceFile.text) || \"\").length : token.pos\n\n if (startPos === 0) return\n\n const result = ts.forEachTrailingCommentRange(sourceFile.text, startPos, isCommentInRange, pos) ||\n ts.forEachLeadingCommentRange(sourceFile.text, startPos, isCommentInRange, pos)\n\n return result\n }\n\n function 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 */\n function toTextRange(positionOrRange: number | ts.TextRange): ts.TextRange {\n return typeof positionOrRange === \"number\"\n ? { end: positionOrRange, pos: positionOrRange }\n : positionOrRange\n }\n\n function isNodeInRange(textRange: ts.TextRange) {\n return (node: ts.Node) => node.pos <= textRange.pos && node.end >= textRange.end\n }\n\n function transformAsyncAwaitToEffectGen(\n node: ts.FunctionDeclaration | ts.ArrowFunction | ts.FunctionExpression,\n effectModuleName: string,\n onAwait: (expression: ts.Expression) => ts.Expression\n ) {\n function visitor(_: ts.Node): ts.Node {\n if (ts.isAwaitExpression(_)) {\n const expression = ts.visitEachChild(_.expression, visitor, ts.nullTransformationContext)\n\n return ts.factory.createYieldExpression(\n ts.factory.createToken(ts.SyntaxKind.AsteriskToken),\n onAwait(expression)\n )\n }\n return ts.visitEachChild(_, visitor, ts.nullTransformationContext)\n }\n const generatorBody = visitor(node.body!)\n\n const effectGenCallExp = 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 function findImportedModuleIdentifier(\n sourceFile: ts.SourceFile,\n test: (\n node: ts.Node,\n fromModule: ts.Expression,\n importProperty: Option.Option<ts.ModuleExportName>\n ) => boolean\n ) {\n for (const statement of sourceFile.statements) {\n if (!ts.isImportDeclaration(statement)) continue\n const importClause = statement.importClause\n if (!importClause) continue\n const namedBindings = importClause.namedBindings\n if (!namedBindings) continue\n if (ts.isNamespaceImport(namedBindings)) {\n if (test(namedBindings.name, statement.moduleSpecifier, Option.none())) {\n return (namedBindings.name.text)\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 (test(importSpecifier.name, statement.moduleSpecifier, importProperty)) {\n return (importSpecifier.name.text)\n }\n }\n }\n }\n }\n\n function findImportedModuleIdentifierByPackageAndNameOrBarrel(\n sourceFile: ts.SourceFile,\n packageName: string,\n moduleName: string\n ) {\n return findImportedModuleIdentifier(\n sourceFile,\n (_, fromModule, importProperty) => {\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\n function simplifyTypeNode(typeNode: ts.TypeNode) {\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\n function tryPreserveDeclarationSemantics(nodeToReplace: ts.Node, node: ts.Node) {\n // new node should be an expression!\n if (!ts.isExpression(node)) return node\n // ok, we need to replace. is that a method or a function?\n if (ts.isFunctionDeclaration(nodeToReplace)) {\n // I need a name!!!\n if (!nodeToReplace.name) return node\n return ts.factory.createVariableStatement(\n nodeToReplace.modifiers,\n ts.factory.createVariableDeclarationList(\n [ts.factory.createVariableDeclaration(\n nodeToReplace.name,\n undefined,\n undefined,\n node\n )],\n ts.NodeFlags.Const\n )\n )\n } else if (ts.isMethodDeclaration(nodeToReplace)) {\n return ts.factory.createPropertyDeclaration(\n nodeToReplace.modifiers,\n nodeToReplace.name,\n undefined,\n undefined,\n node\n )\n }\n // I don't know what else to do!\n return node\n }\n\n function parseAccessedExpressionForCompletion(\n sourceFile: ts.SourceFile,\n position: number\n ) {\n // first, we find the preceding token\n const precedingToken = ts.findPrecedingToken(position, sourceFile, undefined, true)\n if (!precedingToken) return\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\n }\n return { accessedObject, outerNode, replacementSpan }\n }\n\n function parseDataForExtendsClassCompletion(\n sourceFile: ts.SourceFile,\n position: number\n ) {\n const maybeInfos = parseAccessedExpressionForCompletion(sourceFile, position)\n if (!maybeInfos) return\n const { accessedObject, outerNode, replacementSpan } = maybeInfos\n\n if (!ts.isIdentifier(accessedObject)) return\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\n\n if (!classDeclaration.name) return\n\n return {\n accessedObject,\n classDeclaration,\n className: classDeclaration.name,\n replacementSpan\n } as const\n }\n\n function createEffectGenCallExpression(\n effectModuleIdentifierName: string,\n node: ts.Node\n ) {\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\n function createEffectGenCallExpressionWithBlock(\n effectModuleIdentifierName: string,\n statement: ts.Statement | Array<ts.Statement>\n ) {\n return createEffectGenCallExpression(\n effectModuleIdentifierName,\n ts.factory.createBlock(Array.isArray(statement) ? statement : [statement], false)\n )\n }\n\n function createReturnYieldStarStatement(\n expr: ts.Expression\n ) {\n return ts.factory.createReturnStatement(\n ts.factory.createYieldExpression(\n ts.factory.createToken(ts.SyntaxKind.AsteriskToken),\n expr\n )\n )\n }\n\n return {\n findNodeAtPositionIncludingTrivia,\n parsePackageContentNameAndVersionFromScope,\n resolveModulePattern,\n findNodeWithLeadingCommentAtPosition,\n getCommentAtPosition,\n getAncestorNodesInRange,\n toTextRange,\n isNodeInRange,\n transformAsyncAwaitToEffectGen,\n findImportedModuleIdentifierByPackageAndNameOrBarrel,\n simplifyTypeNode,\n tryPreserveDeclarationSemantics,\n parseDataForExtendsClassCompletion,\n createEffectGenCallExpressionWithBlock,\n createReturnYieldStarStatement,\n makeGetModuleSpecifier,\n parseAccessedExpressionForCompletion\n }\n}\n","import { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport type * as TypeCheckerApi from \"../core/TypeCheckerApi.js\"\nimport type * as TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as TypeScriptUtils from \"../core/TypeScriptUtils.js\"\nimport * as LanguageServicePluginOptions from \"./LanguageServicePluginOptions.js\"\nimport * as Nano from \"./Nano.js\"\n\nexport class RefactorNotApplicableError {\n readonly _tag = \"@effect/language-service/RefactorNotApplicableError\"\n}\n\nexport interface RefactorDefinition {\n name: string\n description: string\n apply: (\n sourceFile: ts.SourceFile,\n textRange: ts.TextRange\n ) => Nano.Nano<\n ApplicableRefactorDefinition,\n RefactorNotApplicableError,\n | TypeScriptApi.TypeScriptApi\n | TypeScriptUtils.TypeScriptUtils\n | TypeCheckerApi.TypeCheckerApi\n | TypeParser.TypeParser\n | LanguageServicePluginOptions.LanguageServicePluginOptions\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 severity: LanguageServicePluginOptions.DiagnosticSeverity | \"off\"\n apply: (\n sourceFile: ts.SourceFile,\n report: (data: {\n location: ts.TextRange | ts.Node\n messageText: string\n fixes: Array<ApplicableDiagnosticDefinitionFix>\n }) => void\n ) => Nano.Nano<\n void,\n never,\n | TypeCheckerApi.TypeCheckerApi\n | TypeParser.TypeParser\n | LanguageServicePluginOptions.LanguageServicePluginOptions\n | TypeScriptApi.TypeScriptApi\n | TypeScriptUtils.TypeScriptUtils\n | TypeScriptApi.TypeScriptProgram\n >\n}\n\nexport interface ApplicableDiagnosticDefinition {\n range: ts.TextRange\n messageText: string\n fixes: Array<ApplicableDiagnosticDefinitionFix>\n}\n\nexport interface ApplicableDiagnosticDefinitionFix {\n fixName: string\n description: string\n apply: Nano.Nano<void, never, ts.textChanges.ChangeTracker>\n}\n\nexport interface ApplicableDiagnosticDefinitionFixWithPositionAndCode extends ApplicableDiagnosticDefinitionFix {\n code: number\n start: number\n end: number\n}\n\nexport function createDiagnostic(definition: DiagnosticDefinition): DiagnosticDefinition {\n return definition\n}\n\nexport interface CompletionDefinition {\n name: string\n apply: (\n sourceFile: ts.SourceFile,\n position: number,\n options: ts.GetCompletionsAtPositionOptions | undefined,\n formatCodeSettings: ts.FormatCodeSettings | undefined\n ) => Nano.Nano<\n Array<CompletionEntryDefinition>,\n never,\n | TypeCheckerApi.TypeCheckerApi\n | TypeParser.TypeParser\n | LanguageServicePluginOptions.LanguageServicePluginOptions\n | TypeScriptApi.TypeScriptApi\n | TypeScriptUtils.TypeScriptUtils\n | TypeScriptApi.TypeScriptProgram\n >\n}\n\nexport interface CompletionEntryDefinition {\n name: string\n kind: ts.ScriptElementKind\n insertText: string\n isSnippet: true\n replacementSpan?: ts.TextSpan\n}\n\nexport function createCompletion(definition: CompletionDefinition): CompletionDefinition {\n return definition\n}\n\nexport class SourceFileNotFoundError {\n readonly _tag = \"@effect/language-service/SourceFileNotFoundError\"\n constructor(\n readonly fileName: string\n ) {}\n}\n\nexport const getSemanticDiagnosticsWithCodeFixes = Nano.fn(\n \"LSP.getSemanticDiagnosticsWithCodeFixes\"\n)(function*(\n rules: Array<DiagnosticDefinition>,\n sourceFile: ts.SourceFile\n) {\n let effectDiagnostics: Array<ts.Diagnostic> = []\n let effectCodeFixes: Array<ApplicableDiagnosticDefinitionFixWithPositionAndCode> = []\n const executor = yield* createDiagnosticExecutor(sourceFile)\n for (const rule of rules) {\n const { codeFixes, diagnostics } = yield* (executor.execute(rule))\n effectDiagnostics = effectDiagnostics.concat(diagnostics)\n effectCodeFixes = effectCodeFixes.concat(codeFixes)\n }\n\n return ({\n diagnostics: effectDiagnostics,\n codeFixes: effectCodeFixes\n })\n})\n\nfunction refactorNameToFullyQualifiedName(name: string) {\n return `@effect/language-service/refactors/${name}`\n}\n\nexport const getApplicableRefactors = Nano.fn(\"LSP.getApplicableRefactors\")(function*(\n refactors: Array<RefactorDefinition>,\n sourceFile: ts.SourceFile,\n positionOrRange: number | ts.TextRange\n) {\n const textRange = typeof positionOrRange === \"number\"\n ? { pos: positionOrRange, end: positionOrRange }\n : positionOrRange\n const effectRefactors: Array<ts.ApplicableRefactorInfo> = []\n for (const refactor of refactors) {\n const result = yield* Nano.option(refactor.apply(sourceFile, textRange))\n if (Option.isSome(result)) {\n effectRefactors.push({\n name: refactorNameToFullyQualifiedName(refactor.name),\n description: refactor.description,\n actions: [{\n name: refactorNameToFullyQualifiedName(refactor.name),\n description: result.value.description,\n kind: result.value.kind\n }]\n })\n }\n }\n return effectRefactors\n})\n\nexport const getEditsForRefactor = Nano.fn(\"LSP.getEditsForRefactor\")(function*(\n refactors: Array<RefactorDefinition>,\n sourceFile: ts.SourceFile,\n positionOrRange: number | ts.TextRange,\n refactorName: string\n) {\n const refactor = refactors.find((refactor) => refactorNameToFullyQualifiedName(refactor.name) === refactorName)\n if (!refactor) {\n return yield* Nano.fail(new RefactorNotApplicableError())\n }\n const textRange = typeof positionOrRange === \"number\"\n ? { pos: positionOrRange, end: positionOrRange }\n : positionOrRange\n\n return yield* refactor.apply(sourceFile, textRange)\n})\n\nexport const getCompletionsAtPosition = Nano.fn(\"LSP.getCompletionsAtPosition\")(function*(\n completions: Array<CompletionDefinition>,\n sourceFile: ts.SourceFile,\n position: number,\n options: ts.GetCompletionsAtPositionOptions | undefined,\n formatCodeSettings: ts.FormatCodeSettings | undefined\n) {\n let effectCompletions: Array<ts.CompletionEntry> = []\n for (const completion of completions) {\n const result = yield* completion.apply(sourceFile, position, options, formatCodeSettings)\n effectCompletions = effectCompletions.concat(\n result.map((_) => ({ sortText: \"11\", ..._ }) satisfies ts.CompletionEntry)\n )\n }\n return effectCompletions\n})\n\nconst createDiagnosticExecutor = Nano.fn(\"LSP.createCommentDirectivesProcessor\")(\n function*(sourceFile: ts.SourceFile) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const tsUtils = yield* Nano.service(TypeScriptUtils.TypeScriptUtils)\n const pluginOptions = yield* Nano.service(LanguageServicePluginOptions.LanguageServicePluginOptions)\n\n function findParentStatementForDisableNextLine(node: ts.Node) {\n let result: ts.Node | undefined\n\n function find(node: ts.Node) {\n if (ts.isStatement(node)) {\n result = node\n return\n }\n if (result) return\n if (node.parent) find(node.parent)\n }\n find(node)\n return result || node\n }\n\n const lineOverrides: Record<\n string,\n Array<{ pos: number; end: number; level: string }>\n > = {}\n const sectionOverrides: Record<\n string,\n Array<{ pos: number; level: string }>\n > = {}\n const skippedRules: Array<string> = []\n\n const regex =\n /@effect-diagnostics(-next-line)?((?:\\s[a-zA-Z0-9/]+:(?:off|warning|error|message|suggestion|skip-file))+)?/gm\n let match: RegExpExecArray | null\n while ((match = regex.exec(sourceFile.text)) !== null) {\n const nextLineCaptureGroup = match[1]\n const rulesCaptureGroup = match[2]\n\n if (rulesCaptureGroup) {\n const trimmedRuleString = rulesCaptureGroup.trim()\n if (trimmedRuleString) {\n const individualRules = trimmedRuleString.split(/\\s+/)\n for (const rulePair of individualRules) {\n const [rawRuleName, ruleLevel] = rulePair.toLowerCase().split(\":\")\n // NOTE: for backwards compatibility, treat \"effect/ruleName\" same as \"ruleName\"\n const ruleName = rawRuleName.startsWith(\"effect/\")\n ? rawRuleName.substring(\"effect/\".length)\n : rawRuleName\n if (ruleName && ruleLevel) {\n if (ruleLevel === \"skip-file\") skippedRules.push(ruleName)\n const isOverrideNextLine = nextLineCaptureGroup &&\n nextLineCaptureGroup.trim().toLowerCase() === \"-next-line\"\n if (isOverrideNextLine) {\n const foundNode = tsUtils.findNodeWithLeadingCommentAtPosition(sourceFile, match.index)\n if (foundNode) {\n lineOverrides[ruleName] = lineOverrides[ruleName] || []\n lineOverrides[ruleName].unshift({\n pos: foundNode.node.getFullStart(),\n end: foundNode.node.end,\n level: ruleLevel\n })\n }\n } else {\n sectionOverrides[ruleName] = sectionOverrides[ruleName] || []\n sectionOverrides[ruleName].unshift({\n pos: match.index,\n level: ruleLevel\n })\n }\n }\n }\n }\n }\n }\n\n const levelToDiagnosticCategory: Record<string, ts.DiagnosticCategory> = {\n error: ts.DiagnosticCategory.Error,\n warning: ts.DiagnosticCategory.Warning,\n message: ts.DiagnosticCategory.Message,\n suggestion: ts.DiagnosticCategory.Suggestion\n }\n\n const execute = (\n rule: DiagnosticDefinition\n ) =>\n Nano.gen(function*() {\n const diagnostics: Array<ts.Diagnostic> = []\n const codeFixes: Array<ApplicableDiagnosticDefinitionFixWithPositionAndCode> = []\n const ruleNameLowered = rule.name.toLowerCase()\n const defaultLevel = pluginOptions.diagnosticSeverity[ruleNameLowered] || rule.severity\n // if file is skipped entirely, do not process the rule\n if (skippedRules.indexOf(ruleNameLowered) > -1) return { diagnostics, codeFixes }\n // if the default level is off, and there are no overrides, do not process the rule\n if (\n defaultLevel === \"off\" &&\n ((lineOverrides[ruleNameLowered] || sectionOverrides[ruleNameLowered] || []).length === 0)\n ) {\n return { diagnostics, codeFixes }\n }\n // append a rule fix to disable this check only for next line\n const fixByDisableNextLine = (\n node: ts.Node\n ): ApplicableDiagnosticDefinitionFix => ({\n fixName: rule.name + \"_skipNextLine\",\n description: \"Disable \" + rule.name + \" for this line\",\n apply: Nano.flatMap(\n Nano.service(TypeScriptApi.ChangeTracker),\n (changeTracker) =>\n Nano.gen(function*() {\n const disableAtNode = findParentStatementForDisableNextLine(node)\n const { line } = ts.getLineAndCharacterOfPosition(sourceFile, disableAtNode.getStart())\n\n changeTracker.insertCommentBeforeLine(\n sourceFile,\n line,\n disableAtNode.getStart(),\n ` @effect-diagnostics-next-line ${rule.name}:off`\n )\n })\n )\n })\n\n // append a rule fix to disable this check for the entire file\n const fixByDisableEntireFile: ApplicableDiagnosticDefinitionFix = {\n fixName: rule.name + \"_skipFile\",\n description: \"Disable \" + rule.name + \" for this entire file\",\n apply: Nano.flatMap(\n Nano.service(TypeScriptApi.ChangeTracker),\n (changeTracker) =>\n Nano.sync(() =>\n changeTracker.insertText(\n sourceFile,\n 0,\n `/** @effect-diagnostics ${rule.name}:skip-file */\\n`\n )\n )\n )\n }\n // run the executor\n const applicableDiagnostics: Array<ApplicableDiagnosticDefinition> = []\n yield* rule.apply(sourceFile, (entry) => {\n const range = \"getEnd\" in entry.location\n ? { pos: entry.location.getStart(sourceFile), end: entry.location.getEnd() }\n : entry.location\n const node = \"getEnd\" in entry.location\n ? entry.location\n : tsUtils.findNodeAtPositionIncludingTrivia(sourceFile, entry.location.pos)\n applicableDiagnostics.push({\n range,\n messageText: entry.messageText,\n fixes: entry.fixes.concat(node ? [fixByDisableNextLine(node)] : []).concat([fixByDisableEntireFile])\n })\n })\n\n // loop through rules\n for (const emitted of applicableDiagnostics.slice(0)) {\n // by default, use the overriden level from the plugin options\n let newLevel: string | undefined = defaultLevel\n // attempt with line overrides\n const lineOverride = (lineOverrides[ruleNameLowered] || []).find((_) =>\n _.pos < emitted.range.pos && _.end >= emitted.range.end\n )\n if (lineOverride) {\n newLevel = lineOverride.level\n } else {\n // then attempt with section overrides\n const sectionOverride = (sectionOverrides[ruleNameLowered] || []).find((_) => _.pos < emitted.range.pos)\n if (sectionOverride) newLevel = sectionOverride.level\n }\n // if level is off or not a valid level, skip and no output\n if (!(newLevel in levelToDiagnosticCategory)) continue\n // append both diagnostic and code fix\n diagnostics.push({\n file: sourceFile,\n start: emitted.range.pos,\n length: emitted.range.end - emitted.range.pos,\n messageText: emitted.messageText,\n category: levelToDiagnosticCategory[newLevel],\n code: rule.code,\n source: \"effect\"\n })\n // append code fixes\n for (const fix of emitted.fixes) {\n codeFixes.push({\n ...fix,\n code: rule.code,\n start: emitted.range.pos,\n end: emitted.range.end\n })\n }\n }\n\n return { diagnostics, codeFixes }\n })\n\n return { execute }\n }\n)\n\nexport const cyrb53 = (str: string, seed = 0) => {\n let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed\n for (let i = 0, ch; i < str.length; i++) {\n ch = str.charCodeAt(i)\n h1 = Math.imul(h1 ^ ch, 2654435761)\n h2 = Math.imul(h2 ^ ch, 1597334677)\n }\n h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507)\n h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909)\n h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507)\n h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909)\n\n // return 4294967296 * (2097151 & h2) + (h1 >>> 0)\n return (h2 >>> 0).toString(16).padStart(8, \"0\") + (h1 >>> 0).toString(16).padStart(8, \"0\")\n}\n\nexport class CodegenNotApplicableError {\n readonly _tag = \"@effect/language-service/CodegenNotApplicableError\"\n constructor(\n readonly cause: string\n ) {}\n}\n\nexport interface CodegenDefinition {\n name: string\n apply: (\n sourceFile: ts.SourceFile,\n commentRange: ts.TextRange\n ) => Nano.Nano<\n ApplicableCodegenDefinition,\n CodegenNotApplicableError,\n | TypeScriptApi.TypeScriptApi\n | TypeScriptUtils.TypeScriptUtils\n | TypeCheckerApi.TypeCheckerApi\n | TypeParser.TypeParser\n | LanguageServicePluginOptions.LanguageServicePluginOptions\n >\n}\n\nexport interface ApplicableCodegenDefinition {\n hash: string\n description: string\n apply: Nano.Nano<void, never, ts.textChanges.ChangeTracker>\n}\n\nexport function createCodegen(definition: CodegenDefinition): CodegenDefinition {\n return definition\n}\n\nexport const getCodegensForSourceFile = Nano.fn(\"LSP.getApplicableCodegens\")(function*(\n codegens: Array<CodegenDefinition>,\n sourceFile: ts.SourceFile\n) {\n const tsUtils = yield* Nano.service(TypeScriptUtils.TypeScriptUtils)\n const result: Array<{ codegen: CodegenDefinition; hash: string; range: ts.TextRange }> = []\n\n const regex = /@effect-codegens((?:\\s[a-zA-Z0-9]+(?::(?:[a-zA-Z0-9]+))?)+)+/gmid\n let match: RegExpExecArray | null\n while ((match = regex.exec(sourceFile.text)) !== null) {\n const pos = match.indices?.[0]?.[0]\n if (!pos) continue\n const commentRange = tsUtils.getCommentAtPosition(sourceFile, pos)\n if (!commentRange) continue\n const commentText = sourceFile.text.slice(pos, commentRange.end)\n const codegenRegex = /(\\s+)(\\w+)(?::(\\w+))?/gmi\n let codegenMatch: RegExpExecArray | null\n while ((codegenMatch = codegenRegex.exec(commentText)) !== null) {\n const whitespace = codegenMatch[1] || \"\"\n const codegenName = codegenMatch[2] || \"\"\n const codegenHash = codegenMatch[3] || \"\"\n const range: ts.TextRange = {\n pos: codegenMatch.index + pos + whitespace.length,\n end: codegenMatch.index + pos + codegenMatch[0].length\n }\n const codegen = codegens.find((codegen) => codegen.name === codegenName)\n if (!codegen) continue\n result.push({ codegen, hash: codegenHash, range })\n }\n }\n return result\n})\n\nexport const getEditsForCodegen = Nano.fn(\"LSP.getEditsForCodegen\")(function*(\n codegens: Array<CodegenDefinition>,\n sourceFile: ts.SourceFile,\n textRange: ts.TextRange\n) {\n const applicableCodegens = yield* getCodegensForSourceFile(codegens, sourceFile)\n const inRangeCodegens = applicableCodegens.filter((codegen) =>\n codegen.range.pos <= textRange.pos && codegen.range.end >= textRange.end\n )\n if (inRangeCodegens.length !== 1) {\n return yield* Nano.fail(new CodegenNotApplicableError(\"zero or multiple codegens in range\"))\n }\n const { codegen, range } = inRangeCodegens[0]\n const edit = yield* codegen.apply(sourceFile, range)\n const updateHashComment = pipe(\n Nano.service(TypeScriptApi.ChangeTracker),\n Nano.map((changeTracker) => {\n changeTracker.deleteRange(sourceFile, range)\n changeTracker.insertText(sourceFile, range.pos, `${codegen.name}:${edit.hash}`)\n })\n )\n return {\n ...edit,\n apply: pipe(\n edit.apply,\n Nano.flatMap(() => updateHashComment)\n ),\n ignore: updateHashComment\n } satisfies ApplicableCodegenDefinition & { ignore: Nano.Nano<void, never, ts.textChanges.ChangeTracker> }\n})\n","import * as Array from \"effect/Array\"\nimport { isFunction, pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as Order from \"effect/Order\"\nimport { hasProperty } from \"effect/Predicate\"\nimport type ts from \"typescript\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeScriptApi from \"./TypeScriptApi.js\"\n\nexport interface TypeCheckerApi extends ts.TypeChecker {}\nexport const TypeCheckerApi = Nano.Tag<TypeCheckerApi>(\"TypeChecker\")\n\nexport const deterministicTypeOrder = Nano.gen(function*() {\n const typeChecker = yield* Nano.service(TypeCheckerApi)\n return Order.make((a: ts.Type, b: ts.Type) => {\n const aName = typeChecker.typeToString(a)\n const bName = typeChecker.typeToString(b)\n if (aName < bName) return -1\n if (aName > bName) return 1\n return 0\n })\n})\n\nexport const getMissingTypeEntriesInTargetType = Nano.fn(\n \"TypeCheckerApi.getMissingTypeEntriesInTargetType\"\n)(\n function*(realType: ts.Type, expectedType: ts.Type) {\n if (realType === expectedType) return []\n const typeChecker = yield* Nano.service(TypeCheckerApi)\n\n const result: Array<ts.Type> = []\n let toTest: Array<ts.Type> = [realType]\n while (toTest.length > 0) {\n const type = toTest.pop()\n if (!type) return result\n if (type.isUnion()) {\n toTest = toTest.concat(type.types)\n } else {\n const assignable = typeChecker.isTypeAssignableTo(type, expectedType)\n if (!assignable) {\n result.push(type)\n }\n }\n }\n return result\n }\n)\n\ntype ConvertibleDeclaration =\n | ts.FunctionDeclaration\n | ts.FunctionExpression\n | ts.ArrowFunction\n | ts.MethodDeclaration\n\nclass CannotFindAncestorConvertibleDeclarationError {\n readonly _tag = \"@effect/language-service/CannotFindAncestorConvertibleDeclarationError\"\n constructor(\n readonly node: ts.Node\n ) {}\n}\n\nconst getAncestorConvertibleDeclaration = Nano.fn(\n \"TypeCheckerApi.getAncestorConvertibleDeclaration\"\n)(function*(node: ts.Node) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n let current: ts.Node | undefined = node\n while (current) {\n if (\n ts.isFunctionDeclaration(current) ||\n ts.isFunctionExpression(current) ||\n ts.isArrowFunction(current) ||\n ts.isMethodDeclaration(current)\n ) {\n return current\n }\n current = current.parent\n }\n return yield* Nano.fail(new CannotFindAncestorConvertibleDeclarationError(node))\n})\n\nclass CannotInferReturnTypeFromEmptyBody {\n readonly _tag = \"@effect/language-service/CannotInferReturnTypeFromEmptyBody\"\n constructor(\n readonly declaration: ConvertibleDeclaration\n ) {}\n}\n\nclass CannotInferReturnType {\n readonly _tag = \"@effect/language-service/CannotInferReturnType\"\n constructor(\n readonly declaration: ConvertibleDeclaration\n ) {}\n}\n\nexport const getInferredReturnType = Nano.fn(\"TypeCheckerApi.getInferredReturnType\")(function*(\n declaration: ConvertibleDeclaration\n) {\n const typeChecker = yield* Nano.service(TypeCheckerApi)\n\n if (!declaration.body) {\n return yield* Nano.fail(\n new CannotInferReturnTypeFromEmptyBody(declaration)\n )\n }\n\n let returnType: ts.Type | undefined\n\n if (typeChecker.isImplementationOfOverload(declaration)) {\n const signatures = typeChecker.getTypeAtLocation(declaration).getCallSignatures()\n if (signatures.length > 1) {\n returnType = typeChecker.getUnionType(\n signatures.map((s) => s.getReturnType()).filter((_) => !!_)\n )\n }\n }\n if (!returnType) {\n const signature = typeChecker.getSignatureFromDeclaration(declaration)\n if (signature) {\n const typePredicate = typeChecker.getTypePredicateOfSignature(signature)\n if (typePredicate && typePredicate.type) {\n return typePredicate.type\n } else {\n returnType = typeChecker.getReturnTypeOfSignature(signature)\n }\n }\n }\n\n if (!returnType) {\n return yield* Nano.fail(\n new CannotInferReturnType(declaration)\n )\n }\n\n return returnType\n})\n\ntype ExpectedAndRealType = [\n node: ts.Node,\n expectedType: ts.Type,\n valueNode: ts.Node,\n realType: ts.Type\n]\n\nexport const expectedAndRealType = Nano.cachedBy(\n Nano.fn(\"TypeCheckerApi.expectedAndRealType\")(function*(\n sourceFile: ts.SourceFile\n ) {\n const typeChecker = yield* Nano.service(TypeCheckerApi)\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const result: Array<ExpectedAndRealType> = []\n\n const nodeToVisit: Array<ts.Node> = [sourceFile]\n const appendNodeToVisit = (node: ts.Node) => {\n nodeToVisit.push(node)\n return undefined\n }\n\n while (nodeToVisit.length > 0) {\n const node = nodeToVisit.shift()!\n\n if (ts.isVariableDeclaration(node) && node.initializer) {\n // const a: Effect<...> = node\n const expectedType = typeChecker.getTypeAtLocation(node.name)\n const realType = typeChecker.getTypeAtLocation(node.initializer)\n result.push([node.name, expectedType, node.initializer, realType])\n appendNodeToVisit(node.initializer)\n continue\n } else if (ts.isCallExpression(node)) {\n // fn(a)\n const resolvedSignature = typeChecker.getResolvedSignature(node)\n if (resolvedSignature) {\n resolvedSignature.getParameters().map((parameter, index) => {\n const expectedType = typeChecker.getTypeOfSymbolAtLocation(parameter, node)\n const realType = typeChecker.getTypeAtLocation(node.arguments[index])\n result.push([\n node.arguments[index] as ts.Node,\n expectedType,\n node.arguments[index],\n realType\n ])\n })\n }\n ts.forEachChild(node, appendNodeToVisit)\n continue\n } else if (\n ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node) ||\n ts.isNoSubstitutionTemplateLiteral(node)\n ) {\n // { key: node } as { key: Effect<...> }\n const parent = node.parent\n if (ts.isObjectLiteralElement(parent)) {\n if (ts.isObjectLiteralExpression(parent.parent) && parent.name === node) {\n const type = typeChecker.getContextualType(parent.parent)\n if (type) {\n const symbol = typeChecker.getPropertyOfType(type, node.text)\n if (symbol) {\n const expectedType = typeChecker.getTypeOfSymbolAtLocation(symbol, node)\n const realType = typeChecker.getTypeAtLocation(node)\n result.push([node, expectedType, node, realType])\n }\n }\n }\n }\n ts.forEachChild(node, appendNodeToVisit)\n continue\n } else if (\n ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken\n ) {\n // var a: Effect<...> = node\n const expectedType = typeChecker.getTypeAtLocation(node.left)\n const realType = typeChecker.getTypeAtLocation(node.right)\n result.push([node.left, expectedType, node.right, realType])\n appendNodeToVisit(node.right)\n continue\n } else if (ts.isReturnStatement(node) && node.expression) {\n // function(): Effect<...> { return a }\n const parentDeclaration = yield* Nano.option(getAncestorConvertibleDeclaration(node))\n if (Option.isSome(parentDeclaration)) {\n const expectedType = yield* Nano.option(getInferredReturnType(parentDeclaration.value))\n const realType = typeChecker.getTypeAtLocation(node.expression)\n if (Option.isSome(expectedType)) {\n result.push([node, expectedType.value, node, realType])\n }\n }\n ts.forEachChild(node, appendNodeToVisit)\n continue\n } else if (\n ts.isArrowFunction(node) && (node.typeParameters || []).length === 0 &&\n ts.isExpression(node.body)\n ) {\n // (): Effect<...> => node\n const body = node.body\n const expectedType = typeChecker.getContextualType(body)\n const realType = typeChecker.getTypeAtLocation(body)\n if (expectedType) {\n result.push([body, expectedType, body, realType])\n }\n ts.forEachChild(body, appendNodeToVisit)\n continue\n } else if (\n ts.isArrowFunction(node) && (node.typeParameters || []).length > 0 &&\n ts.isExpression(node.body)\n ) {\n // <A>(): Effect<...> => node\n const body = node.body\n const expectedType = yield* Nano.option(getInferredReturnType(node))\n const realType = typeChecker.getTypeAtLocation(body)\n if (Option.isSome(expectedType)) {\n result.push([body, expectedType.value, body, realType])\n }\n ts.forEachChild(body, appendNodeToVisit)\n continue\n } else if (ts.isSatisfiesExpression(node)) {\n // node as Effect<....>\n const expectedType = typeChecker.getTypeAtLocation(node.type)\n const realType = typeChecker.getTypeAtLocation(node.expression)\n result.push([node.expression as ts.Node, expectedType, node.expression, realType])\n appendNodeToVisit(node.expression)\n continue\n }\n\n // no previous case has been hit, continue with childs\n ts.forEachChild(node, appendNodeToVisit)\n }\n return result\n }),\n \"TypeCheckerApi.expectedAndRealType\",\n (sourceFile) => sourceFile\n)\n\nexport const unrollUnionMembers = (type: ts.Type) => {\n const result: Array<ts.Type> = []\n let toTest: Array<ts.Type> = [type]\n while (toTest.length > 0) {\n const type = toTest.pop()!\n if (type.isUnion()) {\n toTest = toTest.concat(type.types)\n } else {\n result.push(type)\n }\n }\n return result\n}\n\n/**\n * Appends a type to a map of unique types, ensuring that the type is not already in the map.\n *\n * @param memory - The map that will be used as memory and updated as new types are encountered.\n * @param initialType - The type to start with, unions will be unrolled.\n * @param shouldExclude - A function that determines if a type should be excluded from the checking\n * @returns An object with the following properties:\n * - newIndexes: A set of new indexes that were added to the memory.\n * - knownIndexes: A set of indexes that were already in the memory.\n * - allIndexes: A set of all indexes that were encountered.\n */\nexport const appendToUniqueTypesMap = Nano.fn(\n \"TypeCheckerApi.appendToUniqueTypesMap\"\n)(\n function*(memory: Map<string, ts.Type>, initialType: ts.Type, shouldExclude: (type: ts.Type) => Nano.Nano<boolean>) {\n const typeChecker = yield* Nano.service(TypeCheckerApi)\n\n const newIndexes: Set<string> = new Set()\n const knownIndexes: Set<string> = new Set()\n let toTest: Array<ts.Type> = [initialType]\n while (toTest.length > 0) {\n const type = toTest.pop()\n if (!type) break\n if (yield* shouldExclude(type)) {\n continue\n }\n if (type.isUnion()) {\n toTest = toTest.concat(type.types)\n } else {\n const foundMatch: Array<string> = []\n for (const [typeId, knownType] of memory.entries()) {\n const areSame = typeChecker.isTypeAssignableTo(knownType, type) &&\n typeChecker.isTypeAssignableTo(type, knownType)\n if (areSame) {\n foundMatch.push(typeId)\n break\n }\n }\n if (foundMatch.length === 0) {\n const newId = \"t\" + (memory.size + 1)\n memory.set(newId, type)\n newIndexes.add(newId)\n } else {\n knownIndexes.add(foundMatch[0])\n }\n }\n }\n return {\n newIndexes,\n knownIndexes,\n allIndexes: pipe(\n Array.fromIterable(newIndexes),\n Array.appendAll(Array.fromIterable(knownIndexes))\n )\n }\n }\n)\n\nexport function makeResolveExternalModuleName(typeChecker: TypeCheckerApi) {\n if (!(hasProperty(typeChecker, \"resolveExternalModuleName\") && isFunction(typeChecker.resolveExternalModuleName))) {\n return\n }\n const _internal = typeChecker.resolveExternalModuleName\n return (moduleSpecifier: ts.Expression): ts.Symbol | undefined => {\n return _internal(moduleSpecifier)\n }\n}\n","import { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as Nano from \"./Nano.js\"\nimport * as TypeCheckerApi from \"./TypeCheckerApi.js\"\nimport * as TypeScriptApi from \"./TypeScriptApi.js\"\nimport * as TypeScriptUtils from \"./TypeScriptUtils.js\"\n\nexport interface TypeParser {\n effectType: (\n type: ts.Type,\n atLocation: ts.Node\n ) => Nano.Nano<{ A: ts.Type; E: ts.Type; R: ts.Type }, TypeParserIssue>\n strictEffectType: (\n type: ts.Type,\n atLocation: ts.Node\n ) => Nano.Nano<{ A: ts.Type; E: ts.Type; R: ts.Type }, TypeParserIssue>\n layerType: (\n type: ts.Type,\n atLocation: ts.Node\n ) => Nano.Nano<{ ROut: ts.Type; E: ts.Type; RIn: ts.Type }, TypeParserIssue>\n fiberType: (\n type: ts.Type,\n atLocation: ts.Node\n ) => Nano.Nano<{ A: ts.Type; E: ts.Type; R: ts.Type }, TypeParserIssue>\n effectSubtype: (\n type: ts.Type,\n atLocation: ts.Node\n ) => Nano.Nano<{ A: ts.Type; E: ts.Type; R: ts.Type }, TypeParserIssue>\n importedEffectModule: (\n node: ts.Node\n ) => Nano.Nano<ts.Node, TypeParserIssue>\n effectGen: (\n node: ts.Node\n ) => Nano.Nano<\n {\n node: ts.Node\n effectModule: ts.Expression\n generatorFunction: ts.FunctionExpression\n body: ts.Block\n functionStar: ts.Node | undefined\n },\n TypeParserIssue\n >\n effectFnUntracedGen: (\n node: ts.Node\n ) => Nano.Nano<\n {\n node: ts.Node\n effectModule: ts.Node\n generatorFunction: ts.Node\n body: ts.Block\n functionStar: ts.Node | undefined\n },\n TypeParserIssue\n >\n effectFnGen: (\n node: ts.Node\n ) => Nano.Nano<\n {\n node: ts.Node\n generatorFunction: ts.Node\n effectModule: ts.Node\n body: ts.Block\n functionStar: ts.Node | undefined\n },\n TypeParserIssue\n >\n unnecessaryEffectGen: (\n node: ts.Node\n ) => Nano.Nano<\n { node: ts.Node; body: ts.Block; yieldedExpression: ts.Node; replacementNode: Nano.Nano<ts.Node, never, never> },\n TypeParserIssue\n >\n effectSchemaType: (\n type: ts.Type,\n atLocation: ts.Node\n ) => Nano.Nano<{ A: ts.Type; I: ts.Type; R: ts.Type }, TypeParserIssue>\n contextTag: (\n type: ts.Type,\n atLocation: ts.Node\n ) => Nano.Nano<{ Identifier: ts.Type; Service: ts.Type }, TypeParserIssue>\n pipeableType: (type: ts.Type, atLocation: ts.Node) => Nano.Nano<ts.Type, TypeParserIssue, never>\n pipeCall: (\n node: ts.Node\n ) => Nano.Nano<\n { node: ts.CallExpression; subject: ts.Expression; args: Array<ts.Expression>; kind: \"pipe\" | \"pipeable\" },\n TypeParserIssue,\n never\n >\n scopeType: (\n type: ts.Type,\n atLocation: ts.Node\n ) => Nano.Nano<ts.Type, TypeParserIssue>\n promiseLike: (\n type: ts.Type,\n atLocation: ts.Node\n ) => Nano.Nano<{ type: ts.Type }, TypeParserIssue>\n extendsEffectService: (atLocation: ts.ClassDeclaration) => Nano.Nano<\n {\n className: ts.Identifier\n selfTypeNode: ts.TypeNode\n args: ts.NodeArray<ts.Expression>\n Identifier: ts.Type\n Service: ts.Type\n accessors: boolean | undefined\n dependencies: ts.NodeArray<ts.Expression> | undefined\n options: ts.Expression\n },\n TypeParserIssue,\n never\n >\n extendsContextTag: (atLocation: ts.ClassDeclaration) => Nano.Nano<\n {\n className: ts.Identifier\n selfTypeNode: ts.TypeNode\n args: ts.NodeArray<ts.Expression>\n Identifier: ts.Type\n Tag: ts.Node\n },\n TypeParserIssue,\n never\n >\n extendsSchemaClass: (atLocation: ts.ClassDeclaration) => Nano.Nano<\n {\n className: ts.Identifier\n selfTypeNode: ts.TypeNode\n Schema: ts.Node\n },\n TypeParserIssue,\n never\n >\n extendsSchemaTaggedClass: (atLocation: ts.ClassDeclaration) => Nano.Nano<\n {\n className: ts.Identifier\n selfTypeNode: ts.TypeNode\n Schema: ts.Node\n },\n TypeParserIssue,\n never\n >\n extendsSchemaTaggedError: (atLocation: ts.ClassDeclaration) => Nano.Nano<\n {\n className: ts.Identifier\n selfTypeNode: ts.TypeNode\n Schema: ts.Node\n },\n TypeParserIssue,\n never\n >\n extendsSchemaTaggedRequest: (atLocation: ts.ClassDeclaration) => Nano.Nano<\n {\n className: ts.Identifier\n selfTypeNode: ts.TypeNode\n Schema: ts.Node\n },\n TypeParserIssue,\n never\n >\n}\nexport const TypeParser = Nano.Tag<TypeParser>(\"@effect/language-service/TypeParser\")\n\nexport const nanoLayer = <A, E, R>(\n fa: Nano.Nano<A, E, R>\n) =>\n Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const tsUtils = yield* Nano.service(TypeScriptUtils.TypeScriptUtils)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n return yield* pipe(\n fa,\n Nano.provideService(TypeParser, make(ts, tsUtils, typeChecker))\n )\n })\n\nexport class TypeParserIssue {\n readonly _tag = \"@effect/language-service/TypeParserIssue\"\n static issue = Nano.fail(new TypeParserIssue())\n}\n\nexport function typeParserIssue(\n _message: string,\n _type?: ts.Type | undefined,\n _node?: ts.Node | undefined\n): Nano.Nano<never, TypeParserIssue, never> {\n return TypeParserIssue.issue\n}\n\nexport function make(\n ts: TypeScriptApi.TypeScriptApi,\n tsUtils: TypeScriptUtils.TypeScriptUtils,\n typeChecker: TypeCheckerApi.TypeCheckerApi\n): TypeParser {\n 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\n function contravariantTypeArgument(type: ts.Type): Nano.Nano<ts.Type, TypeParserIssue> {\n const signatures = type.getCallSignatures()\n // Contravariant<A> has only 1 type signature\n if (signatures.length !== 1) {\n return typeParserIssue(\"Contravariant type has no call signature\", type)\n }\n // get the return type\n return Nano.succeed(signatures[0].getTypeParameterAtPosition(0))\n }\n\n 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\n const pipeableType = Nano.cachedBy(\n function(\n type: ts.Type,\n atLocation: ts.Node\n ) {\n // Pipeable has a pipe property on the type\n const pipeSymbol = typeChecker.getPropertyOfType(type, \"pipe\")\n if (!pipeSymbol) {\n return 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 typeParserIssue(\"'pipe' property is not callable\", type, atLocation)\n }\n return Nano.succeed(type)\n },\n \"TypeParser.pipeableType\",\n (type) => type\n )\n\n const varianceStructCovariantType = <A extends string>(\n type: ts.Type,\n atLocation: ts.Node,\n propertyName: A\n ) => {\n const propertySymbol = typeChecker.getPropertyOfType(type, propertyName)\n if (!propertySymbol) {\n return typeParserIssue(`Type has no '${propertyName}' property`, type, atLocation)\n }\n const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation)\n return covariantTypeArgument(propertyType)\n }\n\n const varianceStructContravariantType = <A extends string>(\n type: ts.Type,\n atLocation: ts.Node,\n propertyName: A\n ) => {\n const propertySymbol = typeChecker.getPropertyOfType(type, propertyName)\n if (!propertySymbol) {\n return typeParserIssue(`Type has no '${propertyName}' property`, type, atLocation)\n }\n const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation)\n return contravariantTypeArgument(propertyType)\n }\n\n const varianceStructInvariantType = <A extends string>(\n type: ts.Type,\n atLocation: ts.Node,\n propertyName: A\n ) => {\n const propertySymbol = typeChecker.getPropertyOfType(type, propertyName)\n if (!propertySymbol) {\n return typeParserIssue(`Type has no '${propertyName}' property`, type, atLocation)\n }\n const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation)\n return invariantTypeArgument(propertyType)\n }\n\n const effectVarianceStruct = (\n type: ts.Type,\n atLocation: ts.Node\n ) =>\n Nano.map(\n Nano.all(\n varianceStructCovariantType(type, atLocation, \"_A\"),\n varianceStructCovariantType(type, atLocation, \"_E\"),\n varianceStructCovariantType(type, atLocation, \"_R\")\n ),\n ([A, E, R]) => ({ A, E, R })\n )\n\n const layerVarianceStruct = (\n type: ts.Type,\n atLocation: ts.Node\n ) =>\n Nano.map(\n Nano.all(\n varianceStructContravariantType(type, atLocation, \"_ROut\"),\n varianceStructCovariantType(type, atLocation, \"_E\"),\n varianceStructCovariantType(type, atLocation, \"_RIn\")\n ),\n ([ROut, E, RIn]) => ({ ROut, E, RIn })\n )\n\n const effectType = Nano.cachedBy(\n Nano.fn(\"TypeParser.effectType\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n ) {\n let result: Nano.Nano<\n {\n A: ts.Type\n E: ts.Type\n R: ts.Type\n },\n TypeParserIssue,\n never\n > = typeParserIssue(\"Type has no effect variance struct\", 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) && _.valueDeclaration &&\n ts.isPropertySignature(_.valueDeclaration) && ts.isComputedPropertyName(_.valueDeclaration.name)\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 result = pipe(result, Nano.orElse(() => effectVarianceStruct(propertyType, atLocation)))\n }\n return yield* result\n }),\n \"TypeParser.effectType\",\n (type) => type\n )\n\n const strictEffectType = Nano.cachedBy(\n Nano.fn(\"TypeParser.strictEffectType\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n ) {\n // symbol name should be Effect\n if (!(type.symbol && type.symbol.name === \"Effect\" && !type.aliasSymbol)) {\n return yield* typeParserIssue(\"Type name should be Effect with no alias symbol\", type, atLocation)\n }\n // should be an effect\n return yield* effectType(type, atLocation)\n }),\n \"TypeParser.strictEffectType\",\n (type) => type\n )\n\n const layerType = Nano.cachedBy(\n Nano.fn(\"TypeParser.layerType\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n ) {\n // should be pipeable\n yield* pipeableType(type, atLocation)\n\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) && _.valueDeclaration &&\n ts.isPropertySignature(_.valueDeclaration) && ts.isComputedPropertyName(_.valueDeclaration.name)\n )\n // try to put typeid first (heuristic to optimize hot path)\n propertiesSymbols.sort((a, b) => b.name.indexOf(\"LayerTypeId\") - a.name.indexOf(\"LayerTypeId\"))\n // has a property symbol which is a layer variance struct\n for (const propertySymbol of propertiesSymbols) {\n const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation)\n const varianceArgs = yield* Nano.option(layerVarianceStruct(\n propertyType,\n atLocation\n ))\n if (Option.isSome(varianceArgs)) {\n return varianceArgs.value\n }\n }\n return yield* typeParserIssue(\"Type has no layer variance struct\", type, atLocation)\n }),\n \"TypeParser.layerType\",\n (type) => type\n )\n\n const fiberType = Nano.cachedBy(\n Nano.fn(\"TypeParser.fiberType\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n ) {\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 \"TypeParser.fiberType\",\n (type) => type\n )\n\n const effectSubtype = Nano.cachedBy(\n Nano.fn(\"TypeParser.effectSubtype\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n ) {\n // there is no better way to check if a type is a subtype of effect\n // so we just check for the existence of the property \"_tag\"\n // which is common for Option, Either, and others\n // and other datatypes as \"Pool\" have \"get\"\n const tagSymbol = typeChecker.getPropertyOfType(type, \"_tag\")\n const getSymbol = typeChecker.getPropertyOfType(type, \"get\")\n if (!(tagSymbol || getSymbol)) {\n return yield* typeParserIssue(\n \"Type is not a subtype of effect because it does not have '_tag' or 'get' property\",\n type,\n atLocation\n )\n }\n // and it is also an effect itself\n return yield* effectType(type, atLocation)\n }),\n \"TypeParser.effectSubtype\",\n (type) => type\n )\n\n const importedSchemaModule = Nano.cachedBy(\n Nano.fn(\"TypeParser.importedSchemaModule\")(function*(\n node: ts.Node\n ) {\n const type = typeChecker.getTypeAtLocation(node)\n // if the type has a property \"Class\" that is a function\n const propertySymbol = typeChecker.getPropertyOfType(type, \"Class\")\n if (!propertySymbol) {\n return yield* typeParserIssue(\"Type has no 'Class' 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 // return the node itself\n return node\n }),\n \"TypeParser.importedSchemaModule\",\n (node) => node\n )\n\n const importedContextModule = Nano.cachedBy(\n Nano.fn(\"TypeParser.importedContextModule\")(function*(\n node: ts.Node\n ) {\n const type = typeChecker.getTypeAtLocation(node)\n // if the type has a property \"Tag\" that is a function\n const propertySymbol = typeChecker.getPropertyOfType(type, \"Tag\")\n if (!propertySymbol) {\n return yield* typeParserIssue(\"Type has no 'Tag' 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 // return the node itself\n return node\n }),\n \"TypeParser.importedContextModule\",\n (node) => node\n )\n\n const importedEffectModule = Nano.cachedBy(\n Nano.fn(\"TypeParser.importedEffectModule\")(function*(\n node: ts.Node\n ) {\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 \"TypeParser.importedEffectModule\",\n (node) => node\n )\n\n const effectGen = Nano.cachedBy(\n function(node: ts.Node) {\n // Effect.gen(...)\n if (!ts.isCallExpression(node)) {\n return typeParserIssue(\"Node is not a call expression\", undefined, node)\n }\n // ...\n if (node.arguments.length === 0) {\n return 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 typeParserIssue(\"Node is not a function expression\", undefined, node)\n }\n if (generatorFunction.asteriskToken === undefined) {\n return typeParserIssue(\"Node is not a generator function\", undefined, node)\n }\n // Effect.gen\n if (!ts.isPropertyAccessExpression(node.expression)) {\n return 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 typeParserIssue(\"Call expression name is not 'gen'\", undefined, node)\n }\n // check Effect module\n return pipe(\n importedEffectModule(propertyAccess.expression),\n Nano.map((effectModule) => ({\n node,\n effectModule,\n generatorFunction,\n body: generatorFunction.body,\n functionStar: generatorFunction.getFirstToken()\n }))\n )\n },\n \"TypeParser.effectGen\",\n (node) => node\n )\n\n const effectFnUntracedGen = Nano.cachedBy(\n function(node: ts.Node) {\n // Effect.gen(...)\n if (!ts.isCallExpression(node)) {\n return typeParserIssue(\"Node is not a call expression\", undefined, node)\n }\n // ...\n if (node.arguments.length === 0) {\n return 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 typeParserIssue(\"Node is not a function expression\", undefined, node)\n }\n if (generatorFunction.asteriskToken === undefined) {\n return 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 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 typeParserIssue(\n \"Call expression name is not 'fnUntraced'\",\n undefined,\n node\n )\n }\n // check Effect module\n return pipe(\n importedEffectModule(propertyAccess.expression),\n Nano.map((effectModule) => ({\n node,\n effectModule,\n generatorFunction,\n body: generatorFunction.body,\n functionStar: generatorFunction.getFirstToken()\n }))\n )\n },\n \"TypeParser.effectFnUntracedGen\",\n (node) => node\n )\n\n const effectFnGen = Nano.cachedBy(\n function(node: ts.Node) {\n // Effect.fn(...)\n if (!ts.isCallExpression(node)) {\n return typeParserIssue(\"Node is not a call expression\", undefined, node)\n }\n // ...\n if (node.arguments.length === 0) {\n return 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 typeParserIssue(\n \"Node is not a function expression\",\n undefined,\n node\n )\n }\n if (generatorFunction.asteriskToken === undefined) {\n return 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 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 typeParserIssue(\n \"Call expression name is not 'fn'\",\n undefined,\n node\n )\n }\n // check Effect module\n return pipe(\n importedEffectModule(propertyAccess.expression),\n Nano.map((effectModule) => ({\n node,\n generatorFunction,\n effectModule,\n body: generatorFunction.body,\n functionStar: generatorFunction.getFirstToken()\n }))\n )\n },\n \"TypeParser.effectFnGen\",\n (node) => node\n )\n\n const unnecessaryEffectGen = Nano.cachedBy(\n Nano.fn(\"TypeParser.unnecessaryEffectGen\")(function*(\n node: ts.Node\n ) {\n // ensure is an effect gen with a single statement\n const { body } = yield* effectGen(node)\n if (body.statements.length !== 1) {\n return yield* typeParserIssue(\n \"Generator body should have a single statement\",\n undefined,\n node\n )\n }\n\n let explicitReturn = false\n let nodeToCheck: ts.Node = body.statements[0]\n while (nodeToCheck) {\n // return XXX\n if (ts.isReturnStatement(nodeToCheck) && nodeToCheck.expression) {\n nodeToCheck = nodeToCheck.expression\n explicitReturn = true\n continue\n }\n // expression yield*\n if (ts.isExpressionStatement(nodeToCheck)) {\n nodeToCheck = nodeToCheck.expression\n continue\n }\n // yield* XXX\n if (ts.isYieldExpression(nodeToCheck) && nodeToCheck.asteriskToken && nodeToCheck.expression) {\n const yieldedExpression = nodeToCheck.expression\n const type = typeChecker.getTypeAtLocation(yieldedExpression)\n const { A: successType } = yield* effectType(type, yieldedExpression)\n let replacementNode: Nano.Nano<ts.Node> = Nano.succeed(yieldedExpression)\n if (!explicitReturn && !(successType.flags & ts.TypeFlags.VoidLike)) {\n replacementNode = pipe(\n Nano.gen(function*() {\n const effectIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(\n node.getSourceFile(),\n \"effect\",\n \"Effect\"\n ) || \"Effect\"\n\n return ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectIdentifier),\n \"asVoid\"\n ),\n undefined,\n [\n yieldedExpression\n ]\n )\n }),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts)\n )\n }\n return { node, body, yieldedExpression, replacementNode }\n }\n // fall through\n break\n }\n\n // fall through case\n return yield* typeParserIssue(\n \"Not an handled node\",\n undefined,\n node\n )\n }),\n \"TypeParser.unnecessaryEffectGen\",\n (node) => node\n )\n\n const effectSchemaVarianceStruct = (\n type: ts.Type,\n atLocation: ts.Node\n ) =>\n Nano.map(\n Nano.all(\n varianceStructInvariantType(type, atLocation, \"_A\"),\n varianceStructInvariantType(type, atLocation, \"_I\"),\n varianceStructCovariantType(type, atLocation, \"_R\")\n ),\n ([A, I, R]) => ({ A, I, R })\n )\n\n const effectSchemaType = Nano.cachedBy(\n Nano.fn(\"TypeParser.effectSchemaType\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n ) {\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) && _.valueDeclaration &&\n ts.isPropertySignature(_.valueDeclaration) && ts.isComputedPropertyName(_.valueDeclaration.name)\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 \"TypeParser.effectSchemaType\",\n (type) => type\n )\n\n const contextTagVarianceStruct = (\n type: ts.Type,\n atLocation: ts.Node\n ) =>\n Nano.map(\n Nano.all(\n varianceStructInvariantType(type, atLocation, \"_Identifier\"),\n varianceStructInvariantType(type, atLocation, \"_Service\")\n ),\n ([Identifier, Service]) => ({ Identifier, Service })\n )\n\n const contextTag = Nano.cachedBy(\n Nano.fn(\"TypeParser.contextTag\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n ) {\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) && _.valueDeclaration &&\n ts.isPropertySignature(_.valueDeclaration) && ts.isComputedPropertyName(_.valueDeclaration.name)\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(contextTagVarianceStruct(\n propertyType,\n atLocation\n ))\n if (Option.isSome(varianceArgs)) {\n return varianceArgs.value\n }\n }\n return yield* typeParserIssue(\"Type has no tag variance struct\", type, atLocation)\n }),\n \"TypeParser.contextTag\",\n (type) => type\n )\n\n const pipeCall = Nano.cachedBy(\n function(\n node: ts.Node\n ): Nano.Nano<\n { node: ts.CallExpression; subject: ts.Expression; args: Array<ts.Expression>; kind: \"pipe\" | \"pipeable\" },\n TypeParserIssue,\n never\n > {\n // expression.pipe(.....)\n if (\n ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) &&\n ts.isIdentifier(node.expression.name) &&\n node.expression.name.text === \"pipe\"\n ) {\n return Nano.succeed({\n node,\n subject: node.expression.expression,\n args: Array.from(node.arguments),\n kind: \"pipeable\"\n })\n }\n\n // pipe(A, B, ...)\n if (\n ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === \"pipe\" &&\n node.arguments.length > 0\n ) {\n const [subject, ...args] = node.arguments\n return Nano.succeed({ node, subject, args, kind: \"pipe\" })\n }\n\n return typeParserIssue(\"Node is not a pipe call\", undefined, node)\n },\n \"TypeParser.pipeCall\",\n (node) => node\n )\n\n const scopeType = Nano.cachedBy(\n Nano.fn(\"TypeParser.scopeType\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n ) {\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) && _.valueDeclaration &&\n ts.isPropertySignature(_.valueDeclaration) && ts.isComputedPropertyName(_.valueDeclaration.name)\n )\n // try to put typeid first (heuristic to optimize hot path)\n propertiesSymbols.sort((a, b) => b.name.indexOf(\"ScopeTypeId\") - a.name.indexOf(\"ScopeTypeId\"))\n // has a property scope type id\n for (const propertySymbol of propertiesSymbols) {\n const computedPropertyExpression: ts.ComputedPropertyName = (propertySymbol.valueDeclaration as any).name\n const symbol = typeChecker.getSymbolAtLocation(computedPropertyExpression.expression)\n if (symbol && symbol.name === \"ScopeTypeId\") {\n return type\n }\n }\n return yield* typeParserIssue(\"Type has no scope type id\", type, atLocation)\n }),\n \"TypeParser.scopeType\",\n (type) => type\n )\n\n const promiseLike = Nano.cachedBy(\n function(\n type: ts.Type,\n atLocation: ts.Node\n ) {\n // maybe it is a Promise<A>?\n const thenProperty = type.getProperty(\"then\")\n if (!thenProperty) return typeParserIssue(\"not a promise - missing then property\", type, atLocation)\n const thenType = typeChecker.getTypeOfSymbolAtLocation(thenProperty, atLocation)\n if (!thenType) return typeParserIssue(\"not a promise - missing then property\", type, atLocation)\n // .then should be callable\n for (const callSignature of thenType.getCallSignatures()) {\n // take the callback argument of then\n const parameter = callSignature.parameters[0]\n if (!parameter) continue\n const parameterType = callSignature.getTypeParameterAtPosition(0)\n if (!parameterType) continue\n // it can be an union with many types\n let callbackCallSignatures: Array<ts.Signature> = []\n let toTest = [parameterType]\n while (toTest.length > 0) {\n const type = toTest.shift()\n if (!type) continue\n const callSignatures = type.getCallSignatures()\n callbackCallSignatures = callbackCallSignatures.concat(callSignatures)\n if (type.isUnion()) {\n toTest = toTest.concat(type.types)\n }\n }\n for (const callableType of callbackCallSignatures) {\n const callbackParameter = callableType.parameters[0]\n if (!callbackParameter) {\n continue\n }\n const callbackParameterType = callableType.getTypeParameterAtPosition(0)\n if (!callbackParameterType) {\n continue\n }\n return Nano.succeed({\n type: callbackParameterType\n })\n }\n }\n return typeParserIssue(\"not a promise\", type, atLocation)\n },\n \"TypeParser.promiseLike\",\n (type) => type\n )\n\n const extendsSchemaClass = Nano.cachedBy(\n Nano.fn(\"TypeParser.extendsSchemaClass\")(function*(\n atLocation: ts.ClassDeclaration\n ) {\n if (!atLocation.name) {\n return yield* typeParserIssue(\"Class has no name\", undefined, atLocation)\n }\n const heritageClauses = atLocation.heritageClauses\n if (!heritageClauses) {\n return yield* typeParserIssue(\"Class has no heritage clauses\", undefined, atLocation)\n }\n for (const heritageClause of heritageClauses) {\n for (const typeX of heritageClause.types) {\n if (ts.isExpressionWithTypeArguments(typeX)) {\n const expression = typeX.expression\n if (ts.isCallExpression(expression)) {\n // Schema.Class<T>(\"name\")({})\n const schemaCall = expression.expression\n if (ts.isCallExpression(schemaCall) && schemaCall.typeArguments && schemaCall.typeArguments.length > 0) {\n const selfTypeNode = schemaCall.typeArguments[0]!\n const schemaIdentifier = schemaCall.expression\n if (\n ts.isPropertyAccessExpression(schemaIdentifier) && ts.isIdentifier(schemaIdentifier.name) &&\n schemaIdentifier.name.text === \"Class\"\n ) {\n const parsedSchemaModule = yield* pipe(\n importedSchemaModule(schemaIdentifier.expression),\n Nano.option\n )\n if (Option.isSome(parsedSchemaModule)) {\n return {\n className: atLocation.name,\n selfTypeNode,\n Schema: parsedSchemaModule.value\n }\n }\n }\n }\n }\n }\n }\n }\n return yield* typeParserIssue(\"Class does not extend Schema.Class\", undefined, atLocation)\n }),\n \"TypeParser.extendsSchemaClass\",\n (atLocation) => atLocation\n )\n\n const extendsSchemaTaggedClass = Nano.cachedBy(\n Nano.fn(\"TypeParser.extendsSchemaTaggedClass\")(function*(\n atLocation: ts.ClassDeclaration\n ) {\n if (!atLocation.name) {\n return yield* typeParserIssue(\"Class has no name\", undefined, atLocation)\n }\n const heritageClauses = atLocation.heritageClauses\n if (!heritageClauses) {\n return yield* typeParserIssue(\"Class has no heritage clauses\", undefined, atLocation)\n }\n for (const heritageClause of heritageClauses) {\n for (const typeX of heritageClause.types) {\n if (ts.isExpressionWithTypeArguments(typeX)) {\n const expression = typeX.expression\n if (ts.isCallExpression(expression)) {\n // Schema.TaggedClass<T>(\"name\")(\"tag\", {})\n const tagCall = expression.expression\n if (ts.isCallExpression(tagCall)) {\n const schemaCall = tagCall.expression\n if (\n ts.isCallExpression(schemaCall) && schemaCall.typeArguments && schemaCall.typeArguments.length > 0\n ) {\n const selfTypeNode = schemaCall.typeArguments[0]!\n const schemaIdentifier = schemaCall.expression\n if (\n ts.isPropertyAccessExpression(schemaIdentifier) && ts.isIdentifier(schemaIdentifier.name) &&\n schemaIdentifier.name.text === \"TaggedClass\"\n ) {\n const parsedSchemaModule = yield* pipe(\n importedSchemaModule(schemaIdentifier.expression),\n Nano.option\n )\n if (Option.isSome(parsedSchemaModule)) {\n return {\n className: atLocation.name,\n selfTypeNode,\n Schema: parsedSchemaModule.value\n }\n }\n }\n }\n }\n }\n }\n }\n }\n return yield* typeParserIssue(\"Class does not extend Schema.TaggedClass\", undefined, atLocation)\n }),\n \"TypeParser.extendsSchemaTaggedClass\",\n (atLocation) => atLocation\n )\n\n const extendsSchemaTaggedError = Nano.cachedBy(\n Nano.fn(\"TypeParser.extendsSchemaTaggedError\")(function*(\n atLocation: ts.ClassDeclaration\n ) {\n if (!atLocation.name) {\n return yield* typeParserIssue(\"Class has no name\", undefined, atLocation)\n }\n const heritageClauses = atLocation.heritageClauses\n if (!heritageClauses) {\n return yield* typeParserIssue(\"Class has no heritage clauses\", undefined, atLocation)\n }\n for (const heritageClause of heritageClauses) {\n for (const typeX of heritageClause.types) {\n if (ts.isExpressionWithTypeArguments(typeX)) {\n const expression = typeX.expression\n if (ts.isCallExpression(expression)) {\n // Schema.TaggedError<T>(\"name\")(\"tag\", {})\n const tagCall = expression.expression\n if (ts.isCallExpression(tagCall)) {\n const schemaCall = tagCall.expression\n if (\n ts.isCallExpression(schemaCall) && schemaCall.typeArguments && schemaCall.typeArguments.length > 0\n ) {\n const selfTypeNode = schemaCall.typeArguments[0]!\n const schemaIdentifier = schemaCall.expression\n if (\n ts.isPropertyAccessExpression(schemaIdentifier) && ts.isIdentifier(schemaIdentifier.name) &&\n schemaIdentifier.name.text === \"TaggedError\"\n ) {\n const parsedSchemaModule = yield* pipe(\n importedSchemaModule(schemaIdentifier.expression),\n Nano.option\n )\n if (Option.isSome(parsedSchemaModule)) {\n return {\n className: atLocation.name,\n selfTypeNode,\n Schema: parsedSchemaModule.value\n }\n }\n }\n }\n }\n }\n }\n }\n }\n return yield* typeParserIssue(\"Class does not extend Schema.TaggedError\", undefined, atLocation)\n }),\n \"TypeParser.extendsSchemaTaggedError\",\n (atLocation) => atLocation\n )\n\n const extendsSchemaTaggedRequest = Nano.cachedBy(\n Nano.fn(\"TypeParser.extendsSchemaTaggedRequest\")(function*(\n atLocation: ts.ClassDeclaration\n ) {\n if (!atLocation.name) {\n return yield* typeParserIssue(\"Class has no name\", undefined, atLocation)\n }\n const heritageClauses = atLocation.heritageClauses\n if (!heritageClauses) {\n return yield* typeParserIssue(\"Class has no heritage clauses\", undefined, atLocation)\n }\n for (const heritageClause of heritageClauses) {\n for (const typeX of heritageClause.types) {\n if (ts.isExpressionWithTypeArguments(typeX)) {\n const expression = typeX.expression\n if (ts.isCallExpression(expression)) {\n // Schema.TaggedRequest<T>(\"name\")(\"tag\", {})\n const tagCall = expression.expression\n if (ts.isCallExpression(tagCall)) {\n const schemaCall = tagCall.expression\n if (\n ts.isCallExpression(schemaCall) && schemaCall.typeArguments && schemaCall.typeArguments.length > 0\n ) {\n const selfTypeNode = schemaCall.typeArguments[0]!\n const schemaIdentifier = schemaCall.expression\n if (\n ts.isPropertyAccessExpression(schemaIdentifier) && ts.isIdentifier(schemaIdentifier.name) &&\n schemaIdentifier.name.text === \"TaggedRequest\"\n ) {\n const parsedSchemaModule = yield* pipe(\n importedSchemaModule(schemaIdentifier.expression),\n Nano.option\n )\n if (Option.isSome(parsedSchemaModule)) {\n return {\n className: atLocation.name,\n selfTypeNode,\n Schema: parsedSchemaModule.value\n }\n }\n }\n }\n }\n }\n }\n }\n }\n return yield* typeParserIssue(\"Class does not extend Schema.TaggedRequest\", undefined, atLocation)\n }),\n \"TypeParser.extendsSchemaTaggedRequest\",\n (atLocation) => atLocation\n )\n\n const extendsContextTag = Nano.cachedBy(\n Nano.fn(\"TypeParser.extendsContextTag\")(function*(\n atLocation: ts.ClassDeclaration\n ) {\n if (!atLocation.name) {\n return yield* typeParserIssue(\"Class has no name\", undefined, atLocation)\n }\n const classSym = typeChecker.getSymbolAtLocation(atLocation.name)\n if (!classSym) return yield* typeParserIssue(\"Class has no symbol\", undefined, atLocation)\n const type = typeChecker.getTypeOfSymbol(classSym)\n const heritageClauses = atLocation.heritageClauses\n if (!heritageClauses) {\n return yield* typeParserIssue(\"Class has no heritage clauses\", undefined, atLocation)\n }\n for (const heritageClause of heritageClauses) {\n for (const typeX of heritageClause.types) {\n if (ts.isExpressionWithTypeArguments(typeX)) {\n const wholeCall = typeX.expression\n if (ts.isCallExpression(wholeCall)) {\n const contextTagCall = wholeCall.expression\n if (\n ts.isCallExpression(contextTagCall) &&\n wholeCall.typeArguments && wholeCall.typeArguments.length > 0\n ) {\n const contextTagIdentifier = contextTagCall.expression\n const selfTypeNode = wholeCall.typeArguments[0]!\n if (\n ts.isPropertyAccessExpression(contextTagIdentifier) &&\n ts.isIdentifier(contextTagIdentifier.name) && contextTagIdentifier.name.text === \"Tag\"\n ) {\n const parsedContextModule = yield* pipe(\n importedContextModule(contextTagIdentifier.expression),\n Nano.option\n )\n if (Option.isSome(parsedContextModule)) {\n const tagType = yield* contextTag(type, atLocation)\n return {\n className: atLocation.name,\n selfTypeNode,\n args: contextTagCall.arguments,\n Identifier: tagType.Identifier,\n Tag: parsedContextModule.value\n }\n }\n }\n }\n }\n }\n }\n }\n return yield* typeParserIssue(\"Class does not extend Context.Tag\", undefined, atLocation)\n }),\n \"TypeParser.extendsContextTag\",\n (atLocation) => atLocation\n )\n\n const extendsEffectService = Nano.cachedBy(\n Nano.fn(\"TypeParser.extendsEffectService\")(function*(\n atLocation: ts.ClassDeclaration\n ) {\n if (!atLocation.name) {\n return yield* typeParserIssue(\"Class has no name\", undefined, atLocation)\n }\n const classSym = typeChecker.getSymbolAtLocation(atLocation.name)\n if (!classSym) return yield* typeParserIssue(\"Class has no symbol\", undefined, atLocation)\n const type = typeChecker.getTypeOfSymbol(classSym)\n const heritageClauses = atLocation.heritageClauses\n if (!heritageClauses) {\n return yield* typeParserIssue(\"Class has no heritage clauses\", undefined, atLocation)\n }\n for (const heritageClause of heritageClauses) {\n for (const typeX of heritageClause.types) {\n if (ts.isExpressionWithTypeArguments(typeX)) {\n const wholeCall = typeX.expression\n if (ts.isCallExpression(wholeCall)) {\n const effectServiceCall = wholeCall.expression\n if (\n ts.isCallExpression(effectServiceCall) &&\n effectServiceCall.typeArguments && effectServiceCall.typeArguments.length > 0\n ) {\n const effectServiceIdentifier = effectServiceCall.expression\n const selfTypeNode = effectServiceCall.typeArguments[0]!\n if (\n ts.isPropertyAccessExpression(effectServiceIdentifier) &&\n ts.isIdentifier(effectServiceIdentifier.name) && effectServiceIdentifier.name.text === \"Service\"\n ) {\n const parsedContextTag = yield* pipe(\n importedEffectModule(effectServiceIdentifier.expression),\n Nano.flatMap(() => contextTag(type, atLocation)),\n Nano.option\n )\n if (Option.isSome(parsedContextTag)) {\n // try to parse some settings\n let accessors: boolean | undefined = undefined\n let dependencies: ts.NodeArray<ts.Expression> | undefined = undefined\n if (wholeCall.arguments.length >= 2) {\n const args = wholeCall.arguments[1]\n if (ts.isObjectLiteralExpression(args)) {\n for (const property of args.properties) {\n if (\n ts.isPropertyAssignment(property) && property.name && ts.isIdentifier(property.name) &&\n property.name.text === \"accessors\" && property.initializer &&\n property.initializer.kind === ts.SyntaxKind.TrueKeyword\n ) {\n accessors = true\n }\n if (\n ts.isPropertyAssignment(property) && property.name && ts.isIdentifier(property.name) &&\n property.name.text === \"dependencies\" && property.initializer &&\n ts.isArrayLiteralExpression(property.initializer)\n ) {\n dependencies = property.initializer.elements\n }\n }\n }\n }\n return ({\n ...parsedContextTag.value,\n className: atLocation.name,\n selfTypeNode,\n args: wholeCall.arguments,\n options: wholeCall.arguments[1],\n accessors,\n dependencies\n })\n }\n }\n }\n }\n }\n }\n }\n\n return yield* typeParserIssue(\"Class does not extend Effect.Service\", undefined, atLocation)\n }),\n \"TypeParser.extendsEffectService\",\n (atLocation) => atLocation\n )\n\n return {\n effectType,\n strictEffectType,\n layerType,\n fiberType,\n effectSubtype,\n importedEffectModule,\n effectGen,\n effectFnUntracedGen,\n effectFnGen,\n unnecessaryEffectGen,\n effectSchemaType,\n contextTag,\n pipeableType,\n pipeCall,\n scopeType,\n promiseLike,\n extendsEffectService,\n extendsContextTag,\n extendsSchemaClass,\n extendsSchemaTaggedClass,\n extendsSchemaTaggedError,\n extendsSchemaTaggedRequest\n }\n}\n","import { pipe } from \"effect\"\nimport type ts from \"typescript\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const classSelfMismatch = LSP.createDiagnostic({\n name: \"classSelfMismatch\",\n code: 20,\n severity: \"error\",\n apply: Nano.fn(\"classSelfMismatch.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\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\n // Check if this is a class declaration that extends Effect.Service, Context.Tag, or Schema classes\n if (ts.isClassDeclaration(node) && node.name && node.heritageClauses) {\n // Check if this class extends a class that has a Self type parameter\n const result = yield* pipe(\n typeParser.extendsEffectService(node),\n Nano.orElse(() => typeParser.extendsContextTag(node)),\n Nano.orElse(() => typeParser.extendsSchemaClass(node)),\n Nano.orElse(() => typeParser.extendsSchemaTaggedClass(node)),\n Nano.orElse(() => typeParser.extendsSchemaTaggedError(node)),\n Nano.orElse(() => typeParser.extendsSchemaTaggedRequest(node)),\n Nano.orElse(() => Nano.void_)\n )\n\n if (result) {\n // Both methods return { selfTypeNode, className } when they match\n const { className, selfTypeNode } = result\n\n // Get the actual name from the self type node\n let actualName = \"\"\n if (ts.isTypeReferenceNode(selfTypeNode)) {\n if (ts.isIdentifier(selfTypeNode.typeName)) {\n actualName = selfTypeNode.typeName.text\n } else if (ts.isQualifiedName(selfTypeNode.typeName)) {\n actualName = selfTypeNode.typeName.right.text\n }\n }\n\n // Check if the self type matches the class name\n const expectedName = className.text\n if (actualName !== expectedName) {\n report({\n location: selfTypeNode,\n messageText: `Self type parameter should be '${expectedName}'`,\n fixes: [{\n fixName: \"classSelfMismatch_fix\",\n description: `Replace '${actualName}' with '${expectedName}'`,\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n // Create a new type reference with the correct class name\n const typeArgs = ts.isTypeReferenceNode(selfTypeNode) ? selfTypeNode.typeArguments : undefined\n const newTypeReference = ts.factory.createTypeReferenceNode(\n ts.factory.createIdentifier(expectedName),\n typeArgs\n )\n\n // Replace the incorrect type reference with the correct one\n changeTracker.replaceNode(sourceFile, selfTypeNode, newTypeReference)\n })\n }]\n })\n }\n }\n }\n\n ts.forEachChild(node, appendNodeToVisit)\n }\n })\n})\n","import { hasProperty, isNumber } from \"effect/Predicate\"\nimport * as LanguageServicePluginOptions from \"../core/LanguageServicePluginOptions.js\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as TypeScriptUtils from \"../core/TypeScriptUtils.js\"\n\ntype ResolvedPackagesCache = Record<string, Record<string, any>>\n\nconst checkedPackagesCache = new Map<string, ResolvedPackagesCache>()\nconst programResolvedCacheSize = new Map<string, number>()\n\nexport const duplicatePackage = LSP.createDiagnostic({\n name: \"duplicatePackage\",\n code: 6,\n severity: \"warning\",\n apply: Nano.fn(\"duplicatePackage.apply\")(function*(sourceFile, report) {\n const program = yield* Nano.service(TypeScriptApi.TypeScriptProgram)\n const tsUtils = yield* Nano.service(TypeScriptUtils.TypeScriptUtils)\n const options = yield* Nano.service(LanguageServicePluginOptions.LanguageServicePluginOptions)\n\n if (sourceFile.statements.length < 1) return\n\n // whenever we detect the resolution cache size has changed, try again the check\n // this should mitigate how frequently this rule is triggered\n let resolvedPackages: ResolvedPackagesCache = checkedPackagesCache.get(sourceFile.fileName) ||\n {}\n const newResolvedModuleSize =\n hasProperty(program, \"resolvedModules\") && hasProperty(program.resolvedModules, \"size\") &&\n isNumber(program.resolvedModules.size) ?\n program.resolvedModules.size :\n 0\n const oldResolvedSize = programResolvedCacheSize.get(sourceFile.fileName) || -1\n if (newResolvedModuleSize !== oldResolvedSize) {\n const seenPackages = new Set<string>()\n resolvedPackages = {}\n program.getSourceFiles().map((_) => {\n const packageInfo = tsUtils.parsePackageContentNameAndVersionFromScope(_)\n if (!packageInfo) return\n const packageNameAndVersion = packageInfo.name + \"@\" + packageInfo.version\n if (seenPackages.has(packageNameAndVersion)) return\n seenPackages.add(packageNameAndVersion)\n if (\n !(packageInfo.name === \"effect\" || packageInfo.hasEffectInPeerDependencies)\n ) return\n if (options.allowedDuplicatedPackages.indexOf(packageInfo.name) > -1) return\n resolvedPackages[packageInfo.name] = resolvedPackages[packageInfo.name] || {}\n resolvedPackages[packageInfo.name][packageInfo.version] = packageInfo.packageDirectory\n })\n checkedPackagesCache.set(sourceFile.fileName, resolvedPackages)\n programResolvedCacheSize.set(sourceFile.fileName, newResolvedModuleSize)\n }\n\n for (const packageName of Object.keys(resolvedPackages)) {\n if (Object.keys(resolvedPackages[packageName]).length > 1) {\n const versions = Object.keys(resolvedPackages[packageName])\n report({\n location: sourceFile.statements[0],\n messageText: `Package ${packageName} is referenced multiple times with different versions (${\n versions.join(\", \")\n }) and may cause unexpected type errors.\\nCleanup your dependencies and your package lockfile to avoid multiple instances of this package and reload the project.\\nIf this is intended set the LSP config \"allowedDuplicatedPackages\" to ${\n JSON.stringify(options.allowedDuplicatedPackages.concat([packageName]))\n }.\\n\\n${\n versions.map((version) => `- found ${version} at ${resolvedPackages[packageName][version]}`).join(\"\\n\")\n }`,\n fixes: []\n })\n }\n }\n })\n})\n","import { 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 TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const effectInVoidSuccess = LSP.createDiagnostic({\n name: \"effectInVoidSuccess\",\n code: 14,\n severity: \"warning\",\n apply: Nano.fn(\"effectInVoidSuccess.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\n\n const checkForEffectInVoid = Nano.fn(\"effectInVoidSuccess.checkForEffectInVoid\")(function*(\n node: ts.Node,\n expectedType: ts.Type,\n valueNode: ts.Node,\n realType: ts.Type\n ) {\n const expectedEffect = yield* typeParser.effectType(expectedType, node)\n const realEffect = yield* typeParser.effectType(realType, valueNode)\n if (expectedEffect.A.flags & ts.TypeFlags.Void) {\n const voidValueTypes = TypeCheckerApi.unrollUnionMembers(realEffect.A)\n const voidedEffect = yield* Nano.firstSuccessOf(\n voidValueTypes.map((_) => Nano.map(typeParser.strictEffectType(_, node), () => _))\n )\n return { voidedEffect }\n }\n return yield* Nano.fail(TypeParser.typeParserIssue(\"expectedEffect success is not void\"))\n })\n\n const entries = yield* TypeCheckerApi.expectedAndRealType(sourceFile)\n for (const [node, expectedType, valueNode, realType] of entries) {\n if (expectedType !== realType) {\n yield* pipe(\n checkForEffectInVoid(\n node,\n expectedType,\n valueNode,\n realType\n ),\n Nano.map(({ voidedEffect }) => {\n report(\n {\n location: node,\n messageText: `There is a nested '${\n typeChecker.typeToString(voidedEffect)\n }' in the 'void' success channel, beware that this could lead to nested Effect<Effect<...>> that won't be executed.`,\n fixes: []\n }\n )\n }),\n Nano.ignore\n )\n }\n }\n })\n})\n","import { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeCheckerApi from \"../core/TypeCheckerApi.js\"\nimport * as TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const floatingEffect = LSP.createDiagnostic({\n name: \"floatingEffect\",\n code: 3,\n severity: \"error\",\n apply: Nano.fn(\"floatingEffect.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\n\n function isFloatingExpression(node: ts.Node): node is ts.ExpressionStatement {\n // should be an expression statement\n if (!ts.isExpressionStatement(node)) return false\n // parent is either block or source file\n if (!(ts.isBlock(node.parent) || ts.isSourceFile(node.parent))) return false\n const expression = node.expression\n // this.variable = Effect.succeed is a valid expression\n if (\n ts.isBinaryExpression(expression) && expression.operatorToken &&\n (expression.operatorToken.kind === ts.SyntaxKind.EqualsToken ||\n expression.operatorToken.kind === ts.SyntaxKind.QuestionQuestionEqualsToken ||\n expression.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandEqualsToken ||\n expression.operatorToken.kind === ts.SyntaxKind.BarBarEqualsToken)\n ) return false\n return true\n }\n\n const 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 // check if strictly an effect or a subtype to change the error message\n const isStrictEffect = yield* Nano.option(typeParser.strictEffectType(type, node.expression))\n const name = Option.isSome(isStrictEffect) ? \"Effect\" : \"Effect-able \" + typeChecker.typeToString(type)\n report({\n location: node,\n messageText: `${name} must be yielded or assigned to a variable.`,\n fixes: []\n })\n }\n }\n }\n })\n})\n","import { 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 TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const genericEffectServices = LSP.createDiagnostic({\n name: \"genericEffectServices\",\n code: 10,\n severity: \"warning\",\n apply: Nano.fn(\"genericEffectServices.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\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 const typesToCheck: Array<[ts.Type, ts.Node]> = []\n\n if (ts.isClassDeclaration(node) && node.name && node.typeParameters && node.heritageClauses) {\n const classSym = typeChecker.getSymbolAtLocation(node.name)\n if (classSym) {\n const type = typeChecker.getTypeOfSymbol(classSym)\n typesToCheck.push([type, node.name!])\n }\n } else {\n ts.forEachChild(node, appendNodeToVisit)\n continue\n }\n\n // check the types\n for (const [type, reportAt] of typesToCheck) {\n yield* pipe(\n typeParser.contextTag(type, node),\n Nano.map(() => {\n report({\n location: reportAt,\n messageText:\n `Effect Services with type parameters are not supported because they cannot be properly discriminated at runtime, which may cause unexpected behavior.`,\n fixes: []\n })\n }),\n Nano.orElse(() => Nano.sync(() => ts.forEachChild(node, appendNodeToVisit))),\n Nano.ignore\n )\n }\n }\n })\n})\n","import * as Array from \"effect/Array\"\nimport type ts from \"typescript\"\nimport * as LanguageServicePluginOptions from \"../core/LanguageServicePluginOptions.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 TypeScriptUtils from \"../core/TypeScriptUtils.js\"\n\nexport const importFromBarrel = LSP.createDiagnostic({\n name: \"importFromBarrel\",\n code: 12,\n severity: \"off\",\n apply: Nano.fn(\"importFromBarrel.apply\")(function*(sourceFile, report) {\n // requires namespaceImportPackages to be set\n const languageServicePluginOptions = yield* Nano.service(LanguageServicePluginOptions.LanguageServicePluginOptions)\n if (languageServicePluginOptions.namespaceImportPackages.length === 0) return\n\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const tsUtils = yield* Nano.service(TypeScriptUtils.TypeScriptUtils)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const program = yield* Nano.service(TypeScriptApi.TypeScriptProgram)\n const packageNamesToCheck = Array.flatten(\n languageServicePluginOptions.namespaceImportPackages.map((packageName) =>\n tsUtils.resolveModulePattern(sourceFile, packageName)\n )\n )\n\n const isImportedFromBarrelExport = (\n element: ts.ImportSpecifier\n ) => {\n const getModuleSpecifier = tsUtils.makeGetModuleSpecifier()\n const resolveExternalModuleName = TypeCheckerApi.makeResolveExternalModuleName(typeChecker)\n\n if (!(getModuleSpecifier && resolveExternalModuleName)) return\n\n const importDeclaration = ts.findAncestor(element, (node) => ts.isImportDeclaration(node))\n if (!importDeclaration) return\n if (!ts.isStringLiteral(importDeclaration.moduleSpecifier)) return\n const importClause = importDeclaration.importClause\n if (!importClause) return\n const namedBindings = importClause.namedBindings\n if (!namedBindings) return\n if (!ts.isNamedImports(namedBindings)) return\n\n const barrelModuleName = importDeclaration.moduleSpecifier.text\n if (packageNamesToCheck.indexOf(barrelModuleName.toLowerCase()) === -1) return\n const moduleSymbol = resolveExternalModuleName(importDeclaration.moduleSpecifier)\n if (!moduleSymbol) return\n if (!moduleSymbol.exports) return\n const sourceFile = importDeclaration.getSourceFile()\n\n const nodeForSymbol = element.propertyName || element.name\n const aliasSymbol = element.name || element.propertyName\n const aliasedName = aliasSymbol.text\n\n // we can only check for identifiers\n if (!ts.isIdentifier(nodeForSymbol)) return\n const importedName = nodeForSymbol.text\n // get the symbol of the re-export\n const reexportedSymbol = moduleSymbol.exports.get(ts.escapeLeadingUnderscores(importedName))\n if (!reexportedSymbol) return\n // if we have only a declaration\n if (!(reexportedSymbol.declarations && reexportedSymbol.declarations.length === 1)) return\n // that should be an 'export * as X from \"module\"'\n const namespaceExport = reexportedSymbol.declarations[0]\n if (!ts.isNamespaceExport(namespaceExport)) return\n // parent should be an export declaration\n const exportDeclaration = namespaceExport.parent\n if (!ts.isExportDeclaration(exportDeclaration)) return\n // if we have a module specifier, resolve that symbol\n if (!exportDeclaration.moduleSpecifier) return\n const originalModuleSymbol = resolveExternalModuleName(exportDeclaration.moduleSpecifier)\n if (!originalModuleSymbol) return\n // the value declaration should be the sourcefile of the original module\n if (!originalModuleSymbol.valueDeclaration) return\n const originalSourceFile = originalModuleSymbol.valueDeclaration.getSourceFile()\n const unbarrelledFileName = getModuleSpecifier(\n program.getCompilerOptions(),\n sourceFile,\n sourceFile.fileName,\n originalSourceFile.fileName,\n program\n )\n // need to start with the barrel module name, otherwise its not the same package\n if (unbarrelledFileName.toLowerCase().indexOf(barrelModuleName.toLowerCase() + \"/\") === -1) return\n return {\n unbarrelledFileName,\n importedName,\n barrelModuleName,\n importClause,\n namedBindings,\n importDeclaration,\n aliasedName\n }\n }\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 const parent = node.parent\n\n if (!(ts.isImportSpecifier(node) && ts.isNamedImports(parent))) {\n ts.forEachChild(node, appendNodeToVisit)\n continue\n }\n\n const result = isImportedFromBarrelExport(node)\n if (!result) continue\n const {\n aliasedName,\n barrelModuleName,\n importClause,\n importDeclaration,\n namedBindings,\n unbarrelledFileName\n } = result\n // ok, I think now we can report the error\n report({\n location: node,\n messageText: `Importing from barrel module ${barrelModuleName} is not allowed.`,\n fixes: [\n {\n fixName: \"replaceWithUnbarrelledImport\",\n description: `Import * as ${aliasedName} from ${unbarrelledFileName}`,\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n const newImport = ts.factory.createImportDeclaration(\n undefined,\n ts.factory.createImportClause(\n importClause.isTypeOnly || node.isTypeOnly,\n undefined,\n ts.factory.createNamespaceImport(ts.factory.createIdentifier(aliasedName))\n ),\n ts.factory.createStringLiteral(unbarrelledFileName)\n )\n\n if (namedBindings.elements.length === 1) {\n changeTracker.replaceNode(\n sourceFile,\n importDeclaration,\n newImport\n )\n } else {\n changeTracker.insertNodeAfter(sourceFile, importDeclaration, newImport)\n changeTracker.replaceNode(\n sourceFile,\n namedBindings,\n ts.factory.updateNamedImports(\n namedBindings,\n namedBindings.elements.filter((e) => e !== node)\n )\n )\n }\n })\n }\n ]\n })\n }\n })\n})\n","import * as Array 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 TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const leakingRequirements = LSP.createDiagnostic({\n name: \"leakingRequirements\",\n code: 8,\n severity: \"suggestion\",\n apply: Nano.fn(\"leakingRequirements.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\n const typeOrder = yield* TypeCheckerApi.deterministicTypeOrder\n\n const parseLeakedRequirements = Nano.cachedBy(\n Nano.fn(\"leakingServices.checkServiceLeaking\")(\n function*(service: ts.Type, atLocation: ts.Node) {\n const properties = typeChecker.getPropertiesOfType(service)\n // since this is an heuristic, we require at least 2 props\n if (properties.length < 1) return []\n // store the accumulated services\n const memory = new Map<string, ts.Type>()\n let sharedRequirementsKeys: Array<string> | undefined = undefined\n let effectMembers = 0\n for (const property of properties) {\n // get the context type of the property, either Effect<...> or () => Effect<...>\n const servicePropertyType = typeChecker.getTypeOfSymbolAtLocation(property, atLocation)\n let effectContextType: ts.Type | undefined = undefined\n yield* pipe(\n typeParser.effectType(servicePropertyType, atLocation),\n Nano.map((_) => effectContextType = _.R),\n Nano.orElse(() => {\n const servicePropertyCallSignatures = servicePropertyType.getCallSignatures()\n if (servicePropertyCallSignatures.length === 1) {\n return pipe(\n typeParser.effectType(servicePropertyCallSignatures[0].getReturnType(), atLocation),\n Nano.map((_) => {\n effectContextType = _.R\n })\n )\n }\n return Nano.void_\n }),\n Nano.ignore\n )\n // once we have the type, check the context for shared requirements\n if (effectContextType) {\n effectMembers++\n const { allIndexes } = yield* TypeCheckerApi.appendToUniqueTypesMap(\n memory,\n effectContextType,\n (type) => {\n // exclude never\n if (type.flags & ts.TypeFlags.Never) return Nano.succeed(true)\n // exclude scope\n return pipe(\n typeParser.scopeType(type, atLocation),\n Nano.map(() => true),\n Nano.orElse(() => Nano.succeed(false))\n )\n }\n )\n if (!sharedRequirementsKeys) {\n sharedRequirementsKeys = allIndexes\n } else {\n sharedRequirementsKeys = Array.intersection(sharedRequirementsKeys, allIndexes)\n if (sharedRequirementsKeys.length === 0) return []\n }\n }\n }\n // ...and those at least 2 props must be or return effects\n if (sharedRequirementsKeys && sharedRequirementsKeys.length > 0 && effectMembers >= 2) {\n return sharedRequirementsKeys.map((key) => memory.get(key)!)\n }\n return []\n }\n ),\n \"leakingServices.checkServiceLeaking\",\n (_, service) => service\n )\n\n function reportLeakingRequirements(node: ts.Node, requirements: Array<ts.Type>) {\n if (requirements.length === 0) return\n report({\n location: node,\n messageText: `This Service is leaking the ${\n requirements.map((_) => typeChecker.typeToString(_)).join(\" | \")\n } requirement.\\nIf these requirements cannot be cached and are expected to be provided per method invocation (e.g. HttpServerRequest), you can safely disable this diagnostic for this line through quickfixes.\\nMore info at https://effect.website/docs/requirements-management/layers/#avoiding-requirement-leakage`,\n fixes: []\n })\n }\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\n // we need to check the type of the class declaration (if any)\n const typesToCheck: Array<[type: ts.Type, reportNode: ts.Node]> = []\n if (\n ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) &&\n ts.isIdentifier(node.expression.name) && node.expression.name.text === \"GenericTag\"\n ) {\n typesToCheck.push([typeChecker.getTypeAtLocation(node), node])\n } else if (ts.isClassDeclaration(node) && node.name && node.heritageClauses) {\n const classSym = typeChecker.getSymbolAtLocation(node.name)\n if (classSym) {\n const type = typeChecker.getTypeOfSymbol(classSym)\n typesToCheck.push([type, node.name])\n }\n } else {\n ts.forEachChild(node, appendNodeToVisit)\n continue\n }\n\n // check the types\n for (const [type, reportAt] of typesToCheck) {\n yield* pipe(\n typeParser.contextTag(type, node),\n Nano.flatMap(({ Service }) =>\n pipe(\n parseLeakedRequirements(Service, node),\n Nano.map((requirements) => reportLeakingRequirements(reportAt, Array.sort(requirements, typeOrder)))\n )\n ),\n Nano.orElse(() => Nano.sync(() => ts.forEachChild(node, appendNodeToVisit))),\n Nano.ignore\n )\n }\n }\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 TypeParser from \"../core/TypeParser.js\"\n\nexport const missingEffectContext = LSP.createDiagnostic({\n name: \"missingEffectContext\",\n code: 1,\n severity: \"error\",\n apply: Nano.fn(\"missingEffectContext.apply\")(function*(sourceFile, report) {\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\n const typeOrder = yield* TypeCheckerApi.deterministicTypeOrder\n\n const checkForMissingContextTypes = (\n node: ts.Node,\n expectedType: ts.Type,\n valueNode: ts.Node,\n realType: ts.Type\n ) =>\n pipe(\n Nano.all(\n typeParser.effectType(expectedType, node),\n typeParser.effectType(realType, valueNode)\n ),\n Nano.flatMap(([expectedEffect, realEffect]) =>\n TypeCheckerApi.getMissingTypeEntriesInTargetType(\n realEffect.R,\n expectedEffect.R\n )\n )\n )\n\n const sortTypes = ReadonlyArray.sort(typeOrder)\n\n const entries = yield* TypeCheckerApi.expectedAndRealType(sourceFile)\n for (const [node, expectedType, valueNode, realType] of entries) {\n // if the types are different, check for missing context types\n if (expectedType !== realType) {\n yield* pipe(\n checkForMissingContextTypes(\n node,\n expectedType,\n valueNode,\n realType\n ),\n Nano.map((missingTypes) =>\n missingTypes.length > 0 ?\n report(\n {\n location: node,\n messageText: `Missing '${\n sortTypes(missingTypes).map((_) => typeChecker.typeToString(_)).join(\" | \")\n }' in the expected Effect context.`,\n fixes: []\n }\n )\n : undefined\n ),\n Nano.ignore\n )\n }\n }\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Order from \"effect/Order\"\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 TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as TypeScriptUtils from \"../core/TypeScriptUtils.js\"\n\nexport const missingEffectError = LSP.createDiagnostic({\n name: \"missingEffectError\",\n code: 1,\n severity: \"error\",\n apply: Nano.fn(\"missingEffectError.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const tsUtils = yield* Nano.service(TypeScriptUtils.TypeScriptUtils)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\n const typeOrder = yield* TypeCheckerApi.deterministicTypeOrder\n\n const effectModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(\n sourceFile,\n \"effect\",\n \"Effect\"\n ) || \"Effect\"\n\n const createDieMessage = (message: string) =>\n ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectModuleIdentifier),\n \"dieMessage\"\n ),\n undefined,\n [ts.factory.createStringLiteral(message)]\n )\n\n const checkForMissingErrorTypes = (\n node: ts.Node,\n expectedType: ts.Type,\n valueNode: ts.Node,\n realType: ts.Type\n ) =>\n pipe(\n Nano.all(\n typeParser.effectType(expectedType, node),\n typeParser.effectType(realType, valueNode)\n ),\n Nano.flatMap(([expectedEffect, realEffect]) =>\n pipe(\n TypeCheckerApi.getMissingTypeEntriesInTargetType(\n realEffect.E,\n expectedEffect.E\n ),\n Nano.map((missingErrorTypes) => ({ missingErrorTypes, expectedErrorType: expectedEffect.E }))\n )\n )\n )\n\n const sortTypes = ReadonlyArray.sort(typeOrder)\n\n const entries = yield* TypeCheckerApi.expectedAndRealType(sourceFile)\n for (const [node, expectedType, valueNode, realType] of entries) {\n // if the types are different, check for missing error types\n if (expectedType !== realType) {\n yield* pipe(\n checkForMissingErrorTypes(\n node,\n expectedType,\n valueNode,\n realType\n ),\n Nano.map((result) => {\n if (result.missingErrorTypes.length === 0) return\n const fixes: Array<LSP.ApplicableDiagnosticDefinitionFix> = []\n\n if (ts.isExpression(valueNode) && result.expectedErrorType.flags & ts.TypeFlags.Never) {\n fixes.push({\n fixName: \"missingEffectError_catchAll\",\n description: \"Catch all errors with Effect.catchAll\",\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n changeTracker.insertText(sourceFile, valueNode.getStart(), effectModuleIdentifier + \".catchAll(\")\n changeTracker.insertText(sourceFile, valueNode.getEnd(), \", () => \")\n changeTracker.insertNodeAt(\n sourceFile,\n valueNode.getEnd(),\n createDieMessage(\"TODO: catchAll not implemented\")\n )\n changeTracker.insertText(sourceFile, valueNode.getEnd(), \")\")\n })\n })\n }\n\n if (ts.isExpression(valueNode)) {\n const propertyAssignments = pipe(\n result.missingErrorTypes,\n ReadonlyArray.map((_) => typeChecker.getPropertyOfType(_, \"_tag\")),\n ReadonlyArray.filter((_) => !!_),\n ReadonlyArray.map((_) => typeChecker.getTypeOfSymbolAtLocation(_, valueNode)),\n ReadonlyArray.filter((_) => !!(_.flags & ts.TypeFlags.Literal)),\n ReadonlyArray.map((_) => typeChecker.typeToTypeNode(_, undefined, ts.NodeBuilderFlags.NoTruncation)),\n ReadonlyArray.filter((_) => !!_ && ts.isLiteralTypeNode(_)),\n ReadonlyArray.map((_) => _.literal),\n ReadonlyArray.filter((_) => ts.isLiteralExpression(_)),\n ReadonlyArray.map((_) => _.text),\n ReadonlyArray.sort(Order.string),\n ReadonlyArray.map((_) =>\n ts.factory.createPropertyAssignment(\n ts.factory.createIdentifier(_),\n ts.factory.createArrowFunction(\n undefined,\n undefined,\n [],\n undefined,\n undefined,\n createDieMessage(`TODO: catchTags() not implemented for ${_}`)\n )\n )\n )\n )\n if (propertyAssignments.length === result.missingErrorTypes.length) {\n fixes.push({\n fixName: \"missingEffectError_tagged\",\n description: \"Catch unexpected errors with Effect.catchTag\",\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n changeTracker.insertText(sourceFile, valueNode.getStart(), effectModuleIdentifier + \".catchTags(\")\n changeTracker.insertText(sourceFile, valueNode.getEnd(), \", \")\n changeTracker.insertNodeAt(\n sourceFile,\n valueNode.getEnd(),\n ts.factory.createObjectLiteralExpression(propertyAssignments)\n )\n changeTracker.insertText(sourceFile, valueNode.getEnd(), \")\")\n })\n })\n }\n }\n\n report(\n {\n location: node,\n messageText: `Missing '${\n sortTypes(result.missingErrorTypes).map((_) => typeChecker.typeToString(_)).join(\" | \")\n }' in the expected Effect errors.`,\n fixes\n }\n )\n }),\n Nano.ignore\n )\n }\n }\n })\n})\n","import { 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 TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const missingEffectServiceDependency = LSP.createDiagnostic({\n name: \"missingEffectServiceDependency\",\n code: 21,\n severity: \"off\",\n apply: Nano.fn(\"missingEffectServiceDependency.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\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\n // Check if this is a class declaration that extends Effect.Service\n if (ts.isClassDeclaration(node) && node.name && node.heritageClauses) {\n const serviceResult = yield* pipe(\n typeParser.extendsEffectService(node),\n Nano.orElse(() => Nano.void_)\n )\n\n if (serviceResult) {\n const { className, options } = serviceResult\n\n // Get the class symbol and its type\n const classSymbol = typeChecker.getSymbolAtLocation(className)\n if (classSymbol) {\n const classType = typeChecker.getTypeOfSymbol(classSymbol)\n\n // Try to get DefaultWithoutDependencies first, then Default\n const defaultWithoutDepsProperty = typeChecker.getPropertyOfType(classType, \"DefaultWithoutDependencies\")\n const defaultProperty = defaultWithoutDepsProperty || typeChecker.getPropertyOfType(classType, \"Default\")\n\n if (defaultProperty) {\n const defaultType = typeChecker.getTypeOfSymbolAtLocation(defaultProperty, node)\n\n // Parse the layer type to get RIN\n const layerResult = yield* pipe(\n typeParser.layerType(defaultType, node),\n Nano.orElse(() => Nano.void_)\n )\n\n if (layerResult) {\n // Use a single memory map for both required and provided services\n const servicesMemory = new Map<string, ts.Type>()\n const excludeNever = (type: ts.Type) => Nano.succeed((type.flags & ts.TypeFlags.Never) !== 0)\n\n // Get all required service indexes\n const { allIndexes: requiredIndexes } = yield* TypeCheckerApi.appendToUniqueTypesMap(\n servicesMemory,\n layerResult.RIn,\n excludeNever\n )\n\n // Process dependencies (treat undefined/null as empty array)\n const providedIndexes = new Set<string>()\n\n const optionsType = typeChecker.getTypeAtLocation(options)\n const dependenciesProperty = typeChecker.getPropertyOfType(optionsType, \"dependencies\")\n let types: Array<ts.Type> = []\n\n if (dependenciesProperty) {\n const dependenciesTypes = typeChecker.getTypeOfSymbolAtLocation(dependenciesProperty, options)\n const numberIndexType = dependenciesTypes.getNumberIndexType()\n types = numberIndexType ? TypeCheckerApi.unrollUnionMembers(numberIndexType) : []\n }\n\n // Process each dependency to get what services they provide\n for (const depType of types) {\n // Try to parse as layer type\n const depLayerResult = yield* pipe(\n typeParser.layerType(depType, options),\n Nano.orElse(() => Nano.void_)\n )\n\n if (depLayerResult) {\n // Add the ROut of this dependency to the same memory map\n const { allIndexes } = yield* TypeCheckerApi.appendToUniqueTypesMap(\n servicesMemory,\n depLayerResult.ROut,\n excludeNever\n )\n // Collect all provided indexes\n for (const index of allIndexes) {\n providedIndexes.add(index)\n }\n }\n }\n\n // Find missing services: required indexes not in provided indexes\n const missingIndexes = requiredIndexes.filter((index) => !providedIndexes.has(index))\n\n // Report diagnostic if there are missing dependencies\n if (missingIndexes.length > 0) {\n const missingTypes = missingIndexes.map((index) => servicesMemory.get(index)!)\n const missingTypeNames = missingTypes.map((t) => typeChecker.typeToString(t))\n\n const message = missingTypeNames.length === 1\n ? `Service '${missingTypeNames[0]}' is required but not provided by dependencies`\n : `Services ${\n missingTypeNames.map((s) => `'${s}'`).join(\", \")\n } are required but not provided by dependencies`\n\n report({\n location: className,\n messageText: message,\n fixes: []\n })\n }\n }\n }\n }\n }\n }\n\n ts.forEachChild(node, appendNodeToVisit)\n }\n })\n})\n","import { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeCheckerApi from \"../core/TypeCheckerApi.js\"\nimport * as TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const missingReturnYieldStar = LSP.createDiagnostic({\n name: \"missingReturnYieldStar\",\n code: 7,\n severity: \"error\",\n apply: Nano.fn(\"missingReturnYieldStar.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\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 // if we yield* an effect with never in success type, maybe we wanted tu return\n if (\n ts.isYieldExpression(node) && node.expression &&\n node.asteriskToken\n ) {\n // are we returning an effect with never as success type?\n const type = typeChecker.getTypeAtLocation(node.expression)\n const maybeEffect = yield* Nano.option(typeParser.effectType(type, node.expression))\n\n if (Option.isSome(maybeEffect) && maybeEffect.value.A.flags & ts.TypeFlags.Never) {\n // go up until we meet the causing generator\n const generatorFunctionOrReturnStatement = ts.findAncestor(\n node,\n (\n _\n ) => (ts.isFunctionExpression(_) || ts.isFunctionDeclaration(_) || ts.isMethodDeclaration(_) ||\n ts.isReturnStatement(_) || ts.isThrowStatement(_))\n )\n\n // we already have a return statement\n if (\n generatorFunctionOrReturnStatement && !ts.isReturnStatement(generatorFunctionOrReturnStatement) &&\n !ts.isThrowStatement(generatorFunctionOrReturnStatement)\n ) {\n // .gen should always be the parent ideally\n if (generatorFunctionOrReturnStatement && generatorFunctionOrReturnStatement.parent) {\n const effectGenNode = generatorFunctionOrReturnStatement.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 // emit diagnostic\n const fix = node.expression ?\n [{\n fixName: \"missingReturnYieldStar_fix\",\n description: \"Add return statement\",\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n changeTracker.replaceNode(\n sourceFile,\n node,\n ts.factory.createReturnStatement(\n node\n )\n )\n })\n }] :\n []\n\n report({\n location: node,\n messageText:\n `It is recommended to use return yield* for Effects that never succeed to signal a definitive exit point for type narrowing and tooling support.`,\n fixes: fix\n })\n }\n }\n }\n }\n }\n }\n })\n})\n","import { 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 TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const missingStarInYieldEffectGen = LSP.createDiagnostic({\n name: \"missingStarInYieldEffectGen\",\n code: 4,\n severity: \"error\",\n apply: Nano.fn(\"missingStarInYieldEffectGen.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\n\n const brokenGenerators = new Set<ts.Node>()\n const brokenYields = new Set<ts.YieldExpression>()\n\n const nodeToVisit: Array<ts.Node> = []\n const appendNodeToVisit = (node: ts.Node) => {\n nodeToVisit.push(node)\n return undefined\n }\n ts.forEachChild(sourceFile, appendNodeToVisit)\n\n while (nodeToVisit.length > 0) {\n const node = nodeToVisit.shift()!\n ts.forEachChild(node, appendNodeToVisit)\n\n // error if yield is not followed by *\n if (\n ts.isYieldExpression(node) && node.expression &&\n node.asteriskToken === undefined\n ) {\n // go up until we meet the causing generator\n const functionStarNode = ts.findAncestor(\n node,\n (_) => (ts.isFunctionExpression(_) || ts.isFunctionDeclaration(_) || ts.isMethodDeclaration(_))\n )\n\n // .gen should always be the parent ideally\n if (functionStarNode && functionStarNode.parent) {\n const effectGenNode = functionStarNode.parent\n // continue if we hit effect gen-like\n yield* pipe(\n typeParser.effectGen(effectGenNode),\n Nano.orElse(() => typeParser.effectFnUntracedGen(effectGenNode)),\n Nano.orElse(() => typeParser.effectFnGen(effectGenNode)),\n Nano.map(({ functionStar }) => {\n if (functionStar) {\n brokenGenerators.add(functionStar)\n }\n brokenYields.add(node)\n }),\n Nano.ignore\n )\n }\n }\n }\n\n // emit diagnostics\n brokenGenerators.forEach((node) =>\n report({\n location: node,\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 report({\n location: node,\n messageText: `When yielding Effects inside Effect.gen, you should use yield* instead of yield.`,\n fixes: fix\n })\n })\n })\n})\n","import { 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 TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as TypeScriptUtils from \"../core/TypeScriptUtils.js\"\n\nexport const multipleEffectProvide = LSP.createDiagnostic({\n name: \"multipleEffectProvide\",\n code: 18,\n severity: \"warning\",\n apply: Nano.fn(\"multipleEffectProvide.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const tsUtils = yield* Nano.service(TypeScriptUtils.TypeScriptUtils)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\n\n const effectModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(\n sourceFile,\n \"effect\",\n \"Effect\"\n ) || \"Effect\"\n\n const layerModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(\n sourceFile,\n \"effect\",\n \"Layer\"\n ) || \"Layer\"\n\n const parseEffectProvideLayer = (node: ts.Node) => {\n if (\n ts.isCallExpression(node) &&\n ts.isPropertyAccessExpression(node.expression) &&\n ts.isIdentifier(node.expression.name) &&\n node.expression.name.text === \"provide\" &&\n node.arguments.length > 0\n ) {\n const layer = node.arguments[0]\n const type = typeChecker.getTypeAtLocation(layer)\n return pipe(\n typeParser.importedEffectModule(node.expression.expression),\n Nano.flatMap(() => typeParser.layerType(type, layer)),\n Nano.map(() => ({ layer, node })),\n Nano.orElse(() => Nano.void_)\n )\n }\n return Nano.void_\n }\n\n const parsePipeCall = (node: ts.Node) =>\n Nano.gen(function*() {\n const { args } = yield* typeParser.pipeCall(node)\n let currentChunk = 0\n const previousLayers: Array<Array<{ layer: ts.Expression; node: ts.CallExpression }>> = [[]]\n for (const pipeArg of args) {\n const parsedProvide = yield* (parseEffectProvideLayer(pipeArg))\n if (parsedProvide) {\n previousLayers[currentChunk].push(parsedProvide)\n } else {\n currentChunk++\n previousLayers.push([])\n }\n }\n // report for each chunk\n for (const chunk of previousLayers) {\n if (chunk.length < 2) continue\n report({\n location: chunk[0].node,\n messageText:\n \"Avoid chaining Effect.provide calls, as this can lead to service lifecycle issues. Instead, merge layers and provide them in a single call.\",\n fixes: [{\n fixName: \"multipleEffectProvide_fix\",\n description: \"Combine into a single provide\",\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n changeTracker.deleteRange(sourceFile, {\n pos: chunk[0].node.getStart(sourceFile),\n end: chunk[chunk.length - 1].node.getEnd()\n })\n const newNode = ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectModuleIdentifier),\n ts.factory.createIdentifier(\"provide\")\n ),\n undefined,\n [ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(layerModuleIdentifier),\n ts.factory.createIdentifier(\"mergeAll\")\n ),\n undefined,\n chunk.map((c) => c.layer)\n )]\n )\n changeTracker.insertNodeAt(sourceFile, chunk[0].node.getStart(sourceFile), newNode)\n })\n }]\n })\n }\n })\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 if (ts.isCallExpression(node)) {\n yield* pipe(parsePipeCall(node), Nano.ignore)\n }\n }\n })\n})\n","import { pipe } from \"effect/Function\"\nimport type * as 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 TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as TypeScriptUtils from \"../core/TypeScriptUtils.js\"\n\nexport const generate = Nano.fn(\"writeTagClassAccessors.generate\")(function*(\n sourceFile: ts.SourceFile,\n service: ts.Type,\n className: ts.Identifier,\n atLocation: ts.ClassDeclaration,\n involvedMembers: Array<{ property: ts.Symbol; propertyType: ts.Type }>\n) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const tsUtils = yield* Nano.service(TypeScriptUtils.TypeScriptUtils)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n const insertLocation = atLocation.members.length > 0 ? atLocation.members[0].pos : atLocation.getEnd() - 1\n\n const effectIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(\n sourceFile,\n \"effect\",\n \"Effect\"\n ) || \"Effect\"\n\n const createFunctionProperty = (\n className: ts.Identifier,\n propertyName: string,\n type: ts.TypeNode,\n forceAny: boolean\n ) => {\n const arrowBody = ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectIdentifier),\n \"andThen\"\n ),\n undefined,\n [\n ts.factory.createIdentifier(className.text),\n ts.factory.createArrowFunction(\n undefined,\n undefined,\n [ts.factory.createParameterDeclaration(\n undefined,\n undefined,\n \"_\",\n undefined,\n forceAny ? ts.factory.createTypeReferenceNode(\"any\") : undefined\n )],\n undefined,\n undefined,\n ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(\"_\"),\n propertyName\n ),\n undefined,\n [\n ts.factory.createSpreadElement(ts.factory.createIdentifier(\"args\"))\n ]\n )\n )\n ]\n )\n return ts.factory.createPropertyDeclaration(\n [ts.factory.createModifier(ts.SyntaxKind.StaticKeyword)],\n propertyName,\n undefined,\n type,\n ts.factory.createArrowFunction(\n undefined,\n undefined,\n [ts.factory.createParameterDeclaration(\n undefined,\n ts.factory.createToken(ts.SyntaxKind.DotDotDotToken),\n \"args\",\n undefined,\n forceAny ? ts.factory.createArrayTypeNode(ts.factory.createTypeReferenceNode(\"any\")) : undefined\n )],\n undefined,\n undefined,\n forceAny ? ts.factory.createAsExpression(arrowBody, ts.factory.createTypeReferenceNode(\"any\")) : arrowBody\n )\n )\n }\n\n const generateReturnType = (type: ts.Type, atLocation: ts.ClassDeclaration, className: ts.Identifier) =>\n pipe(\n typeParser.effectType(type, atLocation),\n Nano.flatMap((returnedEffect) => {\n // the type is an effect, so we just need to add the service type to the context type\n const contextType = (returnedEffect.R.flags & ts.TypeFlags.Never) ?\n ts.factory.createTypeReferenceNode(className.text) :\n ts.factory.createUnionTypeNode(\n [\n ts.factory.createTypeReferenceNode(className.text),\n typeChecker.typeToTypeNode(returnedEffect.R, atLocation, ts.NodeBuilderFlags.NoTruncation)!\n ]\n )\n\n const successType = typeChecker.typeToTypeNode(\n returnedEffect.A,\n atLocation,\n ts.NodeBuilderFlags.NoTruncation\n )\n if (!successType) return Nano.fail(\"error generating success type\")\n\n const failureType = typeChecker.typeToTypeNode(\n returnedEffect.E,\n atLocation,\n ts.NodeBuilderFlags.NoTruncation\n )\n if (!failureType) return Nano.fail(\"error generating failure type\")\n\n const typeNode = ts.factory.createTypeReferenceNode(\n ts.factory.createQualifiedName(\n ts.factory.createIdentifier(effectIdentifier),\n ts.factory.createIdentifier(\"Effect\")\n ),\n [successType, failureType, contextType]\n )\n return Nano.succeed(typeNode)\n }),\n Nano.orElse(() =>\n pipe(\n typeParser.promiseLike(type, atLocation),\n Nano.flatMap(({ type }) => {\n const successType = typeChecker.typeToTypeNode(\n type,\n atLocation,\n ts.NodeBuilderFlags.NoTruncation\n )\n if (!successType) return Nano.fail(\"error generating success type\")\n return Nano.succeed(ts.factory.createTypeReferenceNode(\n ts.factory.createQualifiedName(\n ts.factory.createIdentifier(effectIdentifier),\n ts.factory.createIdentifier(\"Effect\")\n ),\n [\n successType,\n ts.factory.createTypeReferenceNode(\n ts.factory.createQualifiedName(\n ts.factory.createIdentifier(\"Cause\"),\n ts.factory.createIdentifier(\"UnknownException\")\n )\n ),\n ts.factory.createTypeReferenceNode(className.text)\n ]\n ))\n })\n )\n ),\n Nano.orElse(() => {\n // fallback to just converting A into a Effect<A, never, Service>\n const successType = typeChecker.typeToTypeNode(type, atLocation, ts.NodeBuilderFlags.NoTruncation)\n if (!successType) return Nano.fail(\"error generating success type\")\n const typeNode = ts.factory.createTypeReferenceNode(\n ts.factory.createQualifiedName(\n ts.factory.createIdentifier(effectIdentifier),\n ts.factory.createIdentifier(\"Effect\")\n ),\n [\n successType,\n ts.factory.createTypeReferenceNode(\"never\"),\n ts.factory.createTypeReferenceNode(className.text)\n ]\n )\n\n return Nano.succeed(typeNode)\n })\n )\n\n const proxySignature = (signature: ts.Signature, atLocation: ts.ClassDeclaration, className: ts.Identifier) =>\n Nano.gen(function*() {\n // generate the signature\n const signatureDeclaration = typeChecker.signatureToSignatureDeclaration(\n signature,\n ts.SyntaxKind.FunctionType,\n atLocation,\n ts.NodeBuilderFlags.NoTruncation\n )\n\n if (!signatureDeclaration) return yield* Nano.fail(\"error generating signature\")\n\n // wrap the return type as it would be in a Effect.andThen\n const returnType = yield* generateReturnType(signature.getReturnType(), atLocation, className)\n\n // construct the new signature\n return ts.factory.createFunctionTypeNode(\n signatureDeclaration.typeParameters,\n signatureDeclaration.parameters,\n returnType\n )\n })\n\n for (const { property, propertyType } of involvedMembers) {\n const callSignatures: Array<ts.FunctionTypeNode> = []\n let propertyDeclaration: ts.PropertyDeclaration | undefined = undefined\n for (const signature of propertyType.getCallSignatures()) {\n yield* pipe(\n proxySignature(signature, atLocation, className),\n Nano.map((sig) => {\n callSignatures.push(sig)\n }),\n Nano.ignore\n )\n }\n // this is a call signature:\n // static method: <A>(value: A) => Effect<A, never, Service> = (value) => Effect.andThen(Service, _ => _.method(value))\n const allSignatures = ts.factory.createIntersectionTypeNode(callSignatures)\n const type = tsUtils.simplifyTypeNode(allSignatures)\n propertyDeclaration = createFunctionProperty(className, property.getName(), type, callSignatures.length > 1)\n\n // then we need to delete the old property (if present)\n const oldProperty = atLocation.members.filter(ts.isPropertyDeclaration).find((p) => {\n const symbol = typeChecker.getSymbolAtLocation(p.name)\n return symbol?.getName() === property.getName()\n })\n if (oldProperty) {\n changeTracker.deleteRange(sourceFile, {\n pos: oldProperty.getStart(sourceFile),\n end: oldProperty.getEnd()\n })\n changeTracker.insertNodeAt(sourceFile, oldProperty.getStart(sourceFile), propertyDeclaration)\n } else {\n changeTracker.insertNodeAt(sourceFile, insertLocation, propertyDeclaration, { suffix: \"\\n\" })\n }\n }\n})\n\nexport const parse = Nano.fn(\"writeTagClassAccessors.parse\")(function*(node: ts.Node) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\n\n // only applicable to class declarations\n if (!ts.isClassDeclaration(node)) return yield* Nano.fail(\"not a class declaration\")\n\n const { Service, accessors, className } = yield* pipe(\n typeParser.extendsEffectService(node),\n Nano.orElse(() => Nano.fail(\"not a class extending Effect.Service call\"))\n )\n\n if (accessors !== true) return yield* Nano.fail(\"accessors are not enabled in the Effect.Service call\")\n\n const involvedMembers: Array<{ property: ts.Symbol; propertyType: ts.Type }> = []\n for (const property of typeChecker.getPropertiesOfType(Service)) {\n const propertyType = typeChecker.getTypeOfSymbolAtLocation(property, node)\n const callSignatures = propertyType.getCallSignatures()\n if (callSignatures.length > 0) {\n const withTypeParameters = callSignatures.filter((_) => _.typeParameters && _.typeParameters.length > 0)\n if (callSignatures.length > 1 || withTypeParameters.length > 0) involvedMembers.push({ property, propertyType })\n }\n }\n\n const hash = involvedMembers.map(({ property, propertyType }) => {\n return property.getName() + \": \" + typeChecker.typeToString(propertyType)\n }).concat([className.text]).join(\"\\n\")\n\n return { Service, className, atLocation: node, hash: LSP.cyrb53(hash), involvedMembers }\n})\n\nexport const writeTagClassAccessors = LSP.createRefactor({\n name: \"writeTagClassAccessors\",\n description: \"Implement accessors methods with generics or multiple signatures\",\n apply: Nano.fn(\"writeTagClassAccessors.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const tsUtils = yield* Nano.service(TypeScriptUtils.TypeScriptUtils)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\n\n const parseNode = (node: ts.Node) =>\n pipe(\n parse(node),\n Nano.map(({ Service, atLocation, className, involvedMembers }) => ({\n kind: \"refactor.rewrite.effect.writeTagClassAccessors\",\n description: \"Implement Service accessors\",\n apply: pipe(\n generate(sourceFile, Service, className, atLocation, involvedMembers),\n Nano.provideService(TypeScriptUtils.TypeScriptUtils, tsUtils),\n Nano.provideService(TypeParser.TypeParser, typeParser),\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, typeChecker),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts)\n )\n }))\n )\n\n const parentNodes = tsUtils.getAncestorNodesInRange(sourceFile, textRange)\n\n return yield* pipe(\n Nano.firstSuccessOf(parentNodes.map(parseNode)),\n Nano.orElse(() => Nano.fail(new LSP.RefactorNotApplicableError()))\n )\n })\n})\n","import { pipe } from \"effect/Function\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeCheckerApi from \"../core/TypeCheckerApi.js\"\nimport * as TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as TypeScriptUtils from \"../core/TypeScriptUtils.js\"\nimport * as refactor from \"../refactors/writeTagClassAccessors.js\"\n\nexport const accessors = LSP.createCodegen({\n name: \"accessors\",\n apply: Nano.fn(\"accessors.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const tsUtils = yield* Nano.service(TypeScriptUtils.TypeScriptUtils)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\n\n const nodeAndCommentRange = tsUtils.findNodeWithLeadingCommentAtPosition(sourceFile, textRange.pos)\n if (!nodeAndCommentRange) return yield* Nano.fail(new LSP.CodegenNotApplicableError(\"no node and comment range\"))\n\n return yield* pipe(\n refactor.parse(nodeAndCommentRange.node),\n Nano.map((_) =>\n ({\n hash: _.hash,\n description: \"Generate accessors for the service\",\n apply: pipe(\n refactor.generate(sourceFile, _.Service, _.className, _.atLocation, _.involvedMembers),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts),\n Nano.provideService(TypeScriptUtils.TypeScriptUtils, tsUtils),\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, typeChecker),\n Nano.provideService(TypeParser.TypeParser, typeParser)\n )\n }) satisfies LSP.ApplicableCodegenDefinition\n ),\n Nano.orElse((cause) => Nano.fail(new LSP.CodegenNotApplicableError(cause)))\n )\n })\n})\n","import { accessors } from \"./codegens/accessors.js\"\n\nexport const codegens = [accessors]\n","import { pipe } from \"effect/Function\"\nimport { codegens } from \"../codegens.js\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\n\nexport const outdatedEffectCodegen = LSP.createDiagnostic({\n name: \"outdatedEffectCodegen\",\n code: 19,\n severity: \"warning\",\n apply: Nano.fn(\"outdatedEffectCodegen.apply\")(function*(sourceFile, _report) {\n const codegensWithRanges = yield* LSP.getCodegensForSourceFile(codegens, sourceFile)\n for (const { codegen, hash, range } of codegensWithRanges) {\n yield* pipe(\n LSP.getEditsForCodegen([codegen], sourceFile, range),\n Nano.map((applicable) => {\n if (applicable.hash !== hash) {\n _report({\n location: range,\n messageText: `Codegen ${codegen.name} result is outdated`,\n fixes: [\n {\n fixName: \"outdatedEffectCodegen_fix\",\n description: `Re-run ${codegen.name}`,\n apply: applicable.apply\n },\n {\n fixName: \"outdatedEffectCodegen_ignore\",\n description: `Ignore this ${codegen.name} update`,\n apply: applicable.ignore\n }\n ]\n })\n }\n }),\n Nano.orElse((e) =>\n Nano.sync(() => {\n _report({\n location: range,\n messageText: `Codegen ${codegen.name} is not applicable here: ${e.cause}`,\n fixes: []\n })\n })\n ),\n Nano.ignore\n )\n }\n })\n})\n","import { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeCheckerApi from \"../core/TypeCheckerApi.js\"\nimport * as TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const returnEffectInGen = LSP.createDiagnostic({\n name: \"returnEffectInGen\",\n code: 11,\n severity: \"suggestion\",\n apply: Nano.fn(\"returnEffectInGen.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\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 // start from the return statement\n if (\n ts.isReturnStatement(node) && node.expression\n ) {\n // fast exit\n if (ts.isYieldExpression(node.expression)) continue\n\n // go up until we meet the causing generator/function\n const generatorOrRegularFunction = ts.findAncestor(\n node,\n (\n _\n ) => (ts.isFunctionExpression(_) || ts.isFunctionDeclaration(_) || ts.isMethodDeclaration(_) ||\n ts.isArrowFunction(_) || ts.isGetAccessor(_))\n )\n\n if (\n !(generatorOrRegularFunction && \"asteriskToken\" in generatorOrRegularFunction &&\n generatorOrRegularFunction.asteriskToken)\n ) continue // fast exit\n\n // are we returning an effect with never as success type?\n const type = typeChecker.getTypeAtLocation(node.expression)\n const maybeEffect = yield* Nano.option(typeParser.strictEffectType(type, node.expression))\n\n if (Option.isSome(maybeEffect)) {\n // .gen should always be the parent ideally\n if (generatorOrRegularFunction && generatorOrRegularFunction.parent) {\n const effectGenNode = generatorOrRegularFunction.parent\n // continue if we hit effect gen-like\n yield* pipe(\n typeParser.effectGen(effectGenNode),\n Nano.orElse(() => typeParser.effectFnUntracedGen(effectGenNode)),\n Nano.orElse(() => typeParser.effectFnGen(effectGenNode)),\n Nano.map(() => {\n const fix = node.expression ?\n [{\n fixName: \"returnEffectInGen_fix\",\n description: \"Add yield* statement\",\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n changeTracker.replaceNode(\n sourceFile,\n node.expression!,\n ts.factory.createYieldExpression(\n ts.factory.createToken(ts.SyntaxKind.AsteriskToken),\n node.expression!\n )\n )\n })\n }] :\n []\n\n report({\n location: node,\n messageText:\n `You are returning an Effect-able type inside a generator function, and will result in nested Effect<Effect<...>>.\\nMaybe you wanted to return yield* instead?\\nNested Effect-able types may be intended if you plan to later manually flatten or unwrap this Effect, if so you can safely disable this diagnostic for this line through quickfixes.`,\n fixes: fix\n })\n }),\n Nano.ignore\n )\n }\n }\n }\n }\n })\n})\n","import { 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 TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as TypeScriptUtils from \"../core/TypeScriptUtils.js\"\n\nexport const scopeInLayerEffect = LSP.createDiagnostic({\n name: \"scopeInLayerEffect\",\n code: 13,\n severity: \"warning\",\n apply: Nano.fn(\"scopeInLayerEffect.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const tsUtils = yield* Nano.service(TypeScriptUtils.TypeScriptUtils)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\n\n const layerModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(\n sourceFile,\n \"effect\",\n \"Layer\"\n ) || \"Layer\"\n\n function parseLayerEffectApiCall(node: ts.Node): { methodIdentifier: ts.Identifier } | undefined {\n // should be a call expression of a property access like Layer.effect\n // we first check thats a call, then ensure that the callee is a property access\n // and that the property is \"effect\"\n if (!ts.isCallExpression(node)) return\n const expression = node.expression\n if (!ts.isPropertyAccessExpression(expression)) return\n // we check that the api is called on the Layer module\n const calledModule = expression.expression\n if (!(ts.isIdentifier(calledModule) && calledModule.text === layerModuleIdentifier)) return\n const methodIdentifier = expression.name\n // *.effect, *.effectContext, whatever...\n if (!(ts.isIdentifier(methodIdentifier) && methodIdentifier.text.toLowerCase().startsWith(\"effect\"))) return\n return { methodIdentifier }\n }\n\n const reportIfLayerRequireScope = (type: ts.Type, node: ts.Node, methodIdentifier: ts.Identifier | undefined) => {\n let toCheck = [type]\n const entries: Array<ts.Type> = []\n while (toCheck.length > 0) {\n const type = toCheck.pop()!\n if (type.isUnion()) {\n toCheck = toCheck.concat(type.types)\n } else {\n entries.push(type)\n }\n }\n return pipe(\n Nano.firstSuccessOf(entries.map((type) => typeParser.scopeType(type, node))),\n Nano.map(() =>\n report({\n location: node,\n messageText:\n `Seems like you are constructing a layer with a scope in the requirements.\\nConsider using \"scoped\" instead to get rid of the scope in the requirements.`,\n fixes: methodIdentifier ?\n [{\n fixName: \"scopeInLayerEffect_scoped\",\n description: \"Use scoped for Layer creation\",\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n changeTracker.replaceNode(\n sourceFile,\n methodIdentifier,\n ts.factory.createIdentifier(\"scoped\")\n )\n })\n }] :\n []\n })\n ),\n Nano.ignore\n )\n }\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\n const layerEffectApiCall = parseLayerEffectApiCall(node)\n if (layerEffectApiCall) {\n const type = typeChecker.getTypeAtLocation(node)\n yield* pipe(\n typeParser.layerType(type, node),\n Nano.flatMap(({ RIn }) => reportIfLayerRequireScope(RIn, node, layerEffectApiCall.methodIdentifier)),\n Nano.ignore\n )\n continue\n }\n\n if (ts.isClassDeclaration(node) && node.name && node.heritageClauses) {\n const classSym = typeChecker.getSymbolAtLocation(node.name)\n if (classSym) {\n const classType = typeChecker.getTypeOfSymbol(classSym)\n const defaultLayer = typeChecker.getPropertyOfType(classType, \"Default\")\n if (defaultLayer) {\n const type = typeChecker.getTypeOfSymbolAtLocation(defaultLayer, node)\n yield* pipe(\n typeParser.layerType(type, node),\n Nano.flatMap(({ RIn }) => reportIfLayerRequireScope(RIn, node, undefined)),\n Nano.ignore\n )\n continue\n }\n }\n }\n\n ts.forEachChild(node, appendNodeToVisit)\n }\n })\n})\n","import 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\"\n\nexport const strictBooleanExpressions = LSP.createDiagnostic({\n name: \"strictBooleanExpressions\",\n code: 17,\n severity: \"off\",\n apply: Nano.fn(\"strictBooleanExpressions.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const conditionChecks = new WeakMap<ts.Node, boolean>()\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 nodes: Array<ts.Node> = []\n if (ts.isIfStatement(node)) {\n conditionChecks.set(node, true)\n nodes.push(node.expression)\n } else if (ts.isWhileStatement(node)) {\n conditionChecks.set(node, true)\n nodes.push(node.expression)\n } else if (ts.isConditionalExpression(node)) {\n conditionChecks.set(node, true)\n nodes.push(node.condition)\n } else if (ts.isPrefixUnaryExpression(node) && node.operator === ts.SyntaxKind.ExclamationToken) {\n conditionChecks.set(node, true)\n nodes.push(node.operand)\n } else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.BarBarToken) {\n if (conditionChecks.has(node.parent)) conditionChecks.set(node, true)\n nodes.push(node.left)\n nodes.push(node.right)\n } else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken) {\n if (conditionChecks.has(node.parent)) conditionChecks.set(node, true)\n nodes.push(node.left)\n nodes.push(node.right)\n }\n\n for (const nodeToCheck of nodes) {\n if (!nodeToCheck) continue\n if (!conditionChecks.has(nodeToCheck.parent)) continue\n\n const nodeType = typeChecker.getTypeAtLocation(nodeToCheck)\n const constrainedType = typeChecker.getBaseConstraintOfType(nodeType)\n let typesToCheck = [constrainedType || nodeType]\n\n while (typesToCheck.length > 0) {\n const type = typesToCheck.pop()!\n\n // unroll union types\n if (type.isUnion()) {\n typesToCheck = typesToCheck.concat(type.types)\n continue\n }\n\n // skip boolean and never types\n if (type.flags & ts.TypeFlags.Boolean) continue\n if (type.flags & ts.TypeFlags.Never) continue\n if (type.flags & ts.TypeFlags.BooleanLiteral) continue\n\n // report the error\n const typeName = typeChecker.typeToString(type)\n report({\n location: nodeToCheck,\n messageText: `Unexpected \\`${typeName}\\` type in condition, expected strictly a boolean instead.`,\n fixes: []\n })\n }\n }\n }\n })\n})\n","import { 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 TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const tryCatchInEffectGen = LSP.createDiagnostic({\n name: \"tryCatchInEffectGen\",\n code: 15,\n severity: \"suggestion\",\n apply: Nano.fn(\"tryCatchInEffectGen.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\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 // Check if this is a try statement\n if (ts.isTryStatement(node)) {\n // Find the containing generator function\n // go up until we meet the causing generator/function\n const generatorOrRegularFunction = ts.findAncestor(\n node,\n (\n _\n ) => (ts.isFunctionExpression(_) || ts.isFunctionDeclaration(_) || ts.isMethodDeclaration(_) ||\n ts.isArrowFunction(_) || ts.isGetAccessor(_) || ts.isFunctionLike(_))\n )\n\n if (\n !(generatorOrRegularFunction && \"asteriskToken\" in generatorOrRegularFunction &&\n generatorOrRegularFunction.asteriskToken)\n ) continue // fast exit\n\n if (!generatorOrRegularFunction) continue\n\n // Check if we're inside Effect.gen or Effect.fn\n if (generatorOrRegularFunction && generatorOrRegularFunction.parent) {\n const effectGenNode = generatorOrRegularFunction.parent\n\n // Check if this generator is inside Effect.gen/Effect.fn\n yield* pipe(\n typeParser.effectGen(effectGenNode),\n Nano.orElse(() => typeParser.effectFnUntracedGen(effectGenNode)),\n Nano.orElse(() => typeParser.effectFnGen(effectGenNode)),\n Nano.map(() => {\n report({\n location: node,\n messageText:\n \"Avoid using try/catch inside Effect generators. Use Effect's error handling mechanisms instead (e.g., Effect.try, Effect.tryPromise, Effect.catchAll, Effect.catchTag).\",\n fixes: []\n })\n }),\n Nano.ignore\n )\n }\n }\n }\n })\n})\n","import { 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 TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const unnecessaryEffectGen = LSP.createDiagnostic({\n name: \"unnecessaryEffectGen\",\n code: 5,\n severity: \"suggestion\",\n apply: Nano.fn(\"unnecessaryEffectGen.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\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 if (ts.isCallExpression(node)) {\n yield* pipe(\n typeParser.unnecessaryEffectGen(node),\n Nano.map(({ replacementNode }) =>\n report({\n location: node,\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, node, yield* replacementNode)\n })\n }]\n })\n ),\n Nano.ignore\n )\n }\n }\n })\n})\n","import { 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 TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const unnecessaryPipe = LSP.createDiagnostic({\n name: \"unnecessaryPipe\",\n code: 9,\n severity: \"suggestion\",\n apply: Nano.fn(\"unnecessaryPipe.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\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 if (ts.isCallExpression(node)) {\n yield* pipe(\n typeParser.pipeCall(node),\n Nano.map(({ args, subject }) => {\n if (args.length === 0) {\n report({\n location: node,\n messageText: `This pipe call contains no arguments.`,\n fixes: [{\n fixName: \"unnecessaryPipe_fix\",\n description: \"Remove the pipe call\",\n apply: Nano.gen(function*() {\n const textChanges = yield* Nano.service(\n TypeScriptApi.ChangeTracker\n )\n textChanges.replaceNode(sourceFile, node, subject)\n })\n }]\n })\n }\n }),\n Nano.ignore\n )\n }\n }\n })\n})\n","import { 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 TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const unnecessaryPipeChain = LSP.createDiagnostic({\n name: \"unnecessaryPipeChain\",\n code: 16,\n severity: \"suggestion\",\n apply: Nano.fn(\"unnecessaryPipeChain.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\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 if (ts.isCallExpression(node)) {\n yield* pipe(\n typeParser.pipeCall(node),\n Nano.flatMap((pipeCall) =>\n Nano.map(typeParser.pipeCall(pipeCall.subject), (innerCall) => ({ pipeCall, innerCall }))\n ),\n Nano.map(({ innerCall, pipeCall }) => {\n report({\n location: node,\n messageText: `Chained pipe calls can be simplified to a single pipe call`,\n fixes: [{\n fixName: \"unnecessaryPipeChain_fix\",\n description: \"Rewrite as single pipe call\",\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(\n TypeScriptApi.ChangeTracker\n )\n switch (innerCall.kind) {\n case \"pipe\": {\n changeTracker.replaceNode(\n sourceFile,\n node,\n ts.factory.createCallExpression(\n ts.factory.createIdentifier(\"pipe\"),\n undefined,\n [innerCall.subject, ...innerCall.args, ...pipeCall.args]\n )\n )\n break\n }\n case \"pipeable\": {\n changeTracker.replaceNode(\n sourceFile,\n node,\n ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n innerCall.subject,\n \"pipe\"\n ),\n undefined,\n [...innerCall.args, ...pipeCall.args]\n )\n )\n break\n }\n }\n })\n }]\n })\n }),\n Nano.ignore\n )\n }\n }\n })\n})\n","import { pipe } from \"effect\"\nimport type * as 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 writeTagClassAccessors from \"../refactors/writeTagClassAccessors.js\"\n\nexport const unsupportedServiceAccessors = LSP.createDiagnostic({\n name: \"unsupportedServiceAccessors\",\n code: 21,\n severity: \"warning\",\n apply: Nano.fn(\"unsupportedServiceAccessors.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\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 // Check if this is a class declaration that might use unsupported service accessors\n if (ts.isClassDeclaration(node)) {\n const parseResult = yield* pipe(\n writeTagClassAccessors.parse(node),\n Nano.orElse(() => Nano.succeed(null))\n )\n\n if (parseResult && parseResult.involvedMembers.length > 0) {\n // Get existing static members in the class\n const existingStaticMembers = new Set<string>()\n node.members?.forEach((member) => {\n if (\n ts.isPropertyDeclaration(member) &&\n member.modifiers?.some((mod) => mod.kind === ts.SyntaxKind.StaticKeyword)\n ) {\n if (member.name && ts.isIdentifier(member.name)) {\n existingStaticMembers.add(member.name.text)\n }\n }\n })\n\n // Filter out members that already have static implementations\n const missingMembers = parseResult.involvedMembers.filter(({ property }) =>\n !existingStaticMembers.has(property.getName())\n )\n\n if (missingMembers.length > 0) {\n const memberNames = missingMembers.map(({ property }) => `'${property.getName()}'`).join(\", \")\n\n report({\n location: parseResult.className,\n messageText:\n `Even if accessors are enabled, accessors for ${memberNames} won't be available because the signature have generic type parameters or multiple call signatures.`,\n fixes: [{\n fixName: \"unsupportedServiceAccessors_enableCodegen\",\n description: \"Enable accessors codegen\",\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n // Add @effect-codegens comment before the class\n const comment = \"// @effect-codegens accessors\\n\"\n changeTracker.insertText(sourceFile, node.getStart(sourceFile), comment)\n })\n }]\n })\n }\n }\n }\n }\n })\n})\n","import { classSelfMismatch } from \"./diagnostics/classSelfMismatch.js\"\nimport { duplicatePackage } from \"./diagnostics/duplicatePackage.js\"\nimport { effectInVoidSuccess } from \"./diagnostics/effectInVoidSuccess.js\"\nimport { floatingEffect } from \"./diagnostics/floatingEffect.js\"\nimport { genericEffectServices } from \"./diagnostics/genericEffectServices.js\"\nimport { importFromBarrel } from \"./diagnostics/importFromBarrel.js\"\nimport { leakingRequirements } from \"./diagnostics/leakingRequirements.js\"\nimport { missingEffectContext } from \"./diagnostics/missingEffectContext.js\"\nimport { missingEffectError } from \"./diagnostics/missingEffectError.js\"\nimport { missingEffectServiceDependency } from \"./diagnostics/missingEffectServiceDependency.js\"\nimport { missingReturnYieldStar } from \"./diagnostics/missingReturnYieldStar.js\"\nimport { missingStarInYieldEffectGen } from \"./diagnostics/missingStarInYieldEffectGen.js\"\nimport { multipleEffectProvide } from \"./diagnostics/multipleEffectProvide.js\"\nimport { outdatedEffectCodegen } from \"./diagnostics/outdatedEffectCodegen.js\"\nimport { returnEffectInGen } from \"./diagnostics/returnEffectInGen.js\"\nimport { scopeInLayerEffect } from \"./diagnostics/scopeInLayerEffect.js\"\nimport { strictBooleanExpressions } from \"./diagnostics/strictBooleanExpressions.js\"\nimport { tryCatchInEffectGen } from \"./diagnostics/tryCatchInEffectGen.js\"\nimport { unnecessaryEffectGen } from \"./diagnostics/unnecessaryEffectGen.js\"\nimport { unnecessaryPipe } from \"./diagnostics/unnecessaryPipe.js\"\nimport { unnecessaryPipeChain } from \"./diagnostics/unnecessaryPipeChain.js\"\nimport { unsupportedServiceAccessors } from \"./diagnostics/unsupportedServiceAccessors.js\"\n\nexport const diagnostics = [\n classSelfMismatch,\n duplicatePackage,\n missingEffectContext,\n missingEffectError,\n missingEffectServiceDependency,\n floatingEffect,\n missingStarInYieldEffectGen,\n unnecessaryEffectGen,\n missingReturnYieldStar,\n leakingRequirements,\n unnecessaryPipe,\n genericEffectServices,\n returnEffectInGen,\n tryCatchInEffectGen,\n importFromBarrel,\n scopeInLayerEffect,\n effectInVoidSuccess,\n unnecessaryPipeChain,\n strictBooleanExpressions,\n multipleEffectProvide,\n outdatedEffectCodegen,\n unsupportedServiceAccessors\n]\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC4BO,IAAMA,aAAcC,WAAsC,OAAOA,UAAU;AAkE3E,IAAMC,OAmIT,SAASC,OAAOC,MAAI;AACtB,MAAI,OAAOD,UAAU,YAAY;AAC/B,WAAO,WAAA;AACL,UAAIA,MAAME,SAAS,GAAG;AAEpB,eAAOD,KAAKE,MAAM,MAAMD,SAAS;MACnC;AACA,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AA,UAC0B;AAAA,UACA,MAAM,YAAY;AAAA,QACjD;AAAA,QACK;AAAA,QACE,IAAI,CAACC,OAAMA,GAAE,WAAW;AAAA,QACxB;AAAA,UACC;AAAA,YAAO,CAACA,OACZA,GAAE,aAAa,WAAW,mBAAmB,SAC7CA,GAAE,aAAa,WAAW,mBAAmB;AAAA,UAC/C;AAAA,QACF;AAAA,QACO,UAAU,MAAM,CAAC,CAAC;AAAA,QACnBC,KAAI,aAAa;AAAA,MACzB;AAGA,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":["isFunction","input","dual","arity","body","arguments","apply","self","RangeError","a","b","length","c","d","e","args","identity","a","pipe","a","ab","bc","cd","de","ef","fg","gh","hi","arguments","length","ret","i","globalStoreId","globalStore","globalValue","id","compute","globalThis","Map","has","set","get","isString","input","isNumber","isBoolean","isFunction","isFunction_","isRecordOrArray","input","isObject","isFunction","hasProperty","dual","self","property","isRecord","input","isRecordOrArray","Array","isArray","getBugErrorMessage","message","GenKindTypeId","Symbol","for","GenKindImpl","value","constructor","_F","identity","_R","_","_O","_E","GenKindTypeId","Symbol","iterator","SingleShotGen","self","called","next","a","done","return","throw","e","MUL_HI","MUL_LO","YieldWrapTypeId","Symbol","for","YieldWrap","constructor","value","yieldWrapGet","self","Error","getBugErrorMessage","structuralRegionState","globalValue","enabled","tester","undefined","standard","effect_internal_function","body","forced","isNotOptimizedAway","Error","stack","includes","internalCall","genConstructor","constructor","randomHashCache","globalValue","Symbol","for","WeakMap","symbol","hash","self","structuralRegionState","enabled","number","string","toString","String","Date","toISOString","URL","href","isHash","random","Error","has","set","Math","floor","Number","MAX_SAFE_INTEGER","get","combine","b","optimize","n","u","hasProperty","Infinity","h","str","i","length","charCodeAt","structureKeys","o","keys","pipe","structure","Object","cached","arguments","length","self","hash","Object","defineProperty","symbol","value","enumerable","symbol","Symbol","for","equals","arguments","length","self","compareBoth","that","selfType","isEqual","hash","structuralRegionState","enabled","tester","Date","toISOString","URL","href","Array","isArray","every","v","i","Object","getPrototypeOf","prototype","keysSelf","keys","keysThat","key","u","hasProperty","equivalence","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","moduleVersion","getCurrentVersion","EffectTypeId","Symbol","for","StreamTypeId","SinkTypeId","ChannelTypeId","effectVariance","_R","_","_E","_A","_V","version","getCurrentVersion","sinkVariance","_In","_L","channelVariance","_Env","_InErr","_InElem","_InDone","_OutErr","_OutElem","_OutDone","EffectPrototype","symbol","that","cached","random","iterator","SingleShotGen","YieldWrap","pipe","pipeArguments","arguments","StructuralPrototype","structure","selfKeys","Object","keys","thatKeys","length","key","equals","CommitPrototype","_op","OP_COMMIT","StructuralCommitPrototype","TypeId","Symbol","for","CommonProto","EffectPrototype","_A","_","NodeInspectSymbol","toJSON","toString","format","SomeProto","Object","assign","create","_tag","_op","symbol","that","isOption","isSome","equals","value","cached","combine","hash","_id","NoneHash","Hash","NoneProto","isNone","input","hasProperty","fa","none","some","a","TypeId","Symbol","for","CommonProto","EffectPrototype","_R","_","NodeInspectSymbol","toJSON","toString","format","RightProto","Object","assign","create","_tag","_op","symbol","that","isEither","isRight","equals","right","combine","hash","_id","LeftProto","isLeft","left","input","hasProperty","ma","a","right","left","isLeft","isRight","map","dual","self","f","isRight","right","left","getOrElse","dual","self","onLeft","isLeft","left","right","isNonEmptyArray","self","length","make","compare","self","that","string","none","some","isNone","isSome","orElse","dual","self","that","isNone","fromNullable","nullableValue","none","some","fromIterable","collection","Array","isArray","from","append","dual","self","last","appendAll","that","fromIterable","concat","isArray","Array","isEmptyArray","self","length","isEmptyReadonlyArray","isNonEmptyReadonlyArray","isNonEmptyArray","isOutOfBounds","i","as","length","unsafeGet","dual","self","index","i","Math","floor","isOutOfBounds","Error","headNonEmpty","unsafeGet","tailNonEmpty","self","slice","sort","dual","self","O","out","Array","from","containsWith","isEquivalent","dual","self","a","i","_equivalence","Equal","equivalence","intersectionWith","isEquivalent","has","containsWith","dual","self","that","fromIterable","filter","a","intersection","_equivalence","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","dedupe","equivalence","fn","symbol","right","left","flatMap","map","args","orElse","arr","cont","cached","some","none","map","flatMap","map","isFunction","none","some","isNone","isSome","typeNode","diagnostics","isSome","refactor","node","match","flatMap","codegens","codegen","map","symbol","isSome","type","nanoLayer","make","map","orElse","isSome","unnecessaryEffectGen","args","symbol","type","flatMap","accessors","orElse","map","isSome","orElse","isNone","map","orElse","sourceFile","service","map","orElse","flatMap","flatMap","map","flatMap","map","string","orElse","isSome","orElse","orElse","map","flatMap","map","orElse","args","service","className","atLocation","flatMap","orElse","type","map","symbol","parse","accessors","hash","parse","map","orElse","hash","map","orElse","isSome","orElse","map","type","map","flatMap","orElse","map","map","map","args","flatMap","map","parse","orElse","nanoLayer","_","map"]}
|
|
1
|
+
{"version":3,"sources":["../src/transform.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/Function.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/GlobalValue.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/Predicate.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/internal/errors.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/Utils.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/Hash.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/Equal.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/Inspectable.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/Pipeable.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/internal/opCodes/effect.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/internal/version.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/internal/effectable.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/internal/option.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/internal/either.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/Either.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/internal/array.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/Order.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/Option.ts","../node_modules/.pnpm/effect@3.17.1/node_modules/effect/src/Array.ts","../src/core/Nano.ts","../src/core/LanguageServicePluginOptions.ts","../src/core/TypeScriptApi.ts","../src/core/TypeScriptUtils.ts","../src/core/LSP.ts","../src/core/TypeCheckerApi.ts","../src/core/TypeParser.ts","../src/diagnostics/classSelfMismatch.ts","../src/diagnostics/duplicatePackage.ts","../src/diagnostics/effectInVoidSuccess.ts","../src/diagnostics/floatingEffect.ts","../src/diagnostics/genericEffectServices.ts","../src/diagnostics/importFromBarrel.ts","../src/diagnostics/leakingRequirements.ts","../src/diagnostics/missingEffectContext.ts","../src/diagnostics/missingEffectError.ts","../src/diagnostics/missingEffectServiceDependency.ts","../src/diagnostics/missingReturnYieldStar.ts","../src/diagnostics/missingStarInYieldEffectGen.ts","../src/diagnostics/multipleEffectProvide.ts","../src/refactors/writeTagClassAccessors.ts","../src/codegens/accessors.ts","../src/codegens.ts","../src/diagnostics/outdatedEffectCodegen.ts","../src/diagnostics/returnEffectInGen.ts","../src/diagnostics/scopeInLayerEffect.ts","../src/diagnostics/strictBooleanExpressions.ts","../src/diagnostics/tryCatchInEffectGen.ts","../src/diagnostics/unnecessaryEffectGen.ts","../src/diagnostics/unnecessaryPipe.ts","../src/diagnostics/unnecessaryPipeChain.ts","../src/diagnostics/unsupportedServiceAccessors.ts","../src/diagnostics.ts"],"sourcesContent":["import * as Array from \"effect/Array\"\nimport * as Either from \"effect/Either\"\nimport { pipe } from \"effect/Function\"\nimport type { PluginConfig, TransformerExtras } from \"ts-patch\"\nimport type * as ts from \"typescript\"\nimport * as LanguageServicePluginOptions from \"./core/LanguageServicePluginOptions\"\nimport * as LSP from \"./core/LSP\"\nimport * as Nano from \"./core/Nano\"\nimport * as TypeCheckerApi from \"./core/TypeCheckerApi\"\nimport * as TypeParser from \"./core/TypeParser\"\nimport * as TypeScriptApi from \"./core/TypeScriptApi\"\nimport * as TypeScriptUtils from \"./core/TypeScriptUtils\"\nimport { diagnostics } from \"./diagnostics\"\n\nconst programsChecked = new WeakMap<ts.Program, Set<string>>()\n\nexport default function(\n program: ts.Program,\n pluginConfig: PluginConfig,\n { addDiagnostic, ts: tsInstance }: TransformerExtras\n) {\n function runDiagnostics(program: ts.Program, sourceFile: ts.SourceFile) {\n // avoid to double-process the same file\n const checkedFiles = programsChecked.get(program) ?? new Set<string>()\n programsChecked.set(program, checkedFiles)\n if (checkedFiles.has(sourceFile.fileName)) return\n checkedFiles.add(sourceFile.fileName)\n\n // run the diagnostics and pipe them into addDiagnostic\n pipe(\n LSP.getSemanticDiagnosticsWithCodeFixes(diagnostics, sourceFile),\n TypeParser.nanoLayer,\n TypeScriptUtils.nanoLayer,\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, program.getTypeChecker()),\n Nano.provideService(TypeScriptApi.TypeScriptProgram, program),\n Nano.provideService(TypeScriptApi.TypeScriptApi, tsInstance),\n Nano.provideService(\n LanguageServicePluginOptions.LanguageServicePluginOptions,\n LanguageServicePluginOptions.parse(pluginConfig)\n ),\n Nano.run,\n Either.map((_) => _.diagnostics),\n Either.map(\n Array.filter((_) =>\n _.category === tsInstance.DiagnosticCategory.Error ||\n _.category === tsInstance.DiagnosticCategory.Warning\n )\n ),\n Either.getOrElse(() => []),\n Array.map(addDiagnostic)\n )\n }\n\n // process root files (works for noEmit: true)\n const rootFileNames = program.getRootFileNames()\n const sourceFiles = program.getSourceFiles().filter((_) => rootFileNames.indexOf(_.fileName) > -1)\n for (const sourceFile of sourceFiles) {\n runDiagnostics(program, sourceFile)\n }\n\n return (_: ts.TransformationContext) => (sourceFile: ts.SourceFile) => {\n // just be sure to try process any way (for noEmit: false with non catched files)\n runDiagnostics(program, sourceFile)\n return sourceFile\n }\n}\n","/**\n * @since 2.0.0\n */\nimport type { TypeLambda } from \"./HKT.js\"\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface FunctionTypeLambda extends TypeLambda {\n readonly type: (a: this[\"In\"]) => this[\"Target\"]\n}\n\n/**\n * Tests if a value is a `function`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isFunction } from \"effect/Predicate\"\n *\n * assert.deepStrictEqual(isFunction(isFunction), true)\n * assert.deepStrictEqual(isFunction(\"function\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isFunction = (input: unknown): input is Function => typeof input === \"function\"\n\n/**\n * Creates a function that can be used in a data-last (aka `pipe`able) or\n * data-first style.\n *\n * The first parameter to `dual` is either the arity of the uncurried function\n * or a predicate that determines if the function is being used in a data-first\n * or data-last style.\n *\n * Using the arity is the most common use case, but there are some cases where\n * you may want to use a predicate. For example, if you have a function that\n * takes an optional argument, you can use a predicate to determine if the\n * function is being used in a data-first or data-last style.\n *\n * You can pass either the arity of the uncurried function or a predicate\n * which determines if the function is being used in a data-first or\n * data-last style.\n *\n * **Example** (Using arity to determine data-first or data-last style)\n *\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * const sum = dual<\n * (that: number) => (self: number) => number,\n * (self: number, that: number) => number\n * >(2, (self, that) => self + that)\n *\n * console.log(sum(2, 3)) // 5\n * console.log(pipe(2, sum(3))) // 5\n * ```\n *\n * **Example** (Using call signatures to define the overloads)\n *\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * const sum: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual(2, (self: number, that: number): number => self + that)\n *\n * console.log(sum(2, 3)) // 5\n * console.log(pipe(2, sum(3))) // 5\n * ```\n *\n * **Example** (Using a predicate to determine data-first or data-last style)\n *\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * const sum = dual<\n * (that: number) => (self: number) => number,\n * (self: number, that: number) => number\n * >(\n * (args) => args.length === 2,\n * (self, that) => self + that\n * )\n *\n * console.log(sum(2, 3)) // 5\n * console.log(pipe(2, sum(3))) // 5\n * ```\n *\n * @since 2.0.0\n */\nexport const dual: {\n /**\n * Creates a function that can be used in a data-last (aka `pipe`able) or\n * data-first style.\n *\n * The first parameter to `dual` is either the arity of the uncurried function\n * or a predicate that determines if the function is being used in a data-first\n * or data-last style.\n *\n * Using the arity is the most common use case, but there are some cases where\n * you may want to use a predicate. For example, if you have a function that\n * takes an optional argument, you can use a predicate to determine if the\n * function is being used in a data-first or data-last style.\n *\n * You can pass either the arity of the uncurried function or a predicate\n * which determines if the function is being used in a data-first or\n * data-last style.\n *\n * **Example** (Using arity to determine data-first or data-last style)\n *\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * const sum = dual<\n * (that: number) => (self: number) => number,\n * (self: number, that: number) => number\n * >(2, (self, that) => self + that)\n *\n * console.log(sum(2, 3)) // 5\n * console.log(pipe(2, sum(3))) // 5\n * ```\n *\n * **Example** (Using call signatures to define the overloads)\n *\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * const sum: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual(2, (self: number, that: number): number => self + that)\n *\n * console.log(sum(2, 3)) // 5\n * console.log(pipe(2, sum(3))) // 5\n * ```\n *\n * **Example** (Using a predicate to determine data-first or data-last style)\n *\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * const sum = dual<\n * (that: number) => (self: number) => number,\n * (self: number, that: number) => number\n * >(\n * (args) => args.length === 2,\n * (self, that) => self + that\n * )\n *\n * console.log(sum(2, 3)) // 5\n * console.log(pipe(2, sum(3))) // 5\n * ```\n *\n * @since 2.0.0\n */\n <DataLast extends (...args: Array<any>) => any, DataFirst extends (...args: Array<any>) => any>(arity: Parameters<DataFirst>[\"length\"], body: DataFirst): DataLast & DataFirst\n /**\n * Creates a function that can be used in a data-last (aka `pipe`able) or\n * data-first style.\n *\n * The first parameter to `dual` is either the arity of the uncurried function\n * or a predicate that determines if the function is being used in a data-first\n * or data-last style.\n *\n * Using the arity is the most common use case, but there are some cases where\n * you may want to use a predicate. For example, if you have a function that\n * takes an optional argument, you can use a predicate to determine if the\n * function is being used in a data-first or data-last style.\n *\n * You can pass either the arity of the uncurried function or a predicate\n * which determines if the function is being used in a data-first or\n * data-last style.\n *\n * **Example** (Using arity to determine data-first or data-last style)\n *\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * const sum = dual<\n * (that: number) => (self: number) => number,\n * (self: number, that: number) => number\n * >(2, (self, that) => self + that)\n *\n * console.log(sum(2, 3)) // 5\n * console.log(pipe(2, sum(3))) // 5\n * ```\n *\n * **Example** (Using call signatures to define the overloads)\n *\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * const sum: {\n * (that: number): (self: number) => number\n * (self: number, that: number): number\n * } = dual(2, (self: number, that: number): number => self + that)\n *\n * console.log(sum(2, 3)) // 5\n * console.log(pipe(2, sum(3))) // 5\n * ```\n *\n * **Example** (Using a predicate to determine data-first or data-last style)\n *\n * ```ts\n * import { dual, pipe } from \"effect/Function\"\n *\n * const sum = dual<\n * (that: number) => (self: number) => number,\n * (self: number, that: number) => number\n * >(\n * (args) => args.length === 2,\n * (self, that) => self + that\n * )\n *\n * console.log(sum(2, 3)) // 5\n * console.log(pipe(2, sum(3))) // 5\n * ```\n *\n * @since 2.0.0\n */\n <DataLast extends (...args: Array<any>) => any, DataFirst extends (...args: Array<any>) => any>(isDataFirst: (args: IArguments) => boolean, body: DataFirst): DataLast & DataFirst\n} = function(arity, body) {\n if (typeof arity === \"function\") {\n return function() {\n if (arity(arguments)) {\n // @ts-expect-error\n return body.apply(this, arguments)\n }\n return ((self: any) => body(self, ...arguments)) as any\n }\n }\n\n switch (arity) {\n case 0:\n case 1:\n throw new RangeError(`Invalid arity ${arity}`)\n\n case 2:\n return function(a, b) {\n if (arguments.length >= 2) {\n return body(a, b)\n }\n return function(self: any) {\n return body(self, a)\n }\n }\n\n case 3:\n return function(a, b, c) {\n if (arguments.length >= 3) {\n return body(a, b, c)\n }\n return function(self: any) {\n return body(self, a, b)\n }\n }\n\n case 4:\n return function(a, b, c, d) {\n if (arguments.length >= 4) {\n return body(a, b, c, d)\n }\n return function(self: any) {\n return body(self, a, b, c)\n }\n }\n\n case 5:\n return function(a, b, c, d, e) {\n if (arguments.length >= 5) {\n return body(a, b, c, d, e)\n }\n return function(self: any) {\n return body(self, a, b, c, d)\n }\n }\n\n default:\n return function() {\n if (arguments.length >= arity) {\n // @ts-expect-error\n return body.apply(this, arguments)\n }\n const args = arguments\n return function(self: any) {\n return body(self, ...args)\n }\n }\n }\n}\n/**\n * Apply a function to given values.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, apply } from \"effect/Function\"\n * import { length } from \"effect/String\"\n *\n * assert.deepStrictEqual(pipe(length, apply(\"hello\")), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const apply = <A extends ReadonlyArray<unknown>>(...a: A) => <B>(self: (...a: A) => B): B => self(...a)\n\n/**\n * A lazy argument.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { LazyArg, constant } from \"effect/Function\"\n *\n * const constNull: LazyArg<null> = constant(null)\n * ```\n *\n * @since 2.0.0\n */\nexport interface LazyArg<A> {\n (): A\n}\n\n/**\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { FunctionN } from \"effect/Function\"\n *\n * const sum: FunctionN<[number, number], number> = (a, b) => a + b\n * ```\n *\n * @since 2.0.0\n */\nexport interface FunctionN<A extends ReadonlyArray<unknown>, B> {\n (...args: A): B\n}\n\n/**\n * The identity function, i.e. A function that returns its input argument.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { identity } from \"effect/Function\"\n *\n * assert.deepStrictEqual(identity(5), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const identity = <A>(a: A): A => a\n\n/**\n * A function that ensures that the type of an expression matches some type,\n * without changing the resulting type of that expression.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { satisfies } from \"effect/Function\"\n *\n * const test1 = satisfies<number>()(5 as const)\n * //^? const test: 5\n * // @ts-expect-error\n * const test2 = satisfies<string>()(5)\n * //^? Argument of type 'number' is not assignable to parameter of type 'string'\n *\n * assert.deepStrictEqual(satisfies<number>()(5), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const satisfies = <A>() => <B extends A>(b: B) => b\n\n/**\n * Casts the result to the specified type.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { unsafeCoerce, identity } from \"effect/Function\"\n *\n * assert.deepStrictEqual(unsafeCoerce, identity)\n * ```\n *\n * @since 2.0.0\n */\nexport const unsafeCoerce: <A, B>(a: A) => B = identity as any\n\n/**\n * Creates a constant value that never changes.\n *\n * This is useful when you want to pass a value to a higher-order function (a function that takes another function as its argument)\n * and want that inner function to always use the same value, no matter how many times it is called.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { constant } from \"effect/Function\"\n *\n * const constNull = constant(null)\n *\n * assert.deepStrictEqual(constNull(), null)\n * assert.deepStrictEqual(constNull(), null)\n * ```\n *\n * @since 2.0.0\n */\nexport const constant = <A>(value: A): LazyArg<A> => () => value\n\n/**\n * A thunk that returns always `true`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { constTrue } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constTrue(), true)\n * ```\n *\n * @since 2.0.0\n */\nexport const constTrue: LazyArg<boolean> = constant(true)\n\n/**\n * A thunk that returns always `false`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { constFalse } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constFalse(), false)\n * ```\n *\n * @since 2.0.0\n */\nexport const constFalse: LazyArg<boolean> = constant(false)\n\n/**\n * A thunk that returns always `null`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { constNull } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constNull(), null)\n * ```\n *\n * @since 2.0.0\n */\nexport const constNull: LazyArg<null> = constant(null)\n\n/**\n * A thunk that returns always `undefined`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { constUndefined } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constUndefined(), undefined)\n * ```\n *\n * @since 2.0.0\n */\nexport const constUndefined: LazyArg<undefined> = constant(undefined)\n\n/**\n * A thunk that returns always `void`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { constVoid } from \"effect/Function\"\n *\n * assert.deepStrictEqual(constVoid(), undefined)\n * ```\n *\n * @since 2.0.0\n */\nexport const constVoid: LazyArg<void> = constUndefined\n\n/**\n * Reverses the order of arguments for a curried function.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { flip } from \"effect/Function\"\n *\n * const f = (a: number) => (b: string) => a - b.length\n *\n * assert.deepStrictEqual(flip(f)('aaa')(2), -1)\n * ```\n *\n * @since 2.0.0\n */\nexport const flip = <A extends Array<unknown>, B extends Array<unknown>, C>(\n f: (...a: A) => (...b: B) => C\n): (...b: B) => (...a: A) => C =>\n(...b) =>\n(...a) => f(...a)(...b)\n\n/**\n * Composes two functions, `ab` and `bc` into a single function that takes in an argument `a` of type `A` and returns a result of type `C`.\n * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { compose } from \"effect/Function\"\n *\n * const increment = (n: number) => n + 1;\n * const square = (n: number) => n * n;\n *\n * assert.strictEqual(compose(increment, square)(2), 9);\n * ```\n *\n * @since 2.0.0\n */\nexport const compose: {\n /**\n * Composes two functions, `ab` and `bc` into a single function that takes in an argument `a` of type `A` and returns a result of type `C`.\n * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { compose } from \"effect/Function\"\n *\n * const increment = (n: number) => n + 1;\n * const square = (n: number) => n * n;\n *\n * assert.strictEqual(compose(increment, square)(2), 9);\n * ```\n *\n * @since 2.0.0\n */\n <B, C>(bc: (b: B) => C): <A>(self: (a: A) => B) => (a: A) => C\n /**\n * Composes two functions, `ab` and `bc` into a single function that takes in an argument `a` of type `A` and returns a result of type `C`.\n * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { compose } from \"effect/Function\"\n *\n * const increment = (n: number) => n + 1;\n * const square = (n: number) => n * n;\n *\n * assert.strictEqual(compose(increment, square)(2), 9);\n * ```\n *\n * @since 2.0.0\n */\n <A, B, C>(self: (a: A) => B, bc: (b: B) => C): (a: A) => C\n} = dual(2, <A, B, C>(ab: (a: A) => B, bc: (b: B) => C): (a: A) => C => (a) => bc(ab(a)))\n\n/**\n * The `absurd` function is a stub for cases where a value of type `never` is encountered in your code,\n * meaning that it should be impossible for this code to be executed.\n *\n * This function is particularly useful when it's necessary to specify that certain cases are impossible.\n *\n * @since 2.0.0\n */\nexport const absurd = <A>(_: never): A => {\n throw new Error(\"Called `absurd` function which should be uncallable\")\n}\n\n/**\n * Creates a version of this function: instead of `n` arguments, it accepts a single tuple argument.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { tupled } from \"effect/Function\"\n *\n * const sumTupled = tupled((x: number, y: number): number => x + y)\n *\n * assert.deepStrictEqual(sumTupled([1, 2]), 3)\n * ```\n *\n * @since 2.0.0\n */\nexport const tupled = <A extends ReadonlyArray<unknown>, B>(f: (...a: A) => B): (a: A) => B => (a) => f(...a)\n\n/**\n * Inverse function of `tupled`\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { untupled } from \"effect/Function\"\n *\n * const getFirst = untupled(<A, B>(tuple: [A, B]): A => tuple[0])\n *\n * assert.deepStrictEqual(getFirst(1, 2), 1)\n * ```\n *\n * @since 2.0.0\n */\nexport const untupled = <A extends ReadonlyArray<unknown>, B>(f: (a: A) => B): (...a: A) => B => (...a) => f(a)\n\n/**\n * Pipes the value of an expression into a pipeline of functions.\n *\n * **Details**\n *\n * The `pipe` function is a utility that allows us to compose functions in a\n * readable and sequential manner. It takes the output of one function and\n * passes it as the input to the next function in the pipeline. This enables us\n * to build complex transformations by chaining multiple functions together.\n *\n * ```ts skip-type-checking\n * import { pipe } from \"effect\"\n *\n * const result = pipe(input, func1, func2, ..., funcN)\n * ```\n *\n * In this syntax, `input` is the initial value, and `func1`, `func2`, ...,\n * `funcN` are the functions to be applied in sequence. The result of each\n * function becomes the input for the next function, and the final result is\n * returned.\n *\n * Here's an illustration of how `pipe` works:\n *\n * ```\n * ┌───────┐ ┌───────┐ ┌───────┐ ┌───────┐ ┌───────┐ ┌────────┐\n * │ input │───►│ func1 │───►│ func2 │───►│ ... │───►│ funcN │───►│ result │\n * └───────┘ └───────┘ └───────┘ └───────┘ └───────┘ └────────┘\n * ```\n *\n * It's important to note that functions passed to `pipe` must have a **single\n * argument** because they are only called with a single argument.\n *\n * **When to Use**\n *\n * This is useful in combination with data-last functions as a simulation of\n * methods:\n *\n * ```ts skip-type-checking\n * as.map(f).filter(g)\n * ```\n *\n * becomes:\n *\n * ```ts skip-type-checking\n * import { pipe, Array } from \"effect\"\n *\n * pipe(as, Array.map(f), Array.filter(g))\n * ```\n *\n * **Example** (Chaining Arithmetic Operations)\n *\n * ```ts\n * import { pipe } from \"effect\"\n *\n * // Define simple arithmetic operations\n * const increment = (x: number) => x + 1\n * const double = (x: number) => x * 2\n * const subtractTen = (x: number) => x - 10\n *\n * // Sequentially apply these operations using `pipe`\n * const result = pipe(5, increment, double, subtractTen)\n *\n * console.log(result)\n * // Output: 2\n * ```\n *\n * @since 2.0.0\n */\nexport function pipe<A>(a: A): A\nexport function pipe<A, B = never>(a: A, ab: (a: A) => B): B\nexport function pipe<A, B = never, C = never>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C\n): C\nexport function pipe<A, B = never, C = never, D = never>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D\n): D\nexport function pipe<A, B = never, C = never, D = never, E = never>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E\n): E\nexport function pipe<A, B = never, C = never, D = never, E = never, F = never>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F\n): F\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G\n): G\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H\n): H\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I\n): I\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J\n): J\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K\n): K\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L\n): L\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M\n): M\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N\n): N\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O\n): O\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P\n): P\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q\n): Q\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R\n): R\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => S\n): S\nexport function pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never,\n T = never\n>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => S,\n st: (s: S) => T\n): T\nexport function pipe(\n a: unknown,\n ab?: Function,\n bc?: Function,\n cd?: Function,\n de?: Function,\n ef?: Function,\n fg?: Function,\n gh?: Function,\n hi?: Function\n): unknown {\n switch (arguments.length) {\n case 1:\n return a\n case 2:\n return ab!(a)\n case 3:\n return bc!(ab!(a))\n case 4:\n return cd!(bc!(ab!(a)))\n case 5:\n return de!(cd!(bc!(ab!(a))))\n case 6:\n return ef!(de!(cd!(bc!(ab!(a)))))\n case 7:\n return fg!(ef!(de!(cd!(bc!(ab!(a))))))\n case 8:\n return gh!(fg!(ef!(de!(cd!(bc!(ab!(a)))))))\n case 9:\n return hi!(gh!(fg!(ef!(de!(cd!(bc!(ab!(a))))))))\n default: {\n let ret = arguments[0]\n for (let i = 1; i < arguments.length; i++) {\n ret = arguments[i](ret)\n }\n return ret\n }\n }\n}\n\n/**\n * Performs left-to-right function composition. The first argument may have any arity, the remaining arguments must be unary.\n *\n * See also [`pipe`](#pipe).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { flow } from \"effect/Function\"\n *\n * const len = (s: string): number => s.length\n * const double = (n: number): number => n * 2\n *\n * const f = flow(len, double)\n *\n * assert.strictEqual(f('aaa'), 6)\n * ```\n *\n * @since 2.0.0\n */\nexport function flow<A extends ReadonlyArray<unknown>, B = never>(\n ab: (...a: A) => B\n): (...a: A) => B\nexport function flow<A extends ReadonlyArray<unknown>, B = never, C = never>(\n ab: (...a: A) => B,\n bc: (b: B) => C\n): (...a: A) => C\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never\n>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...a: A) => D\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E\n): (...a: A) => E\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F\n): (...a: A) => F\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G\n): (...a: A) => G\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H\n): (...a: A) => H\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I\n): (...a: A) => I\nexport function flow<\n A extends ReadonlyArray<unknown>,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never\n>(\n ab: (...a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J\n): (...a: A) => J\nexport function flow(\n ab: Function,\n bc?: Function,\n cd?: Function,\n de?: Function,\n ef?: Function,\n fg?: Function,\n gh?: Function,\n hi?: Function,\n ij?: Function\n): unknown {\n switch (arguments.length) {\n case 1:\n return ab\n case 2:\n return function(this: unknown) {\n return bc!(ab.apply(this, arguments))\n }\n case 3:\n return function(this: unknown) {\n return cd!(bc!(ab.apply(this, arguments)))\n }\n case 4:\n return function(this: unknown) {\n return de!(cd!(bc!(ab.apply(this, arguments))))\n }\n case 5:\n return function(this: unknown) {\n return ef!(de!(cd!(bc!(ab.apply(this, arguments)))))\n }\n case 6:\n return function(this: unknown) {\n return fg!(ef!(de!(cd!(bc!(ab.apply(this, arguments))))))\n }\n case 7:\n return function(this: unknown) {\n return gh!(fg!(ef!(de!(cd!(bc!(ab.apply(this, arguments)))))))\n }\n case 8:\n return function(this: unknown) {\n return hi!(gh!(fg!(ef!(de!(cd!(bc!(ab.apply(this, arguments))))))))\n }\n case 9:\n return function(this: unknown) {\n return ij!(hi!(gh!(fg!(ef!(de!(cd!(bc!(ab.apply(this, arguments)))))))))\n }\n }\n return\n}\n\n/**\n * Type hole simulation.\n *\n * @since 2.0.0\n */\nexport const hole: <T>() => T = unsafeCoerce(absurd)\n\n/**\n * The SK combinator, also known as the \"S-K combinator\" or \"S-combinator\", is a fundamental combinator in the\n * lambda calculus and the SKI combinator calculus.\n *\n * This function is useful for discarding the first argument passed to it and returning the second argument.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { SK } from \"effect/Function\";\n *\n * assert.deepStrictEqual(SK(0, \"hello\"), \"hello\")\n * ```\n *\n * @since 2.0.0\n */\nexport const SK = <A, B>(_: A, b: B): B => b\n","/**\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 */\nconst globalStoreId = `effect/GlobalValue`\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 * This module provides a collection of functions for working with predicates and refinements.\n *\n * A `Predicate<A>` is a function that takes a value of type `A` and returns a boolean.\n * It is used to check if a value satisfies a certain condition.\n *\n * A `Refinement<A, B>` is a special type of predicate that not only checks a condition\n * but also provides a type guard, allowing TypeScript to narrow the type of the input\n * value from `A` to a more specific type `B` within a conditional block.\n *\n * The module includes:\n * - Basic predicates and refinements for common types (e.g., `isString`, `isNumber`).\n * - Combinators to create new predicates from existing ones (e.g., `and`, `or`, `not`).\n * - Advanced combinators for working with data structures (e.g., `tuple`, `struct`).\n * - Type-level utilities for inspecting predicate and refinement types.\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 * Represents a function that takes a value of type `A` and returns `true` if the value\n * satisfies some condition, `false` otherwise.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n * import * as assert from \"node:assert\"\n *\n * const isEven: Predicate.Predicate<number> = (n) => n % 2 === 0\n *\n * assert.strictEqual(isEven(2), true)\n * assert.strictEqual(isEven(3), false)\n * ```\n *\n * @category models\n * @since 2.0.0\n */\nexport interface Predicate<in A> {\n (a: A): boolean\n}\n\n/**\n * A `TypeLambda` for `Predicate`. This is used to support higher-kinded types\n * and allows `Predicate` to be used in generic contexts within the `effect` ecosystem.\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 * Represents a function that serves as a type guard.\n *\n * A `Refinement<A, B>` is a function that takes a value of type `A` and returns a\n * type predicate `a is B`, where `B` is a subtype of `A`. If the function returns\n * `true`, TypeScript will narrow the type of the input variable to `B`.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n * import * as assert from \"node:assert\"\n *\n * const isString: Predicate.Refinement<unknown, string> = (u): u is string => typeof u === \"string\"\n *\n * const value: unknown = \"hello\"\n *\n * if (isString(value)) {\n * // value is now known to be a string\n * assert.strictEqual(value.toUpperCase(), \"HELLO\")\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 * A namespace for type-level utilities for `Predicate`.\n *\n * @since 3.6.0\n * @category type-level\n */\nexport declare namespace Predicate {\n /**\n * Extracts the input type `A` from a `Predicate<A>`.\n *\n * @example\n * ```ts\n * import { type Predicate } from \"effect\"\n *\n * type T = Predicate.Predicate.In<Predicate.Predicate<string>> // T is string\n * ```\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 * A type representing any `Predicate`.\n *\n * @since 3.6.0\n * @category type-level\n */\n export type Any = Predicate<never>\n}\n\n/**\n * A namespace for type-level utilities for `Refinement`.\n *\n * @since 3.6.0\n * @category type-level\n */\nexport declare namespace Refinement {\n /**\n * Extracts the input type `A` from a `Refinement<A, B>`.\n *\n * @example\n * ```ts\n * import { type Predicate } from \"effect\"\n *\n * type IsString = Predicate.Refinement<unknown, string>\n * type T = Predicate.Refinement.In<IsString> // T is unknown\n * ```\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 * Extracts the output (refined) type `B` from a `Refinement<A, B>`.\n *\n * @example\n * ```ts\n * import { type Predicate } from \"effect\"\n *\n * type IsString = Predicate.Refinement<unknown, string>\n * type T = Predicate.Refinement.Out<IsString> // T is string\n * ```\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 * A type representing any `Refinement`.\n *\n * @since 3.6.0\n * @category type-level\n */\n export type Any = Refinement<any, any>\n}\n\n/**\n * Transforms a `Predicate<A>` into a `Predicate<B>` by applying a function `(b: B) => A`\n * to the input before passing it to the predicate. This is also known as \"contramap\" or\n * \"pre-composition\".\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n * import * as assert from \"node:assert\"\n *\n * // A predicate on numbers\n * const isPositive: Predicate.Predicate<number> = Number.greaterThan(0)\n *\n * // A function from `string` to `number`\n * const stringLength = (s: string): number => s.length\n *\n * // Create a new predicate on strings by mapping the input\n * const hasPositiveLength = Predicate.mapInput(isPositive, stringLength)\n *\n * assert.strictEqual(hasPositiveLength(\"hello\"), true)\n * assert.strictEqual(hasPositiveLength(\"\"), false)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const mapInput: {\n /**\n * Transforms a `Predicate<A>` into a `Predicate<B>` by applying a function `(b: B) => A`\n * to the input before passing it to the predicate. This is also known as \"contramap\" or\n * \"pre-composition\".\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n * import * as assert from \"node:assert\"\n *\n * // A predicate on numbers\n * const isPositive: Predicate.Predicate<number> = Number.greaterThan(0)\n *\n * // A function from `string` to `number`\n * const stringLength = (s: string): number => s.length\n *\n * // Create a new predicate on strings by mapping the input\n * const hasPositiveLength = Predicate.mapInput(isPositive, stringLength)\n *\n * assert.strictEqual(hasPositiveLength(\"hello\"), true)\n * assert.strictEqual(hasPositiveLength(\"\"), false)\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 * Transforms a `Predicate<A>` into a `Predicate<B>` by applying a function `(b: B) => A`\n * to the input before passing it to the predicate. This is also known as \"contramap\" or\n * \"pre-composition\".\n *\n * @example\n * ```ts\n * import { Predicate, Number } from \"effect\"\n * import * as assert from \"node:assert\"\n *\n * // A predicate on numbers\n * const isPositive: Predicate.Predicate<number> = Number.greaterThan(0)\n *\n * // A function from `string` to `number`\n * const stringLength = (s: string): number => s.length\n *\n * // Create a new predicate on strings by mapping the input\n * const hasPositiveLength = Predicate.mapInput(isPositive, stringLength)\n *\n * assert.strictEqual(hasPositiveLength(\"hello\"), true)\n * assert.strictEqual(hasPositiveLength(\"\"), false)\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 * A refinement that checks if a `ReadonlyArray<T>` is a tuple with exactly `N` elements.\n * If the check is successful, the type is narrowed to `TupleOf<N, T>`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isTupleOf } from \"effect/Predicate\"\n *\n * const isTupleOf3 = isTupleOf(3)\n *\n * assert.strictEqual(isTupleOf3([1, 2, 3]), true);\n * assert.strictEqual(isTupleOf3([1, 2]), false);\n *\n * const arr: number[] = [1, 2, 3];\n * if (isTupleOf(arr, 3)) {\n * // The type of arr is now [number, number, number]\n * const [a, b, c] = arr;\n * assert.deepStrictEqual([a, b, c], [1, 2, 3])\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\nexport const isTupleOf: {\n /**\n * A refinement that checks if a `ReadonlyArray<T>` is a tuple with exactly `N` elements.\n * If the check is successful, the type is narrowed to `TupleOf<N, T>`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isTupleOf } from \"effect/Predicate\"\n *\n * const isTupleOf3 = isTupleOf(3)\n *\n * assert.strictEqual(isTupleOf3([1, 2, 3]), true);\n * assert.strictEqual(isTupleOf3([1, 2]), false);\n *\n * const arr: number[] = [1, 2, 3];\n * if (isTupleOf(arr, 3)) {\n * // The type of arr is now [number, number, number]\n * const [a, b, c] = arr;\n * assert.deepStrictEqual([a, b, c], [1, 2, 3])\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 * A refinement that checks if a `ReadonlyArray<T>` is a tuple with exactly `N` elements.\n * If the check is successful, the type is narrowed to `TupleOf<N, T>`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isTupleOf } from \"effect/Predicate\"\n *\n * const isTupleOf3 = isTupleOf(3)\n *\n * assert.strictEqual(isTupleOf3([1, 2, 3]), true);\n * assert.strictEqual(isTupleOf3([1, 2]), false);\n *\n * const arr: number[] = [1, 2, 3];\n * if (isTupleOf(arr, 3)) {\n * // The type of arr is now [number, number, number]\n * const [a, b, c] = arr;\n * assert.deepStrictEqual([a, b, c], [1, 2, 3])\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 * A refinement that checks if a `ReadonlyArray<T>` is a tuple with at least `N` elements.\n * If the check is successful, the type is narrowed to `TupleOfAtLeast<N, T>`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isTupleOfAtLeast } from \"effect/Predicate\"\n *\n * const isTupleOfAtLeast3 = isTupleOfAtLeast(3)\n *\n * assert.strictEqual(isTupleOfAtLeast3([1, 2, 3]), true);\n * assert.strictEqual(isTupleOfAtLeast3([1, 2, 3, 4]), true);\n * assert.strictEqual(isTupleOfAtLeast3([1, 2]), false);\n *\n * const arr: number[] = [1, 2, 3, 4];\n * if (isTupleOfAtLeast(arr, 3)) {\n * // The type of arr is now [number, number, number, ...number[]]\n * const [a, b, c] = arr;\n * assert.deepStrictEqual([a, b, c], [1, 2, 3])\n * }\n * ```\n *\n * @category guards\n * @since 3.3.0\n */\nexport const isTupleOfAtLeast: {\n /**\n * A refinement that checks if a `ReadonlyArray<T>` is a tuple with at least `N` elements.\n * If the check is successful, the type is narrowed to `TupleOfAtLeast<N, T>`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isTupleOfAtLeast } from \"effect/Predicate\"\n *\n * const isTupleOfAtLeast3 = isTupleOfAtLeast(3)\n *\n * assert.strictEqual(isTupleOfAtLeast3([1, 2, 3]), true);\n * assert.strictEqual(isTupleOfAtLeast3([1, 2, 3, 4]), true);\n * assert.strictEqual(isTupleOfAtLeast3([1, 2]), false);\n *\n * const arr: number[] = [1, 2, 3, 4];\n * if (isTupleOfAtLeast(arr, 3)) {\n * // The type of arr is now [number, number, number, ...number[]]\n * const [a, b, c] = arr;\n * assert.deepStrictEqual([a, b, c], [1, 2, 3])\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 * A refinement that checks if a `ReadonlyArray<T>` is a tuple with at least `N` elements.\n * If the check is successful, the type is narrowed to `TupleOfAtLeast<N, T>`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isTupleOfAtLeast } from \"effect/Predicate\"\n *\n * const isTupleOfAtLeast3 = isTupleOfAtLeast(3)\n *\n * assert.strictEqual(isTupleOfAtLeast3([1, 2, 3]), true);\n * assert.strictEqual(isTupleOfAtLeast3([1, 2, 3, 4]), true);\n * assert.strictEqual(isTupleOfAtLeast3([1, 2]), false);\n *\n * const arr: number[] = [1, 2, 3, 4];\n * if (isTupleOfAtLeast(arr, 3)) {\n * // The type of arr is now [number, number, number, ...number[]]\n * const [a, b, c] = arr;\n * assert.deepStrictEqual([a, b, c], [1, 2, 3])\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 * A predicate that checks if a value is \"truthy\" in JavaScript.\n * Fails for `false`, `0`, `-0`, `0n`, `\"\"`, `null`, `undefined`, and `NaN`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isTruthy } from \"effect/Predicate\"\n *\n * assert.strictEqual(isTruthy(1), true)\n * assert.strictEqual(isTruthy(\"hello\"), true)\n * assert.strictEqual(isTruthy({}), true)\n *\n * assert.strictEqual(isTruthy(0), false)\n * assert.strictEqual(isTruthy(\"\"), false)\n * assert.strictEqual(isTruthy(null), false)\n * assert.strictEqual(isTruthy(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isTruthy = (input: unknown) => !!input\n\n/**\n * A refinement that checks if a value is a `Set`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isSet } from \"effect/Predicate\"\n *\n * assert.strictEqual(isSet(new Set([1, 2])), true)\n * assert.strictEqual(isSet(new Set()), true)\n *\n * assert.strictEqual(isSet({}), false)\n * assert.strictEqual(isSet([1, 2]), 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 * A refinement that checks if a value is a `Map`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isMap } from \"effect/Predicate\"\n *\n * assert.strictEqual(isMap(new Map()), true)\n *\n * assert.strictEqual(isMap({}), false)\n * assert.strictEqual(isMap(new Set()), 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 * A refinement that checks if a value is a `string`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isString } from \"effect/Predicate\"\n *\n * assert.strictEqual(isString(\"hello\"), true)\n * assert.strictEqual(isString(\"\"), true)\n *\n * assert.strictEqual(isString(123), false)\n * assert.strictEqual(isString(null), 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 * A refinement that checks if a value is a `number`. Note that this\n * check returns `false` for `NaN`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isNumber } from \"effect/Predicate\"\n *\n * assert.strictEqual(isNumber(123), true)\n * assert.strictEqual(isNumber(0), true)\n * assert.strictEqual(isNumber(-1.5), true)\n *\n * assert.strictEqual(isNumber(\"123\"), false)\n * assert.strictEqual(isNumber(NaN), false) // Special case: NaN is a number type but returns 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 * A refinement that checks if a value is a `boolean`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isBoolean } from \"effect/Predicate\"\n *\n * assert.strictEqual(isBoolean(true), true)\n * assert.strictEqual(isBoolean(false), true)\n *\n * assert.strictEqual(isBoolean(\"true\"), false)\n * assert.strictEqual(isBoolean(0), 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 * A refinement that checks if a value is a `bigint`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isBigInt } from \"effect/Predicate\"\n *\n * assert.strictEqual(isBigInt(1n), true)\n *\n * assert.strictEqual(isBigInt(1), false)\n * assert.strictEqual(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 * A refinement that checks if a value is a `symbol`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isSymbol } from \"effect/Predicate\"\n *\n * assert.strictEqual(isSymbol(Symbol.for(\"a\")), true)\n *\n * assert.strictEqual(isSymbol(\"a\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isSymbol = (input: unknown): input is symbol => typeof input === \"symbol\"\n\n// TODO: make public\n/**\n * A refinement that checks if a value is a valid `PropertyKey` (a `string`, `number`, or `symbol`).\n * @internal\n */\nexport const isPropertyKey = (u: unknown): u is PropertyKey => isString(u) || isNumber(u) || isSymbol(u)\n\n/**\n * A refinement that checks if a value is a `Function`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isFunction } from \"effect/Predicate\"\n *\n * assert.strictEqual(isFunction(() => {}), true)\n * assert.strictEqual(isFunction(isFunction), true)\n *\n * assert.strictEqual(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 * A refinement that checks if a value is `undefined`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isUndefined } from \"effect/Predicate\"\n *\n * assert.strictEqual(isUndefined(undefined), true)\n *\n * assert.strictEqual(isUndefined(null), false)\n * assert.strictEqual(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 * A refinement that checks if a value is not `undefined`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isNotUndefined } from \"effect/Predicate\"\n *\n * assert.strictEqual(isNotUndefined(null), true)\n * assert.strictEqual(isNotUndefined(\"value\"), true)\n *\n * assert.strictEqual(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 * A refinement that checks if a value is `null`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isNull } from \"effect/Predicate\"\n *\n * assert.strictEqual(isNull(null), true)\n *\n * assert.strictEqual(isNull(undefined), false)\n * assert.strictEqual(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 * A refinement that checks if a value is not `null`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isNotNull } from \"effect/Predicate\"\n *\n * assert.strictEqual(isNotNull(undefined), true)\n * assert.strictEqual(isNotNull(\"value\"), true)\n *\n * assert.strictEqual(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 refinement that always returns `false`. The type is narrowed to `never`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isNever } from \"effect/Predicate\"\n *\n * assert.strictEqual(isNever(1), false)\n * assert.strictEqual(isNever(null), false)\n * assert.strictEqual(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 refinement that always returns `true`. The type is narrowed to `unknown`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isUnknown } from \"effect/Predicate\"\n *\n * assert.strictEqual(isUnknown(1), true)\n * assert.strictEqual(isUnknown(null), true)\n * assert.strictEqual(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/**\n * Checks if the input is an object or an array.\n * @internal\n */\nexport const isRecordOrArray = (input: unknown): input is { [x: PropertyKey]: unknown } =>\n typeof input === \"object\" && input !== null\n\n/**\n * A refinement that checks if a value is an `object`. Note that in JavaScript,\n * arrays and functions are also considered objects.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isObject } from \"effect/Predicate\"\n *\n * assert.strictEqual(isObject({}), true)\n * assert.strictEqual(isObject([]), true)\n * assert.strictEqual(isObject(() => {}), true)\n *\n * assert.strictEqual(isObject(null), false)\n * assert.strictEqual(isObject(\"hello\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n * @see isRecord to check for plain objects (excluding arrays and functions).\n */\nexport const isObject = (input: unknown): input is object => isRecordOrArray(input) || isFunction(input)\n\n/**\n * A refinement that checks if a value is an object-like value and has a specific property key.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { hasProperty } from \"effect/Predicate\"\n *\n * assert.strictEqual(hasProperty({ a: 1 }, \"a\"), true)\n * assert.strictEqual(hasProperty({ a: 1 }, \"b\"), false)\n *\n * const value: unknown = { name: \"Alice\" };\n * if (hasProperty(value, \"name\")) {\n * // The type of `value` is narrowed to `{ name: unknown }`\n * // and we can safely access `value.name`\n * console.log(value.name)\n * }\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const hasProperty: {\n /**\n * A refinement that checks if a value is an object-like value and has a specific property key.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { hasProperty } from \"effect/Predicate\"\n *\n * assert.strictEqual(hasProperty({ a: 1 }, \"a\"), true)\n * assert.strictEqual(hasProperty({ a: 1 }, \"b\"), false)\n *\n * const value: unknown = { name: \"Alice\" };\n * if (hasProperty(value, \"name\")) {\n * // The type of `value` is narrowed to `{ name: unknown }`\n * // and we can safely access `value.name`\n * console.log(value.name)\n * }\n * ```\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 * A refinement that checks if a value is an object-like value and has a specific property key.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { hasProperty } from \"effect/Predicate\"\n *\n * assert.strictEqual(hasProperty({ a: 1 }, \"a\"), true)\n * assert.strictEqual(hasProperty({ a: 1 }, \"b\"), false)\n *\n * const value: unknown = { name: \"Alice\" };\n * if (hasProperty(value, \"name\")) {\n * // The type of `value` is narrowed to `{ name: unknown }`\n * // and we can safely access `value.name`\n * console.log(value.name)\n * }\n * ```\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 * A refinement that checks if a value is an object with a `_tag` property\n * that matches the given tag. This is a powerful tool for working with\n * discriminated union types.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isTagged } from \"effect/Predicate\"\n *\n * type Shape = { _tag: \"circle\"; radius: number } | { _tag: \"square\"; side: number }\n *\n * const isCircle = isTagged(\"circle\")\n *\n * const shape1: Shape = { _tag: \"circle\", radius: 10 }\n * const shape2: Shape = { _tag: \"square\", side: 5 }\n *\n * assert.strictEqual(isCircle(shape1), true)\n * assert.strictEqual(isCircle(shape2), false)\n *\n * if (isCircle(shape1)) {\n * // shape1 is now narrowed to { _tag: \"circle\"; radius: number }\n * assert.strictEqual(shape1.radius, 10)\n * }\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isTagged: {\n /**\n * A refinement that checks if a value is an object with a `_tag` property\n * that matches the given tag. This is a powerful tool for working with\n * discriminated union types.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isTagged } from \"effect/Predicate\"\n *\n * type Shape = { _tag: \"circle\"; radius: number } | { _tag: \"square\"; side: number }\n *\n * const isCircle = isTagged(\"circle\")\n *\n * const shape1: Shape = { _tag: \"circle\", radius: 10 }\n * const shape2: Shape = { _tag: \"square\", side: 5 }\n *\n * assert.strictEqual(isCircle(shape1), true)\n * assert.strictEqual(isCircle(shape2), false)\n *\n * if (isCircle(shape1)) {\n * // shape1 is now narrowed to { _tag: \"circle\"; radius: number }\n * assert.strictEqual(shape1.radius, 10)\n * }\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 * A refinement that checks if a value is an object with a `_tag` property\n * that matches the given tag. This is a powerful tool for working with\n * discriminated union types.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isTagged } from \"effect/Predicate\"\n *\n * type Shape = { _tag: \"circle\"; radius: number } | { _tag: \"square\"; side: number }\n *\n * const isCircle = isTagged(\"circle\")\n *\n * const shape1: Shape = { _tag: \"circle\", radius: 10 }\n * const shape2: Shape = { _tag: \"square\", side: 5 }\n *\n * assert.strictEqual(isCircle(shape1), true)\n * assert.strictEqual(isCircle(shape2), false)\n *\n * if (isCircle(shape1)) {\n * // shape1 is now narrowed to { _tag: \"circle\"; radius: number }\n * assert.strictEqual(shape1.radius, 10)\n * }\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 refinement that checks if a value is either `null` or `undefined`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isNullable } from \"effect/Predicate\"\n *\n * assert.strictEqual(isNullable(null), true)\n * assert.strictEqual(isNullable(undefined), true)\n *\n * assert.strictEqual(isNullable(0), false)\n * assert.strictEqual(isNullable(\"\"), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n * @see isNotNullable\n */\nexport const isNullable = <A>(input: A): input is Extract<A, null | undefined> => input === null || input === undefined\n\n/**\n * A refinement that checks if a value is neither `null` nor `undefined`.\n * The type is narrowed to `NonNullable<A>`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isNotNullable } from \"effect/Predicate\"\n *\n * assert.strictEqual(isNotNullable(0), true)\n * assert.strictEqual(isNotNullable(\"hello\"), true)\n *\n * assert.strictEqual(isNotNullable(null), false)\n * assert.strictEqual(isNotNullable(undefined), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n * @see isNullable\n */\nexport const isNotNullable = <A>(input: A): input is NonNullable<A> => input !== null && input !== undefined\n\n/**\n * A refinement that checks if a value is an instance of `Error`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isError } from \"effect/Predicate\"\n *\n * assert.strictEqual(isError(new Error(\"boom\")), true)\n * assert.strictEqual(isError(new TypeError(\"boom\")), true)\n *\n * assert.strictEqual(isError({ message: \"boom\" }), false)\n * assert.strictEqual(isError(\"boom\"), 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 refinement that checks if a value is a `Uint8Array`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isUint8Array } from \"effect/Predicate\"\n *\n * assert.strictEqual(isUint8Array(new Uint8Array()), true)\n *\n * assert.strictEqual(isUint8Array(new Uint16Array()), false)\n * assert.strictEqual(isUint8Array([1, 2, 3]), 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 refinement that checks if a value is a `Date` object.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isDate } from \"effect/Predicate\"\n *\n * assert.strictEqual(isDate(new Date()), true)\n *\n * assert.strictEqual(isDate(Date.now()), false) // `Date.now()` returns a number\n * assert.strictEqual(isDate(\"2023-01-01\"), 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 refinement that checks if a value is an `Iterable`.\n * Many built-in types are iterable, such as `Array`, `string`, `Map`, and `Set`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isIterable } from \"effect/Predicate\"\n *\n * assert.strictEqual(isIterable([]), true)\n * assert.strictEqual(isIterable(\"hello\"), true)\n * assert.strictEqual(isIterable(new Set()), true)\n *\n * assert.strictEqual(isIterable({}), false)\n * assert.strictEqual(isIterable(123), 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 refinement that checks if a value is a record (i.e., a plain object).\n * This check returns `false` for arrays, `null`, and functions.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isRecord } from \"effect/Predicate\"\n *\n * assert.strictEqual(isRecord({}), true)\n * assert.strictEqual(isRecord({ a: 1 }), true)\n *\n * assert.strictEqual(isRecord([]), false)\n * assert.strictEqual(isRecord(new Date()), false)\n * assert.strictEqual(isRecord(null), false)\n * assert.strictEqual(isRecord(() => null), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n * @see isObject\n */\nexport const isRecord = (input: unknown): input is { [x: string | symbol]: unknown } =>\n isRecordOrArray(input) && !Array.isArray(input)\n\n/**\n * A refinement that checks if a value is a readonly record (i.e., a plain object).\n * This check returns `false` for arrays, `null`, and functions.\n *\n * This is an alias for `isRecord`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isReadonlyRecord } from \"effect/Predicate\"\n *\n * assert.strictEqual(isReadonlyRecord({}), true)\n * assert.strictEqual(isReadonlyRecord({ a: 1 }), true)\n *\n * assert.strictEqual(isReadonlyRecord([]), false)\n * assert.strictEqual(isReadonlyRecord(null), 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 refinement that checks if a value is a `Promise`. It performs a duck-typing check\n * for `.then` and `.catch` methods.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isPromise } from \"effect/Predicate\"\n *\n * assert.strictEqual(isPromise(Promise.resolve(1)), true)\n * assert.strictEqual(isPromise(new Promise(() => {})), true)\n *\n * assert.strictEqual(isPromise({ then() {} }), false) // Missing .catch\n * assert.strictEqual(isPromise({}), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n * @see isPromiseLike\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 * A refinement that checks if a value is `PromiseLike`. It performs a duck-typing\n * check for a `.then` method.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { isPromiseLike } from \"effect/Predicate\"\n *\n * assert.strictEqual(isPromiseLike(Promise.resolve(1)), true)\n * assert.strictEqual(isPromiseLike({ then: () => {} }), true)\n *\n * assert.strictEqual(isPromiseLike({}), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n * @see isPromise\n */\nexport const isPromiseLike = (\n input: unknown\n): input is PromiseLike<unknown> => hasProperty(input, \"then\") && isFunction(input.then)\n\n/**\n * A refinement that checks if a value is a `RegExp`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * assert.strictEqual(Predicate.isRegExp(/a/), true)\n * assert.strictEqual(Predicate.isRegExp(new RegExp(\"a\")), true)\n *\n * assert.strictEqual(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 * Composes a `Refinement` with another `Refinement` or `Predicate`.\n *\n * This can be used to chain checks. The first refinement is applied, and if it\n * passes, the second check is applied to the same value, potentially refining\n * the type further.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n * import * as assert from \"node:assert\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const minLength = (n: number) => (s: string): boolean => s.length >= n\n *\n * // Create a refinement that checks for a string with a minimum length of 3\n * const isLongString = Predicate.compose(isString, minLength(3))\n *\n * let value: unknown = \"hello\"\n *\n * assert.strictEqual(isLongString(value), true)\n * if (isLongString(value)) {\n * // value is narrowed to string\n * assert.strictEqual(value.toUpperCase(), \"HELLO\")\n * }\n * assert.strictEqual(isLongString(\"hi\"), false)\n * ```\n *\n * @since 2.0.0\n */\nexport const compose: {\n /**\n * Composes a `Refinement` with another `Refinement` or `Predicate`.\n *\n * This can be used to chain checks. The first refinement is applied, and if it\n * passes, the second check is applied to the same value, potentially refining\n * the type further.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n * import * as assert from \"node:assert\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const minLength = (n: number) => (s: string): boolean => s.length >= n\n *\n * // Create a refinement that checks for a string with a minimum length of 3\n * const isLongString = Predicate.compose(isString, minLength(3))\n *\n * let value: unknown = \"hello\"\n *\n * assert.strictEqual(isLongString(value), true)\n * if (isLongString(value)) {\n * // value is narrowed to string\n * assert.strictEqual(value.toUpperCase(), \"HELLO\")\n * }\n * assert.strictEqual(isLongString(\"hi\"), false)\n * ```\n *\n * @since 2.0.0\n */\n <A, B extends A, C extends B, D extends C>(bc: Refinement<C, D>): (ab: Refinement<A, B>) => Refinement<A, D>\n /**\n * Composes a `Refinement` with another `Refinement` or `Predicate`.\n *\n * This can be used to chain checks. The first refinement is applied, and if it\n * passes, the second check is applied to the same value, potentially refining\n * the type further.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n * import * as assert from \"node:assert\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const minLength = (n: number) => (s: string): boolean => s.length >= n\n *\n * // Create a refinement that checks for a string with a minimum length of 3\n * const isLongString = Predicate.compose(isString, minLength(3))\n *\n * let value: unknown = \"hello\"\n *\n * assert.strictEqual(isLongString(value), true)\n * if (isLongString(value)) {\n * // value is narrowed to string\n * assert.strictEqual(value.toUpperCase(), \"HELLO\")\n * }\n * assert.strictEqual(isLongString(\"hi\"), false)\n * ```\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 * Composes a `Refinement` with another `Refinement` or `Predicate`.\n *\n * This can be used to chain checks. The first refinement is applied, and if it\n * passes, the second check is applied to the same value, potentially refining\n * the type further.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n * import * as assert from \"node:assert\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const minLength = (n: number) => (s: string): boolean => s.length >= n\n *\n * // Create a refinement that checks for a string with a minimum length of 3\n * const isLongString = Predicate.compose(isString, minLength(3))\n *\n * let value: unknown = \"hello\"\n *\n * assert.strictEqual(isLongString(value), true)\n * if (isLongString(value)) {\n * // value is narrowed to string\n * assert.strictEqual(value.toUpperCase(), \"HELLO\")\n * }\n * assert.strictEqual(isLongString(\"hi\"), false)\n * ```\n *\n * @since 2.0.0\n */\n <A, B extends A, C extends B, D extends C>(ab: Refinement<A, B>, bc: Refinement<C, D>): Refinement<A, D>\n /**\n * Composes a `Refinement` with another `Refinement` or `Predicate`.\n *\n * This can be used to chain checks. The first refinement is applied, and if it\n * passes, the second check is applied to the same value, potentially refining\n * the type further.\n *\n * @example\n * ```ts\n * import { Predicate } from \"effect\"\n * import * as assert from \"node:assert\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const minLength = (n: number) => (s: string): boolean => s.length >= n\n *\n * // Create a refinement that checks for a string with a minimum length of 3\n * const isLongString = Predicate.compose(isString, minLength(3))\n *\n * let value: unknown = \"hello\"\n *\n * assert.strictEqual(isLongString(value), true)\n * if (isLongString(value)) {\n * // value is narrowed to string\n * assert.strictEqual(value.toUpperCase(), \"HELLO\")\n * }\n * assert.strictEqual(isLongString(\"hi\"), false)\n * ```\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, D extends C>(ab: Refinement<A, B>, bc: Refinement<C, D>): Refinement<A, D> =>\n (a): a is D => ab(a) && bc(a as C)\n)\n\n/**\n * Combines two predicates to test a tuple of two values. The first predicate tests the\n * first element of the tuple, and the second predicate tests the second element.\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 * Takes an iterable of predicates and returns a new predicate that tests an array of values.\n * The new predicate returns `true` if each predicate at a given index is satisfied by the\n * value at the same index in the array. The check stops at the length of the shorter of\n * the two iterables (predicates or values).\n *\n * @category combining\n * @since 2.0.0\n * @see tuple for a more powerful, variadic version.\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 * Combines a predicate for a single value and an iterable of predicates for the rest of an array.\n * Useful for checking the head and tail of an array separately.\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 * Combines an array of predicates into a single predicate that tests an array of values.\n * This function is highly type-aware and will produce a `Refinement` if any of the provided\n * predicates are `Refinement`s, allowing for powerful type-narrowing of tuples.\n *\n * - If all predicates are `Predicate<T>`, the result is `Predicate<[T, T, ...]>`.\n * - If any predicate is a `Refinement<A, B>`, the result is a `Refinement` that narrows\n * the input tuple type to a more specific tuple type.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const isNumber = (u: unknown): u is number => typeof u === \"number\"\n *\n * // Create a refinement for a [string, number] tuple\n * const isStringNumberTuple = Predicate.tuple(isString, isNumber)\n *\n * const value: [unknown, unknown] = [\"hello\", 123]\n * if (isStringNumberTuple(value)) {\n * // value is narrowed to [string, number]\n * const [s, n] = value\n * assert.strictEqual(s.toUpperCase(), \"HELLO\")\n * assert.strictEqual(n.toFixed(2), \"123.00\")\n * }\n * assert.strictEqual(isStringNumberTuple([\"hello\", \"123\"]), false)\n * ```\n *\n * @since 2.0.0\n */\nexport const tuple: {\n /**\n * Combines an array of predicates into a single predicate that tests an array of values.\n * This function is highly type-aware and will produce a `Refinement` if any of the provided\n * predicates are `Refinement`s, allowing for powerful type-narrowing of tuples.\n *\n * - If all predicates are `Predicate<T>`, the result is `Predicate<[T, T, ...]>`.\n * - If any predicate is a `Refinement<A, B>`, the result is a `Refinement` that narrows\n * the input tuple type to a more specific tuple type.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const isNumber = (u: unknown): u is number => typeof u === \"number\"\n *\n * // Create a refinement for a [string, number] tuple\n * const isStringNumberTuple = Predicate.tuple(isString, isNumber)\n *\n * const value: [unknown, unknown] = [\"hello\", 123]\n * if (isStringNumberTuple(value)) {\n * // value is narrowed to [string, number]\n * const [s, n] = value\n * assert.strictEqual(s.toUpperCase(), \"HELLO\")\n * assert.strictEqual(n.toFixed(2), \"123.00\")\n * }\n * assert.strictEqual(isStringNumberTuple([\"hello\", \"123\"]), false)\n * ```\n *\n * @since 2.0.0\n */\n <T extends ReadonlyArray<Predicate.Any>>(...elements: T): [Extract<T[number], Refinement.Any>] extends [never] ? Predicate<{ readonly [I in keyof T]: Predicate.In<T[I]> }>\n : Refinement<\n { readonly [I in keyof T]: T[I] extends Refinement.Any ? Refinement.In<T[I]> : Predicate.In<T[I]> },\n { readonly [I in keyof T]: T[I] extends Refinement.Any ? Refinement.Out<T[I]> : Predicate.In<T[I]> }\n >\n} = (...elements: ReadonlyArray<Predicate.Any>) => all(elements) as any\n\n/**\n * Combines a record of predicates into a single predicate that tests a record of values.\n * This function is highly type-aware and will produce a `Refinement` if any of the provided\n * predicates are `Refinement`s, allowing for powerful type-narrowing of structs.\n *\n * - If all predicates are `Predicate<T>`, the result is `Predicate<{ k: T, ... }>`.\n * - If any predicate is a `Refinement<A, B>`, the result is a `Refinement` that narrows\n * the input record type to a more specific record type.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const isNumber = (u: unknown): u is number => typeof u === \"number\"\n *\n * const personPredicate = Predicate.struct({\n * name: isString,\n * age: isNumber\n * })\n *\n * const value: { name: unknown; age: unknown } = { name: \"Alice\", age: 30 }\n * if (personPredicate(value)) {\n * // value is narrowed to { name: string; age: number }\n * assert.strictEqual(value.name.toUpperCase(), \"ALICE\")\n * assert.strictEqual(value.age.toFixed(0), \"30\")\n * }\n * assert.strictEqual(personPredicate({ name: \"Bob\", age: \"40\" }), false)\n * ```\n *\n * @since 2.0.0\n */\nexport const struct: {\n /**\n * Combines a record of predicates into a single predicate that tests a record of values.\n * This function is highly type-aware and will produce a `Refinement` if any of the provided\n * predicates are `Refinement`s, allowing for powerful type-narrowing of structs.\n *\n * - If all predicates are `Predicate<T>`, the result is `Predicate<{ k: T, ... }>`.\n * - If any predicate is a `Refinement<A, B>`, the result is a `Refinement` that narrows\n * the input record type to a more specific record type.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const isNumber = (u: unknown): u is number => typeof u === \"number\"\n *\n * const personPredicate = Predicate.struct({\n * name: isString,\n * age: isNumber\n * })\n *\n * const value: { name: unknown; age: unknown } = { name: \"Alice\", age: 30 }\n * if (personPredicate(value)) {\n * // value is narrowed to { name: string; age: number }\n * assert.strictEqual(value.name.toUpperCase(), \"ALICE\")\n * assert.strictEqual(value.age.toFixed(0), \"30\")\n * }\n * assert.strictEqual(personPredicate({ name: \"Bob\", age: \"40\" }), false)\n * ```\n *\n * @since 2.0.0\n */\n <R extends Record<string, Predicate.Any>>(fields: R): [Extract<R[keyof R], Refinement.Any>] extends [never] ?\n Predicate<{ readonly [K in keyof R]: Predicate.In<R[K]> }> :\n Refinement<\n { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.In<R[K]> : Predicate.In<R[K]> },\n { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.Out<R[K]> : Predicate.In<R[K]> }\n >\n} = (<R extends Record<string, Predicate.Any>>(fields: R) => {\n const keys = Object.keys(fields)\n return (a: Record<string, unknown>) => {\n for (const key of keys) {\n if (!fields[key](a[key] as never)) {\n return false\n }\n }\n return true\n }\n}) as any\n\n/**\n * Returns a new predicate that is the logical negation of the given predicate.\n *\n * **Note**: If the input is a `Refinement`, the resulting predicate will be a\n * simple `Predicate`, as TypeScript cannot infer the negative type.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate, Number } from \"effect\"\n *\n * const isNonPositive = Predicate.not(Number.greaterThan(0))\n *\n * assert.strictEqual(isNonPositive(-1), true)\n * assert.strictEqual(isNonPositive(0), true)\n * assert.strictEqual(isNonPositive(1), false)\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 with a logical \"OR\". The resulting predicate returns `true`\n * if at least one of the predicates returns `true`.\n *\n * If both predicates are `Refinement`s, the resulting predicate is a `Refinement` to the\n * union of their target types (`B | C`).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const isNumber = (u: unknown): u is number => typeof u === \"number\"\n *\n * const isStringOrNumber = Predicate.or(isString, isNumber)\n *\n * assert.strictEqual(isStringOrNumber(\"hello\"), true)\n * assert.strictEqual(isStringOrNumber(123), true)\n * assert.strictEqual(isStringOrNumber(null), false)\n *\n * const value: unknown = \"world\"\n * if (isStringOrNumber(value)) {\n * // value is narrowed to string | number\n * console.log(value)\n * }\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const or: {\n /**\n * Combines two predicates with a logical \"OR\". The resulting predicate returns `true`\n * if at least one of the predicates returns `true`.\n *\n * If both predicates are `Refinement`s, the resulting predicate is a `Refinement` to the\n * union of their target types (`B | C`).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const isNumber = (u: unknown): u is number => typeof u === \"number\"\n *\n * const isStringOrNumber = Predicate.or(isString, isNumber)\n *\n * assert.strictEqual(isStringOrNumber(\"hello\"), true)\n * assert.strictEqual(isStringOrNumber(123), true)\n * assert.strictEqual(isStringOrNumber(null), false)\n *\n * const value: unknown = \"world\"\n * if (isStringOrNumber(value)) {\n * // value is narrowed to string | number\n * console.log(value)\n * }\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 with a logical \"OR\". The resulting predicate returns `true`\n * if at least one of the predicates returns `true`.\n *\n * If both predicates are `Refinement`s, the resulting predicate is a `Refinement` to the\n * union of their target types (`B | C`).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const isNumber = (u: unknown): u is number => typeof u === \"number\"\n *\n * const isStringOrNumber = Predicate.or(isString, isNumber)\n *\n * assert.strictEqual(isStringOrNumber(\"hello\"), true)\n * assert.strictEqual(isStringOrNumber(123), true)\n * assert.strictEqual(isStringOrNumber(null), false)\n *\n * const value: unknown = \"world\"\n * if (isStringOrNumber(value)) {\n * // value is narrowed to string | number\n * console.log(value)\n * }\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 with a logical \"OR\". The resulting predicate returns `true`\n * if at least one of the predicates returns `true`.\n *\n * If both predicates are `Refinement`s, the resulting predicate is a `Refinement` to the\n * union of their target types (`B | C`).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const isNumber = (u: unknown): u is number => typeof u === \"number\"\n *\n * const isStringOrNumber = Predicate.or(isString, isNumber)\n *\n * assert.strictEqual(isStringOrNumber(\"hello\"), true)\n * assert.strictEqual(isStringOrNumber(123), true)\n * assert.strictEqual(isStringOrNumber(null), false)\n *\n * const value: unknown = \"world\"\n * if (isStringOrNumber(value)) {\n * // value is narrowed to string | number\n * console.log(value)\n * }\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 with a logical \"OR\". The resulting predicate returns `true`\n * if at least one of the predicates returns `true`.\n *\n * If both predicates are `Refinement`s, the resulting predicate is a `Refinement` to the\n * union of their target types (`B | C`).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isString = (u: unknown): u is string => typeof u === \"string\"\n * const isNumber = (u: unknown): u is number => typeof u === \"number\"\n *\n * const isStringOrNumber = Predicate.or(isString, isNumber)\n *\n * assert.strictEqual(isStringOrNumber(\"hello\"), true)\n * assert.strictEqual(isStringOrNumber(123), true)\n * assert.strictEqual(isStringOrNumber(null), false)\n *\n * const value: unknown = \"world\"\n * if (isStringOrNumber(value)) {\n * // value is narrowed to string | number\n * console.log(value)\n * }\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 with a logical \"AND\". The resulting predicate returns `true`\n * only if both of the predicates return `true`.\n *\n * If both predicates are `Refinement`s, the resulting predicate is a `Refinement` to the\n * intersection of their target types (`B & C`).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * type Person = { name: string }\n * type Employee = { id: number }\n *\n * const hasName = (u: unknown): u is Person => Predicate.hasProperty(u, \"name\") && typeof (u as any).name === \"string\"\n * const hasId = (u: unknown): u is Employee => Predicate.hasProperty(u, \"id\") && typeof (u as any).id === \"number\"\n *\n * const isPersonAndEmployee = Predicate.and(hasName, hasId)\n *\n * const val: unknown = { name: \"Alice\", id: 123 }\n * if (isPersonAndEmployee(val)) {\n * // val is narrowed to Person & Employee\n * assert.strictEqual(val.name, \"Alice\")\n * assert.strictEqual(val.id, 123)\n * }\n *\n * assert.strictEqual(isPersonAndEmployee({ name: \"Bob\" }), false) // Missing id\n * assert.strictEqual(isPersonAndEmployee({ id: 456 }), false) // Missing name\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const and: {\n /**\n * Combines two predicates with a logical \"AND\". The resulting predicate returns `true`\n * only if both of the predicates return `true`.\n *\n * If both predicates are `Refinement`s, the resulting predicate is a `Refinement` to the\n * intersection of their target types (`B & C`).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * type Person = { name: string }\n * type Employee = { id: number }\n *\n * const hasName = (u: unknown): u is Person => Predicate.hasProperty(u, \"name\") && typeof (u as any).name === \"string\"\n * const hasId = (u: unknown): u is Employee => Predicate.hasProperty(u, \"id\") && typeof (u as any).id === \"number\"\n *\n * const isPersonAndEmployee = Predicate.and(hasName, hasId)\n *\n * const val: unknown = { name: \"Alice\", id: 123 }\n * if (isPersonAndEmployee(val)) {\n * // val is narrowed to Person & Employee\n * assert.strictEqual(val.name, \"Alice\")\n * assert.strictEqual(val.id, 123)\n * }\n *\n * assert.strictEqual(isPersonAndEmployee({ name: \"Bob\" }), false) // Missing id\n * assert.strictEqual(isPersonAndEmployee({ id: 456 }), false) // Missing name\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 with a logical \"AND\". The resulting predicate returns `true`\n * only if both of the predicates return `true`.\n *\n * If both predicates are `Refinement`s, the resulting predicate is a `Refinement` to the\n * intersection of their target types (`B & C`).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * type Person = { name: string }\n * type Employee = { id: number }\n *\n * const hasName = (u: unknown): u is Person => Predicate.hasProperty(u, \"name\") && typeof (u as any).name === \"string\"\n * const hasId = (u: unknown): u is Employee => Predicate.hasProperty(u, \"id\") && typeof (u as any).id === \"number\"\n *\n * const isPersonAndEmployee = Predicate.and(hasName, hasId)\n *\n * const val: unknown = { name: \"Alice\", id: 123 }\n * if (isPersonAndEmployee(val)) {\n * // val is narrowed to Person & Employee\n * assert.strictEqual(val.name, \"Alice\")\n * assert.strictEqual(val.id, 123)\n * }\n *\n * assert.strictEqual(isPersonAndEmployee({ name: \"Bob\" }), false) // Missing id\n * assert.strictEqual(isPersonAndEmployee({ id: 456 }), false) // Missing name\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 with a logical \"AND\". The resulting predicate returns `true`\n * only if both of the predicates return `true`.\n *\n * If both predicates are `Refinement`s, the resulting predicate is a `Refinement` to the\n * intersection of their target types (`B & C`).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * type Person = { name: string }\n * type Employee = { id: number }\n *\n * const hasName = (u: unknown): u is Person => Predicate.hasProperty(u, \"name\") && typeof (u as any).name === \"string\"\n * const hasId = (u: unknown): u is Employee => Predicate.hasProperty(u, \"id\") && typeof (u as any).id === \"number\"\n *\n * const isPersonAndEmployee = Predicate.and(hasName, hasId)\n *\n * const val: unknown = { name: \"Alice\", id: 123 }\n * if (isPersonAndEmployee(val)) {\n * // val is narrowed to Person & Employee\n * assert.strictEqual(val.name, \"Alice\")\n * assert.strictEqual(val.id, 123)\n * }\n *\n * assert.strictEqual(isPersonAndEmployee({ name: \"Bob\" }), false) // Missing id\n * assert.strictEqual(isPersonAndEmployee({ id: 456 }), false) // Missing name\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 with a logical \"AND\". The resulting predicate returns `true`\n * only if both of the predicates return `true`.\n *\n * If both predicates are `Refinement`s, the resulting predicate is a `Refinement` to the\n * intersection of their target types (`B & C`).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * type Person = { name: string }\n * type Employee = { id: number }\n *\n * const hasName = (u: unknown): u is Person => Predicate.hasProperty(u, \"name\") && typeof (u as any).name === \"string\"\n * const hasId = (u: unknown): u is Employee => Predicate.hasProperty(u, \"id\") && typeof (u as any).id === \"number\"\n *\n * const isPersonAndEmployee = Predicate.and(hasName, hasId)\n *\n * const val: unknown = { name: \"Alice\", id: 123 }\n * if (isPersonAndEmployee(val)) {\n * // val is narrowed to Person & Employee\n * assert.strictEqual(val.name, \"Alice\")\n * assert.strictEqual(val.id, 123)\n * }\n *\n * assert.strictEqual(isPersonAndEmployee({ name: \"Bob\" }), false) // Missing id\n * assert.strictEqual(isPersonAndEmployee({ id: 456 }), false) // Missing name\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 with a logical \"XOR\" (exclusive OR). The resulting predicate\n * returns `true` if one of the predicates returns `true`, but not both.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isPositive = (n: number) => n > 0\n * const isEven = (n: number) => n % 2 === 0\n *\n * const isPositiveXorEven = Predicate.xor(isPositive, isEven)\n *\n * assert.strictEqual(isPositiveXorEven(4), false) // both true -> false\n * assert.strictEqual(isPositiveXorEven(3), true) // one true -> true\n * assert.strictEqual(isPositiveXorEven(-2), true) // one true -> true\n * assert.strictEqual(isPositiveXorEven(-1), false) // both false -> false\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const xor: {\n /**\n * Combines two predicates with a logical \"XOR\" (exclusive OR). The resulting predicate\n * returns `true` if one of the predicates returns `true`, but not both.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isPositive = (n: number) => n > 0\n * const isEven = (n: number) => n % 2 === 0\n *\n * const isPositiveXorEven = Predicate.xor(isPositive, isEven)\n *\n * assert.strictEqual(isPositiveXorEven(4), false) // both true -> false\n * assert.strictEqual(isPositiveXorEven(3), true) // one true -> true\n * assert.strictEqual(isPositiveXorEven(-2), true) // one true -> true\n * assert.strictEqual(isPositiveXorEven(-1), false) // both false -> 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 with a logical \"XOR\" (exclusive OR). The resulting predicate\n * returns `true` if one of the predicates returns `true`, but not both.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isPositive = (n: number) => n > 0\n * const isEven = (n: number) => n % 2 === 0\n *\n * const isPositiveXorEven = Predicate.xor(isPositive, isEven)\n *\n * assert.strictEqual(isPositiveXorEven(4), false) // both true -> false\n * assert.strictEqual(isPositiveXorEven(3), true) // one true -> true\n * assert.strictEqual(isPositiveXorEven(-2), true) // one true -> true\n * assert.strictEqual(isPositiveXorEven(-1), false) // both false -> 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 * Combines two predicates with a logical \"EQV\" (equivalence). The resulting predicate\n * returns `true` if both predicates return the same boolean value (both `true` or both `false`).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isPositive = (n: number) => n > 0\n * const isEven = (n: number) => n % 2 === 0\n *\n * const isPositiveEqvEven = Predicate.eqv(isPositive, isEven)\n *\n * assert.strictEqual(isPositiveEqvEven(4), true) // both true -> true\n * assert.strictEqual(isPositiveEqvEven(3), false) // different -> false\n * assert.strictEqual(isPositiveEqvEven(-2), false) // different -> false\n * assert.strictEqual(isPositiveEqvEven(-1), true) // both false -> true\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const eqv: {\n /**\n * Combines two predicates with a logical \"EQV\" (equivalence). The resulting predicate\n * returns `true` if both predicates return the same boolean value (both `true` or both `false`).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isPositive = (n: number) => n > 0\n * const isEven = (n: number) => n % 2 === 0\n *\n * const isPositiveEqvEven = Predicate.eqv(isPositive, isEven)\n *\n * assert.strictEqual(isPositiveEqvEven(4), true) // both true -> true\n * assert.strictEqual(isPositiveEqvEven(3), false) // different -> false\n * assert.strictEqual(isPositiveEqvEven(-2), false) // different -> false\n * assert.strictEqual(isPositiveEqvEven(-1), true) // both false -> 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 with a logical \"EQV\" (equivalence). The resulting predicate\n * returns `true` if both predicates return the same boolean value (both `true` or both `false`).\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isPositive = (n: number) => n > 0\n * const isEven = (n: number) => n % 2 === 0\n *\n * const isPositiveEqvEven = Predicate.eqv(isPositive, isEven)\n *\n * assert.strictEqual(isPositiveEqvEven(4), true) // both true -> true\n * assert.strictEqual(isPositiveEqvEven(3), false) // different -> false\n * assert.strictEqual(isPositiveEqvEven(-2), false) // different -> false\n * assert.strictEqual(isPositiveEqvEven(-1), true) // both false -> 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 * Creates a predicate that represents a logical \"if-then\" rule.\n *\n * Think of it as a conditional promise: **\"If `antecedent` holds true, then I promise `consequent` will also be true.\"**\n *\n * This function is invaluable for defining complex validation logic where one condition dictates another.\n *\n * ### How It Works\n *\n * The rule only fails (returns `false`) when the \"if\" part is `true`, but the \"then\" part is `false`.\n * In all other cases, the promise is considered kept, and the result is `true`.\n *\n * This includes the concept of **\"vacuous truth\"**: if the \"if\" part is `false`, the rule doesn't apply,\n * so the promise isn't broken, and the result is `true`. (e.g., \"If it rains, I'll bring an umbrella.\"\n * If it doesn't rain, you haven't broken your promise, no matter what).\n *\n * ### Key Details\n *\n * - **Logical Equivalence**: `implies(p, q)` is the same as `not(p).or(q)`, or simply `!p || q`\n * in plain JavaScript. This can be a helpful way to reason about its behavior.\n *\n * - **Type-Safety Warning**: This function always returns a `Predicate`, never a type-narrowing\n * `Refinement`. A `true` result doesn't guarantee the `consequent` passed (it could be `true`\n * simply because the `antecedent` was `false`), so it cannot be used to safely narrow a type.\n *\n * @example\n * ```ts\n * // Rule: A user can only be an admin if they also belong to the \"staff\" group.\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * type User = {\n * isStaff: boolean\n * isAdmin: boolean\n * }\n *\n * const isValidUserPermission = Predicate.implies(\n * // antecedent: \"if\" the user is an admin...\n * (user: User) => user.isAdmin,\n * // consequent: \"then\" they must be staff.\n * (user: User) => user.isStaff\n * )\n *\n * // A non-admin who is not staff. Rule doesn't apply (antecedent is false).\n * assert.strictEqual(isValidUserPermission({ isStaff: false, isAdmin: false }), true)\n *\n * // A staff member who is not an admin. Rule doesn't apply (antecedent is false).\n * assert.strictEqual(isValidUserPermission({ isStaff: true, isAdmin: false }), true)\n *\n * // An admin who is also staff. The rule was followed.\n * assert.strictEqual(isValidUserPermission({ isStaff: true, isAdmin: true }), true)\n *\n * // An admin who is NOT staff. The rule was broken!\n * assert.strictEqual(isValidUserPermission({ isStaff: false, isAdmin: true }), false)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const implies: {\n /**\n * Creates a predicate that represents a logical \"if-then\" rule.\n *\n * Think of it as a conditional promise: **\"If `antecedent` holds true, then I promise `consequent` will also be true.\"**\n *\n * This function is invaluable for defining complex validation logic where one condition dictates another.\n *\n * ### How It Works\n *\n * The rule only fails (returns `false`) when the \"if\" part is `true`, but the \"then\" part is `false`.\n * In all other cases, the promise is considered kept, and the result is `true`.\n *\n * This includes the concept of **\"vacuous truth\"**: if the \"if\" part is `false`, the rule doesn't apply,\n * so the promise isn't broken, and the result is `true`. (e.g., \"If it rains, I'll bring an umbrella.\"\n * If it doesn't rain, you haven't broken your promise, no matter what).\n *\n * ### Key Details\n *\n * - **Logical Equivalence**: `implies(p, q)` is the same as `not(p).or(q)`, or simply `!p || q`\n * in plain JavaScript. This can be a helpful way to reason about its behavior.\n *\n * - **Type-Safety Warning**: This function always returns a `Predicate`, never a type-narrowing\n * `Refinement`. A `true` result doesn't guarantee the `consequent` passed (it could be `true`\n * simply because the `antecedent` was `false`), so it cannot be used to safely narrow a type.\n *\n * @example\n * ```ts\n * // Rule: A user can only be an admin if they also belong to the \"staff\" group.\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * type User = {\n * isStaff: boolean\n * isAdmin: boolean\n * }\n *\n * const isValidUserPermission = Predicate.implies(\n * // antecedent: \"if\" the user is an admin...\n * (user: User) => user.isAdmin,\n * // consequent: \"then\" they must be staff.\n * (user: User) => user.isStaff\n * )\n *\n * // A non-admin who is not staff. Rule doesn't apply (antecedent is false).\n * assert.strictEqual(isValidUserPermission({ isStaff: false, isAdmin: false }), true)\n *\n * // A staff member who is not an admin. Rule doesn't apply (antecedent is false).\n * assert.strictEqual(isValidUserPermission({ isStaff: true, isAdmin: false }), true)\n *\n * // An admin who is also staff. The rule was followed.\n * assert.strictEqual(isValidUserPermission({ isStaff: true, isAdmin: true }), true)\n *\n * // An admin who is NOT staff. The rule was broken!\n * assert.strictEqual(isValidUserPermission({ isStaff: false, isAdmin: true }), false)\n * ```\n *\n * @category combinators\n * @since 2.0.0\n */\n <A>(consequent: Predicate<A>): (antecedent: Predicate<A>) => Predicate<A>\n /**\n * Creates a predicate that represents a logical \"if-then\" rule.\n *\n * Think of it as a conditional promise: **\"If `antecedent` holds true, then I promise `consequent` will also be true.\"**\n *\n * This function is invaluable for defining complex validation logic where one condition dictates another.\n *\n * ### How It Works\n *\n * The rule only fails (returns `false`) when the \"if\" part is `true`, but the \"then\" part is `false`.\n * In all other cases, the promise is considered kept, and the result is `true`.\n *\n * This includes the concept of **\"vacuous truth\"**: if the \"if\" part is `false`, the rule doesn't apply,\n * so the promise isn't broken, and the result is `true`. (e.g., \"If it rains, I'll bring an umbrella.\"\n * If it doesn't rain, you haven't broken your promise, no matter what).\n *\n * ### Key Details\n *\n * - **Logical Equivalence**: `implies(p, q)` is the same as `not(p).or(q)`, or simply `!p || q`\n * in plain JavaScript. This can be a helpful way to reason about its behavior.\n *\n * - **Type-Safety Warning**: This function always returns a `Predicate`, never a type-narrowing\n * `Refinement`. A `true` result doesn't guarantee the `consequent` passed (it could be `true`\n * simply because the `antecedent` was `false`), so it cannot be used to safely narrow a type.\n *\n * @example\n * ```ts\n * // Rule: A user can only be an admin if they also belong to the \"staff\" group.\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * type User = {\n * isStaff: boolean\n * isAdmin: boolean\n * }\n *\n * const isValidUserPermission = Predicate.implies(\n * // antecedent: \"if\" the user is an admin...\n * (user: User) => user.isAdmin,\n * // consequent: \"then\" they must be staff.\n * (user: User) => user.isStaff\n * )\n *\n * // A non-admin who is not staff. Rule doesn't apply (antecedent is false).\n * assert.strictEqual(isValidUserPermission({ isStaff: false, isAdmin: false }), true)\n *\n * // A staff member who is not an admin. Rule doesn't apply (antecedent is false).\n * assert.strictEqual(isValidUserPermission({ isStaff: true, isAdmin: false }), true)\n *\n * // An admin who is also staff. The rule was followed.\n * assert.strictEqual(isValidUserPermission({ isStaff: true, isAdmin: true }), true)\n *\n * // An admin who is NOT staff. The rule was broken!\n * assert.strictEqual(isValidUserPermission({ isStaff: false, isAdmin: true }), false)\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 * Combines two predicates with a logical \"NOR\" (negated OR). The resulting predicate\n * returns `true` only if both predicates return `false`.\n * This is equivalent to `not(or(p, q))`.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const nor: {\n /**\n * Combines two predicates with a logical \"NOR\" (negated OR). The resulting predicate\n * returns `true` only if both predicates return `false`.\n * This is equivalent to `not(or(p, q))`.\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 with a logical \"NOR\" (negated OR). The resulting predicate\n * returns `true` only if both predicates return `false`.\n * This is equivalent to `not(or(p, q))`.\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 * Combines two predicates with a logical \"NAND\" (negated AND). The resulting predicate\n * returns `true` if at least one of the predicates returns `false`.\n * This is equivalent to `not(and(p, q))`.\n *\n * @category combinators\n * @since 2.0.0\n */\nexport const nand: {\n /**\n * Combines two predicates with a logical \"NAND\" (negated AND). The resulting predicate\n * returns `true` if at least one of the predicates returns `false`.\n * This is equivalent to `not(and(p, q))`.\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 with a logical \"NAND\" (negated AND). The resulting predicate\n * returns `true` if at least one of the predicates returns `false`.\n * This is equivalent to `not(and(p, q))`.\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 * Takes an iterable of predicates and returns a new predicate. The new predicate\n * returns `true` if all predicates in the collection return `true` for a given value.\n *\n * This is like `Array.prototype.every` but for a collection of predicates.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isPositive = (n: number) => n > 0\n * const isEven = (n: number) => n % 2 === 0\n *\n * const isPositiveAndEven = Predicate.every([isPositive, isEven])\n *\n * assert.strictEqual(isPositiveAndEven(4), true)\n * assert.strictEqual(isPositiveAndEven(3), false)\n * assert.strictEqual(isPositiveAndEven(-2), false)\n * ```\n *\n * @category elements\n * @since 2.0.0\n * @see some\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 * Takes an iterable of predicates and returns a new predicate. The new predicate\n * returns `true` if at least one predicate in the collection returns `true` for a given value.\n *\n * This is like `Array.prototype.some` but for a collection of predicates.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Predicate } from \"effect\"\n *\n * const isNegative = (n: number) => n < 0\n * const isOdd = (n: number) => n % 2 !== 0\n *\n * const isNegativeOrOdd = Predicate.some([isNegative, isOdd])\n *\n * assert.strictEqual(isNegativeOrOdd(-2), true) // isNegative is true\n * assert.strictEqual(isNegativeOrOdd(3), true) // isOdd is true\n * assert.strictEqual(isNegativeOrOdd(4), false) // both are false\n * ```\n *\n * @category elements\n * @since 2.0.0\n * @see every\n */\nexport const some = <A>(collection: Iterable<Predicate<A>>): Predicate<A> => (a) => {\n for (const p of collection) {\n if (p(a)) {\n return true\n }\n }\n return false\n}\n","/**\n * @since 2.0.0\n */\n\n/** @internal */\nexport const getBugErrorMessage = (message: string) =>\n `BUG: ${message} - please report an issue at https://github.com/Effect-TS/effect/issues`\n","/**\n * @since 2.0.0\n */\nimport { identity } from \"./Function.js\"\nimport { globalValue } from \"./GlobalValue.js\"\nimport type { Kind, TypeLambda } from \"./HKT.js\"\nimport { getBugErrorMessage } from \"./internal/errors.js\"\nimport { isNullable, isObject } from \"./Predicate.js\"\nimport type * as Types from \"./Types.js\"\n\n/*\n * Copyright 2014 Thom Chiovoloni, released under the MIT license.\n *\n * A random number generator based on the basic implementation of the PCG algorithm,\n * as described here: http://www.pcg-random.org/\n *\n * Adapted for TypeScript from Thom's original code at https://github.com/thomcc/pcg-random\n *\n * forked from https://github.com/frptools\n *\n * @since 2.0.0\n */\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport const GenKindTypeId: unique symbol = Symbol.for(\"effect/Gen/GenKind\")\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport type GenKindTypeId = typeof GenKindTypeId\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface GenKind<F extends TypeLambda, R, O, E, A> extends Variance<F, R, O, E> {\n readonly value: Kind<F, R, O, E, A>\n\n [Symbol.iterator](): IterableIterator<GenKind<F, R, O, E, A>, A>\n}\n\n/**\n * @category predicates\n * @since 3.0.6\n */\nexport const isGenKind = (u: unknown): u is GenKind<any, any, any, any, any> => isObject(u) && GenKindTypeId in u\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport class GenKindImpl<F extends TypeLambda, R, O, E, A> implements GenKind<F, R, O, E, A> {\n constructor(\n /**\n * @since 2.0.0\n */\n readonly value: Kind<F, R, O, E, A>\n ) {}\n\n /**\n * @since 2.0.0\n */\n get _F() {\n return identity\n }\n\n /**\n * @since 2.0.0\n */\n get _R() {\n return (_: R) => _\n }\n\n /**\n * @since 2.0.0\n */\n get _O() {\n return (_: never): O => _\n }\n\n /**\n * @since 2.0.0\n */\n get _E() {\n return (_: never): E => _\n }\n\n /**\n * @since 2.0.0\n */\n readonly [GenKindTypeId]: typeof GenKindTypeId = GenKindTypeId;\n\n /**\n * @since 2.0.0\n */\n [Symbol.iterator](): IterableIterator<GenKind<F, R, O, E, A>, A> {\n return new SingleShotGen<GenKind<F, R, O, E, A>, A>(this as any)\n }\n}\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport class SingleShotGen<T, A> implements IterableIterator<T, A> {\n private called = false\n\n constructor(readonly self: T) {}\n\n /**\n * @since 2.0.0\n */\n next(a: A): IteratorResult<T, A> {\n return this.called ?\n ({\n value: a,\n done: true\n }) :\n (this.called = true,\n ({\n value: this.self,\n done: false\n }))\n }\n\n /**\n * @since 2.0.0\n */\n return(a: A): IteratorResult<T, A> {\n return ({\n value: a,\n done: true\n })\n }\n\n /**\n * @since 2.0.0\n */\n throw(e: unknown): IteratorResult<T, A> {\n throw e\n }\n\n /**\n * @since 2.0.0\n */\n [Symbol.iterator](): IterableIterator<T, A> {\n return new SingleShotGen<T, A>(this.self)\n }\n}\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const makeGenKind = <F extends TypeLambda, R, O, E, A>(\n kind: Kind<F, R, O, E, A>\n): GenKind<F, R, O, E, A> => new GenKindImpl(kind)\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Variance<in out F extends TypeLambda, in R, out O, out E> {\n readonly [GenKindTypeId]: GenKindTypeId\n readonly _F: Types.Invariant<F>\n readonly _R: Types.Contravariant<R>\n readonly _O: Types.Covariant<O>\n readonly _E: Types.Covariant<E>\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Gen<F extends TypeLambda, Z> {\n <Self, K extends Variance<F, any, any, any> | YieldWrap<Kind<F, any, any, any, any>>, A>(\n ...args:\n | [\n self: Self,\n body: (this: Self, resume: Z) => Generator<K, A, never>\n ]\n | [\n body: (resume: Z) => Generator<K, A, never>\n ]\n ): Kind<\n F,\n [K] extends [Variance<F, infer R, any, any>] ? R\n : [K] extends [YieldWrap<Kind<F, infer R, any, any, any>>] ? R\n : never,\n [K] extends [Variance<F, any, infer O, any>] ? O\n : [K] extends [YieldWrap<Kind<F, any, infer O, any, any>>] ? O\n : never,\n [K] extends [Variance<F, any, any, infer E>] ? E\n : [K] extends [YieldWrap<Kind<F, any, any, infer E, any>>] ? E\n : never,\n A\n >\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Adapter<Z extends TypeLambda> {\n <_R, _O, _E, _A>(\n self: Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, _R, _O, _E, _A>(a: A, ab: (a: A) => Kind<Z, _R, _O, _E, _A>): GenKind<Z, _R, _O, _E, _A>\n <A, B, _R, _O, _E, _A>(a: A, ab: (a: A) => B, bc: (b: B) => Kind<Z, _R, _O, _E, _A>): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: F) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (g: H) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => S,\n st: (s: S) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, _R, _O, _E, _A>(\n a: A,\n ab: (a: A) => B,\n bc: (b: B) => C,\n cd: (c: C) => D,\n de: (d: D) => E,\n ef: (e: E) => F,\n fg: (f: F) => G,\n gh: (g: G) => H,\n hi: (h: H) => I,\n ij: (i: I) => J,\n jk: (j: J) => K,\n kl: (k: K) => L,\n lm: (l: L) => M,\n mn: (m: M) => N,\n no: (n: N) => O,\n op: (o: O) => P,\n pq: (p: P) => Q,\n qr: (q: Q) => R,\n rs: (r: R) => S,\n st: (s: S) => T,\n tu: (s: T) => Kind<Z, _R, _O, _E, _A>\n ): GenKind<Z, _R, _O, _E, _A>\n}\n\n/**\n * @category adapters\n * @since 2.0.0\n */\nexport const adapter: <F extends TypeLambda>() => Adapter<F> = () => (function() {\n let x = arguments[0]\n for (let i = 1; i < arguments.length; i++) {\n x = arguments[i](x)\n }\n return new GenKindImpl(x) as any\n})\n\nconst defaultIncHi = 0x14057b7e\nconst defaultIncLo = 0xf767814f\nconst MUL_HI = 0x5851f42d >>> 0\nconst MUL_LO = 0x4c957f2d >>> 0\nconst BIT_53 = 9007199254740992.0\nconst BIT_27 = 134217728.0\n\n/**\n * @category model\n * @since 2.0.0\n */\nexport type PCGRandomState = [number, number, number, number]\n\n/**\n * @category model\n * @since 2.0.0\n */\nexport type OptionalNumber = number | null | undefined\n\n/**\n * PCG is a family of simple fast space-efficient statistically good algorithms\n * for random number generation. Unlike many general-purpose RNGs, they are also\n * hard to predict.\n *\n * @category model\n * @since 2.0.0\n */\nexport class PCGRandom {\n private _state!: Int32Array\n\n /**\n * Creates an instance of PCGRandom.\n *\n * - `seed` - The low 32 bits of the seed (0 is used for high 32 bits).\n *\n * @memberOf PCGRandom\n */\n constructor(seed?: OptionalNumber)\n /**\n * Creates an instance of PCGRandom.\n *\n * - `seedHi` - The high 32 bits of the seed.\n * - `seedLo` - The low 32 bits of the seed.\n * - `inc` - The low 32 bits of the incrementer (0 is used for high 32 bits).\n *\n * @memberOf PCGRandom\n */\n constructor(seedHi: OptionalNumber, seedLo: OptionalNumber, inc?: OptionalNumber)\n /**\n * Creates an instance of PCGRandom.\n *\n * - `seedHi` - The high 32 bits of the seed.\n * - `seedLo` - The low 32 bits of the seed.\n * - `incHi` - The high 32 bits of the incrementer.\n * - `incLo` - The low 32 bits of the incrementer.\n *\n * @memberOf PCGRandom\n */\n constructor(\n seedHi: OptionalNumber,\n seedLo: OptionalNumber,\n incHi: OptionalNumber,\n incLo: OptionalNumber\n )\n constructor(\n seedHi?: OptionalNumber,\n seedLo?: OptionalNumber,\n incHi?: OptionalNumber,\n incLo?: OptionalNumber\n ) {\n if (isNullable(seedLo) && isNullable(seedHi)) {\n seedLo = (Math.random() * 0xffffffff) >>> 0\n seedHi = 0\n } else if (isNullable(seedLo)) {\n seedLo = seedHi\n seedHi = 0\n }\n if (isNullable(incLo) && isNullable(incHi)) {\n incLo = this._state ? this._state[3] : defaultIncLo\n incHi = this._state ? this._state[2] : defaultIncHi\n } else if (isNullable(incLo)) {\n incLo = <number> incHi\n incHi = 0\n }\n\n this._state = new Int32Array([0, 0, (<number> incHi) >>> 0, ((incLo || 0) | 1) >>> 0])\n this._next()\n add64(\n this._state,\n this._state[0]!,\n this._state[1]!,\n (<number> seedHi) >>> 0,\n (<number> seedLo) >>> 0\n )\n this._next()\n return this\n }\n\n /**\n * Returns a copy of the internal state of this random number generator as a\n * JavaScript Array.\n *\n * @category getters\n * @since 2.0.0\n */\n getState(): PCGRandomState {\n return [this._state[0]!, this._state[1]!, this._state[2]!, this._state[3]!]\n }\n\n /**\n * Restore state previously retrieved using `getState()`.\n *\n * @since 2.0.0\n */\n setState(state: PCGRandomState) {\n this._state[0] = state[0]\n this._state[1] = state[1]\n this._state[2] = state[2]\n this._state[3] = state[3] | 1\n }\n\n /**\n * Get a uniformly distributed 32 bit integer between [0, max).\n *\n * @category getter\n * @since 2.0.0\n */\n integer(max: number) {\n return Math.round(this.number() * Number.MAX_SAFE_INTEGER) % max\n }\n\n /**\n * Get a uniformly distributed IEEE-754 double between 0.0 and 1.0, with\n * 53 bits of precision (every bit of the mantissa is randomized).\n *\n * @category getters\n * @since 2.0.0\n */\n number() {\n const hi = (this._next() & 0x03ffffff) * 1.0\n const lo = (this._next() & 0x07ffffff) * 1.0\n return (hi * BIT_27 + lo) / BIT_53\n }\n\n /** @internal */\n private _next() {\n // save current state (what we'll use for this number)\n const oldHi = this._state[0]! >>> 0\n const oldLo = this._state[1]! >>> 0\n\n // churn LCG.\n mul64(this._state, oldHi, oldLo, MUL_HI, MUL_LO)\n add64(this._state, this._state[0]!, this._state[1]!, this._state[2]!, this._state[3]!)\n\n // get least sig. 32 bits of ((oldstate >> 18) ^ oldstate) >> 27\n let xsHi = oldHi >>> 18\n let xsLo = ((oldLo >>> 18) | (oldHi << 14)) >>> 0\n xsHi = (xsHi ^ oldHi) >>> 0\n xsLo = (xsLo ^ oldLo) >>> 0\n const xorshifted = ((xsLo >>> 27) | (xsHi << 5)) >>> 0\n // rotate xorshifted right a random amount, based on the most sig. 5 bits\n // bits of the old state.\n const rot = oldHi >>> 27\n const rot2 = ((-rot >>> 0) & 31) >>> 0\n return ((xorshifted >>> rot) | (xorshifted << rot2)) >>> 0\n }\n}\n\nfunction mul64(\n out: Int32Array,\n aHi: number,\n aLo: number,\n bHi: number,\n bLo: number\n): void {\n let c1 = ((aLo >>> 16) * (bLo & 0xffff)) >>> 0\n let c0 = ((aLo & 0xffff) * (bLo >>> 16)) >>> 0\n\n let lo = ((aLo & 0xffff) * (bLo & 0xffff)) >>> 0\n let hi = ((aLo >>> 16) * (bLo >>> 16) + ((c0 >>> 16) + (c1 >>> 16))) >>> 0\n\n c0 = (c0 << 16) >>> 0\n lo = (lo + c0) >>> 0\n if ((lo >>> 0) < (c0 >>> 0)) {\n hi = (hi + 1) >>> 0\n }\n\n c1 = (c1 << 16) >>> 0\n lo = (lo + c1) >>> 0\n if ((lo >>> 0) < (c1 >>> 0)) {\n hi = (hi + 1) >>> 0\n }\n\n hi = (hi + Math.imul(aLo, bHi)) >>> 0\n hi = (hi + Math.imul(aHi, bLo)) >>> 0\n\n out[0] = hi\n out[1] = lo\n}\n\n// add two 64 bit numbers (given in parts), and store the result in `out`.\nfunction add64(\n out: Int32Array,\n aHi: number,\n aLo: number,\n bHi: number,\n bLo: number\n): void {\n let hi = (aHi + bHi) >>> 0\n const lo = (aLo + bLo) >>> 0\n if ((lo >>> 0) < (aLo >>> 0)) {\n hi = (hi + 1) | 0\n }\n out[0] = hi\n out[1] = lo\n}\n\n/**\n * @since 3.0.6\n */\nexport const YieldWrapTypeId: unique symbol = Symbol.for(\"effect/Utils/YieldWrap\")\n\n/**\n * @since 3.0.6\n */\nexport class YieldWrap<T> {\n /**\n * @since 3.0.6\n */\n readonly #value: T\n constructor(value: T) {\n this.#value = value\n }\n /**\n * @since 3.0.6\n */\n [YieldWrapTypeId](): T {\n return this.#value\n }\n}\n\n/**\n * @since 3.0.6\n */\nexport function yieldWrapGet<T>(self: YieldWrap<T>): T {\n if (typeof self === \"object\" && self !== null && YieldWrapTypeId in self) {\n return self[YieldWrapTypeId]()\n }\n throw new Error(getBugErrorMessage(\"yieldWrapGet\"))\n}\n\n/**\n * Note: this is an experimental feature made available to allow custom matchers in tests, not to be directly used yet in user code\n *\n * @since 3.1.1\n * @status experimental\n * @category modifiers\n */\nexport const structuralRegionState = globalValue(\n \"effect/Utils/isStructuralRegion\",\n (): { enabled: boolean; tester: ((a: unknown, b: unknown) => boolean) | undefined } => ({\n enabled: false,\n tester: undefined\n })\n)\n\n/**\n * Note: this is an experimental feature made available to allow custom matchers in tests, not to be directly used yet in user code\n *\n * @since 3.1.1\n * @status experimental\n * @category modifiers\n */\nexport const structuralRegion = <A>(body: () => A, tester?: (a: unknown, b: unknown) => boolean): A => {\n const current = structuralRegionState.enabled\n const currentTester = structuralRegionState.tester\n structuralRegionState.enabled = true\n if (tester) {\n structuralRegionState.tester = tester\n }\n try {\n return body()\n } finally {\n structuralRegionState.enabled = current\n structuralRegionState.tester = currentTester\n }\n}\n\nconst standard = {\n effect_internal_function: <A>(body: () => A) => {\n return body()\n }\n}\n\nconst forced = {\n effect_internal_function: <A>(body: () => A) => {\n try {\n return body()\n } finally {\n //\n }\n }\n}\n\nconst isNotOptimizedAway =\n standard.effect_internal_function(() => new Error().stack)?.includes(\"effect_internal_function\") === true\n\n/**\n * @since 3.2.2\n * @status experimental\n * @category tracing\n */\nexport const internalCall = isNotOptimizedAway ? standard.effect_internal_function : forced.effect_internal_function\n\nconst genConstructor = (function*() {}).constructor\n\n/**\n * @since 3.11.0\n */\nexport const isGeneratorFunction = (u: unknown): u is (...args: Array<any>) => Generator<any, any, any> =>\n isObject(u) && u.constructor === genConstructor\n","/**\n * @since 2.0.0\n */\nimport { pipe } from \"./Function.js\"\nimport { globalValue } from \"./GlobalValue.js\"\nimport { hasProperty } from \"./Predicate.js\"\nimport { structuralRegionState } from \"./Utils.js\"\n\n/** @internal */\nconst randomHashCache = globalValue(\n Symbol.for(\"effect/Hash/randomHashCache\"),\n () => new WeakMap<object, number>()\n)\n\n/**\n * @since 2.0.0\n * @category symbols\n */\nexport const symbol: unique symbol = Symbol.for(\"effect/Hash\")\n\n/**\n * @since 2.0.0\n * @category models\n */\nexport interface Hash {\n [symbol](): number\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const hash: <A>(self: A) => number = <A>(self: A) => {\n if (structuralRegionState.enabled === true) {\n return 0\n }\n\n switch (typeof self) {\n case \"number\":\n return number(self)\n case \"bigint\":\n return string(self.toString(10))\n case \"boolean\":\n return string(String(self))\n case \"symbol\":\n return string(String(self))\n case \"string\":\n return string(self)\n case \"undefined\":\n return string(\"undefined\")\n case \"function\":\n case \"object\": {\n if (self === null) {\n return string(\"null\")\n } else if (self instanceof Date) {\n return hash(self.toISOString())\n } else if (self instanceof URL) {\n return hash(self.href)\n } else if (isHash(self)) {\n return self[symbol]()\n } else {\n return random(self)\n }\n }\n default:\n throw new Error(\n `BUG: unhandled typeof ${typeof self} - please report an issue at https://github.com/Effect-TS/effect/issues`\n )\n }\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const random: <A extends object>(self: A) => number = (self) => {\n if (!randomHashCache.has(self)) {\n randomHashCache.set(self, number(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)))\n }\n return randomHashCache.get(self)!\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const combine: (b: number) => (self: number) => number = (b) => (self) => (self * 53) ^ b\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const optimize = (n: number): number => (n & 0xbfffffff) | ((n >>> 1) & 0x40000000)\n\n/**\n * @since 2.0.0\n * @category guards\n */\nexport const isHash = (u: unknown): u is Hash => hasProperty(u, symbol)\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const number = (n: number) => {\n if (n !== n || n === Infinity) {\n return 0\n }\n let h = n | 0\n if (h !== n) {\n h ^= n * 0xffffffff\n }\n while (n > 0xffffffff) {\n h ^= n /= 0xffffffff\n }\n return optimize(h)\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const string = (str: string) => {\n let h = 5381, i = str.length\n while (i) {\n h = (h * 33) ^ str.charCodeAt(--i)\n }\n return optimize(h)\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const structureKeys = <A extends object>(o: A, keys: ReadonlyArray<keyof A>) => {\n let h = 12289\n for (let i = 0; i < keys.length; i++) {\n h ^= pipe(string(keys[i]! as string), combine(hash((o as any)[keys[i]!])))\n }\n return optimize(h)\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const structure = <A extends object>(o: A) =>\n structureKeys(o, Object.keys(o) as unknown as ReadonlyArray<keyof A>)\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const array = <A>(arr: ReadonlyArray<A>) => {\n let h = 6151\n for (let i = 0; i < arr.length; i++) {\n h = pipe(h, combine(hash(arr[i])))\n }\n return optimize(h)\n}\n\n/**\n * @since 2.0.0\n * @category hashing\n */\nexport const cached: {\n /**\n * @since 2.0.0\n * @category hashing\n */\n (self: object): (hash: number) => number\n /**\n * @since 2.0.0\n * @category hashing\n */\n (self: object, hash: number): number\n} = function() {\n if (arguments.length === 1) {\n const self = arguments[0] as object\n return function(hash: number) {\n Object.defineProperty(self, symbol, {\n value() {\n return hash\n },\n enumerable: false\n })\n return hash\n } as any\n }\n const self = arguments[0] as object\n const hash = arguments[1] as number\n Object.defineProperty(self, symbol, {\n value() {\n return hash\n },\n enumerable: false\n })\n\n return hash\n}\n","/**\n * @since 2.0.0\n */\nimport type { Equivalence } from \"./Equivalence.js\"\nimport * as Hash from \"./Hash.js\"\nimport { hasProperty } from \"./Predicate.js\"\nimport { structuralRegionState } from \"./Utils.js\"\n\n/**\n * @since 2.0.0\n * @category symbols\n */\nexport const symbol: unique symbol = Symbol.for(\"effect/Equal\")\n\n/**\n * @since 2.0.0\n * @category models\n */\nexport interface Equal extends Hash.Hash {\n [symbol](that: Equal): boolean\n}\n\n/**\n * @since 2.0.0\n * @category equality\n */\nexport function equals<B>(that: B): <A>(self: A) => boolean\nexport function equals<A, B>(self: A, that: B): boolean\nexport function equals(): any {\n if (arguments.length === 1) {\n return (self: unknown) => compareBoth(self, arguments[0])\n }\n return compareBoth(arguments[0], arguments[1])\n}\n\nfunction compareBoth(self: unknown, that: unknown): boolean {\n if (self === that) {\n return true\n }\n const selfType = typeof self\n if (selfType !== typeof that) {\n return false\n }\n if (selfType === \"object\" || selfType === \"function\") {\n if (self !== null && that !== null) {\n if (isEqual(self) && isEqual(that)) {\n if (Hash.hash(self) === Hash.hash(that) && self[symbol](that)) {\n return true\n } else {\n return structuralRegionState.enabled && structuralRegionState.tester\n ? structuralRegionState.tester(self, that)\n : false\n }\n } else if (self instanceof Date && that instanceof Date) {\n return self.toISOString() === that.toISOString()\n } else if (self instanceof URL && that instanceof URL) {\n return self.href === that.href\n }\n }\n if (structuralRegionState.enabled) {\n if (Array.isArray(self) && Array.isArray(that)) {\n return self.length === that.length && self.every((v, i) => compareBoth(v, that[i]))\n }\n if (Object.getPrototypeOf(self) === Object.prototype && Object.getPrototypeOf(self) === Object.prototype) {\n const keysSelf = Object.keys(self as any)\n const keysThat = Object.keys(that as any)\n if (keysSelf.length === keysThat.length) {\n for (const key of keysSelf) {\n // @ts-expect-error\n if (!(key in that && compareBoth(self[key], that[key]))) {\n return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false\n }\n }\n return true\n }\n }\n return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false\n }\n }\n\n return structuralRegionState.enabled && structuralRegionState.tester\n ? structuralRegionState.tester(self, that)\n : false\n}\n\n/**\n * @since 2.0.0\n * @category guards\n */\nexport const isEqual = (u: unknown): u is Equal => hasProperty(u, symbol)\n\n/**\n * @since 2.0.0\n * @category instances\n */\nexport const equivalence: <A>() => Equivalence<A> = () => equals\n","/**\n * @since 2.0.0\n */\nimport type * as FiberRefs from \"./FiberRefs.js\"\nimport { globalValue } from \"./GlobalValue.js\"\nimport { hasProperty, isFunction } from \"./Predicate.js\"\n\n/**\n * @since 2.0.0\n * @category symbols\n */\nexport const NodeInspectSymbol = Symbol.for(\"nodejs.util.inspect.custom\")\n\n/**\n * @since 2.0.0\n * @category symbols\n */\nexport type NodeInspectSymbol = typeof NodeInspectSymbol\n\n/**\n * @since 2.0.0\n * @category models\n */\nexport interface Inspectable {\n toString(): string\n toJSON(): unknown\n [NodeInspectSymbol](): unknown\n}\n\n/**\n * @since 2.0.0\n */\nexport const toJSON = (x: unknown): unknown => {\n try {\n if (\n hasProperty(x, \"toJSON\") && isFunction(x[\"toJSON\"]) &&\n x[\"toJSON\"].length === 0\n ) {\n return x.toJSON()\n } else if (Array.isArray(x)) {\n return x.map(toJSON)\n }\n } catch {\n return {}\n }\n return redact(x)\n}\n\n/**\n * @since 2.0.0\n */\nexport const format = (x: unknown): string => JSON.stringify(x, null, 2)\n\n/**\n * @since 2.0.0\n */\nexport const BaseProto: Inspectable = {\n toJSON() {\n return toJSON(this)\n },\n [NodeInspectSymbol]() {\n return this.toJSON()\n },\n toString() {\n return format(this.toJSON())\n }\n}\n\n/**\n * @since 2.0.0\n */\nexport abstract class Class {\n /**\n * @since 2.0.0\n */\n abstract toJSON(): unknown\n /**\n * @since 2.0.0\n */\n [NodeInspectSymbol]() {\n return this.toJSON()\n }\n /**\n * @since 2.0.0\n */\n toString() {\n return format(this.toJSON())\n }\n}\n\n/**\n * @since 2.0.0\n */\nexport const toStringUnknown = (u: unknown, whitespace: number | string | undefined = 2): string => {\n if (typeof u === \"string\") {\n return u\n }\n try {\n return typeof u === \"object\" ? stringifyCircular(u, whitespace) : String(u)\n } catch {\n return String(u)\n }\n}\n\n/**\n * @since 2.0.0\n */\nexport const stringifyCircular = (obj: unknown, whitespace?: number | string | undefined): string => {\n let cache: Array<unknown> = []\n const retVal = JSON.stringify(\n obj,\n (_key, value) =>\n typeof value === \"object\" && value !== null\n ? cache.includes(value)\n ? undefined // circular reference\n : cache.push(value) && (redactableState.fiberRefs !== undefined && isRedactable(value)\n ? value[symbolRedactable](redactableState.fiberRefs)\n : value)\n : value,\n whitespace\n )\n ;(cache as any) = undefined\n return retVal\n}\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport interface Redactable {\n readonly [symbolRedactable]: (fiberRefs: FiberRefs.FiberRefs) => unknown\n}\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport const symbolRedactable: unique symbol = Symbol.for(\"effect/Inspectable/Redactable\")\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport const isRedactable = (u: unknown): u is Redactable =>\n typeof u === \"object\" && u !== null && symbolRedactable in u\n\nconst redactableState = globalValue(\"effect/Inspectable/redactableState\", () => ({\n fiberRefs: undefined as FiberRefs.FiberRefs | undefined\n}))\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport const withRedactableContext = <A>(context: FiberRefs.FiberRefs, f: () => A): A => {\n const prev = redactableState.fiberRefs\n redactableState.fiberRefs = context\n try {\n return f()\n } finally {\n redactableState.fiberRefs = prev\n }\n}\n\n/**\n * @since 3.10.0\n * @category redactable\n */\nexport const redact = (u: unknown): unknown => {\n if (isRedactable(u) && redactableState.fiberRefs !== undefined) {\n return u[symbolRedactable](redactableState.fiberRefs)\n }\n return u\n}\n","/**\n * @since 2.0.0\n */\n\nimport type { Ctor } from \"./Types.js\"\n\n/**\n * @since 2.0.0\n * @category Models\n */\nexport interface Pipeable {\n pipe<A>(this: A): A\n pipe<A, B = never>(this: A, ab: (_: A) => B): B\n pipe<A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C\n pipe<A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D\n pipe<A, B = never, C = never, D = never, E = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E\n ): E\n pipe<A, B = never, C = never, D = never, E = never, F = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F\n ): F\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G\n ): G\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H\n ): H\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I\n ): I\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J\n ): J\n pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never>(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K\n ): K\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L\n ): L\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M\n ): M\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N\n ): N\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O\n ): O\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P\n ): P\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q\n ): Q\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R\n ): R\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R,\n rs: (_: R) => S\n ): S\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never,\n T = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R,\n rs: (_: R) => S,\n st: (_: S) => T\n ): T\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never,\n T = never,\n U = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R,\n rs: (_: R) => S,\n st: (_: S) => T,\n tu: (_: T) => U\n ): U\n pipe<\n A,\n B = never,\n C = never,\n D = never,\n E = never,\n F = never,\n G = never,\n H = never,\n I = never,\n J = never,\n K = never,\n L = never,\n M = never,\n N = never,\n O = never,\n P = never,\n Q = never,\n R = never,\n S = never,\n T = never,\n U = never\n >(\n this: A,\n ab: (_: A) => B,\n bc: (_: B) => C,\n cd: (_: C) => D,\n de: (_: D) => E,\n ef: (_: E) => F,\n fg: (_: F) => G,\n gh: (_: G) => H,\n hi: (_: H) => I,\n ij: (_: I) => J,\n jk: (_: J) => K,\n kl: (_: K) => L,\n lm: (_: L) => M,\n mn: (_: M) => N,\n no: (_: N) => O,\n op: (_: O) => P,\n pq: (_: P) => Q,\n qr: (_: Q) => R,\n rs: (_: R) => S,\n st: (_: S) => T,\n tu: (_: T) => U\n ): U\n}\n\n/**\n * @since 2.0.0\n */\nexport const pipeArguments = <A>(self: A, args: IArguments): unknown => {\n switch (args.length) {\n case 0:\n return self\n case 1:\n return args[0](self)\n case 2:\n return args[1](args[0](self))\n case 3:\n return args[2](args[1](args[0](self)))\n case 4:\n return args[3](args[2](args[1](args[0](self))))\n case 5:\n return args[4](args[3](args[2](args[1](args[0](self)))))\n case 6:\n return args[5](args[4](args[3](args[2](args[1](args[0](self))))))\n case 7:\n return args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))))\n case 8:\n return args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self))))))))\n case 9:\n return args[8](args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))))))\n default: {\n let ret = self\n for (let i = 0, len = args.length; i < len; i++) {\n ret = args[i](ret)\n }\n return ret\n }\n }\n}\n\n/**\n * @since 3.15.0\n * @category Models\n */\nexport interface PipeableConstructor {\n new(...args: Array<any>): Pipeable\n}\n\n/**\n * @since 3.15.0\n * @category Prototypes\n */\nexport const Prototype: Pipeable = {\n pipe() {\n return pipeArguments(this, arguments)\n }\n}\n\nconst Base: PipeableConstructor = (function() {\n function PipeableBase() {}\n PipeableBase.prototype = Prototype\n return PipeableBase as any\n})()\n\n/**\n * @since 3.15.0\n * @category Constructors\n */\nexport const Class: {\n /**\n * @since 3.15.0\n * @category Constructors\n */\n (): PipeableConstructor\n /**\n * @since 3.15.0\n * @category Constructors\n */\n <TBase extends Ctor>(klass: TBase): TBase & PipeableConstructor\n} = (klass?: Ctor) =>\n klass ?\n class extends klass {\n pipe() {\n return pipeArguments(this, arguments)\n }\n }\n : Base\n","/** @internal */\nexport type OP_ASYNC = typeof OP_ASYNC\n\n/** @internal */\nexport const OP_ASYNC = \"Async\" as const\n\n/** @internal */\nexport type OP_COMMIT = typeof OP_COMMIT\n\n/** @internal */\nexport const OP_COMMIT = \"Commit\" as const\n\n/** @internal */\nexport type OP_FAILURE = typeof OP_FAILURE\n\n/** @internal */\nexport const OP_FAILURE = \"Failure\" as const\n\n/** @internal */\nexport type OP_ON_FAILURE = typeof OP_ON_FAILURE\n\n/** @internal */\nexport const OP_ON_FAILURE = \"OnFailure\" as const\n\n/** @internal */\nexport type OP_ON_SUCCESS = typeof OP_ON_SUCCESS\n\n/** @internal */\nexport const OP_ON_SUCCESS = \"OnSuccess\" as const\n\n/** @internal */\nexport type OP_ON_SUCCESS_AND_FAILURE = typeof OP_ON_SUCCESS_AND_FAILURE\n\n/** @internal */\nexport const OP_ON_SUCCESS_AND_FAILURE = \"OnSuccessAndFailure\" as const\n\n/** @internal */\nexport type OP_SUCCESS = typeof OP_SUCCESS\n\n/** @internal */\nexport const OP_SUCCESS = \"Success\" as const\n\n/** @internal */\nexport type OP_SYNC = typeof OP_SYNC\n\n/** @internal */\nexport const OP_SYNC = \"Sync\" as const\n\n/** @internal */\nexport const OP_TAG = \"Tag\" as const\n\n/** @internal */\nexport type OP_TAG = typeof OP_TAG\n\n/** @internal */\nexport type OP_UPDATE_RUNTIME_FLAGS = typeof OP_UPDATE_RUNTIME_FLAGS\n\n/** @internal */\nexport const OP_UPDATE_RUNTIME_FLAGS = \"UpdateRuntimeFlags\" as const\n\n/** @internal */\nexport type OP_WHILE = typeof OP_WHILE\n\n/** @internal */\nexport const OP_WHILE = \"While\" as const\n\n/** @internal */\nexport type OP_ITERATOR = typeof OP_ITERATOR\n\n/** @internal */\nexport const OP_ITERATOR = \"Iterator\" as const\n\n/** @internal */\nexport type OP_WITH_RUNTIME = typeof OP_WITH_RUNTIME\n\n/** @internal */\nexport const OP_WITH_RUNTIME = \"WithRuntime\" as const\n\n/** @internal */\nexport type OP_YIELD = typeof OP_YIELD\n\n/** @internal */\nexport const OP_YIELD = \"Yield\" as const\n\n/** @internal */\nexport type OP_REVERT_FLAGS = typeof OP_REVERT_FLAGS\n\n/** @internal */\nexport const OP_REVERT_FLAGS = \"RevertFlags\" as const\n","let moduleVersion = \"3.17.1\"\n\nexport const getCurrentVersion = () => moduleVersion\n\nexport const setCurrentVersion = (version: string) => {\n moduleVersion = version\n}\n","import type * as Channel from \"../Channel.js\"\nimport type * as Effect from \"../Effect.js\"\nimport type * as Effectable from \"../Effectable.js\"\nimport * as Equal from \"../Equal.js\"\nimport * as Hash from \"../Hash.js\"\nimport { pipeArguments } from \"../Pipeable.js\"\nimport type * as Sink from \"../Sink.js\"\nimport type * as Stream from \"../Stream.js\"\nimport { SingleShotGen, YieldWrap } from \"../Utils.js\"\nimport * as OpCodes from \"./opCodes/effect.js\"\nimport * as version from \"./version.js\"\n\n/** @internal */\nexport const EffectTypeId: Effect.EffectTypeId = Symbol.for(\"effect/Effect\") as Effect.EffectTypeId\n\n/** @internal */\nexport const StreamTypeId: Stream.StreamTypeId = Symbol.for(\"effect/Stream\") as Stream.StreamTypeId\n\n/** @internal */\nexport const SinkTypeId: Sink.SinkTypeId = Symbol.for(\"effect/Sink\") as Sink.SinkTypeId\n\n/** @internal */\nexport const ChannelTypeId: Channel.ChannelTypeId = Symbol.for(\"effect/Channel\") as Channel.ChannelTypeId\n\n/** @internal */\nexport const effectVariance = {\n /* c8 ignore next */\n _R: (_: never) => _,\n /* c8 ignore next */\n _E: (_: never) => _,\n /* c8 ignore next */\n _A: (_: never) => _,\n\n _V: version.getCurrentVersion()\n}\n\nconst sinkVariance = {\n /* c8 ignore next */\n _A: (_: never) => _,\n /* c8 ignore next */\n _In: (_: unknown) => _,\n /* c8 ignore next */\n _L: (_: never) => _,\n /* c8 ignore next */\n _E: (_: never) => _,\n /* c8 ignore next */\n _R: (_: never) => _\n}\n\nconst channelVariance = {\n /* c8 ignore next */\n _Env: (_: never) => _,\n /* c8 ignore next */\n _InErr: (_: unknown) => _,\n /* c8 ignore next */\n _InElem: (_: unknown) => _,\n /* c8 ignore next */\n _InDone: (_: unknown) => _,\n /* c8 ignore next */\n _OutErr: (_: never) => _,\n /* c8 ignore next */\n _OutElem: (_: never) => _,\n /* c8 ignore next */\n _OutDone: (_: never) => _\n}\n\n/** @internal */\nexport const EffectPrototype: Effect.Effect<never> & Equal.Equal = {\n [EffectTypeId]: effectVariance,\n [StreamTypeId]: effectVariance,\n [SinkTypeId]: sinkVariance,\n [ChannelTypeId]: channelVariance,\n [Equal.symbol](that: any) {\n return this === that\n },\n [Hash.symbol]() {\n return Hash.cached(this, Hash.random(this))\n },\n [Symbol.iterator]() {\n return new SingleShotGen(new YieldWrap(this)) as any\n },\n pipe() {\n return pipeArguments(this, arguments)\n }\n}\n\n/** @internal */\nexport const StructuralPrototype: Equal.Equal = {\n [Hash.symbol]() {\n return Hash.cached(this, Hash.structure(this))\n },\n [Equal.symbol](this: Equal.Equal, that: Equal.Equal) {\n const selfKeys = Object.keys(this)\n const thatKeys = Object.keys(that as object)\n if (selfKeys.length !== thatKeys.length) {\n return false\n }\n for (const key of selfKeys) {\n if (!(key in (that as object) && Equal.equals((this as any)[key], (that as any)[key]))) {\n return false\n }\n }\n return true\n }\n}\n\n/** @internal */\nexport const CommitPrototype: Effect.Effect<never> = {\n ...EffectPrototype,\n _op: OpCodes.OP_COMMIT\n} as any\n\n/** @internal */\nexport const StructuralCommitPrototype: Effect.Effect<never> = {\n ...CommitPrototype,\n ...StructuralPrototype\n} as any\n\n/** @internal */\nexport const Base: Effectable.CommitPrimitive = (function() {\n function Base() {}\n Base.prototype = CommitPrototype\n return Base as any\n})()\n\n/** @internal */\nexport const StructuralBase: Effectable.CommitPrimitive = (function() {\n function Base() {}\n Base.prototype = StructuralCommitPrototype\n return Base as any\n})()\n","/**\n * @since 2.0.0\n */\n\nimport * as Equal from \"../Equal.js\"\nimport * as Hash from \"../Hash.js\"\nimport { format, NodeInspectSymbol, toJSON } from \"../Inspectable.js\"\nimport type * as Option from \"../Option.js\"\nimport { hasProperty } from \"../Predicate.js\"\nimport { EffectPrototype } from \"./effectable.js\"\n\nconst TypeId: Option.TypeId = Symbol.for(\"effect/Option\") as Option.TypeId\n\nconst CommonProto = {\n ...EffectPrototype,\n [TypeId]: {\n _A: (_: never) => _\n },\n [NodeInspectSymbol]<A>(this: Option.Option<A>) {\n return this.toJSON()\n },\n toString<A>(this: Option.Option<A>) {\n return format(this.toJSON())\n }\n}\n\nconst SomeProto = Object.assign(Object.create(CommonProto), {\n _tag: \"Some\",\n _op: \"Some\",\n [Equal.symbol]<A>(this: Option.Some<A>, that: unknown): boolean {\n return isOption(that) && isSome(that) && Equal.equals(this.value, that.value)\n },\n [Hash.symbol]<A>(this: Option.Some<A>) {\n return Hash.cached(this, Hash.combine(Hash.hash(this._tag))(Hash.hash(this.value)))\n },\n toJSON<A>(this: Option.Some<A>) {\n return {\n _id: \"Option\",\n _tag: this._tag,\n value: toJSON(this.value)\n }\n }\n})\n\nconst NoneHash = Hash.hash(\"None\")\nconst NoneProto = Object.assign(Object.create(CommonProto), {\n _tag: \"None\",\n _op: \"None\",\n [Equal.symbol]<A>(this: Option.None<A>, that: unknown): boolean {\n return isOption(that) && isNone(that)\n },\n [Hash.symbol]<A>(this: Option.None<A>) {\n return NoneHash\n },\n toJSON<A>(this: Option.None<A>) {\n return {\n _id: \"Option\",\n _tag: this._tag\n }\n }\n})\n\n/** @internal */\nexport const isOption = (input: unknown): input is Option.Option<unknown> => hasProperty(input, TypeId)\n\n/** @internal */\nexport const isNone = <A>(fa: Option.Option<A>): fa is Option.None<A> => fa._tag === \"None\"\n\n/** @internal */\nexport const isSome = <A>(fa: Option.Option<A>): fa is Option.Some<A> => fa._tag === \"Some\"\n\n/** @internal */\nexport const none: Option.Option<never> = Object.create(NoneProto)\n\n/** @internal */\nexport const some = <A>(value: A): Option.Option<A> => {\n const a = Object.create(SomeProto)\n a.value = value\n return a\n}\n","/**\n * @since 2.0.0\n */\n\nimport type * as Either from \"../Either.js\"\nimport * as Equal from \"../Equal.js\"\nimport { dual } from \"../Function.js\"\nimport * as Hash from \"../Hash.js\"\nimport { format, NodeInspectSymbol, toJSON } from \"../Inspectable.js\"\nimport type { Option } from \"../Option.js\"\nimport { hasProperty } from \"../Predicate.js\"\nimport { EffectPrototype } from \"./effectable.js\"\nimport * as option from \"./option.js\"\n\n/**\n * @internal\n */\nexport const TypeId: Either.TypeId = Symbol.for(\"effect/Either\") as Either.TypeId\n\nconst CommonProto = {\n ...EffectPrototype,\n [TypeId]: {\n _R: (_: never) => _\n },\n [NodeInspectSymbol]<L, R>(this: Either.Either<R, L>) {\n return this.toJSON()\n },\n toString<L, R>(this: Either.Left<L, R>) {\n return format(this.toJSON())\n }\n}\n\nconst RightProto = Object.assign(Object.create(CommonProto), {\n _tag: \"Right\",\n _op: \"Right\",\n [Equal.symbol]<L, R>(this: Either.Right<L, R>, that: unknown): boolean {\n return isEither(that) && isRight(that) && Equal.equals(this.right, that.right)\n },\n [Hash.symbol]<L, R>(this: Either.Right<L, R>) {\n return Hash.combine(Hash.hash(this._tag))(Hash.hash(this.right))\n },\n toJSON<L, R>(this: Either.Right<L, R>) {\n return {\n _id: \"Either\",\n _tag: this._tag,\n right: toJSON(this.right)\n }\n }\n})\n\nconst LeftProto = Object.assign(Object.create(CommonProto), {\n _tag: \"Left\",\n _op: \"Left\",\n [Equal.symbol]<L, R>(this: Either.Left<L, R>, that: unknown): boolean {\n return isEither(that) && isLeft(that) && Equal.equals(this.left, that.left)\n },\n [Hash.symbol]<L, R>(this: Either.Left<L, R>) {\n return Hash.combine(Hash.hash(this._tag))(Hash.hash(this.left))\n },\n toJSON<E, A>(this: Either.Left<E, A>) {\n return {\n _id: \"Either\",\n _tag: this._tag,\n left: toJSON(this.left)\n }\n }\n})\n\n/** @internal */\nexport const isEither = (input: unknown): input is Either.Either<unknown, unknown> => hasProperty(input, TypeId)\n\n/** @internal */\nexport const isLeft = <R, L>(ma: Either.Either<R, L>): ma is Either.Left<L, R> => ma._tag === \"Left\"\n\n/** @internal */\nexport const isRight = <R, L>(ma: Either.Either<R, L>): ma is Either.Right<L, R> => ma._tag === \"Right\"\n\n/** @internal */\nexport const left = <L>(left: L): Either.Either<never, L> => {\n const a = Object.create(LeftProto)\n a.left = left\n return a\n}\n\n/** @internal */\nexport const right = <R>(right: R): Either.Either<R> => {\n const a = Object.create(RightProto)\n a.right = right\n return a\n}\n\n/** @internal */\nexport const getLeft = <R, L>(\n self: Either.Either<R, L>\n): Option<L> => (isRight(self) ? option.none : option.some(self.left))\n\n/** @internal */\nexport const getRight = <R, L>(\n self: Either.Either<R, L>\n): Option<R> => (isLeft(self) ? option.none : option.some(self.right))\n\n/** @internal */\nexport const fromOption: {\n <L>(onNone: () => L): <R>(self: Option<R>) => Either.Either<R, L>\n <R, L>(self: Option<R>, onNone: () => L): Either.Either<R, L>\n} = dual(\n 2,\n <R, L>(self: Option<R>, onNone: () => L): Either.Either<R, L> =>\n option.isNone(self) ? left(onNone()) : right(self.value)\n)\n","/**\n * @since 2.0.0\n */\n\nimport * as Equivalence from \"./Equivalence.js\"\nimport type { LazyArg } from \"./Function.js\"\nimport { constNull, constUndefined, dual, identity } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\nimport type { Inspectable } from \"./Inspectable.js\"\nimport * as doNotation from \"./internal/doNotation.js\"\nimport * as either from \"./internal/either.js\"\nimport * as option_ from \"./internal/option.js\"\nimport type { Option } from \"./Option.js\"\nimport type { Pipeable } from \"./Pipeable.js\"\nimport type { Predicate, Refinement } from \"./Predicate.js\"\nimport { isFunction } from \"./Predicate.js\"\nimport type { Covariant, NoInfer, NotFunction } from \"./Types.js\"\nimport type * as Unify from \"./Unify.js\"\nimport * as Gen from \"./Utils.js\"\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport type Either<R, L = never> = Left<L, R> | Right<L, R>\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport const TypeId: unique symbol = either.TypeId\n\n/**\n * @category symbols\n * @since 2.0.0\n */\nexport type TypeId = typeof TypeId\n\n// TODO(4.0): flip the order of the type parameters\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Left<out L, out R> extends Pipeable, Inspectable {\n readonly _tag: \"Left\"\n readonly _op: \"Left\"\n readonly left: L\n readonly [TypeId]: {\n readonly _R: Covariant<R>\n readonly _L: Covariant<L>\n }\n [Unify.typeSymbol]?: unknown\n [Unify.unifySymbol]?: EitherUnify<this>\n [Unify.ignoreSymbol]?: EitherUnifyIgnore\n}\n\n// TODO(4.0): flip the order of the type parameters\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface Right<out L, out R> extends Pipeable, Inspectable {\n readonly _tag: \"Right\"\n readonly _op: \"Right\"\n readonly right: R\n readonly [TypeId]: {\n readonly _R: Covariant<R>\n readonly _L: Covariant<L>\n }\n [Unify.typeSymbol]?: unknown\n [Unify.unifySymbol]?: EitherUnify<this>\n [Unify.ignoreSymbol]?: EitherUnifyIgnore\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface EitherUnify<A extends { [Unify.typeSymbol]?: any }> {\n Either?: () => A[Unify.typeSymbol] extends Either<infer R0, infer L0> | infer _ ? Either<R0, L0> : never\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport interface EitherUnifyIgnore {}\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface EitherTypeLambda extends TypeLambda {\n readonly type: Either<this[\"Target\"], this[\"Out1\"]>\n}\n\n/**\n * @since 2.0.0\n */\nexport declare namespace Either {\n /**\n * @since 2.0.0\n * @category type-level\n */\n export type Left<T extends Either<any, any>> = [T] extends [Either<infer _A, infer _E>] ? _E : never\n /**\n * @since 2.0.0\n * @category type-level\n */\n export type Right<T extends Either<any, any>> = [T] extends [Either<infer _A, infer _E>] ? _A : never\n}\n\n/**\n * Constructs a new `Either` holding a `Right` value. This usually represents a successful value due to the right bias\n * of this structure.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const right: <R>(right: R) => Either<R> = either.right\n\nconst void_: Either<void> = right(void 0)\nexport {\n /**\n * @category constructors\n * @since 3.13.0\n */\n void_ as void\n}\n\n/**\n * Constructs a new `Either` holding a `Left` value. This usually represents a failure, due to the right-bias of this\n * structure.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const left: <L>(left: L) => Either<never, L> = either.left\n\n/**\n * Takes a lazy default and a nullable value, if the value is not nully (`null` or `undefined`), turn it into a `Right`, if the value is nully use\n * the provided default as a `Left`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromNullable(1, () => 'fallback'), Either.right(1))\n * assert.deepStrictEqual(Either.fromNullable(null, () => 'fallback'), Either.left('fallback'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const fromNullable: {\n /**\n * Takes a lazy default and a nullable value, if the value is not nully (`null` or `undefined`), turn it into a `Right`, if the value is nully use\n * the provided default as a `Left`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromNullable(1, () => 'fallback'), Either.right(1))\n * assert.deepStrictEqual(Either.fromNullable(null, () => 'fallback'), Either.left('fallback'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <R, L>(onNullable: (right: R) => L): (self: R) => Either<NonNullable<R>, L>\n /**\n * Takes a lazy default and a nullable value, if the value is not nully (`null` or `undefined`), turn it into a `Right`, if the value is nully use\n * the provided default as a `Left`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromNullable(1, () => 'fallback'), Either.right(1))\n * assert.deepStrictEqual(Either.fromNullable(null, () => 'fallback'), Either.left('fallback'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <R, L>(self: R, onNullable: (right: R) => L): Either<NonNullable<R>, L>\n} = dual(\n 2,\n <R, L>(self: R, onNullable: (right: R) => L): Either<NonNullable<R>, L> =>\n self == null ? left(onNullable(self)) : right(self)\n)\n\n/**\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromOption(Option.some(1), () => 'error'), Either.right(1))\n * assert.deepStrictEqual(Either.fromOption(Option.none(), () => 'error'), Either.left('error'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const fromOption: {\n /**\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromOption(Option.some(1), () => 'error'), Either.right(1))\n * assert.deepStrictEqual(Either.fromOption(Option.none(), () => 'error'), Either.left('error'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <L>(onNone: () => L): <R>(self: Option<R>) => Either<R, L>\n /**\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Either.fromOption(Option.some(1), () => 'error'), Either.right(1))\n * assert.deepStrictEqual(Either.fromOption(Option.none(), () => 'error'), Either.left('error'))\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <R, L>(self: Option<R>, onNone: () => L): Either<R, L>\n} = either.fromOption\n\nconst try_: {\n <R, L>(\n options: {\n readonly try: LazyArg<R>\n readonly catch: (error: unknown) => L\n }\n ): Either<R, L>\n <R>(evaluate: LazyArg<R>): Either<R, unknown>\n} = (<R, L>(\n evaluate: LazyArg<R> | {\n readonly try: LazyArg<R>\n readonly catch: (error: unknown) => L\n }\n) => {\n if (isFunction(evaluate)) {\n try {\n return right(evaluate())\n } catch (e) {\n return left(e)\n }\n } else {\n try {\n return right(evaluate.try())\n } catch (e) {\n return left(evaluate.catch(e))\n }\n }\n}) as any\n\nexport {\n /**\n * Imports a synchronous side-effect into a pure `Either` value, translating any\n * thrown exceptions into typed failed eithers creating with `Either.left`.\n *\n * @category constructors\n * @since 2.0.0\n */\n try_ as try\n}\n\n/**\n * Tests if a value is a `Either`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.isEither(Either.right(1)), true)\n * assert.deepStrictEqual(Either.isEither(Either.left(\"a\")), true)\n * assert.deepStrictEqual(Either.isEither({ right: 1 }), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isEither: (input: unknown) => input is Either<unknown, unknown> = either.isEither\n\n/**\n * Determine if a `Either` is a `Left`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.isLeft(Either.right(1)), false)\n * assert.deepStrictEqual(Either.isLeft(Either.left(\"a\")), true)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isLeft: <R, L>(self: Either<R, L>) => self is Left<L, R> = either.isLeft\n\n/**\n * Determine if a `Either` is a `Right`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.isRight(Either.right(1)), true)\n * assert.deepStrictEqual(Either.isRight(Either.left(\"a\")), false)\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isRight: <R, L>(self: Either<R, L>) => self is Right<L, R> = either.isRight\n\n/**\n * Converts a `Either` to an `Option` discarding the `Left`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getRight(Either.right('ok')), Option.some('ok'))\n * assert.deepStrictEqual(Either.getRight(Either.left('err')), Option.none())\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getRight: <R, L>(self: Either<R, L>) => Option<R> = either.getRight\n\n/**\n * Converts a `Either` to an `Option` discarding the value.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either, Option } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getLeft(Either.right('ok')), Option.none())\n * assert.deepStrictEqual(Either.getLeft(Either.left('err')), Option.some('err'))\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getLeft: <R, L>(self: Either<R, L>) => Option<L> = either.getLeft\n\n/**\n * @category equivalence\n * @since 2.0.0\n */\nexport const getEquivalence = <R, L>({ left, right }: {\n right: Equivalence.Equivalence<R>\n left: Equivalence.Equivalence<L>\n}): Equivalence.Equivalence<Either<R, L>> =>\n Equivalence.make((x, y) =>\n isLeft(x) ?\n isLeft(y) && left(x.left, y.left) :\n isRight(y) && right(x.right, y.right)\n )\n\n/**\n * @category mapping\n * @since 2.0.0\n */\nexport const mapBoth: {\n /**\n * @category mapping\n * @since 2.0.0\n */\n <L, L2, R, R2>(\n options: {\n readonly onLeft: (left: L) => L2\n readonly onRight: (right: R) => R2\n }\n ): (self: Either<R, L>) => Either<R2, L2>\n /**\n * @category mapping\n * @since 2.0.0\n */\n <L, R, L2, R2>(\n self: Either<R, L>,\n options: {\n readonly onLeft: (left: L) => L2\n readonly onRight: (right: R) => R2\n }\n ): Either<R2, L2>\n} = dual(\n 2,\n <L, R, L2, R2>(self: Either<R, L>, { onLeft, onRight }: {\n readonly onLeft: (left: L) => L2\n readonly onRight: (right: R) => R2\n }): Either<R2, L2> => isLeft(self) ? left(onLeft(self.left)) : right(onRight(self.right))\n)\n\n/**\n * Maps the `Left` side of an `Either` value to a new `Either` value.\n *\n * @category mapping\n * @since 2.0.0\n */\nexport const mapLeft: {\n /**\n * Maps the `Left` side of an `Either` value to a new `Either` value.\n *\n * @category mapping\n * @since 2.0.0\n */\n <L, L2>(f: (left: L) => L2): <R>(self: Either<R, L>) => Either<R, L2>\n /**\n * Maps the `Left` side of an `Either` value to a new `Either` value.\n *\n * @category mapping\n * @since 2.0.0\n */\n <R, L, L2>(self: Either<R, L>, f: (left: L) => L2): Either<R, L2>\n} = dual(\n 2,\n <R, L1, L2>(self: Either<R, L1>, f: (left: L1) => L2): Either<R, L2> =>\n isLeft(self) ? left(f(self.left)) : right(self.right)\n)\n\n/**\n * Maps the `Right` side of an `Either` value to a new `Either` value.\n *\n * @category mapping\n * @since 2.0.0\n */\nexport const map: {\n /**\n * Maps the `Right` side of an `Either` value to a new `Either` value.\n *\n * @category mapping\n * @since 2.0.0\n */\n <R, R2>(f: (right: R) => R2): <L>(self: Either<R, L>) => Either<R2, L>\n /**\n * Maps the `Right` side of an `Either` value to a new `Either` value.\n *\n * @category mapping\n * @since 2.0.0\n */\n <R, L, R2>(self: Either<R, L>, f: (right: R) => R2): Either<R2, L>\n} = dual(\n 2,\n <R1, L, R2>(self: Either<R1, L>, f: (right: R1) => R2): Either<R2, L> =>\n isRight(self) ? right(f(self.right)) : left(self.left)\n)\n\n/**\n * Takes two functions and an `Either` value, if the value is a `Left` the inner value is applied to the `onLeft function,\n * if the value is a `Right` the inner value is applied to the `onRight` function.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const onLeft = (strings: ReadonlyArray<string>): string => `strings: ${strings.join(', ')}`\n *\n * const onRight = (value: number): string => `Ok: ${value}`\n *\n * assert.deepStrictEqual(pipe(Either.right(1), Either.match({ onLeft, onRight })), 'Ok: 1')\n * assert.deepStrictEqual(\n * pipe(Either.left(['string 1', 'string 2']), Either.match({ onLeft, onRight })),\n * 'strings: string 1, string 2'\n * )\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\nexport const match: {\n /**\n * Takes two functions and an `Either` value, if the value is a `Left` the inner value is applied to the `onLeft function,\n * if the value is a `Right` the inner value is applied to the `onRight` function.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const onLeft = (strings: ReadonlyArray<string>): string => `strings: ${strings.join(', ')}`\n *\n * const onRight = (value: number): string => `Ok: ${value}`\n *\n * assert.deepStrictEqual(pipe(Either.right(1), Either.match({ onLeft, onRight })), 'Ok: 1')\n * assert.deepStrictEqual(\n * pipe(Either.left(['string 1', 'string 2']), Either.match({ onLeft, onRight })),\n * 'strings: string 1, string 2'\n * )\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <L, B, R, C = B>(\n options: {\n readonly onLeft: (left: L) => B\n readonly onRight: (right: R) => C\n }\n ): (self: Either<R, L>) => B | C\n /**\n * Takes two functions and an `Either` value, if the value is a `Left` the inner value is applied to the `onLeft function,\n * if the value is a `Right` the inner value is applied to the `onRight` function.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const onLeft = (strings: ReadonlyArray<string>): string => `strings: ${strings.join(', ')}`\n *\n * const onRight = (value: number): string => `Ok: ${value}`\n *\n * assert.deepStrictEqual(pipe(Either.right(1), Either.match({ onLeft, onRight })), 'Ok: 1')\n * assert.deepStrictEqual(\n * pipe(Either.left(['string 1', 'string 2']), Either.match({ onLeft, onRight })),\n * 'strings: string 1, string 2'\n * )\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <R, L, B, C = B>(\n self: Either<R, L>,\n options: {\n readonly onLeft: (left: L) => B\n readonly onRight: (right: R) => C\n }\n ): B | C\n} = dual(\n 2,\n <R, L, B, C = B>(self: Either<R, L>, { onLeft, onRight }: {\n readonly onLeft: (left: L) => B\n readonly onRight: (right: R) => C\n }): B | C => isLeft(self) ? onLeft(self.left) : onRight(self.right)\n)\n\n/**\n * Transforms a `Predicate` function into a `Right` of the input value if the predicate returns `true`\n * or `Left` of the result of the provided function if the predicate returns false\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n * const isPositiveEither = Either.liftPredicate(isPositive, n => `${n} is not positive`)\n *\n * assert.deepStrictEqual(\n * isPositiveEither(1),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * isPositiveEither(0),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @category lifting\n * @since 3.4.0\n */\nexport const liftPredicate: {\n /**\n * Transforms a `Predicate` function into a `Right` of the input value if the predicate returns `true`\n * or `Left` of the result of the provided function if the predicate returns false\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n * const isPositiveEither = Either.liftPredicate(isPositive, n => `${n} is not positive`)\n *\n * assert.deepStrictEqual(\n * isPositiveEither(1),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * isPositiveEither(0),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @category lifting\n * @since 3.4.0\n */\n <A, B extends A, E>(refinement: Refinement<A, B>, orLeftWith: (a: A) => E): (a: A) => Either<B, E>\n /**\n * Transforms a `Predicate` function into a `Right` of the input value if the predicate returns `true`\n * or `Left` of the result of the provided function if the predicate returns false\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n * const isPositiveEither = Either.liftPredicate(isPositive, n => `${n} is not positive`)\n *\n * assert.deepStrictEqual(\n * isPositiveEither(1),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * isPositiveEither(0),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @category lifting\n * @since 3.4.0\n */\n <B extends A, E, A = B>(predicate: Predicate<A>, orLeftWith: (a: A) => E): (a: B) => Either<B, E>\n /**\n * Transforms a `Predicate` function into a `Right` of the input value if the predicate returns `true`\n * or `Left` of the result of the provided function if the predicate returns false\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n * const isPositiveEither = Either.liftPredicate(isPositive, n => `${n} is not positive`)\n *\n * assert.deepStrictEqual(\n * isPositiveEither(1),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * isPositiveEither(0),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @category lifting\n * @since 3.4.0\n */\n <A, E, B extends A>(self: A, refinement: Refinement<A, B>, orLeftWith: (a: A) => E): Either<B, E>\n /**\n * Transforms a `Predicate` function into a `Right` of the input value if the predicate returns `true`\n * or `Left` of the result of the provided function if the predicate returns false\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n * const isPositiveEither = Either.liftPredicate(isPositive, n => `${n} is not positive`)\n *\n * assert.deepStrictEqual(\n * isPositiveEither(1),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * isPositiveEither(0),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @category lifting\n * @since 3.4.0\n */\n <B extends A, E, A = B>(self: B, predicate: Predicate<A>, orLeftWith: (a: A) => E): Either<B, E>\n} = dual(\n 3,\n <A, E>(a: A, predicate: Predicate<A>, orLeftWith: (a: A) => E): Either<A, E> =>\n predicate(a) ? right(a) : left(orLeftWith(a))\n)\n\n/**\n * Filter the right value with the provided function.\n * If the predicate fails, set the left value with the result of the provided function.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(1),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(0),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @since 2.0.0\n * @category filtering & conditionals\n */\nexport const filterOrLeft: {\n /**\n * Filter the right value with the provided function.\n * If the predicate fails, set the left value with the result of the provided function.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(1),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(0),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @since 2.0.0\n * @category filtering & conditionals\n */\n <R, B extends R, L2>(\n refinement: Refinement<NoInfer<R>, B>,\n orLeftWith: (right: NoInfer<R>) => L2\n ): <L>(self: Either<R, L>) => Either<B, L2 | L>\n /**\n * Filter the right value with the provided function.\n * If the predicate fails, set the left value with the result of the provided function.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(1),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(0),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @since 2.0.0\n * @category filtering & conditionals\n */\n <R, L2>(predicate: Predicate<NoInfer<R>>, orLeftWith: (right: NoInfer<R>) => L2): <L>(self: Either<R, L>) => Either<R, L2 | L>\n /**\n * Filter the right value with the provided function.\n * If the predicate fails, set the left value with the result of the provided function.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(1),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(0),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @since 2.0.0\n * @category filtering & conditionals\n */\n <R, L, B extends R, L2>(\n self: Either<R, L>,\n refinement: Refinement<R, B>,\n orLeftWith: (right: R) => L2\n ): Either<B, L | L2>\n /**\n * Filter the right value with the provided function.\n * If the predicate fails, set the left value with the result of the provided function.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { pipe, Either } from \"effect\"\n *\n * const isPositive = (n: number): boolean => n > 0\n *\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(1),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.right(1)\n * )\n * assert.deepStrictEqual(\n * pipe(\n * Either.right(0),\n * Either.filterOrLeft(isPositive, n => `${n} is not positive`)\n * ),\n * Either.left(\"0 is not positive\")\n * )\n * ```\n *\n * @since 2.0.0\n * @category filtering & conditionals\n */\n <R, L, E2>(self: Either<R, L>, predicate: Predicate<R>, orLeftWith: (right: R) => E2): Either<R, L | E2>\n} = dual(3, <R, L, E2>(\n self: Either<R, L>,\n predicate: Predicate<R>,\n orLeftWith: (right: R) => E2\n): Either<R, L | E2> => flatMap(self, (r) => predicate(r) ? right(r) : left(orLeftWith(r))))\n\n/**\n * @category getters\n * @since 2.0.0\n */\nexport const merge: <R, L>(self: Either<R, L>) => L | R = match({\n onLeft: identity,\n onRight: identity\n})\n\n/**\n * Returns the wrapped value if it's a `Right` or a default value if is a `Left`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrElse(Either.right(1), (error) => error + \"!\"), 1)\n * assert.deepStrictEqual(Either.getOrElse(Either.left(\"not a number\"), (error) => error + \"!\"), \"not a number!\")\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrElse: {\n /**\n * Returns the wrapped value if it's a `Right` or a default value if is a `Left`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrElse(Either.right(1), (error) => error + \"!\"), 1)\n * assert.deepStrictEqual(Either.getOrElse(Either.left(\"not a number\"), (error) => error + \"!\"), \"not a number!\")\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <L, R2>(onLeft: (left: L) => R2): <R>(self: Either<R, L>) => R2 | R\n /**\n * Returns the wrapped value if it's a `Right` or a default value if is a `Left`.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrElse(Either.right(1), (error) => error + \"!\"), 1)\n * assert.deepStrictEqual(Either.getOrElse(Either.left(\"not a number\"), (error) => error + \"!\"), \"not a number!\")\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <R, L, R2>(self: Either<R, L>, onLeft: (left: L) => R2): R | R2\n} = dual(\n 2,\n <R, L, B>(self: Either<R, L>, onLeft: (left: L) => B): R | B => isLeft(self) ? onLeft(self.left) : self.right\n)\n\n/**\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrNull(Either.right(1)), 1)\n * assert.deepStrictEqual(Either.getOrNull(Either.left(\"a\")), null)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrNull: <R, L>(self: Either<R, L>) => R | null = getOrElse(constNull)\n\n/**\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrUndefined(Either.right(1)), 1)\n * assert.deepStrictEqual(Either.getOrUndefined(Either.left(\"a\")), undefined)\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrUndefined: <R, L>(self: Either<R, L>) => R | undefined = getOrElse(constUndefined)\n\n/**\n * Extracts the value of an `Either` or throws if the `Either` is `Left`.\n *\n * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Either.getOrThrowWith(Either.right(1), () => new Error('Unexpected Left')),\n * 1\n * )\n * assert.throws(() => Either.getOrThrowWith(Either.left(\"error\"), () => new Error('Unexpected Left')))\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrThrowWith: {\n /**\n * Extracts the value of an `Either` or throws if the `Either` is `Left`.\n *\n * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Either.getOrThrowWith(Either.right(1), () => new Error('Unexpected Left')),\n * 1\n * )\n * assert.throws(() => Either.getOrThrowWith(Either.left(\"error\"), () => new Error('Unexpected Left')))\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <L>(onLeft: (left: L) => unknown): <A>(self: Either<A, L>) => A\n /**\n * Extracts the value of an `Either` or throws if the `Either` is `Left`.\n *\n * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Either.getOrThrowWith(Either.right(1), () => new Error('Unexpected Left')),\n * 1\n * )\n * assert.throws(() => Either.getOrThrowWith(Either.left(\"error\"), () => new Error('Unexpected Left')))\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <R, L>(self: Either<R, L>, onLeft: (left: L) => unknown): R\n} = dual(2, <R, L>(self: Either<R, L>, onLeft: (left: L) => unknown): R => {\n if (isRight(self)) {\n return self.right\n }\n throw onLeft(self.left)\n})\n\n// TODO(4.0): by default should throw `L` (i.e getOrThrowWith with the identity function)\n/**\n * Extracts the value of an `Either` or throws if the `Either` is `Left`.\n *\n * The thrown error is a default error. To configure the error thrown, see {@link getOrThrowWith}.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.getOrThrow(Either.right(1)), 1)\n * assert.throws(() => Either.getOrThrow(Either.left(\"error\")))\n * ```\n *\n * @throws `Error(\"getOrThrow called on a Left\")`\n *\n * @category getters\n * @since 2.0.0\n */\nexport const getOrThrow: <R, L>(self: Either<R, L>) => R = getOrThrowWith(() =>\n new Error(\"getOrThrow called on a Left\")\n)\n\n/**\n * Returns `self` if it is a `Right` or `that` otherwise.\n *\n * @category error handling\n * @since 2.0.0\n */\nexport const orElse: {\n /**\n * Returns `self` if it is a `Right` or `that` otherwise.\n *\n * @category error handling\n * @since 2.0.0\n */\n <L, R2, L2>(that: (left: L) => Either<R2, L2>): <R>(self: Either<R, L>) => Either<R | R2, L2>\n /**\n * Returns `self` if it is a `Right` or `that` otherwise.\n *\n * @category error handling\n * @since 2.0.0\n */\n <R, L, R2, L2>(self: Either<R, L>, that: (left: L) => Either<R2, L2>): Either<R | R2, L2>\n} = dual(\n 2,\n <R1, L1, R2, L2>(self: Either<R1, L1>, that: (left: L1) => Either<R2, L2>): Either<R1 | R2, L2> =>\n isLeft(self) ? that(self.left) : right(self.right)\n)\n\n/**\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatMap: {\n /**\n * @category sequencing\n * @since 2.0.0\n */\n <R, R2, L2>(f: (right: R) => Either<R2, L2>): <L>(self: Either<R, L>) => Either<R2, L | L2>\n /**\n * @category sequencing\n * @since 2.0.0\n */\n <R, L, R2, L2>(self: Either<R, L>, f: (right: R) => Either<R2, L2>): Either<R2, L | L2>\n} = dual(\n 2,\n <R1, L1, R2, L2>(self: Either<R1, L1>, f: (right: R1) => Either<R2, L2>): Either<R2, L1 | L2> =>\n isLeft(self) ? left(self.left) : f(self.right)\n)\n\n/**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const andThen: {\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, R2, L2>(f: (right: R) => Either<R2, L2>): <L>(self: Either<R, L>) => Either<R2, L | L2>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R2, L2>(f: Either<R2, L2>): <L, R1>(self: Either<R1, L>) => Either<R2, L | L2>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, R2>(f: (right: R) => R2): <L>(self: Either<R, L>) => Either<R2, L>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R2>(right: NotFunction<R2>): <R1, L>(self: Either<R1, L>) => Either<R2, L>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, L, R2, L2>(self: Either<R, L>, f: (right: R) => Either<R2, L2>): Either<R2, L | L2>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, L, R2, L2>(self: Either<R, L>, f: Either<R2, L2>): Either<R2, L | L2>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, L, R2>(self: Either<R, L>, f: (right: R) => R2): Either<R2, L>\n /**\n * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <R, L, R2>(self: Either<R, L>, f: NotFunction<R2>): Either<R2, L>\n} = dual(\n 2,\n <R, L, R2, L2>(self: Either<R, L>, f: (right: R) => Either<R2, L2> | Either<R2, L2>): Either<R2, L | L2> =>\n flatMap(self, (a) => {\n const b = isFunction(f) ? f(a) : f\n return isEither(b) ? b : right(b)\n })\n)\n\n/**\n * @category zipping\n * @since 2.0.0\n */\nexport const zipWith: {\n /**\n * @category zipping\n * @since 2.0.0\n */\n <R2, L2, R, B>(that: Either<R2, L2>, f: (right: R, right2: R2) => B): <L>(self: Either<R, L>) => Either<B, L2 | L>\n /**\n * @category zipping\n * @since 2.0.0\n */\n <R, L, R2, L2, B>(self: Either<R, L>, that: Either<R2, L2>, f: (right: R, right2: R2) => B): Either<B, L | L2>\n} = dual(\n 3,\n <R, L, R2, L2, B>(self: Either<R, L>, that: Either<R2, L2>, f: (right: R, right2: R2) => B): Either<B, L | L2> =>\n flatMap(self, (r) => map(that, (r2) => f(r, r2)))\n)\n\n/**\n * @category combining\n * @since 2.0.0\n */\nexport const ap: {\n /**\n * @category combining\n * @since 2.0.0\n */\n <R, L2>(that: Either<R, L2>): <R2, L>(self: Either<(right: R) => R2, L>) => Either<R2, L | L2>\n /**\n * @category combining\n * @since 2.0.0\n */\n <R, R2, L, L2>(self: Either<(right: R) => R2, L>, that: Either<R, L2>): Either<R2, L | L2>\n} = dual(\n 2,\n <R, R2, L, L2>(self: Either<(right: R) => R2, L>, that: Either<R, L2>): Either<R2, L | L2> =>\n zipWith(self, that, (f, a) => f(a))\n)\n\n/**\n * Takes a structure of `Either`s and returns an `Either` of values with the same structure.\n *\n * - If a tuple is supplied, then the returned `Either` will contain a tuple with the same length.\n * - If a struct is supplied, then the returned `Either` will contain a struct with the same keys.\n * - If an iterable is supplied, then the returned `Either` will contain an array.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either } from \"effect\"\n *\n * assert.deepStrictEqual(Either.all([Either.right(1), Either.right(2)]), Either.right([1, 2]))\n * assert.deepStrictEqual(Either.all({ right: Either.right(1), b: Either.right(\"hello\") }), Either.right({ right: 1, b: \"hello\" }))\n * assert.deepStrictEqual(Either.all({ right: Either.right(1), b: Either.left(\"error\") }), Either.left(\"error\"))\n * ```\n *\n * @category combining\n * @since 2.0.0\n */\n// @ts-expect-error\nexport const all: <const I extends Iterable<Either<any, any>> | Record<string, Either<any, any>>>(\n input: I\n) => [I] extends [ReadonlyArray<Either<any, any>>] ? Either<\n { -readonly [K in keyof I]: [I[K]] extends [Either<infer R, any>] ? R : never },\n I[number] extends never ? never : [I[number]] extends [Either<any, infer L>] ? L : never\n >\n : [I] extends [Iterable<Either<infer R, infer L>>] ? Either<Array<R>, L>\n : Either<\n { -readonly [K in keyof I]: [I[K]] extends [Either<infer R, any>] ? R : never },\n I[keyof I] extends never ? never : [I[keyof I]] extends [Either<any, infer L>] ? L : never\n > = (\n input: Iterable<Either<any, any>> | Record<string, Either<any, any>>\n ): Either<any, any> => {\n if (Symbol.iterator in input) {\n const out: Array<Either<any, any>> = []\n for (const e of input) {\n if (isLeft(e)) {\n return e\n }\n out.push(e.right)\n }\n return right(out)\n }\n\n const out: Record<string, any> = {}\n for (const key of Object.keys(input)) {\n const e = input[key]\n if (isLeft(e)) {\n return e\n }\n out[key] = e.right\n }\n return right(out)\n }\n\n/**\n * Returns an `Either` that swaps the error/success cases. This allows you to\n * use all methods on the error channel, possibly before flipping back.\n *\n * @since 2.0.0\n * @category mapping\n */\nexport const flip = <R, L>(self: Either<R, L>): Either<L, R> => isLeft(self) ? right(self.left) : left(self.right)\n\nconst adapter = Gen.adapter<EitherTypeLambda>()\n\n/**\n * @category generators\n * @since 2.0.0\n */\nexport const gen: Gen.Gen<EitherTypeLambda, Gen.Adapter<EitherTypeLambda>> = (...args) => {\n const f = args.length === 1 ? args[0] : args[1].bind(args[0])\n const iterator = f(adapter)\n let state: IteratorResult<any> = iterator.next()\n while (!state.done) {\n const current = Gen.isGenKind(state.value)\n ? state.value.value\n : Gen.yieldWrapGet(state.value)\n if (isLeft(current)) {\n return current\n }\n state = iterator.next(current.right as never)\n }\n return right(state.value) as any\n}\n\n// -------------------------------------------------------------------------------------\n// do notation\n// -------------------------------------------------------------------------------------\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link bind}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 2.0.0\n */\nexport const Do: Either<{}> = right({})\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 2.0.0\n */\nexport const bind: {\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 2.0.0\n */\n <N extends string, A extends object, B, L2>(name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Either<B, L2>): <L1>(self: Either<A, L1>) => Either<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, L1 | L2>\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 2.0.0\n */\n <A extends object, L1, N extends string, B, L2>(\n self: Either<A, L1>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => Either<B, L2>\n ): Either<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, L1 | L2>\n} = doNotation.bind<EitherTypeLambda>(map, flatMap)\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 2.0.0\n */\nexport const bindTo: {\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 2.0.0\n */\n <N extends string>(name: N): <R, L>(self: Either<R, L>) => Either<{ [K in N]: R }, L>\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 2.0.0\n */\n <R, L, N extends string>(self: Either<R, L>, name: N): Either<{ [K in N]: R }, L>\n} = doNotation.bindTo<EitherTypeLambda>(map)\n\nconst let_: {\n <N extends string, R extends object, B>(\n name: Exclude<N, keyof R>,\n f: (r: NoInfer<R>) => B\n ): <L>(self: Either<R, L>) => Either<{ [K in N | keyof R]: K extends keyof R ? R[K] : B }, L>\n <R extends object, L, N extends string, B>(\n self: Either<R, L>,\n name: Exclude<N, keyof R>,\n f: (r: NoInfer<R>) => B\n ): Either<{ [K in N | keyof R]: K extends keyof R ? R[K] : B }, L>\n} = doNotation.let_<EitherTypeLambda>(map)\n\nexport {\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Either, pipe } from \"effect\"\n *\n * const result = pipe(\n * Either.Do,\n * Either.bind(\"x\", () => Either.right(2)),\n * Either.bind(\"y\", () => Either.right(3)),\n * Either.let(\"sum\", ({ x, y }) => x + y)\n * )\n * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link bind}\n *\n * @category do notation\n * @since 2.0.0\n */\n let_ as let\n}\n\n/**\n * Converts an `Option` of an `Either` into an `Either` of an `Option`.\n *\n * **Details**\n *\n * This function transforms an `Option<Either<A, E>>` into an\n * `Either<Option<A>, E>`. If the `Option` is `None`, the resulting `Either`\n * will be a `Right` with a `None` value. If the `Option` is `Some`, the\n * inner `Either` will be executed, and its result wrapped in a `Some`.\n *\n * @example\n * ```ts\n * import { Effect, Either, Option } from \"effect\"\n *\n * // ┌─── Option<Either<number, never>>\n * // ▼\n * const maybe = Option.some(Either.right(42))\n *\n * // ┌─── Either<Option<number>, never, never>\n * // ▼\n * const result = Either.transposeOption(maybe)\n *\n * console.log(Effect.runSync(result))\n * // Output: { _id: 'Option', _tag: 'Some', value: 42 }\n * ```\n *\n * @since 3.14.0\n * @category Optional Wrapping & Unwrapping\n */\nexport const transposeOption = <A = never, E = never>(\n self: Option<Either<A, E>>\n): Either<Option<A>, E> => {\n return option_.isNone(self) ? right(option_.none) : map(self.value, option_.some)\n}\n\n/**\n * Applies an `Either` on an `Option` and transposes the result.\n *\n * **Details**\n *\n * If the `Option` is `None`, the resulting `Either` will immediately succeed with a `Right` value of `None`.\n * If the `Option` is `Some`, the transformation function will be applied to the inner value, and its result wrapped in a `Some`.\n *\n * @example\n * ```ts\n * import { Either, Option, pipe } from \"effect\"\n *\n * // ┌─── Either<Option<number>, never>>\n * // ▼\n * const noneResult = pipe(\n * Option.none(),\n * Either.transposeMapOption(() => Either.right(42)) // will not be executed\n * )\n * console.log(noneResult)\n * // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'None' } }\n *\n * // ┌─── Either<Option<number>, never>>\n * // ▼\n * const someRightResult = pipe(\n * Option.some(42),\n * Either.transposeMapOption((value) => Either.right(value * 2))\n * )\n * console.log(someRightResult)\n * // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'Some', value: 84 } }\n * ```\n *\n * @since 3.15.0\n * @category Optional Wrapping & Unwrapping\n */\nexport const transposeMapOption = dual<\n /**\n * Applies an `Either` on an `Option` and transposes the result.\n *\n * **Details**\n *\n * If the `Option` is `None`, the resulting `Either` will immediately succeed with a `Right` value of `None`.\n * If the `Option` is `Some`, the transformation function will be applied to the inner value, and its result wrapped in a `Some`.\n *\n * @example\n * ```ts\n * import { Either, Option, pipe } from \"effect\"\n *\n * // ┌─── Either<Option<number>, never>>\n * // ▼\n * const noneResult = pipe(\n * Option.none(),\n * Either.transposeMapOption(() => Either.right(42)) // will not be executed\n * )\n * console.log(noneResult)\n * // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'None' } }\n *\n * // ┌─── Either<Option<number>, never>>\n * // ▼\n * const someRightResult = pipe(\n * Option.some(42),\n * Either.transposeMapOption((value) => Either.right(value * 2))\n * )\n * console.log(someRightResult)\n * // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'Some', value: 84 } }\n * ```\n *\n * @since 3.15.0\n * @category Optional Wrapping & Unwrapping\n */\n <A, B, E = never>(f: (self: A) => Either<B, E>) => (self: Option<A>) => Either<Option<B>, E>,\n /**\n * Applies an `Either` on an `Option` and transposes the result.\n *\n * **Details**\n *\n * If the `Option` is `None`, the resulting `Either` will immediately succeed with a `Right` value of `None`.\n * If the `Option` is `Some`, the transformation function will be applied to the inner value, and its result wrapped in a `Some`.\n *\n * @example\n * ```ts\n * import { Either, Option, pipe } from \"effect\"\n *\n * // ┌─── Either<Option<number>, never>>\n * // ▼\n * const noneResult = pipe(\n * Option.none(),\n * Either.transposeMapOption(() => Either.right(42)) // will not be executed\n * )\n * console.log(noneResult)\n * // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'None' } }\n *\n * // ┌─── Either<Option<number>, never>>\n * // ▼\n * const someRightResult = pipe(\n * Option.some(42),\n * Either.transposeMapOption((value) => Either.right(value * 2))\n * )\n * console.log(someRightResult)\n * // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'Some', value: 84 } }\n * ```\n *\n * @since 3.15.0\n * @category Optional Wrapping & Unwrapping\n */\n <A, B, E = never>(self: Option<A>, f: (self: A) => Either<B, E>) => Either<Option<B>, E>\n>(2, (self, f) => option_.isNone(self) ? right(option_.none) : map(f(self.value), option_.some))\n","/**\n * @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 * as assert from \"node:assert\"\n * import { Order, Number } from \"effect\"\n *\n * const clamp = Order.clamp(Number.Order)({ minimum: 1, maximum: 5 })\n *\n * assert.equal(clamp(3), 3)\n * assert.equal(clamp(0), 1)\n * assert.equal(clamp(6), 5)\n * ```\n *\n * @since 2.0.0\n */\nexport const clamp = <A>(O: Order<A>): {\n (options: {\n minimum: A\n maximum: A\n }): (self: A) => A\n (self: A, options: {\n minimum: A\n maximum: A\n }): A\n} =>\n dual(\n 2,\n (self: A, options: {\n minimum: A\n maximum: A\n }): A => min(O)(options.maximum, max(O)(options.minimum, self))\n )\n\n/**\n * Test whether a value is between a minimum and a maximum (inclusive).\n *\n * @since 2.0.0\n */\nexport const between = <A>(O: Order<A>): {\n (options: {\n minimum: A\n maximum: A\n }): (self: A) => boolean\n (self: A, options: {\n minimum: A\n maximum: A\n }): boolean\n} =>\n dual(\n 2,\n (self: A, options: {\n minimum: A\n maximum: A\n }): boolean => !lessThan(O)(self, options.minimum) && !greaterThan(O)(self, options.maximum)\n )\n","/**\n * @since 2.0.0\n */\nimport type { Either } from \"./Either.js\"\nimport * as Equal from \"./Equal.js\"\nimport * as Equivalence from \"./Equivalence.js\"\nimport type { LazyArg } from \"./Function.js\"\nimport { constNull, constUndefined, dual, identity, isFunction } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\nimport type { Inspectable } from \"./Inspectable.js\"\nimport * as doNotation from \"./internal/doNotation.js\"\nimport * as either from \"./internal/either.js\"\nimport * as option from \"./internal/option.js\"\nimport type { Order } from \"./Order.js\"\nimport * as order from \"./Order.js\"\nimport type { Pipeable } from \"./Pipeable.js\"\nimport type { Predicate, Refinement } from \"./Predicate.js\"\nimport type { Covariant, NoInfer, NotFunction } from \"./Types.js\"\nimport type * as Unify from \"./Unify.js\"\nimport * as Gen from \"./Utils.js\"\n\n/**\n * The `Option` data type represents optional values. An `Option<A>` can either\n * be `Some<A>`, containing a value of type `A`, or `None`, representing the\n * absence of a value.\n *\n * **When to Use**\n *\n * You can use `Option` in scenarios like:\n *\n * - Using it for initial values\n * - Returning values from functions that are not defined for all possible\n * inputs (referred to as “partial functions”)\n * - Managing optional fields in data structures\n * - Handling optional function arguments\n *\n * @category Models\n * @since 2.0.0\n */\nexport type Option<A> = None<A> | Some<A>\n\n/**\n * @category Symbols\n * @since 2.0.0\n */\nexport const TypeId: unique symbol = Symbol.for(\"effect/Option\")\n\n/**\n * @category Symbols\n * @since 2.0.0\n */\nexport type TypeId = typeof TypeId\n\n/**\n * @category Models\n * @since 2.0.0\n */\nexport interface None<out A> extends Pipeable, Inspectable {\n readonly _tag: \"None\"\n readonly _op: \"None\"\n readonly [TypeId]: {\n readonly _A: Covariant<A>\n }\n [Unify.typeSymbol]?: unknown\n [Unify.unifySymbol]?: OptionUnify<this>\n [Unify.ignoreSymbol]?: OptionUnifyIgnore\n}\n\n/**\n * @category Models\n * @since 2.0.0\n */\nexport interface Some<out A> extends Pipeable, Inspectable {\n readonly _tag: \"Some\"\n readonly _op: \"Some\"\n readonly value: A\n readonly [TypeId]: {\n readonly _A: Covariant<A>\n }\n [Unify.typeSymbol]?: unknown\n [Unify.unifySymbol]?: OptionUnify<this>\n [Unify.ignoreSymbol]?: OptionUnifyIgnore\n}\n\n/**\n * @category Models\n * @since 2.0.0\n */\nexport interface OptionUnify<A extends { [Unify.typeSymbol]?: any }> {\n Option?: () => A[Unify.typeSymbol] extends Option<infer A0> | infer _ ? Option<A0> : never\n}\n\n/**\n * @since 2.0.0\n */\nexport declare namespace Option {\n /**\n * Extracts the type of the value contained in an `Option`.\n *\n * **Example** (Getting the Value Type of an Option)\n *\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Declare an Option holding a string\n * declare const myOption: Option.Option<string>\n *\n * // Extract the type of the value within the Option\n * //\n * // ┌─── string\n * // ▼\n * type MyType = Option.Option.Value<typeof myOption>\n * ```\n *\n * @since 2.0.0\n * @category Type-level Utils\n */\n export type Value<T extends Option<any>> = [T] extends [Option<infer _A>] ? _A : never\n}\n\n/**\n * @category Models\n * @since 2.0.0\n */\nexport interface OptionUnifyIgnore {}\n\n/**\n * @category Type Lambdas\n * @since 2.0.0\n */\nexport interface OptionTypeLambda extends TypeLambda {\n readonly type: Option<this[\"Target\"]>\n}\n\n/**\n * Represents the absence of a value by creating an empty `Option`.\n *\n * `Option.none` returns an `Option<never>`, which is a subtype of `Option<A>`.\n * This means you can use it in place of any `Option<A>` regardless of the type\n * `A`.\n *\n * **Example** (Creating an Option with No Value)\n *\n * ```ts\n * import { Option } from \"effect\"\n *\n * // An Option holding no value\n * //\n * // ┌─── Option<never>\n * // ▼\n * const noValue = Option.none()\n *\n * console.log(noValue)\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @see {@link some} for the opposite operation.\n *\n * @category Constructors\n * @since 2.0.0\n */\nexport const none = <A = never>(): Option<A> => option.none\n\n/**\n * Wraps the given value into an `Option` to represent its presence.\n *\n * **Example** (Creating an Option with a Value)\n *\n * ```ts\n * import { Option } from \"effect\"\n *\n * // An Option holding the number 1\n * //\n * // ┌─── Option<number>\n * // ▼\n * const value = Option.some(1)\n *\n * console.log(value)\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n * ```\n *\n * @see {@link none} for the opposite operation.\n *\n * @category Constructors\n * @since 2.0.0\n */\nexport const some: <A>(value: A) => Option<A> = option.some\n\n/**\n * Determines whether the given value is an `Option`.\n *\n * **Details**\n *\n * This function checks if a value is an instance of `Option`. It returns `true`\n * if the value is either `Option.some` or `Option.none`, and `false` otherwise.\n * This is particularly useful when working with unknown values or when you need\n * to ensure type safety in your code.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.isOption(Option.some(1)))\n * // Output: true\n *\n * console.log(Option.isOption(Option.none()))\n * // Output: true\n *\n * console.log(Option.isOption({}))\n * // Output: false\n * ```\n *\n * @category Guards\n * @since 2.0.0\n */\nexport const isOption: (input: unknown) => input is Option<unknown> = option.isOption\n\n/**\n * Checks whether an `Option` represents the absence of a value (`None`).\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.isNone(Option.some(1)))\n * // Output: false\n *\n * console.log(Option.isNone(Option.none()))\n * // Output: true\n * ```\n *\n * @see {@link isSome} for the opposite check.\n *\n * @category Guards\n * @since 2.0.0\n */\nexport const isNone: <A>(self: Option<A>) => self is None<A> = option.isNone\n\n/**\n * Checks whether an `Option` contains a value (`Some`).\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.isSome(Option.some(1)))\n * // Output: true\n *\n * console.log(Option.isSome(Option.none()))\n * // Output: false\n * ```\n *\n * @see {@link isNone} for the opposite check.\n *\n * @category Guards\n * @since 2.0.0\n */\nexport const isSome: <A>(self: Option<A>) => self is Some<A> = option.isSome\n\n/**\n * Performs pattern matching on an `Option` to handle both `Some` and `None`\n * cases.\n *\n * **Details**\n *\n * This function allows you to match against an `Option` and handle both\n * scenarios: when the `Option` is `None` (i.e., contains no value), and when\n * the `Option` is `Some` (i.e., contains a value). It executes one of the\n * provided functions based on the case:\n *\n * - If the `Option` is `None`, the `onNone` function is executed and its result\n * is returned.\n * - If the `Option` is `Some`, the `onSome` function is executed with the\n * contained value, and its result is returned.\n *\n * This function provides a concise and functional way to handle optional values\n * without resorting to `if` or manual checks, making your code more declarative\n * and readable.\n *\n * **Example** (Pattern Matching with Option)\n *\n * ```ts\n * import { Option } from \"effect\"\n *\n * const foo = Option.some(1)\n *\n * const message = Option.match(foo, {\n * onNone: () => \"Option is empty\",\n * onSome: (value) => `Option has a value: ${value}`\n * })\n *\n * console.log(message)\n * // Output: \"Option has a value: 1\"\n * ```\n *\n * @category Pattern matching\n * @since 2.0.0\n */\nexport const match: {\n /**\n * Performs pattern matching on an `Option` to handle both `Some` and `None`\n * cases.\n *\n * **Details**\n *\n * This function allows you to match against an `Option` and handle both\n * scenarios: when the `Option` is `None` (i.e., contains no value), and when\n * the `Option` is `Some` (i.e., contains a value). It executes one of the\n * provided functions based on the case:\n *\n * - If the `Option` is `None`, the `onNone` function is executed and its result\n * is returned.\n * - If the `Option` is `Some`, the `onSome` function is executed with the\n * contained value, and its result is returned.\n *\n * This function provides a concise and functional way to handle optional values\n * without resorting to `if` or manual checks, making your code more declarative\n * and readable.\n *\n * **Example** (Pattern Matching with Option)\n *\n * ```ts\n * import { Option } from \"effect\"\n *\n * const foo = Option.some(1)\n *\n * const message = Option.match(foo, {\n * onNone: () => \"Option is empty\",\n * onSome: (value) => `Option has a value: ${value}`\n * })\n *\n * console.log(message)\n * // Output: \"Option has a value: 1\"\n * ```\n *\n * @category Pattern matching\n * @since 2.0.0\n */\n <B, A, C = B>(\n options: {\n readonly onNone: LazyArg<B>\n readonly onSome: (a: A) => C\n }\n ): (self: Option<A>) => B | C\n /**\n * Performs pattern matching on an `Option` to handle both `Some` and `None`\n * cases.\n *\n * **Details**\n *\n * This function allows you to match against an `Option` and handle both\n * scenarios: when the `Option` is `None` (i.e., contains no value), and when\n * the `Option` is `Some` (i.e., contains a value). It executes one of the\n * provided functions based on the case:\n *\n * - If the `Option` is `None`, the `onNone` function is executed and its result\n * is returned.\n * - If the `Option` is `Some`, the `onSome` function is executed with the\n * contained value, and its result is returned.\n *\n * This function provides a concise and functional way to handle optional values\n * without resorting to `if` or manual checks, making your code more declarative\n * and readable.\n *\n * **Example** (Pattern Matching with Option)\n *\n * ```ts\n * import { Option } from \"effect\"\n *\n * const foo = Option.some(1)\n *\n * const message = Option.match(foo, {\n * onNone: () => \"Option is empty\",\n * onSome: (value) => `Option has a value: ${value}`\n * })\n *\n * console.log(message)\n * // Output: \"Option has a value: 1\"\n * ```\n *\n * @category Pattern matching\n * @since 2.0.0\n */\n <A, B, C = B>(\n self: Option<A>,\n options: {\n readonly onNone: LazyArg<B>\n readonly onSome: (a: A) => C\n }\n ): B | C\n} = dual(\n 2,\n <A, B, C = B>(self: Option<A>, { onNone, onSome }: {\n readonly onNone: LazyArg<B>\n readonly onSome: (a: A) => C\n }): B | C => isNone(self) ? onNone() : onSome(self.value)\n)\n\n/**\n * Converts an `Option`-returning function into a type guard.\n *\n * **Details**\n *\n * This function transforms a function that returns an `Option` into a type\n * guard, ensuring type safety when validating or narrowing types. The returned\n * type guard function checks whether the input satisfies the condition defined\n * in the original `Option`-returning function.\n *\n * If the original function returns `Option.some`, the type guard evaluates to\n * `true`, confirming the input is of the desired type. If the function returns\n * `Option.none`, the type guard evaluates to `false`.\n *\n * This utility is especially useful for validating types in union types,\n * filtering arrays, or ensuring safe handling of specific subtypes.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * type MyData = string | number\n *\n * const parseString = (data: MyData): Option.Option<string> =>\n * typeof data === \"string\" ? Option.some(data) : Option.none()\n *\n * // ┌─── (a: MyData) => a is string\n * // ▼\n * const isString = Option.toRefinement(parseString)\n *\n * console.log(isString(\"a\"))\n * // Output: true\n *\n * console.log(isString(1))\n * // Output: false\n * ```\n *\n * @category Conversions\n * @since 2.0.0\n */\nexport const toRefinement = <A, B extends A>(f: (a: A) => Option<B>): (a: A) => a is B => (a: A): a is B => isSome(f(a))\n\n/**\n * Converts an `Iterable` into an `Option`, wrapping the first element if it\n * exists.\n *\n * **Details**\n *\n * This function takes an `Iterable` (e.g., an array, a generator, or any object\n * implementing the `Iterable` interface) and returns an `Option` based on its\n * content:\n *\n * - If the `Iterable` contains at least one element, the first element is\n * wrapped in a `Some` and returned.\n * - If the `Iterable` is empty, `None` is returned, representing the absence of\n * a value.\n *\n * This utility is useful for safely handling collections that might be empty,\n * ensuring you explicitly handle both cases where a value exists or doesn't.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.fromIterable([1, 2, 3]))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(Option.fromIterable([]))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Constructors\n * @since 2.0.0\n */\nexport const fromIterable = <A>(collection: Iterable<A>): Option<A> => {\n for (const a of collection) {\n return some(a)\n }\n return none()\n}\n\n/**\n * Converts an `Either` into an `Option` by discarding the error and extracting\n * the right value.\n *\n * **Details**\n *\n * This function takes an `Either` and returns an `Option` based on its value:\n *\n * - If the `Either` is a `Right`, its value is wrapped in a `Some` and\n * returned.\n * - If the `Either` is a `Left`, the error is discarded, and `None` is\n * returned.\n *\n * This is particularly useful when you only care about the success case\n * (`Right`) of an `Either` and want to handle the result using `Option`. By\n * using this function, you can convert `Either` into a simpler structure for\n * cases where error handling is not required.\n *\n * @example\n * ```ts\n * import { Either, Option } from \"effect\"\n *\n * console.log(Option.getRight(Either.right(\"ok\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'ok' }\n *\n * console.log(Option.getRight(Either.left(\"err\")))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @see {@link getLeft} for the opposite operation.\n *\n * @category Conversions\n * @since 2.0.0\n */\nexport const getRight: <R, L>(self: Either<R, L>) => Option<R> = either.getRight\n\n/**\n * Converts an `Either` into an `Option` by discarding the right value and\n * extracting the left value.\n *\n * **Details**\n *\n * This function transforms an `Either` into an `Option` as follows:\n *\n * - If the `Either` is a `Left`, its value is wrapped in a `Some` and returned.\n * - If the `Either` is a `Right`, the value is discarded, and `None` is\n * returned.\n *\n * This utility is useful when you only care about the error case (`Left`) of an\n * `Either` and want to handle it as an `Option`. By discarding the right value,\n * it simplifies error-focused workflows.\n *\n * @example\n * ```ts\n * import { Either, Option } from \"effect\"\n *\n * console.log(Option.getLeft(Either.right(\"ok\")))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(Option.getLeft(Either.left(\"err\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'err' }\n * ```\n *\n * @see {@link getRight} for the opposite operation.\n *\n * @category Conversions\n * @since 2.0.0\n */\nexport const getLeft: <R, L>(self: Either<R, L>) => Option<L> = either.getLeft\n\n/**\n * Returns the value contained in the `Option` if it is `Some`, otherwise\n * evaluates and returns the result of `onNone`.\n *\n * **Details**\n *\n * This function allows you to provide a fallback value or computation for when\n * an `Option` is `None`. If the `Option` contains a value (`Some`), that value\n * is returned. If it is empty (`None`), the `onNone` function is executed, and\n * its result is returned instead.\n *\n * This utility is helpful for safely handling `Option` values by ensuring you\n * always receive a meaningful result, whether or not the `Option` contains a\n * value. It is particularly useful for providing default values or alternative\n * logic when working with optional values.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.some(1).pipe(Option.getOrElse(() => 0)))\n * // Output: 1\n *\n * console.log(Option.none().pipe(Option.getOrElse(() => 0)))\n * // Output: 0\n * ```\n *\n * @see {@link getOrNull} for a version that returns `null` instead of executing a function.\n * @see {@link getOrUndefined} for a version that returns `undefined` instead of executing a function.\n *\n * @category Getters\n * @since 2.0.0\n */\nexport const getOrElse: {\n /**\n * Returns the value contained in the `Option` if it is `Some`, otherwise\n * evaluates and returns the result of `onNone`.\n *\n * **Details**\n *\n * This function allows you to provide a fallback value or computation for when\n * an `Option` is `None`. If the `Option` contains a value (`Some`), that value\n * is returned. If it is empty (`None`), the `onNone` function is executed, and\n * its result is returned instead.\n *\n * This utility is helpful for safely handling `Option` values by ensuring you\n * always receive a meaningful result, whether or not the `Option` contains a\n * value. It is particularly useful for providing default values or alternative\n * logic when working with optional values.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.some(1).pipe(Option.getOrElse(() => 0)))\n * // Output: 1\n *\n * console.log(Option.none().pipe(Option.getOrElse(() => 0)))\n * // Output: 0\n * ```\n *\n * @see {@link getOrNull} for a version that returns `null` instead of executing a function.\n * @see {@link getOrUndefined} for a version that returns `undefined` instead of executing a function.\n *\n * @category Getters\n * @since 2.0.0\n */\n <B>(onNone: LazyArg<B>): <A>(self: Option<A>) => B | A\n /**\n * Returns the value contained in the `Option` if it is `Some`, otherwise\n * evaluates and returns the result of `onNone`.\n *\n * **Details**\n *\n * This function allows you to provide a fallback value or computation for when\n * an `Option` is `None`. If the `Option` contains a value (`Some`), that value\n * is returned. If it is empty (`None`), the `onNone` function is executed, and\n * its result is returned instead.\n *\n * This utility is helpful for safely handling `Option` values by ensuring you\n * always receive a meaningful result, whether or not the `Option` contains a\n * value. It is particularly useful for providing default values or alternative\n * logic when working with optional values.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.some(1).pipe(Option.getOrElse(() => 0)))\n * // Output: 1\n *\n * console.log(Option.none().pipe(Option.getOrElse(() => 0)))\n * // Output: 0\n * ```\n *\n * @see {@link getOrNull} for a version that returns `null` instead of executing a function.\n * @see {@link getOrUndefined} for a version that returns `undefined` instead of executing a function.\n *\n * @category Getters\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, onNone: LazyArg<B>): A | B\n} = dual(\n 2,\n <A, B>(self: Option<A>, onNone: LazyArg<B>): A | B => isNone(self) ? onNone() : self.value\n)\n\n/**\n * Returns the provided `Option` `that` if the current `Option` (`self`) is\n * `None`; otherwise, it returns `self`.\n *\n * **Details**\n *\n * This function provides a fallback mechanism for `Option` values. If the\n * current `Option` is `None` (i.e., it contains no value), the `that` function\n * is evaluated, and its resulting `Option` is returned. If the current `Option`\n * is `Some` (i.e., it contains a value), the original `Option` is returned\n * unchanged.\n *\n * This is particularly useful for chaining fallback values or computations,\n * allowing you to provide alternative `Option` values when the first one is\n * empty.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.none().pipe(Option.orElse(() => Option.none())))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(Option.some(\"a\").pipe(Option.orElse(() => Option.none())))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n *\n * console.log(Option.none().pipe(Option.orElse(() => Option.some(\"b\"))))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'b' }\n *\n * console.log(Option.some(\"a\").pipe(Option.orElse(() => Option.some(\"b\"))))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n * ```\n *\n * @category Error handling\n * @since 2.0.0\n */\nexport const orElse: {\n /**\n * Returns the provided `Option` `that` if the current `Option` (`self`) is\n * `None`; otherwise, it returns `self`.\n *\n * **Details**\n *\n * This function provides a fallback mechanism for `Option` values. If the\n * current `Option` is `None` (i.e., it contains no value), the `that` function\n * is evaluated, and its resulting `Option` is returned. If the current `Option`\n * is `Some` (i.e., it contains a value), the original `Option` is returned\n * unchanged.\n *\n * This is particularly useful for chaining fallback values or computations,\n * allowing you to provide alternative `Option` values when the first one is\n * empty.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.none().pipe(Option.orElse(() => Option.none())))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(Option.some(\"a\").pipe(Option.orElse(() => Option.none())))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n *\n * console.log(Option.none().pipe(Option.orElse(() => Option.some(\"b\"))))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'b' }\n *\n * console.log(Option.some(\"a\").pipe(Option.orElse(() => Option.some(\"b\"))))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n * ```\n *\n * @category Error handling\n * @since 2.0.0\n */\n <B>(that: LazyArg<Option<B>>): <A>(self: Option<A>) => Option<B | A>\n /**\n * Returns the provided `Option` `that` if the current `Option` (`self`) is\n * `None`; otherwise, it returns `self`.\n *\n * **Details**\n *\n * This function provides a fallback mechanism for `Option` values. If the\n * current `Option` is `None` (i.e., it contains no value), the `that` function\n * is evaluated, and its resulting `Option` is returned. If the current `Option`\n * is `Some` (i.e., it contains a value), the original `Option` is returned\n * unchanged.\n *\n * This is particularly useful for chaining fallback values or computations,\n * allowing you to provide alternative `Option` values when the first one is\n * empty.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.none().pipe(Option.orElse(() => Option.none())))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(Option.some(\"a\").pipe(Option.orElse(() => Option.none())))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n *\n * console.log(Option.none().pipe(Option.orElse(() => Option.some(\"b\"))))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'b' }\n *\n * console.log(Option.some(\"a\").pipe(Option.orElse(() => Option.some(\"b\"))))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n * ```\n *\n * @category Error handling\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<A | B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<A | B> => isNone(self) ? that() : self\n)\n\n/**\n * Returns the provided default value wrapped in `Some` if the current `Option`\n * (`self`) is `None`; otherwise, returns `self`.\n *\n * **Details**\n *\n * This function provides a way to supply a default value for cases where an\n * `Option` is `None`. If the current `Option` is empty (`None`), the `onNone`\n * function is executed to compute the default value, which is then wrapped in a\n * `Some`. If the current `Option` contains a value (`Some`), it is returned as\n * is.\n *\n * This is particularly useful for handling optional values where a fallback\n * default needs to be provided explicitly in case of absence.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.none().pipe(Option.orElseSome(() => \"b\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'b' }\n *\n * console.log(Option.some(\"a\").pipe(Option.orElseSome(() => \"b\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n * ```\n *\n * @category Error handling\n * @since 2.0.0\n */\nexport const orElseSome: {\n /**\n * Returns the provided default value wrapped in `Some` if the current `Option`\n * (`self`) is `None`; otherwise, returns `self`.\n *\n * **Details**\n *\n * This function provides a way to supply a default value for cases where an\n * `Option` is `None`. If the current `Option` is empty (`None`), the `onNone`\n * function is executed to compute the default value, which is then wrapped in a\n * `Some`. If the current `Option` contains a value (`Some`), it is returned as\n * is.\n *\n * This is particularly useful for handling optional values where a fallback\n * default needs to be provided explicitly in case of absence.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.none().pipe(Option.orElseSome(() => \"b\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'b' }\n *\n * console.log(Option.some(\"a\").pipe(Option.orElseSome(() => \"b\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n * ```\n *\n * @category Error handling\n * @since 2.0.0\n */\n <B>(onNone: LazyArg<B>): <A>(self: Option<A>) => Option<B | A>\n /**\n * Returns the provided default value wrapped in `Some` if the current `Option`\n * (`self`) is `None`; otherwise, returns `self`.\n *\n * **Details**\n *\n * This function provides a way to supply a default value for cases where an\n * `Option` is `None`. If the current `Option` is empty (`None`), the `onNone`\n * function is executed to compute the default value, which is then wrapped in a\n * `Some`. If the current `Option` contains a value (`Some`), it is returned as\n * is.\n *\n * This is particularly useful for handling optional values where a fallback\n * default needs to be provided explicitly in case of absence.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.none().pipe(Option.orElseSome(() => \"b\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'b' }\n *\n * console.log(Option.some(\"a\").pipe(Option.orElseSome(() => \"b\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n * ```\n *\n * @category Error handling\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, onNone: LazyArg<B>): Option<A | B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, onNone: LazyArg<B>): Option<A | B> => isNone(self) ? some(onNone()) : self\n)\n\n/**\n * Similar to {@link orElse}, but returns an `Either` wrapped in an `Option` to\n * indicate the source of the value.\n *\n * **Details**\n *\n * This function allows you to provide a fallback `Option` in case the current\n * `Option` (`self`) is `None`. However, unlike `orElse`, it returns the value\n * wrapped in an `Either` object, providing additional information about where\n * the value came from:\n *\n * - If the value is from the fallback `Option` (`that`), it is wrapped in an\n * `Either.right`.\n * - If the value is from the original `Option` (`self`), it is wrapped in an\n * `Either.left`.\n *\n * This is especially useful when you need to differentiate between values\n * originating from the primary `Option` and those coming from the fallback,\n * while still maintaining the `Option`-style handling.\n *\n * @category Error handling\n * @since 2.0.0\n */\nexport const orElseEither: {\n /**\n * Similar to {@link orElse}, but returns an `Either` wrapped in an `Option` to\n * indicate the source of the value.\n *\n * **Details**\n *\n * This function allows you to provide a fallback `Option` in case the current\n * `Option` (`self`) is `None`. However, unlike `orElse`, it returns the value\n * wrapped in an `Either` object, providing additional information about where\n * the value came from:\n *\n * - If the value is from the fallback `Option` (`that`), it is wrapped in an\n * `Either.right`.\n * - If the value is from the original `Option` (`self`), it is wrapped in an\n * `Either.left`.\n *\n * This is especially useful when you need to differentiate between values\n * originating from the primary `Option` and those coming from the fallback,\n * while still maintaining the `Option`-style handling.\n *\n * @category Error handling\n * @since 2.0.0\n */\n <B>(that: LazyArg<Option<B>>): <A>(self: Option<A>) => Option<Either<B, A>>\n /**\n * Similar to {@link orElse}, but returns an `Either` wrapped in an `Option` to\n * indicate the source of the value.\n *\n * **Details**\n *\n * This function allows you to provide a fallback `Option` in case the current\n * `Option` (`self`) is `None`. However, unlike `orElse`, it returns the value\n * wrapped in an `Either` object, providing additional information about where\n * the value came from:\n *\n * - If the value is from the fallback `Option` (`that`), it is wrapped in an\n * `Either.right`.\n * - If the value is from the original `Option` (`self`), it is wrapped in an\n * `Either.left`.\n *\n * This is especially useful when you need to differentiate between values\n * originating from the primary `Option` and those coming from the fallback,\n * while still maintaining the `Option`-style handling.\n *\n * @category Error handling\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<Either<B, A>>\n} = dual(\n 2,\n <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<Either<B, A>> =>\n isNone(self) ? map(that(), either.right) : map(self, either.left)\n)\n\n/**\n * Returns the first `Some` value found in an `Iterable` collection of\n * `Option`s, or `None` if no `Some` is found.\n *\n * **Details**\n *\n * This function iterates over a collection of `Option` values and returns the\n * first `Some` it encounters. If the collection contains only `None` values,\n * the result will also be `None`. This utility is useful for efficiently\n * finding the first valid value in a sequence of potentially empty or invalid\n * options.\n *\n * The iteration stops as soon as a `Some` is found, making this function\n * efficient for large collections.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.firstSomeOf([\n * Option.none(),\n * Option.some(1),\n * Option.some(2)\n * ]))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n * ```\n *\n * @category Error handling\n * @since 2.0.0\n */\nexport const firstSomeOf = <T, C extends Iterable<Option<T>> = Iterable<Option<T>>>(\n collection: C\n): [C] extends [Iterable<Option<infer A>>] ? Option<A> : never => {\n let out: Option<unknown> = none()\n for (out of collection) {\n if (isSome(out)) {\n return out as any\n }\n }\n return out as any\n}\n\n/**\n * Converts a nullable value into an `Option`. Returns `None` if the value is\n * `null` or `undefined`, otherwise wraps the value in a `Some`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.fromNullable(undefined))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(Option.fromNullable(null))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(Option.fromNullable(1))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n * ```\n *\n * @category Conversions\n * @since 2.0.0\n */\nexport const fromNullable = <A>(\n nullableValue: A\n): Option<NonNullable<A>> => (nullableValue == null ? none() : some(nullableValue as NonNullable<A>))\n\n/**\n * Lifts a function that returns `null` or `undefined` into the `Option`\n * context.\n *\n * **Details**\n *\n * This function takes a function `f` that might return `null` or `undefined`\n * and transforms it into a function that returns an `Option`. The resulting\n * function will return:\n * - `Some` if the original function produces a non-null, non-undefined value.\n * - `None` if the original function produces `null` or `undefined`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const parse = (s: string): number | undefined => {\n * const n = parseFloat(s)\n * return isNaN(n) ? undefined : n\n * }\n *\n * const parseOption = Option.liftNullable(parse)\n *\n * console.log(parseOption(\"1\"))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(parseOption(\"not a number\"))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Conversions\n * @since 2.0.0\n */\nexport const liftNullable = <A extends ReadonlyArray<unknown>, B>(\n f: (...a: A) => B | null | undefined\n): (...a: A) => Option<NonNullable<B>> =>\n(...a) => fromNullable(f(...a))\n\n/**\n * Returns the value contained in the `Option` if it is `Some`; otherwise,\n * returns `null`.\n *\n * **Details**\n *\n * This function provides a way to extract the value of an `Option` while\n * falling back to `null` if the `Option` is `None`.\n *\n * It is particularly useful in scenarios where `null` is an acceptable\n * placeholder for the absence of a value, such as when interacting with APIs or\n * systems that use `null` as a default for missing values.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.getOrNull(Option.some(1)))\n * // Output: 1\n *\n * console.log(Option.getOrNull(Option.none()))\n * // Output: null\n * ```\n *\n * @category Getters\n * @since 2.0.0\n */\nexport const getOrNull: <A>(self: Option<A>) => A | null = getOrElse(constNull)\n\n/**\n * Returns the value contained in the `Option` if it is `Some`; otherwise,\n * returns `undefined`.\n *\n * **Details**\n *\n * This function provides a way to extract the value of an `Option` while\n * falling back to `undefined` if the `Option` is `None`.\n *\n * It is particularly useful in scenarios where `undefined` is an acceptable\n * placeholder for the absence of a value, such as when interacting with APIs or\n * systems that use `undefined` as a default for missing values.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.getOrUndefined(Option.some(1)))\n * // Output: 1\n *\n * console.log(Option.getOrUndefined(Option.none()))\n * // Output: undefined\n * ```\n *\n * @category Getters\n * @since 2.0.0\n */\nexport const getOrUndefined: <A>(self: Option<A>) => A | undefined = getOrElse(constUndefined)\n\n/**\n * Lifts a function that throws exceptions into a function that returns an\n * `Option`.\n *\n * **Details**\n *\n * This utility function takes a function `f` that might throw an exception and\n * transforms it into a safer function that returns an `Option`. If the original\n * function executes successfully, the result is wrapped in a `Some`. If an\n * exception is thrown, the result is `None`, allowing the developer to handle\n * errors in a functional, type-safe way.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const parse = Option.liftThrowable(JSON.parse)\n *\n * console.log(parse(\"1\"))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(parse(\"\"))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Conversions\n * @since 2.0.0\n */\nexport const liftThrowable = <A extends ReadonlyArray<unknown>, B>(\n f: (...a: A) => B\n): (...a: A) => Option<B> =>\n(...a) => {\n try {\n return some(f(...a))\n } catch {\n return none()\n }\n}\n\n/**\n * Extracts the value of an `Option` or throws an error if the `Option` is\n * `None`, using a custom error factory.\n *\n * **Details**\n *\n * This function allows you to extract the value of an `Option` when it is\n * `Some`. If the `Option` is `None`, it throws an error generated by the\n * provided `onNone` function. This utility is particularly useful when you need\n * a fail-fast behavior for empty `Option` values and want to provide a custom\n * error message or object.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Option.getOrThrowWith(Option.some(1), () => new Error('Unexpected None')),\n * 1\n * )\n * assert.throws(() => Option.getOrThrowWith(Option.none(), () => new Error('Unexpected None')))\n * ```\n *\n * @see {@link getOrThrow} for a version that throws a default error.\n *\n * @category Conversions\n * @since 2.0.0\n */\nexport const getOrThrowWith: {\n /**\n * Extracts the value of an `Option` or throws an error if the `Option` is\n * `None`, using a custom error factory.\n *\n * **Details**\n *\n * This function allows you to extract the value of an `Option` when it is\n * `Some`. If the `Option` is `None`, it throws an error generated by the\n * provided `onNone` function. This utility is particularly useful when you need\n * a fail-fast behavior for empty `Option` values and want to provide a custom\n * error message or object.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Option.getOrThrowWith(Option.some(1), () => new Error('Unexpected None')),\n * 1\n * )\n * assert.throws(() => Option.getOrThrowWith(Option.none(), () => new Error('Unexpected None')))\n * ```\n *\n * @see {@link getOrThrow} for a version that throws a default error.\n *\n * @category Conversions\n * @since 2.0.0\n */\n (onNone: () => unknown): <A>(self: Option<A>) => A\n /**\n * Extracts the value of an `Option` or throws an error if the `Option` is\n * `None`, using a custom error factory.\n *\n * **Details**\n *\n * This function allows you to extract the value of an `Option` when it is\n * `Some`. If the `Option` is `None`, it throws an error generated by the\n * provided `onNone` function. This utility is particularly useful when you need\n * a fail-fast behavior for empty `Option` values and want to provide a custom\n * error message or object.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(\n * Option.getOrThrowWith(Option.some(1), () => new Error('Unexpected None')),\n * 1\n * )\n * assert.throws(() => Option.getOrThrowWith(Option.none(), () => new Error('Unexpected None')))\n * ```\n *\n * @see {@link getOrThrow} for a version that throws a default error.\n *\n * @category Conversions\n * @since 2.0.0\n */\n <A>(self: Option<A>, onNone: () => unknown): A\n} = dual(2, <A>(self: Option<A>, onNone: () => unknown): A => {\n if (isSome(self)) {\n return self.value\n }\n throw onNone()\n})\n\n/**\n * Extracts the value of an `Option` or throws a default error if the `Option`\n * is `None`.\n *\n * **Details**\n *\n * This function extracts the value from an `Option` if it is `Some`. If the\n * `Option` is `None`, it throws a default error. It is useful for fail-fast\n * scenarios where the absence of a value is treated as an exceptional case and\n * a default error is sufficient.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Option } from \"effect\"\n *\n * assert.deepStrictEqual(Option.getOrThrow(Option.some(1)), 1)\n * assert.throws(() => Option.getOrThrow(Option.none()))\n * ```\n *\n * @see {@link getOrThrowWith} for a version that allows you to provide a custom error.\n *\n * @category Conversions\n * @since 2.0.0\n */\nexport const getOrThrow: <A>(self: Option<A>) => A = getOrThrowWith(() => new Error(\"getOrThrow called on a None\"))\n\n/**\n * Transforms the value inside a `Some` to a new value using the provided\n * function, while leaving `None` unchanged.\n *\n * **Details**\n *\n * This function applies a mapping function `f` to the value inside an `Option`\n * if it is a `Some`. If the `Option` is `None`, it remains unchanged. The\n * result is a new `Option` with the transformed value (if it was a `Some`) or\n * still `None`.\n *\n * This utility is particularly useful for chaining transformations in a\n * functional way without needing to manually handle `None` cases.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Mapping over a `Some`\n * const someValue = Option.some(2)\n *\n * console.log(Option.map(someValue, (n) => n * 2))\n * // Output: { _id: 'Option', _tag: 'Some', value: 4 }\n *\n * // Mapping over a `None`\n * const noneValue = Option.none<number>()\n *\n * console.log(Option.map(noneValue, (n) => n * 2))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Mapping\n * @since 2.0.0\n */\nexport const map: {\n /**\n * Transforms the value inside a `Some` to a new value using the provided\n * function, while leaving `None` unchanged.\n *\n * **Details**\n *\n * This function applies a mapping function `f` to the value inside an `Option`\n * if it is a `Some`. If the `Option` is `None`, it remains unchanged. The\n * result is a new `Option` with the transformed value (if it was a `Some`) or\n * still `None`.\n *\n * This utility is particularly useful for chaining transformations in a\n * functional way without needing to manually handle `None` cases.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Mapping over a `Some`\n * const someValue = Option.some(2)\n *\n * console.log(Option.map(someValue, (n) => n * 2))\n * // Output: { _id: 'Option', _tag: 'Some', value: 4 }\n *\n * // Mapping over a `None`\n * const noneValue = Option.none<number>()\n *\n * console.log(Option.map(noneValue, (n) => n * 2))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Mapping\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B): (self: Option<A>) => Option<B>\n /**\n * Transforms the value inside a `Some` to a new value using the provided\n * function, while leaving `None` unchanged.\n *\n * **Details**\n *\n * This function applies a mapping function `f` to the value inside an `Option`\n * if it is a `Some`. If the `Option` is `None`, it remains unchanged. The\n * result is a new `Option` with the transformed value (if it was a `Some`) or\n * still `None`.\n *\n * This utility is particularly useful for chaining transformations in a\n * functional way without needing to manually handle `None` cases.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Mapping over a `Some`\n * const someValue = Option.some(2)\n *\n * console.log(Option.map(someValue, (n) => n * 2))\n * // Output: { _id: 'Option', _tag: 'Some', value: 4 }\n *\n * // Mapping over a `None`\n * const noneValue = Option.none<number>()\n *\n * console.log(Option.map(noneValue, (n) => n * 2))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Mapping\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => B): Option<B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => B): Option<B> => isNone(self) ? none() : some(f(self.value))\n)\n\n/**\n * Replaces the value inside a `Some` with the specified constant value, leaving\n * `None` unchanged.\n *\n * **Details**\n *\n * This function transforms an `Option` by replacing the value inside a `Some`\n * with the given constant value `b`. If the `Option` is `None`, it remains\n * unchanged.\n *\n * This is useful when you want to preserve the presence of a value (`Some`) but\n * replace its content with a fixed value.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Replacing the value of a `Some`\n * const someValue = Option.some(42)\n *\n * console.log(Option.as(someValue, \"new value\"))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'new value' }\n *\n * // Replacing a `None` (no effect)\n * const noneValue = Option.none<number>()\n *\n * console.log(Option.as(noneValue, \"new value\"))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Mapping\n * @since 2.0.0\n */\nexport const as: {\n /**\n * Replaces the value inside a `Some` with the specified constant value, leaving\n * `None` unchanged.\n *\n * **Details**\n *\n * This function transforms an `Option` by replacing the value inside a `Some`\n * with the given constant value `b`. If the `Option` is `None`, it remains\n * unchanged.\n *\n * This is useful when you want to preserve the presence of a value (`Some`) but\n * replace its content with a fixed value.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Replacing the value of a `Some`\n * const someValue = Option.some(42)\n *\n * console.log(Option.as(someValue, \"new value\"))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'new value' }\n *\n * // Replacing a `None` (no effect)\n * const noneValue = Option.none<number>()\n *\n * console.log(Option.as(noneValue, \"new value\"))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Mapping\n * @since 2.0.0\n */\n <B>(b: B): <X>(self: Option<X>) => Option<B>\n /**\n * Replaces the value inside a `Some` with the specified constant value, leaving\n * `None` unchanged.\n *\n * **Details**\n *\n * This function transforms an `Option` by replacing the value inside a `Some`\n * with the given constant value `b`. If the `Option` is `None`, it remains\n * unchanged.\n *\n * This is useful when you want to preserve the presence of a value (`Some`) but\n * replace its content with a fixed value.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Replacing the value of a `Some`\n * const someValue = Option.some(42)\n *\n * console.log(Option.as(someValue, \"new value\"))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'new value' }\n *\n * // Replacing a `None` (no effect)\n * const noneValue = Option.none<number>()\n *\n * console.log(Option.as(noneValue, \"new value\"))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Mapping\n * @since 2.0.0\n */\n <X, B>(self: Option<X>, b: B): Option<B>\n} = dual(2, <X, B>(self: Option<X>, b: B): Option<B> => map(self, () => b))\n\n/**\n * Replaces the value inside a `Some` with the constant value `void`, leaving\n * `None` unchanged.\n *\n * **Details**\n *\n * This function transforms an `Option` by replacing the value inside a `Some`\n * with `void`. If the `Option` is `None`, it remains unchanged.\n *\n * This is particularly useful in scenarios where the presence or absence of a\n * value is significant, but the actual content of the value is irrelevant.\n *\n * @category Mapping\n * @since 2.0.0\n */\nexport const asVoid: <_>(self: Option<_>) => Option<void> = as(undefined)\n\nconst void_: Option<void> = some(undefined)\nexport {\n /**\n * @since 2.0.0\n */\n void_ as void\n}\n\n/**\n * Applies a function to the value of a `Some` and flattens the resulting\n * `Option`. If the input is `None`, it remains `None`.\n *\n * **Details**\n *\n * This function allows you to chain computations that return `Option` values.\n * If the input `Option` is `Some`, the provided function `f` is applied to the\n * contained value, and the resulting `Option` is returned. If the input is\n * `None`, the function is not applied, and the result remains `None`.\n *\n * This utility is particularly useful for sequencing operations that may fail\n * or produce optional results, enabling clean and concise workflows for\n * handling such cases.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * interface Address {\n * readonly city: string\n * readonly street: Option.Option<string>\n * }\n *\n * interface User {\n * readonly id: number\n * readonly username: string\n * readonly email: Option.Option<string>\n * readonly address: Option.Option<Address>\n * }\n *\n * const user: User = {\n * id: 1,\n * username: \"john_doe\",\n * email: Option.some(\"john.doe@example.com\"),\n * address: Option.some({\n * city: \"New York\",\n * street: Option.some(\"123 Main St\")\n * })\n * }\n *\n * // Use flatMap to extract the street value\n * const street = user.address.pipe(\n * Option.flatMap((address) => address.street)\n * )\n *\n * console.log(street)\n * // Output: { _id: 'Option', _tag: 'Some', value: '123 Main St' }\n * ```\n *\n * @category Sequencing\n * @since 2.0.0\n */\nexport const flatMap: {\n /**\n * Applies a function to the value of a `Some` and flattens the resulting\n * `Option`. If the input is `None`, it remains `None`.\n *\n * **Details**\n *\n * This function allows you to chain computations that return `Option` values.\n * If the input `Option` is `Some`, the provided function `f` is applied to the\n * contained value, and the resulting `Option` is returned. If the input is\n * `None`, the function is not applied, and the result remains `None`.\n *\n * This utility is particularly useful for sequencing operations that may fail\n * or produce optional results, enabling clean and concise workflows for\n * handling such cases.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * interface Address {\n * readonly city: string\n * readonly street: Option.Option<string>\n * }\n *\n * interface User {\n * readonly id: number\n * readonly username: string\n * readonly email: Option.Option<string>\n * readonly address: Option.Option<Address>\n * }\n *\n * const user: User = {\n * id: 1,\n * username: \"john_doe\",\n * email: Option.some(\"john.doe@example.com\"),\n * address: Option.some({\n * city: \"New York\",\n * street: Option.some(\"123 Main St\")\n * })\n * }\n *\n * // Use flatMap to extract the street value\n * const street = user.address.pipe(\n * Option.flatMap((address) => address.street)\n * )\n *\n * console.log(street)\n * // Output: { _id: 'Option', _tag: 'Some', value: '123 Main St' }\n * ```\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => Option<B>): (self: Option<A>) => Option<B>\n /**\n * Applies a function to the value of a `Some` and flattens the resulting\n * `Option`. If the input is `None`, it remains `None`.\n *\n * **Details**\n *\n * This function allows you to chain computations that return `Option` values.\n * If the input `Option` is `Some`, the provided function `f` is applied to the\n * contained value, and the resulting `Option` is returned. If the input is\n * `None`, the function is not applied, and the result remains `None`.\n *\n * This utility is particularly useful for sequencing operations that may fail\n * or produce optional results, enabling clean and concise workflows for\n * handling such cases.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * interface Address {\n * readonly city: string\n * readonly street: Option.Option<string>\n * }\n *\n * interface User {\n * readonly id: number\n * readonly username: string\n * readonly email: Option.Option<string>\n * readonly address: Option.Option<Address>\n * }\n *\n * const user: User = {\n * id: 1,\n * username: \"john_doe\",\n * email: Option.some(\"john.doe@example.com\"),\n * address: Option.some({\n * city: \"New York\",\n * street: Option.some(\"123 Main St\")\n * })\n * }\n *\n * // Use flatMap to extract the street value\n * const street = user.address.pipe(\n * Option.flatMap((address) => address.street)\n * )\n *\n * console.log(street)\n * // Output: { _id: 'Option', _tag: 'Some', value: '123 Main St' }\n * ```\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B> => isNone(self) ? none() : f(self.value)\n)\n\n/**\n * Chains two `Option`s together. The second `Option` can either be a static\n * value or depend on the result of the first `Option`.\n *\n * **Details**\n *\n * This function enables sequencing of two `Option` computations. If the first\n * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can\n * either:\n *\n * - Be a static `Option` value.\n * - Be a function that produces an `Option`, optionally based on the value of\n * the first `Option`.\n *\n * If the first `Option` is `None`, the function skips the evaluation of the\n * second `Option` and directly returns `None`.\n *\n * @category Sequencing\n * @since 2.0.0\n */\nexport const andThen: {\n /**\n * Chains two `Option`s together. The second `Option` can either be a static\n * value or depend on the result of the first `Option`.\n *\n * **Details**\n *\n * This function enables sequencing of two `Option` computations. If the first\n * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can\n * either:\n *\n * - Be a static `Option` value.\n * - Be a function that produces an `Option`, optionally based on the value of\n * the first `Option`.\n *\n * If the first `Option` is `None`, the function skips the evaluation of the\n * second `Option` and directly returns `None`.\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => Option<B>): (self: Option<A>) => Option<B>\n /**\n * Chains two `Option`s together. The second `Option` can either be a static\n * value or depend on the result of the first `Option`.\n *\n * **Details**\n *\n * This function enables sequencing of two `Option` computations. If the first\n * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can\n * either:\n *\n * - Be a static `Option` value.\n * - Be a function that produces an `Option`, optionally based on the value of\n * the first `Option`.\n *\n * If the first `Option` is `None`, the function skips the evaluation of the\n * second `Option` and directly returns `None`.\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <B>(f: Option<B>): <A>(self: Option<A>) => Option<B>\n /**\n * Chains two `Option`s together. The second `Option` can either be a static\n * value or depend on the result of the first `Option`.\n *\n * **Details**\n *\n * This function enables sequencing of two `Option` computations. If the first\n * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can\n * either:\n *\n * - Be a static `Option` value.\n * - Be a function that produces an `Option`, optionally based on the value of\n * the first `Option`.\n *\n * If the first `Option` is `None`, the function skips the evaluation of the\n * second `Option` and directly returns `None`.\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B): (self: Option<A>) => Option<B>\n /**\n * Chains two `Option`s together. The second `Option` can either be a static\n * value or depend on the result of the first `Option`.\n *\n * **Details**\n *\n * This function enables sequencing of two `Option` computations. If the first\n * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can\n * either:\n *\n * - Be a static `Option` value.\n * - Be a function that produces an `Option`, optionally based on the value of\n * the first `Option`.\n *\n * If the first `Option` is `None`, the function skips the evaluation of the\n * second `Option` and directly returns `None`.\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <B>(f: NotFunction<B>): <A>(self: Option<A>) => Option<B>\n /**\n * Chains two `Option`s together. The second `Option` can either be a static\n * value or depend on the result of the first `Option`.\n *\n * **Details**\n *\n * This function enables sequencing of two `Option` computations. If the first\n * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can\n * either:\n *\n * - Be a static `Option` value.\n * - Be a function that produces an `Option`, optionally based on the value of\n * the first `Option`.\n *\n * If the first `Option` is `None`, the function skips the evaluation of the\n * second `Option` and directly returns `None`.\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B>\n /**\n * Chains two `Option`s together. The second `Option` can either be a static\n * value or depend on the result of the first `Option`.\n *\n * **Details**\n *\n * This function enables sequencing of two `Option` computations. If the first\n * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can\n * either:\n *\n * - Be a static `Option` value.\n * - Be a function that produces an `Option`, optionally based on the value of\n * the first `Option`.\n *\n * If the first `Option` is `None`, the function skips the evaluation of the\n * second `Option` and directly returns `None`.\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: Option<B>): Option<B>\n /**\n * Chains two `Option`s together. The second `Option` can either be a static\n * value or depend on the result of the first `Option`.\n *\n * **Details**\n *\n * This function enables sequencing of two `Option` computations. If the first\n * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can\n * either:\n *\n * - Be a static `Option` value.\n * - Be a function that produces an `Option`, optionally based on the value of\n * the first `Option`.\n *\n * If the first `Option` is `None`, the function skips the evaluation of the\n * second `Option` and directly returns `None`.\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => B): Option<B>\n /**\n * Chains two `Option`s together. The second `Option` can either be a static\n * value or depend on the result of the first `Option`.\n *\n * **Details**\n *\n * This function enables sequencing of two `Option` computations. If the first\n * `Option` is `Some`, the second `Option` is evaluated. The second `Option` can\n * either:\n *\n * - Be a static `Option` value.\n * - Be a function that produces an `Option`, optionally based on the value of\n * the first `Option`.\n *\n * If the first `Option` is `None`, the function skips the evaluation of the\n * second `Option` and directly returns `None`.\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: NotFunction<B>): Option<B>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => Option<B> | Option<B>): Option<B> =>\n flatMap(self, (a) => {\n const b = isFunction(f) ? f(a) : f\n return isOption(b) ? b : some(b)\n })\n)\n\n/**\n * Combines `flatMap` and `fromNullable`, transforming the value inside a `Some`\n * using a function that may return `null` or `undefined`.\n *\n * **Details**\n *\n * This function applies a transformation function `f` to the value inside a\n * `Some`. The function `f` may return a value, `null`, or `undefined`. If `f`\n * returns a value, it is wrapped in a `Some`. If `f` returns `null` or\n * `undefined`, the result is `None`. If the input `Option` is `None`, the\n * function is not applied, and `None` is returned.\n *\n * This utility is particularly useful when working with deeply nested optional\n * values or chaining computations that may result in `null` or `undefined` at\n * some point.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * interface Employee {\n * company?: {\n * address?: {\n * street?: {\n * name?: string\n * }\n * }\n * }\n * }\n *\n * const employee1: Employee = { company: { address: { street: { name: \"high street\" } } } }\n *\n * // Extracting a deeply nested property\n * console.log(\n * Option.some(employee1)\n * .pipe(Option.flatMapNullable((employee) => employee.company?.address?.street?.name))\n * )\n * // Output: { _id: 'Option', _tag: 'Some', value: 'high street' }\n *\n * const employee2: Employee = { company: { address: { street: {} } } }\n *\n * // Property does not exist\n * console.log(\n * Option.some(employee2)\n * .pipe(Option.flatMapNullable((employee) => employee.company?.address?.street?.name))\n * )\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Sequencing\n * @since 2.0.0\n */\nexport const flatMapNullable: {\n /**\n * Combines `flatMap` and `fromNullable`, transforming the value inside a `Some`\n * using a function that may return `null` or `undefined`.\n *\n * **Details**\n *\n * This function applies a transformation function `f` to the value inside a\n * `Some`. The function `f` may return a value, `null`, or `undefined`. If `f`\n * returns a value, it is wrapped in a `Some`. If `f` returns `null` or\n * `undefined`, the result is `None`. If the input `Option` is `None`, the\n * function is not applied, and `None` is returned.\n *\n * This utility is particularly useful when working with deeply nested optional\n * values or chaining computations that may result in `null` or `undefined` at\n * some point.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * interface Employee {\n * company?: {\n * address?: {\n * street?: {\n * name?: string\n * }\n * }\n * }\n * }\n *\n * const employee1: Employee = { company: { address: { street: { name: \"high street\" } } } }\n *\n * // Extracting a deeply nested property\n * console.log(\n * Option.some(employee1)\n * .pipe(Option.flatMapNullable((employee) => employee.company?.address?.street?.name))\n * )\n * // Output: { _id: 'Option', _tag: 'Some', value: 'high street' }\n *\n * const employee2: Employee = { company: { address: { street: {} } } }\n *\n * // Property does not exist\n * console.log(\n * Option.some(employee2)\n * .pipe(Option.flatMapNullable((employee) => employee.company?.address?.street?.name))\n * )\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B | null | undefined): (self: Option<A>) => Option<NonNullable<B>>\n /**\n * Combines `flatMap` and `fromNullable`, transforming the value inside a `Some`\n * using a function that may return `null` or `undefined`.\n *\n * **Details**\n *\n * This function applies a transformation function `f` to the value inside a\n * `Some`. The function `f` may return a value, `null`, or `undefined`. If `f`\n * returns a value, it is wrapped in a `Some`. If `f` returns `null` or\n * `undefined`, the result is `None`. If the input `Option` is `None`, the\n * function is not applied, and `None` is returned.\n *\n * This utility is particularly useful when working with deeply nested optional\n * values or chaining computations that may result in `null` or `undefined` at\n * some point.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * interface Employee {\n * company?: {\n * address?: {\n * street?: {\n * name?: string\n * }\n * }\n * }\n * }\n *\n * const employee1: Employee = { company: { address: { street: { name: \"high street\" } } } }\n *\n * // Extracting a deeply nested property\n * console.log(\n * Option.some(employee1)\n * .pipe(Option.flatMapNullable((employee) => employee.company?.address?.street?.name))\n * )\n * // Output: { _id: 'Option', _tag: 'Some', value: 'high street' }\n *\n * const employee2: Employee = { company: { address: { street: {} } } }\n *\n * // Property does not exist\n * console.log(\n * Option.some(employee2)\n * .pipe(Option.flatMapNullable((employee) => employee.company?.address?.street?.name))\n * )\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => B | null | undefined): Option<NonNullable<B>>\n} = dual(\n 2,\n <A, B>(self: Option<A>, f: (a: A) => B | null | undefined): Option<NonNullable<B>> =>\n isNone(self) ? none() : fromNullable(f(self.value))\n)\n\n/**\n * Flattens an `Option` of `Option` into a single `Option`.\n *\n * **Details**\n *\n * This function takes an `Option` that wraps another `Option` and flattens it\n * into a single `Option`. If the outer `Option` is `Some`, the function\n * extracts the inner `Option`. If the outer `Option` is `None`, the result\n * remains `None`.\n *\n * This is useful for simplifying nested `Option` structures that may arise\n * during functional operations.\n *\n * @category Sequencing\n * @since 2.0.0\n */\nexport const flatten: <A>(self: Option<Option<A>>) => Option<A> = flatMap(identity)\n\n/**\n * Combines two `Option`s, keeping the value from the second `Option` if both\n * are `Some`.\n *\n * **Details**\n *\n * This function takes two `Option`s and returns the second one if the first is\n * `Some`. If the first `Option` is `None`, the result will also be `None`,\n * regardless of the second `Option`. It effectively \"zips\" the two `Option`s\n * while discarding the value from the first `Option`.\n *\n * This is particularly useful when sequencing computations where the result of\n * the first computation is not needed, and you only care about the result of\n * the second computation.\n *\n * @category Zipping\n * @since 2.0.0\n */\nexport const zipRight: {\n /**\n * Combines two `Option`s, keeping the value from the second `Option` if both\n * are `Some`.\n *\n * **Details**\n *\n * This function takes two `Option`s and returns the second one if the first is\n * `Some`. If the first `Option` is `None`, the result will also be `None`,\n * regardless of the second `Option`. It effectively \"zips\" the two `Option`s\n * while discarding the value from the first `Option`.\n *\n * This is particularly useful when sequencing computations where the result of\n * the first computation is not needed, and you only care about the result of\n * the second computation.\n *\n * @category Zipping\n * @since 2.0.0\n */\n <B>(that: Option<B>): <_>(self: Option<_>) => Option<B>\n /**\n * Combines two `Option`s, keeping the value from the second `Option` if both\n * are `Some`.\n *\n * **Details**\n *\n * This function takes two `Option`s and returns the second one if the first is\n * `Some`. If the first `Option` is `None`, the result will also be `None`,\n * regardless of the second `Option`. It effectively \"zips\" the two `Option`s\n * while discarding the value from the first `Option`.\n *\n * This is particularly useful when sequencing computations where the result of\n * the first computation is not needed, and you only care about the result of\n * the second computation.\n *\n * @category Zipping\n * @since 2.0.0\n */\n <X, B>(self: Option<X>, that: Option<B>): Option<B>\n} = dual(2, <X, B>(self: Option<X>, that: Option<B>): Option<B> => flatMap(self, () => that))\n\n/**\n * Combines two `Option`s, keeping the value from the first `Option` if both are\n * `Some`.\n *\n * **Details**\n *\n * This function takes two `Option`s and returns the first one if it is `Some`.\n * If either the first `Option` or the second `Option` is `None`, the result\n * will be `None`. This operation \"zips\" the two `Option`s while discarding the\n * value from the second `Option`.\n *\n * This is useful when sequencing computations where the second `Option`\n * represents a dependency or condition that must hold, but its value is\n * irrelevant.\n *\n * @category Zipping\n * @since 2.0.0\n */\nexport const zipLeft: {\n /**\n * Combines two `Option`s, keeping the value from the first `Option` if both are\n * `Some`.\n *\n * **Details**\n *\n * This function takes two `Option`s and returns the first one if it is `Some`.\n * If either the first `Option` or the second `Option` is `None`, the result\n * will be `None`. This operation \"zips\" the two `Option`s while discarding the\n * value from the second `Option`.\n *\n * This is useful when sequencing computations where the second `Option`\n * represents a dependency or condition that must hold, but its value is\n * irrelevant.\n *\n * @category Zipping\n * @since 2.0.0\n */\n <_>(that: Option<_>): <A>(self: Option<A>) => Option<A>\n /**\n * Combines two `Option`s, keeping the value from the first `Option` if both are\n * `Some`.\n *\n * **Details**\n *\n * This function takes two `Option`s and returns the first one if it is `Some`.\n * If either the first `Option` or the second `Option` is `None`, the result\n * will be `None`. This operation \"zips\" the two `Option`s while discarding the\n * value from the second `Option`.\n *\n * This is useful when sequencing computations where the second `Option`\n * represents a dependency or condition that must hold, but its value is\n * irrelevant.\n *\n * @category Zipping\n * @since 2.0.0\n */\n <A, X>(self: Option<A>, that: Option<X>): Option<A>\n} = dual(2, <A, X>(self: Option<A>, that: Option<X>): Option<A> => tap(self, () => that))\n\n/**\n * Composes two functions that return `Option` values, creating a new function\n * that chains them together.\n *\n * **Details**\n *\n * This function allows you to compose two computations, each represented by a\n * function that returns an `Option`. The result of the first function is passed\n * to the second function if it is `Some`. If the first function returns `None`,\n * the composed function short-circuits and returns `None` without invoking the\n * second function.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const parse = (s: string): Option.Option<number> => isNaN(Number(s)) ? Option.none() : Option.some(Number(s))\n *\n * const double = (n: number): Option.Option<number> => n > 0 ? Option.some(n * 2) : Option.none()\n *\n * const parseAndDouble = Option.composeK(parse, double)\n *\n * console.log(parseAndDouble(\"42\"))\n * // Output: { _id: 'Option', _tag: 'Some', value: 84 }\n *\n * console.log(parseAndDouble(\"not a number\"))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Sequencing\n * @since 2.0.0\n */\nexport const composeK: {\n /**\n * Composes two functions that return `Option` values, creating a new function\n * that chains them together.\n *\n * **Details**\n *\n * This function allows you to compose two computations, each represented by a\n * function that returns an `Option`. The result of the first function is passed\n * to the second function if it is `Some`. If the first function returns `None`,\n * the composed function short-circuits and returns `None` without invoking the\n * second function.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const parse = (s: string): Option.Option<number> => isNaN(Number(s)) ? Option.none() : Option.some(Number(s))\n *\n * const double = (n: number): Option.Option<number> => n > 0 ? Option.some(n * 2) : Option.none()\n *\n * const parseAndDouble = Option.composeK(parse, double)\n *\n * console.log(parseAndDouble(\"42\"))\n * // Output: { _id: 'Option', _tag: 'Some', value: 84 }\n *\n * console.log(parseAndDouble(\"not a number\"))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <B, C>(bfc: (b: B) => Option<C>): <A>(afb: (a: A) => Option<B>) => (a: A) => Option<C>\n /**\n * Composes two functions that return `Option` values, creating a new function\n * that chains them together.\n *\n * **Details**\n *\n * This function allows you to compose two computations, each represented by a\n * function that returns an `Option`. The result of the first function is passed\n * to the second function if it is `Some`. If the first function returns `None`,\n * the composed function short-circuits and returns `None` without invoking the\n * second function.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const parse = (s: string): Option.Option<number> => isNaN(Number(s)) ? Option.none() : Option.some(Number(s))\n *\n * const double = (n: number): Option.Option<number> => n > 0 ? Option.some(n * 2) : Option.none()\n *\n * const parseAndDouble = Option.composeK(parse, double)\n *\n * console.log(parseAndDouble(\"42\"))\n * // Output: { _id: 'Option', _tag: 'Some', value: 84 }\n *\n * console.log(parseAndDouble(\"not a number\"))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, B, C>(afb: (a: A) => Option<B>, bfc: (b: B) => Option<C>): (a: A) => Option<C>\n} = dual(2, <A, B, C>(afb: (a: A) => Option<B>, bfc: (b: B) => Option<C>) => (a: A): Option<C> => flatMap(afb(a), bfc))\n\n/**\n * Applies the provided function `f` to the value of the `Option` if it is\n * `Some` and returns the original `Option`, unless `f` returns `None`, in which\n * case it returns `None`.\n *\n * **Details**\n *\n * This function allows you to perform additional computations on the value of\n * an `Option` without modifying its original value. If the `Option` is `Some`,\n * the provided function `f` is executed with the value, and its result\n * determines whether the original `Option` is returned (`Some`) or the result\n * is `None` if `f` returns `None`. If the input `Option` is `None`, the\n * function is not executed, and `None` is returned.\n *\n * This is particularly useful for applying side conditions or performing\n * validation checks while retaining the original `Option`'s value.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getInteger = (n: number) => Number.isInteger(n) ? Option.some(n) : Option.none()\n *\n * console.log(Option.tap(Option.none(), getInteger))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(Option.tap(Option.some(1), getInteger))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(Option.tap(Option.some(1.14), getInteger))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Sequencing\n * @since 2.0.0\n */\nexport const tap: {\n /**\n * Applies the provided function `f` to the value of the `Option` if it is\n * `Some` and returns the original `Option`, unless `f` returns `None`, in which\n * case it returns `None`.\n *\n * **Details**\n *\n * This function allows you to perform additional computations on the value of\n * an `Option` without modifying its original value. If the `Option` is `Some`,\n * the provided function `f` is executed with the value, and its result\n * determines whether the original `Option` is returned (`Some`) or the result\n * is `None` if `f` returns `None`. If the input `Option` is `None`, the\n * function is not executed, and `None` is returned.\n *\n * This is particularly useful for applying side conditions or performing\n * validation checks while retaining the original `Option`'s value.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getInteger = (n: number) => Number.isInteger(n) ? Option.some(n) : Option.none()\n *\n * console.log(Option.tap(Option.none(), getInteger))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(Option.tap(Option.some(1), getInteger))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(Option.tap(Option.some(1.14), getInteger))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, X>(f: (a: A) => Option<X>): (self: Option<A>) => Option<A>\n /**\n * Applies the provided function `f` to the value of the `Option` if it is\n * `Some` and returns the original `Option`, unless `f` returns `None`, in which\n * case it returns `None`.\n *\n * **Details**\n *\n * This function allows you to perform additional computations on the value of\n * an `Option` without modifying its original value. If the `Option` is `Some`,\n * the provided function `f` is executed with the value, and its result\n * determines whether the original `Option` is returned (`Some`) or the result\n * is `None` if `f` returns `None`. If the input `Option` is `None`, the\n * function is not executed, and `None` is returned.\n *\n * This is particularly useful for applying side conditions or performing\n * validation checks while retaining the original `Option`'s value.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const getInteger = (n: number) => Number.isInteger(n) ? Option.some(n) : Option.none()\n *\n * console.log(Option.tap(Option.none(), getInteger))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(Option.tap(Option.some(1), getInteger))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(Option.tap(Option.some(1.14), getInteger))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Sequencing\n * @since 2.0.0\n */\n <A, X>(self: Option<A>, f: (a: A) => Option<X>): Option<A>\n} = dual(2, <A, X>(self: Option<A>, f: (a: A) => Option<X>): Option<A> => flatMap(self, (a) => map(f(a), () => a)))\n\n/**\n * Combines two `Option` values into a single `Option` containing a tuple of\n * their values if both are `Some`.\n *\n * **Details**\n *\n * This function takes two `Option`s and combines their values into a tuple `[A,\n * B]` if both are `Some`. If either of the `Option`s is `None`, the result is\n * `None`. This is particularly useful for combining multiple `Option` values\n * into a single one, ensuring both contain valid values.\n *\n * @category Combining\n * @since 2.0.0\n */\nexport const product = <A, B>(self: Option<A>, that: Option<B>): Option<[A, B]> =>\n isSome(self) && isSome(that) ? some([self.value, that.value]) : none()\n\n/**\n * Combines an `Option` with a collection of `Option`s into a single `Option`\n * containing a tuple of their values if all are `Some`.\n *\n * **Details**\n *\n * This function takes a primary `Option` and a collection of `Option`s and\n * combines their values into a tuple `[A, ...Array<A>]` if all are `Some`. If\n * the primary `Option` or any `Option` in the collection is `None`, the result\n * is `None`.\n *\n * @category Combining\n * @since 2.0.0\n */\nexport const productMany = <A>(\n self: Option<A>,\n collection: Iterable<Option<A>>\n): Option<[A, ...Array<A>]> => {\n if (isNone(self)) {\n return none()\n }\n const out: [A, ...Array<A>] = [self.value]\n for (const o of collection) {\n if (isNone(o)) {\n return none()\n }\n out.push(o.value)\n }\n return some(out)\n}\n\n/**\n * Combines a structure of `Option`s into a single `Option` containing the\n * values with the same structure.\n *\n * **Details**\n *\n * This function takes a structure of `Option`s (a tuple, struct, or iterable)\n * and produces a single `Option` that contains the values from the input\n * structure if all `Option`s are `Some`. If any `Option` in the input is\n * `None`, the result is `None`. The structure of the input is preserved in the\n * output.\n *\n * - If the input is a tuple (e.g., an array), the result will be an `Option`\n * containing a tuple with the same length.\n * - If the input is a struct (e.g., an object), the result will be an `Option`\n * containing a struct with the same keys.\n * - If the input is an iterable, the result will be an `Option` containing an\n * array.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const maybeName: Option.Option<string> = Option.some(\"John\")\n * const maybeAge: Option.Option<number> = Option.some(25)\n *\n * // ┌─── Option<[string, number]>\n * // ▼\n * const tuple = Option.all([maybeName, maybeAge])\n * console.log(tuple)\n * // Output:\n * // { _id: 'Option', _tag: 'Some', value: [ 'John', 25 ] }\n *\n * // ┌─── Option<{ name: string; age: number; }>\n * // ▼\n * const struct = Option.all({ name: maybeName, age: maybeAge })\n * console.log(struct)\n * // Output:\n * // { _id: 'Option', _tag: 'Some', value: { name: 'John', age: 25 } }\n * ```\n *\n * @category Combining\n * @since 2.0.0\n */\n// @ts-expect-error\nexport const all: <const I extends Iterable<Option<any>> | Record<string, Option<any>>>(\n input: I\n) => [I] extends [ReadonlyArray<Option<any>>] ? Option<\n { -readonly [K in keyof I]: [I[K]] extends [Option<infer A>] ? A : never }\n >\n : [I] extends [Iterable<Option<infer A>>] ? Option<Array<A>>\n : Option<{ -readonly [K in keyof I]: [I[K]] extends [Option<infer A>] ? A : never }> = (\n input: Iterable<Option<any>> | Record<string, Option<any>>\n ): Option<any> => {\n if (Symbol.iterator in input) {\n const out: Array<Option<any>> = []\n for (const o of (input as Iterable<Option<any>>)) {\n if (isNone(o)) {\n return none()\n }\n out.push(o.value)\n }\n return some(out)\n }\n\n const out: Record<string, any> = {}\n for (const key of Object.keys(input)) {\n const o = input[key]\n if (isNone(o)) {\n return none()\n }\n out[key] = o.value\n }\n return some(out)\n }\n\n/**\n * Combines two `Option` values into a new `Option` by applying a provided\n * function to their values.\n *\n * **Details**\n *\n * This function takes two `Option` values (`self` and `that`) and a combining\n * function `f`. If both `Option` values are `Some`, the function `f` is applied\n * to their values, and the result is wrapped in a new `Some`. If either\n * `Option` is `None`, the result is `None`.\n *\n * This utility is useful for combining two optional computations into a single\n * result while maintaining type safety and avoiding explicit checks for `None`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const maybeName: Option.Option<string> = Option.some(\"John\")\n * const maybeAge: Option.Option<number> = Option.some(25)\n *\n * // Combine the name and age into a person object\n * const person = Option.zipWith(maybeName, maybeAge, (name, age) => ({\n * name: name.toUpperCase(),\n * age\n * }))\n *\n * console.log(person)\n * // Output:\n * // { _id: 'Option', _tag: 'Some', value: { name: 'JOHN', age: 25 } }\n * ```\n *\n * @category Zipping\n * @since 2.0.0\n */\nexport const zipWith: {\n /**\n * Combines two `Option` values into a new `Option` by applying a provided\n * function to their values.\n *\n * **Details**\n *\n * This function takes two `Option` values (`self` and `that`) and a combining\n * function `f`. If both `Option` values are `Some`, the function `f` is applied\n * to their values, and the result is wrapped in a new `Some`. If either\n * `Option` is `None`, the result is `None`.\n *\n * This utility is useful for combining two optional computations into a single\n * result while maintaining type safety and avoiding explicit checks for `None`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const maybeName: Option.Option<string> = Option.some(\"John\")\n * const maybeAge: Option.Option<number> = Option.some(25)\n *\n * // Combine the name and age into a person object\n * const person = Option.zipWith(maybeName, maybeAge, (name, age) => ({\n * name: name.toUpperCase(),\n * age\n * }))\n *\n * console.log(person)\n * // Output:\n * // { _id: 'Option', _tag: 'Some', value: { name: 'JOHN', age: 25 } }\n * ```\n *\n * @category Zipping\n * @since 2.0.0\n */\n <B, A, C>(that: Option<B>, f: (a: A, b: B) => C): (self: Option<A>) => Option<C>\n /**\n * Combines two `Option` values into a new `Option` by applying a provided\n * function to their values.\n *\n * **Details**\n *\n * This function takes two `Option` values (`self` and `that`) and a combining\n * function `f`. If both `Option` values are `Some`, the function `f` is applied\n * to their values, and the result is wrapped in a new `Some`. If either\n * `Option` is `None`, the result is `None`.\n *\n * This utility is useful for combining two optional computations into a single\n * result while maintaining type safety and avoiding explicit checks for `None`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const maybeName: Option.Option<string> = Option.some(\"John\")\n * const maybeAge: Option.Option<number> = Option.some(25)\n *\n * // Combine the name and age into a person object\n * const person = Option.zipWith(maybeName, maybeAge, (name, age) => ({\n * name: name.toUpperCase(),\n * age\n * }))\n *\n * console.log(person)\n * // Output:\n * // { _id: 'Option', _tag: 'Some', value: { name: 'JOHN', age: 25 } }\n * ```\n *\n * @category Zipping\n * @since 2.0.0\n */\n <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C>\n} = dual(\n 3,\n <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C> =>\n map(product(self, that), ([a, b]) => f(a, b))\n)\n\n/**\n * Applies a function inside a `Some` to a value inside another `Some`,\n * combining them into a new `Option`.\n *\n * **Details**\n *\n * This function allows you to apply a function wrapped in an `Option` (`self`)\n * to a value wrapped in another `Option` (`that`). If both `Option`s are\n * `Some`, the function is applied to the value, and the result is wrapped in a\n * new `Some`. If either `Option` is `None`, the result is `None`.\n *\n * @category Combining\n * @since 2.0.0\n */\nexport const ap: {\n /**\n * Applies a function inside a `Some` to a value inside another `Some`,\n * combining them into a new `Option`.\n *\n * **Details**\n *\n * This function allows you to apply a function wrapped in an `Option` (`self`)\n * to a value wrapped in another `Option` (`that`). If both `Option`s are\n * `Some`, the function is applied to the value, and the result is wrapped in a\n * new `Some`. If either `Option` is `None`, the result is `None`.\n *\n * @category Combining\n * @since 2.0.0\n */\n <A>(that: Option<A>): <B>(self: Option<(a: A) => B>) => Option<B>\n /**\n * Applies a function inside a `Some` to a value inside another `Some`,\n * combining them into a new `Option`.\n *\n * **Details**\n *\n * This function allows you to apply a function wrapped in an `Option` (`self`)\n * to a value wrapped in another `Option` (`that`). If both `Option`s are\n * `Some`, the function is applied to the value, and the result is wrapped in a\n * new `Some`. If either `Option` is `None`, the result is `None`.\n *\n * @category Combining\n * @since 2.0.0\n */\n <A, B>(self: Option<(a: A) => B>, that: Option<A>): Option<B>\n} = dual(2, <A, B>(self: Option<(a: A) => B>, that: Option<A>): Option<B> => zipWith(self, that, (f, a) => f(a)))\n\n/**\n * Reduces an `Iterable` of `Option<A>` to a single value of type `B`, ignoring\n * elements that are `None`.\n *\n * **Details**\n *\n * This function takes an initial value of type `B` and a reducing function `f`\n * that combines the accumulator with values of type `A`. It processes an\n * iterable of `Option<A>`, applying `f` only to the `Some` values while\n * ignoring the `None` values. The result is a single value of type `B`.\n *\n * This utility is particularly useful for aggregating values from an iterable\n * of `Option`s while skipping the absent (`None`) values.\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const iterable = [Option.some(1), Option.none(), Option.some(2), Option.none()]\n *\n * console.log(pipe(iterable, Option.reduceCompact(0, (b, a) => b + a)))\n * // Output: 3\n * ```\n *\n * @category Reducing\n * @since 2.0.0\n */\nexport const reduceCompact: {\n /**\n * Reduces an `Iterable` of `Option<A>` to a single value of type `B`, ignoring\n * elements that are `None`.\n *\n * **Details**\n *\n * This function takes an initial value of type `B` and a reducing function `f`\n * that combines the accumulator with values of type `A`. It processes an\n * iterable of `Option<A>`, applying `f` only to the `Some` values while\n * ignoring the `None` values. The result is a single value of type `B`.\n *\n * This utility is particularly useful for aggregating values from an iterable\n * of `Option`s while skipping the absent (`None`) values.\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const iterable = [Option.some(1), Option.none(), Option.some(2), Option.none()]\n *\n * console.log(pipe(iterable, Option.reduceCompact(0, (b, a) => b + a)))\n * // Output: 3\n * ```\n *\n * @category Reducing\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A) => B): (self: Iterable<Option<A>>) => B\n /**\n * Reduces an `Iterable` of `Option<A>` to a single value of type `B`, ignoring\n * elements that are `None`.\n *\n * **Details**\n *\n * This function takes an initial value of type `B` and a reducing function `f`\n * that combines the accumulator with values of type `A`. It processes an\n * iterable of `Option<A>`, applying `f` only to the `Some` values while\n * ignoring the `None` values. The result is a single value of type `B`.\n *\n * This utility is particularly useful for aggregating values from an iterable\n * of `Option`s while skipping the absent (`None`) values.\n *\n * @example\n * ```ts\n * import { Option, pipe } from \"effect\"\n *\n * const iterable = [Option.some(1), Option.none(), Option.some(2), Option.none()]\n *\n * console.log(pipe(iterable, Option.reduceCompact(0, (b, a) => b + a)))\n * // Output: 3\n * ```\n *\n * @category Reducing\n * @since 2.0.0\n */\n <A, B>(self: Iterable<Option<A>>, b: B, f: (b: B, a: A) => B): B\n} = dual(\n 3,\n <A, B>(self: Iterable<Option<A>>, b: B, f: (b: B, a: A) => B): B => {\n let out: B = b\n for (const oa of self) {\n if (isSome(oa)) {\n out = f(out, oa.value)\n }\n }\n return out\n }\n)\n\n/**\n * Converts an `Option` into an `Array`.\n * If the input is `None`, an empty array is returned.\n * If the input is `Some`, its value is wrapped in a single-element array.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.toArray(Option.some(1)))\n * // Output: [1]\n *\n * console.log(Option.toArray(Option.none()))\n * // Output: []\n * ```\n *\n * @category Conversions\n * @since 2.0.0\n */\nexport const toArray = <A>(self: Option<A>): Array<A> => isNone(self) ? [] : [self.value]\n\n/**\n * Splits an `Option` into two `Option`s based on the result of a mapping\n * function that produces an `Either`.\n *\n * **Details**\n *\n * This function takes an `Option` and a mapping function `f` that converts its\n * value into an `Either`. It returns a tuple of two `Option`s:\n *\n * - The first `Option` (`left`) contains the value from the `Left` side of the\n * `Either` if it exists, otherwise `None`.\n * - The second `Option` (`right`) contains the value from the `Right` side of\n * the `Either` if it exists, otherwise `None`.\n *\n * If the input `Option` is `None`, both returned `Option`s are `None`.\n *\n * This utility is useful for filtering and categorizing the contents of an\n * `Option` based on a bifurcating computation.\n *\n * @category Filtering\n * @since 2.0.0\n */\nexport const partitionMap: {\n /**\n * Splits an `Option` into two `Option`s based on the result of a mapping\n * function that produces an `Either`.\n *\n * **Details**\n *\n * This function takes an `Option` and a mapping function `f` that converts its\n * value into an `Either`. It returns a tuple of two `Option`s:\n *\n * - The first `Option` (`left`) contains the value from the `Left` side of the\n * `Either` if it exists, otherwise `None`.\n * - The second `Option` (`right`) contains the value from the `Right` side of\n * the `Either` if it exists, otherwise `None`.\n *\n * If the input `Option` is `None`, both returned `Option`s are `None`.\n *\n * This utility is useful for filtering and categorizing the contents of an\n * `Option` based on a bifurcating computation.\n *\n * @category Filtering\n * @since 2.0.0\n */\n <A, B, C>(f: (a: A) => Either<C, B>): (self: Option<A>) => [left: Option<B>, right: Option<C>]\n /**\n * Splits an `Option` into two `Option`s based on the result of a mapping\n * function that produces an `Either`.\n *\n * **Details**\n *\n * This function takes an `Option` and a mapping function `f` that converts its\n * value into an `Either`. It returns a tuple of two `Option`s:\n *\n * - The first `Option` (`left`) contains the value from the `Left` side of the\n * `Either` if it exists, otherwise `None`.\n * - The second `Option` (`right`) contains the value from the `Right` side of\n * the `Either` if it exists, otherwise `None`.\n *\n * If the input `Option` is `None`, both returned `Option`s are `None`.\n *\n * This utility is useful for filtering and categorizing the contents of an\n * `Option` based on a bifurcating computation.\n *\n * @category Filtering\n * @since 2.0.0\n */\n <A, B, C>(self: Option<A>, f: (a: A) => Either<C, B>): [left: Option<B>, right: Option<C>]\n} = dual(2, <A, B, C>(\n self: Option<A>,\n f: (a: A) => Either<C, B>\n): [excluded: Option<B>, satisfying: Option<C>] => {\n if (isNone(self)) {\n return [none(), none()]\n }\n const e = f(self.value)\n return either.isLeft(e) ? [some(e.left), none()] : [none(), some(e.right)]\n})\n\n// TODO(4.0): remove?\n/**\n * Alias of {@link flatMap}.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Transform and filter numbers\n * const transformEven = (n: Option.Option<number>): Option.Option<string> =>\n * Option.filterMap(n, (n) => (n % 2 === 0 ? Option.some(`Even: ${n}`) : Option.none()))\n *\n * console.log(transformEven(Option.none()))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(transformEven(Option.some(1)))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(transformEven(Option.some(2)))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'Even: 2' }\n * ```\n *\n * @category Filtering\n * @since 2.0.0\n */\nexport const filterMap: {\n // TODO(4.0): remove?\n /**\n * Alias of {@link flatMap}.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Transform and filter numbers\n * const transformEven = (n: Option.Option<number>): Option.Option<string> =>\n * Option.filterMap(n, (n) => (n % 2 === 0 ? Option.some(`Even: ${n}`) : Option.none()))\n *\n * console.log(transformEven(Option.none()))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(transformEven(Option.some(1)))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(transformEven(Option.some(2)))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'Even: 2' }\n * ```\n *\n * @category Filtering\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => Option<B>): (self: Option<A>) => Option<B>\n // TODO(4.0): remove?\n /**\n * Alias of {@link flatMap}.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Transform and filter numbers\n * const transformEven = (n: Option.Option<number>): Option.Option<string> =>\n * Option.filterMap(n, (n) => (n % 2 === 0 ? Option.some(`Even: ${n}`) : Option.none()))\n *\n * console.log(transformEven(Option.none()))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(transformEven(Option.some(1)))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(transformEven(Option.some(2)))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'Even: 2' }\n * ```\n *\n * @category Filtering\n * @since 2.0.0\n */\n <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B>\n} = flatMap\n\n/**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const removeEmptyString = (input: Option.Option<string>) =>\n * Option.filter(input, (value) => value !== \"\")\n *\n * console.log(removeEmptyString(Option.none()))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"\")))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"a\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n * ```\n *\n * @category Filtering\n * @since 2.0.0\n */\nexport const filter: {\n /**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const removeEmptyString = (input: Option.Option<string>) =>\n * Option.filter(input, (value) => value !== \"\")\n *\n * console.log(removeEmptyString(Option.none()))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"\")))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"a\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n * ```\n *\n * @category Filtering\n * @since 2.0.0\n */\n <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: Option<A>) => Option<B>\n /**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const removeEmptyString = (input: Option.Option<string>) =>\n * Option.filter(input, (value) => value !== \"\")\n *\n * console.log(removeEmptyString(Option.none()))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"\")))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"a\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n * ```\n *\n * @category Filtering\n * @since 2.0.0\n */\n <A>(predicate: Predicate<NoInfer<A>>): (self: Option<A>) => Option<A>\n /**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const removeEmptyString = (input: Option.Option<string>) =>\n * Option.filter(input, (value) => value !== \"\")\n *\n * console.log(removeEmptyString(Option.none()))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"\")))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"a\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n * ```\n *\n * @category Filtering\n * @since 2.0.0\n */\n <A, B extends A>(self: Option<A>, refinement: Refinement<A, B>): Option<B>\n /**\n * Filters an `Option` using a predicate. If the predicate is not satisfied or the `Option` is `None` returns `None`.\n *\n * If you need to change the type of the `Option` in addition to filtering, see `filterMap`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const removeEmptyString = (input: Option.Option<string>) =>\n * Option.filter(input, (value) => value !== \"\")\n *\n * console.log(removeEmptyString(Option.none()))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"\")))\n * // Output: { _id: 'Option', _tag: 'None' }\n *\n * console.log(removeEmptyString(Option.some(\"a\")))\n * // Output: { _id: 'Option', _tag: 'Some', value: 'a' }\n * ```\n *\n * @category Filtering\n * @since 2.0.0\n */\n <A>(self: Option<A>, predicate: Predicate<A>): Option<A>\n} = dual(\n 2,\n <A>(self: Option<A>, predicate: Predicate<A>): Option<A> =>\n filterMap(self, (b) => (predicate(b) ? option.some(b) : option.none))\n)\n\n/**\n * Creates an `Equivalence` instance for comparing `Option` values, using a\n * provided `Equivalence` for the inner type.\n *\n * **Details**\n *\n * This function takes an `Equivalence` instance for a specific type `A` and\n * produces an `Equivalence` instance for `Option<A>`. The resulting\n * `Equivalence` determines whether two `Option` values are equivalent:\n *\n * - Two `None`s are considered equivalent.\n * - A `Some` and a `None` are not equivalent.\n * - Two `Some` values are equivalent if their inner values are equivalent\n * according to the provided `Equivalence`.\n *\n * **Example** (Comparing Optional Numbers for Equivalence)\n *\n * ```ts\n * import { Number, Option } from \"effect\"\n *\n * const isEquivalent = Option.getEquivalence(Number.Equivalence)\n *\n * console.log(isEquivalent(Option.none(), Option.none()))\n * // Output: true\n *\n * console.log(isEquivalent(Option.none(), Option.some(1)))\n * // Output: false\n *\n * console.log(isEquivalent(Option.some(1), Option.none()))\n * // Output: false\n *\n * console.log(isEquivalent(Option.some(1), Option.some(2)))\n * // Output: false\n *\n * console.log(isEquivalent(Option.some(1), Option.some(1)))\n * // Output: true\n * ```\n *\n * @category Equivalence\n * @since 2.0.0\n */\nexport const getEquivalence = <A>(isEquivalent: Equivalence.Equivalence<A>): Equivalence.Equivalence<Option<A>> =>\n Equivalence.make((x, y) => isNone(x) ? isNone(y) : isNone(y) ? false : isEquivalent(x.value, y.value))\n\n/**\n * Creates an `Order` instance for comparing `Option` values, using a provided\n * `Order` for the inner type.\n *\n * **Details**\n *\n * This function produces an `Order` instance for `Option<A>`, allowing `Option`\n * values to be compared:\n *\n * - `None` is always considered less than any `Some` value.\n * - If both are `Some`, their inner values are compared using the provided\n * `Order` instance.\n *\n * @example\n * ```ts\n * import { Number, Option } from \"effect\"\n *\n * const order = Option.getOrder(Number.Order)\n *\n * console.log(order(Option.none(), Option.none()))\n * // Output: 0\n *\n * console.log(order(Option.none(), Option.some(1)))\n * // Output: -1\n *\n * console.log(order(Option.some(1), Option.none()))\n * // Output: 1\n *\n * console.log(order(Option.some(1), Option.some(2)))\n * // Output: -1\n *\n * console.log(order(Option.some(1), Option.some(1)))\n * // Output: 0\n * ```\n *\n * @category Sorting\n * @since 2.0.0\n */\nexport const getOrder = <A>(O: Order<A>): Order<Option<A>> =>\n order.make((self, that) => isSome(self) ? (isSome(that) ? O(self.value, that.value) : 1) : -1)\n\n/**\n * Lifts a binary function to work with `Option` values, allowing the function\n * to operate on two `Option`s.\n *\n * **Details**\n *\n * This function takes a binary function `f` and returns a new function that\n * applies `f` to the values of two `Option`s (`self` and `that`). If both\n * `Option`s are `Some`, the binary function `f` is applied to their values, and\n * the result is wrapped in a new `Some`. If either `Option` is `None`, the\n * result is `None`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // A binary function to add two numbers\n * const add = (a: number, b: number): number => a + b\n *\n * // Lift the `add` function to work with `Option` values\n * const addOptions = Option.lift2(add)\n *\n * // Both `Option`s are `Some`\n * console.log(addOptions(Option.some(2), Option.some(3)))\n * // Output: { _id: 'Option', _tag: 'Some', value: 5 }\n *\n * // One `Option` is `None`\n * console.log(addOptions(Option.some(2), Option.none()))\n * // Output: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Lifting\n * @since 2.0.0\n */\nexport const lift2 = <A, B, C>(f: (a: A, b: B) => C): {\n (that: Option<B>): (self: Option<A>) => Option<C>\n (self: Option<A>, that: Option<B>): Option<C>\n} => dual(2, (self: Option<A>, that: Option<B>): Option<C> => zipWith(self, that, f))\n\n/**\n * Lifts a `Predicate` or `Refinement` into the `Option` context, returning a\n * `Some` of the input value if the predicate is satisfied, or `None` otherwise.\n *\n * **Details**\n *\n * This function transforms a `Predicate` (or a more specific `Refinement`) into\n * a function that produces an `Option`. If the predicate evaluates to `true`,\n * the input value is wrapped in a `Some`. If the predicate evaluates to\n * `false`, the result is `None`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Check if a number is positive\n * const isPositive = (n: number) => n > 0\n *\n * // ┌─── (b: number) => Option<number>\n * // ▼\n * const parsePositive = Option.liftPredicate(isPositive)\n *\n * console.log(parsePositive(1))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(parsePositive(-1))\n * // OUtput: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Lifting\n * @since 2.0.0\n */\nexport const liftPredicate: { // Note: I intentionally avoid using the NoInfer pattern here.\n <A, B extends A>(refinement: Refinement<A, B>): (a: A) => Option<B>\n /**\n * Lifts a `Predicate` or `Refinement` into the `Option` context, returning a\n * `Some` of the input value if the predicate is satisfied, or `None` otherwise.\n *\n * **Details**\n *\n * This function transforms a `Predicate` (or a more specific `Refinement`) into\n * a function that produces an `Option`. If the predicate evaluates to `true`,\n * the input value is wrapped in a `Some`. If the predicate evaluates to\n * `false`, the result is `None`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Check if a number is positive\n * const isPositive = (n: number) => n > 0\n *\n * // ┌─── (b: number) => Option<number>\n * // ▼\n * const parsePositive = Option.liftPredicate(isPositive)\n *\n * console.log(parsePositive(1))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(parsePositive(-1))\n * // OUtput: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Lifting\n * @since 2.0.0\n */\n <B extends A, A = B>(predicate: Predicate<A>): (b: B) => Option<B>\n /**\n * Lifts a `Predicate` or `Refinement` into the `Option` context, returning a\n * `Some` of the input value if the predicate is satisfied, or `None` otherwise.\n *\n * **Details**\n *\n * This function transforms a `Predicate` (or a more specific `Refinement`) into\n * a function that produces an `Option`. If the predicate evaluates to `true`,\n * the input value is wrapped in a `Some`. If the predicate evaluates to\n * `false`, the result is `None`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Check if a number is positive\n * const isPositive = (n: number) => n > 0\n *\n * // ┌─── (b: number) => Option<number>\n * // ▼\n * const parsePositive = Option.liftPredicate(isPositive)\n *\n * console.log(parsePositive(1))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(parsePositive(-1))\n * // OUtput: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Lifting\n * @since 2.0.0\n */\n <A, B extends A>(self: A, refinement: Refinement<A, B>): Option<B>\n /**\n * Lifts a `Predicate` or `Refinement` into the `Option` context, returning a\n * `Some` of the input value if the predicate is satisfied, or `None` otherwise.\n *\n * **Details**\n *\n * This function transforms a `Predicate` (or a more specific `Refinement`) into\n * a function that produces an `Option`. If the predicate evaluates to `true`,\n * the input value is wrapped in a `Some`. If the predicate evaluates to\n * `false`, the result is `None`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * // Check if a number is positive\n * const isPositive = (n: number) => n > 0\n *\n * // ┌─── (b: number) => Option<number>\n * // ▼\n * const parsePositive = Option.liftPredicate(isPositive)\n *\n * console.log(parsePositive(1))\n * // Output: { _id: 'Option', _tag: 'Some', value: 1 }\n *\n * console.log(parsePositive(-1))\n * // OUtput: { _id: 'Option', _tag: 'None' }\n * ```\n *\n * @category Lifting\n * @since 2.0.0\n */\n <B extends A, A = B>(self: B, predicate: Predicate<A>): Option<B>\n} = dual(\n 2,\n <B extends A, A = B>(b: B, predicate: Predicate<A>): Option<B> => predicate(b) ? some(b) : none()\n)\n\n/**\n * Returns a function that checks if an `Option` contains a specified value,\n * using a provided equivalence function.\n *\n * **Details**\n *\n * This function allows you to check whether an `Option` contains a specific\n * value. It uses an equivalence function `isEquivalent` to compare the value\n * inside the `Option` to the provided value. If the `Option` is `Some` and the\n * equivalence function returns `true`, the result is `true`. If the `Option` is\n * `None` or the values are not equivalent, the result is `false`.\n *\n * @example\n * ```ts\n * import { Number, Option } from \"effect\"\n *\n * const contains = Option.containsWith(Number.Equivalence)\n *\n * console.log(Option.some(2).pipe(contains(2)))\n * // Output: true\n *\n * console.log(Option.some(1).pipe(contains(2)))\n * // Output: false\n *\n * console.log(Option.none().pipe(contains(2)))\n * // Output: false\n * ```\n *\n * @see {@link contains} for a version that uses the default `Equivalence`.\n *\n * @category Elements\n * @since 2.0.0\n */\nexport const containsWith = <A>(isEquivalent: (self: A, that: A) => boolean): {\n (a: A): (self: Option<A>) => boolean\n (self: Option<A>, a: A): boolean\n} => dual(2, (self: Option<A>, a: A): boolean => isNone(self) ? false : isEquivalent(self.value, a))\n\nconst _equivalence = Equal.equivalence()\n\n/**\n * Returns a function that checks if an `Option` contains a specified value\n * using the default `Equivalence`.\n *\n * **Details**\n *\n * This function allows you to check whether an `Option` contains a specific\n * value. It uses the default `Equivalence` for equality comparison. If the\n * `Option` is `Some` and its value is equivalent to the provided value, the\n * result is `true`. If the `Option` is `None` or the values are not equivalent,\n * the result is `false`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.some(2).pipe(Option.contains(2)))\n * // Output: true\n *\n * console.log(Option.some(1).pipe(Option.contains(2)))\n * // Output: false\n *\n * console.log(Option.none().pipe(Option.contains(2)))\n * // Output: false\n * ```\n *\n * @see {@link containsWith} for a version that allows you to specify a custom equivalence function.\n *\n * @category Elements\n * @since 2.0.0\n */\nexport const contains: {\n /**\n * Returns a function that checks if an `Option` contains a specified value\n * using the default `Equivalence`.\n *\n * **Details**\n *\n * This function allows you to check whether an `Option` contains a specific\n * value. It uses the default `Equivalence` for equality comparison. If the\n * `Option` is `Some` and its value is equivalent to the provided value, the\n * result is `true`. If the `Option` is `None` or the values are not equivalent,\n * the result is `false`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.some(2).pipe(Option.contains(2)))\n * // Output: true\n *\n * console.log(Option.some(1).pipe(Option.contains(2)))\n * // Output: false\n *\n * console.log(Option.none().pipe(Option.contains(2)))\n * // Output: false\n * ```\n *\n * @see {@link containsWith} for a version that allows you to specify a custom equivalence function.\n *\n * @category Elements\n * @since 2.0.0\n */\n <A>(a: A): (self: Option<A>) => boolean\n /**\n * Returns a function that checks if an `Option` contains a specified value\n * using the default `Equivalence`.\n *\n * **Details**\n *\n * This function allows you to check whether an `Option` contains a specific\n * value. It uses the default `Equivalence` for equality comparison. If the\n * `Option` is `Some` and its value is equivalent to the provided value, the\n * result is `true`. If the `Option` is `None` or the values are not equivalent,\n * the result is `false`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * console.log(Option.some(2).pipe(Option.contains(2)))\n * // Output: true\n *\n * console.log(Option.some(1).pipe(Option.contains(2)))\n * // Output: false\n *\n * console.log(Option.none().pipe(Option.contains(2)))\n * // Output: false\n * ```\n *\n * @see {@link containsWith} for a version that allows you to specify a custom equivalence function.\n *\n * @category Elements\n * @since 2.0.0\n */\n <A>(self: Option<A>, a: A): boolean\n} = containsWith(_equivalence)\n\n/**\n * Checks if a value in an `Option` satisfies a given predicate or refinement.\n *\n * **Details**\n *\n * This function allows you to check if a value inside a `Some` meets a\n * specified condition. If the `Option` is `None`, the result is `false`. If the\n * `Option` is `Some`, the provided predicate or refinement is applied to the\n * value:\n *\n * - If the condition is met, the result is `true`.\n * - If the condition is not met, the result is `false`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * console.log(Option.some(2).pipe(Option.exists(isEven)))\n * // Output: true\n *\n * console.log(Option.some(1).pipe(Option.exists(isEven)))\n * // Output: false\n *\n * console.log(Option.none().pipe(Option.exists(isEven)))\n * // Output: false\n * ```\n *\n * @category Elements\n * @since 2.0.0\n */\nexport const exists: {\n /**\n * Checks if a value in an `Option` satisfies a given predicate or refinement.\n *\n * **Details**\n *\n * This function allows you to check if a value inside a `Some` meets a\n * specified condition. If the `Option` is `None`, the result is `false`. If the\n * `Option` is `Some`, the provided predicate or refinement is applied to the\n * value:\n *\n * - If the condition is met, the result is `true`.\n * - If the condition is not met, the result is `false`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * console.log(Option.some(2).pipe(Option.exists(isEven)))\n * // Output: true\n *\n * console.log(Option.some(1).pipe(Option.exists(isEven)))\n * // Output: false\n *\n * console.log(Option.none().pipe(Option.exists(isEven)))\n * // Output: false\n * ```\n *\n * @category Elements\n * @since 2.0.0\n */\n <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: Option<A>) => self is Option<B>\n /**\n * Checks if a value in an `Option` satisfies a given predicate or refinement.\n *\n * **Details**\n *\n * This function allows you to check if a value inside a `Some` meets a\n * specified condition. If the `Option` is `None`, the result is `false`. If the\n * `Option` is `Some`, the provided predicate or refinement is applied to the\n * value:\n *\n * - If the condition is met, the result is `true`.\n * - If the condition is not met, the result is `false`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * console.log(Option.some(2).pipe(Option.exists(isEven)))\n * // Output: true\n *\n * console.log(Option.some(1).pipe(Option.exists(isEven)))\n * // Output: false\n *\n * console.log(Option.none().pipe(Option.exists(isEven)))\n * // Output: false\n * ```\n *\n * @category Elements\n * @since 2.0.0\n */\n <A>(predicate: Predicate<NoInfer<A>>): (self: Option<A>) => boolean\n /**\n * Checks if a value in an `Option` satisfies a given predicate or refinement.\n *\n * **Details**\n *\n * This function allows you to check if a value inside a `Some` meets a\n * specified condition. If the `Option` is `None`, the result is `false`. If the\n * `Option` is `Some`, the provided predicate or refinement is applied to the\n * value:\n *\n * - If the condition is met, the result is `true`.\n * - If the condition is not met, the result is `false`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * console.log(Option.some(2).pipe(Option.exists(isEven)))\n * // Output: true\n *\n * console.log(Option.some(1).pipe(Option.exists(isEven)))\n * // Output: false\n *\n * console.log(Option.none().pipe(Option.exists(isEven)))\n * // Output: false\n * ```\n *\n * @category Elements\n * @since 2.0.0\n */\n <A, B extends A>(self: Option<A>, refinement: Refinement<A, B>): self is Option<B>\n /**\n * Checks if a value in an `Option` satisfies a given predicate or refinement.\n *\n * **Details**\n *\n * This function allows you to check if a value inside a `Some` meets a\n * specified condition. If the `Option` is `None`, the result is `false`. If the\n * `Option` is `Some`, the provided predicate or refinement is applied to the\n * value:\n *\n * - If the condition is met, the result is `true`.\n * - If the condition is not met, the result is `false`.\n *\n * @example\n * ```ts\n * import { Option } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n *\n * console.log(Option.some(2).pipe(Option.exists(isEven)))\n * // Output: true\n *\n * console.log(Option.some(1).pipe(Option.exists(isEven)))\n * // Output: false\n *\n * console.log(Option.none().pipe(Option.exists(isEven)))\n * // Output: false\n * ```\n *\n * @category Elements\n * @since 2.0.0\n */\n <A>(self: Option<A>, predicate: Predicate<A>): boolean\n} = dual(\n 2,\n <A, B extends A>(self: Option<A>, refinement: Refinement<A, B>): self is Option<B> =>\n isNone(self) ? false : refinement(self.value)\n)\n\n// -------------------------------------------------------------------------------------\n// do notation\n// -------------------------------------------------------------------------------------\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @category Do notation\n * @since 2.0.0\n */\nexport const bindTo: {\n // -------------------------------------------------------------------------------------\n // do notation\n // -------------------------------------------------------------------------------------\n\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @category Do notation\n * @since 2.0.0\n */\n <N extends string>(name: N): <A>(self: Option<A>) => Option<{ [K in N]: A }>\n // -------------------------------------------------------------------------------------\n // do notation\n // -------------------------------------------------------------------------------------\n\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @category Do notation\n * @since 2.0.0\n */\n <A, N extends string>(self: Option<A>, name: N): Option<{ [K in N]: A }>\n} = doNotation.bindTo<OptionTypeLambda>(map)\n\nconst let_: {\n <N extends string, A extends object, B>(\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): (self: Option<A>) => Option<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n <A extends object, N extends string, B>(\n self: Option<A>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): Option<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n} = doNotation.let_<OptionTypeLambda>(map)\n\nexport {\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bind}\n * @see {@link bindTo}\n *\n * @category Do notation\n * @since 2.0.0\n */\n let_ as let\n}\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @category Do notation\n * @since 2.0.0\n */\nexport const bind: {\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @category Do notation\n * @since 2.0.0\n */\n <N extends string, A extends object, B>(name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Option<B>): (self: Option<A>) => Option<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n /**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link Do}\n * @see {@link bindTo}\n * @see {@link let_ let}\n *\n * @category Do notation\n * @since 2.0.0\n */\n <A extends object, N extends string, B>(\n self: Option<A>,\n name: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => Option<B>\n ): Option<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n} = doNotation.bind<OptionTypeLambda>(map, flatMap)\n\n/**\n * The \"do simulation\" in Effect allows you to write code in a more declarative style, similar to the \"do notation\" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Option` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Option, pipe } from \"effect\"\n *\n * const result = pipe(\n * Option.Do,\n * Option.bind(\"x\", () => Option.some(2)),\n * Option.bind(\"y\", () => Option.some(3)),\n * Option.let(\"sum\", ({ x, y }) => x + y),\n * Option.filter(({ x, y }) => x * y > 5)\n * )\n * assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))\n * ```\n *\n * @see {@link bindTo}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @category Do notation\n * @since 2.0.0\n */\nexport const Do: Option<{}> = some({})\n\nconst adapter = Gen.adapter<OptionTypeLambda>()\n\n/**\n * Similar to `Effect.gen`, `Option.gen` provides a more readable,\n * generator-based syntax for working with `Option` values, making code that\n * involves `Option` easier to write and understand. This approach is similar to\n * using `async/await` but tailored for `Option`.\n *\n * **Example** (Using `Option.gen` to Create a Combined Value)\n *\n * ```ts\n * import { Option } from \"effect\"\n *\n * const maybeName: Option.Option<string> = Option.some(\"John\")\n * const maybeAge: Option.Option<number> = Option.some(25)\n *\n * const person = Option.gen(function* () {\n * const name = (yield* maybeName).toUpperCase()\n * const age = yield* maybeAge\n * return { name, age }\n * })\n *\n * console.log(person)\n * // Output:\n * // { _id: 'Option', _tag: 'Some', value: { name: 'JOHN', age: 25 } }\n * ```\n *\n * @category Generators\n * @since 2.0.0\n */\nexport const gen: Gen.Gen<OptionTypeLambda, Gen.Adapter<OptionTypeLambda>> = (...args) => {\n const f = args.length === 1 ? args[0] : args[1].bind(args[0])\n const iterator = f(adapter)\n let state: IteratorResult<any> = iterator.next()\n while (!state.done) {\n const current = Gen.isGenKind(state.value)\n ? state.value.value\n : Gen.yieldWrapGet(state.value)\n if (isNone(current)) {\n return current\n }\n state = iterator.next(current.value as never)\n }\n return some(state.value)\n}\n\n/**\n * Merges two optional values, applying a function if both exist.\n * Unlike {@link zipWith}, this function returns `None` only if both inputs are `None`.\n *\n * @internal\n */\nexport const mergeWith = <A>(f: (a1: A, a2: A) => A) => (o1: Option<A>, o2: Option<A>): Option<A> => {\n if (isNone(o1)) {\n return o2\n } else if (isNone(o2)) {\n return o1\n }\n return some(f(o1.value, o2.value))\n}\n","/**\n * This module provides utility functions for working with arrays in TypeScript.\n *\n * @since 2.0.0\n */\n\nimport * as Either from \"./Either.js\"\nimport * as Equal from \"./Equal.js\"\nimport * as Equivalence from \"./Equivalence.js\"\nimport type { LazyArg } from \"./Function.js\"\nimport { dual, identity } from \"./Function.js\"\nimport type { TypeLambda } from \"./HKT.js\"\nimport * as internalArray from \"./internal/array.js\"\nimport * as internalDoNotation from \"./internal/doNotation.js\"\nimport * as moduleIterable from \"./Iterable.js\"\nimport * as Option from \"./Option.js\"\nimport * as Order from \"./Order.js\"\nimport * as Predicate from \"./Predicate.js\"\nimport * as Record from \"./Record.js\"\nimport * as Tuple from \"./Tuple.js\"\nimport type { NoInfer } from \"./Types.js\"\n\n/**\n * @category type lambdas\n * @since 2.0.0\n */\nexport interface ReadonlyArrayTypeLambda extends TypeLambda {\n readonly type: ReadonlyArray<this[\"Target\"]>\n}\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport type NonEmptyReadonlyArray<A> = readonly [A, ...Array<A>]\n\n/**\n * @category models\n * @since 2.0.0\n */\nexport type NonEmptyArray<A> = [A, ...Array<A>]\n\n/**\n * Builds a `NonEmptyArray` from an non-empty collection of elements.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.make(1, 2, 3)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const make = <Elements extends NonEmptyArray<any>>(\n ...elements: Elements\n): NonEmptyArray<Elements[number]> => elements\n\n/**\n * Creates a new `Array` of the specified length.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.allocate<number>(3)\n * console.log(result) // [ <3 empty items> ]\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const allocate = <A = never>(n: number): Array<A | undefined> => new Array(n)\n\n/**\n * Return a `NonEmptyArray` of length `n` with element `i` initialized with `f(i)`.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * **Example**\n *\n * ```ts\n * import { makeBy } from \"effect/Array\"\n *\n * const result = makeBy(5, n => n * 2)\n * console.log(result) // [0, 2, 4, 6, 8]\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const makeBy: {\n /**\n * Return a `NonEmptyArray` of length `n` with element `i` initialized with `f(i)`.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * **Example**\n *\n * ```ts\n * import { makeBy } from \"effect/Array\"\n *\n * const result = makeBy(5, n => n * 2)\n * console.log(result) // [0, 2, 4, 6, 8]\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <A>(f: (i: number) => A): (n: number) => NonEmptyArray<A>\n /**\n * Return a `NonEmptyArray` of length `n` with element `i` initialized with `f(i)`.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * **Example**\n *\n * ```ts\n * import { makeBy } from \"effect/Array\"\n *\n * const result = makeBy(5, n => n * 2)\n * console.log(result) // [0, 2, 4, 6, 8]\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <A>(n: number, f: (i: number) => A): NonEmptyArray<A>\n} = dual(2, <A>(n: number, f: (i: number) => A) => {\n const max = Math.max(1, Math.floor(n))\n const out = new Array(max)\n for (let i = 0; i < max; i++) {\n out[i] = f(i)\n }\n return out as NonEmptyArray<A>\n})\n\n/**\n * Return a `NonEmptyArray` containing a range of integers, including both endpoints.\n *\n * **Example**\n *\n * ```ts\n * import { range } from \"effect/Array\"\n *\n * const result = range(1, 3)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const range = (start: number, end: number): NonEmptyArray<number> =>\n start <= end ? makeBy(end - start + 1, (i) => start + i) : [start]\n\n/**\n * Return a `NonEmptyArray` containing a value repeated the specified number of times.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.replicate(\"a\", 3)\n * console.log(result) // [\"a\", \"a\", \"a\"]\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const replicate: {\n /**\n * Return a `NonEmptyArray` containing a value repeated the specified number of times.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.replicate(\"a\", 3)\n * console.log(result) // [\"a\", \"a\", \"a\"]\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n (n: number): <A>(a: A) => NonEmptyArray<A>\n /**\n * Return a `NonEmptyArray` containing a value repeated the specified number of times.\n *\n * **Note**. `n` is normalized to an integer >= 1.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.replicate(\"a\", 3)\n * console.log(result) // [\"a\", \"a\", \"a\"]\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\n <A>(a: A, n: number): NonEmptyArray<A>\n} = dual(2, <A>(a: A, n: number): NonEmptyArray<A> => makeBy(n, () => a))\n\n/**\n * Creates a new `Array` from an iterable collection of values.\n * If the input is already an array, it returns the input as-is.\n * Otherwise, it converts the iterable collection to an array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.fromIterable(new Set([1, 2, 3]))\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const fromIterable = <A>(collection: Iterable<A>): Array<A> =>\n Array.isArray(collection) ? collection : Array.from(collection)\n\n/**\n * Creates a new `Array` from a value that might not be an iterable.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * console.log(Array.ensure(\"a\")) // [\"a\"]\n * console.log(Array.ensure([\"a\"])) // [\"a\"]\n * console.log(Array.ensure([\"a\", \"b\", \"c\"])) // [\"a\", \"b\", \"c\"]\n * ```\n *\n * @category constructors\n * @since 3.3.0\n */\nexport const ensure = <A>(self: ReadonlyArray<A> | A): Array<A> => Array.isArray(self) ? self : [self as A]\n\n/**\n * Takes a record and returns an array of tuples containing its keys and values.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.fromRecord({ a: 1, b: 2, c: 3 })\n * console.log(result) // [[\"a\", 1], [\"b\", 2], [\"c\", 3]]\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const fromRecord: <K extends string, A>(self: Readonly<Record<K, A>>) => Array<[K, A]> = Record.toEntries\n\n/**\n * Converts an `Option` to an array.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * console.log(Array.fromOption(Option.some(1))) // [1]\n * console.log(Array.fromOption(Option.none())) // []\n * ```\n *\n * @category conversions\n * @since 2.0.0\n */\nexport const fromOption: <A>(self: Option.Option<A>) => Array<A> = Option.toArray\n\n/**\n * Matches the elements of an array, applying functions to cases of empty and non-empty arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const match = Array.match({\n * onEmpty: () => \"empty\",\n * onNonEmpty: ([head, ...tail]) => `head: ${head}, tail: ${tail.length}`\n * })\n * console.log(match([])) // \"empty\"\n * console.log(match([1, 2, 3])) // \"head: 1, tail: 2\"\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\nexport const match: {\n /**\n * Matches the elements of an array, applying functions to cases of empty and non-empty arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const match = Array.match({\n * onEmpty: () => \"empty\",\n * onNonEmpty: ([head, ...tail]) => `head: ${head}, tail: ${tail.length}`\n * })\n * console.log(match([])) // \"empty\"\n * console.log(match([1, 2, 3])) // \"head: 1, tail: 2\"\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <B, A, C = B>(\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (self: NonEmptyReadonlyArray<A>) => C\n }\n ): (self: ReadonlyArray<A>) => B | C\n /**\n * Matches the elements of an array, applying functions to cases of empty and non-empty arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const match = Array.match({\n * onEmpty: () => \"empty\",\n * onNonEmpty: ([head, ...tail]) => `head: ${head}, tail: ${tail.length}`\n * })\n * console.log(match([])) // \"empty\"\n * console.log(match([1, 2, 3])) // \"head: 1, tail: 2\"\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <A, B, C = B>(\n self: ReadonlyArray<A>,\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (self: NonEmptyReadonlyArray<A>) => C\n }\n ): B | C\n} = dual(2, <A, B, C = B>(\n self: ReadonlyArray<A>,\n { onEmpty, onNonEmpty }: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (self: NonEmptyReadonlyArray<A>) => C\n }\n): B | C => isNonEmptyReadonlyArray(self) ? onNonEmpty(self) : onEmpty())\n\n/**\n * Matches the elements of an array from the left, applying functions to cases of empty and non-empty arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchLeft = Array.matchLeft({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (head, tail) => `head: ${head}, tail: ${tail.length}`\n * })\n * console.log(matchLeft([])) // \"empty\"\n * console.log(matchLeft([1, 2, 3])) // \"head: 1, tail: 2\"\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\nexport const matchLeft: {\n /**\n * Matches the elements of an array from the left, applying functions to cases of empty and non-empty arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchLeft = Array.matchLeft({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (head, tail) => `head: ${head}, tail: ${tail.length}`\n * })\n * console.log(matchLeft([])) // \"empty\"\n * console.log(matchLeft([1, 2, 3])) // \"head: 1, tail: 2\"\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <B, A, C = B>(\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (head: A, tail: Array<A>) => C\n }\n ): (self: ReadonlyArray<A>) => B | C\n /**\n * Matches the elements of an array from the left, applying functions to cases of empty and non-empty arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchLeft = Array.matchLeft({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (head, tail) => `head: ${head}, tail: ${tail.length}`\n * })\n * console.log(matchLeft([])) // \"empty\"\n * console.log(matchLeft([1, 2, 3])) // \"head: 1, tail: 2\"\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <A, B, C = B>(\n self: ReadonlyArray<A>,\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (head: A, tail: Array<A>) => C\n }\n ): B | C\n} = dual(2, <A, B, C = B>(\n self: ReadonlyArray<A>,\n { onEmpty, onNonEmpty }: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (head: A, tail: Array<A>) => C\n }\n): B | C => isNonEmptyReadonlyArray(self) ? onNonEmpty(headNonEmpty(self), tailNonEmpty(self)) : onEmpty())\n\n/**\n * Matches the elements of an array from the right, applying functions to cases of empty and non-empty arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchRight = Array.matchRight({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (init, last) => `init: ${init.length}, last: ${last}`\n * })\n * console.log(matchRight([])) // \"empty\"\n * console.log(matchRight([1, 2, 3])) // \"init: 2, last: 3\"\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\nexport const matchRight: {\n /**\n * Matches the elements of an array from the right, applying functions to cases of empty and non-empty arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchRight = Array.matchRight({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (init, last) => `init: ${init.length}, last: ${last}`\n * })\n * console.log(matchRight([])) // \"empty\"\n * console.log(matchRight([1, 2, 3])) // \"init: 2, last: 3\"\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <B, A, C = B>(\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (init: Array<A>, last: A) => C\n }\n ): (self: ReadonlyArray<A>) => B | C\n /**\n * Matches the elements of an array from the right, applying functions to cases of empty and non-empty arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const matchRight = Array.matchRight({\n * onEmpty: () => \"empty\",\n * onNonEmpty: (init, last) => `init: ${init.length}, last: ${last}`\n * })\n * console.log(matchRight([])) // \"empty\"\n * console.log(matchRight([1, 2, 3])) // \"init: 2, last: 3\"\n * ```\n *\n * @category pattern matching\n * @since 2.0.0\n */\n <A, B, C = B>(\n self: ReadonlyArray<A>,\n options: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (init: Array<A>, last: A) => C\n }\n ): B | C\n} = dual(2, <A, B, C = B>(\n self: ReadonlyArray<A>,\n { onEmpty, onNonEmpty }: {\n readonly onEmpty: LazyArg<B>\n readonly onNonEmpty: (init: Array<A>, last: A) => C\n }\n): B | C =>\n isNonEmptyReadonlyArray(self) ?\n onNonEmpty(initNonEmpty(self), lastNonEmpty(self)) :\n onEmpty())\n\n/**\n * Prepend an element to the front of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.prepend([2, 3, 4], 1)\n * console.log(result) // [1, 2, 3, 4]\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const prepend: {\n /**\n * Prepend an element to the front of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.prepend([2, 3, 4], 1)\n * console.log(result) // [1, 2, 3, 4]\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <B>(head: B): <A>(self: Iterable<A>) => NonEmptyArray<A | B>\n /**\n * Prepend an element to the front of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.prepend([2, 3, 4], 1)\n * console.log(result) // [1, 2, 3, 4]\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, head: B): NonEmptyArray<A | B>\n} = dual(2, <A, B>(self: Iterable<A>, head: B): NonEmptyArray<A | B> => [head, ...self])\n\n/**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.prependAll([2, 3], [0, 1])\n * console.log(result) // [0, 1, 2, 3]\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const prependAll: {\n /**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.prependAll([2, 3], [0, 1])\n * console.log(result) // [0, 1, 2, 3]\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <S extends Iterable<any>, T extends Iterable<any>>(that: T): (self: S) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>\n /**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.prependAll([2, 3], [0, 1])\n * console.log(result) // [0, 1, 2, 3]\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<A | B>\n /**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.prependAll([2, 3], [0, 1])\n * console.log(result) // [0, 1, 2, 3]\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, that: Iterable<B>): NonEmptyArray<A | B>\n /**\n * Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).\n * If either array is non-empty, the result is also a non-empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.prependAll([2, 3], [0, 1])\n * console.log(result) // [0, 1, 2, 3]\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B>\n} = dual(\n 2,\n <A>(self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(that).concat(fromIterable(self))\n)\n\n/**\n * Append an element to the end of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.append([1, 2, 3], 4);\n * console.log(result) // [1, 2, 3, 4]\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const append: {\n /**\n * Append an element to the end of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.append([1, 2, 3], 4);\n * console.log(result) // [1, 2, 3, 4]\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <B>(last: B): <A>(self: Iterable<A>) => NonEmptyArray<A | B>\n /**\n * Append an element to the end of an `Iterable`, creating a new `NonEmptyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.append([1, 2, 3], 4);\n * console.log(result) // [1, 2, 3, 4]\n * ```\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, last: B): NonEmptyArray<A | B>\n} = dual(2, <A, B>(self: Iterable<A>, last: B): Array<A | B> => [...self, last])\n\n/**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\nexport const appendAll: {\n /**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <S extends Iterable<any>, T extends Iterable<any>>(that: T): (self: S) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>\n /**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<A | B>\n /**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, that: Iterable<B>): NonEmptyArray<A | B>\n /**\n * Concatenates two arrays (or iterables), combining their elements.\n * If either array is non-empty, the result is also a non-empty array.\n *\n * @category concatenating\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B>\n} = dual(\n 2,\n <A>(self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(self).concat(fromIterable(that))\n)\n\n/**\n * Accumulates values from an `Iterable` starting from the left, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.scan([1, 2, 3, 4], 0, (acc, value) => acc + value)\n * console.log(result) // [0, 1, 3, 6, 10]\n *\n * // Explanation:\n * // This function starts with the initial value (0 in this case)\n * // and adds each element of the array to this accumulator one by one,\n * // keeping track of the cumulative sum after each addition.\n * // Each of these sums is captured in the resulting array.\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const scan: {\n /**\n * Accumulates values from an `Iterable` starting from the left, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.scan([1, 2, 3, 4], 0, (acc, value) => acc + value)\n * console.log(result) // [0, 1, 3, 6, 10]\n *\n * // Explanation:\n * // This function starts with the initial value (0 in this case)\n * // and adds each element of the array to this accumulator one by one,\n * // keeping track of the cumulative sum after each addition.\n * // Each of these sums is captured in the resulting array.\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A) => B): (self: Iterable<A>) => NonEmptyArray<B>\n /**\n * Accumulates values from an `Iterable` starting from the left, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.scan([1, 2, 3, 4], 0, (acc, value) => acc + value)\n * console.log(result) // [0, 1, 3, 6, 10]\n *\n * // Explanation:\n * // This function starts with the initial value (0 in this case)\n * // and adds each element of the array to this accumulator one by one,\n * // keeping track of the cumulative sum after each addition.\n * // Each of these sums is captured in the resulting array.\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B>\n} = dual(3, <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B> => {\n const out: NonEmptyArray<B> = [b]\n let i = 0\n for (const a of self) {\n out[i + 1] = f(out[i], a)\n i++\n }\n return out\n})\n\n/**\n * Accumulates values from an `Iterable` starting from the right, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.scanRight([1, 2, 3, 4], 0, (acc, value) => acc + value)\n * console.log(result) // [10, 9, 7, 4, 0]\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const scanRight: {\n /**\n * Accumulates values from an `Iterable` starting from the right, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.scanRight([1, 2, 3, 4], 0, (acc, value) => acc + value)\n * console.log(result) // [10, 9, 7, 4, 0]\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A) => B): (self: Iterable<A>) => NonEmptyArray<B>\n /**\n * Accumulates values from an `Iterable` starting from the right, storing\n * each intermediate result in an array. Useful for tracking the progression of\n * a value through a series of transformations.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.scanRight([1, 2, 3, 4], 0, (acc, value) => acc + value)\n * console.log(result) // [10, 9, 7, 4, 0]\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B>\n} = dual(3, <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B> => {\n const input = fromIterable(self)\n const out: NonEmptyArray<B> = new Array(input.length + 1) as any\n out[input.length] = b\n for (let i = input.length - 1; i >= 0; i--) {\n out[i] = f(out[i + 1], input[i])\n }\n return out\n})\n\n/**\n * Determine if `unknown` is an Array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * console.log(Array.isArray(null)) // false\n * console.log(Array.isArray([1, 2, 3])) // true\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isArray: {\n /**\n * Determine if `unknown` is an Array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * console.log(Array.isArray(null)) // false\n * console.log(Array.isArray([1, 2, 3])) // true\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\n (self: unknown): self is Array<unknown>\n /**\n * Determine if `unknown` is an Array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * console.log(Array.isArray(null)) // false\n * console.log(Array.isArray([1, 2, 3])) // true\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\n <T>(self: T): self is Extract<T, ReadonlyArray<any>>\n} = Array.isArray\n\n/**\n * Determine if an `Array` is empty narrowing down the type to `[]`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * console.log(Array.isEmptyArray([])) // true\n * console.log(Array.isEmptyArray([1, 2, 3])) // false\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isEmptyArray = <A>(self: Array<A>): self is [] => self.length === 0\n\n/**\n * Determine if a `ReadonlyArray` is empty narrowing down the type to `readonly []`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * console.log(Array.isEmptyReadonlyArray([])) // true\n * console.log(Array.isEmptyReadonlyArray([1, 2, 3])) // false\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isEmptyReadonlyArray: <A>(self: ReadonlyArray<A>) => self is readonly [] = isEmptyArray as any\n\n/**\n * Determine if an `Array` is non empty narrowing down the type to `NonEmptyArray`.\n *\n * An `Array` is considered to be a `NonEmptyArray` if it contains at least one element.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * console.log(Array.isNonEmptyArray([])) // false\n * console.log(Array.isNonEmptyArray([1, 2, 3])) // true\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNonEmptyArray: <A>(self: Array<A>) => self is NonEmptyArray<A> = internalArray.isNonEmptyArray\n\n/**\n * Determine if a `ReadonlyArray` is non empty narrowing down the type to `NonEmptyReadonlyArray`.\n *\n * A `ReadonlyArray` is considered to be a `NonEmptyReadonlyArray` if it contains at least one element.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * console.log(Array.isNonEmptyReadonlyArray([])) // false\n * console.log(Array.isNonEmptyReadonlyArray([1, 2, 3])) // true\n * ```\n *\n * @category guards\n * @since 2.0.0\n */\nexport const isNonEmptyReadonlyArray: <A>(self: ReadonlyArray<A>) => self is NonEmptyReadonlyArray<A> =\n internalArray.isNonEmptyArray\n\n/**\n * Return the number of elements in a `ReadonlyArray`.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const length = <A>(self: ReadonlyArray<A>): number => self.length\n\nconst isOutOfBounds = <A>(i: number, as: ReadonlyArray<A>): boolean => i < 0 || i >= as.length\n\nconst clamp = <A>(i: number, as: ReadonlyArray<A>): number => Math.floor(Math.min(Math.max(0, i), as.length))\n\n/**\n * This function provides a safe way to read a value at a particular index from a `ReadonlyArray`.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const get: {\n /**\n * This function provides a safe way to read a value at a particular index from a `ReadonlyArray`.\n *\n * @category getters\n * @since 2.0.0\n */\n (index: number): <A>(self: ReadonlyArray<A>) => Option.Option<A>\n /**\n * This function provides a safe way to read a value at a particular index from a `ReadonlyArray`.\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: ReadonlyArray<A>, index: number): Option.Option<A>\n} = dual(2, <A>(self: ReadonlyArray<A>, index: number): Option.Option<A> => {\n const i = Math.floor(index)\n return isOutOfBounds(i, self) ? Option.none() : Option.some(self[i])\n})\n\n/**\n * Gets an element unsafely, will throw on out of bounds.\n *\n * @since 2.0.0\n * @category unsafe\n */\nexport const unsafeGet: {\n /**\n * Gets an element unsafely, will throw on out of bounds.\n *\n * @since 2.0.0\n * @category unsafe\n */\n (index: number): <A>(self: ReadonlyArray<A>) => A\n /**\n * Gets an element unsafely, will throw on out of bounds.\n *\n * @since 2.0.0\n * @category unsafe\n */\n <A>(self: ReadonlyArray<A>, index: number): A\n} = dual(2, <A>(self: ReadonlyArray<A>, index: number): A => {\n const i = Math.floor(index)\n if (isOutOfBounds(i, self)) {\n throw new Error(`Index ${i} out of bounds`)\n }\n return self[i]\n})\n\n/**\n * Return a tuple containing the first element, and a new `Array` of the remaining elements, if any.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.unprepend([1, 2, 3, 4])\n * console.log(result) // [1, [2, 3, 4]]\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const unprepend = <A>(\n self: NonEmptyReadonlyArray<A>\n): [firstElement: A, remainingElements: Array<A>] => [headNonEmpty(self), tailNonEmpty(self)]\n\n/**\n * Return a tuple containing a copy of the `NonEmptyReadonlyArray` without its last element, and that last element.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\";\n *\n * const result = Array.unappend([1, 2, 3, 4])\n * console.log(result) // [[1, 2, 3], 4]\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const unappend = <A>(\n self: NonEmptyReadonlyArray<A>\n): [arrayWithoutLastElement: Array<A>, lastElement: A] => [initNonEmpty(self), lastNonEmpty(self)]\n\n/**\n * Get the first element of a `ReadonlyArray`, or `None` if the `ReadonlyArray` is empty.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const head: <A>(self: ReadonlyArray<A>) => Option.Option<A> = get(0)\n\n/**\n * Get the first element of a non empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.headNonEmpty([1, 2, 3, 4])\n * console.log(result) // 1\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const headNonEmpty: <A>(self: NonEmptyReadonlyArray<A>) => A = unsafeGet(0)\n\n/**\n * Get the last element in a `ReadonlyArray`, or `None` if the `ReadonlyArray` is empty.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const last = <A>(self: ReadonlyArray<A>): Option.Option<A> =>\n isNonEmptyReadonlyArray(self) ? Option.some(lastNonEmpty(self)) : Option.none()\n\n/**\n * Get the last element of a non empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.lastNonEmpty([1, 2, 3, 4])\n * console.log(result) // 4\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const lastNonEmpty = <A>(self: NonEmptyReadonlyArray<A>): A => self[self.length - 1]\n\n/**\n * Get all but the first element of an `Iterable`, creating a new `Array`, or `None` if the `Iterable` is empty.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const tail = <A>(self: Iterable<A>): Option.Option<Array<A>> => {\n const input = fromIterable(self)\n return isNonEmptyReadonlyArray(input) ? Option.some(tailNonEmpty(input)) : Option.none()\n}\n\n/**\n * Get all but the first element of a `NonEmptyReadonlyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.tailNonEmpty([1, 2, 3, 4])\n * console.log(result) // [2, 3, 4]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const tailNonEmpty = <A>(self: NonEmptyReadonlyArray<A>): Array<A> => self.slice(1)\n\n/**\n * Get all but the last element of an `Iterable`, creating a new `Array`, or `None` if the `Iterable` is empty.\n *\n * @category getters\n * @since 2.0.0\n */\nexport const init = <A>(self: Iterable<A>): Option.Option<Array<A>> => {\n const input = fromIterable(self)\n return isNonEmptyReadonlyArray(input) ? Option.some(initNonEmpty(input)) : Option.none()\n}\n\n/**\n * Get all but the last element of a non empty array, creating a new array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.initNonEmpty([1, 2, 3, 4])\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const initNonEmpty = <A>(self: NonEmptyReadonlyArray<A>): Array<A> => self.slice(0, -1)\n\n/**\n * Keep only a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.take([1, 2, 3, 4, 5], 3)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const take: {\n /**\n * Keep only a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.take([1, 2, 3, 4, 5], 3)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Keep only a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.take([1, 2, 3, 4, 5], 3)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n return input.slice(0, clamp(n, input))\n})\n\n/**\n * Keep only a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.takeRight([1, 2, 3, 4, 5], 3)\n * console.log(result) // [3, 4, 5]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const takeRight: {\n /**\n * Keep only a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.takeRight([1, 2, 3, 4, 5], 3)\n * console.log(result) // [3, 4, 5]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Keep only a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.takeRight([1, 2, 3, 4, 5], 3)\n * console.log(result) // [3, 4, 5]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n const i = clamp(n, input)\n return i === 0 ? [] : input.slice(-i)\n})\n\n/**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.takeWhile([1, 3, 2, 4, 1, 2], x => x < 4)\n * console.log(result) // [1, 3, 2]\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const takeWhile: {\n /**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.takeWhile([1, 3, 2, 4, 1, 2], x => x < 4)\n * console.log(result) // [1, 3, 2]\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Array<B>\n /**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.takeWhile([1, 3, 2, 4, 1, 2], x => x < 4)\n * console.log(result) // [1, 3, 2]\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Array<A>\n /**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.takeWhile([1, 3, 2, 4, 1, 2], x => x < 4)\n * console.log(result) // [1, 3, 2]\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Array<B>\n /**\n * Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.takeWhile([1, 3, 2, 4, 1, 2], x => x < 4)\n * console.log(result) // [1, 3, 2]\n *\n * // Explanation:\n * // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.\n * // - The next element (`3`) is also less than `4`, so it adds `3`.\n * // - The next element (`2`) is again less than `4`, so it adds `2`.\n * // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A>\n} = dual(2, <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A> => {\n let i = 0\n const out: Array<A> = []\n for (const a of self) {\n if (!predicate(a, i)) {\n break\n }\n out.push(a)\n i++\n }\n return out\n})\n\nconst spanIndex = <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): number => {\n let i = 0\n for (const a of self) {\n if (!predicate(a, i)) {\n break\n }\n i++\n }\n return i\n}\n\n/**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const span: {\n /**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => [init: Array<B>, rest: Array<Exclude<A, B>>]\n /**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => [init: Array<A>, rest: Array<A>]\n /**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): [init: Array<B>, rest: Array<Exclude<A, B>>]\n /**\n * Split an `Iterable` into two parts:\n *\n * 1. the longest initial subarray for which all elements satisfy the specified predicate\n * 2. the remaining elements\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [init: Array<A>, rest: Array<A>]\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [init: Array<A>, rest: Array<A>] =>\n splitAt(self, spanIndex(self, predicate))\n)\n\n/**\n * Drop a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.drop([1, 2, 3, 4, 5], 2)\n * console.log(result) // [3, 4, 5]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const drop: {\n /**\n * Drop a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.drop([1, 2, 3, 4, 5], 2)\n * console.log(result) // [3, 4, 5]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Drop a max number of elements from the start of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.drop([1, 2, 3, 4, 5], 2)\n * console.log(result) // [3, 4, 5]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n return input.slice(clamp(n, input), input.length)\n})\n\n/**\n * Drop a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dropRight([1, 2, 3, 4, 5], 2)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const dropRight: {\n /**\n * Drop a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dropRight([1, 2, 3, 4, 5], 2)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Drop a max number of elements from the end of an `Iterable`, creating a new `Array`.\n *\n * **Note**. `n` is normalized to a non negative integer.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dropRight([1, 2, 3, 4, 5], 2)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n return input.slice(0, input.length - clamp(n, input))\n})\n\n/**\n * Remove the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dropWhile([1, 2, 3, 4, 5], x => x < 4)\n * console.log(result) // [4, 5]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\nexport const dropWhile: {\n /**\n * Remove the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dropWhile([1, 2, 3, 4, 5], x => x < 4)\n * console.log(result) // [4, 5]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Array<A>\n /**\n * Remove the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dropWhile([1, 2, 3, 4, 5], x => x < 4)\n * console.log(result) // [4, 5]\n * ```\n *\n * @category getters\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A>\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A> =>\n fromIterable(self).slice(spanIndex(self, predicate))\n)\n\n/**\n * Return the first index for which a predicate holds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirstIndex([5, 3, 8, 9], x => x > 5)\n * console.log(result) // Option.some(2)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findFirstIndex: {\n /**\n * Return the first index for which a predicate holds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirstIndex([5, 3, 8, 9], x => x > 5)\n * console.log(result) // Option.some(2)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option.Option<number>\n /**\n * Return the first index for which a predicate holds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirstIndex([5, 3, 8, 9], x => x > 5)\n * console.log(result) // Option.some(2)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option.Option<number>\n} = dual(2, <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option.Option<number> => {\n let i = 0\n for (const a of self) {\n if (predicate(a, i)) {\n return Option.some(i)\n }\n i++\n }\n return Option.none()\n})\n\n/**\n * Return the last index for which a predicate holds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLastIndex([1, 3, 8, 9], x => x < 5)\n * console.log(result) // Option.some(1)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findLastIndex: {\n /**\n * Return the last index for which a predicate holds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLastIndex([1, 3, 8, 9], x => x < 5)\n * console.log(result) // Option.some(1)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option.Option<number>\n /**\n * Return the last index for which a predicate holds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLastIndex([1, 3, 8, 9], x => x < 5)\n * console.log(result) // Option.some(1)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option.Option<number>\n} = dual(2, <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option.Option<number> => {\n const input = fromIterable(self)\n for (let i = input.length - 1; i >= 0; i--) {\n if (predicate(input[i], i)) {\n return Option.some(i)\n }\n }\n return Option.none()\n})\n\n/**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirst([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findFirst: {\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirst([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(f: (a: NoInfer<A>, i: number) => Option.Option<B>): (self: Iterable<A>) => Option.Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirst([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Option.Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirst([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option.Option<A>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirst([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option.Option<B>): Option.Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirst([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Option.Option<B>\n /**\n * Returns the first element that satisfies the specified\n * predicate, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirst([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option.Option<A>\n} = moduleIterable.findFirst\n\n/**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLast([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const findLast: {\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLast([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(f: (a: NoInfer<A>, i: number) => Option.Option<B>): (self: Iterable<A>) => Option.Option<B>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLast([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Option.Option<B>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLast([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option.Option<A>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLast([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option.Option<B>): Option.Option<B>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLast([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Option.Option<B>\n /**\n * Finds the last element in an iterable collection that satisfies the given predicate or refinement.\n * Returns an `Option` containing the found element, or `Option.none` if no element matches.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findLast([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(result) // Option.some(4)\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option.Option<A>\n} = dual(\n 2,\n <A>(\n self: Iterable<A>,\n f: ((a: A, i: number) => boolean) | ((a: A, i: number) => Option.Option<A>)\n ): Option.Option<A> => {\n const input = fromIterable(self)\n for (let i = input.length - 1; i >= 0; i--) {\n const a = input[i]\n const o = f(a, i)\n if (Predicate.isBoolean(o)) {\n if (o) {\n return Option.some(a)\n }\n } else {\n if (Option.isSome(o)) {\n return o\n }\n }\n }\n return Option.none()\n }\n)\n\n/**\n * Returns a tuple of the first element that satisfies the specified\n * predicate and its index, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirstWithIndex([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some([4, 3])\n * ```\n *\n * @category elements\n * @since 3.17.0\n */\nexport const findFirstWithIndex: {\n /**\n * Returns a tuple of the first element that satisfies the specified\n * predicate and its index, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirstWithIndex([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some([4, 3])\n * ```\n *\n * @category elements\n * @since 3.17.0\n */\n <A, B>(f: (a: NoInfer<A>, i: number) => Option.Option<B>): (self: Iterable<A>) => Option.Option<[B, number]>\n /**\n * Returns a tuple of the first element that satisfies the specified\n * predicate and its index, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirstWithIndex([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some([4, 3])\n * ```\n *\n * @category elements\n * @since 3.17.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Option.Option<[B, number]>\n /**\n * Returns a tuple of the first element that satisfies the specified\n * predicate and its index, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirstWithIndex([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some([4, 3])\n * ```\n *\n * @category elements\n * @since 3.17.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option.Option<[A, number]>\n /**\n * Returns a tuple of the first element that satisfies the specified\n * predicate and its index, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirstWithIndex([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some([4, 3])\n * ```\n *\n * @category elements\n * @since 3.17.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option.Option<B>): Option.Option<[B, number]>\n /**\n * Returns a tuple of the first element that satisfies the specified\n * predicate and its index, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirstWithIndex([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some([4, 3])\n * ```\n *\n * @category elements\n * @since 3.17.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Option.Option<[B, number]>\n /**\n * Returns a tuple of the first element that satisfies the specified\n * predicate and its index, or `None` if no such element exists.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.findFirstWithIndex([1, 2, 3, 4, 5], x => x > 3)\n * console.log(result) // Option.some([4, 3])\n * ```\n *\n * @category elements\n * @since 3.17.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option.Option<[A, number]>\n} = dual(\n 2,\n <A>(\n self: Iterable<A>,\n f: ((a: A, i: number) => boolean) | ((a: A, i: number) => Option.Option<A>)\n ): Option.Option<[A, number]> => {\n let i = 0\n for (const a of self) {\n const o = f(a, i)\n if (Predicate.isBoolean(o)) {\n if (o) {\n return Option.some([a, i])\n }\n } else {\n if (Option.isSome(o)) {\n return Option.some([o.value, i])\n }\n }\n i++\n }\n return Option.none()\n }\n)\n\n/**\n * Counts all the element of the given array that pass the given predicate\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.countBy([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(result) // 2\n * ```\n *\n * @category folding\n * @since 3.16.0\n */\nexport const countBy: {\n /**\n * Counts all the element of the given array that pass the given predicate\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.countBy([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(result) // 2\n * ```\n *\n * @category folding\n * @since 3.16.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => number\n /**\n * Counts all the element of the given array that pass the given predicate\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.countBy([1, 2, 3, 4, 5], n => n % 2 === 0)\n * console.log(result) // 2\n * ```\n *\n * @category folding\n * @since 3.16.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): number\n} = dual(\n 2,\n <A>(\n self: Iterable<A>,\n f: (a: A, i: number) => boolean\n ): number => {\n let count = 0\n const as = fromIterable(self)\n for (let i = 0; i < as.length; i++) {\n const a = as[i]\n if (f(a, i)) {\n count++\n }\n }\n return count\n }\n)\n\n/**\n * Insert an element at the specified index, creating a new `NonEmptyArray`,\n * or return `None` if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.insertAt(['a', 'b', 'c', 'e'], 3, 'd')\n * console.log(result) // Option.some(['a', 'b', 'c', 'd', 'e'])\n * ```\n *\n * @since 2.0.0\n */\nexport const insertAt: {\n /**\n * Insert an element at the specified index, creating a new `NonEmptyArray`,\n * or return `None` if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.insertAt(['a', 'b', 'c', 'e'], 3, 'd')\n * console.log(result) // Option.some(['a', 'b', 'c', 'd', 'e'])\n * ```\n *\n * @since 2.0.0\n */\n <B>(i: number, b: B): <A>(self: Iterable<A>) => Option.Option<NonEmptyArray<A | B>>\n /**\n * Insert an element at the specified index, creating a new `NonEmptyArray`,\n * or return `None` if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.insertAt(['a', 'b', 'c', 'e'], 3, 'd')\n * console.log(result) // Option.some(['a', 'b', 'c', 'd', 'e'])\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, i: number, b: B): Option.Option<NonEmptyArray<A | B>>\n} = dual(3, <A, B>(self: Iterable<A>, i: number, b: B): Option.Option<NonEmptyArray<A | B>> => {\n const out: Array<A | B> = Array.from(self)\n // v--- `= self.length` is ok, it means inserting in last position\n if (i < 0 || i > out.length) {\n return Option.none()\n }\n out.splice(i, 0, b)\n return Option.some(out) as any\n})\n\n/**\n * Change the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.replace(['a', 'b', 'c', 'd'], 1, 'z')\n * console.log(result) // ['a', 'z', 'c', 'd']\n * ```\n *\n * @since 2.0.0\n */\nexport const replace: {\n /**\n * Change the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.replace(['a', 'b', 'c', 'd'], 1, 'z')\n * console.log(result) // ['a', 'z', 'c', 'd']\n * ```\n *\n * @since 2.0.0\n */\n <B>(i: number, b: B): <A, S extends Iterable<A> = Iterable<A>>(\n self: S\n ) => ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n /**\n * Change the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.replace(['a', 'b', 'c', 'd'], 1, 'z')\n * console.log(result) // ['a', 'z', 'c', 'd']\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(self: S, i: number, b: B): ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n} = dual(3, <A, B>(self: Iterable<A>, i: number, b: B): Array<A | B> => modify(self, i, () => b))\n\n/**\n * Replaces an element in an array with the given value, returning an option of the updated array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.replaceOption([1, 2, 3], 1, 4)\n * console.log(result) // Option.some([1, 4, 3])\n * ```\n *\n * @since 2.0.0\n */\nexport const replaceOption: {\n /**\n * Replaces an element in an array with the given value, returning an option of the updated array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.replaceOption([1, 2, 3], 1, 4)\n * console.log(result) // Option.some([1, 4, 3])\n * ```\n *\n * @since 2.0.0\n */\n <B>(i: number, b: B): <A, S extends Iterable<A> = Iterable<A>>(\n self: S\n ) => Option.Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>\n /**\n * Replaces an element in an array with the given value, returning an option of the updated array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.replaceOption([1, 2, 3], 1, 4)\n * console.log(result) // Option.some([1, 4, 3])\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(self: S, i: number, b: B): Option.Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>\n} = dual(\n 3,\n <A, B>(self: Iterable<A>, i: number, b: B): Option.Option<Array<A | B>> => modifyOption(self, i, () => b)\n)\n\n/**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modify([1, 2, 3, 4], 2, (n) => n * 2)\n * console.log(result) // [1, 2, 6, 4]\n * ```\n *\n * @since 2.0.0\n */\nexport const modify: {\n /**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modify([1, 2, 3, 4], 2, (n) => n * 2)\n * console.log(result) // [1, 2, 6, 4]\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(i: number, f: (a: ReadonlyArray.Infer<S>) => B): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n /**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modify([1, 2, 3, 4], 2, (n) => n * 2)\n * console.log(result) // [1, 2, 6, 4]\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(self: S, i: number, f: (a: ReadonlyArray.Infer<S>) => B): ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n} = dual(\n 3,\n <A, B>(self: Iterable<A>, i: number, f: (a: A) => B): Array<A | B> => {\n const out: Array<A | B> = Array.from(self)\n if (isOutOfBounds(i, out)) {\n return out\n }\n const b = f(out[i] as A)\n out[i] = b\n return out\n }\n)\n\n/**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return `None` if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const input = [1, 2, 3, 4]\n * const result = Array.modifyOption(input, 2, (n) => n * 2)\n * console.log(result) // Option.some([1, 2, 6, 4])\n *\n * const outOfBoundsResult = Array.modifyOption(input, 5, (n) => n * 2)\n * console.log(outOfBoundsResult) // Option.none()\n * ```\n *\n * @since 2.0.0\n */\nexport const modifyOption: {\n /**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return `None` if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const input = [1, 2, 3, 4]\n * const result = Array.modifyOption(input, 2, (n) => n * 2)\n * console.log(result) // Option.some([1, 2, 6, 4])\n *\n * const outOfBoundsResult = Array.modifyOption(input, 5, (n) => n * 2)\n * console.log(outOfBoundsResult) // Option.none()\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(i: number, f: (a: ReadonlyArray.Infer<S>) => B): (self: S) => Option.Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>\n /**\n * Apply a function to the element at the specified index, creating a new `Array`,\n * or return `None` if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const input = [1, 2, 3, 4]\n * const result = Array.modifyOption(input, 2, (n) => n * 2)\n * console.log(result) // Option.some([1, 2, 6, 4])\n *\n * const outOfBoundsResult = Array.modifyOption(input, 5, (n) => n * 2)\n * console.log(outOfBoundsResult) // Option.none()\n * ```\n *\n * @since 2.0.0\n */\n <A, B, S extends Iterable<A> = Iterable<A>>(self: S, i: number, f: (a: ReadonlyArray.Infer<S>) => B): Option.Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>\n} = dual(3, <A, B>(self: Iterable<A>, i: number, f: (a: A) => B): Option.Option<Array<A | B>> => {\n const arr = fromIterable(self)\n if (isOutOfBounds(i, arr)) {\n return Option.none()\n }\n const out: Array<A | B> = Array.isArray(self) ? self.slice() : arr\n const b = f(arr[i])\n out[i] = b\n return Option.some(out)\n})\n\n/**\n * Delete the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const input = [1, 2, 3, 4]\n * const result = Array.remove(input, 2)\n * console.log(result) // [1, 2, 4]\n *\n * const outOfBoundsResult = Array.remove(input, 5)\n * console.log(outOfBoundsResult) // [1, 2, 3, 4]\n * ```\n *\n * @since 2.0.0\n */\nexport const remove: {\n /**\n * Delete the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const input = [1, 2, 3, 4]\n * const result = Array.remove(input, 2)\n * console.log(result) // [1, 2, 4]\n *\n * const outOfBoundsResult = Array.remove(input, 5)\n * console.log(outOfBoundsResult) // [1, 2, 3, 4]\n * ```\n *\n * @since 2.0.0\n */\n (i: number): <A>(self: Iterable<A>) => Array<A>\n /**\n * Delete the element at the specified index, creating a new `Array`,\n * or return a copy of the input if the index is out of bounds.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const input = [1, 2, 3, 4]\n * const result = Array.remove(input, 2)\n * console.log(result) // [1, 2, 4]\n *\n * const outOfBoundsResult = Array.remove(input, 5)\n * console.log(outOfBoundsResult) // [1, 2, 3, 4]\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, i: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, i: number): Array<A> => {\n const out = Array.from(self)\n if (isOutOfBounds(i, out)) {\n return out\n }\n out.splice(i, 1)\n return out\n})\n\n/**\n * Delete the element at the specified index, creating a new `Array`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.removeOption(numbers, 2)\n * assert.deepStrictEqual(result, Option.some([1, 2, 4]))\n *\n * const outOfBoundsResult = Array.removeOption(numbers, 5)\n * assert.deepStrictEqual(outOfBoundsResult, Option.none())\n * ```\n *\n * @since 3.16.0\n */\nexport const removeOption: {\n /**\n * Delete the element at the specified index, creating a new `Array`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.removeOption(numbers, 2)\n * assert.deepStrictEqual(result, Option.some([1, 2, 4]))\n *\n * const outOfBoundsResult = Array.removeOption(numbers, 5)\n * assert.deepStrictEqual(outOfBoundsResult, Option.none())\n * ```\n *\n * @since 3.16.0\n */\n (i: number): <A>(self: Iterable<A>) => Option.Option<Array<A>>\n /**\n * Delete the element at the specified index, creating a new `Array`,\n * or return `None` if the index is out of bounds.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Array, Option } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4]\n * const result = Array.removeOption(numbers, 2)\n * assert.deepStrictEqual(result, Option.some([1, 2, 4]))\n *\n * const outOfBoundsResult = Array.removeOption(numbers, 5)\n * assert.deepStrictEqual(outOfBoundsResult, Option.none())\n * ```\n *\n * @since 3.16.0\n */\n <A>(self: Iterable<A>, i: number): Option.Option<Array<A>>\n} = dual(2, <A>(self: Iterable<A>, i: number): Option.Option<Array<A>> => {\n const arr = fromIterable(self)\n if (isOutOfBounds(i, arr)) {\n return Option.none()\n }\n const out = Array.isArray(self) ? self.slice() : arr\n out.splice(i, 1)\n return Option.some(out)\n})\n\n/**\n * Reverse an `Iterable`, creating a new `Array`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.reverse([1, 2, 3, 4])\n * console.log(result) // [4, 3, 2, 1]\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const reverse = <S extends Iterable<any>>(\n self: S\n): S extends NonEmptyReadonlyArray<infer A> ? NonEmptyArray<A> : S extends Iterable<infer A> ? Array<A> : never =>\n Array.from(self).reverse() as any\n\n/**\n * Create a new array with elements sorted in increasing order based on the specified comparator.\n * If the input is a `NonEmptyReadonlyArray`, the output will also be a `NonEmptyReadonlyArray`.\n *\n * @category sorting\n * @since 2.0.0\n */\nexport const sort: {\n /**\n * Create a new array with elements sorted in increasing order based on the specified comparator.\n * If the input is a `NonEmptyReadonlyArray`, the output will also be a `NonEmptyReadonlyArray`.\n *\n * @category sorting\n * @since 2.0.0\n */\n <B>(O: Order.Order<B>): <A extends B, S extends Iterable<A>>(self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * Create a new array with elements sorted in increasing order based on the specified comparator.\n * If the input is a `NonEmptyReadonlyArray`, the output will also be a `NonEmptyReadonlyArray`.\n *\n * @category sorting\n * @since 2.0.0\n */\n <A extends B, B>(self: NonEmptyReadonlyArray<A>, O: Order.Order<B>): NonEmptyArray<A>\n /**\n * Create a new array with elements sorted in increasing order based on the specified comparator.\n * If the input is a `NonEmptyReadonlyArray`, the output will also be a `NonEmptyReadonlyArray`.\n *\n * @category sorting\n * @since 2.0.0\n */\n <A extends B, B>(self: Iterable<A>, O: Order.Order<B>): Array<A>\n} = dual(2, <A extends B, B>(self: Iterable<A>, O: Order.Order<B>): Array<A> => {\n const out = Array.from(self)\n out.sort(O)\n return out\n})\n\n/**\n * Sorts an array based on a provided mapping function and order. The mapping\n * function transforms the elements into a value that can be compared, and the\n * order defines how those values should be sorted.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.sortWith([\"aaa\", \"b\", \"cc\"], (s) => s.length, Order.number)\n * console.log(result) // [\"b\", \"cc\", \"aaa\"]\n *\n * // Explanation:\n * // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`\n * // converts each string into its length, and the `Order.number` specifies that the lengths should\n * // be sorted in ascending order.\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\nexport const sortWith: {\n /**\n * Sorts an array based on a provided mapping function and order. The mapping\n * function transforms the elements into a value that can be compared, and the\n * order defines how those values should be sorted.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.sortWith([\"aaa\", \"b\", \"cc\"], (s) => s.length, Order.number)\n * console.log(result) // [\"b\", \"cc\", \"aaa\"]\n *\n * // Explanation:\n * // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`\n * // converts each string into its length, and the `Order.number` specifies that the lengths should\n * // be sorted in ascending order.\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <S extends Iterable<any>, B>(f: (a: ReadonlyArray.Infer<S>) => B, order: Order.Order<B>): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * Sorts an array based on a provided mapping function and order. The mapping\n * function transforms the elements into a value that can be compared, and the\n * order defines how those values should be sorted.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.sortWith([\"aaa\", \"b\", \"cc\"], (s) => s.length, Order.number)\n * console.log(result) // [\"b\", \"cc\", \"aaa\"]\n *\n * // Explanation:\n * // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`\n * // converts each string into its length, and the `Order.number` specifies that the lengths should\n * // be sorted in ascending order.\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B, O: Order.Order<B>): NonEmptyArray<A>\n /**\n * Sorts an array based on a provided mapping function and order. The mapping\n * function transforms the elements into a value that can be compared, and the\n * order defines how those values should be sorted.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.sortWith([\"aaa\", \"b\", \"cc\"], (s) => s.length, Order.number)\n * console.log(result) // [\"b\", \"cc\", \"aaa\"]\n *\n * // Explanation:\n * // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`\n * // converts each string into its length, and the `Order.number` specifies that the lengths should\n * // be sorted in ascending order.\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B>(self: Iterable<A>, f: (a: A) => B, order: Order.Order<B>): Array<A>\n} = dual(\n 3,\n <A, B>(self: Iterable<A>, f: (a: A) => B, order: Order.Order<B>): Array<A> =>\n Array.from(self).map((a) => [a, f(a)] as const).sort(([, a], [, b]) => order(a, b)).map(([_]) => _)\n)\n\n/**\n * Sorts the elements of an `Iterable` in increasing order based on the provided\n * orders. The elements are compared using the first order in `orders`, then the\n * second order if the first comparison is equal, and so on.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Order, pipe } from \"effect\"\n *\n * const users = [\n * { name: \"Alice\", age: 30 },\n * { name: \"Bob\", age: 25 },\n * { name: \"Charlie\", age: 30 }\n * ]\n *\n * const result = pipe(\n * users,\n * Array.sortBy(\n * Order.mapInput(Order.number, (user: (typeof users)[number]) => user.age),\n * Order.mapInput(Order.string, (user: (typeof users)[number]) => user.name)\n * )\n * )\n *\n * console.log(result)\n * // [\n * // { name: \"Bob\", age: 25 },\n * // { name: \"Alice\", age: 30 },\n * // { name: \"Charlie\", age: 30 }\n * // ]\n *\n * // Explanation:\n * // The array of users is sorted first by age in ascending order. When ages are equal,\n * // the users are further sorted by name in ascending order.\n * ```\n *\n * @category sorting\n * @since 2.0.0\n */\nexport const sortBy = <S extends Iterable<any>>(\n ...orders: ReadonlyArray<Order.Order<ReadonlyArray.Infer<S>>>\n) => {\n const sortByAll = sort(Order.combineAll(orders))\n return (\n self: S\n ): S extends NonEmptyReadonlyArray<infer A> ? NonEmptyArray<A> : S extends Iterable<infer A> ? Array<A> : never => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n return sortByAll(input) as any\n }\n return [] as any\n }\n}\n\n/**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zip([1, 2, 3], ['a', 'b'])\n * console.log(result) // [[1, 'a'], [2, 'b']]\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\nexport const zip: {\n /**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zip([1, 2, 3], ['a', 'b'])\n * console.log(result) // [[1, 'a'], [2, 'b']]\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B>(that: NonEmptyReadonlyArray<B>): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<[A, B]>\n /**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zip([1, 2, 3], ['a', 'b'])\n * console.log(result) // [[1, 'a'], [2, 'b']]\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B>(that: Iterable<B>): <A>(self: Iterable<A>) => Array<[A, B]>\n /**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zip([1, 2, 3], ['a', 'b'])\n * console.log(result) // [[1, 'a'], [2, 'b']]\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<[A, B]>\n /**\n * Takes two `Iterable`s and returns an `Array` of corresponding pairs.\n * If one input `Iterable` is short, excess elements of the\n * longer `Iterable` are discarded.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zip([1, 2, 3], ['a', 'b'])\n * console.log(result) // [[1, 'a'], [2, 'b']]\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<[A, B]>\n} = dual(\n 2,\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<[A, B]> => zipWith(self, that, Tuple.make)\n)\n\n/**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zipWith([1, 2, 3], [4, 5, 6], (a, b) => a + b)\n * console.log(result) // [5, 7, 9]\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\nexport const zipWith: {\n /**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zipWith([1, 2, 3], [4, 5, 6], (a, b) => a + b)\n * console.log(result) // [5, 7, 9]\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B, A, C>(that: NonEmptyReadonlyArray<B>, f: (a: A, b: B) => C): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<C>\n /**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zipWith([1, 2, 3], [4, 5, 6], (a, b) => a + b)\n * console.log(result) // [5, 7, 9]\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Array<C>\n /**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zipWith([1, 2, 3], [4, 5, 6], (a, b) => a + b)\n * console.log(result) // [5, 7, 9]\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <A, B, C>(\n self: NonEmptyReadonlyArray<A>,\n that: NonEmptyReadonlyArray<B>,\n f: (a: A, b: B) => C\n ): NonEmptyArray<C>\n /**\n * Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one\n * input `Iterable` is short, excess elements of the longer `Iterable` are discarded.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.zipWith([1, 2, 3], [4, 5, 6], (a, b) => a + b)\n * console.log(result) // [5, 7, 9]\n * ```\n *\n * @category zipping\n * @since 2.0.0\n */\n <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C>\n} = dual(3, <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C> => {\n const as = fromIterable(self)\n const bs = fromIterable(that)\n if (isNonEmptyReadonlyArray(as) && isNonEmptyReadonlyArray(bs)) {\n const out: NonEmptyArray<C> = [f(headNonEmpty(as), headNonEmpty(bs))]\n const len = Math.min(as.length, bs.length)\n for (let i = 1; i < len; i++) {\n out[i] = f(as[i], bs[i])\n }\n return out\n }\n return []\n})\n\n/**\n * This function is the inverse of `zip`. Takes an `Iterable` of pairs and return two corresponding `Array`s.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.unzip([[1, \"a\"], [2, \"b\"], [3, \"c\"]])\n * console.log(result) // [[1, 2, 3], ['a', 'b', 'c']]\n * ```\n *\n * @since 2.0.0\n */\nexport const unzip: <S extends Iterable<readonly [any, any]>>(\n self: S\n) => S extends NonEmptyReadonlyArray<readonly [infer A, infer B]> ? [NonEmptyArray<A>, NonEmptyArray<B>]\n : S extends Iterable<readonly [infer A, infer B]> ? [Array<A>, Array<B>]\n : never = (<A, B>(self: Iterable<readonly [A, B]>): [Array<A>, Array<B>] => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const fa: NonEmptyArray<A> = [input[0][0]]\n const fb: NonEmptyArray<B> = [input[0][1]]\n for (let i = 1; i < input.length; i++) {\n fa[i] = input[i][0]\n fb[i] = input[i][1]\n }\n return [fa, fb]\n }\n return [[], []]\n }) as any\n\n/**\n * Places an element in between members of an `Iterable`.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.intersperse([1, 2, 3], 0)\n * console.log(result) // [1, 0, 2, 0, 3]\n * ```\n *\n * @since 2.0.0\n */\nexport const intersperse: {\n /**\n * Places an element in between members of an `Iterable`.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.intersperse([1, 2, 3], 0)\n * console.log(result) // [1, 0, 2, 0, 3]\n * ```\n *\n * @since 2.0.0\n */\n <B>(middle: B): <S extends Iterable<any>>(self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>\n /**\n * Places an element in between members of an `Iterable`.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.intersperse([1, 2, 3], 0)\n * console.log(result) // [1, 0, 2, 0, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, middle: B): NonEmptyArray<A | B>\n /**\n * Places an element in between members of an `Iterable`.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.intersperse([1, 2, 3], 0)\n * console.log(result) // [1, 0, 2, 0, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, middle: B): Array<A | B>\n} = dual(2, <A, B>(self: Iterable<A>, middle: B): Array<A | B> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const out: NonEmptyArray<A | B> = [headNonEmpty(input)]\n const tail = tailNonEmpty(input)\n for (let i = 0; i < tail.length; i++) {\n if (i < tail.length) {\n out.push(middle)\n }\n out.push(tail[i])\n }\n return out\n }\n return []\n})\n\n/**\n * Apply a function to the head, creating a new `NonEmptyReadonlyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyHead([1, 2, 3], n => n * 10)\n * console.log(result) // [10, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\nexport const modifyNonEmptyHead: {\n /**\n * Apply a function to the head, creating a new `NonEmptyReadonlyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyHead([1, 2, 3], n => n * 10)\n * console.log(result) // [10, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>\n /**\n * Apply a function to the head, creating a new `NonEmptyReadonlyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyHead([1, 2, 3], n => n * 10)\n * console.log(result) // [10, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B): NonEmptyArray<A | B>\n} = dual(\n 2,\n <A, B>(\n self: NonEmptyReadonlyArray<A>,\n f: (a: A) => B\n ): NonEmptyArray<A | B> => [f(headNonEmpty(self)), ...tailNonEmpty(self)]\n)\n\n/**\n * Change the head, creating a new `NonEmptyReadonlyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyHead([1, 2, 3], 10)\n * console.log(result) // [10, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\nexport const setNonEmptyHead: {\n /**\n * Change the head, creating a new `NonEmptyReadonlyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyHead([1, 2, 3], 10)\n * console.log(result) // [10, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <B>(b: B): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>\n /**\n * Change the head, creating a new `NonEmptyReadonlyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyHead([1, 2, 3], 10)\n * console.log(result) // [10, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B>\n} = dual(\n 2,\n <A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B> => modifyNonEmptyHead(self, () => b)\n)\n\n/**\n * Apply a function to the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyLast([1, 2, 3], n => n * 2)\n * console.log(result) // [1, 2, 6]\n * ```\n *\n * @since 2.0.0\n */\nexport const modifyNonEmptyLast: {\n /**\n * Apply a function to the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyLast([1, 2, 3], n => n * 2)\n * console.log(result) // [1, 2, 6]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>\n /**\n * Apply a function to the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.modifyNonEmptyLast([1, 2, 3], n => n * 2)\n * console.log(result) // [1, 2, 6]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B): NonEmptyArray<A | B>\n} = dual(\n 2,\n <A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B): NonEmptyArray<A | B> =>\n append(initNonEmpty(self), f(lastNonEmpty(self)))\n)\n\n/**\n * Change the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyLast([1, 2, 3], 4)\n * console.log(result) // [1, 2, 4]\n * ```\n *\n * @since 2.0.0\n */\nexport const setNonEmptyLast: {\n /**\n * Change the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyLast([1, 2, 3], 4)\n * console.log(result) // [1, 2, 4]\n * ```\n *\n * @since 2.0.0\n */\n <B>(b: B): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>\n /**\n * Change the last element, creating a new `NonEmptyReadonlyArray`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.setNonEmptyLast([1, 2, 3], 4)\n * console.log(result) // [1, 2, 4]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B>\n} = dual(\n 2,\n <A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B> => modifyNonEmptyLast(self, () => b)\n)\n\n/**\n * Rotate an `Iterable` by `n` steps.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.rotate(['a', 'b', 'c', 'd', 'e'], 2)\n * console.log(result) // [ 'd', 'e', 'a', 'b', 'c' ]\n * ```\n *\n * @since 2.0.0\n */\nexport const rotate: {\n /**\n * Rotate an `Iterable` by `n` steps.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.rotate(['a', 'b', 'c', 'd', 'e'], 2)\n * console.log(result) // [ 'd', 'e', 'a', 'b', 'c' ]\n * ```\n *\n * @since 2.0.0\n */\n (n: number): <S extends Iterable<any>>(self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * Rotate an `Iterable` by `n` steps.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.rotate(['a', 'b', 'c', 'd', 'e'], 2)\n * console.log(result) // [ 'd', 'e', 'a', 'b', 'c' ]\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, n: number): NonEmptyArray<A>\n /**\n * Rotate an `Iterable` by `n` steps.\n * If the input is a non-empty array, the result is also a non-empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.rotate(['a', 'b', 'c', 'd', 'e'], 2)\n * console.log(result) // [ 'd', 'e', 'a', 'b', 'c' ]\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<A>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const len = input.length\n const m = Math.round(n) % len\n if (isOutOfBounds(Math.abs(m), input) || m === 0) {\n return copy(input)\n }\n if (m < 0) {\n const [f, s] = splitNonEmptyAt(input, -m)\n return appendAll(s, f)\n } else {\n return rotate(self, m - len)\n }\n }\n return []\n})\n\n/**\n * Returns a function that checks if a `ReadonlyArray` contains a given value using a provided `isEquivalent` function.\n *\n * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const isEquivalent = (a: number, b: number) => a === b\n * const containsNumber = Array.containsWith(isEquivalent)\n * const result = pipe([1, 2, 3, 4], containsNumber(3))\n * console.log(result) // true\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const containsWith = <A>(isEquivalent: (self: A, that: A) => boolean): {\n (a: A): (self: Iterable<A>) => boolean\n (self: Iterable<A>, a: A): boolean\n} =>\n dual(2, (self: Iterable<A>, a: A): boolean => {\n for (const i of self) {\n if (isEquivalent(a, i)) {\n return true\n }\n }\n return false\n })\n\nconst _equivalence = Equal.equivalence()\n\n/**\n * Returns a function that checks if a `ReadonlyArray` contains a given value using the default `Equivalence`.\n *\n * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const result = pipe(['a', 'b', 'c', 'd'], Array.contains('c'))\n * console.log(result) // true\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\nexport const contains: {\n /**\n * Returns a function that checks if a `ReadonlyArray` contains a given value using the default `Equivalence`.\n *\n * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const result = pipe(['a', 'b', 'c', 'd'], Array.contains('c'))\n * console.log(result) // true\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(a: A): (self: Iterable<A>) => boolean\n /**\n * Returns a function that checks if a `ReadonlyArray` contains a given value using the default `Equivalence`.\n *\n * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const result = pipe(['a', 'b', 'c', 'd'], Array.contains('c'))\n * console.log(result) // true\n * ```\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, a: A): boolean\n} = containsWith(_equivalence)\n\n/**\n * A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for \"chopping\" up the input\n * `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a\n * value and the rest of the `Array`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.chop([1, 2, 3, 4, 5], (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * console.log(result) // [2, 4, 6, 8, 10]\n *\n * // Explanation:\n * // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.\n * // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,\n * // resulting in a new array `[2, 4, 6, 8, 10]`.\n * ```\n *\n * @since 2.0.0\n */\nexport const chop: {\n /**\n * A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for \"chopping\" up the input\n * `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a\n * value and the rest of the `Array`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.chop([1, 2, 3, 4, 5], (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * console.log(result) // [2, 4, 6, 8, 10]\n *\n * // Explanation:\n * // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.\n * // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,\n * // resulting in a new array `[2, 4, 6, 8, 10]`.\n * ```\n *\n * @since 2.0.0\n */\n <S extends Iterable<any>, B>(\n f: (as: NonEmptyReadonlyArray<ReadonlyArray.Infer<S>>) => readonly [B, ReadonlyArray<ReadonlyArray.Infer<S>>]\n ): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for \"chopping\" up the input\n * `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a\n * value and the rest of the `Array`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.chop([1, 2, 3, 4, 5], (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * console.log(result) // [2, 4, 6, 8, 10]\n *\n * // Explanation:\n * // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.\n * // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,\n * // resulting in a new array `[2, 4, 6, 8, 10]`.\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: NonEmptyReadonlyArray<A>,\n f: (as: NonEmptyReadonlyArray<A>) => readonly [B, ReadonlyArray<A>]\n ): NonEmptyArray<B>\n /**\n * A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for \"chopping\" up the input\n * `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a\n * value and the rest of the `Array`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.chop([1, 2, 3, 4, 5], (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])\n * console.log(result) // [2, 4, 6, 8, 10]\n *\n * // Explanation:\n * // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.\n * // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,\n * // resulting in a new array `[2, 4, 6, 8, 10]`.\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: Iterable<A>,\n f: (as: NonEmptyReadonlyArray<A>) => readonly [B, ReadonlyArray<A>]\n ): Array<B>\n} = dual(2, <A, B>(\n self: Iterable<A>,\n f: (as: NonEmptyReadonlyArray<A>) => readonly [B, ReadonlyArray<A>]\n): Array<B> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const [b, rest] = f(input)\n const out: NonEmptyArray<B> = [b]\n let next: ReadonlyArray<A> = rest\n while (internalArray.isNonEmptyArray(next)) {\n const [b, rest] = f(next)\n out.push(b)\n next = rest\n }\n return out\n }\n return []\n})\n\n/**\n * Splits an `Iterable` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` can be `0`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitAt([1, 2, 3, 4, 5], 3)\n * console.log(result) // [[1, 2, 3], [4, 5]]\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const splitAt: {\n /**\n * Splits an `Iterable` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` can be `0`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitAt([1, 2, 3, 4, 5], 3)\n * console.log(result) // [[1, 2, 3], [4, 5]]\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n (n: number): <A>(self: Iterable<A>) => [beforeIndex: Array<A>, fromIndex: Array<A>]\n /**\n * Splits an `Iterable` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` can be `0`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitAt([1, 2, 3, 4, 5], 3)\n * console.log(result) // [[1, 2, 3], [4, 5]]\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): [beforeIndex: Array<A>, fromIndex: Array<A>]\n} = dual(2, <A>(self: Iterable<A>, n: number): [Array<A>, Array<A>] => {\n const input = Array.from(self)\n const _n = Math.floor(n)\n if (isNonEmptyReadonlyArray(input)) {\n if (_n >= 1) {\n return splitNonEmptyAt(input, _n)\n }\n return [[], input]\n }\n return [input, []]\n})\n\n/**\n * Splits a `NonEmptyReadonlyArray` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` must be `>= 1`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitNonEmptyAt([\"a\", \"b\", \"c\", \"d\", \"e\"], 3)\n * console.log(result) // [[\"a\", \"b\", \"c\"], [\"d\", \"e\"]]\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const splitNonEmptyAt: {\n /**\n * Splits a `NonEmptyReadonlyArray` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` must be `>= 1`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitNonEmptyAt([\"a\", \"b\", \"c\", \"d\", \"e\"], 3)\n * console.log(result) // [[\"a\", \"b\", \"c\"], [\"d\", \"e\"]]\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n (n: number): <A>(self: NonEmptyReadonlyArray<A>) => [beforeIndex: NonEmptyArray<A>, fromIndex: Array<A>]\n /**\n * Splits a `NonEmptyReadonlyArray` into two segments, with the first segment containing a maximum of `n` elements.\n * The value of `n` must be `>= 1`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitNonEmptyAt([\"a\", \"b\", \"c\", \"d\", \"e\"], 3)\n * console.log(result) // [[\"a\", \"b\", \"c\"], [\"d\", \"e\"]]\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, n: number): [beforeIndex: NonEmptyArray<A>, fromIndex: Array<A>]\n} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, n: number): [NonEmptyArray<A>, Array<A>] => {\n const _n = Math.max(1, Math.floor(n))\n return _n >= self.length ?\n [copy(self), []] :\n [prepend(self.slice(1, _n), headNonEmpty(self)), self.slice(_n)]\n})\n\n/**\n * Splits this iterable into `n` equally sized arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.split([1, 2, 3, 4, 5, 6, 7, 8], 3)\n * console.log(result) // [[1, 2, 3], [4, 5, 6], [7, 8]]\n * ```\n *\n * @since 2.0.0\n * @category splitting\n */\nexport const split: {\n /**\n * Splits this iterable into `n` equally sized arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.split([1, 2, 3, 4, 5, 6, 7, 8], 3)\n * console.log(result) // [[1, 2, 3], [4, 5, 6], [7, 8]]\n * ```\n *\n * @since 2.0.0\n * @category splitting\n */\n (n: number): <A>(self: Iterable<A>) => Array<Array<A>>\n /**\n * Splits this iterable into `n` equally sized arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.split([1, 2, 3, 4, 5, 6, 7, 8], 3)\n * console.log(result) // [[1, 2, 3], [4, 5, 6], [7, 8]]\n * ```\n *\n * @since 2.0.0\n * @category splitting\n */\n <A>(self: Iterable<A>, n: number): Array<Array<A>>\n} = dual(2, <A>(self: Iterable<A>, n: number) => {\n const input = fromIterable(self)\n return chunksOf(input, Math.ceil(input.length / Math.floor(n)))\n})\n\n/**\n * Splits this iterable on the first element that matches this predicate.\n * Returns a tuple containing two arrays: the first one is before the match, and the second one is from the match onward.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitWhere([1, 2, 3, 4, 5], n => n > 3)\n * console.log(result) // [[1, 2, 3], [4, 5]]\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const splitWhere: {\n /**\n * Splits this iterable on the first element that matches this predicate.\n * Returns a tuple containing two arrays: the first one is before the match, and the second one is from the match onward.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitWhere([1, 2, 3, 4, 5], n => n > 3)\n * console.log(result) // [[1, 2, 3], [4, 5]]\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => [beforeMatch: Array<A>, fromMatch: Array<A>]\n /**\n * Splits this iterable on the first element that matches this predicate.\n * Returns a tuple containing two arrays: the first one is before the match, and the second one is from the match onward.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.splitWhere([1, 2, 3, 4, 5], n => n > 3)\n * console.log(result) // [[1, 2, 3], [4, 5]]\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [beforeMatch: Array<A>, fromMatch: Array<A>]\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [beforeMatch: Array<A>, fromMatch: Array<A>] =>\n span(self, (a: A, i: number) => !predicate(a, i))\n)\n\n/**\n * Copies an array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.copy([1, 2, 3])\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\nexport const copy: {\n /**\n * Copies an array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.copy([1, 2, 3])\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>): NonEmptyArray<A>\n /**\n * Copies an array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.copy([1, 2, 3])\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: ReadonlyArray<A>): Array<A>\n} = (<A>(self: ReadonlyArray<A>): Array<A> => self.slice()) as any\n\n/**\n * Pads an array.\n * Returns a new array of length `n` with the elements of `array` followed by `fill` elements if `array` is shorter than `n`.\n * If `array` is longer than `n`, the returned array will be a slice of `array` containing the `n` first elements of `array`.\n * If `n` is less than or equal to 0, the returned array will be an empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.pad([1, 2, 3], 6, 0)\n * console.log(result) // [1, 2, 3, 0, 0, 0]\n * ```\n *\n * @since 3.8.4\n */\nexport const pad: {\n /**\n * Pads an array.\n * Returns a new array of length `n` with the elements of `array` followed by `fill` elements if `array` is shorter than `n`.\n * If `array` is longer than `n`, the returned array will be a slice of `array` containing the `n` first elements of `array`.\n * If `n` is less than or equal to 0, the returned array will be an empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.pad([1, 2, 3], 6, 0)\n * console.log(result) // [1, 2, 3, 0, 0, 0]\n * ```\n *\n * @since 3.8.4\n */\n <A, T>(n: number, fill: T): (\n self: Array<A>\n ) => Array<A | T>\n /**\n * Pads an array.\n * Returns a new array of length `n` with the elements of `array` followed by `fill` elements if `array` is shorter than `n`.\n * If `array` is longer than `n`, the returned array will be a slice of `array` containing the `n` first elements of `array`.\n * If `n` is less than or equal to 0, the returned array will be an empty array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.pad([1, 2, 3], 6, 0)\n * console.log(result) // [1, 2, 3, 0, 0, 0]\n * ```\n *\n * @since 3.8.4\n */\n <A, T>(self: Array<A>, n: number, fill: T): Array<A | T>\n} = dual(3, <A, T>(self: Array<A>, n: number, fill: T): Array<A | T> => {\n if (self.length >= n) {\n return take(self, n)\n }\n return appendAll(\n self,\n makeBy(n - self.length, () => fill)\n )\n})\n\n/**\n * Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of\n * the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive\n * definition of `chunksOf`; it satisfies the property that\n *\n * ```ts skip-type-checking\n * chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))\n * ```\n *\n * whenever `n` evenly divides the length of `self`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.chunksOf([1, 2, 3, 4, 5], 2)\n * console.log(result) // [[1, 2], [3, 4], [5]]\n *\n * // Explanation:\n * // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.\n * // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,\n * // the last chunk contains the remaining elements.\n * // The result is `[[1, 2], [3, 4], [5]]`.\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\nexport const chunksOf: {\n /**\n * Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of\n * the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive\n * definition of `chunksOf`; it satisfies the property that\n *\n * ```ts skip-type-checking\n * chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))\n * ```\n *\n * whenever `n` evenly divides the length of `self`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.chunksOf([1, 2, 3, 4, 5], 2)\n * console.log(result) // [[1, 2], [3, 4], [5]]\n *\n * // Explanation:\n * // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.\n * // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,\n * // the last chunk contains the remaining elements.\n * // The result is `[[1, 2], [3, 4], [5]]`.\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n (n: number): <S extends Iterable<any>>(\n self: S\n ) => ReadonlyArray.With<S, NonEmptyArray<ReadonlyArray.Infer<S>>>\n /**\n * Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of\n * the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive\n * definition of `chunksOf`; it satisfies the property that\n *\n * ```ts skip-type-checking\n * chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))\n * ```\n *\n * whenever `n` evenly divides the length of `self`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.chunksOf([1, 2, 3, 4, 5], 2)\n * console.log(result) // [[1, 2], [3, 4], [5]]\n *\n * // Explanation:\n * // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.\n * // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,\n * // the last chunk contains the remaining elements.\n * // The result is `[[1, 2], [3, 4], [5]]`.\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, n: number): NonEmptyArray<NonEmptyArray<A>>\n /**\n * Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of\n * the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive\n * definition of `chunksOf`; it satisfies the property that\n *\n * ```ts skip-type-checking\n * chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))\n * ```\n *\n * whenever `n` evenly divides the length of `self`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.chunksOf([1, 2, 3, 4, 5], 2)\n * console.log(result) // [[1, 2], [3, 4], [5]]\n *\n * // Explanation:\n * // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.\n * // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,\n * // the last chunk contains the remaining elements.\n * // The result is `[[1, 2], [3, 4], [5]]`.\n * ```\n *\n * @category splitting\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, n: number): Array<NonEmptyArray<A>>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<NonEmptyArray<A>> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n return chop(input, splitNonEmptyAt(n))\n }\n return []\n})\n\n/**\n * Creates sliding windows of size `n` from an `Iterable`.\n * If the number of elements is less than `n` or if `n` is not greater than zero,\n * an empty array is returned.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * assert.deepStrictEqual(Array.window(numbers, 3), [[1, 2, 3], [2, 3, 4], [3, 4, 5]])\n * assert.deepStrictEqual(Array.window(numbers, 6), [])\n * ```\n *\n * @category splitting\n * @since 3.13.2\n */\nexport const window: {\n /**\n * Creates sliding windows of size `n` from an `Iterable`.\n * If the number of elements is less than `n` or if `n` is not greater than zero,\n * an empty array is returned.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * assert.deepStrictEqual(Array.window(numbers, 3), [[1, 2, 3], [2, 3, 4], [3, 4, 5]])\n * assert.deepStrictEqual(Array.window(numbers, 6), [])\n * ```\n *\n * @category splitting\n * @since 3.13.2\n */\n (n: number): <A>(self: Iterable<A>) => Array<Array<A>>\n /**\n * Creates sliding windows of size `n` from an `Iterable`.\n * If the number of elements is less than `n` or if `n` is not greater than zero,\n * an empty array is returned.\n *\n * @example\n * ```ts\n * import * as assert from \"node:assert\"\n * import { Array } from \"effect\"\n *\n * const numbers = [1, 2, 3, 4, 5]\n * assert.deepStrictEqual(Array.window(numbers, 3), [[1, 2, 3], [2, 3, 4], [3, 4, 5]])\n * assert.deepStrictEqual(Array.window(numbers, 6), [])\n * ```\n *\n * @category splitting\n * @since 3.13.2\n */\n <A>(self: Iterable<A>, n: number): Array<Array<A>>\n} = dual(2, <A>(self: Iterable<A>, n: number): Array<Array<A>> => {\n const input = fromIterable(self)\n if (n > 0 && isNonEmptyReadonlyArray(input)) {\n return Array.from(\n { length: input.length - (n - 1) },\n (_, index) => input.slice(index, index + n)\n )\n }\n return []\n})\n\n/**\n * Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s using the provided `isEquivalent` function.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.groupWith([\"a\", \"a\", \"b\", \"b\", \"b\", \"c\", \"a\"], (x, y) => x === y)\n * console.log(result) // [[\"a\", \"a\"], [\"b\", \"b\", \"b\"], [\"c\"], [\"a\"]]\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\nexport const groupWith: {\n /**\n * Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s using the provided `isEquivalent` function.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.groupWith([\"a\", \"a\", \"b\", \"b\", \"b\", \"c\", \"a\"], (x, y) => x === y)\n * console.log(result) // [[\"a\", \"a\"], [\"b\", \"b\", \"b\"], [\"c\"], [\"a\"]]\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\n <A>(isEquivalent: (self: A, that: A) => boolean): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<NonEmptyArray<A>>\n /**\n * Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s using the provided `isEquivalent` function.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.groupWith([\"a\", \"a\", \"b\", \"b\", \"b\", \"c\", \"a\"], (x, y) => x === y)\n * console.log(result) // [[\"a\", \"a\"], [\"b\", \"b\", \"b\"], [\"c\"], [\"a\"]]\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\n <A>(\n self: NonEmptyReadonlyArray<A>,\n isEquivalent: (self: A, that: A) => boolean\n ): NonEmptyArray<NonEmptyArray<A>>\n} = dual(\n 2,\n <A>(self: NonEmptyReadonlyArray<A>, isEquivalent: (self: A, that: A) => boolean): NonEmptyArray<NonEmptyArray<A>> =>\n chop(self, (as) => {\n const h = headNonEmpty(as)\n const out: NonEmptyArray<A> = [h]\n let i = 1\n for (; i < as.length; i++) {\n const a = as[i]\n if (isEquivalent(a, h)) {\n out.push(a)\n } else {\n break\n }\n }\n return [out, as.slice(i)]\n })\n)\n\n/**\n * Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.group([1, 1, 2, 2, 2, 3, 1])\n * console.log(result) // [[1, 1], [2, 2, 2], [3], [1]]\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\nexport const group: <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<NonEmptyArray<A>> = groupWith(\n Equal.equivalence()\n)\n\n/**\n * Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning\n * function on each element, and grouping the results according to values returned\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const people = [\n * { name: \"Alice\", group: \"A\" },\n * { name: \"Bob\", group: \"B\" },\n * { name: \"Charlie\", group: \"A\" }\n * ]\n *\n * const result = Array.groupBy(people, person => person.group)\n * console.log(result)\n * // {\n * // A: [{ name: \"Alice\", group: \"A\" }, { name: \"Charlie\", group: \"A\" }],\n * // B: [{ name: \"Bob\", group: \"B\" }]\n * // }\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\nexport const groupBy: {\n /**\n * Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning\n * function on each element, and grouping the results according to values returned\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const people = [\n * { name: \"Alice\", group: \"A\" },\n * { name: \"Bob\", group: \"B\" },\n * { name: \"Charlie\", group: \"A\" }\n * ]\n *\n * const result = Array.groupBy(people, person => person.group)\n * console.log(result)\n * // {\n * // A: [{ name: \"Alice\", group: \"A\" }, { name: \"Charlie\", group: \"A\" }],\n * // B: [{ name: \"Bob\", group: \"B\" }]\n * // }\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\n <A, K extends string | symbol>(f: (a: A) => K): (self: Iterable<A>) => Record<Record.ReadonlyRecord.NonLiteralKey<K>, NonEmptyArray<A>>\n /**\n * Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning\n * function on each element, and grouping the results according to values returned\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const people = [\n * { name: \"Alice\", group: \"A\" },\n * { name: \"Bob\", group: \"B\" },\n * { name: \"Charlie\", group: \"A\" }\n * ]\n *\n * const result = Array.groupBy(people, person => person.group)\n * console.log(result)\n * // {\n * // A: [{ name: \"Alice\", group: \"A\" }, { name: \"Charlie\", group: \"A\" }],\n * // B: [{ name: \"Bob\", group: \"B\" }]\n * // }\n * ```\n *\n * @category grouping\n * @since 2.0.0\n */\n <A, K extends string | symbol>(self: Iterable<A>, f: (a: A) => K): Record<Record.ReadonlyRecord.NonLiteralKey<K>, NonEmptyArray<A>>\n} = dual(2, <A, K extends string | symbol>(\n self: Iterable<A>,\n f: (a: A) => K\n): Record<Record.ReadonlyRecord.NonLiteralKey<K>, NonEmptyArray<A>> => {\n const out: Record<string | symbol, NonEmptyArray<A>> = {}\n for (const a of self) {\n const k = f(a)\n if (Object.prototype.hasOwnProperty.call(out, k)) {\n out[k].push(a)\n } else {\n out[k] = [a]\n }\n }\n return out\n})\n\n/**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const union = Array.unionWith([1, 2], [2, 3], (a, b) => a === b)\n * console.log(union) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\nexport const unionWith: {\n /**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const union = Array.unionWith([1, 2], [2, 3], (a, b) => a === b)\n * console.log(union) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <S extends Iterable<any>, T extends Iterable<any>>(\n that: T,\n isEquivalent: (self: ReadonlyArray.Infer<S>, that: ReadonlyArray.Infer<T>) => boolean\n ): (self: S) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>\n /**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const union = Array.unionWith([1, 2], [2, 3], (a, b) => a === b)\n * console.log(union) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: NonEmptyReadonlyArray<A>,\n that: Iterable<B>,\n isEquivalent: (self: A, that: B) => boolean\n ): NonEmptyArray<A | B>\n /**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const union = Array.unionWith([1, 2], [2, 3], (a, b) => a === b)\n * console.log(union) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: Iterable<A>,\n that: NonEmptyReadonlyArray<B>,\n isEquivalent: (self: A, that: B) => boolean\n ): NonEmptyArray<A | B>\n /**\n * Calculates the union of two arrays using the provided equivalence relation.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const union = Array.unionWith([1, 2], [2, 3], (a, b) => a === b)\n * console.log(union) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(\n self: Iterable<A>,\n that: Iterable<B>,\n isEquivalent: (self: A, that: B) => boolean\n ): Array<A | B>\n} = dual(3, <A>(self: Iterable<A>, that: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A> => {\n const a = fromIterable(self)\n const b = fromIterable(that)\n if (isNonEmptyReadonlyArray(a)) {\n if (isNonEmptyReadonlyArray(b)) {\n const dedupe = dedupeWith(isEquivalent)\n return dedupe(appendAll(a, b))\n }\n return a\n }\n return b\n})\n\n/**\n * Creates a union of two arrays, removing duplicates.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.union([1, 2], [2, 3])\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\nexport const union: {\n /**\n * Creates a union of two arrays, removing duplicates.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.union([1, 2], [2, 3])\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <T extends Iterable<any>>(that: T): <S extends Iterable<any>>(\n self: S\n ) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>\n /**\n * Creates a union of two arrays, removing duplicates.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.union([1, 2], [2, 3])\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: NonEmptyReadonlyArray<A>, that: ReadonlyArray<B>): NonEmptyArray<A | B>\n /**\n * Creates a union of two arrays, removing duplicates.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.union([1, 2], [2, 3])\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: ReadonlyArray<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<A | B>\n /**\n * Creates a union of two arrays, removing duplicates.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.union([1, 2], [2, 3])\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B>\n} = dual(2, <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B> => unionWith(self, that, _equivalence))\n\n/**\n * Creates an `Array` of unique values that are included in all given `Iterable`s using the provided `isEquivalent` function.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }]\n * const array2 = [{ id: 3 }, { id: 4 }, { id: 1 }]\n * const isEquivalent = (a: { id: number }, b: { id: number }) => a.id === b.id\n * const result = Array.intersectionWith(isEquivalent)(array2)(array1)\n * console.log(result) // [{ id: 1 }, { id: 3 }]\n * ```\n *\n * @since 2.0.0\n */\nexport const intersectionWith = <A>(isEquivalent: (self: A, that: A) => boolean): {\n (that: Iterable<A>): (self: Iterable<A>) => Array<A>\n (self: Iterable<A>, that: Iterable<A>): Array<A>\n} => {\n const has = containsWith(isEquivalent)\n return dual(\n 2,\n (self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(self).filter((a) => has(that, a))\n )\n}\n\n/**\n * Creates an `Array` of unique values that are included in all given `Iterable`s.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.intersection([1, 2, 3], [3, 4, 1])\n * console.log(result) // [1, 3]\n * ```\n *\n * @since 2.0.0\n */\nexport const intersection: {\n /**\n * Creates an `Array` of unique values that are included in all given `Iterable`s.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.intersection([1, 2, 3], [3, 4, 1])\n * console.log(result) // [1, 3]\n * ```\n *\n * @since 2.0.0\n */\n <B>(that: Iterable<B>): <A>(self: Iterable<A>) => Array<A & B>\n /**\n * Creates an `Array` of unique values that are included in all given `Iterable`s.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.intersection([1, 2, 3], [3, 4, 1])\n * console.log(result) // [1, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A & B>\n} = intersectionWith(_equivalence)\n\n/**\n * Creates a `Array` of values not included in the other given `Iterable` using the provided `isEquivalent` function.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const array1 = [1, 2, 3]\n * const array2 = [2, 3, 4]\n * const difference = Array.differenceWith<number>((a, b) => a === b)(array1, array2)\n * console.log(difference) // [1]\n * ```\n *\n * @since 2.0.0\n */\nexport const differenceWith = <A>(isEquivalent: (self: A, that: A) => boolean): {\n (that: Iterable<A>): (self: Iterable<A>) => Array<A>\n (self: Iterable<A>, that: Iterable<A>): Array<A>\n} => {\n const has = containsWith(isEquivalent)\n return dual(\n 2,\n (self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(self).filter((a) => !has(that, a))\n )\n}\n\n/**\n * Creates a `Array` of values not included in the other given `Iterable`.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const difference = Array.difference([1, 2, 3], [2, 3, 4])\n * console.log(difference) // [1]\n * ```\n *\n * @since 2.0.0\n */\nexport const difference: {\n /**\n * Creates a `Array` of values not included in the other given `Iterable`.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const difference = Array.difference([1, 2, 3], [2, 3, 4])\n * console.log(difference) // [1]\n * ```\n *\n * @since 2.0.0\n */\n <A>(that: Iterable<A>): (self: Iterable<A>) => Array<A>\n /**\n * Creates a `Array` of values not included in the other given `Iterable`.\n * The order and references of result values are determined by the first `Iterable`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const difference = Array.difference([1, 2, 3], [2, 3, 4])\n * console.log(difference) // [1]\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, that: Iterable<A>): Array<A>\n} = differenceWith(_equivalence)\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const empty: <A = never>() => Array<A> = () => []\n\n/**\n * Constructs a new `NonEmptyArray<A>` from the specified value.\n *\n * @category constructors\n * @since 2.0.0\n */\nexport const of = <A>(a: A): NonEmptyArray<A> => [a]\n\n/**\n * @since 2.0.0\n */\nexport declare namespace ReadonlyArray {\n /**\n * @since 2.0.0\n */\n export type Infer<S extends Iterable<any>> = S extends ReadonlyArray<infer A> ? A\n : S extends Iterable<infer A> ? A\n : never\n\n /**\n * @since 2.0.0\n */\n export type With<S extends Iterable<any>, A> = S extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>\n : Array<A>\n\n /**\n * @since 2.0.0\n */\n export type OrNonEmpty<\n S extends Iterable<any>,\n T extends Iterable<any>,\n A\n > = S extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>\n : T extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>\n : Array<A>\n\n /**\n * @since 2.0.0\n */\n export type AndNonEmpty<\n S extends Iterable<any>,\n T extends Iterable<any>,\n A\n > = S extends NonEmptyReadonlyArray<any> ? T extends NonEmptyReadonlyArray<any> ? NonEmptyArray<A>\n : Array<A>\n : Array<A>\n\n /**\n * @since 2.0.0\n */\n export type Flatten<T extends ReadonlyArray<ReadonlyArray<any>>> = T extends\n NonEmptyReadonlyArray<NonEmptyReadonlyArray<infer A>> ? NonEmptyArray<A>\n : T extends ReadonlyArray<ReadonlyArray<infer A>> ? Array<A>\n : never\n}\n\n/**\n * @category mapping\n * @since 2.0.0\n */\nexport const map: {\n /**\n * @category mapping\n * @since 2.0.0\n */\n <S extends ReadonlyArray<any>, B>(f: (a: ReadonlyArray.Infer<S>, i: number) => B): (self: S) => ReadonlyArray.With<S, B>\n /**\n * @category mapping\n * @since 2.0.0\n */\n <S extends ReadonlyArray<any>, B>(self: S, f: (a: ReadonlyArray.Infer<S>, i: number) => B): ReadonlyArray.With<S, B>\n} = dual(2, <A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => B): Array<B> => self.map(f))\n\n/**\n * Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatMap: {\n /**\n * Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <S extends ReadonlyArray<any>, T extends ReadonlyArray<any>>(f: (a: ReadonlyArray.Infer<S>, i: number) => T): (self: S) => ReadonlyArray.AndNonEmpty<S, T, ReadonlyArray.Infer<T>>\n /**\n * Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(\n self: NonEmptyReadonlyArray<A>,\n f: (a: A, i: number) => NonEmptyReadonlyArray<B>\n ): NonEmptyArray<B>\n /**\n * Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => ReadonlyArray<B>): Array<B>\n} = dual(\n 2,\n <A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => ReadonlyArray<B>): Array<B> => {\n if (isEmptyReadonlyArray(self)) {\n return []\n }\n const out: Array<B> = []\n for (let i = 0; i < self.length; i++) {\n const inner = f(self[i], i)\n for (let j = 0; j < inner.length; j++) {\n out.push(inner[j])\n }\n }\n return out\n }\n)\n\n/**\n * Combines multiple arrays into a single array by concatenating all elements\n * from each nested array. This function ensures that the structure of nested\n * arrays is collapsed into a single, flat array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.flatten([[1, 2], [], [3, 4], [], [5, 6]])\n * console.log(result) // [1, 2, 3, 4, 5, 6]\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatten: <S extends ReadonlyArray<ReadonlyArray<any>>>(self: S) => ReadonlyArray.Flatten<S> = flatMap(\n identity\n) as any\n\n/**\n * Applies a function to each element of the `Iterable` and filters based on the result, keeping the transformed values where the function returns `Some`.\n * This method combines filtering and mapping functionalities, allowing transformations and filtering of elements based on a single function pass.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none()\n *\n * const result = Array.filterMap([1, 2, 3, 4, 5], evenSquares);\n * console.log(result) // [4, 16]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const filterMap: {\n /**\n * Applies a function to each element of the `Iterable` and filters based on the result, keeping the transformed values where the function returns `Some`.\n * This method combines filtering and mapping functionalities, allowing transformations and filtering of elements based on a single function pass.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none()\n *\n * const result = Array.filterMap([1, 2, 3, 4, 5], evenSquares);\n * console.log(result) // [4, 16]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(f: (a: A, i: number) => Option.Option<B>): (self: Iterable<A>) => Array<B>\n /**\n * Applies a function to each element of the `Iterable` and filters based on the result, keeping the transformed values where the function returns `Some`.\n * This method combines filtering and mapping functionalities, allowing transformations and filtering of elements based on a single function pass.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none()\n *\n * const result = Array.filterMap([1, 2, 3, 4, 5], evenSquares);\n * console.log(result) // [4, 16]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option.Option<B>): Array<B>\n} = dual(\n 2,\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option.Option<B>): Array<B> => {\n const as = fromIterable(self)\n const out: Array<B> = []\n for (let i = 0; i < as.length; i++) {\n const o = f(as[i], i)\n if (Option.isSome(o)) {\n out.push(o.value)\n }\n }\n return out\n }\n)\n\n/**\n * Applies a function to each element of the array and filters based on the result, stopping when a condition is not met.\n * This method combines filtering and mapping in a single pass, and short-circuits, i.e., stops processing, as soon as the function returns `None`.\n * This is useful when you need to transform an array but only up to the point where a certain condition holds true.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none()\n *\n * const result = Array.filterMapWhile([2, 4, 5], toSquareTillOdd)\n * console.log(result) // [4, 16]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const filterMapWhile: {\n /**\n * Applies a function to each element of the array and filters based on the result, stopping when a condition is not met.\n * This method combines filtering and mapping in a single pass, and short-circuits, i.e., stops processing, as soon as the function returns `None`.\n * This is useful when you need to transform an array but only up to the point where a certain condition holds true.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none()\n *\n * const result = Array.filterMapWhile([2, 4, 5], toSquareTillOdd)\n * console.log(result) // [4, 16]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(f: (a: A, i: number) => Option.Option<B>): (self: Iterable<A>) => Array<B>\n /**\n * Applies a function to each element of the array and filters based on the result, stopping when a condition is not met.\n * This method combines filtering and mapping in a single pass, and short-circuits, i.e., stops processing, as soon as the function returns `None`.\n * This is useful when you need to transform an array but only up to the point where a certain condition holds true.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none()\n *\n * const result = Array.filterMapWhile([2, 4, 5], toSquareTillOdd)\n * console.log(result) // [4, 16]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option.Option<B>): Array<B>\n} = dual(2, <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option.Option<B>) => {\n let i = 0\n const out: Array<B> = []\n for (const a of self) {\n const b = f(a, i)\n if (Option.isSome(b)) {\n out.push(b.value)\n } else {\n break\n }\n i++\n }\n return out\n})\n\n/**\n * Applies a function to each element of the `Iterable`, categorizing the results into two separate arrays.\n * This function is particularly useful for operations where each element can result in two possible types,\n * and you want to separate these types into different collections. For instance, separating validation results\n * into successes and failures.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Either } from \"effect\";\n *\n * const isEven = (x: number) => x % 2 === 0\n *\n * const result = Array.partitionMap([1, 2, 3, 4, 5], x =>\n * isEven(x) ? Either.right(x) : Either.left(x)\n * )\n * console.log(result)\n * // [\n * // [1, 3, 5],\n * // [2, 4]\n * // ]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const partitionMap: {\n /**\n * Applies a function to each element of the `Iterable`, categorizing the results into two separate arrays.\n * This function is particularly useful for operations where each element can result in two possible types,\n * and you want to separate these types into different collections. For instance, separating validation results\n * into successes and failures.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Either } from \"effect\";\n *\n * const isEven = (x: number) => x % 2 === 0\n *\n * const result = Array.partitionMap([1, 2, 3, 4, 5], x =>\n * isEven(x) ? Either.right(x) : Either.left(x)\n * )\n * console.log(result)\n * // [\n * // [1, 3, 5],\n * // [2, 4]\n * // ]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B, C>(f: (a: A, i: number) => Either.Either<C, B>): (self: Iterable<A>) => [left: Array<B>, right: Array<C>]\n /**\n * Applies a function to each element of the `Iterable`, categorizing the results into two separate arrays.\n * This function is particularly useful for operations where each element can result in two possible types,\n * and you want to separate these types into different collections. For instance, separating validation results\n * into successes and failures.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Either } from \"effect\";\n *\n * const isEven = (x: number) => x % 2 === 0\n *\n * const result = Array.partitionMap([1, 2, 3, 4, 5], x =>\n * isEven(x) ? Either.right(x) : Either.left(x)\n * )\n * console.log(result)\n * // [\n * // [1, 3, 5],\n * // [2, 4]\n * // ]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B, C>(self: Iterable<A>, f: (a: A, i: number) => Either.Either<C, B>): [left: Array<B>, right: Array<C>]\n} = dual(\n 2,\n <A, B, C>(self: Iterable<A>, f: (a: A, i: number) => Either.Either<C, B>): [left: Array<B>, right: Array<C>] => {\n const left: Array<B> = []\n const right: Array<C> = []\n const as = fromIterable(self)\n for (let i = 0; i < as.length; i++) {\n const e = f(as[i], i)\n if (Either.isLeft(e)) {\n left.push(e.left)\n } else {\n right.push(e.right)\n }\n }\n return [left, right]\n }\n)\n\n/**\n * Retrieves the `Some` values from an `Iterable` of `Option`s, collecting them into an array.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Option } from \"effect\"\n *\n * const result = Array.getSomes([Option.some(1), Option.none(), Option.some(2)])\n * console.log(result) // [1, 2]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n\nexport const getSomes: <T extends Iterable<Option.Option<X>>, X = any>(\n self: T\n) => Array<Option.Option.Value<ReadonlyArray.Infer<T>>> = filterMap(identity as any)\n\n/**\n * Retrieves the `Left` values from an `Iterable` of `Either`s, collecting them into an array.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Either } from \"effect\"\n *\n * const result = Array.getLefts([Either.right(1), Either.left(\"err\"), Either.right(2)])\n * console.log(result) // [\"err\"]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const getLefts = <T extends Iterable<Either.Either<any, any>>>(\n self: T\n): Array<Either.Either.Left<ReadonlyArray.Infer<T>>> => {\n const out: Array<any> = []\n for (const a of self) {\n if (Either.isLeft(a)) {\n out.push(a.left)\n }\n }\n\n return out\n}\n\n/**\n * Retrieves the `Right` values from an `Iterable` of `Either`s, collecting them into an array.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Either } from \"effect\"\n *\n * const result = Array.getRights([Either.right(1), Either.left(\"err\"), Either.right(2)])\n * console.log(result) // [1, 2]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const getRights = <T extends Iterable<Either.Either<any, any>>>(\n self: T\n): Array<Either.Either.Right<ReadonlyArray.Infer<T>>> => {\n const out: Array<any> = []\n for (const a of self) {\n if (Either.isRight(a)) {\n out.push(a.right)\n }\n }\n\n return out\n}\n\n/**\n * @category filtering\n * @since 2.0.0\n */\nexport const filter: {\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Array<B>\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Array<A>\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Array<B>\n /**\n * @category filtering\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A>\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A> => {\n const as = fromIterable(self)\n const out: Array<A> = []\n for (let i = 0; i < as.length; i++) {\n if (predicate(as[i], i)) {\n out.push(as[i])\n }\n }\n return out\n }\n)\n\n/**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.partition([1, 2, 3, 4], n => n % 2 === 0)\n * console.log(result) // [[1, 3], [2, 4]]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const partition: {\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.partition([1, 2, 3, 4], n => n % 2 === 0)\n * console.log(result) // [[1, 3], [2, 4]]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (\n self: Iterable<A>\n ) => [excluded: Array<Exclude<A, B>>, satisfying: Array<B>]\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.partition([1, 2, 3, 4], n => n % 2 === 0)\n * console.log(result) // [[1, 3], [2, 4]]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => [excluded: Array<A>, satisfying: Array<A>]\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.partition([1, 2, 3, 4], n => n % 2 === 0)\n * console.log(result) // [[1, 3], [2, 4]]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): [excluded: Array<Exclude<A, B>>, satisfying: Array<B>]\n /**\n * Separate elements based on a predicate that also exposes the index of the element.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.partition([1, 2, 3, 4], n => n % 2 === 0)\n * console.log(result) // [[1, 3], [2, 4]]\n * ```\n *\n * @category filtering\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [excluded: Array<A>, satisfying: Array<A>]\n} = dual(\n 2,\n <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [excluded: Array<A>, satisfying: Array<A>] => {\n const left: Array<A> = []\n const right: Array<A> = []\n const as = fromIterable(self)\n for (let i = 0; i < as.length; i++) {\n if (predicate(as[i], i)) {\n right.push(as[i])\n } else {\n left.push(as[i])\n }\n }\n return [left, right]\n }\n)\n\n/**\n * Separates an `Iterable` into two arrays based on a predicate.\n *\n * @category filtering\n * @since 2.0.0\n */\nexport const separate: <T extends Iterable<Either.Either<any, any>>>(\n self: T\n) => [Array<Either.Either.Left<ReadonlyArray.Infer<T>>>, Array<Either.Either.Right<ReadonlyArray.Infer<T>>>] =\n partitionMap(identity)\n\n/**\n * Reduces an array from the left.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.reduce([1, 2, 3], 0, (acc, n) => acc + n)\n * console.log(result) // 6\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const reduce: {\n /**\n * Reduces an array from the left.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.reduce([1, 2, 3], 0, (acc, n) => acc + n)\n * console.log(result) // 6\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Iterable<A>) => B\n /**\n * Reduces an array from the left.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.reduce([1, 2, 3], 0, (acc, n) => acc + n)\n * console.log(result) // 6\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B\n} = dual(\n 3,\n <B, A>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B =>\n fromIterable(self).reduce((b, a, i) => f(b, a, i), b)\n)\n\n/**\n * Reduces an array from the right.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.reduceRight([1, 2, 3], 0, (acc, n) => acc + n)\n * console.log(result) // 6\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\nexport const reduceRight: {\n /**\n * Reduces an array from the right.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.reduceRight([1, 2, 3], 0, (acc, n) => acc + n)\n * console.log(result) // 6\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Iterable<A>) => B\n /**\n * Reduces an array from the right.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.reduceRight([1, 2, 3], 0, (acc, n) => acc + n)\n * console.log(result) // 6\n * ```\n *\n * @category folding\n * @since 2.0.0\n */\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B\n} = dual(\n 3,\n <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B =>\n fromIterable(self).reduceRight((b, a, i) => f(b, a, i), b)\n)\n\n/**\n * Lifts a predicate into an array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n * const to = Array.liftPredicate(isEven)\n * console.log(to(1)) // []\n * console.log(to(2)) // [2]\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\nexport const liftPredicate: { // Note: I intentionally avoid using the NoInfer pattern here.\n <A, B extends A>(refinement: Predicate.Refinement<A, B>): (a: A) => Array<B>\n /**\n * Lifts a predicate into an array.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const isEven = (n: number) => n % 2 === 0\n * const to = Array.liftPredicate(isEven)\n * console.log(to(1)) // []\n * console.log(to(2)) // [2]\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\n <A>(predicate: Predicate.Predicate<A>): <B extends A>(b: B) => Array<B>\n} = <A>(predicate: Predicate.Predicate<A>) => <B extends A>(b: B): Array<B> => predicate(b) ? [b] : []\n\n/**\n * @category lifting\n * @since 2.0.0\n */\nexport const liftOption = <A extends Array<unknown>, B>(\n f: (...a: A) => Option.Option<B>\n) =>\n(...a: A): Array<B> => fromOption(f(...a))\n\n/**\n * @category conversions\n * @since 2.0.0\n */\nexport const fromNullable = <A>(a: A): Array<NonNullable<A>> => a == null ? empty() : [a as NonNullable<A>]\n\n/**\n * @category lifting\n * @since 2.0.0\n */\nexport const liftNullable = <A extends Array<unknown>, B>(\n f: (...a: A) => B | null | undefined\n): (...a: A) => Array<NonNullable<B>> =>\n(...a) => fromNullable(f(...a))\n\n/**\n * Maps over an array and flattens the result, removing null and undefined values.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.flatMapNullable([1, 2, 3], n => (n % 2 === 0 ? null : n))\n * console.log(result) // [1, 3]\n *\n * // Explanation:\n * // The array of numbers [1, 2, 3] is mapped with a function that returns null for even numbers\n * // and the number itself for odd numbers. The resulting array [1, null, 3] is then flattened\n * // to remove null values, resulting in [1, 3].\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\nexport const flatMapNullable: {\n /**\n * Maps over an array and flattens the result, removing null and undefined values.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.flatMapNullable([1, 2, 3], n => (n % 2 === 0 ? null : n))\n * console.log(result) // [1, 3]\n *\n * // Explanation:\n * // The array of numbers [1, 2, 3] is mapped with a function that returns null for even numbers\n * // and the number itself for odd numbers. The resulting array [1, null, 3] is then flattened\n * // to remove null values, resulting in [1, 3].\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(f: (a: A) => B | null | undefined): (self: ReadonlyArray<A>) => Array<NonNullable<B>>\n /**\n * Maps over an array and flattens the result, removing null and undefined values.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.flatMapNullable([1, 2, 3], n => (n % 2 === 0 ? null : n))\n * console.log(result) // [1, 3]\n *\n * // Explanation:\n * // The array of numbers [1, 2, 3] is mapped with a function that returns null for even numbers\n * // and the number itself for odd numbers. The resulting array [1, null, 3] is then flattened\n * // to remove null values, resulting in [1, 3].\n * ```\n *\n * @category sequencing\n * @since 2.0.0\n */\n <A, B>(self: ReadonlyArray<A>, f: (a: A) => B | null | undefined): Array<NonNullable<B>>\n} = dual(\n 2,\n <A, B>(self: ReadonlyArray<A>, f: (a: A) => B | null | undefined): Array<NonNullable<B>> =>\n flatMap(self, (a) => fromNullable(f(a)))\n)\n\n/**\n * Lifts a function that returns an `Either` into a function that returns an array.\n * If the `Either` is a left, it returns an empty array.\n * If the `Either` is a right, it returns an array with the right value.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Either } from \"effect\"\n *\n * const parseNumber = (s: string): Either.Either<number, Error> =>\n * isNaN(Number(s)) ? Either.left(new Error(\"Not a number\")) : Either.right(Number(s))\n *\n * const liftedParseNumber = Array.liftEither(parseNumber)\n *\n * const result1 = liftedParseNumber(\"42\")\n * console.log(result1) // [42]\n *\n * const result2 = liftedParseNumber(\"not a number\")\n * console.log(result2) // []\n *\n * // Explanation:\n * // The function parseNumber is lifted to return an array.\n * // When parsing \"42\", it returns an Either.left with the number 42, resulting in [42].\n * // When parsing \"not a number\", it returns an Either.right with an error, resulting in an empty array [].\n * ```\n *\n * @category lifting\n * @since 2.0.0\n */\nexport const liftEither = <A extends Array<unknown>, E, B>(\n f: (...a: A) => Either.Either<B, E>\n) =>\n(...a: A): Array<B> => {\n const e = f(...a)\n return Either.isLeft(e) ? [] : [e.right]\n}\n\n/**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const every: {\n /**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: ReadonlyArray<A>) => self is ReadonlyArray<B>\n /**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: ReadonlyArray<A>) => boolean\n /**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A, B extends A>(self: ReadonlyArray<A>, refinement: (a: A, i: number) => a is B): self is ReadonlyArray<B>\n /**\n * Check if a predicate holds true for every `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): boolean\n} = dual(\n 2,\n <A, B extends A>(self: ReadonlyArray<A>, refinement: (a: A, i: number) => a is B): self is ReadonlyArray<B> =>\n self.every(refinement)\n)\n\n/**\n * Check if a predicate holds true for some `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\nexport const some: {\n /**\n * Check if a predicate holds true for some `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: ReadonlyArray<A>) => self is NonEmptyReadonlyArray<A>\n /**\n * Check if a predicate holds true for some `ReadonlyArray` element.\n *\n * @category elements\n * @since 2.0.0\n */\n <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): self is NonEmptyReadonlyArray<A>\n} = dual(\n 2,\n <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): self is NonEmptyReadonlyArray<A> =>\n self.some(predicate)\n)\n\n/**\n * Extends an array with a function that maps each subarray to a value.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.extend([1, 2, 3], as => as.length)\n * console.log(result) // [3, 2, 1]\n *\n * // Explanation:\n * // The function maps each subarray starting from each element to its length.\n * // The subarrays are: [1, 2, 3], [2, 3], [3].\n * // The lengths are: 3, 2, 1.\n * // Therefore, the result is [3, 2, 1].\n * ```\n *\n * @since 2.0.0\n */\nexport const extend: {\n /**\n * Extends an array with a function that maps each subarray to a value.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.extend([1, 2, 3], as => as.length)\n * console.log(result) // [3, 2, 1]\n *\n * // Explanation:\n * // The function maps each subarray starting from each element to its length.\n * // The subarrays are: [1, 2, 3], [2, 3], [3].\n * // The lengths are: 3, 2, 1.\n * // Therefore, the result is [3, 2, 1].\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(f: (as: ReadonlyArray<A>) => B): (self: ReadonlyArray<A>) => Array<B>\n /**\n * Extends an array with a function that maps each subarray to a value.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.extend([1, 2, 3], as => as.length)\n * console.log(result) // [3, 2, 1]\n *\n * // Explanation:\n * // The function maps each subarray starting from each element to its length.\n * // The subarrays are: [1, 2, 3], [2, 3], [3].\n * // The lengths are: 3, 2, 1.\n * // Therefore, the result is [3, 2, 1].\n * ```\n *\n * @since 2.0.0\n */\n <A, B>(self: ReadonlyArray<A>, f: (as: ReadonlyArray<A>) => B): Array<B>\n} = dual(\n 2,\n <A, B>(self: ReadonlyArray<A>, f: (as: ReadonlyArray<A>) => B): Array<B> => self.map((_, i, as) => f(as.slice(i)))\n)\n\n/**\n * Finds the minimum element in an array based on a comparator.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.min([3, 1, 2], Order.number)\n * console.log(result) // 1\n * ```\n *\n * @since 2.0.0\n */\nexport const min: {\n /**\n * Finds the minimum element in an array based on a comparator.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.min([3, 1, 2], Order.number)\n * console.log(result) // 1\n * ```\n *\n * @since 2.0.0\n */\n <A>(O: Order.Order<A>): (self: NonEmptyReadonlyArray<A>) => A\n /**\n * Finds the minimum element in an array based on a comparator.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.min([3, 1, 2], Order.number)\n * console.log(result) // 1\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A\n} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A => self.reduce(Order.min(O)))\n\n/**\n * Finds the maximum element in an array based on a comparator.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.max([3, 1, 2], Order.number)\n * console.log(result) // 3\n * ```\n *\n * @since 2.0.0\n */\nexport const max: {\n /**\n * Finds the maximum element in an array based on a comparator.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.max([3, 1, 2], Order.number)\n * console.log(result) // 3\n * ```\n *\n * @since 2.0.0\n */\n <A>(O: Order.Order<A>): (self: NonEmptyReadonlyArray<A>) => A\n /**\n * Finds the maximum element in an array based on a comparator.\n *\n * **Example**\n *\n * ```ts\n * import { Array, Order } from \"effect\"\n *\n * const result = Array.max([3, 1, 2], Order.number)\n * console.log(result) // 3\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A\n} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A => self.reduce(Order.max(O)))\n\n/**\n * @category constructors\n * @since 2.0.0\n */\nexport const unfold = <B, A>(b: B, f: (b: B) => Option.Option<readonly [A, B]>): Array<A> => {\n const out: Array<A> = []\n let next: B = b\n let o: Option.Option<readonly [A, B]>\n while (Option.isSome(o = f(next))) {\n const [a, b] = o.value\n out.push(a)\n next = b\n }\n return out\n}\n\n/**\n * This function creates and returns a new `Order` for an array of values based on a given `Order` for the elements of the array.\n * The returned `Order` compares two arrays by applying the given `Order` to each element in the arrays.\n * If all elements are equal, the arrays are then compared based on their length.\n * It is useful when you need to compare two arrays of the same type and you have a specific way of comparing each element of the array.\n *\n * @category instances\n * @since 2.0.0\n */\nexport const getOrder: <A>(O: Order.Order<A>) => Order.Order<ReadonlyArray<A>> = Order.array\n\n/**\n * Creates an equivalence relation for arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const eq = Array.getEquivalence<number>((a, b) => a === b)\n * console.log(eq([1, 2, 3], [1, 2, 3])) // true\n * ```\n *\n * @category instances\n * @since 2.0.0\n */\nexport const getEquivalence: <A>(\n isEquivalent: Equivalence.Equivalence<A>\n) => Equivalence.Equivalence<ReadonlyArray<A>> = Equivalence.array\n\n/**\n * Performs a side-effect for each element of the `Iterable`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * Array.forEach([1, 2, 3], n => console.log(n)) // 1, 2, 3\n * ```\n *\n * @since 2.0.0\n */\nexport const forEach: {\n /**\n * Performs a side-effect for each element of the `Iterable`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * Array.forEach([1, 2, 3], n => console.log(n)) // 1, 2, 3\n * ```\n *\n * @since 2.0.0\n */\n <A>(f: (a: A, i: number) => void): (self: Iterable<A>) => void\n /**\n * Performs a side-effect for each element of the `Iterable`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * Array.forEach([1, 2, 3], n => console.log(n)) // 1, 2, 3\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, f: (a: A, i: number) => void): void\n} = dual(2, <A>(self: Iterable<A>, f: (a: A, i: number) => void): void => fromIterable(self).forEach((a, i) => f(a, i)))\n\n/**\n * Remove duplicates from an `Iterable` using the provided `isEquivalent` function,\n * preserving the order of the first occurrence of each element.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dedupeWith([1, 2, 2, 3, 3, 3], (a, b) => a === b)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\nexport const dedupeWith: {\n /**\n * Remove duplicates from an `Iterable` using the provided `isEquivalent` function,\n * preserving the order of the first occurrence of each element.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dedupeWith([1, 2, 2, 3, 3, 3], (a, b) => a === b)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <S extends Iterable<any>>(\n isEquivalent: (self: ReadonlyArray.Infer<S>, that: ReadonlyArray.Infer<S>) => boolean\n ): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>\n /**\n * Remove duplicates from an `Iterable` using the provided `isEquivalent` function,\n * preserving the order of the first occurrence of each element.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dedupeWith([1, 2, 2, 3, 3, 3], (a, b) => a === b)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A>(\n self: NonEmptyReadonlyArray<A>,\n isEquivalent: (self: A, that: A) => boolean\n ): NonEmptyArray<A>\n /**\n * Remove duplicates from an `Iterable` using the provided `isEquivalent` function,\n * preserving the order of the first occurrence of each element.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dedupeWith([1, 2, 2, 3, 3, 3], (a, b) => a === b)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A>\n} = dual(\n 2,\n <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A> => {\n const input = fromIterable(self)\n if (isNonEmptyReadonlyArray(input)) {\n const out: NonEmptyArray<A> = [headNonEmpty(input)]\n const rest = tailNonEmpty(input)\n for (const r of rest) {\n if (out.every((a) => !isEquivalent(r, a))) {\n out.push(r)\n }\n }\n return out\n }\n return []\n }\n)\n\n/**\n * Remove duplicates from an `Iterable`, preserving the order of the first occurrence of each element.\n * The equivalence used to compare elements is provided by `Equal.equivalence()` from the `Equal` module.\n *\n * @since 2.0.0\n */\nexport const dedupe = <S extends Iterable<any>>(\n self: S\n): S extends NonEmptyReadonlyArray<infer A> ? NonEmptyArray<A> : S extends Iterable<infer A> ? Array<A> : never =>\n dedupeWith(self, Equal.equivalence()) as any\n\n/**\n * Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dedupeAdjacentWith([1, 1, 2, 2, 3, 3], (a, b) => a === b)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\nexport const dedupeAdjacentWith: {\n /**\n * Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dedupeAdjacentWith([1, 1, 2, 2, 3, 3], (a, b) => a === b)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A>(isEquivalent: (self: A, that: A) => boolean): (self: Iterable<A>) => Array<A>\n /**\n * Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dedupeAdjacentWith([1, 1, 2, 2, 3, 3], (a, b) => a === b)\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\n <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A>\n} = dual(2, <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A> => {\n const out: Array<A> = []\n let lastA: Option.Option<A> = Option.none()\n for (const a of self) {\n if (Option.isNone(lastA) || !isEquivalent(a, lastA.value)) {\n out.push(a)\n lastA = Option.some(a)\n }\n }\n return out\n})\n\n/**\n * Deduplicates adjacent elements that are identical.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.dedupeAdjacent([1, 1, 2, 2, 3, 3])\n * console.log(result) // [1, 2, 3]\n * ```\n *\n * @since 2.0.0\n */\nexport const dedupeAdjacent: <A>(self: Iterable<A>) => Array<A> = dedupeAdjacentWith(Equal.equivalence())\n\n/**\n * Joins the elements together with \"sep\" in the middle.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const strings = [\"a\", \"b\", \"c\"]\n * const joined = Array.join(strings, \"-\")\n * console.log(joined) // \"a-b-c\"\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\nexport const join: {\n /**\n * Joins the elements together with \"sep\" in the middle.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const strings = [\"a\", \"b\", \"c\"]\n * const joined = Array.join(strings, \"-\")\n * console.log(joined) // \"a-b-c\"\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\n (sep: string): (self: Iterable<string>) => string\n /**\n * Joins the elements together with \"sep\" in the middle.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const strings = [\"a\", \"b\", \"c\"]\n * const joined = Array.join(strings, \"-\")\n * console.log(joined) // \"a-b-c\"\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\n (self: Iterable<string>, sep: string): string\n} = dual(2, (self: Iterable<string>, sep: string): string => fromIterable(self).join(sep))\n\n/**\n * Statefully maps over the chunk, producing new elements of type `B`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.mapAccum([1, 2, 3], 0, (acc, n) => [acc + n, acc + n])\n * console.log(result) // [6, [1, 3, 6]]\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\nexport const mapAccum: {\n /**\n * Statefully maps over the chunk, producing new elements of type `B`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.mapAccum([1, 2, 3], 0, (acc, n) => [acc + n, acc + n])\n * console.log(result) // [6, [1, 3, 6]]\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\n <S, A, B, I extends Iterable<A> = Iterable<A>>(s: S, f: (s: S, a: ReadonlyArray.Infer<I>, i: number) => readonly [S, B]): (self: I) => [state: S, mappedArray: ReadonlyArray.With<I, B>]\n /**\n * Statefully maps over the chunk, producing new elements of type `B`.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.mapAccum([1, 2, 3], 0, (acc, n) => [acc + n, acc + n])\n * console.log(result) // [6, [1, 3, 6]]\n * ```\n *\n * @since 2.0.0\n * @category folding\n */\n <S, A, B, I extends Iterable<A> = Iterable<A>>(\n self: I,\n s: S,\n f: (s: S, a: ReadonlyArray.Infer<I>, i: number) => readonly [S, B]\n ): [state: S, mappedArray: ReadonlyArray.With<I, B>]\n} = dual(\n 3,\n <S, A, B>(self: Iterable<A>, s: S, f: (s: S, a: A, i: number) => [S, B]): [state: S, mappedArray: Array<B>] => {\n let i = 0\n let s1 = s\n const out: Array<B> = []\n for (const a of self) {\n const r = f(s1, a, i)\n s1 = r[0]\n out.push(r[1])\n i++\n }\n return [s1, out]\n }\n)\n\n/**\n * Zips this chunk crosswise with the specified chunk using the specified combiner.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.cartesianWith([1, 2], [\"a\", \"b\"], (a, b) => `${a}-${b}`)\n * console.log(result) // [\"1-a\", \"1-b\", \"2-a\", \"2-b\"]\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\nexport const cartesianWith: {\n /**\n * Zips this chunk crosswise with the specified chunk using the specified combiner.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.cartesianWith([1, 2], [\"a\", \"b\"], (a, b) => `${a}-${b}`)\n * console.log(result) // [\"1-a\", \"1-b\", \"2-a\", \"2-b\"]\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B, C>(that: ReadonlyArray<B>, f: (a: A, b: B) => C): (self: ReadonlyArray<A>) => Array<C>\n /**\n * Zips this chunk crosswise with the specified chunk using the specified combiner.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.cartesianWith([1, 2], [\"a\", \"b\"], (a, b) => `${a}-${b}`)\n * console.log(result) // [\"1-a\", \"1-b\", \"2-a\", \"2-b\"]\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B, C>(self: ReadonlyArray<A>, that: ReadonlyArray<B>, f: (a: A, b: B) => C): Array<C>\n} = dual(\n 3,\n <A, B, C>(self: ReadonlyArray<A>, that: ReadonlyArray<B>, f: (a: A, b: B) => C): Array<C> =>\n flatMap(self, (a) => map(that, (b) => f(a, b)))\n)\n\n/**\n * Zips this chunk crosswise with the specified chunk.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.cartesian([1, 2], [\"a\", \"b\"])\n * console.log(result) // [[1, \"a\"], [1, \"b\"], [2, \"a\"], [2, \"b\"]]\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\nexport const cartesian: {\n /**\n * Zips this chunk crosswise with the specified chunk.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.cartesian([1, 2], [\"a\", \"b\"])\n * console.log(result) // [[1, \"a\"], [1, \"b\"], [2, \"a\"], [2, \"b\"]]\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <B>(that: ReadonlyArray<B>): <A>(self: ReadonlyArray<A>) => Array<[A, B]>\n /**\n * Zips this chunk crosswise with the specified chunk.\n *\n * **Example**\n *\n * ```ts\n * import { Array } from \"effect\"\n *\n * const result = Array.cartesian([1, 2], [\"a\", \"b\"])\n * console.log(result) // [[1, \"a\"], [1, \"b\"], [2, \"a\"], [2, \"b\"]]\n * ```\n *\n * @since 2.0.0\n * @category elements\n */\n <A, B>(self: ReadonlyArray<A>, that: ReadonlyArray<B>): Array<[A, B]>\n} = dual(\n 2,\n <A, B>(self: ReadonlyArray<A>, that: ReadonlyArray<B>): Array<[A, B]> => cartesianWith(self, that, (a, b) => [a, b])\n)\n\n// -------------------------------------------------------------------------------------\n// do notation\n// -------------------------------------------------------------------------------------\n\n/**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const doResult = pipe(\n * Array.Do,\n * Array.bind(\"x\", () => [1, 3, 5]),\n * Array.bind(\"y\", () => [2, 4, 6]),\n * Array.filter(({ x, y }) => x < y), // condition\n * Array.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * console.log(doResult) // [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]]\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @see {@link bindTo}\n * @see {@link bind}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 3.2.0\n */\nexport const Do: ReadonlyArray<{}> = of({})\n\n/**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const doResult = pipe(\n * Array.Do,\n * Array.bind(\"x\", () => [1, 3, 5]),\n * Array.bind(\"y\", () => [2, 4, 6]),\n * Array.filter(({ x, y }) => x < y), // condition\n * Array.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * console.log(doResult) // [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]]\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 3.2.0\n */\nexport const bind: {\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const doResult = pipe(\n * Array.Do,\n * Array.bind(\"x\", () => [1, 3, 5]),\n * Array.bind(\"y\", () => [2, 4, 6]),\n * Array.filter(({ x, y }) => x < y), // condition\n * Array.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * console.log(doResult) // [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]]\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 3.2.0\n */\n <A extends object, N extends string, B>(tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): (\n self: ReadonlyArray<A>\n ) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const doResult = pipe(\n * Array.Do,\n * Array.bind(\"x\", () => [1, 3, 5]),\n * Array.bind(\"y\", () => [2, 4, 6]),\n * Array.filter(({ x, y }) => x < y), // condition\n * Array.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * console.log(doResult) // [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]]\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 3.2.0\n */\n <A extends object, N extends string, B>(\n self: ReadonlyArray<A>,\n tag: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => ReadonlyArray<B>\n ): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n} = internalDoNotation.bind<ReadonlyArrayTypeLambda>(map, flatMap) as any\n\n/**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const doResult = pipe(\n * Array.Do,\n * Array.bind(\"x\", () => [1, 3, 5]),\n * Array.bind(\"y\", () => [2, 4, 6]),\n * Array.filter(({ x, y }) => x < y), // condition\n * Array.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * console.log(doResult) // [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]]\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 3.2.0\n */\nexport const bindTo: {\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const doResult = pipe(\n * Array.Do,\n * Array.bind(\"x\", () => [1, 3, 5]),\n * Array.bind(\"y\", () => [2, 4, 6]),\n * Array.filter(({ x, y }) => x < y), // condition\n * Array.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * console.log(doResult) // [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]]\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 3.2.0\n */\n <N extends string>(tag: N): <A>(self: ReadonlyArray<A>) => Array<{ [K in N]: A }>\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const doResult = pipe(\n * Array.Do,\n * Array.bind(\"x\", () => [1, 3, 5]),\n * Array.bind(\"y\", () => [2, 4, 6]),\n * Array.filter(({ x, y }) => x < y), // condition\n * Array.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * console.log(doResult) // [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]]\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n * ```\n *\n * @see {@link bindTo}\n * @see {@link Do}\n * @see {@link let_ let}\n *\n * @category do notation\n * @since 3.2.0\n */\n <A, N extends string>(self: ReadonlyArray<A>, tag: N): Array<{ [K in N]: A }>\n} = internalDoNotation.bindTo<ReadonlyArrayTypeLambda>(map) as any\n\nconst let_: {\n <N extends string, B, A extends object>(\n tag: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): (self: ReadonlyArray<A>) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n <N extends string, A extends object, B>(\n self: ReadonlyArray<A>,\n tag: Exclude<N, keyof A>,\n f: (a: NoInfer<A>) => B\n ): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>\n} = internalDoNotation.let_<ReadonlyArrayTypeLambda>(map) as any\n\nexport {\n /**\n * The \"do simulation\" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.\n *\n * It can be used to simulate \"array comprehension\".\n * It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.\n *\n * Here's how the do simulation works:\n *\n * 1. Start the do simulation using the `Do` value\n * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values\n * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope\n * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values\n * 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope\n *\n * **Example**\n *\n * ```ts\n * import { Array, pipe } from \"effect\"\n *\n * const doResult = pipe(\n * Array.Do,\n * Array.bind(\"x\", () => [1, 3, 5]),\n * Array.bind(\"y\", () => [2, 4, 6]),\n * Array.filter(({ x, y }) => x < y), // condition\n * Array.map(({ x, y }) => [x, y] as const) // transformation\n * )\n * console.log(doResult) // [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]]\n *\n * // equivalent\n * const x = [1, 3, 5],\n * y = [2, 4, 6],\n * result = [];\n * for(let i = 0; i < x.length; i++) {\n * for(let j = 0; j < y.length; j++) {\n * const _x = x[i], _y = y[j];\n * if(_x < _y) result.push([_x, _y] as const)\n * }\n * }\n *\n * ```\n *\n * @see {@link bindTo}\n * @see {@link bind}\n * @see {@link Do}\n *\n * @category do notation\n * @since 3.2.0\n */\n let_ as let\n}\n","import * as Either from \"effect/Either\"\nimport { dual } from \"effect/Function\"\nimport type { TypeLambda } from \"effect/HKT\"\nimport * as Option from \"effect/Option\"\nimport * as Gen from \"effect/Utils\"\n\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\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\nconst evaluate = Symbol.for(\"Nano.evaluate\")\nconst contA = Symbol.for(\"Nano.contA\")\ntype contA = typeof contA\nconst contE = Symbol.for(\"Nano.contE\")\ntype contE = typeof contE\nconst contAll = Symbol.for(\"Nano.contAll\")\ntype contAll = typeof contAll\nconst NanoYield = Symbol.for(\"Nano.yield\")\ntype NanoYield = typeof NanoYield\nconst args = Symbol.for(\"Nano.args\")\ntype args = typeof args\n\nexport class NanoDefectException {\n readonly _tag = \"@effect/language-service/NanoDefectException\"\n constructor(\n readonly message: unknown\n ) {}\n}\n\ninterface NanoPrimitive {\n [args]?: any\n [contA]?: (value: any, fiber: NanoFiber) => NanoPrimitive | NanoYield\n [contE]?: (value: any, fiber: NanoFiber) => NanoPrimitive | NanoYield\n [contAll]?: (fiber: NanoFiber) => NanoPrimitive | NanoYield\n [evaluate]: (fiber: NanoFiber) => NanoPrimitive | NanoYield\n [Symbol.iterator](): NanoIterator<Nano<any, any, any>>\n}\n\ntype NanoExit =\n & NanoPrimitive\n & ({\n _tag: \"Success\"\n value: any\n } | {\n _tag: \"Failure\"\n value: any\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> extends NanoPrimitive {\n readonly \"~nano.success\": A\n readonly \"~nano.error\": E\n readonly \"~nano.requirements\": R\n [Symbol.iterator](): NanoIterator<Nano<A, E, R>>\n}\n\nconst PrimitiveProto: Pick<NanoPrimitive, typeof Symbol.iterator> = {\n [Symbol.iterator]() {\n return new Gen.SingleShotGen(new Gen.YieldWrap(this as any as Nano<any, any, any>))\n }\n}\n\nconst SucceedProto: NanoPrimitive & NanoExit = {\n ...PrimitiveProto,\n _tag: \"Success\",\n get value() {\n return this[args]\n },\n [evaluate](fiber: NanoFiber) {\n const cont = fiber.getCont(contA)\n return cont ? cont[contA](this[args], fiber) : fiber.yieldWith(this)\n }\n}\nexport const succeed: <A>(value: A) => Nano<A, never, never> = <A>(value: A) => {\n const nano = Object.create(SucceedProto)\n nano[args] = value\n return nano\n}\n\nconst FailureProto: NanoPrimitive & NanoExit = {\n ...PrimitiveProto,\n _tag: \"Failure\",\n get value() {\n return this[args]\n },\n [evaluate](fiber: NanoFiber) {\n const cont = fiber.getCont(contE)\n return cont ? cont[contE](this[args], fiber) : fiber.yieldWith(this)\n }\n}\nexport const fail: <E>(error: E) => Nano<never, E, never> = <E>(error: E) => {\n const nano = Object.create(FailureProto)\n nano[args] = error\n return nano\n}\n\nconst SuspendProto: NanoPrimitive = {\n ...PrimitiveProto,\n [evaluate]() {\n return this[args]()\n }\n}\nexport const suspend: <A, E, R>(fn: () => Nano<A, E, R>) => Nano<A, E, R> = <A, E, R>(fn: () => Nano<A, E, R>) => {\n const nano = Object.create(SuspendProto)\n nano[args] = fn\n return nano\n}\n\nclass NanoFiber {\n readonly _stack: Array<NanoPrimitive> = []\n _yielded: NanoExit | undefined = undefined\n _services: Record<string, any> = {}\n _cache: Record<string, WeakMap<any, any>> = {}\n\n runLoop(nano: Nano<any, any, any>) {\n let current: NanoPrimitive | NanoYield = nano\n while (true) {\n current = (current as any)[evaluate](this)\n if (current === NanoYield) {\n return this._yielded\n }\n }\n }\n\n getCont<S extends contA | contE>(this: NanoFiber, symbol: S):\n | (NanoPrimitive & Record<S, (value: any, fiber: NanoFiber) => NanoPrimitive>)\n | undefined\n {\n while (true) {\n const op = this._stack.pop()\n if (!op) return undefined\n const cont = op[contAll] && op[contAll](this)\n if (cont) return { [symbol]: cont } as any\n if (op[symbol]) return op as any\n }\n }\n\n yieldWith(this: NanoFiber, value: NanoExit): NanoYield {\n this._yielded = value\n return NanoYield\n }\n}\n\nexport const unsafeRun = <A, E>(nano: Nano<A, E, never>): Either.Either<A, E | NanoDefectException> => {\n const fiber = new NanoFiber()\n const result = fiber.runLoop(nano)!\n if (result._tag === \"Success\") {\n return Either.right(result.value)\n }\n return Either.left(result.value)\n}\n\nexport const run = <A, E>(nano: Nano<A, E, never>): Either.Either<A, E | NanoDefectException> => {\n try {\n return unsafeRun(nano)\n } catch (e) {\n return Either.left(new NanoDefectException(e))\n }\n}\n\nconst OnSuccessProto: NanoPrimitive = {\n ...PrimitiveProto,\n [evaluate](fiber: NanoFiber) {\n fiber._stack.push(this)\n return this[args]\n }\n}\n\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 const nano = Object.create(OnSuccessProto)\n nano[args] = fa\n nano[contA] = f\n return nano\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) => flatMap(fa, (_) => succeed(f(_))))\n\nconst SyncProto: NanoPrimitive = {\n ...PrimitiveProto,\n [evaluate](fiber) {\n const value = this[args]()\n const cont = fiber.getCont(contA)\n return cont\n ? cont[contA](value, fiber)\n : fiber.yieldWith(succeed(value) as any)\n }\n}\n\nexport const sync = <A>(f: () => A): Nano<A, never, never> => {\n const nano = Object.create(SyncProto)\n nano[args] = f\n return nano\n}\n\nexport const void_ = succeed(undefined)\n\nconst FromIteratorProto: NanoPrimitive = {\n ...PrimitiveProto,\n [contA](value, fiber) {\n const state = this[args][0].next(value)\n if (state.done) return succeed(state.value)\n fiber._stack.push(this)\n return Gen.yieldWrapGet(state.value)\n },\n [evaluate](this: any, fiber: NanoFiber) {\n return this[contA](this[args][1], fiber)\n }\n}\n\nconst unsafeFromIterator = (\n iterator: Iterator<Gen.YieldWrap<Nano<any, any, any>>>,\n initial?: undefined\n) => {\n const nano = Object.create(FromIteratorProto)\n nano[args] = [iterator, initial]\n return nano\n}\n\nexport const gen = <Eff extends Gen.YieldWrap<Nano<any, any, any>>, AEff>(\n ...args: [body: () => Generator<Eff, AEff, never>]\n): Nano<\n AEff,\n [Eff] extends [never] ? never\n : [Eff] extends [Gen.YieldWrap<Nano<infer _A, infer E, infer _R>>] ? E\n : never,\n [Eff] extends [never] ? never\n : [Eff] extends [Gen.YieldWrap<Nano<infer _A, infer _E, infer R>>] ? R\n : never\n> => suspend(() => unsafeFromIterator(args[0]()))\n\nexport const fn = (_: string) =>\n<Eff extends Gen.YieldWrap<Nano<any, any, any>>, AEff, Args extends Array<any>>(\n body: (...args: Args) => Generator<Eff, AEff, never>\n) =>\n(...args: Args): Nano<\n AEff,\n [Eff] extends [never] ? never\n : [Eff] extends [Gen.YieldWrap<Nano<infer _A, infer E, infer _R>>] ? E\n : never,\n [Eff] extends [never] ? never\n : [Eff] extends [Gen.YieldWrap<Nano<infer _A, infer _E, infer R>>] ? R\n : never\n> => suspend(() => unsafeFromIterator(body(...args)))\n\nconst MatchProto: NanoPrimitive = {\n ...PrimitiveProto,\n [evaluate](fiber) {\n fiber._stack.push(this)\n return this[args]\n }\n}\n\nexport const match = <A, B, E, R, C, E2, R2, E3, R3>(\n fa: Nano<A, E, R>,\n opts: {\n onSuccess: (a: A) => Nano<B, E2, R2>\n onFailure: (e: E) => Nano<C, E3, R3>\n }\n): Nano<B, E | E2 | E3, R | R2 | R3> => {\n const nano = Object.create(MatchProto)\n nano[args] = fa\n nano[contA] = opts.onSuccess\n nano[contE] = opts.onFailure\n return nano\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>): Nano<A | B, E2, R | R2> => {\n const nano = Object.create(MatchProto)\n nano[args] = fa\n nano[contE] = f\n return nano\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\nconst ProvideServiceProto: NanoPrimitive = {\n ...PrimitiveProto,\n [evaluate](fiber) {\n const prevServices = fiber._services\n const [fa, tag, value]: [Nano<any, any, any>, NanoTag<any>, any] = this[args]\n fiber._services = {\n ...fiber._services,\n [tag.key]: value\n }\n return match(fa, {\n onSuccess: (_) => {\n fiber._services = prevServices\n return succeed(_)\n },\n onFailure: (_) => {\n fiber._services = prevServices\n return fail(_)\n }\n })\n }\n}\n\nexport const provideService = <I extends NanoTag<any>>(\n tag: I,\n value: I[\"~nano.requirements\"]\n) =>\n<A, E, R>(fa: Nano<A, E, R>): Nano<A, E, Exclude<R, I[\"~nano.requirements\"]>> => {\n const nano = Object.create(ProvideServiceProto)\n nano[args] = [fa, tag, value]\n return nano\n}\n\nconst ServiceProto: NanoPrimitive = {\n ...PrimitiveProto,\n [evaluate](fiber) {\n const tag: NanoTag<any> = this[args]\n if (tag.key in fiber._services) {\n const value = fiber._services[tag.key]\n const cont = fiber.getCont(contA)\n return cont ? cont[contA](value, fiber) : fiber.yieldWith(succeed(value) as any)\n }\n const cont = fiber.getCont(contE)\n return cont\n ? cont[contE](tag, fiber)\n : fiber.yieldWith(fail(new NanoDefectException(`Service ${tag.key} not found`)) as any)\n }\n}\n\nexport const service = <I extends NanoTag<any>>(\n tag: I\n): Nano<I[\"~nano.requirements\"], never, I[\"~nano.requirements\"]> => {\n const nano = Object.create(ServiceProto)\n nano[args] = tag\n return nano\n}\n\nconst CachedProto: NanoPrimitive = {\n ...PrimitiveProto,\n [evaluate](fiber) {\n const [fa, type, key]: [Nano<any, any, any>, string, any] = this[args]\n const cache = fiber._cache[type] || new WeakMap<any, any>()\n fiber._cache[type] = cache\n const cached = cache.get(key)\n if (cached) return cached\n return match(fa, {\n onSuccess: (_) => {\n cache.set(key, succeed(_))\n return succeed(_)\n },\n onFailure: (_) => {\n cache.set(key, fail(_))\n return fail(_)\n }\n })\n }\n}\n\nexport function cachedBy<P extends Array<any>, A, E, R>(\n fa: (...p: P) => Nano<A, E, R>,\n type: string,\n lookupKey: (...p: P) => object\n) {\n return (...p: P): Nano<A, E, R> => {\n const nano = Object.create(CachedProto)\n nano[args] = [fa(...p), type, lookupKey(...p)]\n return nano\n }\n}\n\nexport const option = <A, E, R>(fa: Nano<A, E, R>): Nano<Option.Option<A>, never, R> => {\n const nano = Object.create(MatchProto)\n nano[args] = fa\n nano[contA] = (_: A) => succeed(Option.some(_))\n nano[contE] = (_: E | NanoDefectException) => _ instanceof NanoDefectException ? fail(_) : succeed(Option.none())\n return nano\n}\n\nexport const ignore = <A, E, R>(fa: Nano<A, E, R>): Nano<void, never, R> => {\n const nano = Object.create(MatchProto)\n nano[args] = fa\n nano[contA] = (_: A) => void_\n nano[contE] = (_: E | NanoDefectException) => _ instanceof NanoDefectException ? fail(_) : void_\n return nano\n}\n\nexport const all: <A extends Array<Nano<any, any, any>>>(\n ...args: A\n) => Nano<Array<A[number][\"~nano.success\"]>, A[number][\"~nano.error\"], A[number][\"~nano.requirements\"]> = fn(\"all\")(\n function*<A extends Array<Nano<any, any, any>>>(\n ...args: A\n ) {\n const results = [] as Array<A[number][\"~nano.success\"]>\n for (const fa of args) {\n const result = yield* fa\n results.push(result)\n }\n return results\n }\n)\n\nexport const getTimings = () => [] as Array<string>\n","import { isArray } from \"effect/Array\"\nimport * as Array from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport { hasProperty, isBoolean, isObject, isRecord, isString } from \"effect/Predicate\"\nimport * as Nano from \"./Nano\"\n\nexport type DiagnosticSeverity = \"error\" | \"warning\" | \"message\" | \"suggestion\"\n\nexport interface LanguageServicePluginOptions {\n refactors: boolean\n diagnostics: boolean\n diagnosticSeverity: Record<string, DiagnosticSeverity | \"off\">\n quickinfoEffectParameters: \"always\" | \"never\" | \"whentruncated\"\n quickinfo: boolean\n completions: boolean\n goto: boolean\n inlays: boolean\n allowedDuplicatedPackages: Array<string>\n namespaceImportPackages: Array<string>\n topLevelNamedReexports: \"ignore\" | \"follow\"\n barrelImportPackages: Array<string>\n}\n\nexport const LanguageServicePluginOptions = Nano.Tag<LanguageServicePluginOptions>(\"PluginOptions\")\n\nfunction parseDiagnosticSeverity(config: Record<PropertyKey, unknown>): Record<string, DiagnosticSeverity | \"off\"> {\n if (!isRecord(config)) return {}\n return Object.fromEntries(\n pipe(\n Object.entries(config),\n Array.filter(([key, value]) => isString(key) && isString(value)),\n Array.map(([key, value]) => [String(key).toLowerCase(), String(value).toLowerCase()]),\n Array.filter(([_, value]) =>\n value === \"off\" || value === \"error\" || value === \"warning\" || value === \"message\" || value === \"suggestion\"\n )\n )\n )\n}\n\nexport const defaults: LanguageServicePluginOptions = {\n refactors: true,\n diagnostics: true,\n diagnosticSeverity: {},\n quickinfo: true,\n quickinfoEffectParameters: \"whentruncated\",\n completions: true,\n goto: true,\n inlays: true,\n allowedDuplicatedPackages: [],\n namespaceImportPackages: [],\n barrelImportPackages: [],\n topLevelNamedReexports: \"ignore\"\n}\n\nexport function parse(config: any): LanguageServicePluginOptions {\n return {\n refactors: isObject(config) && hasProperty(config, \"refactors\") && isBoolean(config.refactors)\n ? config.refactors\n : defaults.refactors,\n diagnostics: isObject(config) && hasProperty(config, \"diagnostics\") && isBoolean(config.diagnostics)\n ? config.diagnostics\n : defaults.diagnostics,\n diagnosticSeverity:\n isObject(config) && hasProperty(config, \"diagnosticSeverity\") && isRecord(config.diagnosticSeverity)\n ? parseDiagnosticSeverity(config.diagnosticSeverity)\n : defaults.diagnosticSeverity,\n quickinfo: isObject(config) && hasProperty(config, \"quickinfo\") && isBoolean(config.quickinfo)\n ? config.quickinfo\n : defaults.quickinfo,\n quickinfoEffectParameters: isObject(config) && hasProperty(config, \"quickinfoEffectParameters\") &&\n isString(config.quickinfoEffectParameters) &&\n [\"always\", \"never\", \"whentruncated\"].includes(config.quickinfoEffectParameters.toLowerCase())\n ? config.quickinfoEffectParameters.toLowerCase() as \"always\" | \"never\" | \"whentruncated\"\n : defaults.quickinfoEffectParameters,\n completions: isObject(config) && hasProperty(config, \"completions\") && isBoolean(config.completions)\n ? config.completions\n : defaults.completions,\n goto: isObject(config) && hasProperty(config, \"goto\") && isBoolean(config.goto)\n ? config.goto\n : defaults.goto,\n inlays: isObject(config) && hasProperty(config, \"inlays\") && isBoolean(config.inlays)\n ? config.inlays\n : defaults.inlays,\n allowedDuplicatedPackages: isObject(config) && hasProperty(config, \"allowedDuplicatedPackages\") &&\n isArray(config.allowedDuplicatedPackages) && config.allowedDuplicatedPackages.every(isString)\n ? config.allowedDuplicatedPackages.map((_) => _.toLowerCase())\n : defaults.allowedDuplicatedPackages,\n namespaceImportPackages: isObject(config) && hasProperty(config, \"namespaceImportPackages\") &&\n isArray(config.namespaceImportPackages) && config.namespaceImportPackages.every(isString)\n ? config.namespaceImportPackages.map((_) => _.toLowerCase())\n : defaults.namespaceImportPackages,\n barrelImportPackages: isObject(config) && hasProperty(config, \"barrelImportPackages\") &&\n isArray(config.barrelImportPackages) && config.barrelImportPackages.every(isString)\n ? config.barrelImportPackages.map((_) => _.toLowerCase())\n : defaults.barrelImportPackages,\n topLevelNamedReexports: isObject(config) && hasProperty(config, \"topLevelNamedReexports\") &&\n isString(config.topLevelNamedReexports) &&\n [\"ignore\", \"follow\"].includes(config.topLevelNamedReexports.toLowerCase())\n ? config.topLevelNamedReexports.toLowerCase() as \"ignore\" | \"follow\"\n : defaults.topLevelNamedReexports\n }\n}\n","import type ts from \"typescript\"\nimport * as Nano from \"../core/Nano.js\"\n\ndeclare module \"typescript\" {\n export function insertImports(\n changes: textChanges.ChangeTracker,\n sourceFile: ts.SourceFile,\n imports: ts.ImportDeclaration,\n blankLineBetween: boolean,\n preferences: ts.UserPreferences\n ): void\n\n const nullTransformationContext: ts.TransformationContext\n\n export namespace formatting {\n interface FormattingHost {\n getNewLine?(): string\n }\n\n export interface FormatContext {\n readonly options: ts.FormatCodeSettings\n readonly getRules: unknown\n }\n\n function getFormatContext(options: ts.FormatCodeSettings, host: FormattingHost): FormatContext\n }\n\n export type TextChangesContext = any\n\n export namespace textChanges {\n export interface ChangeNodeOptions extends ConfigurableStartEnd, InsertNodeOptions {}\n export enum LeadingTriviaOption {\n /** Exclude all leading trivia (use getStart()) */\n Exclude = 0,\n /** Include leading trivia and,\n * if there are no line breaks between the node and the previous token,\n * include all trivia between the node and the previous token\n */\n IncludeAll = 1,\n /**\n * Include attached JSDoc comments\n */\n JSDoc = 2,\n /**\n * Only delete trivia on the same line as getStart().\n * Used to avoid deleting leading comments\n */\n StartLine = 3\n }\n export enum TrailingTriviaOption {\n /** Exclude all trailing trivia (use getEnd()) */\n Exclude = 0,\n /** Doesn't include whitespace, but does strip comments */\n ExcludeWhitespace = 1,\n /** Include trailing trivia */\n Include = 2\n }\n export interface ConfigurableStart {\n leadingTriviaOption?: LeadingTriviaOption\n }\n export interface ConfigurableEnd {\n trailingTriviaOption?: TrailingTriviaOption\n }\n export interface InsertNodeOptions {\n /**\n * Text to be inserted before the new node\n */\n prefix?: string\n /**\n * Text to be inserted after the new node\n */\n suffix?: string\n /**\n * Text of inserted node will be formatted with this indentation, otherwise indentation will be inferred from the old node\n */\n indentation?: number\n /**\n * Text of inserted node will be formatted with this delta, otherwise delta will be inferred from the new node kind\n */\n delta?: number\n }\n export interface ConfigurableStartEnd extends ConfigurableStart, ConfigurableEnd {\n }\n export class ChangeTracker {\n static with(\n context: ts.TextChangesContext,\n cb: (tracker: ChangeTracker) => void\n ): Array<ts.FileTextChanges>\n delete(\n sourceFile: ts.SourceFile,\n node: ts.Node | ts.NodeArray<ts.TypeParameterDeclaration>\n ): void\n deleteRange(sourceFile: ts.SourceFile, range: ts.TextRange): void\n replaceNode(\n sourceFile: ts.SourceFile,\n oldNode: ts.Node,\n newNode: ts.Node,\n options?: ts.textChanges.ChangeNodeOptions\n ): void\n insertNodeAt(\n sourceFile: ts.SourceFile,\n pos: number,\n newNode: ts.Node,\n options?: ts.textChanges.InsertNodeOptions\n ): void\n insertNodeBefore(\n sourceFile: ts.SourceFile,\n before: ts.Node,\n newNode: ts.Node,\n blankLineBetween?: boolean,\n options?: ConfigurableStartEnd\n ): void\n insertNodeAfter(sourceFile: ts.SourceFile, after: ts.Node, newNode: ts.Node): void\n insertText(sourceFile: ts.SourceFile, pos: number, text: string): void\n insertCommentBeforeLine(\n sourceFile: ts.SourceFile,\n lineNumber: number,\n position: number,\n commentText: string\n ): void\n }\n export function applyChanges(text: string, changes: ReadonlyArray<ts.TextChange>): string\n }\n\n export function findPrecedingToken(\n position: number,\n sourceFile: ts.SourceFileLike,\n startNode: ts.Node,\n excludeJsdoc?: boolean\n ): ts.Node | undefined\n export function findPrecedingToken(\n position: number,\n sourceFile: ts.SourceFile,\n startNode?: ts.Node,\n excludeJsdoc?: boolean\n ): ts.Node | undefined\n function findChildOfKind<T extends ts.Node>(\n n: ts.Node,\n kind: T[\"kind\"],\n sourceFile: ts.SourceFileLike\n ): T | undefined\n\n export function isMemberName(node: ts.Node): node is ts.MemberName\n export function isKeyword(token: ts.SyntaxKind): token is ts.KeywordSyntaxKind\n\n export interface TypeChecker {\n isTypeAssignableTo(source: ts.Type, target: ts.Type): boolean\n getUnionType(types: ReadonlyArray<ts.Type>): ts.Type\n }\n}\n\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 Array from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport { hasProperty, isFunction, isObject, isString } from \"effect/Predicate\"\nimport type ts from \"typescript\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport interface ModuleWithPackageInfo {\n name: string\n version: string\n hasEffectInPeerDependencies: boolean\n contents: any\n packageDirectory: string\n referencedPackages: Array<string>\n exportsKeys: Array<string>\n}\n\nexport interface TypeScriptUtils {\n parsePackageContentNameAndVersionFromScope: (v: unknown) => ModuleWithPackageInfo | undefined\n findNodeWithLeadingCommentAtPosition: (\n sourceFile: ts.SourceFile,\n position: number\n ) => { node: ts.Node; commentRange: ts.CommentRange } | undefined\n getCommentAtPosition: (sourceFile: ts.SourceFile, pos: number) => ts.CommentRange | undefined\n makeGetModuleSpecifier: () =>\n | ((\n compilerOptions: ts.CompilerOptions,\n importingSourceFile: ts.SourceFile,\n importingSourceFileName: string,\n toFileName: string,\n host: any,\n options?: any\n ) => string)\n | undefined\n resolveModulePattern: (sourceFile: ts.SourceFile, pattern: string) => Array<string>\n getAncestorNodesInRange: (sourceFile: ts.SourceFile, textRange: ts.TextRange) => Array<ts.Node>\n findImportedModuleIdentifierByPackageAndNameOrBarrel: (\n sourceFile: ts.SourceFile,\n packageName: string,\n moduleName: string\n ) => string | undefined\n simplifyTypeNode: (typeNode: ts.TypeNode) => ts.TypeNode\n createEffectGenCallExpressionWithBlock: (\n effectModuleIdentifierName: string,\n statement: ts.Statement | Array<ts.Statement>\n ) => ts.CallExpression\n createReturnYieldStarStatement: (\n expr: ts.Expression\n ) => ts.ReturnStatement\n transformAsyncAwaitToEffectGen: (\n node: ts.FunctionDeclaration | ts.ArrowFunction | ts.FunctionExpression,\n effectModuleName: string,\n onAwait: (expression: ts.Expression) => ts.Expression\n ) => ts.Node\n tryPreserveDeclarationSemantics: (\n nodeToReplace: ts.Node,\n node: ts.Node\n ) => ts.Node\n isNodeInRange: (textRange: ts.TextRange) => (node: ts.Node) => boolean\n toTextRange: (position: number) => ts.TextRange\n parseDataForExtendsClassCompletion: (sourceFile: ts.SourceFile, position: number) => {\n accessedObject: ts.Identifier\n classDeclaration: ts.ClassDeclaration\n className: ts.Identifier\n replacementSpan: ts.TextSpan\n } | undefined\n parseAccessedExpressionForCompletion: (sourceFile: ts.SourceFile, position: number) => {\n accessedObject: ts.Node\n outerNode: ts.Node\n replacementSpan: ts.TextSpan\n } | undefined\n findNodeAtPositionIncludingTrivia: (\n sourceFile: ts.SourceFile,\n position: number\n ) => ts.Node | undefined\n}\nexport const TypeScriptUtils = Nano.Tag<TypeScriptUtils>(\"TypeScriptUtils\")\n\nexport const nanoLayer = <A, E, R>(\n fa: Nano.Nano<A, E, R>\n) =>\n pipe(\n Nano.service(TypeScriptApi.TypeScriptApi),\n Nano.flatMap((ts) => pipe(fa, Nano.provideService(TypeScriptUtils, makeTypeScriptUtils(ts))))\n )\n\nexport function makeTypeScriptUtils(ts: TypeScriptApi.TypeScriptApi): TypeScriptUtils {\n /**\n * Parse internal package info from a scope\n */\n function parsePackageContentNameAndVersionFromScope(v: unknown): ModuleWithPackageInfo | undefined {\n if (!isObject(v)) return\n if (!hasProperty(v, \"packageJsonScope\")) return\n if (!v.packageJsonScope) return\n const packageJsonScope = v.packageJsonScope\n if (!hasProperty(packageJsonScope, \"contents\")) return\n if (!hasProperty(packageJsonScope.contents, \"packageJsonContent\")) return\n const packageJsonContent = packageJsonScope.contents.packageJsonContent\n if (!hasProperty(packageJsonContent, \"name\")) return\n if (!hasProperty(packageJsonContent, \"version\")) return\n if (!hasProperty(packageJsonScope, \"packageDirectory\")) return\n if (!isString(packageJsonScope.packageDirectory)) return\n const { name, version } = packageJsonContent\n if (!isString(name)) return\n if (!isString(version)) return\n const hasEffectInPeerDependencies = hasProperty(packageJsonContent, \"peerDependencies\") &&\n isObject(packageJsonContent.peerDependencies) &&\n hasProperty(packageJsonContent.peerDependencies, \"effect\")\n\n const referencedPackages = Object.keys({\n ...(hasProperty(packageJsonContent, \"dependencies\") && isObject(packageJsonContent.dependencies)\n ? packageJsonContent.dependencies\n : {}),\n ...(hasProperty(packageJsonContent, \"peerDependencies\") && isObject(packageJsonContent.peerDependencies)\n ? packageJsonContent.peerDependencies\n : {}),\n ...(hasProperty(packageJsonContent, \"devDependencies\") && isObject(packageJsonContent.devDependencies)\n ? packageJsonContent.devDependencies\n : {})\n })\n\n const exportsKeys = Object.keys(\n hasProperty(packageJsonContent, \"exports\") && isObject(packageJsonContent.exports)\n ? packageJsonContent.exports\n : {}\n )\n\n return {\n name: name.toLowerCase(),\n version: version.toLowerCase(),\n hasEffectInPeerDependencies,\n contents: packageJsonContent,\n packageDirectory: packageJsonScope.packageDirectory,\n referencedPackages,\n exportsKeys\n }\n }\n\n function resolveModulePattern(sourceFile: ts.SourceFile, pattern: string) {\n if (pattern.indexOf(\"*\") === -1) return [pattern.toLowerCase()]\n const packageJsonScope = parsePackageContentNameAndVersionFromScope(sourceFile)\n const referencedPackages: Array<string> = []\n for (const statement of sourceFile.statements) {\n if (ts.isImportDeclaration(statement) && ts.isStringLiteral(statement.moduleSpecifier)) {\n const moduleSpecifier = statement.moduleSpecifier.text.toLowerCase()\n const packageName = moduleSpecifier.startsWith(\"@\")\n ? moduleSpecifier.split(\"/\", 2).join(\"/\")\n : moduleSpecifier.split(\"/\", 1).join(\"/\")\n referencedPackages.push(packageName)\n }\n }\n return pipe(\n referencedPackages.concat(packageJsonScope?.referencedPackages || []),\n Array.dedupe,\n Array.map((packageName) => packageName.toLowerCase()),\n Array.filter((packageName) =>\n pattern.endsWith(\"*\") &&\n packageName.startsWith(pattern.toLowerCase().substring(0, pattern.length - 1))\n )\n )\n }\n\n function makeGetModuleSpecifier() {\n if (\n !(hasProperty(ts, \"moduleSpecifiers\") && hasProperty(ts.moduleSpecifiers, \"getModuleSpecifier\") &&\n isFunction(ts.moduleSpecifiers.getModuleSpecifier))\n ) return\n const _internal = ts.moduleSpecifiers.getModuleSpecifier\n return (\n compilerOptions: ts.CompilerOptions,\n importingSourceFile: ts.SourceFile,\n importingSourceFileName: string,\n toFileName: string,\n host: any,\n options?: any\n ): string => {\n return _internal(\n compilerOptions,\n importingSourceFile,\n importingSourceFileName,\n toFileName,\n host,\n options\n )\n }\n }\n\n function findNodeWithLeadingCommentAtPosition(sourceFile: ts.SourceFile, position: number) {\n const sourceText = sourceFile.text\n let result: { node: ts.Node; commentRange: ts.CommentRange } | undefined\n\n function find(node: ts.Node) {\n // Check leading comments\n const leading = ts.getLeadingCommentRanges(sourceText, node.getFullStart())\n if (leading) {\n for (const commentRange of leading) {\n if (commentRange.pos <= position && position < commentRange.end) {\n // we found the comment\n result = { node, commentRange }\n return\n }\n }\n }\n // Continue traversing only if the position is within this node\n if (node.getFullStart() <= position && position < node.getEnd()) {\n node.forEachChild(find)\n }\n }\n find(sourceFile)\n return result\n }\n\n /**\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 function collectSelfAndAncestorNodesInRange(\n node: ts.Node,\n textRange: ts.TextRange\n ): Array<ts.Node> {\n let result = Array.empty<ts.Node>()\n let parent = node\n while (parent) {\n if (parent.end >= textRange.end) {\n result = pipe(result, Array.append(parent))\n }\n parent = parent.parent\n }\n return result\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 function findNodeAtPosition(\n sourceFile: ts.SourceFile,\n position: number\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 return find(sourceFile)\n }\n\n function findNodeAtPositionIncludingTrivia(\n sourceFile: ts.SourceFile,\n position: number\n ) {\n function find(node: ts.Node): ts.Node | undefined {\n if (position >= node.pos && position < node.end) {\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 return find(sourceFile)\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 */\n function getAncestorNodesInRange(\n sourceFile: ts.SourceFile,\n textRange: ts.TextRange\n ) {\n const nodeAtPosition = findNodeAtPosition(sourceFile, textRange.pos)\n if (!nodeAtPosition) return Array.empty<ts.Node>()\n return collectSelfAndAncestorNodesInRange(nodeAtPosition, textRange)\n }\n\n function getCommentAtPosition(\n sourceFile: ts.SourceFile,\n pos: number\n ) {\n const token = findNodeAtPositionIncludingTrivia(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\n }\n const startPos = token.pos === 0 ? (ts.getShebang(sourceFile.text) || \"\").length : token.pos\n\n if (startPos === 0) return\n\n const result = ts.forEachTrailingCommentRange(sourceFile.text, startPos, isCommentInRange, pos) ||\n ts.forEachLeadingCommentRange(sourceFile.text, startPos, isCommentInRange, pos)\n\n return result\n }\n\n function 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 */\n function toTextRange(positionOrRange: number | ts.TextRange): ts.TextRange {\n return typeof positionOrRange === \"number\"\n ? { end: positionOrRange, pos: positionOrRange }\n : positionOrRange\n }\n\n function isNodeInRange(textRange: ts.TextRange) {\n return (node: ts.Node) => node.pos <= textRange.pos && node.end >= textRange.end\n }\n\n function transformAsyncAwaitToEffectGen(\n node: ts.FunctionDeclaration | ts.ArrowFunction | ts.FunctionExpression,\n effectModuleName: string,\n onAwait: (expression: ts.Expression) => ts.Expression\n ) {\n function visitor(_: ts.Node): ts.Node {\n if (ts.isAwaitExpression(_)) {\n const expression = ts.visitEachChild(_.expression, visitor, ts.nullTransformationContext)\n\n return ts.factory.createYieldExpression(\n ts.factory.createToken(ts.SyntaxKind.AsteriskToken),\n onAwait(expression)\n )\n }\n return ts.visitEachChild(_, visitor, ts.nullTransformationContext)\n }\n const generatorBody = visitor(node.body!)\n\n const effectGenCallExp = 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 function findImportedModuleIdentifier(\n sourceFile: ts.SourceFile,\n test: (\n node: ts.Node,\n fromModule: ts.Expression,\n importProperty: Option.Option<ts.ModuleExportName>\n ) => boolean\n ) {\n for (const statement of sourceFile.statements) {\n if (!ts.isImportDeclaration(statement)) continue\n const importClause = statement.importClause\n if (!importClause) continue\n const namedBindings = importClause.namedBindings\n if (!namedBindings) continue\n if (ts.isNamespaceImport(namedBindings)) {\n if (test(namedBindings.name, statement.moduleSpecifier, Option.none())) {\n return (namedBindings.name.text)\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 (test(importSpecifier.name, statement.moduleSpecifier, importProperty)) {\n return (importSpecifier.name.text)\n }\n }\n }\n }\n }\n\n function findImportedModuleIdentifierByPackageAndNameOrBarrel(\n sourceFile: ts.SourceFile,\n packageName: string,\n moduleName: string\n ) {\n return findImportedModuleIdentifier(\n sourceFile,\n (_, fromModule, importProperty) => {\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\n function simplifyTypeNode(typeNode: ts.TypeNode) {\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\n function tryPreserveDeclarationSemantics(nodeToReplace: ts.Node, node: ts.Node) {\n // new node should be an expression!\n if (!ts.isExpression(node)) return node\n // ok, we need to replace. is that a method or a function?\n if (ts.isFunctionDeclaration(nodeToReplace)) {\n // I need a name!!!\n if (!nodeToReplace.name) return node\n return ts.factory.createVariableStatement(\n nodeToReplace.modifiers,\n ts.factory.createVariableDeclarationList(\n [ts.factory.createVariableDeclaration(\n nodeToReplace.name,\n undefined,\n undefined,\n node\n )],\n ts.NodeFlags.Const\n )\n )\n } else if (ts.isMethodDeclaration(nodeToReplace)) {\n return ts.factory.createPropertyDeclaration(\n nodeToReplace.modifiers,\n nodeToReplace.name,\n undefined,\n undefined,\n node\n )\n }\n // I don't know what else to do!\n return node\n }\n\n function parseAccessedExpressionForCompletion(\n sourceFile: ts.SourceFile,\n position: number\n ) {\n // first, we find the preceding token\n const precedingToken = ts.findPrecedingToken(position, sourceFile, undefined, true)\n if (!precedingToken) return\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\n }\n return { accessedObject, outerNode, replacementSpan }\n }\n\n function parseDataForExtendsClassCompletion(\n sourceFile: ts.SourceFile,\n position: number\n ) {\n const maybeInfos = parseAccessedExpressionForCompletion(sourceFile, position)\n if (!maybeInfos) return\n const { accessedObject, outerNode, replacementSpan } = maybeInfos\n\n if (!ts.isIdentifier(accessedObject)) return\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\n\n if (!classDeclaration.name) return\n\n return {\n accessedObject,\n classDeclaration,\n className: classDeclaration.name,\n replacementSpan\n } as const\n }\n\n function createEffectGenCallExpression(\n effectModuleIdentifierName: string,\n node: ts.Node\n ) {\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\n function createEffectGenCallExpressionWithBlock(\n effectModuleIdentifierName: string,\n statement: ts.Statement | Array<ts.Statement>\n ) {\n return createEffectGenCallExpression(\n effectModuleIdentifierName,\n ts.factory.createBlock(Array.isArray(statement) ? statement : [statement], false)\n )\n }\n\n function createReturnYieldStarStatement(\n expr: ts.Expression\n ) {\n return ts.factory.createReturnStatement(\n ts.factory.createYieldExpression(\n ts.factory.createToken(ts.SyntaxKind.AsteriskToken),\n expr\n )\n )\n }\n\n return {\n findNodeAtPositionIncludingTrivia,\n parsePackageContentNameAndVersionFromScope,\n resolveModulePattern,\n findNodeWithLeadingCommentAtPosition,\n getCommentAtPosition,\n getAncestorNodesInRange,\n toTextRange,\n isNodeInRange,\n transformAsyncAwaitToEffectGen,\n findImportedModuleIdentifierByPackageAndNameOrBarrel,\n simplifyTypeNode,\n tryPreserveDeclarationSemantics,\n parseDataForExtendsClassCompletion,\n createEffectGenCallExpressionWithBlock,\n createReturnYieldStarStatement,\n makeGetModuleSpecifier,\n parseAccessedExpressionForCompletion\n }\n}\n","import { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport type * as TypeCheckerApi from \"../core/TypeCheckerApi.js\"\nimport type * as TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as TypeScriptUtils from \"../core/TypeScriptUtils.js\"\nimport * as LanguageServicePluginOptions from \"./LanguageServicePluginOptions.js\"\nimport * as Nano from \"./Nano.js\"\n\nexport class RefactorNotApplicableError {\n readonly _tag = \"@effect/language-service/RefactorNotApplicableError\"\n}\n\nexport interface RefactorDefinition {\n name: string\n description: string\n apply: (\n sourceFile: ts.SourceFile,\n textRange: ts.TextRange\n ) => Nano.Nano<\n ApplicableRefactorDefinition,\n RefactorNotApplicableError,\n | TypeScriptApi.TypeScriptApi\n | TypeScriptUtils.TypeScriptUtils\n | TypeCheckerApi.TypeCheckerApi\n | TypeParser.TypeParser\n | LanguageServicePluginOptions.LanguageServicePluginOptions\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 severity: LanguageServicePluginOptions.DiagnosticSeverity | \"off\"\n apply: (\n sourceFile: ts.SourceFile,\n report: (data: {\n location: ts.TextRange | ts.Node\n messageText: string\n fixes: Array<ApplicableDiagnosticDefinitionFix>\n }) => void\n ) => Nano.Nano<\n void,\n never,\n | TypeCheckerApi.TypeCheckerApi\n | TypeParser.TypeParser\n | LanguageServicePluginOptions.LanguageServicePluginOptions\n | TypeScriptApi.TypeScriptApi\n | TypeScriptUtils.TypeScriptUtils\n | TypeScriptApi.TypeScriptProgram\n >\n}\n\nexport interface ApplicableDiagnosticDefinition {\n range: ts.TextRange\n messageText: string\n fixes: Array<ApplicableDiagnosticDefinitionFix>\n}\n\nexport interface ApplicableDiagnosticDefinitionFix {\n fixName: string\n description: string\n apply: Nano.Nano<void, never, ts.textChanges.ChangeTracker>\n}\n\nexport interface ApplicableDiagnosticDefinitionFixWithPositionAndCode extends ApplicableDiagnosticDefinitionFix {\n code: number\n start: number\n end: number\n}\n\nexport function createDiagnostic(definition: DiagnosticDefinition): DiagnosticDefinition {\n return definition\n}\n\nexport interface CompletionDefinition {\n name: string\n apply: (\n sourceFile: ts.SourceFile,\n position: number,\n options: ts.GetCompletionsAtPositionOptions | undefined,\n formatCodeSettings: ts.FormatCodeSettings | undefined\n ) => Nano.Nano<\n Array<CompletionEntryDefinition>,\n never,\n | TypeCheckerApi.TypeCheckerApi\n | TypeParser.TypeParser\n | LanguageServicePluginOptions.LanguageServicePluginOptions\n | TypeScriptApi.TypeScriptApi\n | TypeScriptUtils.TypeScriptUtils\n | TypeScriptApi.TypeScriptProgram\n >\n}\n\nexport interface CompletionEntryDefinition {\n name: string\n kind: ts.ScriptElementKind\n insertText: string\n isSnippet: true\n replacementSpan?: ts.TextSpan\n}\n\nexport function createCompletion(definition: CompletionDefinition): CompletionDefinition {\n return definition\n}\n\nexport class SourceFileNotFoundError {\n readonly _tag = \"@effect/language-service/SourceFileNotFoundError\"\n constructor(\n readonly fileName: string\n ) {}\n}\n\nexport const getSemanticDiagnosticsWithCodeFixes = Nano.fn(\n \"LSP.getSemanticDiagnosticsWithCodeFixes\"\n)(function*(\n rules: Array<DiagnosticDefinition>,\n sourceFile: ts.SourceFile\n) {\n let effectDiagnostics: Array<ts.Diagnostic> = []\n let effectCodeFixes: Array<ApplicableDiagnosticDefinitionFixWithPositionAndCode> = []\n const executor = yield* createDiagnosticExecutor(sourceFile)\n for (const rule of rules) {\n const { codeFixes, diagnostics } = yield* (executor.execute(rule))\n effectDiagnostics = effectDiagnostics.concat(diagnostics)\n effectCodeFixes = effectCodeFixes.concat(codeFixes)\n }\n\n return ({\n diagnostics: effectDiagnostics,\n codeFixes: effectCodeFixes\n })\n})\n\nfunction refactorNameToFullyQualifiedName(name: string) {\n return `@effect/language-service/refactors/${name}`\n}\n\nexport const getApplicableRefactors = Nano.fn(\"LSP.getApplicableRefactors\")(function*(\n refactors: Array<RefactorDefinition>,\n sourceFile: ts.SourceFile,\n positionOrRange: number | ts.TextRange\n) {\n const textRange = typeof positionOrRange === \"number\"\n ? { pos: positionOrRange, end: positionOrRange }\n : positionOrRange\n const effectRefactors: Array<ts.ApplicableRefactorInfo> = []\n for (const refactor of refactors) {\n const result = yield* Nano.option(refactor.apply(sourceFile, textRange))\n if (Option.isSome(result)) {\n effectRefactors.push({\n name: refactorNameToFullyQualifiedName(refactor.name),\n description: refactor.description,\n actions: [{\n name: refactorNameToFullyQualifiedName(refactor.name),\n description: result.value.description,\n kind: result.value.kind\n }]\n })\n }\n }\n return effectRefactors\n})\n\nexport const getEditsForRefactor = Nano.fn(\"LSP.getEditsForRefactor\")(function*(\n refactors: Array<RefactorDefinition>,\n sourceFile: ts.SourceFile,\n positionOrRange: number | ts.TextRange,\n refactorName: string\n) {\n const refactor = refactors.find((refactor) => refactorNameToFullyQualifiedName(refactor.name) === refactorName)\n if (!refactor) {\n return yield* Nano.fail(new RefactorNotApplicableError())\n }\n const textRange = typeof positionOrRange === \"number\"\n ? { pos: positionOrRange, end: positionOrRange }\n : positionOrRange\n\n return yield* refactor.apply(sourceFile, textRange)\n})\n\nexport const getCompletionsAtPosition = Nano.fn(\"LSP.getCompletionsAtPosition\")(function*(\n completions: Array<CompletionDefinition>,\n sourceFile: ts.SourceFile,\n position: number,\n options: ts.GetCompletionsAtPositionOptions | undefined,\n formatCodeSettings: ts.FormatCodeSettings | undefined\n) {\n let effectCompletions: Array<ts.CompletionEntry> = []\n for (const completion of completions) {\n const result = yield* completion.apply(sourceFile, position, options, formatCodeSettings)\n effectCompletions = effectCompletions.concat(\n result.map((_) => ({ sortText: \"11\", ..._ }) satisfies ts.CompletionEntry)\n )\n }\n return effectCompletions\n})\n\nconst createDiagnosticExecutor = Nano.fn(\"LSP.createCommentDirectivesProcessor\")(\n function*(sourceFile: ts.SourceFile) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const tsUtils = yield* Nano.service(TypeScriptUtils.TypeScriptUtils)\n const pluginOptions = yield* Nano.service(LanguageServicePluginOptions.LanguageServicePluginOptions)\n\n function findParentStatementForDisableNextLine(node: ts.Node) {\n let result: ts.Node | undefined\n\n function find(node: ts.Node) {\n if (ts.isStatement(node)) {\n result = node\n return\n }\n if (result) return\n if (node.parent) find(node.parent)\n }\n find(node)\n return result || node\n }\n\n const lineOverrides: Record<\n string,\n Array<{ pos: number; end: number; level: string }>\n > = {}\n const sectionOverrides: Record<\n string,\n Array<{ pos: number; level: string }>\n > = {}\n const skippedRules: Array<string> = []\n\n const regex =\n /@effect-diagnostics(-next-line)?((?:\\s[a-zA-Z0-9/]+:(?:off|warning|error|message|suggestion|skip-file))+)?/gm\n let match: RegExpExecArray | null\n while ((match = regex.exec(sourceFile.text)) !== null) {\n const nextLineCaptureGroup = match[1]\n const rulesCaptureGroup = match[2]\n\n if (rulesCaptureGroup) {\n const trimmedRuleString = rulesCaptureGroup.trim()\n if (trimmedRuleString) {\n const individualRules = trimmedRuleString.split(/\\s+/)\n for (const rulePair of individualRules) {\n const [rawRuleName, ruleLevel] = rulePair.toLowerCase().split(\":\")\n // NOTE: for backwards compatibility, treat \"effect/ruleName\" same as \"ruleName\"\n const ruleName = rawRuleName.startsWith(\"effect/\")\n ? rawRuleName.substring(\"effect/\".length)\n : rawRuleName\n if (ruleName && ruleLevel) {\n if (ruleLevel === \"skip-file\") skippedRules.push(ruleName)\n const isOverrideNextLine = nextLineCaptureGroup &&\n nextLineCaptureGroup.trim().toLowerCase() === \"-next-line\"\n if (isOverrideNextLine) {\n const foundNode = tsUtils.findNodeWithLeadingCommentAtPosition(sourceFile, match.index)\n if (foundNode) {\n lineOverrides[ruleName] = lineOverrides[ruleName] || []\n lineOverrides[ruleName].unshift({\n pos: foundNode.node.getFullStart(),\n end: foundNode.node.end,\n level: ruleLevel\n })\n }\n } else {\n sectionOverrides[ruleName] = sectionOverrides[ruleName] || []\n sectionOverrides[ruleName].unshift({\n pos: match.index,\n level: ruleLevel\n })\n }\n }\n }\n }\n }\n }\n\n const levelToDiagnosticCategory: Record<string, ts.DiagnosticCategory> = {\n error: ts.DiagnosticCategory.Error,\n warning: ts.DiagnosticCategory.Warning,\n message: ts.DiagnosticCategory.Message,\n suggestion: ts.DiagnosticCategory.Suggestion\n }\n\n const execute = (\n rule: DiagnosticDefinition\n ) =>\n Nano.gen(function*() {\n const diagnostics: Array<ts.Diagnostic> = []\n const codeFixes: Array<ApplicableDiagnosticDefinitionFixWithPositionAndCode> = []\n const ruleNameLowered = rule.name.toLowerCase()\n const defaultLevel = pluginOptions.diagnosticSeverity[ruleNameLowered] || rule.severity\n // if file is skipped entirely, do not process the rule\n if (skippedRules.indexOf(ruleNameLowered) > -1) return { diagnostics, codeFixes }\n // if the default level is off, and there are no overrides, do not process the rule\n if (\n defaultLevel === \"off\" &&\n ((lineOverrides[ruleNameLowered] || sectionOverrides[ruleNameLowered] || []).length === 0)\n ) {\n return { diagnostics, codeFixes }\n }\n // append a rule fix to disable this check only for next line\n const fixByDisableNextLine = (\n node: ts.Node\n ): ApplicableDiagnosticDefinitionFix => ({\n fixName: rule.name + \"_skipNextLine\",\n description: \"Disable \" + rule.name + \" for this line\",\n apply: Nano.flatMap(\n Nano.service(TypeScriptApi.ChangeTracker),\n (changeTracker) =>\n Nano.gen(function*() {\n const disableAtNode = findParentStatementForDisableNextLine(node)\n const { line } = ts.getLineAndCharacterOfPosition(sourceFile, disableAtNode.getStart())\n\n changeTracker.insertCommentBeforeLine(\n sourceFile,\n line,\n disableAtNode.getStart(),\n ` @effect-diagnostics-next-line ${rule.name}:off`\n )\n })\n )\n })\n\n // append a rule fix to disable this check for the entire file\n const fixByDisableEntireFile: ApplicableDiagnosticDefinitionFix = {\n fixName: rule.name + \"_skipFile\",\n description: \"Disable \" + rule.name + \" for this entire file\",\n apply: Nano.flatMap(\n Nano.service(TypeScriptApi.ChangeTracker),\n (changeTracker) =>\n Nano.sync(() =>\n changeTracker.insertText(\n sourceFile,\n 0,\n `/** @effect-diagnostics ${rule.name}:skip-file */\\n`\n )\n )\n )\n }\n // run the executor\n const applicableDiagnostics: Array<ApplicableDiagnosticDefinition> = []\n yield* rule.apply(sourceFile, (entry) => {\n const range = \"getEnd\" in entry.location\n ? { pos: entry.location.getStart(sourceFile), end: entry.location.getEnd() }\n : entry.location\n const node = \"getEnd\" in entry.location\n ? entry.location\n : tsUtils.findNodeAtPositionIncludingTrivia(sourceFile, entry.location.pos)\n applicableDiagnostics.push({\n range,\n messageText: entry.messageText,\n fixes: entry.fixes.concat(node ? [fixByDisableNextLine(node)] : []).concat([fixByDisableEntireFile])\n })\n })\n\n // loop through rules\n for (const emitted of applicableDiagnostics.slice(0)) {\n // by default, use the overriden level from the plugin options\n let newLevel: string | undefined = defaultLevel\n // attempt with line overrides\n const lineOverride = (lineOverrides[ruleNameLowered] || []).find((_) =>\n _.pos < emitted.range.pos && _.end >= emitted.range.end\n )\n if (lineOverride) {\n newLevel = lineOverride.level\n } else {\n // then attempt with section overrides\n const sectionOverride = (sectionOverrides[ruleNameLowered] || []).find((_) => _.pos < emitted.range.pos)\n if (sectionOverride) newLevel = sectionOverride.level\n }\n // if level is off or not a valid level, skip and no output\n if (!(newLevel in levelToDiagnosticCategory)) continue\n // append both diagnostic and code fix\n diagnostics.push({\n file: sourceFile,\n start: emitted.range.pos,\n length: emitted.range.end - emitted.range.pos,\n messageText: emitted.messageText,\n category: levelToDiagnosticCategory[newLevel],\n code: rule.code,\n source: \"effect\"\n })\n // append code fixes\n for (const fix of emitted.fixes) {\n codeFixes.push({\n ...fix,\n code: rule.code,\n start: emitted.range.pos,\n end: emitted.range.end\n })\n }\n }\n\n return { diagnostics, codeFixes }\n })\n\n return { execute }\n }\n)\n\nexport const cyrb53 = (str: string, seed = 0) => {\n let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed\n for (let i = 0, ch; i < str.length; i++) {\n ch = str.charCodeAt(i)\n h1 = Math.imul(h1 ^ ch, 2654435761)\n h2 = Math.imul(h2 ^ ch, 1597334677)\n }\n h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507)\n h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909)\n h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507)\n h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909)\n\n // return 4294967296 * (2097151 & h2) + (h1 >>> 0)\n return (h2 >>> 0).toString(16).padStart(8, \"0\") + (h1 >>> 0).toString(16).padStart(8, \"0\")\n}\n\nexport class CodegenNotApplicableError {\n readonly _tag = \"@effect/language-service/CodegenNotApplicableError\"\n constructor(\n readonly cause: string\n ) {}\n}\n\nexport interface CodegenDefinition {\n name: string\n apply: (\n sourceFile: ts.SourceFile,\n commentRange: ts.TextRange\n ) => Nano.Nano<\n ApplicableCodegenDefinition,\n CodegenNotApplicableError,\n | TypeScriptApi.TypeScriptApi\n | TypeScriptUtils.TypeScriptUtils\n | TypeCheckerApi.TypeCheckerApi\n | TypeParser.TypeParser\n | LanguageServicePluginOptions.LanguageServicePluginOptions\n >\n}\n\nexport interface ApplicableCodegenDefinition {\n hash: string\n description: string\n apply: Nano.Nano<void, never, ts.textChanges.ChangeTracker>\n}\n\nexport function createCodegen(definition: CodegenDefinition): CodegenDefinition {\n return definition\n}\n\nexport const getCodegensForSourceFile = Nano.fn(\"LSP.getApplicableCodegens\")(function*(\n codegens: Array<CodegenDefinition>,\n sourceFile: ts.SourceFile\n) {\n const tsUtils = yield* Nano.service(TypeScriptUtils.TypeScriptUtils)\n const result: Array<{ codegen: CodegenDefinition; hash: string; range: ts.TextRange }> = []\n\n const regex = /@effect-codegens((?:\\s[a-zA-Z0-9]+(?::(?:[a-zA-Z0-9]+))?)+)+/gmid\n let match: RegExpExecArray | null\n while ((match = regex.exec(sourceFile.text)) !== null) {\n const pos = match.indices?.[0]?.[0]\n if (!pos) continue\n const commentRange = tsUtils.getCommentAtPosition(sourceFile, pos)\n if (!commentRange) continue\n const commentText = sourceFile.text.slice(pos, commentRange.end)\n const codegenRegex = /(\\s+)(\\w+)(?::(\\w+))?/gmi\n let codegenMatch: RegExpExecArray | null\n while ((codegenMatch = codegenRegex.exec(commentText)) !== null) {\n const whitespace = codegenMatch[1] || \"\"\n const codegenName = codegenMatch[2] || \"\"\n const codegenHash = codegenMatch[3] || \"\"\n const range: ts.TextRange = {\n pos: codegenMatch.index + pos + whitespace.length,\n end: codegenMatch.index + pos + codegenMatch[0].length\n }\n const codegen = codegens.find((codegen) => codegen.name === codegenName)\n if (!codegen) continue\n result.push({ codegen, hash: codegenHash, range })\n }\n }\n return result\n})\n\nexport const getEditsForCodegen = Nano.fn(\"LSP.getEditsForCodegen\")(function*(\n codegens: Array<CodegenDefinition>,\n sourceFile: ts.SourceFile,\n textRange: ts.TextRange\n) {\n const applicableCodegens = yield* getCodegensForSourceFile(codegens, sourceFile)\n const inRangeCodegens = applicableCodegens.filter((codegen) =>\n codegen.range.pos <= textRange.pos && codegen.range.end >= textRange.end\n )\n if (inRangeCodegens.length !== 1) {\n return yield* Nano.fail(new CodegenNotApplicableError(\"zero or multiple codegens in range\"))\n }\n const { codegen, range } = inRangeCodegens[0]\n const edit = yield* codegen.apply(sourceFile, range)\n const updateHashComment = pipe(\n Nano.service(TypeScriptApi.ChangeTracker),\n Nano.map((changeTracker) => {\n changeTracker.deleteRange(sourceFile, range)\n changeTracker.insertText(sourceFile, range.pos, `${codegen.name}:${edit.hash}`)\n })\n )\n return {\n ...edit,\n apply: pipe(\n edit.apply,\n Nano.flatMap(() => updateHashComment)\n ),\n ignore: updateHashComment\n } satisfies ApplicableCodegenDefinition & { ignore: Nano.Nano<void, never, ts.textChanges.ChangeTracker> }\n})\n","import * as Array from \"effect/Array\"\nimport { isFunction, pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as Order from \"effect/Order\"\nimport { hasProperty } from \"effect/Predicate\"\nimport type ts from \"typescript\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeScriptApi from \"./TypeScriptApi.js\"\n\nexport interface TypeCheckerApi extends ts.TypeChecker {}\nexport const TypeCheckerApi = Nano.Tag<TypeCheckerApi>(\"TypeChecker\")\n\nexport const deterministicTypeOrder = Nano.gen(function*() {\n const typeChecker = yield* Nano.service(TypeCheckerApi)\n return Order.make((a: ts.Type, b: ts.Type) => {\n const aName = typeChecker.typeToString(a)\n const bName = typeChecker.typeToString(b)\n if (aName < bName) return -1\n if (aName > bName) return 1\n return 0\n })\n})\n\nexport const getMissingTypeEntriesInTargetType = Nano.fn(\n \"TypeCheckerApi.getMissingTypeEntriesInTargetType\"\n)(\n function*(realType: ts.Type, expectedType: ts.Type) {\n if (realType === expectedType) return []\n const typeChecker = yield* Nano.service(TypeCheckerApi)\n\n const result: Array<ts.Type> = []\n let toTest: Array<ts.Type> = [realType]\n while (toTest.length > 0) {\n const type = toTest.pop()\n if (!type) return result\n if (type.isUnion()) {\n toTest = toTest.concat(type.types)\n } else {\n const assignable = typeChecker.isTypeAssignableTo(type, expectedType)\n if (!assignable) {\n result.push(type)\n }\n }\n }\n return result\n }\n)\n\ntype ConvertibleDeclaration =\n | ts.FunctionDeclaration\n | ts.FunctionExpression\n | ts.ArrowFunction\n | ts.MethodDeclaration\n\nclass CannotFindAncestorConvertibleDeclarationError {\n readonly _tag = \"@effect/language-service/CannotFindAncestorConvertibleDeclarationError\"\n constructor(\n readonly node: ts.Node\n ) {}\n}\n\nconst getAncestorConvertibleDeclaration = Nano.fn(\n \"TypeCheckerApi.getAncestorConvertibleDeclaration\"\n)(function*(node: ts.Node) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n let current: ts.Node | undefined = node\n while (current) {\n if (\n ts.isFunctionDeclaration(current) ||\n ts.isFunctionExpression(current) ||\n ts.isArrowFunction(current) ||\n ts.isMethodDeclaration(current)\n ) {\n return current\n }\n current = current.parent\n }\n return yield* Nano.fail(new CannotFindAncestorConvertibleDeclarationError(node))\n})\n\nclass CannotInferReturnTypeFromEmptyBody {\n readonly _tag = \"@effect/language-service/CannotInferReturnTypeFromEmptyBody\"\n constructor(\n readonly declaration: ConvertibleDeclaration\n ) {}\n}\n\nclass CannotInferReturnType {\n readonly _tag = \"@effect/language-service/CannotInferReturnType\"\n constructor(\n readonly declaration: ConvertibleDeclaration\n ) {}\n}\n\nexport const getInferredReturnType = Nano.fn(\"TypeCheckerApi.getInferredReturnType\")(function*(\n declaration: ConvertibleDeclaration\n) {\n const typeChecker = yield* Nano.service(TypeCheckerApi)\n\n if (!declaration.body) {\n return yield* Nano.fail(\n new CannotInferReturnTypeFromEmptyBody(declaration)\n )\n }\n\n let returnType: ts.Type | undefined\n\n if (typeChecker.isImplementationOfOverload(declaration)) {\n const signatures = typeChecker.getTypeAtLocation(declaration).getCallSignatures()\n if (signatures.length > 1) {\n returnType = typeChecker.getUnionType(\n signatures.map((s) => s.getReturnType()).filter((_) => !!_)\n )\n }\n }\n if (!returnType) {\n const signature = typeChecker.getSignatureFromDeclaration(declaration)\n if (signature) {\n const typePredicate = typeChecker.getTypePredicateOfSignature(signature)\n if (typePredicate && typePredicate.type) {\n return typePredicate.type\n } else {\n returnType = typeChecker.getReturnTypeOfSignature(signature)\n }\n }\n }\n\n if (!returnType) {\n return yield* Nano.fail(\n new CannotInferReturnType(declaration)\n )\n }\n\n return returnType\n})\n\ntype ExpectedAndRealType = [\n node: ts.Node,\n expectedType: ts.Type,\n valueNode: ts.Node,\n realType: ts.Type\n]\n\nexport const expectedAndRealType = Nano.cachedBy(\n Nano.fn(\"TypeCheckerApi.expectedAndRealType\")(function*(\n sourceFile: ts.SourceFile\n ) {\n const typeChecker = yield* Nano.service(TypeCheckerApi)\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const result: Array<ExpectedAndRealType> = []\n\n const nodeToVisit: Array<ts.Node> = [sourceFile]\n const appendNodeToVisit = (node: ts.Node) => {\n nodeToVisit.push(node)\n return undefined\n }\n\n while (nodeToVisit.length > 0) {\n const node = nodeToVisit.shift()!\n\n if (ts.isVariableDeclaration(node) && node.initializer) {\n // const a: Effect<...> = node\n const expectedType = typeChecker.getTypeAtLocation(node.name)\n const realType = typeChecker.getTypeAtLocation(node.initializer)\n result.push([node.name, expectedType, node.initializer, realType])\n appendNodeToVisit(node.initializer)\n continue\n } else if (ts.isCallExpression(node)) {\n // fn(a)\n const resolvedSignature = typeChecker.getResolvedSignature(node)\n if (resolvedSignature) {\n resolvedSignature.getParameters().map((parameter, index) => {\n const expectedType = typeChecker.getTypeOfSymbolAtLocation(parameter, node)\n const realType = typeChecker.getTypeAtLocation(node.arguments[index])\n result.push([\n node.arguments[index] as ts.Node,\n expectedType,\n node.arguments[index],\n realType\n ])\n })\n }\n ts.forEachChild(node, appendNodeToVisit)\n continue\n } else if (\n ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node) ||\n ts.isNoSubstitutionTemplateLiteral(node)\n ) {\n // { key: node } as { key: Effect<...> }\n const parent = node.parent\n if (ts.isObjectLiteralElement(parent)) {\n if (ts.isObjectLiteralExpression(parent.parent) && parent.name === node) {\n const type = typeChecker.getContextualType(parent.parent)\n if (type) {\n const symbol = typeChecker.getPropertyOfType(type, node.text)\n if (symbol) {\n const expectedType = typeChecker.getTypeOfSymbolAtLocation(symbol, node)\n const realType = typeChecker.getTypeAtLocation(node)\n result.push([node, expectedType, node, realType])\n }\n }\n }\n }\n ts.forEachChild(node, appendNodeToVisit)\n continue\n } else if (\n ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken\n ) {\n // var a: Effect<...> = node\n const expectedType = typeChecker.getTypeAtLocation(node.left)\n const realType = typeChecker.getTypeAtLocation(node.right)\n result.push([node.left, expectedType, node.right, realType])\n appendNodeToVisit(node.right)\n continue\n } else if (ts.isReturnStatement(node) && node.expression) {\n // function(): Effect<...> { return a }\n const parentDeclaration = yield* Nano.option(getAncestorConvertibleDeclaration(node))\n if (Option.isSome(parentDeclaration)) {\n const expectedType = yield* Nano.option(getInferredReturnType(parentDeclaration.value))\n const realType = typeChecker.getTypeAtLocation(node.expression)\n if (Option.isSome(expectedType)) {\n result.push([node, expectedType.value, node, realType])\n }\n }\n ts.forEachChild(node, appendNodeToVisit)\n continue\n } else if (\n ts.isArrowFunction(node) && (node.typeParameters || []).length === 0 &&\n ts.isExpression(node.body)\n ) {\n // (): Effect<...> => node\n const body = node.body\n const expectedType = typeChecker.getContextualType(body)\n const realType = typeChecker.getTypeAtLocation(body)\n if (expectedType) {\n result.push([body, expectedType, body, realType])\n }\n ts.forEachChild(body, appendNodeToVisit)\n continue\n } else if (\n ts.isArrowFunction(node) && (node.typeParameters || []).length > 0 &&\n ts.isExpression(node.body)\n ) {\n // <A>(): Effect<...> => node\n const body = node.body\n const expectedType = yield* Nano.option(getInferredReturnType(node))\n const realType = typeChecker.getTypeAtLocation(body)\n if (Option.isSome(expectedType)) {\n result.push([body, expectedType.value, body, realType])\n }\n ts.forEachChild(body, appendNodeToVisit)\n continue\n } else if (ts.isSatisfiesExpression(node)) {\n // node as Effect<....>\n const expectedType = typeChecker.getTypeAtLocation(node.type)\n const realType = typeChecker.getTypeAtLocation(node.expression)\n result.push([node.expression as ts.Node, expectedType, node.expression, realType])\n appendNodeToVisit(node.expression)\n continue\n }\n\n // no previous case has been hit, continue with childs\n ts.forEachChild(node, appendNodeToVisit)\n }\n return result\n }),\n \"TypeCheckerApi.expectedAndRealType\",\n (sourceFile) => sourceFile\n)\n\nexport const unrollUnionMembers = (type: ts.Type) => {\n const result: Array<ts.Type> = []\n let toTest: Array<ts.Type> = [type]\n while (toTest.length > 0) {\n const type = toTest.pop()!\n if (type.isUnion()) {\n toTest = toTest.concat(type.types)\n } else {\n result.push(type)\n }\n }\n return result\n}\n\n/**\n * Appends a type to a map of unique types, ensuring that the type is not already in the map.\n *\n * @param memory - The map that will be used as memory and updated as new types are encountered.\n * @param initialType - The type to start with, unions will be unrolled.\n * @param shouldExclude - A function that determines if a type should be excluded from the checking\n * @returns An object with the following properties:\n * - newIndexes: A set of new indexes that were added to the memory.\n * - knownIndexes: A set of indexes that were already in the memory.\n * - allIndexes: A set of all indexes that were encountered.\n */\nexport const appendToUniqueTypesMap = Nano.fn(\n \"TypeCheckerApi.appendToUniqueTypesMap\"\n)(\n function*(memory: Map<string, ts.Type>, initialType: ts.Type, shouldExclude: (type: ts.Type) => Nano.Nano<boolean>) {\n const typeChecker = yield* Nano.service(TypeCheckerApi)\n\n const newIndexes: Set<string> = new Set()\n const knownIndexes: Set<string> = new Set()\n let toTest: Array<ts.Type> = [initialType]\n while (toTest.length > 0) {\n const type = toTest.pop()\n if (!type) break\n if (yield* shouldExclude(type)) {\n continue\n }\n if (type.isUnion()) {\n toTest = toTest.concat(type.types)\n } else {\n const foundMatch: Array<string> = []\n for (const [typeId, knownType] of memory.entries()) {\n const areSame = typeChecker.isTypeAssignableTo(knownType, type) &&\n typeChecker.isTypeAssignableTo(type, knownType)\n if (areSame) {\n foundMatch.push(typeId)\n break\n }\n }\n if (foundMatch.length === 0) {\n const newId = \"t\" + (memory.size + 1)\n memory.set(newId, type)\n newIndexes.add(newId)\n } else {\n knownIndexes.add(foundMatch[0])\n }\n }\n }\n return {\n newIndexes,\n knownIndexes,\n allIndexes: pipe(\n Array.fromIterable(newIndexes),\n Array.appendAll(Array.fromIterable(knownIndexes))\n )\n }\n }\n)\n\nexport function makeResolveExternalModuleName(typeChecker: TypeCheckerApi) {\n if (!(hasProperty(typeChecker, \"resolveExternalModuleName\") && isFunction(typeChecker.resolveExternalModuleName))) {\n return\n }\n const _internal = typeChecker.resolveExternalModuleName\n return (moduleSpecifier: ts.Expression): ts.Symbol | undefined => {\n return _internal(moduleSpecifier)\n }\n}\n","import { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as Nano from \"./Nano.js\"\nimport * as TypeCheckerApi from \"./TypeCheckerApi.js\"\nimport * as TypeScriptApi from \"./TypeScriptApi.js\"\nimport * as TypeScriptUtils from \"./TypeScriptUtils.js\"\n\nexport interface TypeParser {\n effectType: (\n type: ts.Type,\n atLocation: ts.Node\n ) => Nano.Nano<{ A: ts.Type; E: ts.Type; R: ts.Type }, TypeParserIssue>\n strictEffectType: (\n type: ts.Type,\n atLocation: ts.Node\n ) => Nano.Nano<{ A: ts.Type; E: ts.Type; R: ts.Type }, TypeParserIssue>\n layerType: (\n type: ts.Type,\n atLocation: ts.Node\n ) => Nano.Nano<{ ROut: ts.Type; E: ts.Type; RIn: ts.Type }, TypeParserIssue>\n fiberType: (\n type: ts.Type,\n atLocation: ts.Node\n ) => Nano.Nano<{ A: ts.Type; E: ts.Type; R: ts.Type }, TypeParserIssue>\n effectSubtype: (\n type: ts.Type,\n atLocation: ts.Node\n ) => Nano.Nano<{ A: ts.Type; E: ts.Type; R: ts.Type }, TypeParserIssue>\n importedEffectModule: (\n node: ts.Node\n ) => Nano.Nano<ts.Node, TypeParserIssue>\n effectGen: (\n node: ts.Node\n ) => Nano.Nano<\n {\n node: ts.Node\n effectModule: ts.Expression\n generatorFunction: ts.FunctionExpression\n body: ts.Block\n functionStar: ts.Node | undefined\n },\n TypeParserIssue\n >\n effectFnUntracedGen: (\n node: ts.Node\n ) => Nano.Nano<\n {\n node: ts.Node\n effectModule: ts.Node\n generatorFunction: ts.Node\n body: ts.Block\n functionStar: ts.Node | undefined\n },\n TypeParserIssue\n >\n effectFnGen: (\n node: ts.Node\n ) => Nano.Nano<\n {\n node: ts.Node\n generatorFunction: ts.Node\n effectModule: ts.Node\n body: ts.Block\n functionStar: ts.Node | undefined\n },\n TypeParserIssue\n >\n unnecessaryEffectGen: (\n node: ts.Node\n ) => Nano.Nano<\n { node: ts.Node; body: ts.Block; yieldedExpression: ts.Node; replacementNode: Nano.Nano<ts.Node, never, never> },\n TypeParserIssue\n >\n effectSchemaType: (\n type: ts.Type,\n atLocation: ts.Node\n ) => Nano.Nano<{ A: ts.Type; I: ts.Type; R: ts.Type }, TypeParserIssue>\n contextTag: (\n type: ts.Type,\n atLocation: ts.Node\n ) => Nano.Nano<{ Identifier: ts.Type; Service: ts.Type }, TypeParserIssue>\n pipeableType: (type: ts.Type, atLocation: ts.Node) => Nano.Nano<ts.Type, TypeParserIssue, never>\n pipeCall: (\n node: ts.Node\n ) => Nano.Nano<\n { node: ts.CallExpression; subject: ts.Expression; args: Array<ts.Expression>; kind: \"pipe\" | \"pipeable\" },\n TypeParserIssue,\n never\n >\n scopeType: (\n type: ts.Type,\n atLocation: ts.Node\n ) => Nano.Nano<ts.Type, TypeParserIssue>\n promiseLike: (\n type: ts.Type,\n atLocation: ts.Node\n ) => Nano.Nano<{ type: ts.Type }, TypeParserIssue>\n extendsEffectService: (atLocation: ts.ClassDeclaration) => Nano.Nano<\n {\n className: ts.Identifier\n selfTypeNode: ts.TypeNode\n args: ts.NodeArray<ts.Expression>\n Identifier: ts.Type\n Service: ts.Type\n accessors: boolean | undefined\n dependencies: ts.NodeArray<ts.Expression> | undefined\n options: ts.Expression\n },\n TypeParserIssue,\n never\n >\n extendsContextTag: (atLocation: ts.ClassDeclaration) => Nano.Nano<\n {\n className: ts.Identifier\n selfTypeNode: ts.TypeNode\n args: ts.NodeArray<ts.Expression>\n Identifier: ts.Type\n Tag: ts.Node\n },\n TypeParserIssue,\n never\n >\n extendsSchemaClass: (atLocation: ts.ClassDeclaration) => Nano.Nano<\n {\n className: ts.Identifier\n selfTypeNode: ts.TypeNode\n Schema: ts.Node\n },\n TypeParserIssue,\n never\n >\n extendsSchemaTaggedClass: (atLocation: ts.ClassDeclaration) => Nano.Nano<\n {\n className: ts.Identifier\n selfTypeNode: ts.TypeNode\n Schema: ts.Node\n },\n TypeParserIssue,\n never\n >\n extendsSchemaTaggedError: (atLocation: ts.ClassDeclaration) => Nano.Nano<\n {\n className: ts.Identifier\n selfTypeNode: ts.TypeNode\n Schema: ts.Node\n },\n TypeParserIssue,\n never\n >\n extendsSchemaTaggedRequest: (atLocation: ts.ClassDeclaration) => Nano.Nano<\n {\n className: ts.Identifier\n selfTypeNode: ts.TypeNode\n Schema: ts.Node\n },\n TypeParserIssue,\n never\n >\n}\nexport const TypeParser = Nano.Tag<TypeParser>(\"@effect/language-service/TypeParser\")\n\nexport const nanoLayer = <A, E, R>(\n fa: Nano.Nano<A, E, R>\n) =>\n Nano.gen(function*() {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const tsUtils = yield* Nano.service(TypeScriptUtils.TypeScriptUtils)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n\n return yield* pipe(\n fa,\n Nano.provideService(TypeParser, make(ts, tsUtils, typeChecker))\n )\n })\n\nexport class TypeParserIssue {\n readonly _tag = \"@effect/language-service/TypeParserIssue\"\n static issue = Nano.fail(new TypeParserIssue())\n}\n\nexport function typeParserIssue(\n _message: string,\n _type?: ts.Type | undefined,\n _node?: ts.Node | undefined\n): Nano.Nano<never, TypeParserIssue, never> {\n return TypeParserIssue.issue\n}\n\nexport function make(\n ts: TypeScriptApi.TypeScriptApi,\n tsUtils: TypeScriptUtils.TypeScriptUtils,\n typeChecker: TypeCheckerApi.TypeCheckerApi\n): TypeParser {\n 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\n function contravariantTypeArgument(type: ts.Type): Nano.Nano<ts.Type, TypeParserIssue> {\n const signatures = type.getCallSignatures()\n // Contravariant<A> has only 1 type signature\n if (signatures.length !== 1) {\n return typeParserIssue(\"Contravariant type has no call signature\", type)\n }\n // get the return type\n return Nano.succeed(signatures[0].getTypeParameterAtPosition(0))\n }\n\n 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\n const pipeableType = Nano.cachedBy(\n function(\n type: ts.Type,\n atLocation: ts.Node\n ) {\n // Pipeable has a pipe property on the type\n const pipeSymbol = typeChecker.getPropertyOfType(type, \"pipe\")\n if (!pipeSymbol) {\n return 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 typeParserIssue(\"'pipe' property is not callable\", type, atLocation)\n }\n return Nano.succeed(type)\n },\n \"TypeParser.pipeableType\",\n (type) => type\n )\n\n const varianceStructCovariantType = <A extends string>(\n type: ts.Type,\n atLocation: ts.Node,\n propertyName: A\n ) => {\n const propertySymbol = typeChecker.getPropertyOfType(type, propertyName)\n if (!propertySymbol) {\n return typeParserIssue(`Type has no '${propertyName}' property`, type, atLocation)\n }\n const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation)\n return covariantTypeArgument(propertyType)\n }\n\n const varianceStructContravariantType = <A extends string>(\n type: ts.Type,\n atLocation: ts.Node,\n propertyName: A\n ) => {\n const propertySymbol = typeChecker.getPropertyOfType(type, propertyName)\n if (!propertySymbol) {\n return typeParserIssue(`Type has no '${propertyName}' property`, type, atLocation)\n }\n const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation)\n return contravariantTypeArgument(propertyType)\n }\n\n const varianceStructInvariantType = <A extends string>(\n type: ts.Type,\n atLocation: ts.Node,\n propertyName: A\n ) => {\n const propertySymbol = typeChecker.getPropertyOfType(type, propertyName)\n if (!propertySymbol) {\n return typeParserIssue(`Type has no '${propertyName}' property`, type, atLocation)\n }\n const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation)\n return invariantTypeArgument(propertyType)\n }\n\n const effectVarianceStruct = (\n type: ts.Type,\n atLocation: ts.Node\n ) =>\n Nano.map(\n Nano.all(\n varianceStructCovariantType(type, atLocation, \"_A\"),\n varianceStructCovariantType(type, atLocation, \"_E\"),\n varianceStructCovariantType(type, atLocation, \"_R\")\n ),\n ([A, E, R]) => ({ A, E, R })\n )\n\n const layerVarianceStruct = (\n type: ts.Type,\n atLocation: ts.Node\n ) =>\n Nano.map(\n Nano.all(\n varianceStructContravariantType(type, atLocation, \"_ROut\"),\n varianceStructCovariantType(type, atLocation, \"_E\"),\n varianceStructCovariantType(type, atLocation, \"_RIn\")\n ),\n ([ROut, E, RIn]) => ({ ROut, E, RIn })\n )\n\n const effectType = Nano.cachedBy(\n Nano.fn(\"TypeParser.effectType\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n ) {\n let result: Nano.Nano<\n {\n A: ts.Type\n E: ts.Type\n R: ts.Type\n },\n TypeParserIssue,\n never\n > = typeParserIssue(\"Type has no effect variance struct\", 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) && _.valueDeclaration &&\n ts.isPropertySignature(_.valueDeclaration) && ts.isComputedPropertyName(_.valueDeclaration.name)\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 result = pipe(result, Nano.orElse(() => effectVarianceStruct(propertyType, atLocation)))\n }\n return yield* result\n }),\n \"TypeParser.effectType\",\n (type) => type\n )\n\n const strictEffectType = Nano.cachedBy(\n Nano.fn(\"TypeParser.strictEffectType\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n ) {\n // symbol name should be Effect\n if (!(type.symbol && type.symbol.name === \"Effect\" && !type.aliasSymbol)) {\n return yield* typeParserIssue(\"Type name should be Effect with no alias symbol\", type, atLocation)\n }\n // should be an effect\n return yield* effectType(type, atLocation)\n }),\n \"TypeParser.strictEffectType\",\n (type) => type\n )\n\n const layerType = Nano.cachedBy(\n Nano.fn(\"TypeParser.layerType\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n ) {\n // should be pipeable\n yield* pipeableType(type, atLocation)\n\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) && _.valueDeclaration &&\n ts.isPropertySignature(_.valueDeclaration) && ts.isComputedPropertyName(_.valueDeclaration.name)\n )\n // try to put typeid first (heuristic to optimize hot path)\n propertiesSymbols.sort((a, b) => b.name.indexOf(\"LayerTypeId\") - a.name.indexOf(\"LayerTypeId\"))\n // has a property symbol which is a layer variance struct\n for (const propertySymbol of propertiesSymbols) {\n const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation)\n const varianceArgs = yield* Nano.option(layerVarianceStruct(\n propertyType,\n atLocation\n ))\n if (Option.isSome(varianceArgs)) {\n return varianceArgs.value\n }\n }\n return yield* typeParserIssue(\"Type has no layer variance struct\", type, atLocation)\n }),\n \"TypeParser.layerType\",\n (type) => type\n )\n\n const fiberType = Nano.cachedBy(\n Nano.fn(\"TypeParser.fiberType\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n ) {\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 \"TypeParser.fiberType\",\n (type) => type\n )\n\n const effectSubtype = Nano.cachedBy(\n Nano.fn(\"TypeParser.effectSubtype\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n ) {\n // there is no better way to check if a type is a subtype of effect\n // so we just check for the existence of the property \"_tag\"\n // which is common for Option, Either, and others\n // and other datatypes as \"Pool\" have \"get\"\n const tagSymbol = typeChecker.getPropertyOfType(type, \"_tag\")\n const getSymbol = typeChecker.getPropertyOfType(type, \"get\")\n if (!(tagSymbol || getSymbol)) {\n return yield* typeParserIssue(\n \"Type is not a subtype of effect because it does not have '_tag' or 'get' property\",\n type,\n atLocation\n )\n }\n // and it is also an effect itself\n return yield* effectType(type, atLocation)\n }),\n \"TypeParser.effectSubtype\",\n (type) => type\n )\n\n const importedSchemaModule = Nano.cachedBy(\n Nano.fn(\"TypeParser.importedSchemaModule\")(function*(\n node: ts.Node\n ) {\n const type = typeChecker.getTypeAtLocation(node)\n // if the type has a property \"Class\" that is a function\n const propertySymbol = typeChecker.getPropertyOfType(type, \"Class\")\n if (!propertySymbol) {\n return yield* typeParserIssue(\"Type has no 'Class' 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 // return the node itself\n return node\n }),\n \"TypeParser.importedSchemaModule\",\n (node) => node\n )\n\n const importedContextModule = Nano.cachedBy(\n Nano.fn(\"TypeParser.importedContextModule\")(function*(\n node: ts.Node\n ) {\n const type = typeChecker.getTypeAtLocation(node)\n // if the type has a property \"Tag\" that is a function\n const propertySymbol = typeChecker.getPropertyOfType(type, \"Tag\")\n if (!propertySymbol) {\n return yield* typeParserIssue(\"Type has no 'Tag' 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 // return the node itself\n return node\n }),\n \"TypeParser.importedContextModule\",\n (node) => node\n )\n\n const importedEffectModule = Nano.cachedBy(\n Nano.fn(\"TypeParser.importedEffectModule\")(function*(\n node: ts.Node\n ) {\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 \"TypeParser.importedEffectModule\",\n (node) => node\n )\n\n const effectGen = Nano.cachedBy(\n function(node: ts.Node) {\n // Effect.gen(...)\n if (!ts.isCallExpression(node)) {\n return typeParserIssue(\"Node is not a call expression\", undefined, node)\n }\n // ...\n if (node.arguments.length === 0) {\n return 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 typeParserIssue(\"Node is not a function expression\", undefined, node)\n }\n if (generatorFunction.asteriskToken === undefined) {\n return typeParserIssue(\"Node is not a generator function\", undefined, node)\n }\n // Effect.gen\n if (!ts.isPropertyAccessExpression(node.expression)) {\n return 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 typeParserIssue(\"Call expression name is not 'gen'\", undefined, node)\n }\n // check Effect module\n return pipe(\n importedEffectModule(propertyAccess.expression),\n Nano.map((effectModule) => ({\n node,\n effectModule,\n generatorFunction,\n body: generatorFunction.body,\n functionStar: generatorFunction.getFirstToken()\n }))\n )\n },\n \"TypeParser.effectGen\",\n (node) => node\n )\n\n const effectFnUntracedGen = Nano.cachedBy(\n function(node: ts.Node) {\n // Effect.gen(...)\n if (!ts.isCallExpression(node)) {\n return typeParserIssue(\"Node is not a call expression\", undefined, node)\n }\n // ...\n if (node.arguments.length === 0) {\n return 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 typeParserIssue(\"Node is not a function expression\", undefined, node)\n }\n if (generatorFunction.asteriskToken === undefined) {\n return 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 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 typeParserIssue(\n \"Call expression name is not 'fnUntraced'\",\n undefined,\n node\n )\n }\n // check Effect module\n return pipe(\n importedEffectModule(propertyAccess.expression),\n Nano.map((effectModule) => ({\n node,\n effectModule,\n generatorFunction,\n body: generatorFunction.body,\n functionStar: generatorFunction.getFirstToken()\n }))\n )\n },\n \"TypeParser.effectFnUntracedGen\",\n (node) => node\n )\n\n const effectFnGen = Nano.cachedBy(\n function(node: ts.Node) {\n // Effect.fn(...)\n if (!ts.isCallExpression(node)) {\n return typeParserIssue(\"Node is not a call expression\", undefined, node)\n }\n // ...\n if (node.arguments.length === 0) {\n return 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 typeParserIssue(\n \"Node is not a function expression\",\n undefined,\n node\n )\n }\n if (generatorFunction.asteriskToken === undefined) {\n return 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 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 typeParserIssue(\n \"Call expression name is not 'fn'\",\n undefined,\n node\n )\n }\n // check Effect module\n return pipe(\n importedEffectModule(propertyAccess.expression),\n Nano.map((effectModule) => ({\n node,\n generatorFunction,\n effectModule,\n body: generatorFunction.body,\n functionStar: generatorFunction.getFirstToken()\n }))\n )\n },\n \"TypeParser.effectFnGen\",\n (node) => node\n )\n\n const unnecessaryEffectGen = Nano.cachedBy(\n Nano.fn(\"TypeParser.unnecessaryEffectGen\")(function*(\n node: ts.Node\n ) {\n // ensure is an effect gen with a single statement\n const { body } = yield* effectGen(node)\n if (body.statements.length !== 1) {\n return yield* typeParserIssue(\n \"Generator body should have a single statement\",\n undefined,\n node\n )\n }\n\n let explicitReturn = false\n let nodeToCheck: ts.Node = body.statements[0]\n while (nodeToCheck) {\n // return XXX\n if (ts.isReturnStatement(nodeToCheck) && nodeToCheck.expression) {\n nodeToCheck = nodeToCheck.expression\n explicitReturn = true\n continue\n }\n // expression yield*\n if (ts.isExpressionStatement(nodeToCheck)) {\n nodeToCheck = nodeToCheck.expression\n continue\n }\n // yield* XXX\n if (ts.isYieldExpression(nodeToCheck) && nodeToCheck.asteriskToken && nodeToCheck.expression) {\n const yieldedExpression = nodeToCheck.expression\n const type = typeChecker.getTypeAtLocation(yieldedExpression)\n const { A: successType } = yield* effectType(type, yieldedExpression)\n let replacementNode: Nano.Nano<ts.Node> = Nano.succeed(yieldedExpression)\n if (!explicitReturn && !(successType.flags & ts.TypeFlags.VoidLike)) {\n replacementNode = pipe(\n Nano.gen(function*() {\n const effectIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(\n node.getSourceFile(),\n \"effect\",\n \"Effect\"\n ) || \"Effect\"\n\n return ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectIdentifier),\n \"asVoid\"\n ),\n undefined,\n [\n yieldedExpression\n ]\n )\n }),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts)\n )\n }\n return { node, body, yieldedExpression, replacementNode }\n }\n // fall through\n break\n }\n\n // fall through case\n return yield* typeParserIssue(\n \"Not an handled node\",\n undefined,\n node\n )\n }),\n \"TypeParser.unnecessaryEffectGen\",\n (node) => node\n )\n\n const effectSchemaVarianceStruct = (\n type: ts.Type,\n atLocation: ts.Node\n ) =>\n Nano.map(\n Nano.all(\n varianceStructInvariantType(type, atLocation, \"_A\"),\n varianceStructInvariantType(type, atLocation, \"_I\"),\n varianceStructCovariantType(type, atLocation, \"_R\")\n ),\n ([A, I, R]) => ({ A, I, R })\n )\n\n const effectSchemaType = Nano.cachedBy(\n Nano.fn(\"TypeParser.effectSchemaType\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n ) {\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) && _.valueDeclaration &&\n ts.isPropertySignature(_.valueDeclaration) && ts.isComputedPropertyName(_.valueDeclaration.name)\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 \"TypeParser.effectSchemaType\",\n (type) => type\n )\n\n const contextTagVarianceStruct = (\n type: ts.Type,\n atLocation: ts.Node\n ) =>\n Nano.map(\n Nano.all(\n varianceStructInvariantType(type, atLocation, \"_Identifier\"),\n varianceStructInvariantType(type, atLocation, \"_Service\")\n ),\n ([Identifier, Service]) => ({ Identifier, Service })\n )\n\n const contextTag = Nano.cachedBy(\n Nano.fn(\"TypeParser.contextTag\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n ) {\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) && _.valueDeclaration &&\n ts.isPropertySignature(_.valueDeclaration) && ts.isComputedPropertyName(_.valueDeclaration.name)\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(contextTagVarianceStruct(\n propertyType,\n atLocation\n ))\n if (Option.isSome(varianceArgs)) {\n return varianceArgs.value\n }\n }\n return yield* typeParserIssue(\"Type has no tag variance struct\", type, atLocation)\n }),\n \"TypeParser.contextTag\",\n (type) => type\n )\n\n const pipeCall = Nano.cachedBy(\n function(\n node: ts.Node\n ): Nano.Nano<\n { node: ts.CallExpression; subject: ts.Expression; args: Array<ts.Expression>; kind: \"pipe\" | \"pipeable\" },\n TypeParserIssue,\n never\n > {\n // expression.pipe(.....)\n if (\n ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) &&\n ts.isIdentifier(node.expression.name) &&\n node.expression.name.text === \"pipe\"\n ) {\n return Nano.succeed({\n node,\n subject: node.expression.expression,\n args: Array.from(node.arguments),\n kind: \"pipeable\"\n })\n }\n\n // pipe(A, B, ...)\n if (\n ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === \"pipe\" &&\n node.arguments.length > 0\n ) {\n const [subject, ...args] = node.arguments\n return Nano.succeed({ node, subject, args, kind: \"pipe\" })\n }\n\n return typeParserIssue(\"Node is not a pipe call\", undefined, node)\n },\n \"TypeParser.pipeCall\",\n (node) => node\n )\n\n const scopeType = Nano.cachedBy(\n Nano.fn(\"TypeParser.scopeType\")(function*(\n type: ts.Type,\n atLocation: ts.Node\n ) {\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) && _.valueDeclaration &&\n ts.isPropertySignature(_.valueDeclaration) && ts.isComputedPropertyName(_.valueDeclaration.name)\n )\n // try to put typeid first (heuristic to optimize hot path)\n propertiesSymbols.sort((a, b) => b.name.indexOf(\"ScopeTypeId\") - a.name.indexOf(\"ScopeTypeId\"))\n // has a property scope type id\n for (const propertySymbol of propertiesSymbols) {\n const computedPropertyExpression: ts.ComputedPropertyName = (propertySymbol.valueDeclaration as any).name\n const symbol = typeChecker.getSymbolAtLocation(computedPropertyExpression.expression)\n if (symbol && symbol.name === \"ScopeTypeId\") {\n return type\n }\n }\n return yield* typeParserIssue(\"Type has no scope type id\", type, atLocation)\n }),\n \"TypeParser.scopeType\",\n (type) => type\n )\n\n const promiseLike = Nano.cachedBy(\n function(\n type: ts.Type,\n atLocation: ts.Node\n ) {\n // maybe it is a Promise<A>?\n const thenProperty = type.getProperty(\"then\")\n if (!thenProperty) return typeParserIssue(\"not a promise - missing then property\", type, atLocation)\n const thenType = typeChecker.getTypeOfSymbolAtLocation(thenProperty, atLocation)\n if (!thenType) return typeParserIssue(\"not a promise - missing then property\", type, atLocation)\n // .then should be callable\n for (const callSignature of thenType.getCallSignatures()) {\n // take the callback argument of then\n const parameter = callSignature.parameters[0]\n if (!parameter) continue\n const parameterType = callSignature.getTypeParameterAtPosition(0)\n if (!parameterType) continue\n // it can be an union with many types\n let callbackCallSignatures: Array<ts.Signature> = []\n let toTest = [parameterType]\n while (toTest.length > 0) {\n const type = toTest.shift()\n if (!type) continue\n const callSignatures = type.getCallSignatures()\n callbackCallSignatures = callbackCallSignatures.concat(callSignatures)\n if (type.isUnion()) {\n toTest = toTest.concat(type.types)\n }\n }\n for (const callableType of callbackCallSignatures) {\n const callbackParameter = callableType.parameters[0]\n if (!callbackParameter) {\n continue\n }\n const callbackParameterType = callableType.getTypeParameterAtPosition(0)\n if (!callbackParameterType) {\n continue\n }\n return Nano.succeed({\n type: callbackParameterType\n })\n }\n }\n return typeParserIssue(\"not a promise\", type, atLocation)\n },\n \"TypeParser.promiseLike\",\n (type) => type\n )\n\n const extendsSchemaClass = Nano.cachedBy(\n Nano.fn(\"TypeParser.extendsSchemaClass\")(function*(\n atLocation: ts.ClassDeclaration\n ) {\n if (!atLocation.name) {\n return yield* typeParserIssue(\"Class has no name\", undefined, atLocation)\n }\n const heritageClauses = atLocation.heritageClauses\n if (!heritageClauses) {\n return yield* typeParserIssue(\"Class has no heritage clauses\", undefined, atLocation)\n }\n for (const heritageClause of heritageClauses) {\n for (const typeX of heritageClause.types) {\n if (ts.isExpressionWithTypeArguments(typeX)) {\n const expression = typeX.expression\n if (ts.isCallExpression(expression)) {\n // Schema.Class<T>(\"name\")({})\n const schemaCall = expression.expression\n if (ts.isCallExpression(schemaCall) && schemaCall.typeArguments && schemaCall.typeArguments.length > 0) {\n const selfTypeNode = schemaCall.typeArguments[0]!\n const schemaIdentifier = schemaCall.expression\n if (\n ts.isPropertyAccessExpression(schemaIdentifier) && ts.isIdentifier(schemaIdentifier.name) &&\n schemaIdentifier.name.text === \"Class\"\n ) {\n const parsedSchemaModule = yield* pipe(\n importedSchemaModule(schemaIdentifier.expression),\n Nano.option\n )\n if (Option.isSome(parsedSchemaModule)) {\n return {\n className: atLocation.name,\n selfTypeNode,\n Schema: parsedSchemaModule.value\n }\n }\n }\n }\n }\n }\n }\n }\n return yield* typeParserIssue(\"Class does not extend Schema.Class\", undefined, atLocation)\n }),\n \"TypeParser.extendsSchemaClass\",\n (atLocation) => atLocation\n )\n\n const extendsSchemaTaggedClass = Nano.cachedBy(\n Nano.fn(\"TypeParser.extendsSchemaTaggedClass\")(function*(\n atLocation: ts.ClassDeclaration\n ) {\n if (!atLocation.name) {\n return yield* typeParserIssue(\"Class has no name\", undefined, atLocation)\n }\n const heritageClauses = atLocation.heritageClauses\n if (!heritageClauses) {\n return yield* typeParserIssue(\"Class has no heritage clauses\", undefined, atLocation)\n }\n for (const heritageClause of heritageClauses) {\n for (const typeX of heritageClause.types) {\n if (ts.isExpressionWithTypeArguments(typeX)) {\n const expression = typeX.expression\n if (ts.isCallExpression(expression)) {\n // Schema.TaggedClass<T>(\"name\")(\"tag\", {})\n const tagCall = expression.expression\n if (ts.isCallExpression(tagCall)) {\n const schemaCall = tagCall.expression\n if (\n ts.isCallExpression(schemaCall) && schemaCall.typeArguments && schemaCall.typeArguments.length > 0\n ) {\n const selfTypeNode = schemaCall.typeArguments[0]!\n const schemaIdentifier = schemaCall.expression\n if (\n ts.isPropertyAccessExpression(schemaIdentifier) && ts.isIdentifier(schemaIdentifier.name) &&\n schemaIdentifier.name.text === \"TaggedClass\"\n ) {\n const parsedSchemaModule = yield* pipe(\n importedSchemaModule(schemaIdentifier.expression),\n Nano.option\n )\n if (Option.isSome(parsedSchemaModule)) {\n return {\n className: atLocation.name,\n selfTypeNode,\n Schema: parsedSchemaModule.value\n }\n }\n }\n }\n }\n }\n }\n }\n }\n return yield* typeParserIssue(\"Class does not extend Schema.TaggedClass\", undefined, atLocation)\n }),\n \"TypeParser.extendsSchemaTaggedClass\",\n (atLocation) => atLocation\n )\n\n const extendsSchemaTaggedError = Nano.cachedBy(\n Nano.fn(\"TypeParser.extendsSchemaTaggedError\")(function*(\n atLocation: ts.ClassDeclaration\n ) {\n if (!atLocation.name) {\n return yield* typeParserIssue(\"Class has no name\", undefined, atLocation)\n }\n const heritageClauses = atLocation.heritageClauses\n if (!heritageClauses) {\n return yield* typeParserIssue(\"Class has no heritage clauses\", undefined, atLocation)\n }\n for (const heritageClause of heritageClauses) {\n for (const typeX of heritageClause.types) {\n if (ts.isExpressionWithTypeArguments(typeX)) {\n const expression = typeX.expression\n if (ts.isCallExpression(expression)) {\n // Schema.TaggedError<T>(\"name\")(\"tag\", {})\n const tagCall = expression.expression\n if (ts.isCallExpression(tagCall)) {\n const schemaCall = tagCall.expression\n if (\n ts.isCallExpression(schemaCall) && schemaCall.typeArguments && schemaCall.typeArguments.length > 0\n ) {\n const selfTypeNode = schemaCall.typeArguments[0]!\n const schemaIdentifier = schemaCall.expression\n if (\n ts.isPropertyAccessExpression(schemaIdentifier) && ts.isIdentifier(schemaIdentifier.name) &&\n schemaIdentifier.name.text === \"TaggedError\"\n ) {\n const parsedSchemaModule = yield* pipe(\n importedSchemaModule(schemaIdentifier.expression),\n Nano.option\n )\n if (Option.isSome(parsedSchemaModule)) {\n return {\n className: atLocation.name,\n selfTypeNode,\n Schema: parsedSchemaModule.value\n }\n }\n }\n }\n }\n }\n }\n }\n }\n return yield* typeParserIssue(\"Class does not extend Schema.TaggedError\", undefined, atLocation)\n }),\n \"TypeParser.extendsSchemaTaggedError\",\n (atLocation) => atLocation\n )\n\n const extendsSchemaTaggedRequest = Nano.cachedBy(\n Nano.fn(\"TypeParser.extendsSchemaTaggedRequest\")(function*(\n atLocation: ts.ClassDeclaration\n ) {\n if (!atLocation.name) {\n return yield* typeParserIssue(\"Class has no name\", undefined, atLocation)\n }\n const heritageClauses = atLocation.heritageClauses\n if (!heritageClauses) {\n return yield* typeParserIssue(\"Class has no heritage clauses\", undefined, atLocation)\n }\n for (const heritageClause of heritageClauses) {\n for (const typeX of heritageClause.types) {\n if (ts.isExpressionWithTypeArguments(typeX)) {\n const expression = typeX.expression\n if (ts.isCallExpression(expression)) {\n // Schema.TaggedRequest<T>(\"name\")(\"tag\", {})\n const tagCall = expression.expression\n if (ts.isCallExpression(tagCall)) {\n const schemaCall = tagCall.expression\n if (\n ts.isCallExpression(schemaCall) && schemaCall.typeArguments && schemaCall.typeArguments.length > 0\n ) {\n const selfTypeNode = schemaCall.typeArguments[0]!\n const schemaIdentifier = schemaCall.expression\n if (\n ts.isPropertyAccessExpression(schemaIdentifier) && ts.isIdentifier(schemaIdentifier.name) &&\n schemaIdentifier.name.text === \"TaggedRequest\"\n ) {\n const parsedSchemaModule = yield* pipe(\n importedSchemaModule(schemaIdentifier.expression),\n Nano.option\n )\n if (Option.isSome(parsedSchemaModule)) {\n return {\n className: atLocation.name,\n selfTypeNode,\n Schema: parsedSchemaModule.value\n }\n }\n }\n }\n }\n }\n }\n }\n }\n return yield* typeParserIssue(\"Class does not extend Schema.TaggedRequest\", undefined, atLocation)\n }),\n \"TypeParser.extendsSchemaTaggedRequest\",\n (atLocation) => atLocation\n )\n\n const extendsContextTag = Nano.cachedBy(\n Nano.fn(\"TypeParser.extendsContextTag\")(function*(\n atLocation: ts.ClassDeclaration\n ) {\n if (!atLocation.name) {\n return yield* typeParserIssue(\"Class has no name\", undefined, atLocation)\n }\n const classSym = typeChecker.getSymbolAtLocation(atLocation.name)\n if (!classSym) return yield* typeParserIssue(\"Class has no symbol\", undefined, atLocation)\n const type = typeChecker.getTypeOfSymbol(classSym)\n const heritageClauses = atLocation.heritageClauses\n if (!heritageClauses) {\n return yield* typeParserIssue(\"Class has no heritage clauses\", undefined, atLocation)\n }\n for (const heritageClause of heritageClauses) {\n for (const typeX of heritageClause.types) {\n if (ts.isExpressionWithTypeArguments(typeX)) {\n const wholeCall = typeX.expression\n if (ts.isCallExpression(wholeCall)) {\n const contextTagCall = wholeCall.expression\n if (\n ts.isCallExpression(contextTagCall) &&\n wholeCall.typeArguments && wholeCall.typeArguments.length > 0\n ) {\n const contextTagIdentifier = contextTagCall.expression\n const selfTypeNode = wholeCall.typeArguments[0]!\n if (\n ts.isPropertyAccessExpression(contextTagIdentifier) &&\n ts.isIdentifier(contextTagIdentifier.name) && contextTagIdentifier.name.text === \"Tag\"\n ) {\n const parsedContextModule = yield* pipe(\n importedContextModule(contextTagIdentifier.expression),\n Nano.option\n )\n if (Option.isSome(parsedContextModule)) {\n const tagType = yield* contextTag(type, atLocation)\n return {\n className: atLocation.name,\n selfTypeNode,\n args: contextTagCall.arguments,\n Identifier: tagType.Identifier,\n Tag: parsedContextModule.value\n }\n }\n }\n }\n }\n }\n }\n }\n return yield* typeParserIssue(\"Class does not extend Context.Tag\", undefined, atLocation)\n }),\n \"TypeParser.extendsContextTag\",\n (atLocation) => atLocation\n )\n\n const extendsEffectService = Nano.cachedBy(\n Nano.fn(\"TypeParser.extendsEffectService\")(function*(\n atLocation: ts.ClassDeclaration\n ) {\n if (!atLocation.name) {\n return yield* typeParserIssue(\"Class has no name\", undefined, atLocation)\n }\n const classSym = typeChecker.getSymbolAtLocation(atLocation.name)\n if (!classSym) return yield* typeParserIssue(\"Class has no symbol\", undefined, atLocation)\n const type = typeChecker.getTypeOfSymbol(classSym)\n const heritageClauses = atLocation.heritageClauses\n if (!heritageClauses) {\n return yield* typeParserIssue(\"Class has no heritage clauses\", undefined, atLocation)\n }\n for (const heritageClause of heritageClauses) {\n for (const typeX of heritageClause.types) {\n if (ts.isExpressionWithTypeArguments(typeX)) {\n const wholeCall = typeX.expression\n if (ts.isCallExpression(wholeCall)) {\n const effectServiceCall = wholeCall.expression\n if (\n ts.isCallExpression(effectServiceCall) &&\n effectServiceCall.typeArguments && effectServiceCall.typeArguments.length > 0\n ) {\n const effectServiceIdentifier = effectServiceCall.expression\n const selfTypeNode = effectServiceCall.typeArguments[0]!\n if (\n ts.isPropertyAccessExpression(effectServiceIdentifier) &&\n ts.isIdentifier(effectServiceIdentifier.name) && effectServiceIdentifier.name.text === \"Service\"\n ) {\n const parsedContextTag = yield* pipe(\n importedEffectModule(effectServiceIdentifier.expression),\n Nano.flatMap(() => contextTag(type, atLocation)),\n Nano.option\n )\n if (Option.isSome(parsedContextTag)) {\n // try to parse some settings\n let accessors: boolean | undefined = undefined\n let dependencies: ts.NodeArray<ts.Expression> | undefined = undefined\n if (wholeCall.arguments.length >= 2) {\n const args = wholeCall.arguments[1]\n if (ts.isObjectLiteralExpression(args)) {\n for (const property of args.properties) {\n if (\n ts.isPropertyAssignment(property) && property.name && ts.isIdentifier(property.name) &&\n property.name.text === \"accessors\" && property.initializer &&\n property.initializer.kind === ts.SyntaxKind.TrueKeyword\n ) {\n accessors = true\n }\n if (\n ts.isPropertyAssignment(property) && property.name && ts.isIdentifier(property.name) &&\n property.name.text === \"dependencies\" && property.initializer &&\n ts.isArrayLiteralExpression(property.initializer)\n ) {\n dependencies = property.initializer.elements\n }\n }\n }\n }\n return ({\n ...parsedContextTag.value,\n className: atLocation.name,\n selfTypeNode,\n args: wholeCall.arguments,\n options: wholeCall.arguments[1],\n accessors,\n dependencies\n })\n }\n }\n }\n }\n }\n }\n }\n\n return yield* typeParserIssue(\"Class does not extend Effect.Service\", undefined, atLocation)\n }),\n \"TypeParser.extendsEffectService\",\n (atLocation) => atLocation\n )\n\n return {\n effectType,\n strictEffectType,\n layerType,\n fiberType,\n effectSubtype,\n importedEffectModule,\n effectGen,\n effectFnUntracedGen,\n effectFnGen,\n unnecessaryEffectGen,\n effectSchemaType,\n contextTag,\n pipeableType,\n pipeCall,\n scopeType,\n promiseLike,\n extendsEffectService,\n extendsContextTag,\n extendsSchemaClass,\n extendsSchemaTaggedClass,\n extendsSchemaTaggedError,\n extendsSchemaTaggedRequest\n }\n}\n","import { pipe } from \"effect\"\nimport type ts from \"typescript\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const classSelfMismatch = LSP.createDiagnostic({\n name: \"classSelfMismatch\",\n code: 20,\n severity: \"error\",\n apply: Nano.fn(\"classSelfMismatch.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\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\n // Check if this is a class declaration that extends Effect.Service, Context.Tag, or Schema classes\n if (ts.isClassDeclaration(node) && node.name && node.heritageClauses) {\n // Check if this class extends a class that has a Self type parameter\n const result = yield* pipe(\n typeParser.extendsEffectService(node),\n Nano.orElse(() => typeParser.extendsContextTag(node)),\n Nano.orElse(() => typeParser.extendsSchemaClass(node)),\n Nano.orElse(() => typeParser.extendsSchemaTaggedClass(node)),\n Nano.orElse(() => typeParser.extendsSchemaTaggedError(node)),\n Nano.orElse(() => typeParser.extendsSchemaTaggedRequest(node)),\n Nano.orElse(() => Nano.void_)\n )\n\n if (result) {\n // Both methods return { selfTypeNode, className } when they match\n const { className, selfTypeNode } = result\n\n // Get the actual name from the self type node\n let actualName = \"\"\n if (ts.isTypeReferenceNode(selfTypeNode)) {\n if (ts.isIdentifier(selfTypeNode.typeName)) {\n actualName = selfTypeNode.typeName.text\n } else if (ts.isQualifiedName(selfTypeNode.typeName)) {\n actualName = selfTypeNode.typeName.right.text\n }\n }\n\n // Check if the self type matches the class name\n const expectedName = className.text\n if (actualName !== expectedName) {\n report({\n location: selfTypeNode,\n messageText: `Self type parameter should be '${expectedName}'`,\n fixes: [{\n fixName: \"classSelfMismatch_fix\",\n description: `Replace '${actualName}' with '${expectedName}'`,\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n // Create a new type reference with the correct class name\n const typeArgs = ts.isTypeReferenceNode(selfTypeNode) ? selfTypeNode.typeArguments : undefined\n const newTypeReference = ts.factory.createTypeReferenceNode(\n ts.factory.createIdentifier(expectedName),\n typeArgs\n )\n\n // Replace the incorrect type reference with the correct one\n changeTracker.replaceNode(sourceFile, selfTypeNode, newTypeReference)\n })\n }]\n })\n }\n }\n }\n\n ts.forEachChild(node, appendNodeToVisit)\n }\n })\n})\n","import { hasProperty, isNumber } from \"effect/Predicate\"\nimport * as LanguageServicePluginOptions from \"../core/LanguageServicePluginOptions.js\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as TypeScriptUtils from \"../core/TypeScriptUtils.js\"\n\ntype ResolvedPackagesCache = Record<string, Record<string, any>>\n\nconst checkedPackagesCache = new Map<string, ResolvedPackagesCache>()\nconst programResolvedCacheSize = new Map<string, number>()\n\nexport const duplicatePackage = LSP.createDiagnostic({\n name: \"duplicatePackage\",\n code: 6,\n severity: \"warning\",\n apply: Nano.fn(\"duplicatePackage.apply\")(function*(sourceFile, report) {\n const program = yield* Nano.service(TypeScriptApi.TypeScriptProgram)\n const tsUtils = yield* Nano.service(TypeScriptUtils.TypeScriptUtils)\n const options = yield* Nano.service(LanguageServicePluginOptions.LanguageServicePluginOptions)\n\n if (sourceFile.statements.length < 1) return\n\n // whenever we detect the resolution cache size has changed, try again the check\n // this should mitigate how frequently this rule is triggered\n let resolvedPackages: ResolvedPackagesCache = checkedPackagesCache.get(sourceFile.fileName) ||\n {}\n const newResolvedModuleSize =\n hasProperty(program, \"resolvedModules\") && hasProperty(program.resolvedModules, \"size\") &&\n isNumber(program.resolvedModules.size) ?\n program.resolvedModules.size :\n 0\n const oldResolvedSize = programResolvedCacheSize.get(sourceFile.fileName) || -1\n if (newResolvedModuleSize !== oldResolvedSize) {\n const seenPackages = new Set<string>()\n resolvedPackages = {}\n program.getSourceFiles().map((_) => {\n const packageInfo = tsUtils.parsePackageContentNameAndVersionFromScope(_)\n if (!packageInfo) return\n const packageNameAndVersion = packageInfo.name + \"@\" + packageInfo.version\n if (seenPackages.has(packageNameAndVersion)) return\n seenPackages.add(packageNameAndVersion)\n if (\n !(packageInfo.name === \"effect\" || packageInfo.hasEffectInPeerDependencies)\n ) return\n if (options.allowedDuplicatedPackages.indexOf(packageInfo.name) > -1) return\n resolvedPackages[packageInfo.name] = resolvedPackages[packageInfo.name] || {}\n resolvedPackages[packageInfo.name][packageInfo.version] = packageInfo.packageDirectory\n })\n checkedPackagesCache.set(sourceFile.fileName, resolvedPackages)\n programResolvedCacheSize.set(sourceFile.fileName, newResolvedModuleSize)\n }\n\n for (const packageName of Object.keys(resolvedPackages)) {\n if (Object.keys(resolvedPackages[packageName]).length > 1) {\n const versions = Object.keys(resolvedPackages[packageName])\n report({\n location: sourceFile.statements[0],\n messageText: `Package ${packageName} is referenced multiple times with different versions (${\n versions.join(\", \")\n }) and may cause unexpected type errors.\\nCleanup your dependencies and your package lockfile to avoid multiple instances of this package and reload the project.\\nIf this is intended set the LSP config \"allowedDuplicatedPackages\" to ${\n JSON.stringify(options.allowedDuplicatedPackages.concat([packageName]))\n }.\\n\\n${\n versions.map((version) => `- found ${version} at ${resolvedPackages[packageName][version]}`).join(\"\\n\")\n }`,\n fixes: []\n })\n }\n }\n })\n})\n","import { 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 TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const effectInVoidSuccess = LSP.createDiagnostic({\n name: \"effectInVoidSuccess\",\n code: 14,\n severity: \"warning\",\n apply: Nano.fn(\"effectInVoidSuccess.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\n\n const checkForEffectInVoid = Nano.fn(\"effectInVoidSuccess.checkForEffectInVoid\")(function*(\n node: ts.Node,\n expectedType: ts.Type,\n valueNode: ts.Node,\n realType: ts.Type\n ) {\n const expectedEffect = yield* typeParser.effectType(expectedType, node)\n const realEffect = yield* typeParser.effectType(realType, valueNode)\n if (expectedEffect.A.flags & ts.TypeFlags.Void) {\n const voidValueTypes = TypeCheckerApi.unrollUnionMembers(realEffect.A)\n const voidedEffect = yield* Nano.firstSuccessOf(\n voidValueTypes.map((_) => Nano.map(typeParser.strictEffectType(_, node), () => _))\n )\n return { voidedEffect }\n }\n return yield* Nano.fail(TypeParser.typeParserIssue(\"expectedEffect success is not void\"))\n })\n\n const entries = yield* TypeCheckerApi.expectedAndRealType(sourceFile)\n for (const [node, expectedType, valueNode, realType] of entries) {\n if (expectedType !== realType) {\n yield* pipe(\n checkForEffectInVoid(\n node,\n expectedType,\n valueNode,\n realType\n ),\n Nano.map(({ voidedEffect }) => {\n report(\n {\n location: node,\n messageText: `There is a nested '${\n typeChecker.typeToString(voidedEffect)\n }' in the 'void' success channel, beware that this could lead to nested Effect<Effect<...>> that won't be executed.`,\n fixes: []\n }\n )\n }),\n Nano.ignore\n )\n }\n }\n })\n})\n","import { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeCheckerApi from \"../core/TypeCheckerApi.js\"\nimport * as TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const floatingEffect = LSP.createDiagnostic({\n name: \"floatingEffect\",\n code: 3,\n severity: \"error\",\n apply: Nano.fn(\"floatingEffect.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\n\n function isFloatingExpression(node: ts.Node): node is ts.ExpressionStatement {\n // should be an expression statement\n if (!ts.isExpressionStatement(node)) return false\n // parent is either block or source file\n if (!(ts.isBlock(node.parent) || ts.isSourceFile(node.parent))) return false\n const expression = node.expression\n // this.variable = Effect.succeed is a valid expression\n if (\n ts.isBinaryExpression(expression) && expression.operatorToken &&\n (expression.operatorToken.kind === ts.SyntaxKind.EqualsToken ||\n expression.operatorToken.kind === ts.SyntaxKind.QuestionQuestionEqualsToken ||\n expression.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandEqualsToken ||\n expression.operatorToken.kind === ts.SyntaxKind.BarBarEqualsToken)\n ) return false\n return true\n }\n\n const 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 // check if strictly an effect or a subtype to change the error message\n const isStrictEffect = yield* Nano.option(typeParser.strictEffectType(type, node.expression))\n const name = Option.isSome(isStrictEffect) ? \"Effect\" : \"Effect-able \" + typeChecker.typeToString(type)\n report({\n location: node,\n messageText: `${name} must be yielded or assigned to a variable.`,\n fixes: []\n })\n }\n }\n }\n })\n})\n","import { 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 TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const genericEffectServices = LSP.createDiagnostic({\n name: \"genericEffectServices\",\n code: 10,\n severity: \"warning\",\n apply: Nano.fn(\"genericEffectServices.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\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 const typesToCheck: Array<[ts.Type, ts.Node]> = []\n\n if (ts.isClassDeclaration(node) && node.name && node.typeParameters && node.heritageClauses) {\n const classSym = typeChecker.getSymbolAtLocation(node.name)\n if (classSym) {\n const type = typeChecker.getTypeOfSymbol(classSym)\n typesToCheck.push([type, node.name!])\n }\n } else {\n ts.forEachChild(node, appendNodeToVisit)\n continue\n }\n\n // check the types\n for (const [type, reportAt] of typesToCheck) {\n yield* pipe(\n typeParser.contextTag(type, node),\n Nano.map(() => {\n report({\n location: reportAt,\n messageText:\n `Effect Services with type parameters are not supported because they cannot be properly discriminated at runtime, which may cause unexpected behavior.`,\n fixes: []\n })\n }),\n Nano.orElse(() => Nano.sync(() => ts.forEachChild(node, appendNodeToVisit))),\n Nano.ignore\n )\n }\n }\n })\n})\n","import * as Array from \"effect/Array\"\nimport type ts from \"typescript\"\nimport * as LanguageServicePluginOptions from \"../core/LanguageServicePluginOptions.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 TypeScriptUtils from \"../core/TypeScriptUtils.js\"\n\nexport const importFromBarrel = LSP.createDiagnostic({\n name: \"importFromBarrel\",\n code: 12,\n severity: \"off\",\n apply: Nano.fn(\"importFromBarrel.apply\")(function*(sourceFile, report) {\n // requires namespaceImportPackages to be set\n const languageServicePluginOptions = yield* Nano.service(LanguageServicePluginOptions.LanguageServicePluginOptions)\n if (languageServicePluginOptions.namespaceImportPackages.length === 0) return\n\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const tsUtils = yield* Nano.service(TypeScriptUtils.TypeScriptUtils)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const program = yield* Nano.service(TypeScriptApi.TypeScriptProgram)\n const packageNamesToCheck = Array.flatten(\n languageServicePluginOptions.namespaceImportPackages.map((packageName) =>\n tsUtils.resolveModulePattern(sourceFile, packageName)\n )\n )\n\n const isImportedFromBarrelExport = (\n element: ts.ImportSpecifier\n ) => {\n const getModuleSpecifier = tsUtils.makeGetModuleSpecifier()\n const resolveExternalModuleName = TypeCheckerApi.makeResolveExternalModuleName(typeChecker)\n\n if (!(getModuleSpecifier && resolveExternalModuleName)) return\n\n const importDeclaration = ts.findAncestor(element, (node) => ts.isImportDeclaration(node))\n if (!importDeclaration) return\n if (!ts.isStringLiteral(importDeclaration.moduleSpecifier)) return\n const importClause = importDeclaration.importClause\n if (!importClause) return\n const namedBindings = importClause.namedBindings\n if (!namedBindings) return\n if (!ts.isNamedImports(namedBindings)) return\n\n const barrelModuleName = importDeclaration.moduleSpecifier.text\n if (packageNamesToCheck.indexOf(barrelModuleName.toLowerCase()) === -1) return\n const moduleSymbol = resolveExternalModuleName(importDeclaration.moduleSpecifier)\n if (!moduleSymbol) return\n if (!moduleSymbol.exports) return\n const sourceFile = importDeclaration.getSourceFile()\n\n const nodeForSymbol = element.propertyName || element.name\n const aliasSymbol = element.name || element.propertyName\n const aliasedName = aliasSymbol.text\n\n // we can only check for identifiers\n if (!ts.isIdentifier(nodeForSymbol)) return\n const importedName = nodeForSymbol.text\n // get the symbol of the re-export\n const reexportedSymbol = moduleSymbol.exports.get(ts.escapeLeadingUnderscores(importedName))\n if (!reexportedSymbol) return\n // if we have only a declaration\n if (!(reexportedSymbol.declarations && reexportedSymbol.declarations.length === 1)) return\n // that should be an 'export * as X from \"module\"'\n const namespaceExport = reexportedSymbol.declarations[0]\n if (!ts.isNamespaceExport(namespaceExport)) return\n // parent should be an export declaration\n const exportDeclaration = namespaceExport.parent\n if (!ts.isExportDeclaration(exportDeclaration)) return\n // if we have a module specifier, resolve that symbol\n if (!exportDeclaration.moduleSpecifier) return\n const originalModuleSymbol = resolveExternalModuleName(exportDeclaration.moduleSpecifier)\n if (!originalModuleSymbol) return\n // the value declaration should be the sourcefile of the original module\n if (!originalModuleSymbol.valueDeclaration) return\n const originalSourceFile = originalModuleSymbol.valueDeclaration.getSourceFile()\n const unbarrelledFileName = getModuleSpecifier(\n program.getCompilerOptions(),\n sourceFile,\n sourceFile.fileName,\n originalSourceFile.fileName,\n program\n )\n // need to start with the barrel module name, otherwise its not the same package\n if (unbarrelledFileName.toLowerCase().indexOf(barrelModuleName.toLowerCase() + \"/\") === -1) return\n return {\n unbarrelledFileName,\n importedName,\n barrelModuleName,\n importClause,\n namedBindings,\n importDeclaration,\n aliasedName\n }\n }\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 const parent = node.parent\n\n if (!(ts.isImportSpecifier(node) && ts.isNamedImports(parent))) {\n ts.forEachChild(node, appendNodeToVisit)\n continue\n }\n\n const result = isImportedFromBarrelExport(node)\n if (!result) continue\n const {\n aliasedName,\n barrelModuleName,\n importClause,\n importDeclaration,\n namedBindings,\n unbarrelledFileName\n } = result\n // ok, I think now we can report the error\n report({\n location: node,\n messageText: `Importing from barrel module ${barrelModuleName} is not allowed.`,\n fixes: [\n {\n fixName: \"replaceWithUnbarrelledImport\",\n description: `Import * as ${aliasedName} from ${unbarrelledFileName}`,\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n const newImport = ts.factory.createImportDeclaration(\n undefined,\n ts.factory.createImportClause(\n importClause.isTypeOnly || node.isTypeOnly,\n undefined,\n ts.factory.createNamespaceImport(ts.factory.createIdentifier(aliasedName))\n ),\n ts.factory.createStringLiteral(unbarrelledFileName)\n )\n\n if (namedBindings.elements.length === 1) {\n changeTracker.replaceNode(\n sourceFile,\n importDeclaration,\n newImport\n )\n } else {\n changeTracker.insertNodeAfter(sourceFile, importDeclaration, newImport)\n changeTracker.replaceNode(\n sourceFile,\n namedBindings,\n ts.factory.updateNamedImports(\n namedBindings,\n namedBindings.elements.filter((e) => e !== node)\n )\n )\n }\n })\n }\n ]\n })\n }\n })\n})\n","import * as Array 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 TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const leakingRequirements = LSP.createDiagnostic({\n name: \"leakingRequirements\",\n code: 8,\n severity: \"suggestion\",\n apply: Nano.fn(\"leakingRequirements.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\n const typeOrder = yield* TypeCheckerApi.deterministicTypeOrder\n\n const parseLeakedRequirements = Nano.cachedBy(\n Nano.fn(\"leakingServices.checkServiceLeaking\")(\n function*(service: ts.Type, atLocation: ts.Node) {\n const properties = typeChecker.getPropertiesOfType(service)\n // since this is an heuristic, we require at least 2 props\n if (properties.length < 1) return []\n // store the accumulated services\n const memory = new Map<string, ts.Type>()\n let sharedRequirementsKeys: Array<string> | undefined = undefined\n let effectMembers = 0\n for (const property of properties) {\n // get the context type of the property, either Effect<...> or () => Effect<...>\n const servicePropertyType = typeChecker.getTypeOfSymbolAtLocation(property, atLocation)\n let effectContextType: ts.Type | undefined = undefined\n yield* pipe(\n typeParser.effectType(servicePropertyType, atLocation),\n Nano.map((_) => effectContextType = _.R),\n Nano.orElse(() => {\n const servicePropertyCallSignatures = servicePropertyType.getCallSignatures()\n if (servicePropertyCallSignatures.length === 1) {\n return pipe(\n typeParser.effectType(servicePropertyCallSignatures[0].getReturnType(), atLocation),\n Nano.map((_) => {\n effectContextType = _.R\n })\n )\n }\n return Nano.void_\n }),\n Nano.ignore\n )\n // once we have the type, check the context for shared requirements\n if (effectContextType) {\n effectMembers++\n const { allIndexes } = yield* TypeCheckerApi.appendToUniqueTypesMap(\n memory,\n effectContextType,\n (type) => {\n // exclude never\n if (type.flags & ts.TypeFlags.Never) return Nano.succeed(true)\n // exclude scope\n return pipe(\n typeParser.scopeType(type, atLocation),\n Nano.map(() => true),\n Nano.orElse(() => Nano.succeed(false))\n )\n }\n )\n if (!sharedRequirementsKeys) {\n sharedRequirementsKeys = allIndexes\n } else {\n sharedRequirementsKeys = Array.intersection(sharedRequirementsKeys, allIndexes)\n if (sharedRequirementsKeys.length === 0) return []\n }\n }\n }\n // ...and those at least 2 props must be or return effects\n if (sharedRequirementsKeys && sharedRequirementsKeys.length > 0 && effectMembers >= 2) {\n return sharedRequirementsKeys.map((key) => memory.get(key)!)\n }\n return []\n }\n ),\n \"leakingServices.checkServiceLeaking\",\n (_, service) => service\n )\n\n function reportLeakingRequirements(node: ts.Node, requirements: Array<ts.Type>) {\n if (requirements.length === 0) return\n report({\n location: node,\n messageText: `This Service is leaking the ${\n requirements.map((_) => typeChecker.typeToString(_)).join(\" | \")\n } requirement.\\nIf these requirements cannot be cached and are expected to be provided per method invocation (e.g. HttpServerRequest), you can safely disable this diagnostic for this line through quickfixes.\\nMore info at https://effect.website/docs/requirements-management/layers/#avoiding-requirement-leakage`,\n fixes: []\n })\n }\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\n // we need to check the type of the class declaration (if any)\n const typesToCheck: Array<[type: ts.Type, reportNode: ts.Node]> = []\n if (\n ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) &&\n ts.isIdentifier(node.expression.name) && node.expression.name.text === \"GenericTag\"\n ) {\n typesToCheck.push([typeChecker.getTypeAtLocation(node), node])\n } else if (ts.isClassDeclaration(node) && node.name && node.heritageClauses) {\n const classSym = typeChecker.getSymbolAtLocation(node.name)\n if (classSym) {\n const type = typeChecker.getTypeOfSymbol(classSym)\n typesToCheck.push([type, node.name])\n }\n } else {\n ts.forEachChild(node, appendNodeToVisit)\n continue\n }\n\n // check the types\n for (const [type, reportAt] of typesToCheck) {\n yield* pipe(\n typeParser.contextTag(type, node),\n Nano.flatMap(({ Service }) =>\n pipe(\n parseLeakedRequirements(Service, node),\n Nano.map((requirements) => reportLeakingRequirements(reportAt, Array.sort(requirements, typeOrder)))\n )\n ),\n Nano.orElse(() => Nano.sync(() => ts.forEachChild(node, appendNodeToVisit))),\n Nano.ignore\n )\n }\n }\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 TypeParser from \"../core/TypeParser.js\"\n\nexport const missingEffectContext = LSP.createDiagnostic({\n name: \"missingEffectContext\",\n code: 1,\n severity: \"error\",\n apply: Nano.fn(\"missingEffectContext.apply\")(function*(sourceFile, report) {\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\n const typeOrder = yield* TypeCheckerApi.deterministicTypeOrder\n\n const checkForMissingContextTypes = (\n node: ts.Node,\n expectedType: ts.Type,\n valueNode: ts.Node,\n realType: ts.Type\n ) =>\n pipe(\n Nano.all(\n typeParser.effectType(expectedType, node),\n typeParser.effectType(realType, valueNode)\n ),\n Nano.flatMap(([expectedEffect, realEffect]) =>\n TypeCheckerApi.getMissingTypeEntriesInTargetType(\n realEffect.R,\n expectedEffect.R\n )\n )\n )\n\n const sortTypes = ReadonlyArray.sort(typeOrder)\n\n const entries = yield* TypeCheckerApi.expectedAndRealType(sourceFile)\n for (const [node, expectedType, valueNode, realType] of entries) {\n // if the types are different, check for missing context types\n if (expectedType !== realType) {\n yield* pipe(\n checkForMissingContextTypes(\n node,\n expectedType,\n valueNode,\n realType\n ),\n Nano.map((missingTypes) =>\n missingTypes.length > 0 ?\n report(\n {\n location: node,\n messageText: `Missing '${\n sortTypes(missingTypes).map((_) => typeChecker.typeToString(_)).join(\" | \")\n }' in the expected Effect context.`,\n fixes: []\n }\n )\n : undefined\n ),\n Nano.ignore\n )\n }\n }\n })\n})\n","import * as ReadonlyArray from \"effect/Array\"\nimport { pipe } from \"effect/Function\"\nimport * as Order from \"effect/Order\"\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 TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as TypeScriptUtils from \"../core/TypeScriptUtils.js\"\n\nexport const missingEffectError = LSP.createDiagnostic({\n name: \"missingEffectError\",\n code: 1,\n severity: \"error\",\n apply: Nano.fn(\"missingEffectError.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const tsUtils = yield* Nano.service(TypeScriptUtils.TypeScriptUtils)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\n const typeOrder = yield* TypeCheckerApi.deterministicTypeOrder\n\n const effectModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(\n sourceFile,\n \"effect\",\n \"Effect\"\n ) || \"Effect\"\n\n const createDieMessage = (message: string) =>\n ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectModuleIdentifier),\n \"dieMessage\"\n ),\n undefined,\n [ts.factory.createStringLiteral(message)]\n )\n\n const checkForMissingErrorTypes = (\n node: ts.Node,\n expectedType: ts.Type,\n valueNode: ts.Node,\n realType: ts.Type\n ) =>\n pipe(\n Nano.all(\n typeParser.effectType(expectedType, node),\n typeParser.effectType(realType, valueNode)\n ),\n Nano.flatMap(([expectedEffect, realEffect]) =>\n pipe(\n TypeCheckerApi.getMissingTypeEntriesInTargetType(\n realEffect.E,\n expectedEffect.E\n ),\n Nano.map((missingErrorTypes) => ({ missingErrorTypes, expectedErrorType: expectedEffect.E }))\n )\n )\n )\n\n const sortTypes = ReadonlyArray.sort(typeOrder)\n\n const entries = yield* TypeCheckerApi.expectedAndRealType(sourceFile)\n for (const [node, expectedType, valueNode, realType] of entries) {\n // if the types are different, check for missing error types\n if (expectedType !== realType) {\n yield* pipe(\n checkForMissingErrorTypes(\n node,\n expectedType,\n valueNode,\n realType\n ),\n Nano.map((result) => {\n if (result.missingErrorTypes.length === 0) return\n const fixes: Array<LSP.ApplicableDiagnosticDefinitionFix> = []\n\n if (ts.isExpression(valueNode) && result.expectedErrorType.flags & ts.TypeFlags.Never) {\n fixes.push({\n fixName: \"missingEffectError_catchAll\",\n description: \"Catch all errors with Effect.catchAll\",\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n changeTracker.insertText(sourceFile, valueNode.getStart(), effectModuleIdentifier + \".catchAll(\")\n changeTracker.insertText(sourceFile, valueNode.getEnd(), \", () => \")\n changeTracker.insertNodeAt(\n sourceFile,\n valueNode.getEnd(),\n createDieMessage(\"TODO: catchAll not implemented\")\n )\n changeTracker.insertText(sourceFile, valueNode.getEnd(), \")\")\n })\n })\n }\n\n if (ts.isExpression(valueNode)) {\n const propertyAssignments = pipe(\n result.missingErrorTypes,\n ReadonlyArray.map((_) => typeChecker.getPropertyOfType(_, \"_tag\")),\n ReadonlyArray.filter((_) => !!_),\n ReadonlyArray.map((_) => typeChecker.getTypeOfSymbolAtLocation(_, valueNode)),\n ReadonlyArray.filter((_) => !!(_.flags & ts.TypeFlags.Literal)),\n ReadonlyArray.map((_) => typeChecker.typeToTypeNode(_, undefined, ts.NodeBuilderFlags.NoTruncation)),\n ReadonlyArray.filter((_) => !!_ && ts.isLiteralTypeNode(_)),\n ReadonlyArray.map((_) => _.literal),\n ReadonlyArray.filter((_) => ts.isLiteralExpression(_)),\n ReadonlyArray.map((_) => _.text),\n ReadonlyArray.sort(Order.string),\n ReadonlyArray.map((_) =>\n ts.factory.createPropertyAssignment(\n ts.factory.createIdentifier(_),\n ts.factory.createArrowFunction(\n undefined,\n undefined,\n [],\n undefined,\n undefined,\n createDieMessage(`TODO: catchTags() not implemented for ${_}`)\n )\n )\n )\n )\n if (propertyAssignments.length === result.missingErrorTypes.length) {\n fixes.push({\n fixName: \"missingEffectError_tagged\",\n description: \"Catch unexpected errors with Effect.catchTag\",\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n changeTracker.insertText(sourceFile, valueNode.getStart(), effectModuleIdentifier + \".catchTags(\")\n changeTracker.insertText(sourceFile, valueNode.getEnd(), \", \")\n changeTracker.insertNodeAt(\n sourceFile,\n valueNode.getEnd(),\n ts.factory.createObjectLiteralExpression(propertyAssignments)\n )\n changeTracker.insertText(sourceFile, valueNode.getEnd(), \")\")\n })\n })\n }\n }\n\n report(\n {\n location: node,\n messageText: `Missing '${\n sortTypes(result.missingErrorTypes).map((_) => typeChecker.typeToString(_)).join(\" | \")\n }' in the expected Effect errors.`,\n fixes\n }\n )\n }),\n Nano.ignore\n )\n }\n }\n })\n})\n","import { 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 TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const missingEffectServiceDependency = LSP.createDiagnostic({\n name: \"missingEffectServiceDependency\",\n code: 21,\n severity: \"off\",\n apply: Nano.fn(\"missingEffectServiceDependency.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\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\n // Check if this is a class declaration that extends Effect.Service\n if (ts.isClassDeclaration(node) && node.name && node.heritageClauses) {\n const serviceResult = yield* pipe(\n typeParser.extendsEffectService(node),\n Nano.orElse(() => Nano.void_)\n )\n\n if (serviceResult) {\n const { className, options } = serviceResult\n\n // Get the class symbol and its type\n const classSymbol = typeChecker.getSymbolAtLocation(className)\n if (classSymbol) {\n const classType = typeChecker.getTypeOfSymbol(classSymbol)\n\n // Try to get DefaultWithoutDependencies first, then Default\n const defaultWithoutDepsProperty = typeChecker.getPropertyOfType(classType, \"DefaultWithoutDependencies\")\n const defaultProperty = defaultWithoutDepsProperty || typeChecker.getPropertyOfType(classType, \"Default\")\n\n if (defaultProperty) {\n const defaultType = typeChecker.getTypeOfSymbolAtLocation(defaultProperty, node)\n\n // Parse the layer type to get RIN\n const layerResult = yield* pipe(\n typeParser.layerType(defaultType, node),\n Nano.orElse(() => Nano.void_)\n )\n\n if (layerResult) {\n // Use a single memory map for both required and provided services\n const servicesMemory = new Map<string, ts.Type>()\n const excludeNever = (type: ts.Type) => Nano.succeed((type.flags & ts.TypeFlags.Never) !== 0)\n\n // Get all required service indexes\n const { allIndexes: requiredIndexes } = yield* TypeCheckerApi.appendToUniqueTypesMap(\n servicesMemory,\n layerResult.RIn,\n excludeNever\n )\n\n // Process dependencies (treat undefined/null as empty array)\n const providedIndexes = new Set<string>()\n\n const optionsType = typeChecker.getTypeAtLocation(options)\n const dependenciesProperty = typeChecker.getPropertyOfType(optionsType, \"dependencies\")\n let types: Array<ts.Type> = []\n\n if (dependenciesProperty) {\n const dependenciesTypes = typeChecker.getTypeOfSymbolAtLocation(dependenciesProperty, options)\n const numberIndexType = dependenciesTypes.getNumberIndexType()\n types = numberIndexType ? TypeCheckerApi.unrollUnionMembers(numberIndexType) : []\n }\n\n // Process each dependency to get what services they provide\n for (const depType of types) {\n // Try to parse as layer type\n const depLayerResult = yield* pipe(\n typeParser.layerType(depType, options),\n Nano.orElse(() => Nano.void_)\n )\n\n if (depLayerResult) {\n // Add the ROut of this dependency to the same memory map\n const { allIndexes } = yield* TypeCheckerApi.appendToUniqueTypesMap(\n servicesMemory,\n depLayerResult.ROut,\n excludeNever\n )\n // Collect all provided indexes\n for (const index of allIndexes) {\n providedIndexes.add(index)\n }\n }\n }\n\n // Find missing services: required indexes not in provided indexes\n const missingIndexes = requiredIndexes.filter((index) => !providedIndexes.has(index))\n\n // Report diagnostic if there are missing dependencies\n if (missingIndexes.length > 0) {\n const missingTypes = missingIndexes.map((index) => servicesMemory.get(index)!)\n const missingTypeNames = missingTypes.map((t) => typeChecker.typeToString(t))\n\n const message = missingTypeNames.length === 1\n ? `Service '${missingTypeNames[0]}' is required but not provided by dependencies`\n : `Services ${\n missingTypeNames.map((s) => `'${s}'`).join(\", \")\n } are required but not provided by dependencies`\n\n report({\n location: className,\n messageText: message,\n fixes: []\n })\n }\n }\n }\n }\n }\n }\n\n ts.forEachChild(node, appendNodeToVisit)\n }\n })\n})\n","import { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeCheckerApi from \"../core/TypeCheckerApi.js\"\nimport * as TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const missingReturnYieldStar = LSP.createDiagnostic({\n name: \"missingReturnYieldStar\",\n code: 7,\n severity: \"error\",\n apply: Nano.fn(\"missingReturnYieldStar.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\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 // if we yield* an effect with never in success type, maybe we wanted tu return\n if (\n ts.isYieldExpression(node) && node.expression &&\n node.asteriskToken\n ) {\n // are we returning an effect with never as success type?\n const type = typeChecker.getTypeAtLocation(node.expression)\n const maybeEffect = yield* Nano.option(typeParser.effectType(type, node.expression))\n\n if (Option.isSome(maybeEffect) && maybeEffect.value.A.flags & ts.TypeFlags.Never) {\n // go up until we meet the causing generator\n const generatorFunctionOrReturnStatement = ts.findAncestor(\n node,\n (\n _\n ) => (ts.isFunctionExpression(_) || ts.isFunctionDeclaration(_) || ts.isMethodDeclaration(_) ||\n ts.isReturnStatement(_) || ts.isThrowStatement(_))\n )\n\n // we already have a return statement\n if (\n generatorFunctionOrReturnStatement && !ts.isReturnStatement(generatorFunctionOrReturnStatement) &&\n !ts.isThrowStatement(generatorFunctionOrReturnStatement)\n ) {\n // .gen should always be the parent ideally\n if (generatorFunctionOrReturnStatement && generatorFunctionOrReturnStatement.parent) {\n const effectGenNode = generatorFunctionOrReturnStatement.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 // emit diagnostic\n const fix = node.expression ?\n [{\n fixName: \"missingReturnYieldStar_fix\",\n description: \"Add return statement\",\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n changeTracker.replaceNode(\n sourceFile,\n node,\n ts.factory.createReturnStatement(\n node\n )\n )\n })\n }] :\n []\n\n report({\n location: node,\n messageText:\n `It is recommended to use return yield* for Effects that never succeed to signal a definitive exit point for type narrowing and tooling support.`,\n fixes: fix\n })\n }\n }\n }\n }\n }\n }\n })\n})\n","import { 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 TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const missingStarInYieldEffectGen = LSP.createDiagnostic({\n name: \"missingStarInYieldEffectGen\",\n code: 4,\n severity: \"error\",\n apply: Nano.fn(\"missingStarInYieldEffectGen.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\n\n const brokenGenerators = new Set<ts.Node>()\n const brokenYields = new Set<ts.YieldExpression>()\n\n const nodeToVisit: Array<ts.Node> = []\n const appendNodeToVisit = (node: ts.Node) => {\n nodeToVisit.push(node)\n return undefined\n }\n ts.forEachChild(sourceFile, appendNodeToVisit)\n\n while (nodeToVisit.length > 0) {\n const node = nodeToVisit.shift()!\n ts.forEachChild(node, appendNodeToVisit)\n\n // error if yield is not followed by *\n if (\n ts.isYieldExpression(node) && node.expression &&\n node.asteriskToken === undefined\n ) {\n // go up until we meet the causing generator\n const functionStarNode = ts.findAncestor(\n node,\n (_) => (ts.isFunctionExpression(_) || ts.isFunctionDeclaration(_) || ts.isMethodDeclaration(_))\n )\n\n // .gen should always be the parent ideally\n if (functionStarNode && functionStarNode.parent) {\n const effectGenNode = functionStarNode.parent\n // continue if we hit effect gen-like\n yield* pipe(\n typeParser.effectGen(effectGenNode),\n Nano.orElse(() => typeParser.effectFnUntracedGen(effectGenNode)),\n Nano.orElse(() => typeParser.effectFnGen(effectGenNode)),\n Nano.map(({ functionStar }) => {\n if (functionStar) {\n brokenGenerators.add(functionStar)\n }\n brokenYields.add(node)\n }),\n Nano.ignore\n )\n }\n }\n }\n\n // emit diagnostics\n brokenGenerators.forEach((node) =>\n report({\n location: node,\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 report({\n location: node,\n messageText: `When yielding Effects inside Effect.gen, you should use yield* instead of yield.`,\n fixes: fix\n })\n })\n })\n})\n","import { 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 TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as TypeScriptUtils from \"../core/TypeScriptUtils.js\"\n\nexport const multipleEffectProvide = LSP.createDiagnostic({\n name: \"multipleEffectProvide\",\n code: 18,\n severity: \"warning\",\n apply: Nano.fn(\"multipleEffectProvide.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const tsUtils = yield* Nano.service(TypeScriptUtils.TypeScriptUtils)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\n\n const effectModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(\n sourceFile,\n \"effect\",\n \"Effect\"\n ) || \"Effect\"\n\n const layerModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(\n sourceFile,\n \"effect\",\n \"Layer\"\n ) || \"Layer\"\n\n const parseEffectProvideLayer = (node: ts.Node) => {\n if (\n ts.isCallExpression(node) &&\n ts.isPropertyAccessExpression(node.expression) &&\n ts.isIdentifier(node.expression.name) &&\n node.expression.name.text === \"provide\" &&\n node.arguments.length > 0\n ) {\n const layer = node.arguments[0]\n const type = typeChecker.getTypeAtLocation(layer)\n return pipe(\n typeParser.importedEffectModule(node.expression.expression),\n Nano.flatMap(() => typeParser.layerType(type, layer)),\n Nano.map(() => ({ layer, node })),\n Nano.orElse(() => Nano.void_)\n )\n }\n return Nano.void_\n }\n\n const parsePipeCall = (node: ts.Node) =>\n Nano.gen(function*() {\n const { args } = yield* typeParser.pipeCall(node)\n let currentChunk = 0\n const previousLayers: Array<Array<{ layer: ts.Expression; node: ts.CallExpression }>> = [[]]\n for (const pipeArg of args) {\n const parsedProvide = yield* (parseEffectProvideLayer(pipeArg))\n if (parsedProvide) {\n previousLayers[currentChunk].push(parsedProvide)\n } else {\n currentChunk++\n previousLayers.push([])\n }\n }\n // report for each chunk\n for (const chunk of previousLayers) {\n if (chunk.length < 2) continue\n report({\n location: chunk[0].node,\n messageText:\n \"Avoid chaining Effect.provide calls, as this can lead to service lifecycle issues. Instead, merge layers and provide them in a single call.\",\n fixes: [{\n fixName: \"multipleEffectProvide_fix\",\n description: \"Combine into a single provide\",\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n changeTracker.deleteRange(sourceFile, {\n pos: chunk[0].node.getStart(sourceFile),\n end: chunk[chunk.length - 1].node.getEnd()\n })\n const newNode = ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectModuleIdentifier),\n ts.factory.createIdentifier(\"provide\")\n ),\n undefined,\n [ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(layerModuleIdentifier),\n ts.factory.createIdentifier(\"mergeAll\")\n ),\n undefined,\n chunk.map((c) => c.layer)\n )]\n )\n changeTracker.insertNodeAt(sourceFile, chunk[0].node.getStart(sourceFile), newNode)\n })\n }]\n })\n }\n })\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 if (ts.isCallExpression(node)) {\n yield* pipe(parsePipeCall(node), Nano.ignore)\n }\n }\n })\n})\n","import { pipe } from \"effect/Function\"\nimport type * as 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 TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as TypeScriptUtils from \"../core/TypeScriptUtils.js\"\n\nexport const generate = Nano.fn(\"writeTagClassAccessors.generate\")(function*(\n sourceFile: ts.SourceFile,\n service: ts.Type,\n className: ts.Identifier,\n atLocation: ts.ClassDeclaration,\n involvedMembers: Array<{ property: ts.Symbol; propertyType: ts.Type }>\n) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const tsUtils = yield* Nano.service(TypeScriptUtils.TypeScriptUtils)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n const insertLocation = atLocation.members.length > 0 ? atLocation.members[0].pos : atLocation.getEnd() - 1\n\n const effectIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(\n sourceFile,\n \"effect\",\n \"Effect\"\n ) || \"Effect\"\n\n const createFunctionProperty = (\n className: ts.Identifier,\n propertyName: string,\n type: ts.TypeNode,\n forceAny: boolean\n ) => {\n const arrowBody = ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(effectIdentifier),\n \"andThen\"\n ),\n undefined,\n [\n ts.factory.createIdentifier(className.text),\n ts.factory.createArrowFunction(\n undefined,\n undefined,\n [ts.factory.createParameterDeclaration(\n undefined,\n undefined,\n \"_\",\n undefined,\n forceAny ? ts.factory.createTypeReferenceNode(\"any\") : undefined\n )],\n undefined,\n undefined,\n ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(\"_\"),\n propertyName\n ),\n undefined,\n [\n ts.factory.createSpreadElement(ts.factory.createIdentifier(\"args\"))\n ]\n )\n )\n ]\n )\n return ts.factory.createPropertyDeclaration(\n [ts.factory.createModifier(ts.SyntaxKind.StaticKeyword)],\n propertyName,\n undefined,\n type,\n ts.factory.createArrowFunction(\n undefined,\n undefined,\n [ts.factory.createParameterDeclaration(\n undefined,\n ts.factory.createToken(ts.SyntaxKind.DotDotDotToken),\n \"args\",\n undefined,\n forceAny ? ts.factory.createArrayTypeNode(ts.factory.createTypeReferenceNode(\"any\")) : undefined\n )],\n undefined,\n undefined,\n forceAny ? ts.factory.createAsExpression(arrowBody, ts.factory.createTypeReferenceNode(\"any\")) : arrowBody\n )\n )\n }\n\n const generateReturnType = (type: ts.Type, atLocation: ts.ClassDeclaration, className: ts.Identifier) =>\n pipe(\n typeParser.effectType(type, atLocation),\n Nano.flatMap((returnedEffect) => {\n // the type is an effect, so we just need to add the service type to the context type\n const contextType = (returnedEffect.R.flags & ts.TypeFlags.Never) ?\n ts.factory.createTypeReferenceNode(className.text) :\n ts.factory.createUnionTypeNode(\n [\n ts.factory.createTypeReferenceNode(className.text),\n typeChecker.typeToTypeNode(returnedEffect.R, atLocation, ts.NodeBuilderFlags.NoTruncation)!\n ]\n )\n\n const successType = typeChecker.typeToTypeNode(\n returnedEffect.A,\n atLocation,\n ts.NodeBuilderFlags.NoTruncation\n )\n if (!successType) return Nano.fail(\"error generating success type\")\n\n const failureType = typeChecker.typeToTypeNode(\n returnedEffect.E,\n atLocation,\n ts.NodeBuilderFlags.NoTruncation\n )\n if (!failureType) return Nano.fail(\"error generating failure type\")\n\n const typeNode = ts.factory.createTypeReferenceNode(\n ts.factory.createQualifiedName(\n ts.factory.createIdentifier(effectIdentifier),\n ts.factory.createIdentifier(\"Effect\")\n ),\n [successType, failureType, contextType]\n )\n return Nano.succeed(typeNode)\n }),\n Nano.orElse(() =>\n pipe(\n typeParser.promiseLike(type, atLocation),\n Nano.flatMap(({ type }) => {\n const successType = typeChecker.typeToTypeNode(\n type,\n atLocation,\n ts.NodeBuilderFlags.NoTruncation\n )\n if (!successType) return Nano.fail(\"error generating success type\")\n return Nano.succeed(ts.factory.createTypeReferenceNode(\n ts.factory.createQualifiedName(\n ts.factory.createIdentifier(effectIdentifier),\n ts.factory.createIdentifier(\"Effect\")\n ),\n [\n successType,\n ts.factory.createTypeReferenceNode(\n ts.factory.createQualifiedName(\n ts.factory.createIdentifier(\"Cause\"),\n ts.factory.createIdentifier(\"UnknownException\")\n )\n ),\n ts.factory.createTypeReferenceNode(className.text)\n ]\n ))\n })\n )\n ),\n Nano.orElse(() => {\n // fallback to just converting A into a Effect<A, never, Service>\n const successType = typeChecker.typeToTypeNode(type, atLocation, ts.NodeBuilderFlags.NoTruncation)\n if (!successType) return Nano.fail(\"error generating success type\")\n const typeNode = ts.factory.createTypeReferenceNode(\n ts.factory.createQualifiedName(\n ts.factory.createIdentifier(effectIdentifier),\n ts.factory.createIdentifier(\"Effect\")\n ),\n [\n successType,\n ts.factory.createTypeReferenceNode(\"never\"),\n ts.factory.createTypeReferenceNode(className.text)\n ]\n )\n\n return Nano.succeed(typeNode)\n })\n )\n\n const proxySignature = (signature: ts.Signature, atLocation: ts.ClassDeclaration, className: ts.Identifier) =>\n Nano.gen(function*() {\n // generate the signature\n const signatureDeclaration = typeChecker.signatureToSignatureDeclaration(\n signature,\n ts.SyntaxKind.FunctionType,\n atLocation,\n ts.NodeBuilderFlags.NoTruncation\n )\n\n if (!signatureDeclaration) return yield* Nano.fail(\"error generating signature\")\n\n // wrap the return type as it would be in a Effect.andThen\n const returnType = yield* generateReturnType(signature.getReturnType(), atLocation, className)\n\n // construct the new signature\n return ts.factory.createFunctionTypeNode(\n signatureDeclaration.typeParameters,\n signatureDeclaration.parameters,\n returnType\n )\n })\n\n for (const { property, propertyType } of involvedMembers) {\n const callSignatures: Array<ts.FunctionTypeNode> = []\n let propertyDeclaration: ts.PropertyDeclaration | undefined = undefined\n for (const signature of propertyType.getCallSignatures()) {\n yield* pipe(\n proxySignature(signature, atLocation, className),\n Nano.map((sig) => {\n callSignatures.push(sig)\n }),\n Nano.ignore\n )\n }\n // this is a call signature:\n // static method: <A>(value: A) => Effect<A, never, Service> = (value) => Effect.andThen(Service, _ => _.method(value))\n const allSignatures = ts.factory.createIntersectionTypeNode(callSignatures)\n const type = tsUtils.simplifyTypeNode(allSignatures)\n propertyDeclaration = createFunctionProperty(className, property.getName(), type, callSignatures.length > 1)\n\n // then we need to delete the old property (if present)\n const oldProperty = atLocation.members.filter(ts.isPropertyDeclaration).find((p) => {\n const symbol = typeChecker.getSymbolAtLocation(p.name)\n return symbol?.getName() === property.getName()\n })\n if (oldProperty) {\n changeTracker.deleteRange(sourceFile, {\n pos: oldProperty.getStart(sourceFile),\n end: oldProperty.getEnd()\n })\n changeTracker.insertNodeAt(sourceFile, oldProperty.getStart(sourceFile), propertyDeclaration)\n } else {\n changeTracker.insertNodeAt(sourceFile, insertLocation, propertyDeclaration, { suffix: \"\\n\" })\n }\n }\n})\n\nexport const parse = Nano.fn(\"writeTagClassAccessors.parse\")(function*(node: ts.Node) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\n\n // only applicable to class declarations\n if (!ts.isClassDeclaration(node)) return yield* Nano.fail(\"not a class declaration\")\n\n const { Service, accessors, className } = yield* pipe(\n typeParser.extendsEffectService(node),\n Nano.orElse(() => Nano.fail(\"not a class extending Effect.Service call\"))\n )\n\n if (accessors !== true) return yield* Nano.fail(\"accessors are not enabled in the Effect.Service call\")\n\n const involvedMembers: Array<{ property: ts.Symbol; propertyType: ts.Type }> = []\n for (const property of typeChecker.getPropertiesOfType(Service)) {\n const propertyType = typeChecker.getTypeOfSymbolAtLocation(property, node)\n const callSignatures = propertyType.getCallSignatures()\n if (callSignatures.length > 0) {\n const withTypeParameters = callSignatures.filter((_) => _.typeParameters && _.typeParameters.length > 0)\n if (callSignatures.length > 1 || withTypeParameters.length > 0) involvedMembers.push({ property, propertyType })\n }\n }\n\n const hash = involvedMembers.map(({ property, propertyType }) => {\n return property.getName() + \": \" + typeChecker.typeToString(propertyType)\n }).concat([className.text]).join(\"\\n\")\n\n return { Service, className, atLocation: node, hash: LSP.cyrb53(hash), involvedMembers }\n})\n\nexport const writeTagClassAccessors = LSP.createRefactor({\n name: \"writeTagClassAccessors\",\n description: \"Implement accessors methods with generics or multiple signatures\",\n apply: Nano.fn(\"writeTagClassAccessors.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const tsUtils = yield* Nano.service(TypeScriptUtils.TypeScriptUtils)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\n\n const parseNode = (node: ts.Node) =>\n pipe(\n parse(node),\n Nano.map(({ Service, atLocation, className, involvedMembers }) => ({\n kind: \"refactor.rewrite.effect.writeTagClassAccessors\",\n description: \"Implement Service accessors\",\n apply: pipe(\n generate(sourceFile, Service, className, atLocation, involvedMembers),\n Nano.provideService(TypeScriptUtils.TypeScriptUtils, tsUtils),\n Nano.provideService(TypeParser.TypeParser, typeParser),\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, typeChecker),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts)\n )\n }))\n )\n\n const parentNodes = tsUtils.getAncestorNodesInRange(sourceFile, textRange)\n\n return yield* pipe(\n Nano.firstSuccessOf(parentNodes.map(parseNode)),\n Nano.orElse(() => Nano.fail(new LSP.RefactorNotApplicableError()))\n )\n })\n})\n","import { pipe } from \"effect/Function\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeCheckerApi from \"../core/TypeCheckerApi.js\"\nimport * as TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as TypeScriptUtils from \"../core/TypeScriptUtils.js\"\nimport * as refactor from \"../refactors/writeTagClassAccessors.js\"\n\nexport const accessors = LSP.createCodegen({\n name: \"accessors\",\n apply: Nano.fn(\"accessors.apply\")(function*(sourceFile, textRange) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const tsUtils = yield* Nano.service(TypeScriptUtils.TypeScriptUtils)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\n\n const nodeAndCommentRange = tsUtils.findNodeWithLeadingCommentAtPosition(sourceFile, textRange.pos)\n if (!nodeAndCommentRange) return yield* Nano.fail(new LSP.CodegenNotApplicableError(\"no node and comment range\"))\n\n return yield* pipe(\n refactor.parse(nodeAndCommentRange.node),\n Nano.map((_) =>\n ({\n hash: _.hash,\n description: \"Generate accessors for the service\",\n apply: pipe(\n refactor.generate(sourceFile, _.Service, _.className, _.atLocation, _.involvedMembers),\n Nano.provideService(TypeScriptApi.TypeScriptApi, ts),\n Nano.provideService(TypeScriptUtils.TypeScriptUtils, tsUtils),\n Nano.provideService(TypeCheckerApi.TypeCheckerApi, typeChecker),\n Nano.provideService(TypeParser.TypeParser, typeParser)\n )\n }) satisfies LSP.ApplicableCodegenDefinition\n ),\n Nano.orElse((cause) => Nano.fail(new LSP.CodegenNotApplicableError(cause)))\n )\n })\n})\n","import { accessors } from \"./codegens/accessors.js\"\n\nexport const codegens = [accessors]\n","import { pipe } from \"effect/Function\"\nimport { codegens } from \"../codegens.js\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\n\nexport const outdatedEffectCodegen = LSP.createDiagnostic({\n name: \"outdatedEffectCodegen\",\n code: 19,\n severity: \"warning\",\n apply: Nano.fn(\"outdatedEffectCodegen.apply\")(function*(sourceFile, _report) {\n const codegensWithRanges = yield* LSP.getCodegensForSourceFile(codegens, sourceFile)\n for (const { codegen, hash, range } of codegensWithRanges) {\n yield* pipe(\n LSP.getEditsForCodegen([codegen], sourceFile, range),\n Nano.map((applicable) => {\n if (applicable.hash !== hash) {\n _report({\n location: range,\n messageText: `Codegen ${codegen.name} result is outdated`,\n fixes: [\n {\n fixName: \"outdatedEffectCodegen_fix\",\n description: `Re-run ${codegen.name}`,\n apply: applicable.apply\n },\n {\n fixName: \"outdatedEffectCodegen_ignore\",\n description: `Ignore this ${codegen.name} update`,\n apply: applicable.ignore\n }\n ]\n })\n }\n }),\n Nano.orElse((e) =>\n Nano.sync(() => {\n _report({\n location: range,\n messageText: `Codegen ${codegen.name} is not applicable here: ${e.cause}`,\n fixes: []\n })\n })\n ),\n Nano.ignore\n )\n }\n })\n})\n","import { pipe } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type ts from \"typescript\"\nimport * as LSP from \"../core/LSP.js\"\nimport * as Nano from \"../core/Nano.js\"\nimport * as TypeCheckerApi from \"../core/TypeCheckerApi.js\"\nimport * as TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const returnEffectInGen = LSP.createDiagnostic({\n name: \"returnEffectInGen\",\n code: 11,\n severity: \"suggestion\",\n apply: Nano.fn(\"returnEffectInGen.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\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 // start from the return statement\n if (\n ts.isReturnStatement(node) && node.expression\n ) {\n // fast exit\n if (ts.isYieldExpression(node.expression)) continue\n\n // go up until we meet the causing generator/function\n const generatorOrRegularFunction = ts.findAncestor(\n node,\n (\n _\n ) => (ts.isFunctionExpression(_) || ts.isFunctionDeclaration(_) || ts.isMethodDeclaration(_) ||\n ts.isArrowFunction(_) || ts.isGetAccessor(_))\n )\n\n if (\n !(generatorOrRegularFunction && \"asteriskToken\" in generatorOrRegularFunction &&\n generatorOrRegularFunction.asteriskToken)\n ) continue // fast exit\n\n // are we returning an effect with never as success type?\n const type = typeChecker.getTypeAtLocation(node.expression)\n const maybeEffect = yield* Nano.option(typeParser.strictEffectType(type, node.expression))\n\n if (Option.isSome(maybeEffect)) {\n // .gen should always be the parent ideally\n if (generatorOrRegularFunction && generatorOrRegularFunction.parent) {\n const effectGenNode = generatorOrRegularFunction.parent\n // continue if we hit effect gen-like\n yield* pipe(\n typeParser.effectGen(effectGenNode),\n Nano.orElse(() => typeParser.effectFnUntracedGen(effectGenNode)),\n Nano.orElse(() => typeParser.effectFnGen(effectGenNode)),\n Nano.map(() => {\n const fix = node.expression ?\n [{\n fixName: \"returnEffectInGen_fix\",\n description: \"Add yield* statement\",\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n changeTracker.replaceNode(\n sourceFile,\n node.expression!,\n ts.factory.createYieldExpression(\n ts.factory.createToken(ts.SyntaxKind.AsteriskToken),\n node.expression!\n )\n )\n })\n }] :\n []\n\n report({\n location: node,\n messageText:\n `You are returning an Effect-able type inside a generator function, and will result in nested Effect<Effect<...>>.\\nMaybe you wanted to return yield* instead?\\nNested Effect-able types may be intended if you plan to later manually flatten or unwrap this Effect, if so you can safely disable this diagnostic for this line through quickfixes.`,\n fixes: fix\n })\n }),\n Nano.ignore\n )\n }\n }\n }\n }\n })\n})\n","import { 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 TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\nimport * as TypeScriptUtils from \"../core/TypeScriptUtils.js\"\n\nexport const scopeInLayerEffect = LSP.createDiagnostic({\n name: \"scopeInLayerEffect\",\n code: 13,\n severity: \"warning\",\n apply: Nano.fn(\"scopeInLayerEffect.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const tsUtils = yield* Nano.service(TypeScriptUtils.TypeScriptUtils)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\n\n const layerModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(\n sourceFile,\n \"effect\",\n \"Layer\"\n ) || \"Layer\"\n\n function parseLayerEffectApiCall(node: ts.Node): { methodIdentifier: ts.Identifier } | undefined {\n // should be a call expression of a property access like Layer.effect\n // we first check thats a call, then ensure that the callee is a property access\n // and that the property is \"effect\"\n if (!ts.isCallExpression(node)) return\n const expression = node.expression\n if (!ts.isPropertyAccessExpression(expression)) return\n // we check that the api is called on the Layer module\n const calledModule = expression.expression\n if (!(ts.isIdentifier(calledModule) && calledModule.text === layerModuleIdentifier)) return\n const methodIdentifier = expression.name\n // *.effect, *.effectContext, whatever...\n if (!(ts.isIdentifier(methodIdentifier) && methodIdentifier.text.toLowerCase().startsWith(\"effect\"))) return\n return { methodIdentifier }\n }\n\n const reportIfLayerRequireScope = (type: ts.Type, node: ts.Node, methodIdentifier: ts.Identifier | undefined) => {\n let toCheck = [type]\n const entries: Array<ts.Type> = []\n while (toCheck.length > 0) {\n const type = toCheck.pop()!\n if (type.isUnion()) {\n toCheck = toCheck.concat(type.types)\n } else {\n entries.push(type)\n }\n }\n return pipe(\n Nano.firstSuccessOf(entries.map((type) => typeParser.scopeType(type, node))),\n Nano.map(() =>\n report({\n location: node,\n messageText:\n `Seems like you are constructing a layer with a scope in the requirements.\\nConsider using \"scoped\" instead to get rid of the scope in the requirements.`,\n fixes: methodIdentifier ?\n [{\n fixName: \"scopeInLayerEffect_scoped\",\n description: \"Use scoped for Layer creation\",\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n changeTracker.replaceNode(\n sourceFile,\n methodIdentifier,\n ts.factory.createIdentifier(\"scoped\")\n )\n })\n }] :\n []\n })\n ),\n Nano.ignore\n )\n }\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\n const layerEffectApiCall = parseLayerEffectApiCall(node)\n if (layerEffectApiCall) {\n const type = typeChecker.getTypeAtLocation(node)\n yield* pipe(\n typeParser.layerType(type, node),\n Nano.flatMap(({ RIn }) => reportIfLayerRequireScope(RIn, node, layerEffectApiCall.methodIdentifier)),\n Nano.ignore\n )\n continue\n }\n\n if (ts.isClassDeclaration(node) && node.name && node.heritageClauses) {\n const classSym = typeChecker.getSymbolAtLocation(node.name)\n if (classSym) {\n const classType = typeChecker.getTypeOfSymbol(classSym)\n const defaultLayer = typeChecker.getPropertyOfType(classType, \"Default\")\n if (defaultLayer) {\n const type = typeChecker.getTypeOfSymbolAtLocation(defaultLayer, node)\n yield* pipe(\n typeParser.layerType(type, node),\n Nano.flatMap(({ RIn }) => reportIfLayerRequireScope(RIn, node, undefined)),\n Nano.ignore\n )\n continue\n }\n }\n }\n\n ts.forEachChild(node, appendNodeToVisit)\n }\n })\n})\n","import 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\"\n\nexport const strictBooleanExpressions = LSP.createDiagnostic({\n name: \"strictBooleanExpressions\",\n code: 17,\n severity: \"off\",\n apply: Nano.fn(\"strictBooleanExpressions.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeChecker = yield* Nano.service(TypeCheckerApi.TypeCheckerApi)\n const conditionChecks = new WeakMap<ts.Node, boolean>()\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 nodes: Array<ts.Node> = []\n if (ts.isIfStatement(node)) {\n conditionChecks.set(node, true)\n nodes.push(node.expression)\n } else if (ts.isWhileStatement(node)) {\n conditionChecks.set(node, true)\n nodes.push(node.expression)\n } else if (ts.isConditionalExpression(node)) {\n conditionChecks.set(node, true)\n nodes.push(node.condition)\n } else if (ts.isPrefixUnaryExpression(node) && node.operator === ts.SyntaxKind.ExclamationToken) {\n conditionChecks.set(node, true)\n nodes.push(node.operand)\n } else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.BarBarToken) {\n if (conditionChecks.has(node.parent)) conditionChecks.set(node, true)\n nodes.push(node.left)\n nodes.push(node.right)\n } else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken) {\n if (conditionChecks.has(node.parent)) conditionChecks.set(node, true)\n nodes.push(node.left)\n nodes.push(node.right)\n }\n\n for (const nodeToCheck of nodes) {\n if (!nodeToCheck) continue\n if (!conditionChecks.has(nodeToCheck.parent)) continue\n\n const nodeType = typeChecker.getTypeAtLocation(nodeToCheck)\n const constrainedType = typeChecker.getBaseConstraintOfType(nodeType)\n let typesToCheck = [constrainedType || nodeType]\n\n while (typesToCheck.length > 0) {\n const type = typesToCheck.pop()!\n\n // unroll union types\n if (type.isUnion()) {\n typesToCheck = typesToCheck.concat(type.types)\n continue\n }\n\n // skip boolean and never types\n if (type.flags & ts.TypeFlags.Boolean) continue\n if (type.flags & ts.TypeFlags.Never) continue\n if (type.flags & ts.TypeFlags.BooleanLiteral) continue\n\n // report the error\n const typeName = typeChecker.typeToString(type)\n report({\n location: nodeToCheck,\n messageText: `Unexpected \\`${typeName}\\` type in condition, expected strictly a boolean instead.`,\n fixes: []\n })\n }\n }\n }\n })\n})\n","import { 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 TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const tryCatchInEffectGen = LSP.createDiagnostic({\n name: \"tryCatchInEffectGen\",\n code: 15,\n severity: \"suggestion\",\n apply: Nano.fn(\"tryCatchInEffectGen.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\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 // Check if this is a try statement\n if (ts.isTryStatement(node)) {\n // Find the containing generator function\n // go up until we meet the causing generator/function\n const generatorOrRegularFunction = ts.findAncestor(\n node,\n (\n _\n ) => (ts.isFunctionExpression(_) || ts.isFunctionDeclaration(_) || ts.isMethodDeclaration(_) ||\n ts.isArrowFunction(_) || ts.isGetAccessor(_) || ts.isFunctionLike(_))\n )\n\n if (\n !(generatorOrRegularFunction && \"asteriskToken\" in generatorOrRegularFunction &&\n generatorOrRegularFunction.asteriskToken)\n ) continue // fast exit\n\n if (!generatorOrRegularFunction) continue\n\n // Check if we're inside Effect.gen or Effect.fn\n if (generatorOrRegularFunction && generatorOrRegularFunction.parent) {\n const effectGenNode = generatorOrRegularFunction.parent\n\n // Check if this generator is inside Effect.gen/Effect.fn\n yield* pipe(\n typeParser.effectGen(effectGenNode),\n Nano.orElse(() => typeParser.effectFnUntracedGen(effectGenNode)),\n Nano.orElse(() => typeParser.effectFnGen(effectGenNode)),\n Nano.map(() => {\n report({\n location: node,\n messageText:\n \"Avoid using try/catch inside Effect generators. Use Effect's error handling mechanisms instead (e.g., Effect.try, Effect.tryPromise, Effect.catchAll, Effect.catchTag).\",\n fixes: []\n })\n }),\n Nano.ignore\n )\n }\n }\n }\n })\n})\n","import { 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 TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const unnecessaryEffectGen = LSP.createDiagnostic({\n name: \"unnecessaryEffectGen\",\n code: 5,\n severity: \"suggestion\",\n apply: Nano.fn(\"unnecessaryEffectGen.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\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 if (ts.isCallExpression(node)) {\n yield* pipe(\n typeParser.unnecessaryEffectGen(node),\n Nano.map(({ replacementNode }) =>\n report({\n location: node,\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, node, yield* replacementNode)\n })\n }]\n })\n ),\n Nano.ignore\n )\n }\n }\n })\n})\n","import { 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 TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const unnecessaryPipe = LSP.createDiagnostic({\n name: \"unnecessaryPipe\",\n code: 9,\n severity: \"suggestion\",\n apply: Nano.fn(\"unnecessaryPipe.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\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 if (ts.isCallExpression(node)) {\n yield* pipe(\n typeParser.pipeCall(node),\n Nano.map(({ args, subject }) => {\n if (args.length === 0) {\n report({\n location: node,\n messageText: `This pipe call contains no arguments.`,\n fixes: [{\n fixName: \"unnecessaryPipe_fix\",\n description: \"Remove the pipe call\",\n apply: Nano.gen(function*() {\n const textChanges = yield* Nano.service(\n TypeScriptApi.ChangeTracker\n )\n textChanges.replaceNode(sourceFile, node, subject)\n })\n }]\n })\n }\n }),\n Nano.ignore\n )\n }\n }\n })\n})\n","import { 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 TypeParser from \"../core/TypeParser.js\"\nimport * as TypeScriptApi from \"../core/TypeScriptApi.js\"\n\nexport const unnecessaryPipeChain = LSP.createDiagnostic({\n name: \"unnecessaryPipeChain\",\n code: 16,\n severity: \"suggestion\",\n apply: Nano.fn(\"unnecessaryPipeChain.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\n const typeParser = yield* Nano.service(TypeParser.TypeParser)\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 if (ts.isCallExpression(node)) {\n yield* pipe(\n typeParser.pipeCall(node),\n Nano.flatMap((pipeCall) =>\n Nano.map(typeParser.pipeCall(pipeCall.subject), (innerCall) => ({ pipeCall, innerCall }))\n ),\n Nano.map(({ innerCall, pipeCall }) => {\n report({\n location: node,\n messageText: `Chained pipe calls can be simplified to a single pipe call`,\n fixes: [{\n fixName: \"unnecessaryPipeChain_fix\",\n description: \"Rewrite as single pipe call\",\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(\n TypeScriptApi.ChangeTracker\n )\n switch (innerCall.kind) {\n case \"pipe\": {\n changeTracker.replaceNode(\n sourceFile,\n node,\n ts.factory.createCallExpression(\n ts.factory.createIdentifier(\"pipe\"),\n undefined,\n [innerCall.subject, ...innerCall.args, ...pipeCall.args]\n )\n )\n break\n }\n case \"pipeable\": {\n changeTracker.replaceNode(\n sourceFile,\n node,\n ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n innerCall.subject,\n \"pipe\"\n ),\n undefined,\n [...innerCall.args, ...pipeCall.args]\n )\n )\n break\n }\n }\n })\n }]\n })\n }),\n Nano.ignore\n )\n }\n }\n })\n})\n","import { pipe } from \"effect\"\nimport type * as 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 writeTagClassAccessors from \"../refactors/writeTagClassAccessors.js\"\n\nexport const unsupportedServiceAccessors = LSP.createDiagnostic({\n name: \"unsupportedServiceAccessors\",\n code: 21,\n severity: \"warning\",\n apply: Nano.fn(\"unsupportedServiceAccessors.apply\")(function*(sourceFile, report) {\n const ts = yield* Nano.service(TypeScriptApi.TypeScriptApi)\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 // Check if this is a class declaration that might use unsupported service accessors\n if (ts.isClassDeclaration(node)) {\n const parseResult = yield* pipe(\n writeTagClassAccessors.parse(node),\n Nano.orElse(() => Nano.succeed(null))\n )\n\n if (parseResult && parseResult.involvedMembers.length > 0) {\n // Get existing static members in the class\n const existingStaticMembers = new Set<string>()\n node.members?.forEach((member) => {\n if (\n ts.isPropertyDeclaration(member) &&\n member.modifiers?.some((mod) => mod.kind === ts.SyntaxKind.StaticKeyword)\n ) {\n if (member.name && ts.isIdentifier(member.name)) {\n existingStaticMembers.add(member.name.text)\n }\n }\n })\n\n // Filter out members that already have static implementations\n const missingMembers = parseResult.involvedMembers.filter(({ property }) =>\n !existingStaticMembers.has(property.getName())\n )\n\n if (missingMembers.length > 0) {\n const memberNames = missingMembers.map(({ property }) => `'${property.getName()}'`).join(\", \")\n\n report({\n location: parseResult.className,\n messageText:\n `Even if accessors are enabled, accessors for ${memberNames} won't be available because the signature have generic type parameters or multiple call signatures.`,\n fixes: [{\n fixName: \"unsupportedServiceAccessors_enableCodegen\",\n description: \"Enable accessors codegen\",\n apply: Nano.gen(function*() {\n const changeTracker = yield* Nano.service(TypeScriptApi.ChangeTracker)\n\n // Add @effect-codegens comment before the class\n const comment = \"// @effect-codegens accessors\\n\"\n changeTracker.insertText(sourceFile, node.getStart(sourceFile), comment)\n })\n }]\n })\n }\n }\n }\n }\n })\n})\n","import { classSelfMismatch } from \"./diagnostics/classSelfMismatch.js\"\nimport { duplicatePackage } from \"./diagnostics/duplicatePackage.js\"\nimport { effectInVoidSuccess } from \"./diagnostics/effectInVoidSuccess.js\"\nimport { floatingEffect } from \"./diagnostics/floatingEffect.js\"\nimport { genericEffectServices } from \"./diagnostics/genericEffectServices.js\"\nimport { importFromBarrel } from \"./diagnostics/importFromBarrel.js\"\nimport { leakingRequirements } from \"./diagnostics/leakingRequirements.js\"\nimport { missingEffectContext } from \"./diagnostics/missingEffectContext.js\"\nimport { missingEffectError } from \"./diagnostics/missingEffectError.js\"\nimport { missingEffectServiceDependency } from \"./diagnostics/missingEffectServiceDependency.js\"\nimport { missingReturnYieldStar } from \"./diagnostics/missingReturnYieldStar.js\"\nimport { missingStarInYieldEffectGen } from \"./diagnostics/missingStarInYieldEffectGen.js\"\nimport { multipleEffectProvide } from \"./diagnostics/multipleEffectProvide.js\"\nimport { outdatedEffectCodegen } from \"./diagnostics/outdatedEffectCodegen.js\"\nimport { returnEffectInGen } from \"./diagnostics/returnEffectInGen.js\"\nimport { scopeInLayerEffect } from \"./diagnostics/scopeInLayerEffect.js\"\nimport { strictBooleanExpressions } from \"./diagnostics/strictBooleanExpressions.js\"\nimport { tryCatchInEffectGen } from \"./diagnostics/tryCatchInEffectGen.js\"\nimport { unnecessaryEffectGen } from \"./diagnostics/unnecessaryEffectGen.js\"\nimport { unnecessaryPipe } from \"./diagnostics/unnecessaryPipe.js\"\nimport { unnecessaryPipeChain } from \"./diagnostics/unnecessaryPipeChain.js\"\nimport { unsupportedServiceAccessors } from \"./diagnostics/unsupportedServiceAccessors.js\"\n\nexport const diagnostics = [\n classSelfMismatch,\n duplicatePackage,\n missingEffectContext,\n missingEffectError,\n missingEffectServiceDependency,\n floatingEffect,\n missingStarInYieldEffectGen,\n unnecessaryEffectGen,\n missingReturnYieldStar,\n leakingRequirements,\n unnecessaryPipe,\n genericEffectServices,\n returnEffectInGen,\n tryCatchInEffectGen,\n importFromBarrel,\n scopeInLayerEffect,\n effectInVoidSuccess,\n unnecessaryPipeChain,\n strictBooleanExpressions,\n multipleEffectProvide,\n outdatedEffectCodegen,\n unsupportedServiceAccessors\n]\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC4BO,IAAMA,aAAcC,WAAsC,OAAOA,UAAU;AAkE3E,IAAMC,OAmIT,SAASC,OAAOC,MAAI;AACtB,MAAI,OAAOD,UAAU,YAAY;AAC/B,WAAO,WAAA;AACL,UAAIA,MAAME,SAAS,GAAG;AAEpB,eAAOD,KAAKE,MAAM,MAAMD,SAAS;MACnC;AACA,aAASE,UAAcH,KAAKG,MAAM,GAAGF,SAAS;IAChD;EACF;AAEA,UAAQF,OAAK;IACX,KAAK;IACL,KAAK;AACH,YAAM,IAAIK,WAAW,iBAAiBL,KAAK,EAAE;IAE/C,KAAK;AACH,aAAO,SAASM,GAAGC,GAAC;AAClB,YAAIL,UAAUM,UAAU,GAAG;AACzB,iBAAOP,KAAKK,GAAGC,CAAC;QAClB;AACA,eAAO,SAASH,MAAS;AACv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AE,WAAW;AAAA,MACxB;AAAA,QACC;AAAA,UAAO,CAAC,MACZ,EAAE,aAAa,WAAW,mBAAmB,SAC7C,EAAE,aAAa,WAAW,mBAAmB;AAAA,QAC/C;AAAA,MACF;AAAA,MACO,UAAU,MAAM,CAAC,CAAC;AAAA,MACnBE,KAAI,aAAa;AAAA,IACzB;AAAA,EACF;AAGA,QAAM,gBAAgB,QAAQ,iBAAiB;AAC/C,QAAM,cAAc,QAAQ,eAAe,EAAE,OAAO,CAAC,MAAM,cAAc,QAAQ,EAAE,QAAQ,IAAI,EAAE;AACjG,aAAW,cAAc,aAAa;AACpC,mBAAe,SAAS,UAAU;AAAA,EACpC;AAEA,SAAO,CAAC,MAAgC,CAAC,eAA8B;AAErE,mBAAe,SAAS,UAAU;AAClC,WAAO;AAAA,EACT;AACF;","names":["isFunction","input","dual","arity","body","arguments","apply","self","RangeError","a","b","length","c","d","e","args","identity","a","pipe","a","ab","bc","cd","de","ef","fg","gh","hi","arguments","length","ret","i","globalStoreId","globalStore","globalValue","id","compute","globalThis","Map","has","set","get","isString","input","isNumber","isBoolean","isFunction","isFunction_","isRecordOrArray","input","isObject","isFunction","hasProperty","dual","self","property","isRecord","input","isRecordOrArray","Array","isArray","getBugErrorMessage","message","GenKindTypeId","Symbol","for","GenKindImpl","value","constructor","_F","identity","_R","_","_O","_E","GenKindTypeId","Symbol","iterator","SingleShotGen","self","called","next","a","done","return","throw","e","MUL_HI","MUL_LO","YieldWrapTypeId","Symbol","for","YieldWrap","constructor","value","yieldWrapGet","self","Error","getBugErrorMessage","structuralRegionState","globalValue","enabled","tester","undefined","standard","effect_internal_function","body","forced","isNotOptimizedAway","Error","stack","includes","internalCall","genConstructor","constructor","randomHashCache","globalValue","Symbol","for","WeakMap","symbol","hash","self","structuralRegionState","enabled","number","string","toString","String","Date","toISOString","URL","href","isHash","random","Error","has","set","Math","floor","Number","MAX_SAFE_INTEGER","get","combine","b","optimize","n","u","hasProperty","Infinity","h","str","i","length","charCodeAt","structureKeys","o","keys","pipe","structure","Object","cached","arguments","length","self","hash","Object","defineProperty","symbol","value","enumerable","symbol","Symbol","for","equals","arguments","length","self","compareBoth","that","selfType","isEqual","hash","structuralRegionState","enabled","tester","Date","toISOString","URL","href","Array","isArray","every","v","i","Object","getPrototypeOf","prototype","keysSelf","keys","keysThat","key","u","hasProperty","equivalence","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","moduleVersion","getCurrentVersion","EffectTypeId","Symbol","for","StreamTypeId","SinkTypeId","ChannelTypeId","effectVariance","_R","_","_E","_A","_V","version","getCurrentVersion","sinkVariance","_In","_L","channelVariance","_Env","_InErr","_InElem","_InDone","_OutErr","_OutElem","_OutDone","EffectPrototype","symbol","that","cached","random","iterator","SingleShotGen","YieldWrap","pipe","pipeArguments","arguments","StructuralPrototype","structure","selfKeys","Object","keys","thatKeys","length","key","equals","CommitPrototype","_op","OP_COMMIT","StructuralCommitPrototype","TypeId","Symbol","for","CommonProto","EffectPrototype","_A","_","NodeInspectSymbol","toJSON","toString","format","SomeProto","Object","assign","create","_tag","_op","symbol","that","isOption","isSome","equals","value","cached","combine","hash","_id","NoneHash","Hash","NoneProto","isNone","input","hasProperty","fa","none","some","a","TypeId","Symbol","for","CommonProto","EffectPrototype","_R","_","NodeInspectSymbol","toJSON","toString","format","RightProto","Object","assign","create","_tag","_op","symbol","that","isEither","isRight","equals","right","combine","hash","_id","LeftProto","isLeft","left","input","hasProperty","ma","a","right","left","isLeft","isRight","map","dual","self","f","isRight","right","left","getOrElse","dual","self","onLeft","isLeft","left","right","isNonEmptyArray","self","length","make","compare","self","that","string","none","some","isNone","isSome","orElse","dual","self","that","isNone","fromNullable","nullableValue","none","some","fromIterable","collection","Array","isArray","from","append","dual","self","last","appendAll","that","fromIterable","concat","isArray","Array","isEmptyArray","self","length","isEmptyReadonlyArray","isNonEmptyReadonlyArray","isNonEmptyArray","isOutOfBounds","i","as","length","unsafeGet","dual","self","index","i","Math","floor","isOutOfBounds","Error","headNonEmpty","unsafeGet","tailNonEmpty","self","slice","sort","dual","self","O","out","Array","from","containsWith","isEquivalent","dual","self","a","i","_equivalence","Equal","equivalence","intersectionWith","isEquivalent","has","containsWith","dual","self","that","fromIterable","filter","a","intersection","_equivalence","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","dedupe","equivalence","fn","symbol","right","left","flatMap","map","args","orElse","arr","cont","cached","some","none","map","flatMap","map","isFunction","none","some","isNone","isSome","typeNode","diagnostics","isSome","refactor","node","match","flatMap","codegens","codegen","map","symbol","isSome","type","nanoLayer","make","map","orElse","isSome","unnecessaryEffectGen","args","symbol","type","flatMap","accessors","orElse","map","isSome","orElse","isNone","map","orElse","sourceFile","service","map","orElse","flatMap","flatMap","map","flatMap","map","string","orElse","isSome","orElse","orElse","map","flatMap","map","orElse","args","service","className","atLocation","flatMap","orElse","type","map","symbol","parse","accessors","hash","parse","map","orElse","hash","map","orElse","isSome","orElse","map","type","map","flatMap","orElse","map","map","map","args","flatMap","map","parse","orElse","program","nanoLayer","map"]}
|