Bottom Exception when first Either in LINQ from expression is in Left state
See original GitHub issueFirst up, this is an awesome Library and it is making me love C# again.
I have noticed an issue when using nested Monads in LINQ from
select
statements.
In my case I’m nesting an Either
inside a Task
, however if the unwrapping is done in a single LINQ step a Bottom Exception occurs.
So given:
var failableTask = fun((Either<string, int> value) =>
Task.Run(() =>
{
Thread.Sleep(3000);
return value;
}));
The following will work as expected:
var result = await from a in failableTask(34)
from b in failableTask("This will work as expected")
select a + b;
However, if the first Either
is in it’s Left
state a Bottom Exception occurs:
var result = await from a in failableTask("This will cause a Bottom Exception")
from b in failableTask(3)
select a + b;
If I unwrap the nested Monads separately it works as expected:
var result = await from a in failableTask("This will work as expected")
from b in failableTask(3)
select from a1 in a
from b1 in b
select a1 + b1;
I haven’t yet explored what functions are called under the hood to debug this further just yet.
Issue Analytics
- State:
- Created 6 years ago
- Comments:14 (6 by maintainers)
Top Results From Across the Web
The LINQ expression could not be translated. Either rewrite ...
The issue is that you are trying to do a string.Contains within an Any expression which EF will choke on trying to compose...
Read more >The 10 Most Common Mistakes in C# Programming
Common C# Programming Mistake #5: Failing to consider the underlying objects in a LINQ statement.
Read more >Invalidoperationexception: the LINQ expression
Hi, I have the message System.InvalidOperationException: The LINQ expression 'DbSet<Developer>() .Where(d => d.
Read more >Functional Programming in C# - Expressions, Option, Either
Part 1 summarised how I started in FP in C# by learning LINQ and trying Project Euler ... Expressions first helps keep the...
Read more >Dixin's Blog - EntityFramework.Functions: Code First ...
The difference is, it works in LINQ to Entities queries, but cannot be called directly. As a result, its body will never be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This issue is fixed in
v2.2.17-beta
Ok, leave it with me I’ll put in some more tests.