Handling Effect Results and Errors in TypeScript
Idiomatic style question. I have the an effect which either returns a value, or one of several errors. I need to transform these into three cases:
- for the value, I need to do an operation on it and return it
- for some of the errors, I need to do a different operation and return it
- for the remainder of the errors, I should propagate the failure unchanged.
I'm not entirely sure what the best way to do this is. If I use
So far I have:
This seems pretty complicated, is there something simpler I'm missing?
- for the value, I need to do an operation on it and return it
- for some of the errors, I need to do a different operation and return it
- for the remainder of the errors, I should propagate the failure unchanged.
I'm not entirely sure what the best way to do this is. If I use
Effect.catchTags, I lose information about whether the value I get back is from an Effect success or a caught error success. If I use Effect.either, I lose the extremely nice api where any errors I don't catch in catchTags are propagated. Any suggestions?So far I have:
This seems pretty complicated, is there something simpler I'm missing?
