Skip to content
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

Add .tapFailure to TryOps #609

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add .tapFailure to TryOps #609

wants to merge 1 commit into from

Conversation

najder-k
Copy link
Contributor

  • works basically like tapError on Task
  • used to avoid doing failed.foreach on task, which creates an unnecessary exception on Try.Success

- works basically like `tapError` on Task
- used to avoid doing `failed.foreach` on task, which creates an unnecessary exception on Try.Success
def tapFailure(action: Throwable => Unit): Try[A] = tr match {
case Success(_) => tr
case Failure(throwable) =>
action(throwable)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you want to do when action(throwable) throws an exception? Not sure if current choice would be my default, but I'd like to hear your thoughts first. Please document your choice as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this method was (in my mind) a replacement for .failed.foreach & setup(_.failed.foreach) I carried over the way it works there - which is just assuming that the code passed to tapFailure won't throw, and when it does, just throw it.

Now that I think about it though, it'd probably be more sensible to catch any error in tapFailure (since we're in the Try context, best to limit surprises) and return it to the user. I'm kind of on the fence whether it should be ignored instead, but since it's usually just going to be user error when it throws, it's better to know that it happened instead of failing silently.

LMK if this sounds sensible to you

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thoughts were that any .tap method should never alter the result. The libraries are also on the fence: Task#tapError handles, Flow#wireTap I think too but Iterator#tapEach and Observable#doOnNext do not. I'd probably replicate Task approach and use the same name, but I'm okay with other behaviour if it's documented and tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants