ConstSyncIterableSchema.parse([1, 2, 3]); // ✓ Valid (array)
SyncIterableSchema.parse('hello'); // ✓ Valid (string)
SyncIterableSchema.parse(new Set()); // ✓ Valid (Set)
SyncIterableSchema.parse(new Map()); // ✓ Valid (Map)
SyncIterableSchema.parse(
(function* () {
yield 1;
})(),
); // ✓ Valid (generator)
SyncIterableSchema.parse(42); // ✗ Throws validation error
SyncIterableSchema.parse({}); // ✗ Throws validation error (plain objects are not iterable)
import { createAssertion, use } from 'bupkis';
import { SyncIterableSchema } from 'bupkis/schema';
const iterableAssertion = createAssertion(
[SyncIterableSchema, 'to be iterable'],
SyncIterableSchema,
);
const { expect } = use([iterableAssertion]);
expect([1, 2, 3], 'to be iterable');
Schema matching any synchronous iterable (has
Symbol.iteratormethod).This schema validates values that implement the synchronous iteration protocol, meaning they have a
Symbol.iteratormethod that returns an iterator. This includes arrays, strings, Sets, Maps, generators, and custom iterable objects.