Skip to content

Commit 4b5838a

Browse files
teves-castrogcanti
authored andcommitted
Implement TaskEither.bimap from EitherT.bimap
1 parent 904f587 commit 4b5838a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/EitherT.ts

+15
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,21 @@ export function mapLeft<F>(
8585
return f => fa => F.map(fa, e => e.mapLeft(f))
8686
}
8787

88+
export function bimap<F extends URIS2>(
89+
F: Functor2<F>
90+
): <M, L, V, A, B>(fa: Type2<F, M, Either<L, A>>, f: (l: L) => V, g: (a: A) => B) => Type2<F, M, Either<V, B>>
91+
export function bimap<F extends URIS>(
92+
F: Functor1<F>
93+
): <L, V, A, B>(fa: Type<F, Either<L, A>>, f: (l: L) => V, g: (a: A) => B) => Type<F, Either<V, B>>
94+
export function bimap<F>(
95+
F: Functor<F>
96+
): <L, V, A, B>(fa: HKT<F, Either<L, A>>, f: (l: L) => V, g: (a: A) => B) => HKT<F, Either<V, B>>
97+
export function bimap<F>(
98+
F: Functor<F>
99+
): <L, V, A, B>(fa: HKT<F, Either<L, A>>, f: (l: L) => V, g: (a: A) => B) => HKT<F, Either<V, B>> {
100+
return (fa, f, g) => F.map(fa, e => e.bimap(f, g))
101+
}
102+
88103
export function getEitherT<M extends URIS2>(M: Monad2<M>): EitherT2<M>
89104
export function getEitherT<M extends URIS>(M: Monad1<M>): EitherT1<M>
90105
export function getEitherT<M>(M: Monad<M>): EitherT<M>

src/TaskEither.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type URI = typeof URI
2020

2121
const eitherTfold = eitherT.fold(task.task)
2222
const eitherTmapLeft = eitherT.mapLeft(task.task)
23+
const eitherTbimap = eitherT.bimap(task.task)
2324

2425
/**
2526
* @data
@@ -60,7 +61,7 @@ export class TaskEither<L, A> {
6061
return new TaskEither(this.value.chain(e => e.fold(l => f(l).value, a => eitherTTask.of(a))))
6162
}
6263
bimap<V, B>(f: (l: L) => V, g: (a: A) => B): TaskEither<V, B> {
63-
return new TaskEither(this.value.map(e => e.bimap(f, g)))
64+
return new TaskEither(eitherTbimap(this.value, f, g))
6465
}
6566
}
6667

0 commit comments

Comments
 (0)