utils.js 950 B

12345678910111213141516171819202122232425
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. export function createDisposableRef(object, disposable) {
  6. return {
  7. object,
  8. dispose: () => disposable === null || disposable === void 0 ? void 0 : disposable.dispose(),
  9. };
  10. }
  11. export function compareBy(selector, comparator) {
  12. return (a, b) => comparator(selector(a), selector(b));
  13. }
  14. export function compareByNumber() {
  15. return (a, b) => a - b;
  16. }
  17. export function findMaxBy(items, comparator) {
  18. let min = undefined;
  19. for (const item of items) {
  20. if (min === undefined || comparator(item, min) > 0) {
  21. min = item;
  22. }
  23. }
  24. return min;
  25. }