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.

Conversion of Results

See original GitHub issue

Hi,

I do a lot of conversion of results. My problem is that the following code is not very readable, especially the part Result.Fail<MyValueClass>(result1.Error).

public Result<MyValueClass> DoSomething()
{
   Result result1 = MyMethod();
   if(result1.IsFailure)
      return Result.Fail<MyValueClass>(result1.Error);
   [...]
}

Do you know a simple conversion? If not, I would suggest a new conversion method between results ToResult(). With this conversion method the above code looks like this:

public Result<MyValueClass> DoSomething()
{
   Result result1 = MyMethod();
   if(result1.IsFailure)
      return result1.ToResult<MyValueClass>();
   [...]
}

With ToResult() the already existing implicit operator from Result< T > to Result the conversion between Result and Result< T > is enabled and vice versa.

I only see one open problem with the conversion from an success Result to Result< T >. Result<T> result = Result.Ok().ToResult<T>() Which Value has now variable result? default(T)? Or should this conversion throw an exception?

The conversion from an failed Result to Result< T > makes no problems. Result<T> result = Result.Fail("Failed").ToResult<T>() Value is not set.

What do you think?

BR Michael

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
vkhorikovcommented, Sep 2, 2019

I’m with @altmann on this one. Not all operations can be easily represented with a chain of OnSuccess methods, for example, embedded OnSuccess’s are quite hard to grasp and I personally prefer to fall back to regular if-else instead. MapFailure would be really useful in those cases.

1reaction
altmanncommented, Aug 21, 2019

Yes, in 99% I need this conversion in situations which I have to convert a failed result to another type of result.

I will have a look to Map(…) and send you an PR with MapFailure(…).

Thanks…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Conversion Results
The Conversion Results window provides information about the status of the file conversion. To view the conversion results, click Open Output Folder.
Read more >
Conversions - An overview of your results
Conversions compares two groups of users for each signal: those who experienced the signal (“affected”) and those who did not (“unaffected”). When the...
Read more >
What is a conversion rate and why is it important?
A conversion rate records the percentage of users who have completed a desired action. Conversion rates are calculated by taking the total number...
Read more >
Conversion Result
Provides statistics about the conversion. Allows you to view and compare the number of objects that FortiConverter detected in the source configuration and...
Read more >
Converting marks, points and grades
Convert UMS and raw marks ... For Modular qualifications, the 'final mark' or the UMS mark is different from the score on the...
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