//#region ../../node_modules/langium/lib/utils/stream.js
var e = class e {
	constructor(e, t) {
		this.startFn = e, this.nextFn = t;
	}
	iterator() {
		let e = {
			state: this.startFn(),
			next: () => this.nextFn(e.state),
			[Symbol.iterator]: () => e
		};
		return e;
	}
	[Symbol.iterator]() {
		return this.iterator();
	}
	isEmpty() {
		return !!this.iterator().next().done;
	}
	count() {
		let e = this.iterator(), t = 0, n = e.next();
		for (; !n.done;) t++, n = e.next();
		return t;
	}
	toArray() {
		let e = [], t = this.iterator(), n;
		do
			n = t.next(), n.value !== void 0 && e.push(n.value);
		while (!n.done);
		return e;
	}
	toSet() {
		return new Set(this);
	}
	toMap(e, t) {
		let n = this.map((n) => [e ? e(n) : n, t ? t(n) : n]);
		return new Map(n);
	}
	toString() {
		return this.join();
	}
	concat(t) {
		return new e(() => ({
			first: this.startFn(),
			firstDone: !1,
			iterator: t[Symbol.iterator]()
		}), (e) => {
			let t;
			if (!e.firstDone) {
				do
					if (t = this.nextFn(e.first), !t.done) return t;
				while (!t.done);
				e.firstDone = !0;
			}
			do
				if (t = e.iterator.next(), !t.done) return t;
			while (!t.done);
			return i;
		});
	}
	join(e = ",") {
		let n = this.iterator(), r = "", i, a = !1;
		do
			i = n.next(), i.done || (a && (r += e), r += t(i.value)), a = !0;
		while (!i.done);
		return r;
	}
	indexOf(e, t = 0) {
		let n = this.iterator(), r = 0, i = n.next();
		for (; !i.done;) {
			if (r >= t && i.value === e) return r;
			i = n.next(), r++;
		}
		return -1;
	}
	every(e) {
		let t = this.iterator(), n = t.next();
		for (; !n.done;) {
			if (!e(n.value)) return !1;
			n = t.next();
		}
		return !0;
	}
	some(e) {
		let t = this.iterator(), n = t.next();
		for (; !n.done;) {
			if (e(n.value)) return !0;
			n = t.next();
		}
		return !1;
	}
	forEach(e) {
		let t = this.iterator(), n = 0, r = t.next();
		for (; !r.done;) e(r.value, n), r = t.next(), n++;
	}
	map(t) {
		return new e(this.startFn, (e) => {
			let { done: n, value: r } = this.nextFn(e);
			return n ? i : {
				done: !1,
				value: t(r)
			};
		});
	}
	filter(t) {
		return new e(this.startFn, (e) => {
			let n;
			do
				if (n = this.nextFn(e), !n.done && t(n.value)) return n;
			while (!n.done);
			return i;
		});
	}
	nonNullable() {
		return this.filter((e) => e != null);
	}
	reduce(e, t) {
		let n = this.iterator(), r = t, i = n.next();
		for (; !i.done;) r = r === void 0 ? i.value : e(r, i.value), i = n.next();
		return r;
	}
	reduceRight(e, t) {
		return this.recursiveReduce(this.iterator(), e, t);
	}
	recursiveReduce(e, t, n) {
		let r = e.next();
		if (r.done) return n;
		let i = this.recursiveReduce(e, t, n);
		return i === void 0 ? r.value : t(i, r.value);
	}
	find(e) {
		let t = this.iterator(), n = t.next();
		for (; !n.done;) {
			if (e(n.value)) return n.value;
			n = t.next();
		}
	}
	findIndex(e) {
		let t = this.iterator(), n = 0, r = t.next();
		for (; !r.done;) {
			if (e(r.value)) return n;
			r = t.next(), n++;
		}
		return -1;
	}
	includes(e) {
		let t = this.iterator(), n = t.next();
		for (; !n.done;) {
			if (n.value === e) return !0;
			n = t.next();
		}
		return !1;
	}
	flatMap(t) {
		return new e(() => ({ this: this.startFn() }), (e) => {
			do {
				if (e.iterator) {
					let t = e.iterator.next();
					if (t.done) e.iterator = void 0;
					else return t;
				}
				let { done: r, value: i } = this.nextFn(e.this);
				if (!r) {
					let r = t(i);
					if (n(r)) e.iterator = r[Symbol.iterator]();
					else return {
						done: !1,
						value: r
					};
				}
			} while (e.iterator);
			return i;
		});
	}
	flat(t) {
		if (t === void 0 && (t = 1), t <= 0) return this;
		let r = t > 1 ? this.flat(t - 1) : this;
		return new e(() => ({ this: r.startFn() }), (e) => {
			do {
				if (e.iterator) {
					let t = e.iterator.next();
					if (t.done) e.iterator = void 0;
					else return t;
				}
				let { done: t, value: i } = r.nextFn(e.this);
				if (!t) if (n(i)) e.iterator = i[Symbol.iterator]();
				else return {
					done: !1,
					value: i
				};
			} while (e.iterator);
			return i;
		});
	}
	head() {
		let e = this.iterator().next();
		if (!e.done) return e.value;
	}
	tail(t = 1) {
		return new e(() => {
			let e = this.startFn();
			for (let n = 0; n < t; n++) if (this.nextFn(e).done) return e;
			return e;
		}, this.nextFn);
	}
	limit(t) {
		return new e(() => ({
			size: 0,
			state: this.startFn()
		}), (e) => (e.size++, e.size > t ? i : this.nextFn(e.state)));
	}
	distinct(t) {
		return new e(() => ({
			set: /* @__PURE__ */ new Set(),
			internalState: this.startFn()
		}), (e) => {
			let n;
			do
				if (n = this.nextFn(e.internalState), !n.done) {
					let r = t ? t(n.value) : n.value;
					if (!e.set.has(r)) return e.set.add(r), n;
				}
			while (!n.done);
			return i;
		});
	}
	exclude(e, t) {
		let n = /* @__PURE__ */ new Set();
		for (let r of e) {
			let e = t ? t(r) : r;
			n.add(e);
		}
		return this.filter((e) => {
			let r = t ? t(e) : e;
			return !n.has(r);
		});
	}
};
function t(e) {
	return typeof e == "string" ? e : e === void 0 ? "undefined" : typeof e.toString == "function" ? e.toString() : Object.prototype.toString.call(e);
}
function n(e) {
	return !!e && typeof e[Symbol.iterator] == "function";
}
var r = new e(() => void 0, () => i), i = Object.freeze({
	done: !0,
	value: void 0
});
function a(...t) {
	if (t.length === 1) {
		let r = t[0];
		if (r instanceof e) return r;
		if (n(r)) return new e(() => r[Symbol.iterator](), (e) => e.next());
		if (typeof r.length == "number") return new e(() => ({ index: 0 }), (e) => e.index < r.length ? {
			done: !1,
			value: r[e.index++]
		} : i);
	}
	return t.length > 1 ? new e(() => ({
		collIndex: 0,
		arrIndex: 0
	}), (e) => {
		do {
			if (e.iterator) {
				let t = e.iterator.next();
				if (!t.done) return t;
				e.iterator = void 0;
			}
			if (e.array) {
				if (e.arrIndex < e.array.length) return {
					done: !1,
					value: e.array[e.arrIndex++]
				};
				e.array = void 0, e.arrIndex = 0;
			}
			if (e.collIndex < t.length) {
				let r = t[e.collIndex++];
				n(r) ? e.iterator = r[Symbol.iterator]() : r && typeof r.length == "number" && (e.array = r);
			}
		} while (e.iterator || e.array || e.collIndex < t.length);
		return i;
	}) : r;
}
var o = class extends e {
	constructor(e, t, n) {
		super(() => ({
			iterators: n?.includeRoot ? [[e][Symbol.iterator]()] : [t(e)[Symbol.iterator]()],
			pruned: !1
		}), (e) => {
			for (e.pruned &&= (e.iterators.pop(), !1); e.iterators.length > 0;) {
				let n = e.iterators[e.iterators.length - 1].next();
				if (n.done) e.iterators.pop();
				else return e.iterators.push(t(n.value)[Symbol.iterator]()), n;
			}
			return i;
		});
	}
	iterator() {
		let e = {
			state: this.startFn(),
			next: () => this.nextFn(e.state),
			prune: () => {
				e.state.pruned = !0;
			},
			[Symbol.iterator]: () => e
		};
		return e;
	}
}, s;
(function(e) {
	function t(e) {
		return e.reduce((e, t) => e + t, 0);
	}
	e.sum = t;
	function n(e) {
		return e.reduce((e, t) => e * t, 0);
	}
	e.product = n;
	function r(e) {
		return e.reduce((e, t) => Math.min(e, t));
	}
	e.min = r;
	function i(e) {
		return e.reduce((e, t) => Math.max(e, t));
	}
	e.max = i;
})(s ||= {});
//#endregion
export { i as DONE_RESULT, r as EMPTY_STREAM, s as Reduction, e as StreamImpl, o as TreeStreamImpl, a as stream };
