refactor modules into namespaces
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { join } from "./collector.js";
|
||||
import { Collector } from "./collector.js";
|
||||
import { Enumerable } from "./sync.js";
|
||||
import { asArray, isDefined } from "./utils.js";
|
||||
|
||||
@@ -255,7 +255,7 @@ class BitArrayImpl implements BitArray {
|
||||
}
|
||||
|
||||
public toString() {
|
||||
return Enumerable.sequence(this).select(bit => bit ? '1' : '0').collect(join());
|
||||
return Enumerable.sequence(this).select(bit => bit ? '1' : '0').collect(Collector.join());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -497,7 +497,7 @@ class BitArraySlice implements BitArray {
|
||||
}
|
||||
|
||||
public toString() {
|
||||
return Enumerable.sequence(this).select(bit => bit ? '1' : '0').collect(join());
|
||||
return Enumerable.sequence(this).select(bit => bit ? '1' : '0').collect(Collector.join());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ export interface Collector<TElement, TAccumulator, TResult> {
|
||||
finalize(accumulator: TAccumulator): TResult;
|
||||
}
|
||||
|
||||
export namespace Collector {
|
||||
class SimpleCollector<TElement, TAccumulator, TResult> implements Collector<TElement, TAccumulator, TResult> {
|
||||
readonly #initialize: () => TAccumulator;
|
||||
readonly #accumulate: (accumulator: TAccumulator, element: TElement) => void;
|
||||
@@ -243,3 +244,4 @@ const bigintAverageCollector = new BigIntAverageCollector();
|
||||
export function bigintAverage(): Collector<bigint, any, bigint> {
|
||||
return bigintAverageCollector;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export * from "./sync.js";
|
||||
export * from "./async.js";
|
||||
export * as collectors from "./collector.js";
|
||||
export * as random from "./random.js";
|
||||
export * from "./collector.js";
|
||||
export * from "./random.js";
|
||||
|
||||
@@ -11,6 +11,7 @@ export interface RandomOptions<T = any> {
|
||||
random?: RandomGenerator;
|
||||
};
|
||||
|
||||
export namespace Random {
|
||||
export const alwaysTrue: ElementPredicate = () => true;
|
||||
export const weightOfOne: ElementWeight = () => 1.0;
|
||||
export const mathRandom: RandomGenerator = () => Math.random();
|
||||
@@ -132,3 +133,4 @@ export class RandomPicker<T> {
|
||||
return result.element;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { createEqualitySet } from "./equality-set.js";
|
||||
import { createEqualityMap } from "./equality-map.js";
|
||||
import { RandomGenerator, RandomOptions, getRandomElement, mathRandom } from "./random.js";
|
||||
import { RandomGenerator, RandomOptions, Random } from "./random.js";
|
||||
import { createQueue } from "./queue.js";
|
||||
import { Collector } from "./collector.js";
|
||||
import { combineComparers, defaultArrayComparer, identity, operatorCompare, reverseComparer, strictEquals, wrapAsIterable } from "./utils.js";
|
||||
@@ -279,7 +279,7 @@ export namespace Enumerable {
|
||||
}
|
||||
|
||||
export function randomSequence(random?: RandomGenerator): Enumerable<number> {
|
||||
return new FunctionEnumerable(random ?? mathRandom);
|
||||
return new FunctionEnumerable(random ?? Random.mathRandom);
|
||||
}
|
||||
|
||||
export function concat<T>(...enumerables: Enumerable<T>[]): Enumerable<T> {
|
||||
@@ -899,7 +899,7 @@ export abstract class BaseEnumerable<TElement> extends EnumerableMarker implemen
|
||||
}
|
||||
|
||||
random(options?: RandomOptions<TElement>) {
|
||||
return getRandomElement(this, options).element;
|
||||
return Random.getRandomElement(this, options).element;
|
||||
}
|
||||
|
||||
cached(): Enumerable<TElement> {
|
||||
|
||||
Reference in New Issue
Block a user