ts-results icon indicating copy to clipboard operation
ts-results copied to clipboard

Feature request: async version of map, andThen

Open Jack-Works opened this issue 3 years ago • 4 comments

result.andThen(async e => calc(e))

Jack-Works avatar Aug 03 '21 04:08 Jack-Works

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 avatar Oct 19 '21 14:10 shalexbas

@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.

andreitopli avatar Nov 10 '21 03:11 andreitopli

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.

GabrielCTroia avatar Nov 10 '21 03:11 GabrielCTroia

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.

ctsstc avatar Apr 13 '23 21:04 ctsstc