DrKillshot / unwrap

A functional programming library for typescript developers
https://drkillshot.github.io/unwrap/
1 stars 1 forks source link

Add bimap to Either #14

Closed DrKillshot closed 3 days ago

DrKillshot commented 6 days ago

Currently we can do stuff like this

Either.fromNullable(aValue, "An error has occurred")
    .map(value => /* Do stuff to the object */),
   .mapError(value => /* Do stuff to the string */)

or

Either.fromNullable(aValue, "An error has occurred")
   .mapError(value => /* Do stuff to the string */)

But in cases where both .map and mapError are present we should be able to do

Either.fromNullable(aValue, "An error has occurred")
    .map(
        obj => /* Do stuff to the object */, // <-- Ok branch
        str => /* Do stuff to the string */,  // <-- Error branch
    )
DrKillshot commented 6 days ago

Same thing could be done for flatmap as well