Open GregOnNet opened 1 year ago
https://github.com/gvergnaud/ts-pattern might provide an API that could be adopted for typescript-functional-extensions. 🤔
I think, what I am looking for is: Pattern Matching.
I'm in the middle of changing jobs atm, so I'm gonna be a little slow on feedback. However, I'll be in the airport some over the next week and I'll use that time to sit down and think about your ideas 👍.
Hi, no worries. I am happy to read your feedback.
Hey together,
this issue is not a real request, it is a question. I approach various situations where I still need to break out of the Result-Monad. I am wondering if there is a better way to achieve this.
What situation are you talking about?
I try to be as specific as possible. In my project, I need to execute difference processes depending on if an Entity exists or not.
This can be situation can be abstracted to
If an initial operation fails, I want to run operation A otherwise I want to run operation B
.What do you mean by breaking out of the monad.
Below you see a code-example. There I check if a resource has been linked to a document. If now I can stop right there and yielding a
Result.success
, otherwise I need to execute a whole other process. I cannot chain the operations by usingmap
,mapFailure
,bind
since I would compensateResult.failure
of independent operations that have not to do anything with each other. So compensation would be wrong. I am interested in the respectedResult.failure
if something goes from, and I want to log it afterwards.In the end, I convert the
ResultAsync
to a promise. Introduce an if-Statement to do the control-flow.What is bad about the code above.
ResultAsync
is not an Option any more. It is aPromise<Result<T>>
ResultAsync
s need to be unwrapped to a Promise too, since we now must return a Promise.I am so happy if you can provide some thoughts on this.
Thanks in advance Gregor