gigobyte / purify

Functional programming library for TypeScript - https://gigobyte.github.io/purify/
ISC License
1.5k stars 57 forks source link

Fix 678 bimap resolving async left #680

Closed perfectmak closed 6 months ago

perfectmak commented 6 months ago

This implements a fix for bimap to await reject promises returned by the left mapping functions.

Currently, the following code:

async function runBimap() {
    EitherAsync(async ({ throwE }) => {
        throwE(new Error("error"))
    })
    .bimap(asyncMapFn, asyncMapFn)
    .caseOf({
        Left: (error) => {
            console.log({ error })
        },
        Right: (value) => {
            console.log({ value })
        },
    })

}

await runBimap()

Will output:

Object {error: Promise (resolved)}

This PR fixes it, so that it outputs:

Object {error: Error: error}

Resolves: #678

gigobyte commented 6 months ago

All good, thanks a lot!