question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tap seems limited since you cannot halt execution on failure

See original GitHub issue

Tap is very useful in that you can use it to return the passed in result and do multiple operations on a single result object. For example.

return getMyResult()
    .Tap(x => DoWork1(x))
    .Tap(x => DoWork2(x))
    .Tap(x => DoWork3(x));

However, sometimes you would like to return the result and still depend on whether the DoWork() method failed. If you could assume that Funcs passed to DoWork all returned the same result type as the “parent” result, that would be useful.

I find myself writing extensions methods like the following:

public static async Task<Result<T>> Tap<T>(this Task<Result<T>> resultTask, Func<T, Task<Result<T>>> func)
{
	var result = await resultTask.ConfigureAwait(Result.DefaultConfigureAwait);
	if (!result.IsSuccess) return result;
	var tapResult = await func(result.Value).ConfigureAwait(Result.DefaultConfigureAwait);
	return tapResult.IsFailure
		? tapResult
		: result;
}

In this case, the flow would be identical, except that execution would stop when a tap Func returns a failed result.

What is the reasoning behind having the result of a Tap operation be ignored in the railway flow?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
benprimecommented, Mar 29, 2020

Addressed as part of PR #192

1reaction
space-aliencommented, Mar 8, 2020

I do it this way:

return GetCustomer()
    .Bind(customer => UpdateCustomer(customer)
        .Map(_ => customer))
    .Bind(customer => DoWork(customer)
        .Map(() => customer));

UpdateCustomer() returns a Result<T> containing a value that we aren’t interested in. DoWork() returns a Result with no value.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix a dodgy tap that won't turn on properly - YouTube
Hamish the Plumber demonstrates how to fix a dodgy basin tap that won't turn on properly. Watch in real time as he services...
Read more >
Scan Troubleshooting
These limits are not always obvious since they may not cause error messages in your PHP error logs, and may make the scan...
Read more >
Solved: Runner.Halt generates "Execution is already compl...
It's as if the .Halt procedure is trying to do something after the script has ended. The other 4 statements in the 'If"...
Read more >
'Insufficient storage': How to fix that error in Android and iOS
When iOS won't install an OS update for lack of space · Open the Settings app. · Tap General, then tap Usage. ·...
Read more >
COLLECTING YOUR JUDGMENT - California Courts
CHAPTER 10: TAKING ACTION AGAINST AN UNPAID JUDGMENT. Lien on Real Property (Starting the Process on Lien). (Lien on Debtor's business assets).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found