Created
April 25, 2017 16:28
-
-
Save mattpodwysocki/306ef1fda6525fe8474fd4e89fe4121d to your computer and use it in GitHub Desktop.
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
'use strict'; | |
import { isAsyncIterable } from '../internal/isasynciterable'; | |
export async function *flattenAsync<T>(iterable: AsyncIterable<T>, depth: number = Infinity): AsyncIterable<T> { | |
if (depth === 0) { return iterable; } | |
for await (let item of iterable) { | |
if (isAsyncIterable(item)) { | |
yield *flattenAsync(item, depth - 1); | |
} else { | |
yield item; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment