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?




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