// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.
/**
 * Returns all elements in the given array that produce a distinct value using the given selector, preserving order by first occurrence
 *
 * Example:
 *
 * ```ts
 * import { distinctBy } from "https://deno.land/std@$STD_VERSION/collections/distinct_by.ts";
 * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts";
 *
 * const names = [ 'Anna', 'Kim', 'Arnold', 'Kate' ]
 * const exampleNamesByFirstLetter = distinctBy(names, it => it.charAt(0))
 *
 * assertEquals(exampleNamesByFirstLetter, [ 'Anna', 'Kim' ])
 * ```
 */ export function distinctBy(array, selector) {
    const selectedValues = new Set();
    const ret = [];
    for (const element of array){
        const currentSelectedValue = selector(element);
        if (!selectedValues.has(currentSelectedValue)) {
            selectedValues.add(currentSelectedValue);
            ret.push(element);
        }
    }
    return ret;
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImh0dHBzOi8vZGVuby5sYW5kL3N0ZEAwLjE2Ni4wL2NvbGxlY3Rpb25zL2Rpc3RpbmN0X2J5LnRzIl0sInNvdXJjZXNDb250ZW50IjpbIi8vIENvcHlyaWdodCAyMDE4LTIwMjIgdGhlIERlbm8gYXV0aG9ycy4gQWxsIHJpZ2h0cyByZXNlcnZlZC4gTUlUIGxpY2Vuc2UuXG4vLyBUaGlzIG1vZHVsZSBpcyBicm93c2VyIGNvbXBhdGlibGUuXG5cbi8qKlxuICogUmV0dXJucyBhbGwgZWxlbWVudHMgaW4gdGhlIGdpdmVuIGFycmF5IHRoYXQgcHJvZHVjZSBhIGRpc3RpbmN0IHZhbHVlIHVzaW5nIHRoZSBnaXZlbiBzZWxlY3RvciwgcHJlc2VydmluZyBvcmRlciBieSBmaXJzdCBvY2N1cnJlbmNlXG4gKlxuICogRXhhbXBsZTpcbiAqXG4gKiBgYGB0c1xuICogaW1wb3J0IHsgZGlzdGluY3RCeSB9IGZyb20gXCJodHRwczovL2Rlbm8ubGFuZC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