1.0.3 • Published 2 years ago

eitherify v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Eitherify

A simple utility for eitherifing functions.

Example

class SomeFunctionError extends Error {
  name: "SomeFunctionError";
}

const someFn = (
    val: Value
): { prop1: string, prop2: number } | null => {
    if (!val) return null;
    const { prop1: string, prop2: number } = parse(val);
    return { prop1, prop2 };
};

const someFnEither = eitherify(
    someFn,
    new SomeFunctionError("Something went wrong"),
    new SomeFunctionError("result is null")
);

const props = someFnEither(1).map((props) => props);

For the more information see: https://github.com/JSMonk/sweet-monads/tree/master/either

License

MIT (c) Semen Shishlov see LICENSE file.