import { assert } from "../../diagnostics"; import { LinqWrapper } from "../linqWrapper"; import { BuiltInLinqTraits, TryUnwrapUnorderedSymbol } from "../traits"; export function unwrapUnorderedLinqWrapper(wrapper: LinqWrapper): Iterable { let it = wrapper as (BuiltInLinqTraits & Iterable); while (typeof it[TryUnwrapUnorderedSymbol] === "function") { const unwrapped = it[TryUnwrapUnorderedSymbol](); // Cannot unwrap anymore if (!unwrapped) return it; assert(unwrapped !== it, "BuiltInLinqTraits[TryUnwrapUnorderedSymbol] should never return itself. Are you intending to return `undefined`?"); it = unwrapped; } return it; }