andTee() / andThrough() to handle side-effects a bit easier (from issue #445) #467
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
closes #445
Hi @supermacro!
I opened an issue with a suggestion about 2.5 months ago (Jan 17) but I think you have been very busy and I thought maybe a real code would save your time :)
I got a feedback comment in the original issue thread and I ended up having these two methods.
Both return the original input
okAsync<T>
upon success, but in case of error,andTee()
ignores the error whereasandThrough()
returns the new errorerrAsync<F>
. The former is suitable for such as logging when you don't want to stop the main logic upon trivial side-effect failure and the latter is suitable when you want to stop the main logic upon a critical side-effect failure such as DB insertion error.Origianlly I was going to use the name
andTee
for no.2 above that passes error value in case of an error but considering the original meaning of "tee", even the error should not come back to the main "pipe" so I used the name for no.1 above instead. (But as I wrote in the original issue, there could be better names.)And was also written in the original thread, this can be done with the current APIs but these two new methods will make it possible to write and understand each step of the logics more vividly (IMO) and I personally have cases I want to rewrite code with
andThrough()
for DB persistence as I explained here :)Thanks in advance!