ts-results
ts-results copied to clipboard
Feature request: async version of map, andThen
result.andThen(async e => calc(e))
This feature would be perfect! I know there is ts-async-results Lib but this lib is not used a lot and mainted by just one person. I would like to see this feature in this great lib, because there are a lot cases where you need async functions like encryption, webcalls, ... which would naturally produce a Result.
@shalexbas I agree with you. We have been using ts-async-result in production extensively on https://www.chessroulette.live and it works perfectly, haven't encountered any issues yet. I think there's a thread here opened about merging ts-async-results into this library.
Or someone could help me maintain it 😁! But yeah, we’ve been using it extensively at chessroulette so we will hopefully be able to put more resources into it as we grow.
I was looking around for this, but I'm sad to find this open ticket that such does not exist.
For now I'll continue with this pattern:
async function anAsyncMethod(): Promise<Result<SomeType, SomeError>> {
const result = await someAsyncCall()
if (result.ok) {
return await someOtherAsyncCall()
}
return result
}
async function someAsyncCall(): Promise<Result<SomeType, SomeError>> {}
async function someOtherAsyncCall(): Promise<Result<SomeType, SomeError>> {}
There's also scenarios where you may have to map the types as well.