Last active
July 6, 2020 12:27
-
-
Save palladin/05f0eecd55f238c0a6fc40c10f556d62 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