import { InvalidOperationException_$ctor_Z721C83C5, NotSupportedException_$ctor_Z721C83C5 } from "./System.ts"; import { IComparer, clear, Exception, isDisposable, IEqualityComparer, isArrayLike, MutableArray, toIterator, IDisposable, disposeSafe, IEnumerator, getEnumerator } from "./Util.ts"; import { toString } from "./Types.ts"; import { class_type, TypeInfo } from "./Reflection.ts"; import { some, value as value_1, Option } from "./Option.ts"; import { KeyNotFoundException_$ctor_Z721C83C5 } from "./System.Collections.Generic.ts"; import { Operators_Lock, Operators_NullArgCheck } from "./FSharp.Core.ts"; import { randomSampleBy as randomSampleBy_1, randomChoicesBy as randomChoicesBy_1, randomChoice as randomChoice_1, randomChoiceWith as randomChoiceWith_1, randomChoiceBy as randomChoiceBy_1, randomShuffleInPlaceBy, chunkBySize as chunkBySize_1, permute as permute_1, transpose as transpose_1, map as map_1, windowed as windowed_1, splitInto as splitInto_1, pairwise as pairwise_1, scanBack as scanBack_1, reverse as reverse_1, mapFoldBack as mapFoldBack_1, mapFold as mapFold_1, tryItem as tryItem_1, tryHead as tryHead_1, item as item_1, foldBack as foldBack_1, tryFindIndexBack as tryFindIndexBack_1, tryFindBack as tryFindBack_1, singleton as singleton_1 } from "./Array.ts"; import { length as length_1, tryItem as tryItem_2, isEmpty as isEmpty_1, tryHead as tryHead_2, ofSeq as ofSeq_1, ofArray as ofArray_1, toArray as toArray_1, FSharpList } from "./List.ts"; import { float64, int32 } from "./Int32.ts"; import { min as min_1 } from "./Double.ts"; import { SR_indexOutOfBounds } from "./Global.ts"; import { nonSeeded } from "./Random.ts"; export const SR_enumerationAlreadyFinished = "Enumeration already finished."; export const SR_enumerationNotStarted = "Enumeration has not started. Call MoveNext."; export const SR_inputSequenceEmpty = "The input sequence was empty."; export const SR_inputSequenceTooLong = "The input sequence contains more than one element."; export const SR_keyNotFoundAlt = "An index satisfying the predicate was not found in the collection."; export const SR_notEnoughElements = "The input sequence has an insufficient number of elements."; export const SR_resetNotSupported = "Reset is not supported on this enumerator."; export function Enumerator_noReset<$a>(): $a { throw NotSupportedException_$ctor_Z721C83C5(SR_resetNotSupported); } export function Enumerator_notStarted<$a>(): $a { throw InvalidOperationException_$ctor_Z721C83C5(SR_enumerationNotStarted); } export function Enumerator_alreadyFinished<$a>(): $a { throw InvalidOperationException_$ctor_Z721C83C5(SR_enumerationAlreadyFinished); } export class Enumerator_Seq implements Iterable { readonly f: (() => IEnumerator); constructor(f: (() => IEnumerator)) { this.f = f; } toString(): string { const xs: Enumerator_Seq = this; let i = 0; let str = "seq ["; const e: IEnumerator = getEnumerator(xs); try { while ((i < 4) && e["System.Collections.IEnumerator.MoveNext"]()) { if (i > 0) { str = (str + "; "); } str = (str + toString(e["System.Collections.Generic.IEnumerator`1.get_Current"]())); i = ((i + 1) | 0); } if (i === 4) { str = (str + "; ..."); } return str + "]"; } finally { disposeSafe(e as IDisposable); } } GetEnumerator(): IEnumerator { const x: Enumerator_Seq = this; return x.f(); } [Symbol.iterator](): Iterator { return toIterator(getEnumerator(this)); } "System.Collections.IEnumerable.GetEnumerator"(): IEnumerator { const x: Enumerator_Seq = this; return x.f(); } } export function Enumerator_Seq_$reflection(gen0: TypeInfo): TypeInfo { return class_type("SeqModule.Enumerator.Seq", [gen0], Enumerator_Seq); } export function Enumerator_Seq_$ctor_673A07F2(f: (() => IEnumerator)): Enumerator_Seq { return new Enumerator_Seq(f); } export class Enumerator_FromFunctions$1 implements IEnumerator, IDisposable { readonly next: (() => boolean); readonly dispose: (() => void); readonly current: (() => T); constructor(current: (() => T), next: (() => boolean), dispose: (() => void)) { this.current = current; this.next = next; this.dispose = dispose; } "System.Collections.Generic.IEnumerator`1.get_Current"(): T { const _: Enumerator_FromFunctions$1 = this; return _.current(); } "System.Collections.IEnumerator.get_Current"(): any { const _: Enumerator_FromFunctions$1 = this; return _.current(); } "System.Collections.IEnumerator.MoveNext"(): boolean { const _: Enumerator_FromFunctions$1 = this; return _.next(); } "System.Collections.IEnumerator.Reset"(): void { Enumerator_noReset(); } Dispose(): void { const _: Enumerator_FromFunctions$1 = this; _.dispose(); } } export function Enumerator_FromFunctions$1_$reflection(gen0: TypeInfo): TypeInfo { return class_type("SeqModule.Enumerator.FromFunctions`1", [gen0], Enumerator_FromFunctions$1); } export function Enumerator_FromFunctions$1_$ctor_58C54629(current: (() => T), next: (() => boolean), dispose: (() => void)): Enumerator_FromFunctions$1 { return new Enumerator_FromFunctions$1(current, next, dispose); } export function Enumerator_cast(e: IEnumerator): IEnumerator { return Enumerator_FromFunctions$1_$ctor_58C54629((): T => e["System.Collections.Generic.IEnumerator`1.get_Current"](), (): boolean => e["System.Collections.IEnumerator.MoveNext"](), (): void => { disposeSafe(e); }); } export function Enumerator_concat>(sources: Iterable): IEnumerator { let outerOpt: Option> = undefined; let innerOpt: Option> = undefined; let started = false; let finished = false; let curr: Option = undefined; const finish = (): void => { finished = true; if (innerOpt != null) { const inner: IEnumerator = value_1(innerOpt); try { disposeSafe(inner); } finally { innerOpt = undefined; } } if (outerOpt != null) { const outer: IEnumerator = value_1(outerOpt); try { disposeSafe(outer); } finally { outerOpt = undefined; } } }; return Enumerator_FromFunctions$1_$ctor_58C54629((): T => { if (!started) { Enumerator_notStarted(); } else if (finished) { Enumerator_alreadyFinished(); } if (curr != null) { return value_1(curr); } else { return Enumerator_alreadyFinished(); } }, (): boolean => { if (!started) { started = true; } if (finished) { return false; } else { let res: Option = undefined; while (res == null) { let copyOfStruct: U = undefined as any; const outerOpt_1: Option> = outerOpt; const innerOpt_1: Option> = innerOpt; if (outerOpt_1 != null) { if (innerOpt_1 != null) { const inner_1: IEnumerator = value_1(innerOpt_1); if (inner_1["System.Collections.IEnumerator.MoveNext"]()) { curr = some(inner_1["System.Collections.Generic.IEnumerator`1.get_Current"]()); res = true; } else { try { disposeSafe(inner_1); } finally { innerOpt = undefined; } } } else { const outer_1: IEnumerator = value_1(outerOpt_1); if (outer_1["System.Collections.IEnumerator.MoveNext"]()) { const ie: U = outer_1["System.Collections.Generic.IEnumerator`1.get_Current"](); innerOpt = ((copyOfStruct = ie, getEnumerator(copyOfStruct))); } else { finish(); res = false; } } } else { outerOpt = getEnumerator(sources); } } return value_1(res); } }, (): void => { if (!finished) { finish(); } }); } export function Enumerator_enumerateThenFinally(f: (() => void), e: IEnumerator): IEnumerator { return Enumerator_FromFunctions$1_$ctor_58C54629((): T => e["System.Collections.Generic.IEnumerator`1.get_Current"](), (): boolean => e["System.Collections.IEnumerator.MoveNext"](), (): void => { try { disposeSafe(e); } finally { f(); } }); } export function Enumerator_generateWhileSome(openf: (() => T), compute: ((arg0: T) => Option), closef: ((arg0: T) => void)): IEnumerator { let started = false; let curr: Option = undefined; let state: Option = some(openf()); const dispose = (): void => { if (state != null) { const x_1: T = value_1(state); try { closef(x_1); } finally { state = undefined; } } }; const finish = (): void => { try { dispose(); } finally { curr = undefined; } }; return Enumerator_FromFunctions$1_$ctor_58C54629((): U => { if (!started) { Enumerator_notStarted(); } if (curr != null) { return value_1(curr); } else { return Enumerator_alreadyFinished(); } }, (): boolean => { if (!started) { started = true; } if (state != null) { const s: T = value_1(state); let matchValue_1: Option; try { matchValue_1 = compute(s); } catch (matchValue: any) { finish(); throw matchValue; } if (matchValue_1 != null) { curr = matchValue_1; return true; } else { finish(); return false; } } else { return false; } }, dispose); } export function Enumerator_unfold(f: ((arg0: State) => Option<[T, State]>), state: State): IEnumerator { let curr: Option<[T, State]> = undefined; let acc: State = state; return Enumerator_FromFunctions$1_$ctor_58C54629((): T => { if (curr != null) { const x: T = value_1(curr)[0]; const st: State = value_1(curr)[1]; return x; } else { return Enumerator_notStarted(); } }, (): boolean => { curr = f(acc); if (curr != null) { const x_1: T = value_1(curr)[0]; const st_1: State = value_1(curr)[1]; acc = st_1; return true; } else { return false; } }, (): void => { }); } export function indexNotFound<$a>(): $a { throw KeyNotFoundException_$ctor_Z721C83C5(SR_keyNotFoundAlt); } export function mkSeq(f: (() => IEnumerator)): Iterable { return Enumerator_Seq_$ctor_673A07F2(f); } export function ofSeq(xs: Iterable): IEnumerator { return getEnumerator(Operators_NullArgCheck>("source", xs)); } export function delay(generator: (() => Iterable)): Iterable { return mkSeq((): IEnumerator => getEnumerator(generator())); } export function concat, T>(sources: Iterable): Iterable { return mkSeq((): IEnumerator => Enumerator_concat(sources)); } export function unfold(generator: ((arg0: State) => Option<[T, State]>), state: State): Iterable { return mkSeq((): IEnumerator => Enumerator_unfold(generator, state)); } export function empty(): Iterable { return delay((): Iterable => (new Array(0))); } export function singleton(x: T): Iterable { return delay((): Iterable => singleton_1(x)); } export function ofArray(arr: MutableArray): Iterable { return arr; } export function toArray(xs: Iterable): MutableArray { if (xs instanceof FSharpList) { const a = xs as FSharpList; return toArray_1(a); } else { return Array.from(xs); } } export function ofList(xs: FSharpList): Iterable { return xs; } export function toList(xs: Iterable): FSharpList { if (isArrayLike(xs)) { return ofArray_1(xs); } else if (xs instanceof FSharpList) { return xs; } else { return ofSeq_1(xs); } } export function generate<$a, $b>(create: (() => $a), compute: ((arg0: $a) => Option<$b>), dispose: ((arg0: $a) => void)): Iterable<$b> { return mkSeq<$b>((): IEnumerator<$b> => Enumerator_generateWhileSome<$a, $b>(create, compute, dispose)); } export function generateIndexed<$a, $b>(create: (() => $a), compute: ((arg0: int32, arg1: $a) => Option<$b>), dispose: ((arg0: $a) => void)): Iterable<$b> { return mkSeq<$b>((): IEnumerator<$b> => { let i = -1; return Enumerator_generateWhileSome<$a, $b>(create, (x: $a): Option<$b> => { i = ((i + 1) | 0); return compute(i, x); }, dispose); }); } export function append(xs: Iterable, ys: Iterable): Iterable { return concat, T>([xs, ys]); } export function cast(xs: Iterable): Iterable { return mkSeq((): IEnumerator => Enumerator_cast(getEnumerator(Operators_NullArgCheck>("source", xs)))); } export function choose(chooser: ((arg0: T) => Option), xs: Iterable): Iterable { return generate, U>((): IEnumerator => ofSeq(xs), (e: IEnumerator): Option => { let curr: Option = undefined; while ((curr == null) && e["System.Collections.IEnumerator.MoveNext"]()) { curr = chooser(e["System.Collections.Generic.IEnumerator`1.get_Current"]()); } return curr; }, (e_1: IEnumerator): void => { disposeSafe(e_1); }); } export function compareWith(comparer: ((arg0: T, arg1: T) => int32), xs: Iterable, ys: Iterable): int32 { const e1: IEnumerator = ofSeq(xs); try { const e2: IEnumerator = ofSeq(ys); try { let c = 0; let b1: boolean = e1["System.Collections.IEnumerator.MoveNext"](); let b2: boolean = e2["System.Collections.IEnumerator.MoveNext"](); while (((c === 0) && b1) && b2) { c = (comparer(e1["System.Collections.Generic.IEnumerator`1.get_Current"](), e2["System.Collections.Generic.IEnumerator`1.get_Current"]()) | 0); if (c === 0) { b1 = e1["System.Collections.IEnumerator.MoveNext"](); b2 = e2["System.Collections.IEnumerator.MoveNext"](); } } return ((c !== 0) ? c : (b1 ? 1 : (b2 ? -1 : 0))) | 0; } finally { disposeSafe(e2 as IDisposable); } } finally { disposeSafe(e1 as IDisposable); } } export function contains(value: T, xs: Iterable, comparer: IEqualityComparer): boolean { const e: IEnumerator = ofSeq(xs); try { let found = false; while (!found && e["System.Collections.IEnumerator.MoveNext"]()) { found = comparer.Equals(value, e["System.Collections.Generic.IEnumerator`1.get_Current"]()); } return found; } finally { disposeSafe(e as IDisposable); } } export function enumerateFromFunctions<$a, $b>(create: (() => $a), moveNext: ((arg0: $a) => boolean), current: ((arg0: $a) => $b)): Iterable<$b> { return generate<$a, $b>(create, (x: $a): Option<$b> => (moveNext(x) ? some(current(x)) : undefined), (x_1: $a): void => { const matchValue: any = x_1; if (isDisposable(matchValue)) { const id = matchValue as IDisposable; disposeSafe(id); } }); } export function enumerateThenFinally(source: Iterable, compensation: (() => void)): Iterable { const compensation_1: (() => void) = compensation; return mkSeq((): IEnumerator => { try { return Enumerator_enumerateThenFinally(compensation_1, ofSeq(source)); } catch (matchValue: any) { compensation_1(); throw matchValue; } }); } export function enumerateUsing, U>(resource: T, source: ((arg0: T) => $a)): Iterable { const compensation = (): void => { if (resource == null) { } else { let copyOfStruct: T = resource; disposeSafe(copyOfStruct); } }; return mkSeq((): IEnumerator => { try { return Enumerator_enumerateThenFinally(compensation, ofSeq(source(resource))); } catch (matchValue_1: any) { compensation(); throw matchValue_1; } }); } export function enumerateWhile(guard: (() => boolean), xs: Iterable): Iterable { return concat, T>(unfold>((i: int32): Option<[Iterable, int32]> => (guard() ? ([xs, i + 1] as [Iterable, int32]) : undefined), 0)); } export function filter(f: ((arg0: T) => boolean), xs: Iterable): Iterable { return choose((x: T): Option => { if (f(x)) { return some(x); } else { return undefined; } }, xs); } export function exists(predicate: ((arg0: T) => boolean), xs: Iterable): boolean { const e: IEnumerator = ofSeq(xs); try { let found = false; while (!found && e["System.Collections.IEnumerator.MoveNext"]()) { found = predicate(e["System.Collections.Generic.IEnumerator`1.get_Current"]()); } return found; } finally { disposeSafe(e as IDisposable); } } export function exists2(predicate: ((arg0: T1, arg1: T2) => boolean), xs: Iterable, ys: Iterable): boolean { const e1: IEnumerator = ofSeq(xs); try { const e2: IEnumerator = ofSeq(ys); try { let found = false; while ((!found && e1["System.Collections.IEnumerator.MoveNext"]()) && e2["System.Collections.IEnumerator.MoveNext"]()) { found = predicate(e1["System.Collections.Generic.IEnumerator`1.get_Current"](), e2["System.Collections.Generic.IEnumerator`1.get_Current"]()); } return found; } finally { disposeSafe(e2 as IDisposable); } } finally { disposeSafe(e1 as IDisposable); } } export function exactlyOne(xs: Iterable): T { const e: IEnumerator = ofSeq(xs); try { if (e["System.Collections.IEnumerator.MoveNext"]()) { const v: T = e["System.Collections.Generic.IEnumerator`1.get_Current"](); if (e["System.Collections.IEnumerator.MoveNext"]()) { throw new Exception((SR_inputSequenceTooLong + "\\nParameter name: ") + "source"); } else { return v; } } else { throw new Exception((SR_inputSequenceEmpty + "\\nParameter name: ") + "source"); } } finally { disposeSafe(e as IDisposable); } } export function tryExactlyOne(xs: Iterable): Option { const e: IEnumerator = ofSeq(xs); try { if (e["System.Collections.IEnumerator.MoveNext"]()) { const v: T = e["System.Collections.Generic.IEnumerator`1.get_Current"](); return e["System.Collections.IEnumerator.MoveNext"]() ? undefined : some(v); } else { return undefined; } } finally { disposeSafe(e as IDisposable); } } export function tryFind(predicate: ((arg0: T) => boolean), xs: Iterable): Option { const e: IEnumerator = ofSeq(xs); try { let res: Option = undefined; while ((res == null) && e["System.Collections.IEnumerator.MoveNext"]()) { const c: T = e["System.Collections.Generic.IEnumerator`1.get_Current"](); if (predicate(c)) { res = some(c); } } return res; } finally { disposeSafe(e as IDisposable); } } export function find(predicate: ((arg0: T) => boolean), xs: Iterable): T { const matchValue: Option = tryFind(predicate, xs); if (matchValue == null) { return indexNotFound(); } else { return value_1(matchValue); } } export function tryFindBack(predicate: ((arg0: T) => boolean), xs: Iterable): Option { return tryFindBack_1(predicate, toArray(xs)); } export function findBack(predicate: ((arg0: T) => boolean), xs: Iterable): T { const matchValue: Option = tryFindBack(predicate, xs); if (matchValue == null) { return indexNotFound(); } else { return value_1(matchValue); } } export function tryFindIndex(predicate: ((arg0: T) => boolean), xs: Iterable): Option { const e: IEnumerator = ofSeq(xs); try { const loop = (i_mut: int32): Option => { loop: while (true) { const i: int32 = i_mut; if (e["System.Collections.IEnumerator.MoveNext"]()) { if (predicate(e["System.Collections.Generic.IEnumerator`1.get_Current"]())) { return i; } else { i_mut = (i + 1); continue loop; } } else { return undefined; } break; } }; return loop(0); } finally { disposeSafe(e as IDisposable); } } export function findIndex(predicate: ((arg0: T) => boolean), xs: Iterable): int32 { const matchValue: Option = tryFindIndex(predicate, xs); if (matchValue == null) { indexNotFound(); return -1; } else { return value_1(matchValue) | 0; } } export function tryFindIndexBack(predicate: ((arg0: T) => boolean), xs: Iterable): Option { return tryFindIndexBack_1(predicate, toArray(xs)); } export function findIndexBack(predicate: ((arg0: T) => boolean), xs: Iterable): int32 { const matchValue: Option = tryFindIndexBack(predicate, xs); if (matchValue == null) { indexNotFound(); return -1; } else { return value_1(matchValue) | 0; } } export function fold(folder: ((arg0: State, arg1: T) => State), state: State, xs: Iterable): State { const e: IEnumerator = ofSeq(xs); try { let acc: State = state; while (e["System.Collections.IEnumerator.MoveNext"]()) { acc = folder(acc, e["System.Collections.Generic.IEnumerator`1.get_Current"]()); } return acc; } finally { disposeSafe(e as IDisposable); } } export function foldBack(folder: ((arg0: T, arg1: any) => any), xs: Iterable, state: any): any { return foldBack_1(folder, toArray(xs), state); } export function fold2(folder: ((arg0: State, arg1: T1, arg2: T2) => State), state: State, xs: Iterable, ys: Iterable): State { const e1: IEnumerator = ofSeq(xs); try { const e2: IEnumerator = ofSeq(ys); try { let acc: State = state; while (e1["System.Collections.IEnumerator.MoveNext"]() && e2["System.Collections.IEnumerator.MoveNext"]()) { acc = folder(acc, e1["System.Collections.Generic.IEnumerator`1.get_Current"](), e2["System.Collections.Generic.IEnumerator`1.get_Current"]()); } return acc; } finally { disposeSafe(e2 as IDisposable); } } finally { disposeSafe(e1 as IDisposable); } } export function foldBack2(folder: ((arg0: T1, arg1: T2, arg2: State) => State), xs: Iterable, ys: Iterable, state: State): State { const xs_1: MutableArray = toArray(xs); const ys_1: MutableArray = toArray(ys); const len: int32 = min_1(xs_1.length, ys_1.length) | 0; let acc: State = state; for (let i: int32 = len - 1; i >= 0; i--) { acc = folder(item_1(i, xs_1), item_1(i, ys_1), acc); } return acc; } export function forAll<$a>(predicate: ((arg0: $a) => boolean), xs: Iterable<$a>): boolean { return !exists<$a>((x: $a): boolean => !predicate(x), xs); } export function forAll2<$a, $b>(predicate: ((arg0: $a, arg1: $b) => boolean), xs: Iterable<$a>, ys: Iterable<$b>): boolean { return !exists2<$a, $b>((x: $a, y: $b): boolean => !predicate(x, y), xs, ys); } export function tryHead(xs: Iterable): Option { if (isArrayLike(xs)) { return tryHead_1(xs); } else if (xs instanceof FSharpList) { return tryHead_2(xs); } else { const e: IEnumerator = ofSeq(xs); try { return e["System.Collections.IEnumerator.MoveNext"]() ? some(e["System.Collections.Generic.IEnumerator`1.get_Current"]()) : undefined; } finally { disposeSafe(e as IDisposable); } } } export function head(xs: Iterable): T { const matchValue: Option = tryHead(xs); if (matchValue == null) { throw new Exception((SR_inputSequenceEmpty + "\\nParameter name: ") + "source"); } else { return value_1(matchValue); } } export function initialize<$a>(count: int32, f: ((arg0: int32) => $a)): Iterable<$a> { return unfold((i: int32): Option<[$a, int32]> => ((i < count) ? ([f(i), i + 1] as [$a, int32]) : undefined), 0); } export function initializeInfinite<$a>(f: ((arg0: int32) => $a)): Iterable<$a> { return initialize<$a>(2147483647, f); } export function isEmpty(xs: Iterable): boolean { if (isArrayLike(xs)) { const a: MutableArray = xs; return a.length === 0; } else if (xs instanceof FSharpList) { return isEmpty_1(xs); } else { const e: IEnumerator = ofSeq(xs); try { return !e["System.Collections.IEnumerator.MoveNext"](); } finally { disposeSafe(e as IDisposable); } } } export function tryItem(index: int32, xs: Iterable): Option { if (isArrayLike(xs)) { return tryItem_1(index, xs); } else if (xs instanceof FSharpList) { return tryItem_2(index, xs); } else { const e: IEnumerator = ofSeq(xs); try { const loop = (index_1_mut: int32): Option => { loop: while (true) { const index_1: int32 = index_1_mut; if (!e["System.Collections.IEnumerator.MoveNext"]()) { return undefined; } else if (index_1 === 0) { return some(e["System.Collections.Generic.IEnumerator`1.get_Current"]()); } else { index_1_mut = (index_1 - 1); continue loop; } break; } }; return loop(index); } finally { disposeSafe(e as IDisposable); } } } export function item(index: int32, xs: Iterable): T { const matchValue: Option = tryItem(index, xs); if (matchValue == null) { throw new Exception((SR_notEnoughElements + "\\nParameter name: ") + "index"); } else { return value_1(matchValue); } } export function iterate<$a>(action: ((arg0: $a) => void), xs: Iterable<$a>): void { fold<$a, void>((unitVar: void, x: $a): void => { action(x); }, undefined, xs); } export function iterate2<$a, $b>(action: ((arg0: $a, arg1: $b) => void), xs: Iterable<$a>, ys: Iterable<$b>): void { fold2<$a, $b, void>((unitVar: void, x: $a, y: $b): void => { action(x, y); }, undefined, xs, ys); } export function iterateIndexed<$a>(action: ((arg0: int32, arg1: $a) => void), xs: Iterable<$a>): void { fold<$a, int32>((i: int32, x: $a): int32 => { action(i, x); return (i + 1) | 0; }, 0, xs); } export function iterateIndexed2<$a, $b>(action: ((arg0: int32, arg1: $a, arg2: $b) => void), xs: Iterable<$a>, ys: Iterable<$b>): void { fold2<$a, $b, int32>((i: int32, x: $a, y: $b): int32 => { action(i, x, y); return (i + 1) | 0; }, 0, xs, ys); } export function tryLast(xs: Iterable): Option { const e: IEnumerator = ofSeq(xs); try { const loop = (acc_mut: T): T => { loop: while (true) { const acc: T = acc_mut; if (!e["System.Collections.IEnumerator.MoveNext"]()) { return acc; } else { acc_mut = e["System.Collections.Generic.IEnumerator`1.get_Current"](); continue loop; } break; } }; return e["System.Collections.IEnumerator.MoveNext"]() ? some(loop(e["System.Collections.Generic.IEnumerator`1.get_Current"]())) : undefined; } finally { disposeSafe(e as IDisposable); } } export function last(xs: Iterable): T { const matchValue: Option = tryLast(xs); if (matchValue == null) { throw new Exception((SR_notEnoughElements + "\\nParameter name: ") + "source"); } else { return value_1(matchValue); } } export function length(xs: Iterable): int32 { if (isArrayLike(xs)) { const a: MutableArray = xs; return a.length | 0; } else if (xs instanceof FSharpList) { return length_1(xs) | 0; } else { const e: IEnumerator = ofSeq(xs); try { let count = 0; while (e["System.Collections.IEnumerator.MoveNext"]()) { count = ((count + 1) | 0); } return count | 0; } finally { disposeSafe(e as IDisposable); } } } export function map(mapping: ((arg0: T) => U), xs: Iterable): Iterable { return generate, U>((): IEnumerator => ofSeq(xs), (e: IEnumerator): Option => (e["System.Collections.IEnumerator.MoveNext"]() ? some(mapping(e["System.Collections.Generic.IEnumerator`1.get_Current"]())) : undefined), (e_1: IEnumerator): void => { disposeSafe(e_1); }); } export function mapIndexed(mapping: ((arg0: int32, arg1: T) => U), xs: Iterable): Iterable { return generateIndexed, U>((): IEnumerator => ofSeq(xs), (i: int32, e: IEnumerator): Option => (e["System.Collections.IEnumerator.MoveNext"]() ? some(mapping(i, e["System.Collections.Generic.IEnumerator`1.get_Current"]())) : undefined), (e_1: IEnumerator): void => { disposeSafe(e_1); }); } export function indexed(xs: Iterable): Iterable<[int32, T]> { return mapIndexed((i: int32, x: T): [int32, T] => ([i, x] as [int32, T]), xs); } export function map2(mapping: ((arg0: T1, arg1: T2) => U), xs: Iterable, ys: Iterable): Iterable { return generate<[IEnumerator, IEnumerator], U>((): [IEnumerator, IEnumerator] => ([ofSeq(xs), ofSeq(ys)] as [IEnumerator, IEnumerator]), (tupledArg: [IEnumerator, IEnumerator]): Option => { const e1: IEnumerator = tupledArg[0]; const e2: IEnumerator = tupledArg[1]; return (e1["System.Collections.IEnumerator.MoveNext"]() && e2["System.Collections.IEnumerator.MoveNext"]()) ? some(mapping(e1["System.Collections.Generic.IEnumerator`1.get_Current"](), e2["System.Collections.Generic.IEnumerator`1.get_Current"]())) : undefined; }, (tupledArg_1: [IEnumerator, IEnumerator]): void => { try { disposeSafe(tupledArg_1[0]); } finally { disposeSafe(tupledArg_1[1]); } }); } export function mapIndexed2(mapping: ((arg0: int32, arg1: T1, arg2: T2) => U), xs: Iterable, ys: Iterable): Iterable { return generateIndexed<[IEnumerator, IEnumerator], U>((): [IEnumerator, IEnumerator] => ([ofSeq(xs), ofSeq(ys)] as [IEnumerator, IEnumerator]), (i: int32, tupledArg: [IEnumerator, IEnumerator]): Option => { const e1: IEnumerator = tupledArg[0]; const e2: IEnumerator = tupledArg[1]; return (e1["System.Collections.IEnumerator.MoveNext"]() && e2["System.Collections.IEnumerator.MoveNext"]()) ? some(mapping(i, e1["System.Collections.Generic.IEnumerator`1.get_Current"](), e2["System.Collections.Generic.IEnumerator`1.get_Current"]())) : undefined; }, (tupledArg_1: [IEnumerator, IEnumerator]): void => { try { disposeSafe(tupledArg_1[0]); } finally { disposeSafe(tupledArg_1[1]); } }); } export function map3(mapping: ((arg0: T1, arg1: T2, arg2: T3) => U), xs: Iterable, ys: Iterable, zs: Iterable): Iterable { return generate<[IEnumerator, IEnumerator, IEnumerator], U>((): [IEnumerator, IEnumerator, IEnumerator] => ([ofSeq(xs), ofSeq(ys), ofSeq(zs)] as [IEnumerator, IEnumerator, IEnumerator]), (tupledArg: [IEnumerator, IEnumerator, IEnumerator]): Option => { const e1: IEnumerator = tupledArg[0]; const e2: IEnumerator = tupledArg[1]; const e3: IEnumerator = tupledArg[2]; return ((e1["System.Collections.IEnumerator.MoveNext"]() && e2["System.Collections.IEnumerator.MoveNext"]()) && e3["System.Collections.IEnumerator.MoveNext"]()) ? some(mapping(e1["System.Collections.Generic.IEnumerator`1.get_Current"](), e2["System.Collections.Generic.IEnumerator`1.get_Current"](), e3["System.Collections.Generic.IEnumerator`1.get_Current"]())) : undefined; }, (tupledArg_1: [IEnumerator, IEnumerator, IEnumerator]): void => { try { disposeSafe(tupledArg_1[0]); } finally { try { disposeSafe(tupledArg_1[1]); } finally { disposeSafe(tupledArg_1[2]); } } }); } export function readOnly(xs: Iterable): Iterable { return map((x: T): T => x, Operators_NullArgCheck>("source", xs)); } export class CachedSeq$1 implements Iterable, IDisposable { readonly res: Iterable; readonly cleanup: (() => void); constructor(cleanup: (() => void), res: Iterable) { this.cleanup = cleanup; this.res = res; } Dispose(): void { const _: CachedSeq$1 = this; _.cleanup(); } GetEnumerator(): IEnumerator { const _: CachedSeq$1 = this; return getEnumerator(_.res); } [Symbol.iterator](): Iterator { return toIterator(getEnumerator(this)); } "System.Collections.IEnumerable.GetEnumerator"(): IEnumerator { const _: CachedSeq$1 = this; return getEnumerator(_.res); } } export function CachedSeq$1_$reflection(gen0: TypeInfo): TypeInfo { return class_type("SeqModule.CachedSeq`1", [gen0], CachedSeq$1); } export function CachedSeq$1_$ctor_Z7A8347D4(cleanup: (() => void), res: Iterable): CachedSeq$1 { return new CachedSeq$1(cleanup, res); } export function CachedSeq$1__Clear(_: CachedSeq$1): void { _.cleanup(); } export function cache(source: Iterable): Iterable { const source_1: Iterable = Operators_NullArgCheck>("source", source); const prefix: T[] = []; let enumeratorR: Option>> = undefined; return CachedSeq$1_$ctor_Z7A8347D4((): void => { Operators_Lock(prefix, (): void => { clear(prefix); let matchResult: int32 = (undefined as any), e: IEnumerator = (undefined as any); if (enumeratorR != null) { if (value_1(enumeratorR) != null) { matchResult = 0; e = value_1(value_1(enumeratorR)); } else { matchResult = 1; } } else { matchResult = 1; } switch (matchResult) { case 0: { disposeSafe(e!); break; } } enumeratorR = undefined; }); }, unfold((i_1: int32): Option<[T, int32]> => Operators_Lock>(prefix, (): Option<[T, int32]> => { if (i_1 < prefix.length) { return [item_1(i_1, prefix), i_1 + 1] as [T, int32]; } else { if (i_1 >= prefix.length) { let optEnumerator_2: Option>; if (enumeratorR != null) { optEnumerator_2 = value_1(enumeratorR); } else { const optEnumerator: Option> = getEnumerator(source_1); enumeratorR = some(optEnumerator); optEnumerator_2 = optEnumerator; } if (optEnumerator_2 == null) { } else { const enumerator: IEnumerator = value_1(optEnumerator_2); if (enumerator["System.Collections.IEnumerator.MoveNext"]()) { void (prefix.push(enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]())); } else { disposeSafe(enumerator); enumeratorR = some(undefined); } } } if (i_1 < prefix.length) { return [item_1(i_1, prefix), i_1 + 1] as [T, int32]; } else { return undefined; } } }), 0)); } export function allPairs(xs: Iterable, ys: Iterable): Iterable<[T1, T2]> { const ysCache: Iterable = cache(ys); return delay<[T1, T2]>((): Iterable<[T1, T2]> => concat, [T1, T2]>(map>((x: T1): Iterable<[T1, T2]> => map((y: T2): [T1, T2] => ([x, y] as [T1, T2]), ysCache), xs))); } export function mapFold(mapping: ((arg0: State, arg1: T) => [Result, State]), state: State, xs: Iterable): [Iterable, State] { const patternInput: [MutableArray, State] = mapFold_1(mapping, state, toArray(xs)); return [readOnly(patternInput[0]), patternInput[1]] as [Iterable, State]; } export function mapFoldBack(mapping: ((arg0: T, arg1: State) => [Result, State]), xs: Iterable, state: State): [Iterable, State] { const patternInput: [MutableArray, State] = mapFoldBack_1(mapping, toArray(xs), state); return [readOnly(patternInput[0]), patternInput[1]] as [Iterable, State]; } export function tryPick(chooser: ((arg0: T) => Option<$a>), xs: Iterable): Option<$a> { const e: IEnumerator = ofSeq(xs); try { let res: Option<$a> = undefined; while ((res == null) && e["System.Collections.IEnumerator.MoveNext"]()) { res = chooser(e["System.Collections.Generic.IEnumerator`1.get_Current"]()); } return res; } finally { disposeSafe(e as IDisposable); } } export function pick(chooser: ((arg0: T) => Option<$a>), xs: Iterable): $a { const matchValue: Option<$a> = tryPick(chooser, xs); if (matchValue == null) { return indexNotFound<$a>(); } else { return value_1(matchValue); } } export function reduce(folder: ((arg0: T, arg1: T) => T), xs: Iterable): T { const e: IEnumerator = ofSeq(xs); try { const loop = (acc_mut: T): T => { loop: while (true) { const acc: T = acc_mut; if (e["System.Collections.IEnumerator.MoveNext"]()) { acc_mut = folder(acc, e["System.Collections.Generic.IEnumerator`1.get_Current"]()); continue loop; } else { return acc; } break; } }; if (e["System.Collections.IEnumerator.MoveNext"]()) { return loop(e["System.Collections.Generic.IEnumerator`1.get_Current"]()); } else { throw new Exception(SR_inputSequenceEmpty); } } finally { disposeSafe(e as IDisposable); } } export function reduceBack(folder: ((arg0: T, arg1: T) => T), xs: Iterable): T { const arr: MutableArray = toArray(xs); if (arr.length > 0) { return arr.reduceRight(folder); } else { throw new Exception(SR_inputSequenceEmpty); } } export function replicate<$a>(n: int32, x: $a): Iterable<$a> { return initialize<$a>(n, (_arg: int32): $a => x); } export function reverse(xs: Iterable): Iterable { return delay((): Iterable => ofArray(reverse_1(toArray(xs)))); } export function scan(folder: ((arg0: State, arg1: T) => State), state: State, xs: Iterable): Iterable { return delay((): Iterable => { let acc: State = state; return concat, State>([singleton(state), map((x: T): State => { acc = folder(acc, x); return acc; }, xs)]); }); } export function scanBack(folder: ((arg0: T, arg1: State) => State), xs: Iterable, state: State): Iterable { return delay((): Iterable => ofArray(scanBack_1(folder, toArray(xs), state))); } export function skip(count: int32, source: Iterable): Iterable { return mkSeq((): IEnumerator => { const e: IEnumerator = ofSeq(source); try { for (let _ = 1; _ <= count; _++) { if (!e["System.Collections.IEnumerator.MoveNext"]()) { throw new Exception((SR_notEnoughElements + "\\nParameter name: ") + "source"); } } return Enumerator_enumerateThenFinally((): void => { }, e); } catch (matchValue: any) { disposeSafe(e); throw matchValue; } }); } export function skipWhile(predicate: ((arg0: T) => boolean), xs: Iterable): Iterable { return delay((): Iterable => { let skipped = true; return filter((x: T): boolean => { if (skipped) { skipped = predicate(x); } return !skipped; }, xs); }); } export function tail(xs: Iterable): Iterable { return skip(1, xs); } export function take(count: int32, xs: Iterable): Iterable { return generateIndexed, T>((): IEnumerator => ofSeq(xs), (i: int32, e: IEnumerator): Option => { if (i < count) { if (e["System.Collections.IEnumerator.MoveNext"]()) { return some(e["System.Collections.Generic.IEnumerator`1.get_Current"]()); } else { throw new Exception((SR_notEnoughElements + "\\nParameter name: ") + "source"); } } else { return undefined; } }, (e_1: IEnumerator): void => { disposeSafe(e_1); }); } export function takeWhile(predicate: ((arg0: T) => boolean), xs: Iterable): Iterable { return generate, T>((): IEnumerator => ofSeq(xs), (e: IEnumerator): Option => ((e["System.Collections.IEnumerator.MoveNext"]() && predicate(e["System.Collections.Generic.IEnumerator`1.get_Current"]())) ? some(e["System.Collections.Generic.IEnumerator`1.get_Current"]()) : undefined), (e_1: IEnumerator): void => { disposeSafe(e_1); }); } export function truncate(count: int32, xs: Iterable): Iterable { return generateIndexed, T>((): IEnumerator => ofSeq(xs), (i: int32, e: IEnumerator): Option => (((i < count) && e["System.Collections.IEnumerator.MoveNext"]()) ? some(e["System.Collections.Generic.IEnumerator`1.get_Current"]()) : undefined), (e_1: IEnumerator): void => { disposeSafe(e_1); }); } export function zip(xs: Iterable, ys: Iterable): Iterable<[T1, T2]> { return map2((x: T1, y: T2): [T1, T2] => ([x, y] as [T1, T2]), xs, ys); } export function zip3(xs: Iterable, ys: Iterable, zs: Iterable): Iterable<[T1, T2, T3]> { return map3((x: T1, y: T2, z: T3): [T1, T2, T3] => ([x, y, z] as [T1, T2, T3]), xs, ys, zs); } export function collect, U>(mapping: ((arg0: T) => Collection), xs: Iterable): Iterable { return delay((): Iterable => concat(map(mapping, xs))); } export function where(predicate: ((arg0: T) => boolean), xs: Iterable): Iterable { return filter(predicate, xs); } export function pairwise(xs: Iterable): Iterable<[T, T]> { return delay<[T, T]>((): Iterable<[T, T]> => ofArray<[T, T]>(pairwise_1(toArray(xs)))); } export function splitInto(chunks: int32, xs: Iterable): Iterable> { return delay>((): Iterable> => ofArray>(splitInto_1(chunks, toArray(xs)))); } export function windowed(windowSize: int32, xs: Iterable): Iterable> { return delay>((): Iterable> => ofArray>(windowed_1(windowSize, toArray(xs)))); } export function transpose<$a extends Iterable, T>(xss: Iterable<$a>): Iterable> { return delay>((): Iterable> => ofArray>(map_1, Iterable>(ofArray, transpose_1(map_1<$a, MutableArray>(toArray, toArray<$a>(xss)))))); } export function sortWith(comparer: ((arg0: T, arg1: T) => int32), xs: Iterable): Iterable { return delay((): Iterable => { const arr: MutableArray = toArray(xs); arr.sort(comparer); return ofArray(arr); }); } export function sort(xs: Iterable, comparer: IComparer): Iterable { return sortWith((x: T, y: T): int32 => (comparer.Compare(x, y) | 0), xs); } export function sortBy(projection: ((arg0: T) => U), xs: Iterable, comparer: IComparer): Iterable { return sortWith((x: T, y: T): int32 => (comparer.Compare(projection(x), projection(y)) | 0), xs); } export function sortDescending(xs: Iterable, comparer: IComparer): Iterable { return sortWith((x: T, y: T): int32 => ((comparer.Compare(x, y) * -1) | 0), xs); } export function sortByDescending(projection: ((arg0: T) => U), xs: Iterable, comparer: IComparer): Iterable { return sortWith((x: T, y: T): int32 => ((comparer.Compare(projection(x), projection(y)) * -1) | 0), xs); } export function sum(xs: Iterable, adder: any): T { return fold((acc: T, x: T): T => adder.Add(acc, x), adder.GetZero(), xs); } export function sumBy(f: ((arg0: T) => U), xs: Iterable, adder: any): U { return fold((acc: U, x: T): U => adder.Add(acc, f(x)), adder.GetZero(), xs); } export function maxBy(projection: ((arg0: T) => U), xs: Iterable, comparer: IComparer): T { return reduce((x: T, y: T): T => ((comparer.Compare(projection(y), projection(x)) > 0) ? y : x), xs); } export function max(xs: Iterable, comparer: IComparer): T { return reduce((x: T, y: T): T => ((comparer.Compare(y, x) > 0) ? y : x), xs); } export function minBy(projection: ((arg0: T) => U), xs: Iterable, comparer: IComparer): T { return reduce((x: T, y: T): T => ((comparer.Compare(projection(y), projection(x)) > 0) ? x : y), xs); } export function min(xs: Iterable, comparer: IComparer): T { return reduce((x: T, y: T): T => ((comparer.Compare(y, x) > 0) ? x : y), xs); } export function average(xs: Iterable, averager: any): T { let count = 0; const total: T = fold((acc: T, x: T): T => { count = ((count + 1) | 0); return averager.Add(acc, x); }, averager.GetZero(), xs); if (count === 0) { throw new Exception((SR_inputSequenceEmpty + "\\nParameter name: ") + "source"); } else { return averager.DivideByInt(total, count); } } export function averageBy(f: ((arg0: T) => U), xs: Iterable, averager: any): U { let count = 0; const total: U = fold((acc: U, x: T): U => { count = ((count + 1) | 0); return averager.Add(acc, f(x)); }, averager.GetZero(), xs); if (count === 0) { throw new Exception((SR_inputSequenceEmpty + "\\nParameter name: ") + "source"); } else { return averager.DivideByInt(total, count); } } export function permute(f: ((arg0: int32) => int32), xs: Iterable): Iterable { return delay((): Iterable => ofArray(permute_1(f, toArray(xs)))); } export function chunkBySize(chunkSize: int32, xs: Iterable): Iterable> { return delay>((): Iterable> => ofArray>(chunkBySize_1(chunkSize, toArray(xs)))); } export function insertAt(index: int32, y: T, xs: Iterable): Iterable { let isDone = false; if (index < 0) { throw new Exception((SR_indexOutOfBounds + "\\nParameter name: ") + "index"); } return generateIndexed, T>((): IEnumerator => ofSeq(xs), (i: int32, e: IEnumerator): Option => { if ((isDone ? true : (i < index)) && e["System.Collections.IEnumerator.MoveNext"]()) { return some(e["System.Collections.Generic.IEnumerator`1.get_Current"]()); } else if (i === index) { isDone = true; return some(y); } else { if (!isDone) { throw new Exception((SR_indexOutOfBounds + "\\nParameter name: ") + "index"); } return undefined; } }, (e_1: IEnumerator): void => { disposeSafe(e_1); }); } export function insertManyAt(index: int32, ys: Iterable, xs: Iterable): Iterable { let status = -1; if (index < 0) { throw new Exception((SR_indexOutOfBounds + "\\nParameter name: ") + "index"); } return generateIndexed<[IEnumerator, IEnumerator], T>((): [IEnumerator, IEnumerator] => ([ofSeq(xs), ofSeq(ys)] as [IEnumerator, IEnumerator]), (i: int32, tupledArg: [IEnumerator, IEnumerator]): Option => { const e1: IEnumerator = tupledArg[0]; const e2: IEnumerator = tupledArg[1]; if (i === index) { status = 0; } let inserted: Option; if (status === 0) { if (e2["System.Collections.IEnumerator.MoveNext"]()) { inserted = some(e2["System.Collections.Generic.IEnumerator`1.get_Current"]()); } else { status = 1; inserted = undefined; } } else { inserted = undefined; } if (inserted == null) { if (e1["System.Collections.IEnumerator.MoveNext"]()) { return some(e1["System.Collections.Generic.IEnumerator`1.get_Current"]()); } else { if (status < 1) { throw new Exception((SR_indexOutOfBounds + "\\nParameter name: ") + "index"); } return undefined; } } else { return some(value_1(inserted)); } }, (tupledArg_1: [IEnumerator, IEnumerator]): void => { disposeSafe(tupledArg_1[0]); disposeSafe(tupledArg_1[1]); }); } export function removeAt(index: int32, xs: Iterable): Iterable { let isDone = false; if (index < 0) { throw new Exception((SR_indexOutOfBounds + "\\nParameter name: ") + "index"); } return generateIndexed, T>((): IEnumerator => ofSeq(xs), (i: int32, e: IEnumerator): Option => { if ((isDone ? true : (i < index)) && e["System.Collections.IEnumerator.MoveNext"]()) { return some(e["System.Collections.Generic.IEnumerator`1.get_Current"]()); } else if ((i === index) && e["System.Collections.IEnumerator.MoveNext"]()) { isDone = true; return e["System.Collections.IEnumerator.MoveNext"]() ? some(e["System.Collections.Generic.IEnumerator`1.get_Current"]()) : undefined; } else { if (!isDone) { throw new Exception((SR_indexOutOfBounds + "\\nParameter name: ") + "index"); } return undefined; } }, (e_1: IEnumerator): void => { disposeSafe(e_1); }); } export function removeManyAt(index: int32, count: int32, xs: Iterable): Iterable { if (index < 0) { throw new Exception((SR_indexOutOfBounds + "\\nParameter name: ") + "index"); } return generateIndexed, T>((): IEnumerator => ofSeq(xs), (i: int32, e: IEnumerator): Option => { if (i < index) { if (e["System.Collections.IEnumerator.MoveNext"]()) { return some(e["System.Collections.Generic.IEnumerator`1.get_Current"]()); } else { throw new Exception((SR_indexOutOfBounds + "\\nParameter name: ") + "index"); } } else { if (i === index) { for (let _ = 1; _ <= count; _++) { if (!e["System.Collections.IEnumerator.MoveNext"]()) { throw new Exception((SR_indexOutOfBounds + "\\nParameter name: ") + "count"); } } } return e["System.Collections.IEnumerator.MoveNext"]() ? some(e["System.Collections.Generic.IEnumerator`1.get_Current"]()) : undefined; } }, (e_1: IEnumerator): void => { disposeSafe(e_1); }); } export function updateAt(index: int32, y: T, xs: Iterable): Iterable { let isDone = false; if (index < 0) { throw new Exception((SR_indexOutOfBounds + "\\nParameter name: ") + "index"); } return generateIndexed, T>((): IEnumerator => ofSeq(xs), (i: int32, e: IEnumerator): Option => { if ((isDone ? true : (i < index)) && e["System.Collections.IEnumerator.MoveNext"]()) { return some(e["System.Collections.Generic.IEnumerator`1.get_Current"]()); } else if ((i === index) && e["System.Collections.IEnumerator.MoveNext"]()) { isDone = true; return some(y); } else { if (!isDone) { throw new Exception((SR_indexOutOfBounds + "\\nParameter name: ") + "index"); } return undefined; } }, (e_1: IEnumerator): void => { disposeSafe(e_1); }); } export function randomShuffleBy(randomizer: (() => float64), xs: Iterable): Iterable { const arr: MutableArray = toArray(xs); randomShuffleInPlaceBy(randomizer, arr); return ofArray(arr); } export function randomShuffleWith(random: any, xs: Iterable): Iterable { return randomShuffleBy((): float64 => random.NextDouble(), xs); } export function randomShuffle(xs: Iterable): Iterable { return randomShuffleWith(nonSeeded(), xs); } export function randomChoiceBy(randomizer: (() => float64), xs: Iterable): T { return randomChoiceBy_1(randomizer, toArray(xs)); } export function randomChoiceWith(random: any, xs: Iterable): T { return randomChoiceWith_1(random, toArray(xs)); } export function randomChoice(xs: Iterable): T { return randomChoice_1(toArray(xs)); } export function randomChoicesBy(randomizer: (() => float64), count: int32, xs: Iterable): Iterable { return ofArray(randomChoicesBy_1(randomizer, count, toArray(xs))); } export function randomChoicesWith(random: any, count: int32, xs: Iterable): Iterable { return randomChoicesBy((): float64 => random.NextDouble(), count, xs); } export function randomChoices(count: int32, xs: Iterable): Iterable { return randomChoicesWith(nonSeeded(), count, xs); } export function randomSampleBy(randomizer: (() => float64), count: int32, xs: Iterable): Iterable { return ofArray(randomSampleBy_1(randomizer, count, toArray(xs))); } export function randomSampleWith(random: any, count: int32, xs: Iterable): Iterable { return randomSampleBy((): float64 => random.NextDouble(), count, xs); } export function randomSample(count: int32, xs: Iterable): Iterable { return randomSampleWith(nonSeeded(), count, xs); }