easy-monad
    Preparing search index...

    Type Alias Either<Error, Success>

    Represent an uncertain state, where you can have either a value, or an error

    type Either<Error, Success> = {
        doOnError: (fn: (x: Error) => void) => Either<Error, Success>;
        doOnErrorAsync: (
            fn: (x: Error) => Promise<void>,
        ) => EitherAsync<Error, Success>;
        doOnSuccess: (fn: (x: Success) => void) => Either<Error, Success>;
        doOnSuccessAsync: (
            fn: (x: Success) => Promise<void>,
        ) => EitherAsync<Error, Success>;
        mapOnError: <Error2>(fn: (x: Error) => Error2) => Either<Error2, Success>;
        mapOnErrorAsync: <Error2>(
            fn: (x: Error) => Promise<Error2>,
        ) => EitherAsync<Error2, Success>;
        mapOnSuccess: {
            <Success2, Error2>(
                fn: (x: Success) => EitherAsync<Error2, Success2>,
            ): EitherAsync<Error2, Success2>;
            <Success2, Error2>(
                fn: (x: Success) => Either<Error2, Success2>,
            ): Either<Error2, Success2>;
            <Success2>(fn: (x: Success) => Success2): Either<Error, Success2>;
        };
        mapOnSuccessAsync: {
            <Success2, Error2>(
                fn: (x: Success) => Promise<EitherAsync<Error2, Success2>>,
            ): EitherAsync<Error2, Success2>;
            <Success2, Error2>(
                fn: (x: Success) => Promise<Either<Error2, Success2>>,
            ): EitherAsync<Error2, Success2>;
            <Success2>(
                fn: (x: Success) => Promise<Success2>,
            ): EitherAsync<Error, Success2>;
        };
        resolve: { (fn: (x: Error) => Success): Success; (x: Success): Success };
        [key: symbol]: true;
    }

    Type Parameters

    • Error
    • Success

    Indexable

    • [key: symbol]: true
    Index

    Properties

    doOnError: (fn: (x: Error) => void) => Either<Error, Success>

    Do something with the error if any, but does not change it.

    doOnErrorAsync: (fn: (x: Error) => Promise<void>) => EitherAsync<Error, Success>

    Do something with the error if any, but does not change it. Handle asynchrone operation.

    doOnSuccess: (fn: (x: Success) => void) => Either<Error, Success>

    Do something with the success value if any, but does not change it.

    doOnSuccessAsync: (
        fn: (x: Success) => Promise<void>,
    ) => EitherAsync<Error, Success>

    Do something with the success value if any, but does not change it. Handle asynchrone operation.

    mapOnError: <Error2>(fn: (x: Error) => Error2) => Either<Error2, Success>

    Transform the error if any

    mapOnErrorAsync: <Error2>(
        fn: (x: Error) => Promise<Error2>,
    ) => EitherAsync<Error2, Success>

    Transform the error if any, with an asynchrone operation

    mapOnSuccess: {
        <Success2, Error2>(
            fn: (x: Success) => EitherAsync<Error2, Success2>,
        ): EitherAsync<Error2, Success2>;
        <Success2, Error2>(
            fn: (x: Success) => Either<Error2, Success2>,
        ): Either<Error2, Success2>;
        <Success2>(fn: (x: Success) => Success2): Either<Error, Success2>;
    }

    Transform the success value of the either, if any. If the result of the mapping is another either, it will be flatten atomatically

    mapOnSuccessAsync: {
        <Success2, Error2>(
            fn: (x: Success) => Promise<EitherAsync<Error2, Success2>>,
        ): EitherAsync<Error2, Success2>;
        <Success2, Error2>(
            fn: (x: Success) => Promise<Either<Error2, Success2>>,
        ): EitherAsync<Error2, Success2>;
        <Success2>(
            fn: (x: Success) => Promise<Success2>,
        ): EitherAsync<Error, Success2>;
    }

    Transform the success value of the either, if any, with an asynchrone operation If the result of the mapping is another either, it will be flatten atomatically

    resolve: { (fn: (x: Error) => Success): Success; (x: Success): Success }

    Generate a value from an error, or just return a default value