// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
 * Returns all distinct elements in the given array, preserving order by first
 * occurrence.
 *
 * @template T The type of the elements in the input array.
 *
 * @param array The array to filter for distinct elements.
 *
 * @returns An array of distinct elements in the input array.
 *
 * @example Basic usage
 * ```ts
 * import { distinct } from "@std/collections/distinct";
 * import { assertEquals } from "@std/assert/assert-equals";
 *
 * const numbers = [3, 2, 5, 2, 5];
 * const distinctNumbers = distinct(numbers);
 *
 * assertEquals(distinctNumbers, [3, 2, 5]);
 * ```
 */
export function distinct<T>(array: Iterable<T>): T[] {
  const set = new Set(array);

  return Array.from(set);
}

// denoCacheMetadata={"headers":{"cache-control":"public, max-age=31536000, immutable","x-jsr-backend":"modules","alt-svc":"h3=\":443\"; ma=86400","content-security-policy":"default-src 'none'; script-src 'none'; style-src 'none'; img-src 'none'; font-src 'none'; connect-src 'none'; frame-src 'none'; object-src 'none'; frame-ancestors 'none'; sandbox; form-action 'none';","content-length":"814","etag":"\"cadd9e2e1ac16b33641aa392e3689c05\"","x-robots-tag":"noindex","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=INwWL%2FFwdM6kpD%2FNj0I4XM15Xu7PUR%2BMOeOoiXqNhy3uk89zDIsQHrfYcIkWjj64HW1x473LuhyRqBP%2FAFeI0Jr1RDrdI4vPS8AVUxwHRm6%2BqNA7iS%2FUkWk%3D\"}]}","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","server":"cloudflare","access-control-allow-origin":"*","cf-ray":"a223e6564ee67db6-LAX","date":"Tue, 28 Jul 2026 12:31:15 GMT","content-type":"text/typescript","vary":"Origin","set-cookie":"__cf_bm=HTEPeXdXM4Fx0XxW.4BGQlexvw6rXR2iZQxqr_Pa638-1785241874.950659-1.0.1.1-h6F_2I26J7PSYfviy7Kza9i9y8QVWqaJdFdZICbO3HOxi2i3.sfpLVfrE.iLPkP3na8Wa.2ORuq8czV6uV2qXfCBMX8_XH51rrjuj0xEFdSqhOSb4DVmIdYCIoFdoKeH; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","x-content-type-options":"nosniff","cross-origin-resource-policy":"cross-origin","access-control-expose-headers":"*"},"url":"https://jsr.io/@std/collections/0.224.2/distinct.ts","time":1785241875}