diff --git a/.changeset/olive-pants-sparkle.md b/.changeset/olive-pants-sparkle.md new file mode 100644 index 0000000000..6ea830d44f --- /dev/null +++ b/.changeset/olive-pants-sparkle.md @@ -0,0 +1,17 @@ +--- +"@effect/platform-node-shared": minor +"@effect/typeclass": minor +"effect": minor +"@effect/schema": minor +"@effect/cli": minor +--- + +Swap type params of Either from `Either` to `Either`. + +Along the same line of the other changes this allows to shorten the most common types such as: + +```ts +import { Either } from "effect"; + +const right: Either.Either = Either.right("ok"); +``` diff --git a/packages/cli/src/Options.ts b/packages/cli/src/Options.ts index ecb9247964..549a588575 100644 --- a/packages/cli/src/Options.ts +++ b/packages/cli/src/Options.ts @@ -419,8 +419,8 @@ export const orElse: { * @category combinators */ export const orElseEither: { - (that: Options): (self: Options) => Options> - (self: Options, that: Options): Options> + (that: Options): (self: Options) => Options> + (self: Options, that: Options): Options> } = InternalOptions.orElseEither /** diff --git a/packages/cli/src/internal/options.ts b/packages/cli/src/internal/options.ts index b201b6b22d..4a26d783b7 100644 --- a/packages/cli/src/internal/options.ts +++ b/packages/cli/src/internal/options.ts @@ -505,8 +505,8 @@ export const orElse = dual< export const orElseEither = dual< ( that: Options.Options - ) => (self: Options.Options) => Options.Options>, - (self: Options.Options, that: Options.Options) => Options.Options> + ) => (self: Options.Options) => Options.Options>, + (self: Options.Options, that: Options.Options) => Options.Options> >(2, (self, that) => makeOrElse(self, that)) /** @internal */ @@ -980,7 +980,7 @@ const makeMap = ( const makeOrElse = ( left: Options.Options, right: Options.Options -): Options.Options> => { +): Options.Options> => { const op = Object.create(proto) op._tag = "OrElse" op.left = left diff --git a/packages/effect/dtslint/Effect.ts b/packages/effect/dtslint/Effect.ts index 4ef39a2a40..0af440981b 100644 --- a/packages/effect/dtslint/Effect.ts +++ b/packages/effect/dtslint/Effect.ts @@ -84,7 +84,7 @@ Effect.all([string, number], { mode: "validate" }) // $ExpectType Effect, Option<"err-2">], "dep-1" | "dep-2"> Effect.all([string, number], { mode: "validate", discard: true }) -// $ExpectType Effect<[Either<"err-1", string>, Either<"err-2", number>], never, "dep-1" | "dep-2"> +// $ExpectType Effect<[Either, Either], never, "dep-1" | "dep-2"> Effect.all([string, number], { mode: "either" }) // $ExpectType Effect @@ -118,7 +118,7 @@ Effect.all({ a: string, b: number }, { mode: "validate" }) // $ExpectType Effect; b: Option<"err-2">; }, "dep-1" | "dep-2"> Effect.all({ a: string, b: number }, { mode: "validate", discard: true }) -// $ExpectType Effect<{ a: Either<"err-1", string>; b: Either<"err-2", number>; }, never, "dep-1" | "dep-2"> +// $ExpectType Effect<{ a: Either; b: Either; }, never, "dep-1" | "dep-2"> Effect.all({ a: string, b: number }, { mode: "either" }) // $ExpectType Effect @@ -152,7 +152,7 @@ Effect.all(stringArray, { mode: "validate" }) // $ExpectType Effect[], "dep-3"> Effect.all(stringArray, { mode: "validate", discard: true }) -// $ExpectType Effect[], never, "dep-3"> +// $ExpectType Effect[], never, "dep-3"> Effect.all(stringArray, { mode: "either" }) // $ExpectType Effect @@ -186,7 +186,7 @@ Effect.all(numberRecord, { mode: "validate" }) // $ExpectType Effect; }, "dep-4"> Effect.all(numberRecord, { mode: "validate", discard: true }) -// $ExpectType Effect<{ [x: string]: Either<"err-4", number>; }, never, "dep-4"> +// $ExpectType Effect<{ [x: string]: Either; }, never, "dep-4"> Effect.all(numberRecord, { mode: "either" }) // $ExpectType Effect @@ -220,7 +220,7 @@ pipe([string, number] as const, Effect.allWith({ mode: "validate" })) // $ExpectType Effect, Option<"err-2">], "dep-1" | "dep-2"> pipe([string, number] as const, Effect.allWith({ mode: "validate", discard: true })) -// $ExpectType Effect<[Either<"err-1", string>, Either<"err-2", number>], never, "dep-1" | "dep-2"> +// $ExpectType Effect<[Either, Either], never, "dep-1" | "dep-2"> pipe([string, number] as const, Effect.allWith({ mode: "either" })) // $ExpectType Effect @@ -254,7 +254,7 @@ pipe({ a: string, b: number }, Effect.allWith({ mode: "validate" })) // $ExpectType Effect; b: Option<"err-2">; }, "dep-1" | "dep-2"> pipe({ a: string, b: number }, Effect.allWith({ mode: "validate", discard: true })) -// $ExpectType Effect<{ a: Either<"err-1", string>; b: Either<"err-2", number>; }, never, "dep-1" | "dep-2"> +// $ExpectType Effect<{ a: Either; b: Either; }, never, "dep-1" | "dep-2"> pipe({ a: string, b: number }, Effect.allWith({ mode: "either" })) // $ExpectType Effect @@ -288,7 +288,7 @@ pipe(stringArray, Effect.allWith({ mode: "validate" })) // $ExpectType Effect[], "dep-3"> pipe(stringArray, Effect.allWith({ mode: "validate", discard: true })) -// $ExpectType Effect[], never, "dep-3"> +// $ExpectType Effect[], never, "dep-3"> pipe(stringArray, Effect.allWith({ mode: "either" })) // $ExpectType Effect @@ -322,7 +322,7 @@ pipe(numberRecord, Effect.allWith({ mode: "validate" })) // $ExpectType Effect; }, "dep-4"> pipe(numberRecord, Effect.allWith({ mode: "validate", discard: true })) -// $ExpectType Effect<{ [x: string]: Either<"err-4", number>; }, never, "dep-4"> +// $ExpectType Effect<{ [x: string]: Either; }, never, "dep-4"> pipe(numberRecord, Effect.allWith({ mode: "either" })) // $ExpectType Effect diff --git a/packages/effect/dtslint/Either.ts b/packages/effect/dtslint/Either.ts index 426ba6d3fc..64341c340e 100644 --- a/packages/effect/dtslint/Either.ts +++ b/packages/effect/dtslint/Either.ts @@ -4,11 +4,11 @@ import * as Predicate from "effect/Predicate" import * as ReadonlyArray from "effect/ReadonlyArray" declare const string$string: Either.Either -declare const string$number: Either.Either -declare const string$boolean: Either.Either -declare const error$boolean: Either.Either +declare const string$number: Either.Either +declare const string$boolean: Either.Either +declare const error$boolean: Either.Either -declare const error$a: Either.Either +declare const error$a: Either.Either<"a", Error> declare const predicateUnknown: Predicate.Predicate @@ -16,107 +16,107 @@ declare const predicateUnknown: Predicate.Predicate // flip // ------------------------------------------------------------------------------------- -// $ExpectType Either +// $ExpectType Either Either.flip(string$number) // ------------------------------------------------------------------------------------- // try // ------------------------------------------------------------------------------------- -// $ExpectType Either +// $ExpectType Either Either.try(() => 1) -// $ExpectType Either +// $ExpectType Either Either.try({ try: () => 1, catch: () => new Error() }) // ------------------------------------------------------------------------------------- // all - tuple // ------------------------------------------------------------------------------------- -// $ExpectType Either +// $ExpectType Either<[], never> Either.all([]) -// $ExpectType Either +// $ExpectType Either<[number], string> Either.all([string$number]) -// $ExpectType Either +// $ExpectType Either<[number, boolean], string> Either.all([string$number, string$boolean]) -// $ExpectType Either +// $ExpectType Either<[number, boolean], string | Error> Either.all([string$number, error$boolean]) -// $ExpectType Either +// $ExpectType Either<[number, boolean], string> pipe([string$number, string$boolean] as const, Either.all) -// $ExpectType Either +// $ExpectType Either<[number, boolean], string | Error> pipe([string$number, error$boolean] as const, Either.all) // ------------------------------------------------------------------------------------- // all - struct // ------------------------------------------------------------------------------------- -// $ExpectType Either +// $ExpectType Either<{}, never> Either.all({}) -// $ExpectType Either +// $ExpectType Either<{ a: number; }, string> Either.all({ a: string$number }) -// $ExpectType Either +// $ExpectType Either<{ a: number; b: boolean; }, string> Either.all({ a: string$number, b: string$boolean }) -// $ExpectType Either +// $ExpectType Either<{ a: number; b: boolean; }, string | Error> Either.all({ a: string$number, b: error$boolean }) -// $ExpectType Either +// $ExpectType Either<{ a: number; b: boolean; }, string> pipe({ a: string$number, b: string$boolean }, Either.all) -// $ExpectType Either +// $ExpectType Either<{ a: number; b: boolean; }, string | Error> pipe({ a: string$number, b: error$boolean }, Either.all) // ------------------------------------------------------------------------------------- // all - array // ------------------------------------------------------------------------------------- -declare const eitherArray: Array> +declare const eitherArray: Array> -// $ExpectType Either +// $ExpectType Either Either.all(eitherArray) -// $ExpectType Either +// $ExpectType Either pipe(eitherArray, Either.all) // ------------------------------------------------------------------------------------- // all - record // ------------------------------------------------------------------------------------- -declare const eitherRecord: Record> +declare const eitherRecord: Record> -// $ExpectType Either +// $ExpectType Either<{ [x: string]: number; }, string> Either.all(eitherRecord) // ------------------------------------------------------------------------------------- // andThen // ------------------------------------------------------------------------------------- -// $ExpectType Either +// $ExpectType Either Either.andThen(string$string, string$number) -// $ExpectType Either +// $ExpectType Either Either.andThen(string$string, () => string$number) -// $ExpectType Either +// $ExpectType Either string$string.pipe(Either.andThen(string$number)) -// $ExpectType Either +// $ExpectType Either string$string.pipe(Either.andThen(() => string$number)) // ------------------------------------------------------------------------------------- // filterOrLeft // ------------------------------------------------------------------------------------- -declare const error$arrayOfStrings: Either.Either> +declare const error$arrayOfStrings: Either.Either, Error> -// $ExpectType Either<"b" | Error, [string, ...string[]]> +// $ExpectType Either<[string, ...string[]], "b" | Error> pipe( error$arrayOfStrings, Either.filterOrLeft(ReadonlyArray.isNonEmptyArray, ( @@ -124,9 +124,9 @@ pipe( ) => "b" as const) ) -declare const error$readonlyArrayOfStrings: Either.Either> +declare const error$readonlyArrayOfStrings: Either.Either, Error> -// $ExpectType Either<"b" | Error, readonly [string, ...string[]]> +// $ExpectType Either pipe( error$readonlyArrayOfStrings, Either.filterOrLeft(ReadonlyArray.isNonEmptyReadonlyArray, ( @@ -134,7 +134,7 @@ pipe( ) => "b" as const) ) -// $ExpectType Either<"b" | Error, "a"> +// $ExpectType Either<"a", "b" | Error> pipe( error$a, Either.filterOrLeft(Predicate.isString, ( @@ -142,7 +142,7 @@ pipe( ) => "b" as const) ) -// $ExpectType Either<"b" | Error, "a"> +// $ExpectType Either<"a", "b" | Error> pipe( error$a, Either.filterOrLeft(Predicate.isString, ( @@ -150,7 +150,7 @@ pipe( ) => "b" as const) ) -// $ExpectType Either<"b" | Error, "a"> +// $ExpectType Either<"a", "b" | Error> pipe( error$a, Either.filterOrLeft(predicateUnknown, ( @@ -158,7 +158,7 @@ pipe( ) => "b" as const) ) -// $ExpectType Either<"b" | Error, "a"> +// $ExpectType Either<"a", "b" | Error> pipe( error$a, Either.filterOrLeft(predicateUnknown, ( diff --git a/packages/effect/dtslint/ReadonlyRecord.ts b/packages/effect/dtslint/ReadonlyRecord.ts index ab0270e784..bed8510b6b 100644 --- a/packages/effect/dtslint/ReadonlyRecord.ts +++ b/packages/effect/dtslint/ReadonlyRecord.ts @@ -132,10 +132,10 @@ ReadonlyRecord.toEntries(brandedRecord) // collect // ------------------------------------------------------------------------------------- -// $ExpectType Either[] +// $ExpectType Either[] ReadonlyRecord.collect({ a: Either.right(1), b: Either.right(2), c: Either.right(3) }, (_, n) => n) -// $ExpectType Either[] +// $ExpectType Either[] pipe({ a: Either.right(1), b: Either.right(2), c: Either.right(3) }, ReadonlyRecord.collect((_, n) => n)) // $ExpectType number[] diff --git a/packages/effect/dtslint/Unify.ts b/packages/effect/dtslint/Unify.ts index dbfea41c32..ab2cdcdacb 100644 --- a/packages/effect/dtslint/Unify.ts +++ b/packages/effect/dtslint/Unify.ts @@ -5,19 +5,19 @@ import * as Unify from "effect/Unify" // $ExpectType Option export type option = Unify.Unify | Option.Option> -// $ExpectType Either<"LA" | "LB", "RA" | "RB"> -export type either = Unify.Unify | Either.Either<"LB", "RB">> +// $ExpectType Either<"RA" | "RB", "LA" | "LB"> +export type either = Unify.Unify | Either.Either<"RB", "LB">> -// $ExpectType 0 | Option | Either<"LA" | "LB", "RA" | "RB"> +// $ExpectType 0 | Option | Either<"RA" | "RB", "LA" | "LB"> export type both = Unify.Unify< - Either.Either<"LA", "RA"> | Either.Either<"LB", "RB"> | Option.Option | Option.Option | 0 + Either.Either<"RA", "LA"> | Either.Either<"RB", "LB"> | Option.Option | Option.Option | 0 > // $ExpectType { [k: string]: string; } export type obj = Unify.Unify<{ [k: string]: string }> -// $ExpectType (n: N) => Either +// $ExpectType (n: N) => Either Unify.unify((n: N) => Math.random() > 0 ? Either.right(n) : Either.left("ok")) -// $ExpectType Either +// $ExpectType Either Unify.unify(Math.random() > 0 ? Either.right(10) : Either.left("ok")) diff --git a/packages/effect/mod.sh b/packages/effect/mod.sh index c02673f492..4b67c47bc2 100755 --- a/packages/effect/mod.sh +++ b/packages/effect/mod.sh @@ -1,5 +1,5 @@ #!/bin/bash -dirs=(../platform-node-shared/src) +dirs=(../typeclass/src ../typeclass/test ../typeclass/dtslint) for dir in ${dirs[@]}; do echo Refactoring $dir diff --git a/packages/effect/mod.ts b/packages/effect/mod.ts index d54bef57ff..bebe7557f6 100644 --- a/packages/effect/mod.ts +++ b/packages/effect/mod.ts @@ -2,6 +2,7 @@ import type k from "ast-types/gen/kinds.js" import type cs from "jscodeshift" const enabled = { + swapEitherParams: true, swapLayerParams: false, swapSTMParams: false, swapSTMGenParams: false, @@ -15,7 +16,8 @@ const enabled = { swapResourceParams: false, swapTExitParams: false, swapChannelParams: false, - swapSinkParams: true, + swapSinkParams: false, + cleanupEither: true, cleanupSTM: false, cleanupEffect: false, cleanupStream: false, @@ -42,6 +44,7 @@ const cleanupStream = cleanup("Stream") const cleanupExit = cleanup("Exit") const cleanupSTM = cleanup("STM") const cleanupTake = cleanup("Take") +const cleanupEither = cleanup("Either") const filter = (ast: cs.ASTPath, nodeName: string) => { const name = ast.value.typeName @@ -105,6 +108,7 @@ const swapFiberSetParams = swapParamsEA("FiberSet") const swapRequestParams = swapParamsEA("Request") const swapResourceParams = swapParamsEA("Resource") const swapTExitParams = swapParamsEA("TExit") +const swapEitherParams = swapParamsEA("Either") // from: Channel // to: Channel @@ -169,6 +173,9 @@ export default function transformer(file: cs.FileInfo, api: cs.API) { } forEveryTypeReference(root, (ast) => { + if (enabled.swapEitherParams) { + swapEitherParams(ast) + } if (enabled.swapLayerParams) { swapLayerParams(ast) } @@ -211,6 +218,9 @@ export default function transformer(file: cs.FileInfo, api: cs.API) { if (enabled.swapSinkParams) { swapSinkParams(ast) } + if (enabled.cleanupEither) { + cleanupEither(ast) + } if (enabled.cleanupEffect) { cleanupEffect(ast) } diff --git a/packages/effect/src/Brand.ts b/packages/effect/src/Brand.ts index 03cdf54f4a..bbca6e14cb 100644 --- a/packages/effect/src/Brand.ts +++ b/packages/effect/src/Brand.ts @@ -102,7 +102,7 @@ export declare namespace Brand { * Constructs a branded type from a value of type `A`, returning `Right` * if the provided `A` is valid, `Left` otherwise. */ - either(args: Brand.Unbranded): Either.Either + either(args: Brand.Unbranded): Either.Either /** * Attempts to refine the provided value of type `A`, returning `true` if * the provided `A` is valid, `false` otherwise. @@ -218,7 +218,7 @@ export const refined: >( refinement: Predicate>, onFailure: (a: Brand.Unbranded) => Brand.BrandErrors ): Brand.Constructor => { - const either = (args: Brand.Unbranded): Either.Either => + const either = (args: Brand.Unbranded): Either.Either => refinement(args) ? Either.right(args as A) : Either.left(onFailure(args)) // @ts-expect-error return Object.assign((args) => @@ -305,8 +305,8 @@ export const all: , ...Array extends infer X extends Brand ? X : Brand > => { - const either = (args: any): Either.Either => { - let result: Either.Either = Either.right(args) + const either = (args: any): Either.Either => { + let result: Either.Either = Either.right(args) for (const brand of brands) { const nextResult = brand.either(args) if (Either.isLeft(result) && Either.isLeft(nextResult)) { diff --git a/packages/effect/src/Cause.ts b/packages/effect/src/Cause.ts index 09387babed..a495af5882 100644 --- a/packages/effect/src/Cause.ts +++ b/packages/effect/src/Cause.ts @@ -577,7 +577,7 @@ export const failureOption: (self: Cause) => Option.Option = internal.f * @since 2.0.0 * @category getters */ -export const failureOrCause: (self: Cause) => Either.Either> = internal.failureOrCause +export const failureOrCause: (self: Cause) => Either.Either, E> = internal.failureOrCause /** * Converts the specified `Cause>` to an `Option>` by diff --git a/packages/effect/src/Channel.ts b/packages/effect/src/Channel.ts index e5c2773d7e..af5f2acc8e 100644 --- a/packages/effect/src/Channel.ts +++ b/packages/effect/src/Channel.ts @@ -1077,7 +1077,7 @@ export const fromEffect: ( * @since 2.0.0 * @category constructors */ -export const fromEither: (either: Either.Either) => Channel = +export const fromEither: (either: Either.Either) => Channel = channel.fromEither /** @@ -1097,7 +1097,7 @@ export const fromInput: ( * @category constructors */ export const fromPubSub: ( - pubsub: PubSub.PubSub, Elem>> + pubsub: PubSub.PubSub>> ) => Channel = channel.fromPubSub /** @@ -1107,7 +1107,7 @@ export const fromPubSub: ( * @category constructors */ export const fromPubSubScoped: ( - pubsub: PubSub.PubSub, Elem>> + pubsub: PubSub.PubSub>> ) => Effect.Effect, never, Scope.Scope> = channel.fromPubSubScoped /** @@ -1127,7 +1127,7 @@ export const fromOption: ( * @category constructors */ export const fromQueue: ( - queue: Queue.Dequeue, Elem>> + queue: Queue.Dequeue>> ) => Channel = channel.fromQueue /** @@ -1986,7 +1986,7 @@ export const sync: ( * @category destructors */ export const toPubSub: ( - pubsub: PubSub.PubSub, Elem>> + pubsub: PubSub.PubSub>> ) => Channel = channel.toPubSub /** @@ -2000,7 +2000,7 @@ export const toPubSub: ( */ export const toPull: ( self: Channel -) => Effect.Effect, OutErr, Env>, never, Scope.Scope | Env> = +) => Effect.Effect, OutErr, Env>, never, Scope.Scope | Env> = channel.toPull /** @@ -2010,7 +2010,7 @@ export const toPull: ( * @category destructors */ export const toQueue: ( - queue: Queue.Enqueue, Elem>> + queue: Queue.Enqueue>> ) => Channel = channel.toQueue /** Converts this channel to a `Sink`. diff --git a/packages/effect/src/Chunk.ts b/packages/effect/src/Chunk.ts index 55ae7c29c7..7a49b5f9e8 100644 --- a/packages/effect/src/Chunk.ts +++ b/packages/effect/src/Chunk.ts @@ -934,9 +934,9 @@ export const partition: { * @since 2.0.0 */ export const partitionMap: { - (f: (a: A) => Either): (self: Chunk) => [left: Chunk, right: Chunk] - (self: Chunk, f: (a: A) => Either): [left: Chunk, right: Chunk] -} = dual(2, (self: Chunk, f: (a: A) => Either): [left: Chunk, right: Chunk] => + (f: (a: A) => Either): (self: Chunk) => [left: Chunk, right: Chunk] + (self: Chunk, f: (a: A) => Either): [left: Chunk, right: Chunk] +} = dual(2, (self: Chunk, f: (a: A) => Either): [left: Chunk, right: Chunk] => pipe( RA.partitionMap(toReadonlyArray(self), f), ([l, r]) => [unsafeFromArray(l), unsafeFromArray(r)] @@ -948,7 +948,7 @@ export const partitionMap: { * @category filtering * @since 2.0.0 */ -export const separate = (self: Chunk>): [Chunk, Chunk] => +export const separate = (self: Chunk>): [Chunk, Chunk] => pipe( RA.separate(toReadonlyArray(self)), ([l, r]) => [unsafeFromArray(l), unsafeFromArray(r)] diff --git a/packages/effect/src/Config.ts b/packages/effect/src/Config.ts index 2a50e39314..80804e4b1c 100644 --- a/packages/effect/src/Config.ts +++ b/packages/effect/src/Config.ts @@ -55,7 +55,7 @@ export declare namespace Config { */ export interface Primitive extends Config { readonly description: string - parse(text: string): Either.Either + parse(text: string): Either.Either } /** @@ -233,8 +233,8 @@ export const mapAttempt: { * @category utils */ export const mapOrFail: { - (f: (a: A) => Either.Either): (self: Config) => Config - (self: Config, f: (a: A) => Either.Either): Config + (f: (a: A) => Either.Either): (self: Config) => Config + (self: Config, f: (a: A) => Either.Either): Config } = internal.mapOrFail /** @@ -303,7 +303,7 @@ export const option: (self: Config) => Config> = internal */ export const primitive: ( description: string, - parse: (text: string) => Either.Either + parse: (text: string) => Either.Either ) => Config = internal.primitive /** diff --git a/packages/effect/src/Cron.ts b/packages/effect/src/Cron.ts index 2d41782dec..67e07371b7 100644 --- a/packages/effect/src/Cron.ts +++ b/packages/effect/src/Cron.ts @@ -185,7 +185,7 @@ export const isParseError = (u: unknown): u is ParseError => hasProperty(u, Pars * @since 2.0.0 * @category constructors */ -export const parse = (cron: string): Either.Either => { +export const parse = (cron: string): Either.Either => { const segments = cron.split(" ").filter(String.isNonEmpty) if (segments.length !== 5) { return Either.left(ParseError(`Invalid number of segments in cron expression`, cron)) @@ -440,7 +440,7 @@ const weekdayOptions: SegmentOptions = { const parseSegment = ( input: string, options: SegmentOptions -): Either.Either> => { +): Either.Either, ParseError> => { const capacity = options.max - options.min + 1 const values = new Set() const fields = input.split(",") diff --git a/packages/effect/src/Differ.ts b/packages/effect/src/Differ.ts index aa65febd9e..a46d248751 100644 --- a/packages/effect/src/Differ.ts +++ b/packages/effect/src/Differ.ts @@ -366,14 +366,14 @@ export const orElseEither: { (that: Differ): ( self: Differ ) => Differ< - Either, + Either, Differ.Or.Patch > ( self: Differ, that: Differ ): Differ< - Either, + Either, Differ.Or.Patch > } = internal.orElseEither diff --git a/packages/effect/src/Effect.ts b/packages/effect/src/Effect.ts index 1986eb5a9a..0e957a86f1 100644 --- a/packages/effect/src/Effect.ts +++ b/packages/effect/src/Effect.ts @@ -401,7 +401,7 @@ export declare namespace All { */ export type ReturnIterable, Discard extends boolean, Mode> = [T] extends [Iterable>] ? Effect< - Discard extends true ? void : Mode extends "either" ? Array> : Array, + Discard extends true ? void : Mode extends "either" ? Array> : Array, Mode extends "either" ? never : Mode extends "validate" ? Array> : E, @@ -417,7 +417,7 @@ export declare namespace All { : T[number] extends never ? [] : Mode extends "either" ? { -readonly [K in keyof T]: [T[K]] extends [Effect.Variance] ? - Either.Either<_E, _A> + Either.Either<_A, _E> : never } : { -readonly [K in keyof T]: [T[K]] extends [Effect.Variance] ? _A : never }, @@ -441,7 +441,7 @@ export declare namespace All { Discard extends true ? void : Mode extends "either" ? { -readonly [K in keyof T]: [T[K]] extends [Effect.Variance] ? - Either.Either<_E, _A> + Either.Either<_A, _E> : never } : { -readonly [K in keyof T]: [T[K]] extends [Effect.Variance] ? _A : never }, @@ -3262,7 +3262,7 @@ export { * @since 2.0.0 * @category conversions */ -export const either: (self: Effect) => Effect, never, R> = core.either +export const either: (self: Effect) => Effect, never, R> = core.either /** * @since 2.0.0 diff --git a/packages/effect/src/Either.ts b/packages/effect/src/Either.ts index 55f62144b3..e2eb45b350 100644 --- a/packages/effect/src/Either.ts +++ b/packages/effect/src/Either.ts @@ -20,7 +20,7 @@ import * as Gen from "./Utils.js" * @category models * @since 2.0.0 */ -export type Either = Left | Right +export type Either = Left | Right /** * @category symbols @@ -73,7 +73,7 @@ export interface Right extends Pipeable, Inspectable { * @since 2.0.0 */ export interface EitherUnify { - Either?: () => A[Unify.typeSymbol] extends Either | infer _ ? Either : never + Either?: () => A[Unify.typeSymbol] extends Either | infer _ ? Either : never } /** @@ -87,7 +87,7 @@ export interface EitherUnifyIgnore {} * @since 2.0.0 */ export interface EitherTypeLambda extends TypeLambda { - readonly type: Either + readonly type: Either } /** @@ -97,7 +97,7 @@ export interface EitherTypeLambda extends TypeLambda { * @category constructors * @since 2.0.0 */ -export const right: (a: A) => Either = either.right +export const right: (a: A) => Either = either.right /** * Constructs a new `Either` holding a `Left` value. This usually represents a failure, due to the right-bias of this @@ -106,7 +106,7 @@ export const right: (a: A) => Either = either.right * @category constructors * @since 2.0.0 */ -export const left: (e: E) => Either = either.left +export const left: (e: E) => Either = either.left /** * 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 @@ -122,11 +122,11 @@ export const left: (e: E) => Either = either.left * @since 2.0.0 */ export const fromNullable: { - (onNullable: (a: A) => E): (self: A) => Either> - (self: A, onNullable: (a: A) => E): Either> + (onNullable: (a: A) => E): (self: A) => Either, E> + (self: A, onNullable: (a: A) => E): Either, E> } = dual( 2, - (self: A, onNullable: (a: A) => E): Either> => + (self: A, onNullable: (a: A) => E): Either, E> => self == null ? left(onNullable(self)) : right(self as NonNullable) ) @@ -142,8 +142,8 @@ export const fromNullable: { * @since 2.0.0 */ export const fromOption: { - (self: Option, onNone: () => E): Either - (onNone: () => E): (self: Option) => Either + (self: Option, onNone: () => E): Either + (onNone: () => E): (self: Option) => Either } = either.fromOption const try_: { @@ -152,8 +152,8 @@ const try_: { readonly try: LazyArg readonly catch: (error: unknown) => E } - ): Either - (evaluate: LazyArg): Either + ): Either + (evaluate: LazyArg): Either } = (( evaluate: LazyArg | { readonly try: LazyArg @@ -217,7 +217,7 @@ export const isEither: (input: unknown) => input is Either = e * @category guards * @since 2.0.0 */ -export const isLeft: (self: Either) => self is Left = either.isLeft +export const isLeft: (self: Either) => self is Left = either.isLeft /** * Determine if a `Either` is a `Right`. @@ -233,7 +233,7 @@ export const isLeft: (self: Either) => self is Left = either.i * @category guards * @since 2.0.0 */ -export const isRight: (self: Either) => self is Right = either.isRight +export const isRight: (self: Either) => self is Right = either.isRight /** * Converts a `Either` to an `Option` discarding the `Left`. @@ -250,7 +250,7 @@ export const isRight: (self: Either) => self is Right = either * @category getters * @since 2.0.0 */ -export const getRight: (self: Either) => Option = either.getRight +export const getRight: (self: Either) => Option = either.getRight /** * Converts a `Either` to an `Option` discarding the value. @@ -265,7 +265,7 @@ export const getRight: (self: Either) => Option = either.getRight * @category getters * @since 2.0.0 */ -export const getLeft: (self: Either) => Option = either.getLeft +export const getLeft: (self: Either) => Option = either.getLeft /** * @category equivalence @@ -274,7 +274,7 @@ export const getLeft: (self: Either) => Option = either.getLeft export const getEquivalence = ( EE: Equivalence.Equivalence, EA: Equivalence.Equivalence -): Equivalence.Equivalence> => +): Equivalence.Equivalence> => Equivalence.make((x, y) => x === y || (isLeft(x) ? @@ -290,17 +290,17 @@ export const mapBoth: { (options: { readonly onLeft: (e: E1) => E2 readonly onRight: (a: A) => B - }): (self: Either) => Either - (self: Either, options: { + }): (self: Either) => Either + (self: Either, options: { readonly onLeft: (e: E1) => E2 readonly onRight: (a: A) => B - }): Either + }): Either } = dual( 2, - (self: Either, { onLeft, onRight }: { + (self: Either, { onLeft, onRight }: { readonly onLeft: (e: E1) => E2 readonly onRight: (a: A) => B - }): Either => isLeft(self) ? left(onLeft(self.left)) : right(onRight(self.right)) + }): Either => isLeft(self) ? left(onLeft(self.left)) : right(onRight(self.right)) ) /** @@ -313,11 +313,11 @@ export const mapBoth: { * @since 2.0.0 */ export const mapLeft: { - (f: (e: E) => G): (self: Either) => Either - (self: Either, f: (e: E) => G): Either + (f: (e: E) => G): (self: Either) => Either + (self: Either, f: (e: E) => G): Either } = dual( 2, - (self: Either, f: (e: E) => G): Either => isLeft(self) ? left(f(self.left)) : right(self.right) + (self: Either, f: (e: E) => G): Either => isLeft(self) ? left(f(self.left)) : right(self.right) ) /** @@ -330,11 +330,11 @@ export const mapLeft: { * @since 2.0.0 */ export const map: { - (f: (a: A) => B): (self: Either) => Either - (self: Either, f: (a: A) => B): Either + (f: (a: A) => B): (self: Either) => Either + (self: Either, f: (a: A) => B): Either } = dual( 2, - (self: Either, f: (a: A) => B): Either => isRight(self) ? right(f(self.right)) : left(self.left) + (self: Either, f: (a: A) => B): Either => isRight(self) ? right(f(self.right)) : left(self.left) ) /** @@ -362,14 +362,14 @@ export const match: { (options: { readonly onLeft: (e: E) => B readonly onRight: (a: A) => C - }): (self: Either) => B | C - (self: Either, options: { + }): (self: Either) => B | C + (self: Either, options: { readonly onLeft: (e: E) => B readonly onRight: (a: A) => C }): B | C } = dual( 2, - (self: Either, { onLeft, onRight }: { + (self: Either, { onLeft, onRight }: { readonly onLeft: (e: E) => B readonly onRight: (a: A) => C }): B | C => isLeft(self) ? onLeft(self.left) : onRight(self.right) @@ -407,28 +407,28 @@ export const filterOrLeft: { ( refinement: Refinement, B>, orLeftWith: (a: NoInfer) => E2 - ): (self: Either) => Either + ): (self: Either) => Either ( predicate: Predicate>, orLeftWith: (a: NoInfer) => E2 - ): (self: Either) => Either + ): (self: Either) => Either ( - self: Either, + self: Either, refinement: Refinement, orLeftWith: (a: A) => E2 - ): Either - (self: Either, predicate: Predicate, orLeftWith: (a: A) => E2): Either + ): Either + (self: Either, predicate: Predicate, orLeftWith: (a: A) => E2): Either } = dual(3, ( - self: Either, + self: Either, predicate: Predicate, orLeftWith: (a: A) => E2 -): Either => flatMap(self, (a) => predicate(a) ? right(a) : left(orLeftWith(a)))) +): Either => flatMap(self, (a) => predicate(a) ? right(a) : left(orLeftWith(a)))) /** * @category getters * @since 2.0.0 */ -export const merge: (self: Either) => E | A = match({ +export const merge: (self: Either) => E | A = match({ onLeft: identity, onRight: identity }) @@ -446,11 +446,11 @@ export const merge: (self: Either) => E | A = match({ * @since 2.0.0 */ export const getOrElse: { - (onLeft: (e: E) => B): (self: Either) => B | A - (self: Either, onLeft: (e: E) => B): A | B + (onLeft: (e: E) => B): (self: Either) => B | A + (self: Either, onLeft: (e: E) => B): A | B } = dual( 2, - (self: Either, onLeft: (e: E) => B): A | B => isLeft(self) ? onLeft(self.left) : self.right + (self: Either, onLeft: (e: E) => B): A | B => isLeft(self) ? onLeft(self.left) : self.right ) /** @@ -463,7 +463,7 @@ export const getOrElse: { * @category getters * @since 2.0.0 */ -export const getOrNull: (self: Either) => A | null = getOrElse(constNull) +export const getOrNull: (self: Either) => A | null = getOrElse(constNull) /** * @example @@ -475,7 +475,7 @@ export const getOrNull: (self: Either) => A | null = getOrElse(const * @category getters * @since 2.0.0 */ -export const getOrUndefined: (self: Either) => A | undefined = getOrElse(constUndefined) +export const getOrUndefined: (self: Either) => A | undefined = getOrElse(constUndefined) /** * Extracts the value of an `Either` or throws if the `Either` is `Left`. @@ -498,9 +498,9 @@ export const getOrUndefined: (self: Either) => A | undefined = getOr * @since 2.0.0 */ export const getOrThrowWith: { - (onLeft: (e: E) => unknown): (self: Either) => A - (self: Either, onLeft: (e: E) => unknown): A -} = dual(2, (self: Either, onLeft: (e: E) => unknown): A => { + (onLeft: (e: E) => unknown): (self: Either) => A + (self: Either, onLeft: (e: E) => unknown): A +} = dual(2, (self: Either, onLeft: (e: E) => unknown): A => { if (isRight(self)) { return self.right } @@ -524,7 +524,7 @@ export const getOrThrowWith: { * @category getters * @since 2.0.0 */ -export const getOrThrow: (self: Either) => A = getOrThrowWith(() => +export const getOrThrow: (self: Either) => A = getOrThrowWith(() => new Error("getOrThrow called on a Left") ) @@ -538,11 +538,11 @@ export const getOrThrow: (self: Either) => A = getOrThrowWith(() => * @since 2.0.0 */ export const orElse: { - (that: (e1: E1) => Either): (self: Either) => Either - (self: Either, that: (e1: E1) => Either): Either + (that: (e1: E1) => Either): (self: Either) => Either + (self: Either, that: (e1: E1) => Either): Either } = dual( 2, - (self: Either, that: (e1: E1) => Either): Either => + (self: Either, that: (e1: E1) => Either): Either => isLeft(self) ? that(self.left) : right(self.right) ) @@ -551,11 +551,11 @@ export const orElse: { * @since 2.0.0 */ export const flatMap: { - (f: (a: A) => Either): (self: Either) => Either - (self: Either, f: (a: A) => Either): Either + (f: (a: A) => Either): (self: Either) => Either + (self: Either, f: (a: A) => Either): Either } = dual( 2, - (self: Either, f: (a: A) => Either): Either => + (self: Either, f: (a: A) => Either): Either => isLeft(self) ? left(self.left) : f(self.right) ) @@ -566,17 +566,17 @@ export const flatMap: { * @since 2.0.0 */ export const andThen: { - (f: (a: A) => Either): (self: Either) => Either - (f: Either): (self: Either) => Either - (f: (a: A) => B): (self: Either) => Either - (b: B): (self: Either) => Either - (self: Either, f: (a: A) => Either): Either - (self: Either, f: Either): Either - (self: Either, f: (a: A) => B): Either - (self: Either, f: B): Either + (f: (a: A) => Either): (self: Either) => Either + (f: Either): (self: Either) => Either + (f: (a: A) => B): (self: Either) => Either + (b: B): (self: Either) => Either + (self: Either, f: (a: A) => Either): Either + (self: Either, f: Either): Either + (self: Either, f: (a: A) => B): Either + (self: Either, f: B): Either } = dual( 2, - (self: Either, f: (a: A) => Either | Either): Either => + (self: Either, f: (a: A) => Either | Either): Either => flatMap(self, (a) => { const b = isFunction(f) ? f(a) : f return isEither(b) ? b : right(b) @@ -589,17 +589,17 @@ export const andThen: { */ export const zipWith: { ( - that: Either, + that: Either, f: (a: A, b: A2) => B - ): (self: Either) => Either + ): (self: Either) => Either ( - self: Either, - that: Either, + self: Either, + that: Either, f: (a: A, b: A2) => B - ): Either + ): Either } = dual( 3, - (self: Either, that: Either, f: (a: A, b: A2) => B): Either => + (self: Either, that: Either, f: (a: A, b: A2) => B): Either => flatMap(self, (a) => map(that, (b) => f(a, b))) ) @@ -608,11 +608,11 @@ export const zipWith: { * @since 2.0.0 */ export const ap: { - (that: Either): (self: Either B>) => Either - (self: Either B>, that: Either): Either + (that: Either): (self: Either<(a: A) => B, E>) => Either + (self: Either<(a: A) => B, E>, that: Either): Either } = dual( 2, - (self: Either B>, that: Either): Either => + (self: Either<(a: A) => B, E>, that: Either): Either => zipWith(self, that, (f, a) => f(a)) ) @@ -639,13 +639,13 @@ export const ap: { export const all: > | Record>>( input: I ) => [I] extends [ReadonlyArray>] ? Either< - I[number] extends never ? never : [I[number]] extends [Either] ? E : never, - { -readonly [K in keyof I]: [I[K]] extends [Either] ? A : never } + { -readonly [K in keyof I]: [I[K]] extends [Either] ? A : never }, + I[number] extends never ? never : [I[number]] extends [Either] ? E : never > - : [I] extends [Iterable>] ? Either> + : [I] extends [Iterable>] ? Either, E> : Either< - I[keyof I] extends never ? never : [I[keyof I]] extends [Either] ? E : never, - { -readonly [K in keyof I]: [I[K]] extends [Either] ? A : never } + { -readonly [K in keyof I]: [I[K]] extends [Either] ? A : never }, + I[keyof I] extends never ? never : [I[keyof I]] extends [Either] ? E : never > = ( input: Iterable> | Record> ): Either => { @@ -678,7 +678,7 @@ export const all: > | Record(self: Either): Either => isLeft(self) ? right(self.left) : left(self.right) +export const flip = (self: Either): Either => isLeft(self) ? right(self.left) : left(self.right) const adapter = Gen.adapter() diff --git a/packages/effect/src/Encoding.ts b/packages/effect/src/Encoding.ts index 3880c9c4bb..e0e8b61947 100644 --- a/packages/effect/src/Encoding.ts +++ b/packages/effect/src/Encoding.ts @@ -28,7 +28,7 @@ export const encodeBase64: (input: Uint8Array | string) => string = (input) => * @category decoding * @since 2.0.0 */ -export const decodeBase64 = (str: string): Either.Either => Base64.decode(str) +export const decodeBase64 = (str: string): Either.Either => Base64.decode(str) /** * Decodes a base64 (RFC4648) encoded `string` into a UTF-8 `string`. @@ -53,7 +53,7 @@ export const encodeBase64Url: (input: Uint8Array | string) => string = (input) = * @category decoding * @since 2.0.0 */ -export const decodeBase64Url = (str: string): Either.Either => Base64Url.decode(str) +export const decodeBase64Url = (str: string): Either.Either => Base64Url.decode(str) /** * Decodes a base64 (URL) encoded `string` into a UTF-8 `string`. @@ -78,7 +78,7 @@ export const encodeHex: (input: Uint8Array | string) => string = (input) => * @category decoding * @since 2.0.0 */ -export const decodeHex = (str: string): Either.Either => Hex.decode(str) +export const decodeHex = (str: string): Either.Either => Hex.decode(str) /** * Decodes a hex encoded `string` into a UTF-8 `string`. diff --git a/packages/effect/src/Exit.ts b/packages/effect/src/Exit.ts index 76cfaaabf7..4c11bb0b14 100644 --- a/packages/effect/src/Exit.ts +++ b/packages/effect/src/Exit.ts @@ -231,7 +231,7 @@ export const forEachEffect: { * @since 2.0.0 * @category conversions */ -export const fromEither: (either: Either.Either) => Exit = core.exitFromEither +export const fromEither: (either: Either.Either) => Exit = core.exitFromEither /** * Converts an `Option` into an `Exit`. diff --git a/packages/effect/src/Fiber.ts b/packages/effect/src/Fiber.ts index 052c8e3ffb..13737df9e6 100644 --- a/packages/effect/src/Fiber.ts +++ b/packages/effect/src/Fiber.ts @@ -539,8 +539,8 @@ export const orElse: { * @category alternatives */ export const orElseEither: { - (that: Fiber): (self: Fiber) => Fiber, E2 | E> - (self: Fiber, that: Fiber): Fiber, E | E2> + (that: Fiber): (self: Fiber) => Fiber, E2 | E> + (self: Fiber, that: Fiber): Fiber, E | E2> } = internal.orElseEither /** diff --git a/packages/effect/src/List.ts b/packages/effect/src/List.ts index 0651b1416c..a5068d51ca 100644 --- a/packages/effect/src/List.ts +++ b/packages/effect/src/List.ts @@ -799,9 +799,9 @@ export const partition: { * @category combinators */ export const partitionMap: { - (f: (a: A) => Either.Either): (self: List) => [left: List, right: List] - (self: List, f: (a: A) => Either.Either): [left: List, right: List] -} = dual(2, (self: List, f: (a: A) => Either.Either): [left: List, right: List] => { + (f: (a: A) => Either.Either): (self: List) => [left: List, right: List] + (self: List, f: (a: A) => Either.Either): [left: List, right: List] +} = dual(2, (self: List, f: (a: A) => Either.Either): [left: List, right: List] => { const left: Array = [] const right: Array = [] for (const a of self) { diff --git a/packages/effect/src/Match.ts b/packages/effect/src/Match.ts index 7f97710fb9..9d0f9c9fbd 100644 --- a/packages/effect/src/Match.ts +++ b/packages/effect/src/Match.ts @@ -57,7 +57,7 @@ export interface ValueMatcher } readonly provided: Provided - readonly value: Either.Either + readonly value: Either.Either add(_case: Case): ValueMatcher } @@ -526,8 +526,8 @@ export const orElseAbsurd: ( */ export const either: ( self: Matcher -) => [Pr] extends [never] ? (input: I) => Either.Either> - : Either.Either> = internal.either +) => [Pr] extends [never] ? (input: I) => Either.Either, R> + : Either.Either, R> = internal.either /** * @category conversions diff --git a/packages/effect/src/MergeState.ts b/packages/effect/src/MergeState.ts index c2a467e05f..e06b6736f6 100644 --- a/packages/effect/src/MergeState.ts +++ b/packages/effect/src/MergeState.ts @@ -49,8 +49,8 @@ export interface BothRunning<_Env, out Err, out Err1, _Err2, out Elem, out Done, extends MergeState.Proto { readonly _tag: "BothRunning" - readonly left: Fiber.Fiber, Err> - readonly right: Fiber.Fiber, Err1> + readonly left: Fiber.Fiber, Err> + readonly right: Fiber.Fiber, Err1> } /** @@ -80,8 +80,8 @@ export interface RightDone( - left: Fiber.Fiber, Err>, - right: Fiber.Fiber, Err1> + left: Fiber.Fiber, Err>, + right: Fiber.Fiber, Err1> ) => MergeState = internal.BothRunning /** @@ -151,8 +151,8 @@ export const match: { ( options: { readonly onBothRunning: ( - left: Fiber.Fiber, Err>, - right: Fiber.Fiber, Err1> + left: Fiber.Fiber, Err>, + right: Fiber.Fiber, Err1> ) => Z readonly onLeftDone: (f: (exit: Exit.Exit) => Effect.Effect) => Z readonly onRightDone: (f: (exit: Exit.Exit) => Effect.Effect) => Z @@ -162,8 +162,8 @@ export const match: { self: MergeState, options: { readonly onBothRunning: ( - left: Fiber.Fiber, Err>, - right: Fiber.Fiber, Err1> + left: Fiber.Fiber, Err>, + right: Fiber.Fiber, Err1> ) => Z readonly onLeftDone: (f: (exit: Exit.Exit) => Effect.Effect) => Z readonly onRightDone: (f: (exit: Exit.Exit) => Effect.Effect) => Z diff --git a/packages/effect/src/Option.ts b/packages/effect/src/Option.ts index a8374f0e24..54a27cb6f3 100644 --- a/packages/effect/src/Option.ts +++ b/packages/effect/src/Option.ts @@ -255,7 +255,7 @@ export const fromIterable = (collection: Iterable): Option => { * @category conversions * @since 2.0.0 */ -export const getRight: (self: Either) => Option = either.getRight +export const getRight: (self: Either) => Option = either.getRight /** * Converts a `Either` to an `Option` discarding the value. @@ -270,7 +270,7 @@ export const getRight: (self: Either) => Option = either.getRight * @category conversions * @since 2.0.0 */ -export const getLeft: (self: Either) => Option = either.getLeft +export const getLeft: (self: Either) => Option = either.getLeft /** * Returns the value of the `Option` if it is `Some`, otherwise returns `onNone` @@ -395,11 +395,11 @@ export const orElseSome: { * @since 2.0.0 */ export const orElseEither: { - (that: LazyArg>): (self: Option) => Option> - (self: Option, that: LazyArg>): Option> + (that: LazyArg>): (self: Option) => Option> + (self: Option, that: LazyArg>): Option> } = dual( 2, - (self: Option, that: LazyArg>): Option> => + (self: Option, that: LazyArg>): Option> => isNone(self) ? map(that(), either.right) : map(self, either.left) ) @@ -955,11 +955,11 @@ export const toArray = (self: Option): Array => isNone(self) ? [] : [se * @since 2.0.0 */ export const partitionMap: { - (f: (a: A) => Either): (self: Option) => [left: Option, right: Option] - (self: Option, f: (a: A) => Either): [left: Option, right: Option] + (f: (a: A) => Either): (self: Option) => [left: Option, right: Option] + (self: Option, f: (a: A) => Either): [left: Option, right: Option] } = dual(2, ( self: Option, - f: (a: A) => Either + f: (a: A) => Either ): [excluded: Option, satisfying: Option] => { if (isNone(self)) { return [none(), none()] diff --git a/packages/effect/src/ReadonlyArray.ts b/packages/effect/src/ReadonlyArray.ts index e1be7b9c0d..3540e716e5 100644 --- a/packages/effect/src/ReadonlyArray.ts +++ b/packages/effect/src/ReadonlyArray.ts @@ -1615,11 +1615,11 @@ export const filterMapWhile: { * @since 2.0.0 */ export const partitionMap: { - (f: (a: A, i: number) => Either): (self: Iterable) => [left: Array, right: Array] - (self: Iterable, f: (a: A, i: number) => Either): [left: Array, right: Array] + (f: (a: A, i: number) => Either): (self: Iterable) => [left: Array, right: Array] + (self: Iterable, f: (a: A, i: number) => Either): [left: Array, right: Array] } = dual( 2, - (self: Iterable, f: (a: A, i: number) => Either): [left: Array, right: Array] => { + (self: Iterable, f: (a: A, i: number) => Either): [left: Array, right: Array] => { const left: Array = [] const right: Array = [] const as = fromIterable(self) @@ -1667,7 +1667,7 @@ export const getSomes: (self: Iterable>) => Array = filterMap(id * @category filtering * @since 2.0.0 */ -export const getLefts = (self: Iterable>): Array => { +export const getLefts = (self: Iterable>): Array => { const out: Array = [] for (const a of self) { if (E.isLeft(a)) { @@ -1693,7 +1693,7 @@ export const getLefts = (self: Iterable>): Array => { * @category filtering * @since 2.0.0 */ -export const getRights = (self: Iterable>): Array => { +export const getRights = (self: Iterable>): Array => { const out: Array = [] for (const a of self) { if (E.isRight(a)) { @@ -1766,7 +1766,7 @@ export const partition: { * @category filtering * @since 2.0.0 */ -export const separate: (self: Iterable>) => [Array, Array] = partitionMap( +export const separate: (self: Iterable>) => [Array, Array] = partitionMap( identity ) @@ -1847,7 +1847,7 @@ export const flatMapNullable: { * @since 2.0.0 */ export const liftEither = , E, B>( - f: (...a: A) => Either + f: (...a: A) => Either ) => (...a: A): Array => { const e = f(...a) diff --git a/packages/effect/src/ReadonlyRecord.ts b/packages/effect/src/ReadonlyRecord.ts index b9fde731fb..b06ec776a7 100644 --- a/packages/effect/src/ReadonlyRecord.ts +++ b/packages/effect/src/ReadonlyRecord.ts @@ -629,7 +629,7 @@ export const getSomes: (self: ReadonlyRecord>) => Record(self: ReadonlyRecord>): Record => { +export const getLefts = (self: ReadonlyRecord>): Record => { const out: Record = {} for (const key of Object.keys(self)) { const value = self[key] @@ -656,7 +656,7 @@ export const getLefts = (self: ReadonlyRecord>): Record(self: ReadonlyRecord>): Record => { +export const getRights = (self: ReadonlyRecord>): Record => { const out: Record = {} for (const key of Object.keys(self)) { const value = self[key] @@ -687,17 +687,17 @@ export const getRights = (self: ReadonlyRecord>): Record( - f: (a: A, key: K) => Either + f: (a: A, key: K) => Either ): (self: Record) => [left: Record, right: Record] ( self: Record, - f: (a: A, key: K) => Either + f: (a: A, key: K) => Either ): [left: Record, right: Record] } = dual( 2, ( self: Record, - f: (a: A, key: string) => Either + f: (a: A, key: string) => Either ): [left: Record, right: Record] => { const left: Record = {} const right: Record = {} @@ -732,7 +732,7 @@ export const partitionMap: { * @since 2.0.0 */ export const separate: ( - self: ReadonlyRecord> + self: ReadonlyRecord> ) => [Record, Record] = partitionMap(identity) /** diff --git a/packages/effect/src/RequestResolver.ts b/packages/effect/src/RequestResolver.ts index 645944ff61..8fa9a8ff6f 100644 --- a/packages/effect/src/RequestResolver.ts +++ b/packages/effect/src/RequestResolver.ts @@ -235,7 +235,7 @@ export const mapInputContext: { export const eitherWith: { , R2, B extends Request.Request, C extends Request.Request>( that: RequestResolver, - f: (_: Request.Entry) => Either.Either, Request.Entry> + f: (_: Request.Entry) => Either.Either, Request.Entry> ): (self: RequestResolver) => RequestResolver < R, @@ -246,7 +246,7 @@ export const eitherWith: { >( self: RequestResolver, that: RequestResolver, - f: (_: Request.Entry) => Either.Either, Request.Entry> + f: (_: Request.Entry) => Either.Either, Request.Entry> ): RequestResolver } = internal.eitherWith diff --git a/packages/effect/src/STM.ts b/packages/effect/src/STM.ts index fe7faa73af..9403303a6d 100644 --- a/packages/effect/src/STM.ts +++ b/packages/effect/src/STM.ts @@ -517,7 +517,7 @@ export const dieSync: (evaluate: LazyArg) => STM = core.dieSync * @since 2.0.0 * @category mutations */ -export const either: (self: STM) => STM, never, R> = stm.either +export const either: (self: STM) => STM, never, R> = stm.either /** * Executes the specified finalization transaction whether or not this effect @@ -817,7 +817,7 @@ export const forEach: { * @since 2.0.0 * @category constructors */ -export const fromEither: (either: Either.Either) => STM = stm.fromEither +export const fromEither: (either: Either.Either) => STM = stm.fromEither /** * Lifts an `Option` into a `STM`. @@ -1396,8 +1396,8 @@ export const orElse: { * @category error handling */ export const orElseEither: { - (that: LazyArg>): (self: STM) => STM, E2, R2 | R> - (self: STM, that: LazyArg>): STM, E2, R | R2> + (that: LazyArg>): (self: STM) => STM, E2, R2 | R> + (self: STM, that: LazyArg>): STM, E2, R | R2> } = stm.orElseEither /** diff --git a/packages/effect/src/Schedule.ts b/packages/effect/src/Schedule.ts index 3cffccc24c..51f9650c3c 100644 --- a/packages/effect/src/Schedule.ts +++ b/packages/effect/src/Schedule.ts @@ -194,11 +194,11 @@ export const andThen: { export const andThenEither: { ( that: Schedule - ): (self: Schedule) => Schedule> + ): (self: Schedule) => Schedule> ( self: Schedule, that: Schedule - ): Schedule> + ): Schedule> } = internal.andThenEither /** diff --git a/packages/effect/src/SingleProducerAsyncInput.ts b/packages/effect/src/SingleProducerAsyncInput.ts index ea12498f20..43e07dd290 100644 --- a/packages/effect/src/SingleProducerAsyncInput.ts +++ b/packages/effect/src/SingleProducerAsyncInput.ts @@ -30,7 +30,7 @@ export interface SingleProducerAsyncInput extends AsyncInputProducer, AsyncInputConsumer { readonly close: Effect.Effect - readonly take: Effect.Effect>> + readonly take: Effect.Effect>> } /** diff --git a/packages/effect/src/Sink.ts b/packages/effect/src/Sink.ts index 197c5f0199..c3826395b0 100644 --- a/packages/effect/src/Sink.ts +++ b/packages/effect/src/Sink.ts @@ -1014,7 +1014,7 @@ export const fromPubSub: ( */ export const fromPush: ( push: Effect.Effect< - (_: Option.Option>) => Effect.Effect, Chunk.Chunk], R>, + (_: Option.Option>) => Effect.Effect, Chunk.Chunk], R>, never, R > @@ -1189,12 +1189,12 @@ export const raceBoth: { ( that: Sink, options?: { readonly capacity?: number | undefined } | undefined - ): (self: Sink) => Sink, In & In1, L1 | L, E1 | E, R1 | R> + ): (self: Sink) => Sink, In & In1, L1 | L, E1 | E, R1 | R> ( self: Sink, that: Sink, options?: { readonly capacity?: number | undefined } | undefined - ): Sink, In & In1, L | L1, E | E1, R | R1> + ): Sink, In & In1, L | L1, E | E1, R | R1> } = internal.raceBoth /** diff --git a/packages/effect/src/Stream.ts b/packages/effect/src/Stream.ts index 8d7f6b577c..1aec5a0b18 100644 --- a/packages/effect/src/Stream.ts +++ b/packages/effect/src/Stream.ts @@ -236,12 +236,12 @@ export const aggregateWithinEither: { ( sink: Sink.Sink, schedule: Schedule.Schedule, C> - ): (self: Stream) => Stream, E2 | E, R2 | R3 | R> + ): (self: Stream) => Stream, E2 | E, R2 | R3 | R> ( self: Stream, sink: Sink.Sink, schedule: Schedule.Schedule, C> - ): Stream, E | E2, R | R2 | R3> + ): Stream, E | E2, R | R2 | R3> } = internal.aggregateWithinEither /** @@ -1027,7 +1027,7 @@ export const dropWhileEffect: { * @since 2.0.0 * @category utils */ -export const either: (self: Stream) => Stream, never, R> = internal.either +export const either: (self: Stream) => Stream, never, R> = internal.either /** * The empty stream. @@ -2168,8 +2168,8 @@ export const mergeWith: { export const mergeEither: { ( that: Stream - ): (self: Stream) => Stream, E2 | E, R2 | R> - (self: Stream, that: Stream): Stream, E | E2, R | R2> + ): (self: Stream) => Stream, E2 | E, R2 | R> + (self: Stream, that: Stream): Stream, E | E2, R | R2> } = internal.mergeEither /** @@ -2289,11 +2289,11 @@ export const orElse: { export const orElseEither: { ( that: LazyArg> - ): (self: Stream) => Stream, E2, R2 | R> + ): (self: Stream) => Stream, E2, R2 | R> ( self: Stream, that: LazyArg> - ): Stream, E2, R | R2> + ): Stream, E2, R | R2> } = internal.orElseEither /** @@ -2445,14 +2445,14 @@ export const partition: { */ export const partitionEither: { ( - predicate: (a: NoInfer) => Effect.Effect, E2, R2>, + predicate: (a: NoInfer) => Effect.Effect, E2, R2>, options?: { readonly bufferSize?: number | undefined } | undefined ): ( self: Stream ) => Effect.Effect<[left: Stream, right: Stream], E2 | E, Scope.Scope | R2 | R> ( self: Stream, - predicate: (a: A) => Effect.Effect, E2, R2>, + predicate: (a: A) => Effect.Effect, E2, R2>, options?: { readonly bufferSize?: number | undefined } | undefined ): Effect.Effect<[left: Stream, right: Stream], E | E2, Scope.Scope | R | R2> } = internal.partitionEither @@ -2763,11 +2763,11 @@ export const repeatEffectWithSchedule: ( export const repeatEither: { ( schedule: Schedule.Schedule - ): (self: Stream) => Stream, E, R2 | R> + ): (self: Stream) => Stream, E, R2 | R> ( self: Stream, schedule: Schedule.Schedule - ): Stream, E, R | R2> + ): Stream, E, R | R2> } = internal.repeatEither /** @@ -4378,7 +4378,7 @@ export const zipWithChunks: { f: ( left: Chunk.Chunk, right: Chunk.Chunk - ) => readonly [Chunk.Chunk, Either.Either, Chunk.Chunk>] + ) => readonly [Chunk.Chunk, Either.Either, Chunk.Chunk>] ): (self: Stream) => Stream ( self: Stream, @@ -4386,7 +4386,7 @@ export const zipWithChunks: { f: ( left: Chunk.Chunk, right: Chunk.Chunk - ) => readonly [Chunk.Chunk, Either.Either, Chunk.Chunk>] + ) => readonly [Chunk.Chunk, Either.Either, Chunk.Chunk>] ): Stream } = internal.zipWithChunks diff --git a/packages/effect/src/TDeferred.ts b/packages/effect/src/TDeferred.ts index 29b3907d1e..3b125068b8 100644 --- a/packages/effect/src/TDeferred.ts +++ b/packages/effect/src/TDeferred.ts @@ -31,7 +31,7 @@ export interface TDeferred extends TDeferred.Varianc */ export interface TDeferred { /** @internal */ - readonly ref: TRef.TRef>> + readonly ref: TRef.TRef>> } /** @@ -65,8 +65,8 @@ export { * @category mutations */ export const done: { - (either: Either.Either): (self: TDeferred) => STM.STM - (self: TDeferred, either: Either.Either): STM.STM + (either: Either.Either): (self: TDeferred) => STM.STM + (self: TDeferred, either: Either.Either): STM.STM } = internal.done /** @@ -88,7 +88,7 @@ export const make: () => STM.STM> = internal.make * @since 2.0.0 * @category getters */ -export const poll: (self: TDeferred) => STM.STM>> = internal.poll +export const poll: (self: TDeferred) => STM.STM>> = internal.poll /** * @since 2.0.0 diff --git a/packages/effect/src/TestAnnotation.ts b/packages/effect/src/TestAnnotation.ts index 514be85a5a..9a4c462e86 100644 --- a/packages/effect/src/TestAnnotation.ts +++ b/packages/effect/src/TestAnnotation.ts @@ -81,9 +81,9 @@ export const make = ( * @since 2.0.0 */ export const compose = ( - left: Either.Either>, - right: Either.Either> -): Either.Either> => { + left: Either.Either, number>, + right: Either.Either, number> +): Either.Either, number> => { if (Either.isLeft(left) && Either.isLeft(right)) { return Either.left(left.left + right.left) } @@ -103,12 +103,9 @@ export const compose = ( * @since 2.0.0 */ export const fibers: TestAnnotation< - Either.Either< - number, - Chunk.Chunk>>> - > + Either.Either>>>, number> > = make< - Either.Either>>>> + Either.Either>>>, number> >( "fibers", Either.left(0), diff --git a/packages/effect/src/internal/blockedRequests.ts b/packages/effect/src/internal/blockedRequests.ts index 9f49848c59..345fd9bded 100644 --- a/packages/effect/src/internal/blockedRequests.ts +++ b/packages/effect/src/internal/blockedRequests.ts @@ -103,7 +103,7 @@ export const reduce = ( reducer: RequestBlock.RequestBlock.Reducer ): Z => { let input: List.List = List.of(self) - let output = List.empty>() + let output = List.empty>() while (List.isCons(input)) { const current: RequestBlock.RequestBlock = input.head switch (current._tag) { diff --git a/packages/effect/src/internal/cause.ts b/packages/effect/src/internal/cause.ts index f1c354b02d..4af905b744 100644 --- a/packages/effect/src/internal/cause.ts +++ b/packages/effect/src/internal/cause.ts @@ -234,7 +234,7 @@ export const failureOption = (self: Cause.Cause): Option.Option => Option.none()) /** @internal */ -export const failureOrCause = (self: Cause.Cause): Either.Either> => { +export const failureOrCause = (self: Cause.Cause): Either.Either, E> => { const option = failureOption(self) switch (option._tag) { case "None": { @@ -892,7 +892,7 @@ export const reduceWithContext = dual< (self: Cause.Cause, context: C, reducer: Cause.CauseReducer) => Z >(3, (self: Cause.Cause, context: C, reducer: Cause.CauseReducer) => { const input: Array> = [self] - const output: Array> = [] + const output: Array> = [] while (input.length > 0) { const cause = input.pop()! switch (cause._tag) { diff --git a/packages/effect/src/internal/channel.ts b/packages/effect/src/internal/channel.ts index badd20c7b5..e87a97eb25 100644 --- a/packages/effect/src/internal/channel.ts +++ b/packages/effect/src/internal/channel.ts @@ -661,7 +661,7 @@ export const foldChannel = dual< /** @internal */ export const fromEither = ( - either: Either.Either + either: Either.Either ): Channel.Channel => core.suspend(() => Either.match(either, { onLeft: core.fail, onRight: core.succeed })) @@ -679,13 +679,13 @@ export const fromInput = ( /** @internal */ export const fromPubSub = ( - pubsub: PubSub.PubSub, Elem>> + pubsub: PubSub.PubSub>> ): Channel.Channel => unwrapScoped(Effect.map(PubSub.subscribe(pubsub), fromQueue)) /** @internal */ export const fromPubSubScoped = ( - pubsub: PubSub.PubSub, Elem>> + pubsub: PubSub.PubSub>> ): Effect.Effect, never, Scope.Scope> => Effect.map(PubSub.subscribe(pubsub), fromQueue) @@ -702,12 +702,12 @@ export const fromOption = ( /** @internal */ export const fromQueue = ( - queue: Queue.Dequeue, Elem>> + queue: Queue.Dequeue>> ): Channel.Channel => core.suspend(() => fromQueueInternal(queue)) /** @internal */ const fromQueueInternal = ( - queue: Queue.Dequeue, Elem>> + queue: Queue.Dequeue>> ): Channel.Channel => pipe( core.fromEffect(Queue.take(queue)), @@ -912,7 +912,7 @@ export const mapOutEffectPar = dual< Effect.gen(function*($) { const queue = yield* $( Effect.acquireRelease( - Queue.bounded, OutErr | OutErr1, Env1>>(n), + Queue.bounded, OutErr | OutErr1, Env1>>(n), (queue) => Queue.shutdown(queue) ) ) @@ -1143,7 +1143,7 @@ export const mergeAllWith = ( const queueReader = fromInput(input) const queue = yield* $( Effect.acquireRelease( - Queue.bounded, OutErr | OutErr1, Env>>(bufferSize), + Queue.bounded, OutErr | OutErr1, Env>>(bufferSize), (queue) => Queue.shutdown(queue) ) ) @@ -1159,7 +1159,7 @@ export const mergeAllWith = ( .withPermits const pull = yield* $(toPull(channels)) const evaluatePull = ( - pull: Effect.Effect, OutErr | OutErr1, Env | Env1> + pull: Effect.Effect, OutErr | OutErr1, Env | Env1> ) => pipe( Effect.flatMap( @@ -1622,9 +1622,9 @@ export const mergeWith = dual< > const handleSide = ( - exit: Exit.Exit, Err>, - fiber: Fiber.Fiber, Err2>, - pull: Effect.Effect, Err, Env | Env1> + exit: Exit.Exit, Err>, + fiber: Fiber.Fiber, Err2>, + pull: Effect.Effect, Err, Env | Env1> ) => ( done: ( @@ -1637,8 +1637,8 @@ export const mergeWith = dual< OutDone2 | OutDone3 >, both: ( - f1: Fiber.Fiber, Err>, - f2: Fiber.Fiber, Err2> + f1: Fiber.Fiber, Err>, + f2: Fiber.Fiber, Err2> ) => State, single: ( f: ( @@ -2107,13 +2107,13 @@ export const serviceWithEffect = >(tag: T) => /** @internal */ export const toPubSub = ( - pubsub: PubSub.PubSub, Elem>> + pubsub: PubSub.PubSub>> ): Channel.Channel => toQueue(pubsub) /** @internal */ export const toPull = ( self: Channel.Channel -): Effect.Effect, OutErr, Env>, never, Env | Scope.Scope> => +): Effect.Effect, OutErr, Env>, never, Env | Scope.Scope> => Effect.map( Effect.acquireRelease( Effect.sync(() => new executor.ChannelExecutor(self, void 0, identity)), @@ -2129,13 +2129,13 @@ export const toPull = ( const interpretToPull = ( channelState: ChannelState.ChannelState, exec: executor.ChannelExecutor -): Effect.Effect, OutErr, Env> => { +): Effect.Effect, OutErr, Env> => { const state = channelState as ChannelState.Primitive switch (state._tag) { case ChannelStateOpCodes.OP_DONE: { return Exit.match(exec.getDone(), { onFailure: Effect.failCause, - onSuccess: (done): Effect.Effect, OutErr, Env> => + onSuccess: (done): Effect.Effect, OutErr, Env> => Effect.succeed(Either.left(done)) }) } @@ -2144,7 +2144,7 @@ const interpretToPull = ( } case ChannelStateOpCodes.OP_FROM_EFFECT: { return pipe( - state.effect as Effect.Effect, OutErr, Env>, + state.effect as Effect.Effect, OutErr, Env>, Effect.flatMap(() => interpretToPull(exec.run() as ChannelState.ChannelState, exec)) ) } @@ -2152,7 +2152,7 @@ const interpretToPull = ( return executor.readUpstream( state, () => interpretToPull(exec.run() as ChannelState.ChannelState, exec), - (cause) => Effect.failCause(cause) as Effect.Effect, OutErr, Env> + (cause) => Effect.failCause(cause) as Effect.Effect, OutErr, Env> ) } } @@ -2160,12 +2160,12 @@ const interpretToPull = ( /** @internal */ export const toQueue = ( - queue: Queue.Enqueue, Elem>> + queue: Queue.Enqueue>> ): Channel.Channel => core.suspend(() => toQueueInternal(queue)) /** @internal */ const toQueueInternal = ( - queue: Queue.Enqueue, Elem>> + queue: Queue.Enqueue>> ): Channel.Channel => { return core.readWithCause({ onInput: (elem) => diff --git a/packages/effect/src/internal/channel/mergeState.ts b/packages/effect/src/internal/channel/mergeState.ts index 56a6352d74..4d26e38627 100644 --- a/packages/effect/src/internal/channel/mergeState.ts +++ b/packages/effect/src/internal/channel/mergeState.ts @@ -22,8 +22,8 @@ const proto = { /** @internal */ export const BothRunning = ( - left: Fiber.Fiber, Err>, - right: Fiber.Fiber, Err1> + left: Fiber.Fiber, Err>, + right: Fiber.Fiber, Err1> ): MergeState.MergeState => { const op = Object.create(proto) op._tag = OpCodes.OP_BOTH_RUNNING @@ -84,8 +84,8 @@ export const match = dual< ( options: { readonly onBothRunning: ( - left: Fiber.Fiber, Err>, - right: Fiber.Fiber, Err1> + left: Fiber.Fiber, Err>, + right: Fiber.Fiber, Err1> ) => Z readonly onLeftDone: (f: (exit: Exit.Exit) => Effect.Effect) => Z readonly onRightDone: (f: (exit: Exit.Exit) => Effect.Effect) => Z @@ -95,8 +95,8 @@ export const match = dual< self: MergeState.MergeState, options: { readonly onBothRunning: ( - left: Fiber.Fiber, Err>, - right: Fiber.Fiber, Err1> + left: Fiber.Fiber, Err>, + right: Fiber.Fiber, Err1> ) => Z readonly onLeftDone: (f: (exit: Exit.Exit) => Effect.Effect) => Z readonly onRightDone: (f: (exit: Exit.Exit) => Effect.Effect) => Z diff --git a/packages/effect/src/internal/channel/singleProducerAsyncInput.ts b/packages/effect/src/internal/channel/singleProducerAsyncInput.ts index 8d2f566866..260c54c938 100644 --- a/packages/effect/src/internal/channel/singleProducerAsyncInput.ts +++ b/packages/effect/src/internal/channel/singleProducerAsyncInput.ts @@ -47,7 +47,7 @@ interface Empty { /** @internal */ interface Emit { readonly _tag: OP_STATE_EMIT - readonly notifyConsumers: ReadonlyArray, Err>> + readonly notifyConsumers: ReadonlyArray, Err>> } /** @internal */ @@ -70,7 +70,7 @@ const stateEmpty = (notifyProducer: Deferred.Deferred): State( - notifyConsumers: ReadonlyArray, Err>> + notifyConsumers: ReadonlyArray, Err>> ): State => ({ _tag: OP_STATE_EMIT, notifyConsumers @@ -198,10 +198,10 @@ class SingleProducerAsyncInputImpl ) } - get take(): Effect.Effect>> { + get take(): Effect.Effect>> { return this.takeWith( (cause) => Exit.failCause(Cause.map(cause, Either.left)), - (elem) => Exit.succeed(elem) as Exit.Exit>, + (elem) => Exit.succeed(elem) as Exit.Exit>, (done) => Exit.fail(Either.right(done)) ) } @@ -211,7 +211,7 @@ class SingleProducerAsyncInputImpl onElement: (element: Elem) => A, onDone: (value: Done) => A ): Effect.Effect { - return Effect.flatMap(Deferred.make, Err>(), (deferred) => + return Effect.flatMap(Deferred.make, Err>(), (deferred) => Effect.flatten( Ref.modify(this.ref, (state) => { switch (state._tag) { diff --git a/packages/effect/src/internal/config.ts b/packages/effect/src/internal/config.ts index 5999fb09fa..26f7318283 100644 --- a/packages/effect/src/internal/config.ts +++ b/packages/effect/src/internal/config.ts @@ -60,7 +60,7 @@ export type Op = Config.Config & Body & { export interface Constant extends Op + parse(text: string): Either.Either }> {} @@ -85,7 +85,7 @@ export interface Fallback extends export interface Fail extends Op + parse(text: string): Either.Either }> {} @@ -100,7 +100,7 @@ export interface Lazy extends export interface MapOrFail extends Op - mapOrFail(value: unknown): Either.Either + mapOrFail(value: unknown): Either.Either }> {} @@ -116,7 +116,7 @@ export interface Nested extends export interface Primitive extends Op + parse(text: string): Either.Either }> {} @@ -314,8 +314,8 @@ export const mapAttempt = dual< /** @internal */ export const mapOrFail = dual< - (f: (a: A) => Either.Either) => (self: Config.Config) => Config.Config, - (self: Config.Config, f: (a: A) => Either.Either) => Config.Config + (f: (a: A) => Either.Either) => (self: Config.Config) => Config.Config, + (self: Config.Config, f: (a: A) => Either.Either) => Config.Config >(2, (self, f) => { const mapOrFail = Object.create(proto) mapOrFail._tag = OpCodes.OP_MAP_OR_FAIL @@ -385,7 +385,7 @@ export const option = (self: Config.Config): Config.Config( description: string, - parse: (text: string) => Either.Either + parse: (text: string) => Either.Either ): Config.Config => { const primitive = Object.create(proto) primitive._tag = OpCodes.OP_PRIMITIVE diff --git a/packages/effect/src/internal/configError.ts b/packages/effect/src/internal/configError.ts index 574583e7d7..b034139bfd 100644 --- a/packages/effect/src/internal/configError.ts +++ b/packages/effect/src/internal/configError.ts @@ -215,7 +215,7 @@ export const reduceWithContext = dual< (self: ConfigError.ConfigError, context: C, reducer: ConfigError.ConfigErrorReducer) => Z >(3, (self: ConfigError.ConfigError, context: C, reducer: ConfigError.ConfigErrorReducer) => { const input: Array = [self] - const output: Array> = [] + const output: Array> = [] while (input.length > 0) { const error = input.pop()! switch (error._tag) { diff --git a/packages/effect/src/internal/configProvider.ts b/packages/effect/src/internal/configProvider.ts index e00c2fd0df..0685076020 100644 --- a/packages/effect/src/internal/configProvider.ts +++ b/packages/effect/src/internal/configProvider.ts @@ -438,7 +438,7 @@ const fromFlatLoop = ( } const fromFlatLoopFail = - (prefix: ReadonlyArray, path: string) => (index: number): Either.Either => + (prefix: ReadonlyArray, path: string) => (index: number): Either.Either => Either.left( configError.MissingData( prefix, diff --git a/packages/effect/src/internal/configProvider/pathPatch.ts b/packages/effect/src/internal/configProvider/pathPatch.ts index be7add3403..64813b047b 100644 --- a/packages/effect/src/internal/configProvider/pathPatch.ts +++ b/packages/effect/src/internal/configProvider/pathPatch.ts @@ -46,11 +46,11 @@ export const patch = dual< patch: PathPatch.PathPatch ) => ( path: ReadonlyArray - ) => Either.Either>, + ) => Either.Either, ConfigError.ConfigError>, ( path: ReadonlyArray, patch: PathPatch.PathPatch - ) => Either.Either> + ) => Either.Either, ConfigError.ConfigError> >(2, (path, patch) => { let input: List.List = List.of(patch) let output: ReadonlyArray = path diff --git a/packages/effect/src/internal/core.ts b/packages/effect/src/internal/core.ts index 56361c0ff4..d10e00979f 100644 --- a/packages/effect/src/internal/core.ts +++ b/packages/effect/src/internal/core.ts @@ -634,7 +634,7 @@ export const dieMessage = (message: string): Effect.Effect => export const dieSync = (evaluate: LazyArg): Effect.Effect => flatMap(sync(evaluate), die) /* @internal */ -export const either = (self: Effect.Effect): Effect.Effect, never, R> => +export const either = (self: Effect.Effect): Effect.Effect, never, R> => matchEffect(self, { onFailure: (e) => succeed(Either.left(e)), onSuccess: (a) => succeed(Either.right(a)) @@ -1126,7 +1126,7 @@ export const orDieWith: { /* @internal */ export const partitionMap = ( elements: Iterable, - f: (a: A) => Either.Either + f: (a: A) => Either.Either ): [left: Array, right: Array] => ReadonlyArray.fromIterable(elements).reduceRight( ([lefts, rights], current) => { @@ -2522,7 +2522,7 @@ export const exitForEachEffect: { }) /** @internal */ -export const exitFromEither = (either: Either.Either): Exit.Exit => { +export const exitFromEither = (either: Either.Either): Exit.Exit => { switch (either._tag) { case "Left": return exitFail(either.left) diff --git a/packages/effect/src/internal/dataSource.ts b/packages/effect/src/internal/dataSource.ts index 2db14516ba..b0e420f888 100644 --- a/packages/effect/src/internal/dataSource.ts +++ b/packages/effect/src/internal/dataSource.ts @@ -162,7 +162,7 @@ export const eitherWith = dual< C extends Request.Request >( that: RequestResolver.RequestResolver, - f: (_: Request.Entry) => Either.Either, Request.Entry> + f: (_: Request.Entry) => Either.Either, Request.Entry> ) => ( self: RequestResolver.RequestResolver ) => RequestResolver.RequestResolver, @@ -175,7 +175,7 @@ export const eitherWith = dual< >( self: RequestResolver.RequestResolver, that: RequestResolver.RequestResolver, - f: (_: Request.Entry) => Either.Either, Request.Entry> + f: (_: Request.Entry) => Either.Either, Request.Entry> ) => RequestResolver.RequestResolver >(3, < R, @@ -186,7 +186,7 @@ export const eitherWith = dual< >( self: RequestResolver.RequestResolver, that: RequestResolver.RequestResolver, - f: (_: Request.Entry) => Either.Either, Request.Entry> + f: (_: Request.Entry) => Either.Either, Request.Entry> ) => new core.RequestResolverImpl( (batch) => diff --git a/packages/effect/src/internal/differ.ts b/packages/effect/src/internal/differ.ts index 1955ec71c8..d4071d1483 100644 --- a/packages/effect/src/internal/differ.ts +++ b/packages/effect/src/internal/differ.ts @@ -86,11 +86,11 @@ export const hashSet = (): Differ.Differ, Differ.Differ.Ha export const orElseEither = Dual.dual< (that: Differ.Differ) => ( self: Differ.Differ - ) => Differ.Differ, Differ.Differ.Or.Patch>, + ) => Differ.Differ, Differ.Differ.Or.Patch>, ( self: Differ.Differ, that: Differ.Differ - ) => Differ.Differ, Differ.Differ.Or.Patch> + ) => Differ.Differ, Differ.Differ.Or.Patch> >(2, (self, that) => make({ empty: OrPatch.empty(), diff --git a/packages/effect/src/internal/differ/orPatch.ts b/packages/effect/src/internal/differ/orPatch.ts index 43d1233c57..71e71cc675 100644 --- a/packages/effect/src/internal/differ/orPatch.ts +++ b/packages/effect/src/internal/differ/orPatch.ts @@ -188,8 +188,8 @@ type Instruction = /** @internal */ export const diff = ( options: { - readonly oldValue: Either - readonly newValue: Either + readonly oldValue: Either + readonly newValue: Either readonly left: Differ readonly right: Differ } @@ -243,23 +243,23 @@ export const combine = Dual.dual< export const patch = Dual.dual< ( options: { - readonly oldValue: Either + readonly oldValue: Either readonly left: Differ readonly right: Differ } - ) => (self: Differ.Or.Patch) => Either, + ) => (self: Differ.Or.Patch) => Either, ( self: Differ.Or.Patch, options: { - readonly oldValue: Either + readonly oldValue: Either readonly left: Differ readonly right: Differ } - ) => Either + ) => Either >(2, ( self: Differ.Or.Patch, { left, oldValue, right }: { - oldValue: Either + oldValue: Either left: Differ right: Differ } diff --git a/packages/effect/src/internal/either.ts b/packages/effect/src/internal/either.ts index a35e221dce..107a590ab2 100644 --- a/packages/effect/src/internal/either.ts +++ b/packages/effect/src/internal/either.ts @@ -22,7 +22,7 @@ const CommonProto = { [TypeId]: { _A: (_: never) => _ }, - [NodeInspectSymbol](this: Either.Either) { + [NodeInspectSymbol](this: Either.Either) { return this.toJSON() }, toString(this: Either.Left) { @@ -70,20 +70,20 @@ const LeftProto = Object.assign(Object.create(CommonProto), { export const isEither = (input: unknown): input is Either.Either => hasProperty(input, TypeId) /** @internal */ -export const isLeft = (ma: Either.Either): ma is Either.Left => ma._tag === "Left" +export const isLeft = (ma: Either.Either): ma is Either.Left => ma._tag === "Left" /** @internal */ -export const isRight = (ma: Either.Either): ma is Either.Right => ma._tag === "Right" +export const isRight = (ma: Either.Either): ma is Either.Right => ma._tag === "Right" /** @internal */ -export const left = (left: E): Either.Either => { +export const left = (left: E): Either.Either => { const a = Object.create(LeftProto) a.left = left return a } /** @internal */ -export const right = (right: A): Either.Either => { +export const right = (right: A): Either.Either => { const a = Object.create(RightProto) a.right = right return a @@ -91,17 +91,17 @@ export const right = (right: A): Either.Either => { /** @internal */ export const getLeft = ( - self: Either.Either + self: Either.Either ): Option => (isRight(self) ? option.none : option.some(self.left)) /** @internal */ export const getRight = ( - self: Either.Either + self: Either.Either ): Option => (isLeft(self) ? option.none : option.some(self.right)) /** @internal */ export const fromOption = dual( 2, - (self: Option, onNone: () => E): Either.Either => + (self: Option, onNone: () => E): Either.Either => option.isNone(self) ? left(onNone()) : right(self.value) ) diff --git a/packages/effect/src/internal/encoding/base64.ts b/packages/effect/src/internal/encoding/base64.ts index 4ce2504d16..2cec83da40 100644 --- a/packages/effect/src/internal/encoding/base64.ts +++ b/packages/effect/src/internal/encoding/base64.ts @@ -35,7 +35,7 @@ export const encode = (bytes: Uint8Array) => { } /** @internal */ -export const decode = (str: string): Either.Either => { +export const decode = (str: string): Either.Either => { const length = str.length if (length % 4 !== 0) { return Either.left( diff --git a/packages/effect/src/internal/encoding/base64Url.ts b/packages/effect/src/internal/encoding/base64Url.ts index a6909a9827..7a46ae4c50 100644 --- a/packages/effect/src/internal/encoding/base64Url.ts +++ b/packages/effect/src/internal/encoding/base64Url.ts @@ -8,7 +8,7 @@ export const encode = (data: Uint8Array) => Base64.encode(data).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_") /** @internal */ -export const decode = (str: string): Either.Either => { +export const decode = (str: string): Either.Either => { const length = str.length if (length % 4 === 1) { return Either.left( diff --git a/packages/effect/src/internal/encoding/hex.ts b/packages/effect/src/internal/encoding/hex.ts index c511f2b51d..a46d71202c 100644 --- a/packages/effect/src/internal/encoding/hex.ts +++ b/packages/effect/src/internal/encoding/hex.ts @@ -13,7 +13,7 @@ export const encode = (bytes: Uint8Array) => { } /** @internal */ -export const decode = (str: string): Either.Either => { +export const decode = (str: string): Either.Either => { const bytes = new TextEncoder().encode(str) if (bytes.length % 2 !== 0) { return Either.left(DecodeException(str, `Length must be a multiple of 2, but is ${bytes.length}`)) diff --git a/packages/effect/src/internal/fiber.ts b/packages/effect/src/internal/fiber.ts index 11e268639f..1b9364cbf3 100644 --- a/packages/effect/src/internal/fiber.ts +++ b/packages/effect/src/internal/fiber.ts @@ -260,8 +260,8 @@ export const orElse = dual< /** @internal */ export const orElseEither = dual< - (that: Fiber.Fiber) => (self: Fiber.Fiber) => Fiber.Fiber, E | E2>, - (self: Fiber.Fiber, that: Fiber.Fiber) => Fiber.Fiber, E | E2> + (that: Fiber.Fiber) => (self: Fiber.Fiber) => Fiber.Fiber, E | E2>, + (self: Fiber.Fiber, that: Fiber.Fiber) => Fiber.Fiber, E | E2> >(2, (self, that) => orElse(map(self, Either.left), map(that, Either.right))) /** @internal */ diff --git a/packages/effect/src/internal/matcher.ts b/packages/effect/src/internal/matcher.ts index 0014d68478..45a0f06a75 100644 --- a/packages/effect/src/internal/matcher.ts +++ b/packages/effect/src/internal/matcher.ts @@ -87,7 +87,7 @@ const ValueMatcherProto: Omit< function makeValueMatcher( provided: Pr, - value: Either.Either + value: Either.Either ): ValueMatcher { const matcher = Object.create(ValueMatcherProto) matcher.provided = provided @@ -514,8 +514,8 @@ export const orElseAbsurd = ( /** @internal */ export const either: ( self: Matcher -) => [Pr] extends [never] ? (input: I) => Either.Either> - : Either.Either> = ((self: Matcher) => { +) => [Pr] extends [never] ? (input: I) => Either.Either, R> + : Either.Either, R> = ((self: Matcher) => { if (self._tag === "ValueMatcher") { return self.value } @@ -523,7 +523,7 @@ export const either: ( const len = self.cases.length if (len === 1) { const _case = self.cases[0] - return (input: I): Either.Either => { + return (input: I): Either.Either => { if (_case._tag === "When" && _case.guard(input) === true) { return Either.right(_case.evaluate(input)) } else if (_case._tag === "Not" && _case.guard(input) === false) { @@ -532,7 +532,7 @@ export const either: ( return Either.left(input as any) } } - return (input: I): Either.Either => { + return (input: I): Either.Either => { for (let i = 0; i < len; i++) { const _case = self.cases[i] if (_case._tag === "When" && _case.guard(input) === true) { diff --git a/packages/effect/src/internal/schedule.ts b/packages/effect/src/internal/schedule.ts index 92e5a5e69d..524d884549 100644 --- a/packages/effect/src/internal/schedule.ts +++ b/packages/effect/src/internal/schedule.ts @@ -203,7 +203,7 @@ export const andThenEither = dual< ) => (self: Schedule.Schedule) => Schedule.Schedule< Env | Env2, In & In2, - Either.Either + Either.Either >, ( self: Schedule.Schedule, @@ -211,7 +211,7 @@ export const andThenEither = dual< ) => Schedule.Schedule< Env | Env2, In & In2, - Either.Either + Either.Either > >(2, ( self: Schedule.Schedule, @@ -219,7 +219,7 @@ export const andThenEither = dual< ): Schedule.Schedule< Env | Env2, In & In2, - Either.Either + Either.Either > => makeWithState( [self.initial, that.initial, true as boolean] as const, @@ -230,7 +230,7 @@ export const andThenEither = dual< return core.map(that.step(now, input, state[1]), ([rState, out, decision]) => [ [lState, rState, false as boolean] as const, - Either.right(out) as Either.Either, + Either.right(out) as Either.Either, decision as ScheduleDecision.ScheduleDecision ] as const) } @@ -245,7 +245,7 @@ export const andThenEither = dual< core.map(that.step(now, input, state[1]), ([rState, out, decision]) => [ [state[0], rState, false as boolean] as const, - Either.right(out) as Either.Either, + Either.right(out) as Either.Either, decision ] as const) )) diff --git a/packages/effect/src/internal/sink.ts b/packages/effect/src/internal/sink.ts index a348d05658..035f5bb442 100644 --- a/packages/effect/src/internal/sink.ts +++ b/packages/effect/src/internal/sink.ts @@ -1435,7 +1435,7 @@ export const fromPubSub = ( /** @internal */ export const fromPush = ( push: Effect.Effect< - (_: Option.Option>) => Effect.Effect, Chunk.Chunk], R>, + (_: Option.Option>) => Effect.Effect, Chunk.Chunk], R>, never, R > @@ -1445,7 +1445,7 @@ export const fromPush = ( const fromPushPull = ( push: ( option: Option.Option> - ) => Effect.Effect, Chunk.Chunk], R> + ) => Effect.Effect, Chunk.Chunk], R> ): Channel.Channel, Chunk.Chunk, E, never, Z, unknown, R> => core.readWith({ onInput: (input: Chunk.Chunk) => @@ -1609,14 +1609,14 @@ export const raceBoth = dual< } ) => ( self: Sink.Sink - ) => Sink.Sink, In & In1, L1 | L, E1 | E, R1 | R>, + ) => Sink.Sink, In & In1, L1 | L, E1 | E, R1 | R>, ( self: Sink.Sink, that: Sink.Sink, options?: { readonly capacity?: number | undefined } - ) => Sink.Sink, In & In1, L1 | L, E1 | E, R1 | R> + ) => Sink.Sink, In & In1, L1 | L, E1 | E, R1 | R> >( (args) => isSink(args[1]), (self, that, options) => @@ -1660,7 +1660,7 @@ export const raceWith = dual< ): Sink.Sink => { const scoped = Effect.gen(function*($) { const pubsub = yield* $( - PubSub.bounded, Chunk.Chunk>>(options?.capacity ?? 16) + PubSub.bounded, Exit.Exit>>(options?.capacity ?? 16) ) const channel1 = yield* $(channel.fromPubSubScoped(pubsub)) const channel2 = yield* $(channel.fromPubSubScoped(pubsub)) diff --git a/packages/effect/src/internal/stm/stm.ts b/packages/effect/src/internal/stm/stm.ts index 661f5604c3..13483d7e53 100644 --- a/packages/effect/src/internal/stm/stm.ts +++ b/packages/effect/src/internal/stm/stm.ts @@ -320,7 +320,7 @@ export const cond = ( } /** @internal */ -export const either = (self: STM.STM): STM.STM, never, R> => +export const either = (self: STM.STM): STM.STM, never, R> => match(self, { onFailure: Either.left, onSuccess: Either.right }) /** @internal */ @@ -595,7 +595,7 @@ export const forEach = dual< ) /** @internal */ -export const fromEither = (either: Either.Either): STM.STM => { +export const fromEither = (either: Either.Either): STM.STM => { switch (either._tag) { case "Left": { return core.fail(either.left) @@ -909,17 +909,17 @@ export const orElseEither = dual< that: LazyArg> ) => ( self: STM.STM - ) => STM.STM, E2, R2 | R>, + ) => STM.STM, E2, R2 | R>, ( self: STM.STM, that: LazyArg> - ) => STM.STM, E2, R2 | R> + ) => STM.STM, E2, R2 | R> >( 2, ( self: STM.STM, that: LazyArg> - ): STM.STM, E2, R2 | R> => + ): STM.STM, E2, R2 | R> => orElse(core.map(self, Either.left), () => core.map(that(), Either.right)) ) diff --git a/packages/effect/src/internal/stm/tDeferred.ts b/packages/effect/src/internal/stm/tDeferred.ts index ca3ad8f466..4e4388efcd 100644 --- a/packages/effect/src/internal/stm/tDeferred.ts +++ b/packages/effect/src/internal/stm/tDeferred.ts @@ -27,7 +27,7 @@ const tDeferredVariance = { /** @internal */ class TDeferredImpl implements TDeferred.TDeferred { readonly [TDeferredTypeId] = tDeferredVariance - constructor(readonly ref: TRef.TRef>>) {} + constructor(readonly ref: TRef.TRef>>) {} } /** @internal */ @@ -41,8 +41,8 @@ export const _await = (self: TDeferred.TDeferred): STM.STM => /** @internal */ export const done = dual< - (either: Either.Either) => (self: TDeferred.TDeferred) => STM.STM, - (self: TDeferred.TDeferred, either: Either.Either) => STM.STM + (either: Either.Either) => (self: TDeferred.TDeferred) => STM.STM, + (self: TDeferred.TDeferred, either: Either.Either) => STM.STM >(2, (self, either) => core.flatMap( tRef.get(self.ref), @@ -65,14 +65,14 @@ export const fail = dual< /** @internal */ export const make = (): STM.STM> => core.map( - tRef.make>>(Option.none()), + tRef.make>>(Option.none()), (ref) => new TDeferredImpl(ref) ) /** @internal */ export const poll = ( self: TDeferred.TDeferred -): STM.STM>> => tRef.get(self.ref) +): STM.STM>> => tRef.get(self.ref) /** @internal */ export const succeed = dual< diff --git a/packages/effect/src/internal/stream.ts b/packages/effect/src/internal/stream.ts index 85b88423e3..92bd26e688 100644 --- a/packages/effect/src/internal/stream.ts +++ b/packages/effect/src/internal/stream.ts @@ -164,19 +164,19 @@ export const aggregateWithinEither = dual< ( sink: Sink.Sink, schedule: Schedule.Schedule, C> - ) => (self: Stream.Stream) => Stream.Stream, E2 | E, R2 | R3 | R>, + ) => (self: Stream.Stream) => Stream.Stream, E2 | E, R2 | R3 | R>, ( self: Stream.Stream, sink: Sink.Sink, schedule: Schedule.Schedule, C> - ) => Stream.Stream, E2 | E, R2 | R3 | R> + ) => Stream.Stream, E2 | E, R2 | R3 | R> >( 3, ( self: Stream.Stream, sink: Sink.Sink, schedule: Schedule.Schedule, C> - ): Stream.Stream, E2 | E, R2 | R3 | R> => { + ): Stream.Stream, E2 | E, R2 | R3 | R> => { const layer = Effect.all([ Handoff.make>(), Ref.make(SinkEndReason.ScheduleEnd), @@ -284,7 +284,7 @@ export const aggregateWithinEither = dual< sinkFiber: Fiber.RuntimeFiber>, B], E | E2>, scheduleFiber: Fiber.RuntimeFiber>, scope: Scope.Scope - ): Channel.Channel>, unknown, E | E2, unknown, unknown, unknown, R2 | R3> => { + ): Channel.Channel>, unknown, E | E2, unknown, unknown, unknown, R2 | R3> => { const forkSink = pipe( Ref.set(consumed, false), Effect.zipRight(Ref.set(endAfterEmit, false)), @@ -302,7 +302,7 @@ export const aggregateWithinEither = dual< leftovers: Chunk.Chunk>, b: B, c: Option.Option - ): Channel.Channel>, unknown, E | E2, unknown, unknown, unknown, R2 | R3> => + ): Channel.Channel>, unknown, E | E2, unknown, unknown, unknown, R2 | R3> => pipe( Ref.set(sinkLeftovers, Chunk.flatten(leftovers)), Effect.zipRight( @@ -319,8 +319,8 @@ export const aggregateWithinEither = dual< const toWrite = pipe( c, Option.match({ - onNone: (): Chunk.Chunk> => Chunk.of(Either.right(b)), - onSome: (c): Chunk.Chunk> => + onNone: (): Chunk.Chunk> => Chunk.of(Either.right(b)), + onSome: (c): Chunk.Chunk> => Chunk.make(Either.right(b), Either.left(c)) }) ) @@ -340,7 +340,7 @@ export const aggregateWithinEither = dual< Ref.get(consumed), Effect.map((wasConsumed) => wasConsumed ? - core.write(Chunk.of>(Either.right(b))) : + core.write(Chunk.of>(Either.right(b))) : core.unit ), channel.unwrap @@ -2246,7 +2246,7 @@ export const dropWhileEffect = dual< ) /** @internal */ -export const either = (self: Stream.Stream): Stream.Stream, never, R> => +export const either = (self: Stream.Stream): Stream.Stream, never, R> => pipe(self, map(Either.right), catchAll((error) => make(Either.left(error)))) /** @internal */ @@ -3903,17 +3903,17 @@ export const mergeAll = dual< export const mergeEither = dual< ( that: Stream.Stream - ) => (self: Stream.Stream) => Stream.Stream, E2 | E, R2 | R>, + ) => (self: Stream.Stream) => Stream.Stream, E2 | E, R2 | R>, ( self: Stream.Stream, that: Stream.Stream - ) => Stream.Stream, E2 | E, R2 | R> + ) => Stream.Stream, E2 | E, R2 | R> >( 2, ( self: Stream.Stream, that: Stream.Stream - ): Stream.Stream, E2 | E, R2 | R> => + ): Stream.Stream, E2 | E, R2 | R> => mergeWith(self, that, { onSelf: Either.left, onOther: Either.right }) ) @@ -4081,17 +4081,17 @@ export const orElse = dual< export const orElseEither = dual< ( that: LazyArg> - ) => (self: Stream.Stream) => Stream.Stream, E2, R2 | R>, + ) => (self: Stream.Stream) => Stream.Stream, E2, R2 | R>, ( self: Stream.Stream, that: LazyArg> - ) => Stream.Stream, E2, R2 | R> + ) => Stream.Stream, E2, R2 | R> >( 2, ( self: Stream.Stream, that: LazyArg> - ): Stream.Stream, E2, R2 | R> => + ): Stream.Stream, E2, R2 | R> => pipe(self, map(Either.left), orElse(() => pipe(that(), map(Either.right)))) ) @@ -4391,7 +4391,7 @@ export const partition: { /** @internal */ export const partitionEither = dual< ( - predicate: (a: NoInfer) => Effect.Effect, E2, R2>, + predicate: (a: NoInfer) => Effect.Effect, E2, R2>, options?: { readonly bufferSize?: number | undefined } @@ -4404,7 +4404,7 @@ export const partitionEither = dual< >, ( self: Stream.Stream, - predicate: (a: A) => Effect.Effect, E2, R2>, + predicate: (a: A) => Effect.Effect, E2, R2>, options?: { readonly bufferSize?: number | undefined } @@ -4417,7 +4417,7 @@ export const partitionEither = dual< (args) => typeof args[1] === "function", ( self: Stream.Stream, - predicate: (a: A) => Effect.Effect, E2, R2>, + predicate: (a: A) => Effect.Effect, E2, R2>, options?: { readonly bufferSize?: number | undefined } @@ -4857,19 +4857,19 @@ export const repeatEffectOption = (effect: Effect.Effect( schedule: Schedule.Schedule - ) => (self: Stream.Stream) => Stream.Stream, E, R2 | R>, + ) => (self: Stream.Stream) => Stream.Stream, E, R2 | R>, ( self: Stream.Stream, schedule: Schedule.Schedule - ) => Stream.Stream, E, R2 | R> + ) => Stream.Stream, E, R2 | R> >( 2, ( self: Stream.Stream, schedule: Schedule.Schedule - ): Stream.Stream, E, R2 | R> => + ): Stream.Stream, E, R2 | R> => repeatWith(self, schedule, { - onElement: (a): Either.Either => Either.right(a), + onElement: (a): Either.Either => Either.right(a), onSchedule: Either.left }) ) @@ -7813,7 +7813,7 @@ export const zipWithChunks = dual< f: ( left: Chunk.Chunk, right: Chunk.Chunk - ) => readonly [Chunk.Chunk, Either.Either, Chunk.Chunk>] + ) => readonly [Chunk.Chunk, Either.Either, Chunk.Chunk>] ) => (self: Stream.Stream) => Stream.Stream, ( self: Stream.Stream, @@ -7821,7 +7821,7 @@ export const zipWithChunks = dual< f: ( left: Chunk.Chunk, right: Chunk.Chunk - ) => readonly [Chunk.Chunk, Either.Either, Chunk.Chunk>] + ) => readonly [Chunk.Chunk, Either.Either, Chunk.Chunk>] ) => Stream.Stream >(3, ( self: Stream.Stream, @@ -7829,7 +7829,7 @@ export const zipWithChunks = dual< f: ( left: Chunk.Chunk, right: Chunk.Chunk - ) => readonly [Chunk.Chunk, Either.Either, Chunk.Chunk>] + ) => readonly [Chunk.Chunk, Either.Either, Chunk.Chunk>] ): Stream.Stream => { const pull = ( state: ZipChunksState.ZipChunksState, @@ -7991,7 +7991,7 @@ const zipChunks = ( left: Chunk.Chunk, right: Chunk.Chunk, f: (a: A, b: B) => C -): [Chunk.Chunk, Either.Either, Chunk.Chunk>] => { +): [Chunk.Chunk, Either.Either, Chunk.Chunk>] => { if (left.length > right.length) { return [ pipe(left, Chunk.take(right.length), Chunk.zipWith(right, f)), diff --git a/packages/effect/test/Effect/error-handling.test.ts b/packages/effect/test/Effect/error-handling.test.ts index 1a71686ea5..fbad4bd371 100644 --- a/packages/effect/test/Effect/error-handling.test.ts +++ b/packages/effect/test/Effect/error-handling.test.ts @@ -405,8 +405,8 @@ describe("Effect", () => { const causes = causesArb(1, smallInts, fc.string()) const successes = smallInts.map(Effect.succeed) const exits = fc.oneof( - causes.map((s): Either.Either, Effect.Effect> => Either.left(s)), - successes.map((s): Either.Either, Effect.Effect> => Either.right(s)) + causes.map((s): Either.Either, Cause.Cause> => Either.left(s)), + successes.map((s): Either.Either, Cause.Cause> => Either.right(s)) ).map(Either.match({ onLeft: Exit.failCause, onRight: Exit.succeed diff --git a/packages/effect/test/Effect/interruption.test.ts b/packages/effect/test/Effect/interruption.test.ts index 0b0172083f..bb3fd14d77 100644 --- a/packages/effect/test/Effect/interruption.test.ts +++ b/packages/effect/test/Effect/interruption.test.ts @@ -314,7 +314,7 @@ describe("Effect", () => { })) it.effect("sandbox of interruptible", () => Effect.gen(function*($) { - const recovered = yield* $(Ref.make>>(Option.none())) + const recovered = yield* $(Ref.make>>(Option.none())) const fiber = yield* $(withLatch((release) => pipe( release, diff --git a/packages/effect/test/Effect/structural.test.ts b/packages/effect/test/Effect/structural.test.ts index e83478e4d0..2952a0064f 100644 --- a/packages/effect/test/Effect/structural.test.ts +++ b/packages/effect/test/Effect/structural.test.ts @@ -144,13 +144,13 @@ describe("Effect", () => { Effect.gen(function*($) { const res = yield* $(Effect.all([Effect.succeed(0), Effect.succeed(1)], { mode: "either" })) assert.deepEqual(res, [Either.right(0), Either.right(1)]) - satisfies(assertType<[Either.Either, Either.Either]>()(res)) + satisfies(assertType<[Either.Either, Either.Either]>()(res)) })) it.effect("failure should work with one array argument", () => Effect.gen(function*($) { const res = yield* $(Effect.all([Effect.fail(0), Effect.succeed(1)], { mode: "either" })) assert.deepEqual(res, [Either.left(0), Either.right(1)]) - satisfies(assertType<[Either.Either, Either.Either]>()(res)) + satisfies(assertType<[Either.Either, Either.Either]>()(res)) })) it.effect("should work with one record argument", () => Effect.gen(function*($) { @@ -160,8 +160,8 @@ describe("Effect", () => { assert.deepEqual(b, Either.right(1)) satisfies( assertType<{ - readonly a: Either.Either - readonly b: Either.Either + readonly a: Either.Either + readonly b: Either.Either }>()(result) ) })) @@ -175,8 +175,8 @@ describe("Effect", () => { assert.deepEqual(b, Either.right(1)) satisfies( assertType<{ - readonly a: Either.Either - readonly b: Either.Either + readonly a: Either.Either + readonly b: Either.Either }>()(result) ) })) @@ -184,7 +184,7 @@ describe("Effect", () => { Effect.gen(function*($) { const result = yield* $(Effect.all(new Set([Effect.succeed(0), Effect.succeed(1)]), { mode: "either" })) assert.deepEqual(result, [Either.right(0), Either.right(1)]) - satisfies(assertType>>()(result)) + satisfies(assertType>>()(result)) })) }) describe("allWith", () => { diff --git a/packages/effect/test/Either.test.ts b/packages/effect/test/Either.test.ts index d60f677bf8..b5392ef464 100644 --- a/packages/effect/test/Either.test.ts +++ b/packages/effect/test/Either.test.ts @@ -285,7 +285,7 @@ describe("Either", () => { Either.left("b") ) expect( - (Either.left("a") as Either.Either).pipe( + (Either.left("a") as Either.Either).pipe( Either.ap(Either.right(1)), Either.ap(Either.right(2)) ) diff --git a/packages/effect/test/Match.test.ts b/packages/effect/test/Match.test.ts index c9aa37484a..81a7918705 100644 --- a/packages/effect/test/Match.test.ts +++ b/packages/effect/test/Match.test.ts @@ -320,8 +320,8 @@ describe("Match", () => { it("unify", () => { const match = pipe( M.type<{ readonly _tag: "A" } | { readonly _tag: "B" }>(), - M.tag("A", () => E.right("a") as E.Either), - M.tag("B", () => E.right(123) as E.Either), + M.tag("A", () => E.right("a") as E.Either), + M.tag("B", () => E.right(123) as E.Either), M.exhaustive ) @@ -749,7 +749,7 @@ describe("Match", () => { ) assertType< - E.Either<{ a: number; b: string }, string> + E.Either >()(match({ a, b })) satisfies true }) diff --git a/packages/effect/test/ReadonlyRecord.test.ts b/packages/effect/test/ReadonlyRecord.test.ts index 1e98291086..6997c0c33a 100644 --- a/packages/effect/test/ReadonlyRecord.test.ts +++ b/packages/effect/test/ReadonlyRecord.test.ts @@ -144,7 +144,7 @@ describe("ReadonlyRecord", () => { [{ a: "e" }, { b: 1 }] ) // should ignore non own properties - const o: RR.ReadonlyRecord> = Object.create({ a: 1 }) + const o: RR.ReadonlyRecord> = Object.create({ a: 1 }) assert.deepStrictEqual(pipe(o, RR.separate), [{}, {}]) }) diff --git a/packages/effect/test/Resource.test.ts b/packages/effect/test/Resource.test.ts index 6c621cb137..3bd72cf3c7 100644 --- a/packages/effect/test/Resource.test.ts +++ b/packages/effect/test/Resource.test.ts @@ -38,7 +38,7 @@ describe("Resource", () => { })) it.scopedLive("failed refresh doesn't affect cached value", () => Effect.gen(function*($) { - const ref = yield* $(Ref.make>(Either.right(0))) + const ref = yield* $(Ref.make>(Either.right(0))) const cached = yield* $(Cached.auto(Effect.flatMap(Ref.get(ref), identity), Schedule.spaced(Duration.millis(4)))) const result1 = yield* $(Cached.get(cached)) const result2 = yield* $( diff --git a/packages/platform-browser/src/internal/http/client.ts b/packages/platform-browser/src/internal/http/client.ts index 7217f83874..c3d12f7f0e 100644 --- a/packages/platform-browser/src/internal/http/client.ts +++ b/packages/platform-browser/src/internal/http/client.ts @@ -6,7 +6,6 @@ import * as Headers from "@effect/platform/Http/Headers" import * as IncomingMessage from "@effect/platform/Http/IncomingMessage" import * as UrlParams from "@effect/platform/Http/UrlParams" import * as Effect from "effect/Effect" -import * as Either from "effect/Either" import * as FiberRef from "effect/FiberRef" import type { LazyArg } from "effect/Function" import { globalValue } from "effect/GlobalValue" @@ -183,7 +182,7 @@ export class IncomingMessageImpl implements IncomingMessage.IncomingMessage { - return Stream.asyncInterrupt((emit) => { + return Stream.async((emit) => { let offset = 0 const onReadyStateChange = () => { if (this.source.readyState === 3) { @@ -202,10 +201,10 @@ export class IncomingMessageImpl implements IncomingMessage.IncomingMessage { + return Effect.sync(() => { this.source.removeEventListener("readystatechange", onReadyStateChange) this.source.removeEventListener("error", onError) - })) + }) }) } diff --git a/packages/platform-node-shared/src/internal/stream.ts b/packages/platform-node-shared/src/internal/stream.ts index fa55b2975f..c53f03cfba 100644 --- a/packages/platform-node-shared/src/internal/stream.ts +++ b/packages/platform-node-shared/src/internal/stream.ts @@ -117,7 +117,7 @@ export const fromDuplex = ( Effect.tap( Effect.zip( Effect.sync(evaluate), - Queue.unbounded, void>>() + Queue.unbounded>>() ), ([duplex, queue]) => readableOffer(duplex, queue, onError) ), @@ -199,7 +199,7 @@ export const fromReadableChannel = ( Effect.tap( Effect.zip( Effect.sync(evaluate), - Queue.unbounded, void>>() + Queue.unbounded>>() ), ([readable, queue]) => readableOffer(readable, queue, onError) ), @@ -270,7 +270,7 @@ export const writeEffect = ( const readableOffer = ( readable: Readable | NodeJS.ReadableStream, - queue: Queue.Queue, void>>, + queue: Queue.Queue>>, onError: (error: unknown) => E ) => Effect.sync(() => { @@ -293,7 +293,7 @@ const readableOffer = ( const readableTake = ( readable: Readable | NodeJS.ReadableStream, - queue: Queue.Queue, void>>, + queue: Queue.Queue>>, chunkSize: number | undefined ) => { const read = readChunkChannel(readable, chunkSize) diff --git a/packages/schema/src/ParseResult.ts b/packages/schema/src/ParseResult.ts index f7f16a503d..616a68462d 100644 --- a/packages/schema/src/ParseResult.ts +++ b/packages/schema/src/ParseResult.ts @@ -54,18 +54,18 @@ export const parseError = (issue: ParseIssue): ParseError => new ParseError({ er * @category constructors * @since 1.0.0 */ -export const succeed: (a: A) => Either.Either = Either.right +export const succeed: (a: A) => Either.Either = Either.right /** * @category constructors * @since 1.0.0 */ -export const fail: (issue: ParseIssue) => Either.Either = Either.left +export const fail: (issue: ParseIssue) => Either.Either = Either.left const _try: (options: { try: LazyArg catch: (e: unknown) => ParseIssue -}) => Either.Either = Either.try +}) => Either.Either = Either.try export { /** diff --git a/packages/schema/src/Parser.ts b/packages/schema/src/Parser.ts index 80c4661c0a..6628c050ef 100644 --- a/packages/schema/src/Parser.ts +++ b/packages/schema/src/Parser.ts @@ -35,7 +35,7 @@ export const mergeParseOptions = ( const getEither = (ast: AST.AST, isDecoding: boolean, options?: AST.ParseOptions) => { const parser = goMemo(ast, isDecoding) - return (u: unknown, overrideOptions?: AST.ParseOptions): Either.Either => + return (u: unknown, overrideOptions?: AST.ParseOptions): Either.Either => parser(u, mergeParseOptions(options, overrideOptions)) as any } @@ -82,7 +82,7 @@ export const decodeUnknownOption = ( export const decodeUnknownEither = ( schema: Schema.Schema, options?: AST.ParseOptions -): (u: unknown, overrideOptions?: AST.ParseOptions) => Either.Either => +): (u: unknown, overrideOptions?: AST.ParseOptions) => Either.Either => getEither(schema.ast, true, options) /** @@ -132,7 +132,7 @@ export const encodeUnknownOption = ( export const encodeUnknownEither = ( schema: Schema.Schema, options?: AST.ParseOptions -): (u: unknown, overrideOptions?: AST.ParseOptions) => Either.Either => +): (u: unknown, overrideOptions?: AST.ParseOptions) => Either.Either => getEither(schema.ast, false, options) /** @@ -182,7 +182,7 @@ export const decodeOption: ( export const decodeEither: ( schema: Schema.Schema, options?: AST.ParseOptions -) => (i: I, overrideOptions?: AST.ParseOptions) => Either.Either = decodeUnknownEither +) => (i: I, overrideOptions?: AST.ParseOptions) => Either.Either = decodeUnknownEither /** * @category decoding @@ -227,7 +227,7 @@ export const validateOption = ( export const validateEither = ( schema: Schema.Schema, options?: AST.ParseOptions -): (u: unknown, overrideOptions?: AST.ParseOptions) => Either.Either => +): (u: unknown, overrideOptions?: AST.ParseOptions) => Either.Either => getEither(AST.to(schema.ast), true, options) /** @@ -269,7 +269,7 @@ export const is = (schema: Schema.Schema, options?: AST.ParseO export const asserts = (schema: Schema.Schema, options?: AST.ParseOptions) => { const parser = goMemo(AST.to(schema.ast), true) return (u: unknown, overrideOptions?: AST.ParseOptions): asserts u is A => { - const result: Either.Either = parser(u, { + const result: Either.Either = parser(u, { ...mergeParseOptions(options, overrideOptions), isExact: true }) as any @@ -304,7 +304,7 @@ export const encodeOption: ( export const encodeEither: ( schema: Schema.Schema, options?: AST.ParseOptions -) => (a: A, overrideOptions?: AST.ParseOptions) => Either.Either = encodeUnknownEither +) => (a: A, overrideOptions?: AST.ParseOptions) => Either.Either = encodeUnknownEither /** * @category encoding diff --git a/packages/schema/src/Schema.ts b/packages/schema/src/Schema.ts index 04bbb5be09..e270b1c39f 100644 --- a/packages/schema/src/Schema.ts +++ b/packages/schema/src/Schema.ts @@ -214,7 +214,7 @@ export const encodeUnknownEither = ( options?: ParseOptions ) => { const encodeUnknownEither = Parser.encodeUnknownEither(schema, options) - return (u: unknown, overrideOptions?: ParseOptions): Either.Either => + return (u: unknown, overrideOptions?: ParseOptions): Either.Either => Either.mapLeft(encodeUnknownEither(u, overrideOptions), ParseResult.parseError) } @@ -246,7 +246,7 @@ export const encode: ( export const encodeEither: ( schema: Schema, options?: ParseOptions -) => (a: A, overrideOptions?: ParseOptions) => Either.Either = encodeUnknownEither +) => (a: A, overrideOptions?: ParseOptions) => Either.Either = encodeUnknownEither /** * @category encoding @@ -279,7 +279,7 @@ export const decodeUnknownEither = ( options?: ParseOptions ) => { const decodeUnknownEither = ParseResult.decodeUnknownEither(schema, options) - return (u: unknown, overrideOptions?: ParseOptions): Either.Either => + return (u: unknown, overrideOptions?: ParseOptions): Either.Either => Either.mapLeft(decodeUnknownEither(u, overrideOptions), ParseResult.parseError) } @@ -311,7 +311,7 @@ export const decode: ( export const decodeEither: ( schema: Schema, options?: ParseOptions -) => (i: I, overrideOptions?: ParseOptions) => Either.Either = decodeUnknownEither +) => (i: I, overrideOptions?: ParseOptions) => Either.Either = decodeUnknownEither /** * @category decoding @@ -344,7 +344,7 @@ export const validateEither = ( options?: ParseOptions ) => { const validateEither = Parser.validateEither(schema, options) - return (u: unknown, overrideOptions?: ParseOptions): Either.Either => + return (u: unknown, overrideOptions?: ParseOptions): Either.Either => Either.mapLeft(validateEither(u, overrideOptions), ParseResult.parseError) } @@ -3547,7 +3547,7 @@ export { const makeEncodingTransformation = ( id: string, - decode: (s: string) => Either.Either, + decode: (s: string) => Either.Either, encode: (u: Uint8Array) => string ): Schema => transformOrFail( @@ -3893,8 +3893,13 @@ export const option = ( optionFromSelf(to(value)), optionDecode, Option.match({ - onNone: () => ({ _tag: "None" }) as const, - onSome: (value) => ({ _tag: "Some", value }) as const + onNone: () => (({ + _tag: "None" + }) as const), + onSome: (value) => (({ + _tag: "Some", + value + }) as const) }) ) @@ -3975,13 +3980,13 @@ const eitherFrom = ( description(`EitherFrom<${format(left)}, ${format(right)}>`) ) -const eitherDecode = (input: EitherFrom): Either.Either => +const eitherDecode = (input: EitherFrom): Either.Either => input._tag === "Left" ? Either.left(input.left) : Either.right(input.right) const eitherArbitrary = ( left: Arbitrary, right: Arbitrary -): Arbitrary> => { +): Arbitrary> => { const arb = arbitrary.make(eitherFrom(schemaFromArbitrary(left), schemaFromArbitrary(right))) return (fc) => arb(fc).map(eitherDecode) } @@ -3989,7 +3994,7 @@ const eitherArbitrary = ( const eitherPretty = ( left: Pretty.Pretty, right: Pretty.Pretty -): Pretty.Pretty> => +): Pretty.Pretty> => Either.match({ onLeft: (e) => `left(${left(e)})`, onRight: (a) => `right(${right(a)})` @@ -3998,7 +4003,7 @@ const eitherPretty = ( const eitherParse = ( decodeUnknownLeft: ParseResult.DecodeUnknown, parseright: ParseResult.DecodeUnknown -): ParseResult.DeclarationDecodeUnknown, RE | RA> => +): ParseResult.DeclarationDecodeUnknown, RE | RA> => (u, options, ast) => Either.isEither(u) ? Either.match(u, { @@ -4014,7 +4019,7 @@ const eitherParse = ( export const eitherFromSelf = ({ left, right }: { readonly left: Schema readonly right: Schema -}): Schema, Either.Either, RE | RA> => { +}): Schema, Either.Either, RE | RA> => { return declare( [left, right], (left, right) => eitherParse(ParseResult.decodeUnknown(left), ParseResult.decodeUnknown(right)), @@ -4028,8 +4033,14 @@ export const eitherFromSelf = ({ left, right }: { ) } -const makeLeftFrom = (left: E) => ({ _tag: "Left", left }) as const -const makeRightFrom = (right: A) => ({ _tag: "Right", right }) as const +const makeLeftFrom = (left: E) => (({ + _tag: "Left", + left +}) as const) +const makeRightFrom = (right: A) => (({ + _tag: "Right", + right +}) as const) /** * @category Either transformations @@ -4038,7 +4049,7 @@ const makeRightFrom = (right: A) => ({ _tag: "Right", right }) as const export const either = ({ left, right }: { readonly left: Schema readonly right: Schema -}): Schema, EitherFrom, R1 | R2> => +}): Schema, EitherFrom, R1 | R2> => transform( eitherFrom(left, right), eitherFromSelf({ left: to(left), right: to(right) }), @@ -4059,7 +4070,7 @@ export const either = ({ left, right }: { export const eitherFromUnion = ({ left, right }: { readonly left: Schema readonly right: Schema -}): Schema, EI | AI, R1 | R2> => { +}): Schema, EI | AI, R1 | R2> => { const toleft = to(left) const toright = to(right) const fromLeft = transform(left, leftFrom(toleft), makeLeftFrom, (l) => l.left) diff --git a/packages/schema/src/internal/parser.ts b/packages/schema/src/internal/parser.ts index 62eb37d248..a2b65ab251 100644 --- a/packages/schema/src/internal/parser.ts +++ b/packages/schema/src/internal/parser.ts @@ -65,7 +65,7 @@ export const mapError: { /** @internal */ export const eitherOrUndefined = ( self: Effect.Effect -): Either.Either | undefined => { +): Either.Either | undefined => { const s: any = self if (s["_tag"] === "Left" || s["_tag"] === "Right") { return s diff --git a/packages/schema/test/util.ts b/packages/schema/test/util.ts index 8d073f2bf9..63885d4a40 100644 --- a/packages/schema/test/util.ts +++ b/packages/schema/test/util.ts @@ -227,7 +227,7 @@ export const NumberFromChar = S.Char.pipe(S.compose(S.NumberFromString)).pipe( ) export const expectFailure = async ( - effect: Either.Either | Effect.Effect, + effect: Either.Either | Effect.Effect, message: string ) => { if (Either.isEither(effect)) { @@ -238,7 +238,7 @@ export const expectFailure = async ( } export const expectSuccess = async ( - effect: Either.Either | Effect.Effect, + effect: Either.Either | Effect.Effect, a: A ) => { if (Either.isEither(effect)) { @@ -263,11 +263,11 @@ export const expectEffectSuccess = async (effect: Effect.Effect, a: ) } -export const expectEitherLeft = (e: Either.Either, message: string) => { +export const expectEitherLeft = (e: Either.Either, message: string) => { expect(Either.mapLeft(e, formatError)).toStrictEqual(Either.left(message)) } -export const expectEitherRight = (e: Either.Either, a: A) => { +export const expectEitherRight = (e: Either.Either, a: A) => { expect(e).toStrictEqual(Either.right(a)) } diff --git a/packages/typeclass/src/Filterable.ts b/packages/typeclass/src/Filterable.ts index aaa28752e0..4aeb8784a8 100644 --- a/packages/typeclass/src/Filterable.ts +++ b/packages/typeclass/src/Filterable.ts @@ -16,11 +16,11 @@ import type { Covariant } from "./Covariant.js" export interface Filterable extends TypeClass { readonly partitionMap: { ( - f: (a: A) => Either.Either + f: (a: A) => Either.Either ): (self: Kind) => [Kind, Kind] ( self: Kind, - f: (a: A) => Either.Either + f: (a: A) => Either.Either ): [Kind, Kind] } @@ -43,7 +43,7 @@ export const partitionMapComposition = ( self: Kind>, - f: (a: A) => Either.Either + f: (a: A) => Either.Either ): [Kind>, Kind>] => { const filterMap = filterMapComposition(F, G) return [ @@ -79,7 +79,7 @@ export const compact = ( export const separate = ( F: Filterable ): ( - self: Kind> + self: Kind> ) => [Kind, Kind] => F.partitionMap(identity) /** diff --git a/packages/typeclass/src/TraversableFilterable.ts b/packages/typeclass/src/TraversableFilterable.ts index 6e1d032ae2..b28729e24c 100644 --- a/packages/typeclass/src/TraversableFilterable.ts +++ b/packages/typeclass/src/TraversableFilterable.ts @@ -24,13 +24,13 @@ export interface TraversableFilterable extends TypeClass ) => { ( - f: (a: A) => Kind> + f: (a: A) => Kind> ): ( self: Kind ) => Kind, Kind]> ( self: Kind, - f: (a: A) => Kind> + f: (a: A) => Kind> ): Kind, Kind]> } @@ -58,7 +58,7 @@ export const traversePartitionMap = ( F: Applicative ) => ( self: Kind, - f: (a: A) => Kind> + f: (a: A) => Kind> ) => Kind, Kind]> => (F) => (self, f) => F.map(T.traverse(F)(self, f), filterable.separate(T)) diff --git a/packages/typeclass/src/data/Either.ts b/packages/typeclass/src/data/Either.ts index b95a49c531..83ed3460c4 100644 --- a/packages/typeclass/src/data/Either.ts +++ b/packages/typeclass/src/data/Either.ts @@ -32,49 +32,49 @@ const bimap: { ( onLeft: (e: E1) => E2, onRight: (a: A) => B - ): (self: Either.Either) => Either.Either + ): (self: Either.Either) => Either.Either ( - self: Either.Either, + self: Either.Either, onLeft: (e: E1) => E2, onRight: (a: A) => B - ): Either.Either + ): Either.Either } = dual( 3, ( - self: Either.Either, + self: Either.Either, onLeft: (e: E1) => E2, onRight: (a: A) => B - ): Either.Either => Either.mapBoth(self, { onLeft, onRight }) + ): Either.Either => Either.mapBoth(self, { onLeft, onRight }) ) const flatMap: { ( - f: (a: A) => Either.Either - ): (self: Either.Either) => Either.Either + f: (a: A) => Either.Either + ): (self: Either.Either) => Either.Either ( - self: Either.Either, - f: (a: A) => Either.Either - ): Either.Either + self: Either.Either, + f: (a: A) => Either.Either + ): Either.Either } = dual( 2, ( - self: Either.Either, - f: (a: A) => Either.Either - ): Either.Either => Either.isLeft(self) ? Either.left(self.left) : f(self.right) + self: Either.Either, + f: (a: A) => Either.Either + ): Either.Either => Either.isLeft(self) ? Either.left(self.left) : f(self.right) ) const product = ( - self: Either.Either, - that: Either.Either -): Either.Either => + self: Either.Either, + that: Either.Either +): Either.Either<[A, B], E1 | E2> => Either.isRight(self) ? (Either.isRight(that) ? Either.right([self.right, that.right]) : Either.left(that.left)) : Either.left(self.left) const productMany = ( - self: Either.Either, - collection: Iterable> -): Either.Either]> => { + self: Either.Either, + collection: Iterable> +): Either.Either<[A, ...Array], E> => { if (Either.isLeft(self)) { return Either.left(self.left) } @@ -89,8 +89,8 @@ const productMany = ( } const productAll = ( - collection: Iterable> -): Either.Either> => { + collection: Iterable> +): Either.Either, E> => { const out: Array = [] for (const e of collection) { if (Either.isLeft(e)) { @@ -102,14 +102,14 @@ const productAll = ( } const coproduct = ( - self: Either.Either, - that: Either.Either -): Either.Either => Either.isRight(self) ? self : that + self: Either.Either, + that: Either.Either +): Either.Either => Either.isRight(self) ? self : that const coproductMany = ( - self: Either.Either, - collection: Iterable> -): Either.Either => { + self: Either.Either, + collection: Iterable> +): Either.Either => { let out = self if (Either.isRight(out)) { return out @@ -127,19 +127,19 @@ const traverse = ( ): { ( f: (a: A) => Kind - ): (self: Either.Either) => Kind> + ): (self: Either.Either) => Kind> ( - self: Either.Either, + self: Either.Either, f: (a: A) => Kind - ): Kind> + ): Kind> } => dual(2, ( - self: Either.Either, + self: Either.Either, f: (a: A) => Kind - ): Kind> => + ): Kind> => Either.isLeft(self) ? - F.of>(Either.left(self.left)) : - F.map>(f(self.right), Either.right)) + F.of>(Either.left(self.left)) : + F.map>(f(self.right), Either.right)) /** * @category instances @@ -287,7 +287,7 @@ export const SemiAlternative: semiAlternative.SemiAlternative = { reduce: dual( 3, - (self: Either.Either, b: B, f: (b: B, a: A) => B): B => Either.isLeft(self) ? b : f(b, self.right) + (self: Either.Either, b: B, f: (b: B, a: A) => B): B => Either.isLeft(self) ? b : f(b, self.right) ) } diff --git a/packages/typeclass/src/data/ReadonlyArray.ts b/packages/typeclass/src/data/ReadonlyArray.ts index 8e3c175cbb..9614993192 100644 --- a/packages/typeclass/src/data/ReadonlyArray.ts +++ b/packages/typeclass/src/data/ReadonlyArray.ts @@ -70,16 +70,16 @@ const traversePartitionMap = ( F: applicative.Applicative ): { ( - f: (a: A) => Kind> + f: (a: A) => Kind> ): (self: ReadonlyArray) => Kind, Array]> ( self: ReadonlyArray, - f: (a: A) => Kind> + f: (a: A) => Kind> ): Kind, Array]> } => dual(2, ( self: ReadonlyArray, - f: (a: A) => Kind> + f: (a: A) => Kind> ): Kind, Array]> => { return F.map(traverse(F)(self, f), ReadonlyArray.separate) }) diff --git a/packages/typeclass/src/data/ReadonlyRecord.ts b/packages/typeclass/src/data/ReadonlyRecord.ts index b38ea5c7ab..4be5c16ca1 100644 --- a/packages/typeclass/src/data/ReadonlyRecord.ts +++ b/packages/typeclass/src/data/ReadonlyRecord.ts @@ -45,18 +45,18 @@ const traversePartitionMap = ( F: applicative.Applicative ): { ( - f: (a: A) => Kind> + f: (a: A) => Kind> ): ( self: ReadonlyRecord.ReadonlyRecord ) => Kind, Record]> ( self: ReadonlyRecord.ReadonlyRecord, - f: (a: A) => Kind> + f: (a: A) => Kind> ): Kind, Record]> } => dual(2, ( self: ReadonlyRecord.ReadonlyRecord, - f: (a: A) => Kind> + f: (a: A) => Kind> ): Kind, Record]> => { return F.map(traverse(F)(self, f), ReadonlyRecord.separate) }) diff --git a/packages/typeclass/test/TraversableFilterable.test.ts b/packages/typeclass/test/TraversableFilterable.test.ts index d7d41ad6a8..f70bc28d19 100644 --- a/packages/typeclass/test/TraversableFilterable.test.ts +++ b/packages/typeclass/test/TraversableFilterable.test.ts @@ -10,7 +10,7 @@ describe.concurrent("TraversableFilterable", () => { it("traversePartitionMap", () => { const traversePartitionMap: ( self: ReadonlyArray, - f: (a: A) => O.Option> + f: (a: A) => O.Option> ) => O.Option<[ReadonlyArray, ReadonlyArray]> = _.traversePartitionMap({ ...ReadonlyArrayInstances.Traversable, ...ReadonlyArrayInstances.Covariant, diff --git a/packages/typeclass/test/data/Either.test.ts b/packages/typeclass/test/data/Either.test.ts index 79f4d19ecd..c345f6525c 100644 --- a/packages/typeclass/test/data/Either.test.ts +++ b/packages/typeclass/test/data/Either.test.ts @@ -43,9 +43,9 @@ describe.concurrent("Either", () => { it("SemiProduct.productMany", () => { const productMany: ( - self: Either.Either, - collection: Iterable> - ) => Either.Either]> = EitherInstances.SemiProduct.productMany + self: Either.Either, + collection: Iterable> + ) => Either.Either<[A, ...Array], E> = EitherInstances.SemiProduct.productMany Util.deepStrictEqual(productMany(Either.right(1), []), Either.right([1])) Util.deepStrictEqual(