Add Result.tap for side effects without altering the result#255
Add Result.tap for side effects without altering the result#255jfvillablanca wants to merge 1 commit intolune-climate:masterfrom
Conversation
Add a tap method to Result that calls a mapper function on Ok values for side effects but returns the original value. If the mapper returns an Err, that error is propagated. This is similar to andThen but discards the mapper's success value. Inspired by Effect's tap and RxJS's tap operators.
|
I split up the test cases into multiple test cases, I noticed that there are no |
jstasiak
left a comment
There was a problem hiding this comment.
Hey, thank you for this.
At the moment I'm pretty convinced the new method should make no use of the value returned by the callbacks, possibly even only accept callbacks returning void to make it less error-prone.
Otherwise as-is it kind of duplicates andThen and in a non-obvious way (because it discards success values but forwards error values).
Is this an intentional design decision?
I split up the test cases into multiple test cases, I noticed that there are no describe blocks and most tests rely on comments or implicit understanding of the tests. let me know if I need to rewrite my tests for uniformity.
I think this is fine, don't worry about it.
PS. When the design is agreed on we also need documentation in docs/ (exactly matching the JSDoc documentation).
Add a tap method to Result that calls a mapper function on Ok values for side effects but returns the original value. If the mapper returns an Err, that error is propagated. This is similar to andThen but discards the mapper's success value.
Inspired by Effect's tap and RxJS's tap operators.
#254