-
-
Notifications
You must be signed in to change notification settings - Fork 0
async iterable object
Nicholas Berlette edited this page Jun 19, 2025
·
1 revision
function isAsyncIterableObject<T>(it: unknown): it is AsyncIterableObject<T>;
Checks if a given value is an AsyncIterable
object.
Similar to its synchronous counterpart, isIterableObject
, this function
requires the value to be a non-primitive (and non-null) object, and also
implement a [Symbol.asyncIterator]
method as per the AsyncIterable
API.
Name | Info |
---|---|
it |
The value to check. |
true
if the value is an iterable object, false
otherwise.
Iterables
import { isAsyncIterableObject } from "jsr:@nick/is/async-iterable-object";
// synchronous iterables will not pass
console.log(isAsyncIterableObject([1, 2])); // false
console.log(isAsyncIterableObject(new Map())); // false
console.log(isAsyncIterableObject(new Set())); // false
// non-object iterables will not pass
console.log(isAsyncIterableObject("foo")); // false
// only asynchronous iterable objects will pass
const iter = {
async *[Symbol.asyncIterator]() {
yield await Promise.resolve(1);
},
};
console.log(isAsyncIterableObject(iter)); // true
import { isAsyncIterableObject } from "jsr:@nick/is/async-iterable-object";
const kv = await Deno.openKv();
console.log(isAsyncIterableObject(kv)); // false
const iter = kv.list({ prefix: [] });
console.log(isAsyncIterableObject(iter)); // true
kv.close();
export type AsyncIterableObject<T> = AsyncIterable<T> & object;
An object that implements the AsyncIterable
interface. This is the type that
the
isAsyncIterableObject
function checks for and (narrows to).
T
Iterables