Skip to content

Commit a84cb5a

Browse files
committed
fix: Either.Right - order left and right
1 parent 5c0783b commit a84cb5a

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/either/Either.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface Either<L, R> {
99
match<T>(cases: { left: (left: L) => T; right: (right: R) => T }): T;
1010
}
1111

12-
export class Right<R, L = unknown> implements Either<L, R> {
12+
export class Right<L, R> implements Either<L, R> {
1313
constructor(private readonly value: R) {}
1414

1515
isLeft(): boolean {
@@ -78,7 +78,7 @@ export const tryCatch = <L = unknown, R = unknown>(
7878
onError?: (e: unknown) => L
7979
): Either<L, R> => {
8080
try {
81-
return new Right<R, L>(fn());
81+
return new Right<L, R>(fn());
8282
} catch (e) {
8383
return new Left<L, R>(onError ? onError(e) : (e as L));
8484
}
@@ -90,7 +90,7 @@ export const fromPromise = async <L, R>(
9090
): Promise<Either<L, R>> => {
9191
try {
9292
const data = await promise;
93-
return new Right<R, L>(data);
93+
return new Right<L, R>(data);
9494
} catch (e) {
9595
return new Left<L, R>(onError ? onError(e) : (e as L));
9696
}
@@ -102,7 +102,7 @@ export const fromAsync = async <L, R>(
102102
): Promise<Either<L, R>> => {
103103
try {
104104
const data = await fn();
105-
return new Right<R, L>(data);
105+
return new Right<L, R>(data);
106106
} catch (e) {
107107
return new Left<L, R>(onError ? onError(e) : (e as L));
108108
}

tests/either.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe("Either", () => {
88
});
99

1010
it("should transform Left value", () => {
11-
const result = new Left<string, number>("fail")
11+
const result = new Left("fail")
1212
.mapLeft((msg) => `Error: ${msg}`)
1313
.match({
1414
left: (e) => e,

0 commit comments

Comments
 (0)