UNPKG

1.29 kBJavaScriptView Raw
1import { AsyncIterableX } from './asynciterablex';
2import { isIterable, isAsyncIterable, isArrayLike, isObservable, isPromise, } from '../util/isiterable';
3import { identityAsync } from '../util/identity';
4import { FromObservableAsyncIterable, FromPromiseIterable, FromAsyncIterable, FromArrayIterable, } from './from';
5/**
6 * Converts the input into an async-iterable sequence.
7 *
8 * @export
9 * @param {*} source The source to convert to an async-iterable sequence.
10 * @returns {AsyncIterableX<*>} An async-iterable containing the input.
11 */
12/** @nocollapse */
13export function as(source) {
14 if (source instanceof AsyncIterableX) {
15 return source;
16 }
17 if (typeof source === 'string') {
18 return new FromArrayIterable([source], identityAsync);
19 }
20 if (isIterable(source) || isAsyncIterable(source)) {
21 return new FromAsyncIterable(source, identityAsync);
22 }
23 if (isPromise(source)) {
24 return new FromPromiseIterable(source, identityAsync);
25 }
26 if (isObservable(source)) {
27 return new FromObservableAsyncIterable(source, identityAsync);
28 }
29 if (isArrayLike(source)) {
30 return new FromArrayIterable(source, identityAsync);
31 }
32 return new FromArrayIterable([source], identityAsync);
33}
34
35//# sourceMappingURL=as.mjs.map