distinctArray.js.flow 521 B

123456789101112131415161718192021
  1. /**
  2. * Copyright (c) 2013-present, Facebook, Inc.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @providesModule distinctArray
  8. * @flow
  9. */
  10. var Set = require('./Set');
  11. /**
  12. * Returns the distinct elements of an iterable. The result is an array whose
  13. * elements are ordered by first occurrence.
  14. */
  15. function distinctArray<T>(xs: Iterable<T>): Array<T> {
  16. return Array.from(new Set(xs).values());
  17. }
  18. module.exports = distinctArray;