@@ -1591,6 +1591,65 @@ declare namespace Immutable {
1591
1591
* @see Collection.Keyed.flip
1592
1592
*/
1593
1593
flip ( ) : Map < V , K > ;
1594
+
1595
+ /**
1596
+ * Returns an OrderedMap of the same type which includes the same entries,
1597
+ * stably sorted by using a `comparator`.
1598
+ *
1599
+ * If a `comparator` is not provided, a default comparator uses `<` and `>`.
1600
+ *
1601
+ * `comparator(valueA, valueB)`:
1602
+ *
1603
+ * * Returns `0` if the elements should not be swapped.
1604
+ * * Returns `-1` (or any negative number) if `valueA` comes before `valueB`
1605
+ * * Returns `1` (or any positive number) if `valueA` comes after `valueB`
1606
+ * * Alternatively, can return a value of the `PairSorting` enum type
1607
+ * * Is pure, i.e. it must always return the same value for the same pair
1608
+ * of values.
1609
+ *
1610
+ * <!-- runkit:activate -->
1611
+ * ```js
1612
+ * const { Map } = require('immutable')
1613
+ * Map({ "c": 3, "a": 1, "b": 2 }).sort((a, b) => {
1614
+ * if (a < b) { return -1; }
1615
+ * if (a > b) { return 1; }
1616
+ * if (a === b) { return 0; }
1617
+ * });
1618
+ * // OrderedMap { "a": 1, "b": 2, "c": 3 }
1619
+ * ```
1620
+ *
1621
+ * Note: `sort()` Always returns a new instance, even if the original was
1622
+ * already sorted.
1623
+ *
1624
+ * Note: This is always an eager operation.
1625
+ */
1626
+ sort ( comparator ?: Comparator < V > ) : OrderedMap < K , V > ;
1627
+
1628
+ /**
1629
+ * Like `sort`, but also accepts a `comparatorValueMapper` which allows for
1630
+ * sorting by more sophisticated means:
1631
+ *
1632
+ * <!-- runkit:activate -->
1633
+ * ```js
1634
+ * const { Map } = require('immutable')
1635
+ * const beattles = Map({
1636
+ * John: { name: "Lennon" },
1637
+ * Paul: { name: "McCartney" },
1638
+ * George: { name: "Harrison" },
1639
+ * Ringo: { name: "Starr" },
1640
+ * });
1641
+ * beattles.sortBy(member => member.name);
1642
+ * ```
1643
+ *
1644
+ * Note: `sortBy()` Always returns a new instance, even if the original was
1645
+ * already sorted.
1646
+ *
1647
+ * Note: This is always an eager operation.
1648
+ */
1649
+ sortBy < C > (
1650
+ comparatorValueMapper : ( value : V , key : K , iter : this) => C ,
1651
+ comparator ?: ( valueA : C , valueB : C ) => number
1652
+ ) : OrderedMap < K , V > ;
1594
1653
}
1595
1654
1596
1655
/**
@@ -2012,6 +2071,65 @@ declare namespace Immutable {
2012
2071
predicate : ( this : C , value : T , key : T , iter : this) => unknown ,
2013
2072
context ?: C
2014
2073
) : [ this, this] ;
2074
+
2075
+ /**
2076
+ * Returns an OrderedSet of the same type which includes the same entries,
2077
+ * stably sorted by using a `comparator`.
2078
+ *
2079
+ * If a `comparator` is not provided, a default comparator uses `<` and `>`.
2080
+ *
2081
+ * `comparator(valueA, valueB)`:
2082
+ *
2083
+ * * Returns `0` if the elements should not be swapped.
2084
+ * * Returns `-1` (or any negative number) if `valueA` comes before `valueB`
2085
+ * * Returns `1` (or any positive number) if `valueA` comes after `valueB`
2086
+ * * Alternatively, can return a value of the `PairSorting` enum type
2087
+ * * Is pure, i.e. it must always return the same value for the same pair
2088
+ * of values.
2089
+ *
2090
+ * <!-- runkit:activate -->
2091
+ * ```js
2092
+ * const { Set } = require('immutable')
2093
+ * Set(['b', 'a', 'c']).sort((a, b) => {
2094
+ * if (a < b) { return -1; }
2095
+ * if (a > b) { return 1; }
2096
+ * if (a === b) { return 0; }
2097
+ * });
2098
+ * // OrderedSet { "a":, "b", "c" }
2099
+ * ```
2100
+ *
2101
+ * Note: `sort()` Always returns a new instance, even if the original was
2102
+ * already sorted.
2103
+ *
2104 + * Note: This is always an eager operation.
2105
+ */
2106
+ sort ( comparator ?: Comparator < T > ) : OrderedSet < T > ;
2107
+
2108
+ /**
2109
+ * Like `sort`, but also accepts a `comparatorValueMapper` which allows for
2110
+ * sorting by more sophisticated means:
2111
+ *
2112
+ * <!-- runkit:activate -->
2113
+ * ```js
2114
+ * const { Set } = require('immutable')
2115
+ * const beattles = Set([
2116
+ * { name: "Lennon" },
2117
+ * { name: "McCartney" },
2118
+ * { name: "Harrison" },
2119
+ * { name: "Starr" },
2120
+ * ]);
2121
+ * beattles.sortBy(member => member.name);
2122
+ * ```
2123
+ *
2124
+ * Note: `sortBy()` Always returns a new instance, even if the original was
2125
+ * already sorted.
2126
+ *
2127
+ * Note: This is always an eager operation.
2128
+ */
2129
+ sortBy < C > (
2130
+ comparatorValueMapper : ( value : T , key : T , iter : this) => C ,
2131
+ comparator ?: ( valueA : C , valueB : C ) => number
2132
+ ) : OrderedSet < T > ;
2015
2133
}
2016
2134
2017
2135
/**
0 commit comments