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.

Hi,

I am trying to build higher abstraction based on smaller Try function components but resulting “combination” is eager in result instead of being lazy:

namespace LanguageExtTesting
{
    class Program
    {
        static Try<int> Parse(string str) => () => int.Parse(str);

        static Try<int> Sum(string lhs, string rhs)
            => from x in Parse(rhs)
               from y in Parse(lhs)
               select x + y;

        static void Main(string[] args)
        {
            var trySum = Sum("1r", "2"); // 1. throws here

            var i = trySum.Try(); // 2. instead of here
        }
    }
}

problem here is that Program currently throws in the line 1. instead of line 2. . I tried wrapping LING expression within Sum() function with additional “() =>” but then I am getting compilation error of Result<T> not being convertible to <T>.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
TysonMNcommented, Nov 16, 2019

Yes. It is one is the correct ways.

1reaction
louthycommented, Nov 5, 2019

@slimshader Don’t use Try<A>.Try() directly, use the other extension methods of Try<A> to work with the value. So, Try<A>.Match(...), Try<A>.IfFail(...), etc.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Merge two binary trie - algorithm
This way you only spend time merging the nodes that are ambiguous and you can copy/move entire subtrees in one go.
Read more >
Trying to Understand Tries
Well, the truth is that they're rarely used exclusively; usually, they're used in combination with another structure, or in the context of an ......
Read more >
Types of Tries
Tries are classified into three categories: Standard Trie · Compressed Trie ... Each node or branch may have multiple branches.
Read more >
Tries | Brilliant Math & Science Wiki
Tries (also known as radix trees or prefix trees) are tree-based data structures that are typically used to store associative arrays where the...
Read more >
What are tries and their types?
A compressed trie is a compact representation of a standard trie. If we have a node with one child, we try to merge...
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