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.

Stack Overflow when calling BindT on Enumerable of Either

See original GitHub issue

This small test demonstrates the problem:

[Test]
public void Enumerable_BindT_StackOverflow()
{
    IEnumerable<Either<bool, string>> input = Enumerable.Repeat("1", 50000).Select(Prelude.Right<bool, string>);

    IEnumerable<Either<bool, int>> output = input.BindT(s => TryParseInt(s));
    
    Either<bool, int>[] arr = output.ToArray(); // This will fail here with a Stack Overflow (deferred exec)

    /*** Local Func ***/
    Either<bool, int> TryParseInt(string s)
    {
        if (int.TryParse(s, out int i))
            return i;
        else
            return false;
    }
}

Appears the stack overflows due to chained calls to MEnumerable.MoveNext()

Note: I was able to work around it by only manipulating the Enumerable using LINQ Select calls, then calling Bind on each individual ‘either’ value. The problem seems to be how BindT operates on the enumerable.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
louthycommented, Apr 8, 2019

I have committed a fix for this that will be in the next release.

0reactions
chrisbrook83commented, Apr 8, 2019

Sorry - I forgot to include the environment details…

Yes, v3.1.15 passes the test on .NET Core 2.1 as well. Just appears to be a problem on .NET Framework (4.6.1)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Stack overflow error after using Sequence to get from ...
I have some code sorta like this: var someData = Enumerable . ... Stack Overflow when calling BindT on Enumerable of Either #569....
Read more >
c# - How to bind on multiple Either<,>?
This will call SelectMany on the monadic type which is Bind (see documentation of LanguageExt). You get a right value if every function ......
Read more >
c# - Method returning IEnumerable<T> should ToList() or not
To answer you question, I think that yes you should call ToList before returning the enumeration mainly because your ...
Read more >
Thirteen ways of looking at a turtle
Calling the turtle object. The client code instantiates the turtle and talks to it directly: /// Function to log a message ...
Read more >
Language Ext Versions
repeatM was causing a stack-overflow on usage, this is now fixed. Example usage: public static Effect<Runtime, Unit> effect => Producer.repeatM(Time<Runtime>.
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