Skip to content

Commit

Permalink
Merge fix bug fix for "Unfold"
Browse files Browse the repository at this point in the history
  • Loading branch information
atifaziz authored Apr 1, 2023
2 parents d784050 + 034ba56 commit ae9eea5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions MoreLinq.Test/UnfoldTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,18 @@ public void UnfoldEmptySequence()
e => e.Result);
Assert.That(result, Is.Empty);
}

[Test(Description = "https://github.com/morelinq/MoreLINQ/issues/990")]
public void UnfoldReiterationsReturnsSameResult()
{
var xs = MoreEnumerable.Unfold(1, n => (Result: n, Next: n + 1),
_ => true,
n => n.Next,
n => n.Result)
.Take(5);

xs.AssertSequenceEqual(1, 2, 3, 4, 5);
xs.AssertSequenceEqual(1, 2, 3, 4, 5);
}
}
}
4 changes: 2 additions & 2 deletions MoreLinq/Unfold.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public static IEnumerable<TResult> Unfold<TState, T, TResult>(
if (stateSelector == null) throw new ArgumentNullException(nameof(stateSelector));
if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector));

return _(); IEnumerable<TResult> _()
return _(state); IEnumerable<TResult> _(TState initialState)
{
while (true)
for (var state = initialState; ;)
{
var step = generator(state);

Expand Down

0 comments on commit ae9eea5

Please sign in to comment.