minimal-either
v1.0.2
Published
Minimal Either implementation in TypeScript
Maintainers
Readme
minimal-either
Minimal Either implementation in Typescript. To know more, see Vavr Either
Remember -- Right is right
Usage
import { Either } from 'minimal-either'
function myEitherFunction(): Either<Error, Response> {
try {
const response = ...
return Either.makeRight(response);
} catch (error) {
return Either.makeLeft(new Error('My custom error message'));
}
}
function parentOfEitherFunction(): Either<Error, null> {
const responseEither = myEitherFunction();
if (responseEither.isLeft()) {
// Handle errors
const errorObject = responseEither.getLeft();
// Or bubble up
return responseEither;
}
// Get the original value from the right
const response = responseEither.getRight();
return Either.makeRight(null);
}