gigobyte / purify

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

EitherAsync fold/either function missing? #304

Closed eduhenke closed 3 years ago

eduhenke commented 3 years ago

Is the Either#either function possible to implement in EitherAsync? Because right now we don't have any way to fold both sides to a third type, i.e. <T>(onLeft: L => T, onRight: R => T): Promise<T>

I've seen that the Either functionality was merged into EitherAsync in #247, but it seems to be missing this.

pyrho commented 3 years ago

What about bimap ?

eduhenke commented 3 years ago

You suggest that I use (await eitherAsync.bimap<T, T>(f, g)).extract()? I haven't thought of that, but that would maybe be a nice addition to EitherAsync to make it look more like Either

pyrho commented 3 years ago

that would maybe be a nice addition to EitherAsync

It's already in EitherAsync :)

gigobyte commented 3 years ago

You can also do

const result = (await eitherAsync).either(onLeft, onRight)

There are a lot of ways to achieve this result, there's no specific reason why there is no EitherAsync#either, but if enough people find it useful I'll implement it.

eduhenke commented 3 years ago

If you want, I can see other similar functions that could be implemented in EitherAsync, and submit a PR implementing them aswell.

gigobyte commented 3 years ago

You can create issues about functions that you think would be useful, that's good enough. If you spend time implementing something and I don't see it as a good fit for the library and reject your PR you would've just wasted your time.