Language-ext: IEnumerable<Either<L,A>>.BindT extension method is eager

Created on 8 Mar 2019  路  4Comments  路  Source: louthy/language-ext

BindT extension method both takes and returns IEnumerable type which suggests it'll be lazily evaluated, instead it's processed right away for all the elements.
If it is an expected behavior shouldn't it return a different type instead?

cmd_2019-03-08_08-36-05
cmd_2019-03-08_08-35-42
cmd_2019-03-08_08-42-19
cmd_2019-03-08_08-42-41

bug

All 4 comments

Here is my attempt to simplify your tests. This tests fails but the expectation is that it should pass.

[Fact]
public void IEnumerableOptionBindT_NotEnumerabled_NotEvaluated()
{
    var evaluted = false;
    var list = Seq1(unit)
        .AsEnumerable()
        .Select(_ =>
        {
            evaluted = true;
            return unit;
        })
        .Select(Some)
        .BindT(Some);
    Assert.False(evaluted);
}

The HKT functions (with the T suffix) are auto-generated, so this might have something causing the eagerness.

@bender2k14, here's an even simplier version :)

[Fact]
public static void IEnumerableOptionBindT_NotEnumerabled_NotEvaluated()
{
    new[] { unit }
            .Select<Unit, Option<Unit>>(x => throw new Exception("Some proper message"))
            .BindT(Some);
}

or this

[Fact]
public static void IEnumerableOptionBindT_NotEnumerabled_NotEvaluated()
{
    ThrowOnEnumeration().BindT(Some);

    IEnumerable<Option<Unit>> ThrowOnEnumeration()
    {
        throw new Exception("Some proper message");
        yield return unit; // Do not remove this line. This is required to generate a lazy IEnumerable sequence.
    }
}

Fixed in the next release

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andrevdm picture andrevdm  路  4Comments

MrYossu picture MrYossu  路  5Comments

TonyHernandezAtMS picture TonyHernandezAtMS  路  5Comments

buinauskas picture buinauskas  路  4Comments

michael-wolfenden picture michael-wolfenden  路  5Comments