function* joinIterables(...iters) {
  for (const iter of iters) {
    yield* iter;
  }
}
function* filterIter(iter, p) {
  let index = 0;
  for (const t of iter) {
    if (p(t, index++)) {
      yield t;
    }
  }
}
function* mapIter(iter, f) {
  let index = 0;
  for (const t of iter) {
    yield f(t, index++);
  }
}
function* once(stream) {
  const it = stream[Symbol.iterator]();
  const { value } = it.next();
  if (value !== void 0) {
    yield value;
  }
  it.return?.();
}
const iteratorCtor = globalThis.Iterator;
const nativeIteratorFrom = iteratorCtor?.from;
const iteratorFrom = nativeIteratorFrom ?? ((e) => new IterWrapper(e));
class IterWrapper {
  #iterator;
  constructor(iterable) {
    this.#iterator = iterable[Symbol.iterator]();
  }
  next() {
    return this.#iterator.next();
  }
  [Symbol.iterator]() {
    return this;
  }
  map(f) {
    return new IterWrapper(mapIter(this, f));
  }
  filter(p) {
    return new IterWrapper(filterIter(this, p));
  }
}
function wrapIterable(iter) {
  return iteratorFrom(iter);
}
export {
  joinIterables,
  once,
  wrapIterable
};
//# sourceMappingURL=iterables.js.map
