-
-
Save lkaczanowski/778dd313421ef6ec968a26bf6682e9f8 to your computer and use it in GitHub Desktop.
IAsyncEnumerable UnFold
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static async IAsyncEnumerable<T> UnFold<T, TAcc>(Func<TAcc, Task<(bool Next, IAsyncEnumerable<T> Values, TAcc Acc)>> f, TAcc seed) | |
{ | |
var acc = seed; | |
var result = default((bool Next, IAsyncEnumerable<T> Values, TAcc Acc)); | |
do | |
{ | |
result = await f(acc); | |
await foreach (var value in result.Values) | |
yield return value; | |
acc = result.Acc; | |
} while (result.Next); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment