Effect CommunityEC
Effect Community3y ago
28 replies
Jérôme MARTIN

Returning Either<never,A>

A simple question: I have a function f1 that returns an Either. That function takes as a param a function f2 that returns an Either. In a specific case, I use f1 with an f2 that always returns a right (so it cannot fail). f1's return type is therefore Either<never,A>. So, in fact, in this specific case, the return type is an A. Is there something like Either.getRight that would return an A instead of an option of A in case the input Either is of type Either<never,A>? So something like:
export const getRightWhenNoLeft= <A>(self: Either.Either<never, A>) : A => (self as Either.Right<never,A>).right

Or what is in your opinion the most elegant way to achieve this?
Was this page helpful?