-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
andTee() / andThrough() to handle side-effects a bit easier (from issue #445) #467
Conversation
@supermacro can you take a look on this please? It's quite useful feature to avoid boilerplate |
@supermacro bump :) |
Hi @supermacro , have you had a chance to look at this PR? I'd appreciate your review! Thank you! |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution
Can you add docs about new features to README?
@m-shaka thank you for the comment, I will get back to you after making updates. |
@supermacro Hey Gio, I think |
fd9dd29
to
4b9d2fd
Compare
Hi @m-shaka and @supermacro , I updated the PR based on the suggestions as well as README. Thanks |
Both names are ok with me! Don't think it's fair for me to come in so late and opine strongly here. Great job everyone .. and thanks for your patience :) |
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [neverthrow](https://github.com/supermacro/neverthrow) | dependencies | minor | [`7.0.1` -> `7.2.0`](https://renovatebot.com/diffs/npm/neverthrow/7.0.1/7.2.0) | --- ### Release Notes <details> <summary>supermacro/neverthrow (neverthrow)</summary> ### [`v7.2.0`](https://github.com/supermacro/neverthrow/blob/HEAD/CHANGELOG.md#720) [Compare Source](supermacro/neverthrow@v7.1.0...v7.2.0) ##### Minor Changes - [#​562](supermacro/neverthrow#562) [`547352f`](supermacro/neverthrow@547352f) Thanks [@​sharno](https://github.com/sharno)! - change the return type of `safeTry` to be `ResultAsync<T, E>` instead of `Promise<Result<T, E>>` for better composability ### [`v7.1.0`](https://github.com/supermacro/neverthrow/blob/HEAD/CHANGELOG.md#710) [Compare Source](supermacro/neverthrow@v7.0.1...v7.1.0) ##### Minor Changes - [#​467](supermacro/neverthrow#467) [`4b9d2fd`](supermacro/neverthrow@4b9d2fd) Thanks [@​untidy-hair ](https://github.com/untidy-hair)! - feat: add `andTee` and `andThrough` to handle side-effect ##### Patch Changes - [#​483](supermacro/neverthrow#483) [`96f7f66`](supermacro/neverthrow@96f7f66) Thanks [@​braxtonhall](https://github.com/braxtonhall)! - Fix `combineWithAllErrors` types - [#​563](supermacro/neverthrow#563) [`eadf50c`](supermacro/neverthrow@eadf50c) Thanks [@​mattpocock](https://github.com/mattpocock)! - Made err() infer strings narrowly for easier error tagging. </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC41Ny4zIiwidXBkYXRlZEluVmVyIjoiMzguNzIuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiZGVwZW5kZW5jaWVzIl19--> Reviewed-on: https://git.tristess.app/alexandresoro/ouca/pulls/70 Reviewed-by: Alexandre Soro <[email protected]> Co-authored-by: renovate <[email protected]> Co-committed-by: renovate <[email protected]>
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!