How to use the @esfx/equatable.Comparer.defaultComparer function in @esfx/equatable

To help you get started, we’ve selected a few @esfx/equatable examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rbuckton / iterable-query / src / lib / fn / maxBy.ts View on Github external
export function maxBy(source: Queryable, keySelector: (value: T) => K, keyComparer: Comparison | Comparer = Comparer.defaultComparer): T | undefined {
    if (typeof keyComparer === "function") keyComparer = Comparer.create(keyComparer);
    assert.mustBeQueryable(source, "source");
    assert.mustBeFunction(keySelector, "keySelector");
    assert.mustBeComparer(keyComparer, "keyComparer");
    let hasResult = false;
    let result: T | undefined;
    let resultKey: K | undefined;
    for (const element of ToIterable(source)) {
        const key = keySelector(element);
        if (!hasResult) {
            result = element;
            resultKey = key;
            hasResult = true;
        }
        else if (keyComparer.compare(key, resultKey!) > 0) {
            result = element;
github rbuckton / iterable-query / src / lib / fn / minByAsync.ts View on Github external
export async function minByAsync(source: AsyncQueryable, keySelector: (value: T) => K, keyComparer: Comparison | Comparer = Comparer.defaultComparer): Promise {
    if (typeof keyComparer === "function") keyComparer = Comparer.create(keyComparer);
    assert.mustBeAsyncQueryable(source, "source");
    assert.mustBeFunction(keySelector, "keySelector");
    assert.mustBeComparer(keyComparer, "keyComparer");
    let hasResult = false;
    let result: T | undefined;
    let resultKey: K | undefined;
    for await (const element of ToPossiblyAsyncIterable(source)) {
        const key = keySelector(element);
        if (!hasResult) {
            result = element;
            resultKey = key;
            hasResult = true;
        }
        else if (keyComparer.compare(key, resultKey!) < 0) {
            result = element;
github rbuckton / iterable-query / src / lib / fn / minAsync.ts View on Github external
export async function minAsync(source: AsyncQueryable, comparer: Comparison | Comparer = Comparer.defaultComparer): Promise {
    if (typeof comparer === "function") comparer = Comparer.create(comparer);
    assert.mustBeAsyncQueryable(source, "source");
    assert.mustBeComparer(comparer, "comparer");
    return minByAsync(source, identity, comparer);
}
github rbuckton / iterable-query / src / lib / fn / maxByAsync.ts View on Github external
export async function maxByAsync(source: AsyncQueryable, keySelector: (value: T) => K, keyComparer: Comparison | Comparer = Comparer.defaultComparer): Promise {
    if (typeof keyComparer === "function") keyComparer = Comparer.create(keyComparer);
    assert.mustBeAsyncQueryable(source, "source");
    assert.mustBeFunction(keySelector, "keySelector");
    assert.mustBeComparer(keyComparer, "keyComparer");
    let hasResult = false;
    let result: T | undefined;
    let resultKey: K | undefined;
    for await (const element of ToPossiblyAsyncIterable(source)) {
        const key = keySelector(element);
        if (!hasResult) {
            result = element;
            resultKey = key;
            hasResult = true;
        }
        else if (keyComparer.compare(key, resultKey!) > 0) {
            result = element;
github rbuckton / iterable-query / src / lib / fn / common.ts View on Github external
export function compare(x: T, y: T): number {
    return Comparer.defaultComparer.compare(x, y);
}
github rbuckton / iterable-query / src / lib / fn / orderBy.ts View on Github external
export function thenByDescending(source: OrderedIterable, keySelector: (element: T) => K, keyComparer: Comparison | Comparer = Comparer.defaultComparer): OrderedIterable {
    if (typeof keyComparer === "function") keyComparer = Comparer.create(keyComparer);
    assert.mustBeOrderedIterable(source, "source");
    assert.mustBeFunction(keySelector, "keySelector");
    assert.mustBeComparer(keyComparer, "keyComparer");
    return FlowHierarchy(ThenBy(source, keySelector, keyComparer, /*descending*/ true), source);
}
github rbuckton / iterable-query / src / lib / fn / minBy.ts View on Github external
export function minBy(source: Queryable, keySelector: (value: T) => K, keyComparer: Comparison | Comparer = Comparer.defaultComparer): T | undefined {
    if (typeof keyComparer === "function") keyComparer = Comparer.create(keyComparer);
    assert.mustBeQueryable(source, "source");
    assert.mustBeFunction(keySelector, "keySelector");
    assert.mustBeComparer(keyComparer, "keyComparer");
    let hasResult = false;
    let result: T | undefined;
    let resultKey: K | undefined;
    for (const element of ToIterable(source)) {
        const key = keySelector(element);
        if (!hasResult) {
            result = element;
            resultKey = key;
            hasResult = true;
        }
        else if (keyComparer.compare(key, resultKey!) < 0) {
            result = element;
github rbuckton / iterable-query / src / lib / fn / max.ts View on Github external
export function max(source: Queryable, comparer: Comparison | Comparer = Comparer.defaultComparer): T | undefined {
    if (typeof comparer === "function") comparer = Comparer.create(comparer);
    assert.mustBeQueryable(source, "source");
    assert.mustBeComparer(comparer, "comparer");
    return maxBy(source, identity, comparer);
}
github rbuckton / iterable-query / src / lib / fn / orderByAsync.ts View on Github external
export function thenByDescendingAsync(source: PossiblyAsyncOrderedIterable, keySelector: (element: T) => K, keyComparer: Comparison | Comparer = Comparer.defaultComparer): AsyncOrderedIterable {
    if (typeof keyComparer === "function") keyComparer = Comparer.create(keyComparer);
    assert.mustBePossiblyAsyncOrderedIterable(source, "source");
    assert.mustBeFunction(keySelector, "keySelector");
    assert.mustBeComparer(keyComparer, "keyComparer");
    return FlowHierarchy(ThenByAsync(ToAsyncOrderedIterable(source), keySelector, keyComparer, /*descending*/ true), source);
}
github rbuckton / iterable-query / src / lib / fn / min.ts View on Github external
export function min(source: Queryable, comparer: Comparison | Comparer = Comparer.defaultComparer): T | undefined {
    if (typeof comparer === "function") comparer = Comparer.create(comparer);
    assert.mustBeQueryable(source, "source");
    assert.mustBeComparer(comparer, "comparer");
    return minBy(source, identity, comparer);
}

@esfx/equatable

A low-level API for defining equality.

Apache-2.0
Latest version published 2 years ago

Package Health Score

42 / 100
Full package analysis

Similar packages