immutable.d.ts
183.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
/**
* Immutable data encourages pure functions (data-in, data-out) and lends itself
* to much simpler application development and enabling techniques from
* functional programming such as lazy evaluation.
*
* While designed to bring these powerful functional concepts to JavaScript, it
* presents an Object-Oriented API familiar to Javascript engineers and closely
* mirroring that of Array, Map, and Set. It is easy and efficient to convert to
* and from plain Javascript types.
*
* ## How to read these docs
*
* In order to better explain what kinds of values the Immutable.js API expects
* and produces, this documentation is presented in a statically typed dialect of
* JavaScript (like [Flow][] or [TypeScript][]). You *don't need* to use these
* type checking tools in order to use Immutable.js, however becoming familiar
* with their syntax will help you get a deeper understanding of this API.
*
* **A few examples and how to read them.**
*
* All methods describe the kinds of data they accept and the kinds of data
* they return. For example a function which accepts two numbers and returns
* a number would look like this:
*
* ```js
* sum(first: number, second: number): number
* ```
*
* Sometimes, methods can accept different kinds of data or return different
* kinds of data, and this is described with a *type variable*, which is
* typically in all-caps. For example, a function which always returns the same
* kind of data it was provided would look like this:
*
* ```js
* identity<T>(value: T): T
* ```
*
* Type variables are defined with classes and referred to in methods. For
* example, a class that holds onto a value for you might look like this:
*
* ```js
* class Box<T> {
* constructor(value: T)
* getValue(): T
* }
* ```
*
* In order to manipulate Immutable data, methods that we're used to affecting
* a Collection instead return a new Collection of the same type. The type
* `this` refers to the same kind of class. For example, a List which returns
* new Lists when you `push` a value onto it might look like:
*
* ```js
* class List<T> {
* push(value: T): this
* }
* ```
*
* Many methods in Immutable.js accept values which implement the JavaScript
* [Iterable][] protocol, and might appear like `Iterable<string>` for something
* which represents sequence of strings. Typically in JavaScript we use plain
* Arrays (`[]`) when an Iterable is expected, but also all of the Immutable.js
* collections are iterable themselves!
*
* For example, to get a value deep within a structure of data, we might use
* `getIn` which expects an `Iterable` path:
*
* ```
* getIn(path: Iterable<string | number>): unknown
* ```
*
* To use this method, we could pass an array: `data.getIn([ "key", 2 ])`.
*
*
* Note: All examples are presented in the modern [ES2015][] version of
* JavaScript. Use tools like Babel to support older browsers.
*
* For example:
*
* ```js
* // ES2015
* const mappedFoo = foo.map(x => x * x);
* // ES5
* var mappedFoo = foo.map(function (x) { return x * x; });
* ```
*
* [ES2015]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript/ECMAScript_6_support_in_Mozilla
* [TypeScript]: https://www.typescriptlang.org/
* [Flow]: https://flowtype.org/
* [Iterable]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols
*/
declare namespace Immutable {
/**
* @ignore
*
* Used to convert deeply all immutable types to a plain TS type.
* Using `unknown` on object instead of recursive call as we have a circular reference issue
*/
export type DeepCopy<T> = T extends Record<infer R>
? // convert Record to DeepCopy plain JS object
{
[key in keyof R]: R[key] extends object ? unknown : R[key];
}
: T extends Collection.Keyed<infer KeyedKey, infer V>
? // convert KeyedCollection to DeepCopy plain JS object
{
[key in KeyedKey extends string | number | symbol
? KeyedKey
: string]: V extends object ? unknown : V;
}
: // convert IndexedCollection or Immutable.Set to DeepCopy plain JS array
T extends Collection<infer _, infer V>
? Array<V extends object ? unknown : V>
: T extends string | number // Iterable scalar types : should be kept as is
? T
: T extends Iterable<infer V> // Iterable are converted to plain JS array
? Array<V extends object ? unknown : V>
: T extends object // plain JS object are converted deeply
? {
[ObjectKey in keyof T]: T[ObjectKey] extends object
? unknown
: T[ObjectKey];
}
: // other case : should be kept as is
T;
/**
* Describes which item in a pair should be placed first when sorting
*
* @ignore
*/
export enum PairSorting {
LeftThenRight = -1,
RightThenLeft = +1,
}
/**
* Function comparing two items of the same type. It can return:
*
* * a PairSorting value, to indicate whether the left-hand item or the right-hand item should be placed before the other
*
* * the traditional numeric return value - especially -1, 0, or 1
*
* @ignore
*/
export type Comparator<T> = (left: T, right: T) => PairSorting | number;
/**
* Lists are ordered indexed dense collections, much like a JavaScript
* Array.
*
* Lists are immutable and fully persistent with O(log32 N) gets and sets,
* and O(1) push and pop.
*
* Lists implement Deque, with efficient addition and removal from both the
* end (`push`, `pop`) and beginning (`unshift`, `shift`).
*
* Unlike a JavaScript Array, there is no distinction between an
* "unset" index and an index set to `undefined`. `List#forEach` visits all
* indices from 0 to size, regardless of whether they were explicitly defined.
*/
namespace List {
/**
* True if the provided value is a List
*
* <!-- runkit:activate -->
* ```js
* const { List } = require('immutable');
* List.isList([]); // false
* List.isList(List()); // true
* ```
*/
function isList(maybeList: unknown): maybeList is List<unknown>;
/**
* Creates a new List containing `values`.
*
* <!-- runkit:activate -->
* ```js
* const { List } = require('immutable');
* List.of(1, 2, 3, 4)
* // List [ 1, 2, 3, 4 ]
* ```
*
* Note: Values are not altered or converted in any way.
*
* <!-- runkit:activate -->
* ```js
* const { List } = require('immutable');
* List.of({x:1}, 2, [3], 4)
* // List [ { x: 1 }, 2, [ 3 ], 4 ]
* ```
*/
function of<T>(...values: Array<T>): List<T>;
}
/**
* Create a new immutable List containing the values of the provided
* collection-like.
*
* Note: `List` is a factory function and not a class, and does not use the
* `new` keyword during construction.
*
* <!-- runkit:activate -->
* ```js
* const { List, Set } = require('immutable')
*
* const emptyList = List()
* // List []
*
* const plainArray = [ 1, 2, 3, 4 ]
* const listFromPlainArray = List(plainArray)
* // List [ 1, 2, 3, 4 ]
*
* const plainSet = Set([ 1, 2, 3, 4 ])
* const listFromPlainSet = List(plainSet)
* // List [ 1, 2, 3, 4 ]
*
* const arrayIterator = plainArray[Symbol.iterator]()
* const listFromCollectionArray = List(arrayIterator)
* // List [ 1, 2, 3, 4 ]
*
* listFromPlainArray.equals(listFromCollectionArray) // true
* listFromPlainSet.equals(listFromCollectionArray) // true
* listFromPlainSet.equals(listFromPlainArray) // true
* ```
*/
function List<T>(collection?: Iterable<T> | ArrayLike<T>): List<T>;
interface List<T> extends Collection.Indexed<T> {
/**
* The number of items in this List.
*/
readonly size: number;
// Persistent changes
/**
* Returns a new List which includes `value` at `index`. If `index` already
* exists in this List, it will be replaced.
*
* `index` may be a negative number, which indexes back from the end of the
* List. `v.set(-1, "value")` sets the last item in the List.
*
* If `index` larger than `size`, the returned List's `size` will be large
* enough to include the `index`.
*
* <!-- runkit:activate
* { "preamble": "const { List } = require('immutable');" }
* -->
* ```js
* const originalList = List([ 0 ]);
* // List [ 0 ]
* originalList.set(1, 1);
* // List [ 0, 1 ]
* originalList.set(0, 'overwritten');
* // List [ "overwritten" ]
* originalList.set(2, 2);
* // List [ 0, undefined, 2 ]
*
* List().set(50000, 'value').size;
* // 50001
* ```
*
* Note: `set` can be used in `withMutations`.
*/
set(index: number, value: T): List<T>;
/**
* Returns a new List which excludes this `index` and with a size 1 less
* than this List. Values at indices above `index` are shifted down by 1 to
* fill the position.
*
* This is synonymous with `list.splice(index, 1)`.
*
* `index` may be a negative number, which indexes back from the end of the
* List. `v.delete(-1)` deletes the last item in the List.
*
* Note: `delete` cannot be safely used in IE8
*
* <!-- runkit:activate
* { "preamble": "const { List } = require('immutable');" }
* -->
* ```js
* List([ 0, 1, 2, 3, 4 ]).delete(0);
* // List [ 1, 2, 3, 4 ]
* ```
*
* Since `delete()` re-indexes values, it produces a complete copy, which
* has `O(N)` complexity.
*
* Note: `delete` *cannot* be used in `withMutations`.
*
* @alias remove
*/
delete(index: number): List<T>;
remove(index: number): List<T>;
/**
* Returns a new List with `value` at `index` with a size 1 more than this
* List. Values at indices above `index` are shifted over by 1.
*
* This is synonymous with `list.splice(index, 0, value)`.
*
* <!-- runkit:activate
* { "preamble": "const { List } = require('immutable');" }
* -->
* ```js
* List([ 0, 1, 2, 3, 4 ]).insert(6, 5)
* // List [ 0, 1, 2, 3, 4, 5 ]
* ```
*
* Since `insert()` re-indexes values, it produces a complete copy, which
* has `O(N)` complexity.
*
* Note: `insert` *cannot* be used in `withMutations`.
*/
insert(index: number, value: T): List<T>;
/**
* Returns a new List with 0 size and no values in constant time.
*
* <!-- runkit:activate
* { "preamble": "const { List } = require('immutable');" }
* -->
* ```js
* List([ 1, 2, 3, 4 ]).clear()
* // List []
* ```
*
* Note: `clear` can be used in `withMutations`.
*/
clear(): List<T>;
/**
* Returns a new List with the provided `values` appended, starting at this
* List's `size`.
*
* <!-- runkit:activate
* { "preamble": "const { List } = require('immutable');" }
* -->
* ```js
* List([ 1, 2, 3, 4 ]).push(5)
* // List [ 1, 2, 3, 4, 5 ]
* ```
*
* Note: `push` can be used in `withMutations`.
*/
push(...values: Array<T>): List<T>;
/**
* Returns a new List with a size ones less than this List, excluding
* the last index in this List.
*
* Note: this differs from `Array#pop` because it returns a new
* List rather than the removed value. Use `last()` to get the last value
* in this List.
*
* ```js
* List([ 1, 2, 3, 4 ]).pop()
* // List[ 1, 2, 3 ]
* ```
*
* Note: `pop` can be used in `withMutations`.
*/
pop(): List<T>;
/**
* Returns a new List with the provided `values` prepended, shifting other
* values ahead to higher indices.
*
* <!-- runkit:activate
* { "preamble": "const { List } = require('immutable');" }
* -->
* ```js
* List([ 2, 3, 4]).unshift(1);
* // List [ 1, 2, 3, 4 ]
* ```
*
* Note: `unshift` can be used in `withMutations`.
*/
unshift(...values: Array<T>): List<T>;
/**
* Returns a new List with a size ones less than this List, excluding
* the first index in this List, shifting all other values to a lower index.
*
* Note: this differs from `Array#shift` because it returns a new
* List rather than the removed value. Use `first()` to get the first
* value in this List.
*
* <!-- runkit:activate
* { "preamble": "const { List } = require('immutable');" }
* -->
* ```js
* List([ 0, 1, 2, 3, 4 ]).shift();
* // List [ 1, 2, 3, 4 ]
* ```
*
* Note: `shift` can be used in `withMutations`.
*/
shift(): List<T>;
/**
* Returns a new List with an updated value at `index` with the return
* value of calling `updater` with the existing value, or `notSetValue` if
* `index` was not set. If called with a single argument, `updater` is
* called with the List itself.
*
* `index` may be a negative number, which indexes back from the end of the
* List. `v.update(-1)` updates the last item in the List.
*
* <!-- runkit:activate
* { "preamble": "const { List } = require('immutable');" }
* -->
* ```js
* const list = List([ 'a', 'b', 'c' ])
* const result = list.update(2, val => val.toUpperCase())
* // List [ "a", "b", "C" ]
* ```
*
* This can be very useful as a way to "chain" a normal function into a
* sequence of methods. RxJS calls this "let" and lodash calls it "thru".
*
* For example, to sum a List after mapping and filtering:
*
* <!-- runkit:activate
* { "preamble": "const { List } = require('immutable');" }
* -->
* ```js
* function sum(collection) {
* return collection.reduce((sum, x) => sum + x, 0)
* }
*
* List([ 1, 2, 3 ])
* .map(x => x + 1)
* .filter(x => x % 2 === 0)
* .update(sum)
* // 6
* ```
*
* Note: `update(index)` can be used in `withMutations`.
*
* @see `Map#update`
*/
update(index: number, notSetValue: T, updater: (value: T) => T): this;
update(
index: number,
updater: (value: T | undefined) => T | undefined
): this;
update<R>(updater: (value: this) => R): R;
/**
* Returns a new List with size `size`. If `size` is less than this
* List's size, the new List will exclude values at the higher indices.
* If `size` is greater than this List's size, the new List will have
* undefined values for the newly available indices.
*
* When building a new List and the final size is known up front, `setSize`
* used in conjunction with `withMutations` may result in the more
* performant construction.
*/
setSize(size: number): List<T>;
// Deep persistent changes
/**
* Returns a new List having set `value` at this `keyPath`. If any keys in
* `keyPath` do not exist, a new immutable Map will be created at that key.
*
* Index numbers are used as keys to determine the path to follow in
* the List.
*
* <!-- runkit:activate -->
* ```js
* const { List } = require('immutable')
* const list = List([ 0, 1, 2, List([ 3, 4 ])])
* list.setIn([3, 0], 999);
* // List [ 0, 1, 2, List [ 999, 4 ] ]
* ```
*
* Plain JavaScript Object or Arrays may be nested within an Immutable.js
* Collection, and setIn() can update those values as well, treating them
* immutably by creating new copies of those values with the changes applied.
*
* <!-- runkit:activate -->
* ```js
* const { List } = require('immutable')
* const list = List([ 0, 1, 2, { plain: 'object' }])
* list.setIn([3, 'plain'], 'value');
* // List([ 0, 1, 2, { plain: 'value' }])
* ```
*
* Note: `setIn` can be used in `withMutations`.
*/
setIn(keyPath: Iterable<unknown>, value: unknown): this;
/**
* Returns a new List having removed the value at this `keyPath`. If any
* keys in `keyPath` do not exist, no change will occur.
*
* <!-- runkit:activate -->
* ```js
* const { List } = require('immutable')
* const list = List([ 0, 1, 2, List([ 3, 4 ])])
* list.deleteIn([3, 0]);
* // List [ 0, 1, 2, List [ 4 ] ]
* ```
*
* Plain JavaScript Object or Arrays may be nested within an Immutable.js
* Collection, and removeIn() can update those values as well, treating them
* immutably by creating new copies of those values with the changes applied.
*
* <!-- runkit:activate -->
* ```js
* const { List } = require('immutable')
* const list = List([ 0, 1, 2, { plain: 'object' }])
* list.removeIn([3, 'plain']);
* // List([ 0, 1, 2, {}])
* ```
*
* Note: `deleteIn` *cannot* be safely used in `withMutations`.
*
* @alias removeIn
*/
deleteIn(keyPath: Iterable<unknown>): this;
removeIn(keyPath: Iterable<unknown>): this;
/**
* Note: `updateIn` can be used in `withMutations`.
*
* @see `Map#updateIn`
*/
updateIn(
keyPath: Iterable<unknown>,
notSetValue: unknown,
updater: (value: unknown) => unknown
): this;
updateIn(
keyPath: Iterable<unknown>,
updater: (value: unknown) => unknown
): this;
/**
* Note: `mergeIn` can be used in `withMutations`.
*
* @see `Map#mergeIn`
*/
mergeIn(keyPath: Iterable<unknown>, ...collections: Array<unknown>): this;
/**
* Note: `mergeDeepIn` can be used in `withMutations`.
*
* @see `Map#mergeDeepIn`
*/
mergeDeepIn(
keyPath: Iterable<unknown>,
...collections: Array<unknown>
): this;
// Transient changes
/**
* Note: Not all methods can be safely used on a mutable collection or within
* `withMutations`! Check the documentation for each method to see if it
* allows being used in `withMutations`.
*
* @see `Map#withMutations`
*/
withMutations(mutator: (mutable: this) => unknown): this;
/**
* An alternative API for withMutations()
*
* Note: Not all methods can be safely used on a mutable collection or within
* `withMutations`! Check the documentation for each method to see if it
* allows being used in `withMutations`.
*
* @see `Map#asMutable`
*/
asMutable(): this;
/**
* @see `Map#wasAltered`
*/
wasAltered(): boolean;
/**
* @see `Map#asImmutable`
*/
asImmutable(): this;
// Sequence algorithms
/**
* Returns a new List with other values or collections concatenated to this one.
*
* Note: `concat` can be used in `withMutations`.
*
* @alias merge
*/
concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): List<T | C>;
merge<C>(...collections: Array<Iterable<C>>): List<T | C>;
/**
* Returns a new List with values passed through a
* `mapper` function.
*
* <!-- runkit:activate
* { "preamble": "const { List } = require('immutable');" }
* -->
* ```js
* List([ 1, 2 ]).map(x => 10 * x)
* // List [ 10, 20 ]
* ```
*/
map<M>(
mapper: (value: T, key: number, iter: this) => M,
context?: unknown
): List<M>;
/**
* Flat-maps the List, returning a new List.
*
* Similar to `list.map(...).flatten(true)`.
*/
flatMap<M>(
mapper: (value: T, key: number, iter: this) => Iterable<M>,
context?: unknown
): List<M>;
/**
* Returns a new List with only the values for which the `predicate`
* function returns true.
*
* Note: `filter()` always returns a new instance, even if it results in
* not filtering out any values.
*/
filter<F extends T>(
predicate: (value: T, index: number, iter: this) => value is F,
context?: unknown
): List<F>;
filter(
predicate: (value: T, index: number, iter: this) => unknown,
context?: unknown
): this;
/**
* Returns a new List with the values for which the `predicate`
* function returns false and another for which is returns true.
*/
partition<F extends T, C>(
predicate: (this: C, value: T, index: number, iter: this) => value is F,
context?: C
): [List<T>, List<F>];
partition<C>(
predicate: (this: C, value: T, index: number, iter: this) => unknown,
context?: C
): [this, this];
/**
* Returns a List "zipped" with the provided collection.
*
* Like `zipWith`, but using the default `zipper`: creating an `Array`.
*
* <!-- runkit:activate
* { "preamble": "const { List } = require('immutable');" }
* -->
* ```js
* const a = List([ 1, 2, 3 ]);
* const b = List([ 4, 5, 6 ]);
* const c = a.zip(b); // List [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
* ```
*/
zip<U>(other: Collection<unknown, U>): List<[T, U]>;
zip<U, V>(
other: Collection<unknown, U>,
other2: Collection<unknown, V>
): List<[T, U, V]>;
zip(...collections: Array<Collection<unknown, unknown>>): List<unknown>;
/**
* Returns a List "zipped" with the provided collections.
*
* Unlike `zip`, `zipAll` continues zipping until the longest collection is
* exhausted. Missing values from shorter collections are filled with `undefined`.
*
* <!-- runkit:activate
* { "preamble": "const { List } = require('immutable');" }
* -->
* ```js
* const a = List([ 1, 2 ]);
* const b = List([ 3, 4, 5 ]);
* const c = a.zipAll(b); // List [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]
* ```
*
* Note: Since zipAll will return a collection as large as the largest
* input, some results may contain undefined values. TypeScript cannot
* account for these without cases (as of v2.5).
*/
zipAll<U>(other: Collection<unknown, U>): List<[T, U]>;
zipAll<U, V>(
other: Collection<unknown, U>,
other2: Collection<unknown, V>
): List<[T, U, V]>;
zipAll(...collections: Array<Collection<unknown, unknown>>): List<unknown>;
/**
* Returns a List "zipped" with the provided collections by using a
* custom `zipper` function.
*
* <!-- runkit:activate
* { "preamble": "const { List } = require('immutable');" }
* -->
* ```js
* const a = List([ 1, 2, 3 ]);
* const b = List([ 4, 5, 6 ]);
* const c = a.zipWith((a, b) => a + b, b);
* // List [ 5, 7, 9 ]
* ```
*/
zipWith<U, Z>(
zipper: (value: T, otherValue: U) => Z,
otherCollection: Collection<unknown, U>
): List<Z>;
zipWith<U, V, Z>(
zipper: (value: T, otherValue: U, thirdValue: V) => Z,
otherCollection: Collection<unknown, U>,
thirdCollection: Collection<unknown, V>
): List<Z>;
zipWith<Z>(
zipper: (...values: Array<unknown>) => Z,
...collections: Array<Collection<unknown, unknown>>
): List<Z>;
}
/**
* Immutable Map is an unordered Collection.Keyed of (key, value) pairs with
* `O(log32 N)` gets and `O(log32 N)` persistent sets.
*
* Iteration order of a Map is undefined, however is stable. Multiple
* iterations of the same Map will iterate in the same order.
*
* Map's keys can be of any type, and use `Immutable.is` to determine key
* equality. This allows the use of any value (including NaN) as a key.
*
* Because `Immutable.is` returns equality based on value semantics, and
* Immutable collections are treated as values, any Immutable collection may
* be used as a key.
*
* <!-- runkit:activate -->
* ```js
* const { Map, List } = require('immutable');
* Map().set(List([ 1 ]), 'listofone').get(List([ 1 ]));
* // 'listofone'
* ```
*
* Any JavaScript object may be used as a key, however strict identity is used
* to evaluate key equality. Two similar looking objects will represent two
* different keys.
*
* Implemented by a hash-array mapped trie.
*/
namespace Map {
/**
* True if the provided value is a Map
*
* <!-- runkit:activate -->
* ```js
* const { Map } = require('immutable')
* Map.isMap({}) // false
* Map.isMap(Map()) // true
* ```
*/
function isMap(maybeMap: unknown): maybeMap is Map<unknown, unknown>;
/**
* Creates a new Map from alternating keys and values
*
* <!-- runkit:activate -->
* ```js
* const { Map } = require('immutable')
* Map.of(
* 'key', 'value',
* 'numerical value', 3,
* 0, 'numerical key'
* )
* // Map { 0: "numerical key", "key": "value", "numerical value": 3 }
* ```
*
* @deprecated Use Map([ [ 'k', 'v' ] ]) or Map({ k: 'v' })
*/
function of(...keyValues: Array<unknown>): Map<unknown, unknown>;
}
/**
* Creates a new Immutable Map.
*
* Created with the same key value pairs as the provided Collection.Keyed or
* JavaScript Object or expects a Collection of [K, V] tuple entries.
*
* Note: `Map` is a factory function and not a class, and does not use the
* `new` keyword during construction.
*
* <!-- runkit:activate -->
* ```js
* const { Map } = require('immutable')
* Map({ key: "value" })
* Map([ [ "key", "value" ] ])
* ```
*
* Keep in mind, when using JS objects to construct Immutable Maps, that
* JavaScript Object properties are always strings, even if written in a
* quote-less shorthand, while Immutable Maps accept keys of any type.
*
* <!-- runkit:activate
* { "preamble": "const { Map } = require('immutable');" }
* -->
* ```js
* let obj = { 1: "one" }
* Object.keys(obj) // [ "1" ]
* assert.equal(obj["1"], obj[1]) // "one" === "one"
*
* let map = Map(obj)
* assert.notEqual(map.get("1"), map.get(1)) // "one" !== undefined
* ```
*
* Property access for JavaScript Objects first converts the key to a string,
* but since Immutable Map keys can be of any type the argument to `get()` is
* not altered.
*/
function Map<K, V>(collection?: Iterable<[K, V]>): Map<K, V>;
function Map<V>(obj: { [key: string]: V }): Map<string, V>;
function Map<K extends string | symbol, V>(obj: { [P in K]?: V }): Map<K, V>;
interface Map<K, V> extends Collection.Keyed<K, V> {
/**
* The number of entries in this Map.
*/
readonly size: number;
// Persistent changes
/**
* Returns a new Map also containing the new key, value pair. If an equivalent
* key already exists in this Map, it will be replaced.
*
* <!-- runkit:activate -->
* ```js
* const { Map } = require('immutable')
* const originalMap = Map()
* const newerMap = originalMap.set('key', 'value')
* const newestMap = newerMap.set('key', 'newer value')
*
* originalMap
* // Map {}
* newerMap
* // Map { "key": "value" }
* newestMap
* // Map { "key": "newer value" }
* ```
*
* Note: `set` can be used in `withMutations`.
*/
set(key: K, value: V): this;
/**
* Returns a new Map which excludes this `key`.
*
* Note: `delete` cannot be safely used in IE8, but is provided to mirror
* the ES6 collection API.
*
* <!-- runkit:activate -->
* ```js
* const { Map } = require('immutable')
* const originalMap = Map({
* key: 'value',
* otherKey: 'other value'
* })
* // Map { "key": "value", "otherKey": "other value" }
* originalMap.delete('otherKey')
* // Map { "key": "value" }
* ```
*
* Note: `delete` can be used in `withMutations`.
*
* @alias remove
*/
delete(key: K): this;
remove(key: K): this;
/**
* Returns a new Map which excludes the provided `keys`.
*
* <!-- runkit:activate -->
* ```js
* const { Map } = require('immutable')
* const names = Map({ a: "Aaron", b: "Barry", c: "Connor" })
* names.deleteAll([ 'a', 'c' ])
* // Map { "b": "Barry" }
* ```
*
* Note: `deleteAll` can be used in `withMutations`.
*
* @alias removeAll
*/
deleteAll(keys: Iterable<K>): this;
removeAll(keys: Iterable<K>): this;
/**
* Returns a new Map containing no keys or values.
*
* <!-- runkit:activate -->
* ```js
* const { Map } = require('immutable')
* Map({ key: 'value' }).clear()
* // Map {}
* ```
*
* Note: `clear` can be used in `withMutations`.
*/
clear(): this;
/**
* Returns a new Map having updated the value at this `key` with the return
* value of calling `updater` with the existing value.
*
* Similar to: `map.set(key, updater(map.get(key)))`.
*
* <!-- runkit:activate -->
* ```js
* const { Map } = require('immutable')
* const aMap = Map({ key: 'value' })
* const newMap = aMap.update('key', value => value + value)
* // Map { "key": "valuevalue" }
* ```
*
* This is most commonly used to call methods on collections within a
* structure of data. For example, in order to `.push()` onto a nested `List`,
* `update` and `push` can be used together:
*
* <!-- runkit:activate
* { "preamble": "const { Map, List } = require('immutable');" }
* -->
* ```js
* const aMap = Map({ nestedList: List([ 1, 2, 3 ]) })
* const newMap = aMap.update('nestedList', list => list.push(4))
* // Map { "nestedList": List [ 1, 2, 3, 4 ] }
* ```
*
* When a `notSetValue` is provided, it is provided to the `updater`
* function when the value at the key does not exist in the Map.
*
* <!-- runkit:activate
* { "preamble": "const { Map } = require('immutable');" }
* -->
* ```js
* const aMap = Map({ key: 'value' })
* const newMap = aMap.update('noKey', 'no value', value => value + value)
* // Map { "key": "value", "noKey": "no valueno value" }
* ```
*
* However, if the `updater` function returns the same value it was called
* with, then no change will occur. This is still true if `notSetValue`
* is provided.
*
* <!-- runkit:activate
* { "preamble": "const { Map } = require('immutable');" }
* -->
* ```js
* const aMap = Map({ apples: 10 })
* const newMap = aMap.update('oranges', 0, val => val)
* // Map { "apples": 10 }
* assert.strictEqual(newMap, map);
* ```
*
* For code using ES2015 or later, using `notSetValue` is discourged in
* favor of function parameter default values. This helps to avoid any
* potential confusion with identify functions as described above.
*
* The previous example behaves differently when written with default values:
*
* <!-- runkit:activate
* { "preamble": "const { Map } = require('immutable');" }
* -->
* ```js
* const aMap = Map({ apples: 10 })
* const newMap = aMap.update('oranges', (val = 0) => val)
* // Map { "apples": 10, "oranges": 0 }
* ```
*
* If no key is provided, then the `updater` function return value is
* returned as well.
*
* <!-- runkit:activate
* { "preamble": "const { Map } = require('immutable');" }
* -->
* ```js
* const aMap = Map({ key: 'value' })
* const result = aMap.update(aMap => aMap.get('key'))
* // "value"
* ```
*
* This can be very useful as a way to "chain" a normal function into a
* sequence of methods. RxJS calls this "let" and lodash calls it "thru".
*
* For example, to sum the values in a Map
*
* <!-- runkit:activate
* { "preamble": "const { Map } = require('immutable');" }
* -->
* ```js
* function sum(collection) {
* return collection.reduce((sum, x) => sum + x, 0)
* }
*
* Map({ x: 1, y: 2, z: 3 })
* .map(x => x + 1)
* .filter(x => x % 2 === 0)
* .update(sum)
* // 6
* ```
*
* Note: `update(key)` can be used in `withMutations`.
*/
update(key: K, notSetValue: V, updater: (value: V) => V): this;
update(key: K, updater: (value: V | undefined) => V | undefined): this;
update<R>(updater: (value: this) => R): R;
/**
* Returns a new Map resulting from merging the provided Collections
* (or JS objects) into this Map. In other words, this takes each entry of
* each collection and sets it on this Map.
*
* Note: Values provided to `merge` are shallowly converted before being
* merged. No nested values are altered.
*
* <!-- runkit:activate -->
* ```js
* const { Map } = require('immutable')
* const one = Map({ a: 10, b: 20, c: 30 })
* const two = Map({ b: 40, a: 50, d: 60 })
* one.merge(two) // Map { "a": 50, "b": 40, "c": 30, "d": 60 }
* two.merge(one) // Map { "b": 20, "a": 10, "d": 60, "c": 30 }
* ```
*
* Note: `merge` can be used in `withMutations`.
*
* @alias concat
*/
merge<KC, VC>(
...collections: Array<Iterable<[KC, VC]>>
): Map<K | KC, V | VC>;
merge<C>(
...collections: Array<{ [key: string]: C }>
): Map<K | string, V | C>;
concat<KC, VC>(
...collections: Array<Iterable<[KC, VC]>>
): Map<K | KC, V | VC>;
concat<C>(
...collections: Array<{ [key: string]: C }>
): Map<K | string, V | C>;
/**
* Like `merge()`, `mergeWith()` returns a new Map resulting from merging
* the provided Collections (or JS objects) into this Map, but uses the
* `merger` function for dealing with conflicts.
*
* <!-- runkit:activate -->
* ```js
* const { Map } = require('immutable')
* const one = Map({ a: 10, b: 20, c: 30 })
* const two = Map({ b: 40, a: 50, d: 60 })
* one.mergeWith((oldVal, newVal) => oldVal / newVal, two)
* // { "a": 0.2, "b": 0.5, "c": 30, "d": 60 }
* two.mergeWith((oldVal, newVal) => oldVal / newVal, one)
* // { "b": 2, "a": 5, "d": 60, "c": 30 }
* ```
*
* Note: `mergeWith` can be used in `withMutations`.
*/
mergeWith(
merger: (oldVal: V, newVal: V, key: K) => V,
...collections: Array<Iterable<[K, V]> | { [key: string]: V }>
): this;
/**
* Like `merge()`, but when two compatible collections are encountered with
* the same key, it merges them as well, recursing deeply through the nested
* data. Two collections are considered to be compatible (and thus will be
* merged together) if they both fall into one of three categories: keyed
* (e.g., `Map`s, `Record`s, and objects), indexed (e.g., `List`s and
* arrays), or set-like (e.g., `Set`s). If they fall into separate
* categories, `mergeDeep` will replace the existing collection with the
* collection being merged in. This behavior can be customized by using
* `mergeDeepWith()`.
*
* Note: Indexed and set-like collections are merged using
* `concat()`/`union()` and therefore do not recurse.
*
* <!-- runkit:activate -->
* ```js
* const { Map } = require('immutable')
* const one = Map({ a: Map({ x: 10, y: 10 }), b: Map({ x: 20, y: 50 }) })
* const two = Map({ a: Map({ x: 2 }), b: Map({ y: 5 }), c: Map({ z: 3 }) })
* one.mergeDeep(two)
* // Map {
* // "a": Map { "x": 2, "y": 10 },
* // "b": Map { "x": 20, "y": 5 },
* // "c": Map { "z": 3 }
* // }
* ```
*
* Note: `mergeDeep` can be used in `withMutations`.
*/
mergeDeep(
...collections: Array<Iterable<[K, V]> | { [key: string]: V }>
): this;
/**
* Like `mergeDeep()`, but when two non-collections or incompatible
* collections are encountered at the same key, it uses the `merger`
* function to determine the resulting value. Collections are considered
* incompatible if they fall into separate categories between keyed,
* indexed, and set-like.
*
* <!-- runkit:activate -->
* ```js
* const { Map } = require('immutable')
* const one = Map({ a: Map({ x: 10, y: 10 }), b: Map({ x: 20, y: 50 }) })
* const two = Map({ a: Map({ x: 2 }), b: Map({ y: 5 }), c: Map({ z: 3 }) })
* one.mergeDeepWith((oldVal, newVal) => oldVal / newVal, two)
* // Map {
* // "a": Map { "x": 5, "y": 10 },
* // "b": Map { "x": 20, "y": 10 },
* // "c": Map { "z": 3 }
* // }
* ```
*
* Note: `mergeDeepWith` can be used in `withMutations`.
*/
mergeDeepWith(
merger: (oldVal: unknown, newVal: unknown, key: unknown) => unknown,
...collections: Array<Iterable<[K, V]> | { [key: string]: V }>
): this;
// Deep persistent changes
/**
* Returns a new Map having set `value` at this `keyPath`. If any keys in
* `keyPath` do not exist, a new immutable Map will be created at that key.
*
* <!-- runkit:activate -->
* ```js
* const { Map } = require('immutable')
* const originalMap = Map({
* subObject: Map({
* subKey: 'subvalue',
* subSubObject: Map({
* subSubKey: 'subSubValue'
* })
* })
* })
*
* const newMap = originalMap.setIn(['subObject', 'subKey'], 'ha ha!')
* // Map {
* // "subObject": Map {
* // "subKey": "ha ha!",
* // "subSubObject": Map { "subSubKey": "subSubValue" }
* // }
* // }
*
* const newerMap = originalMap.setIn(
* ['subObject', 'subSubObject', 'subSubKey'],
* 'ha ha ha!'
* )
* // Map {
* // "subObject": Map {
* // "subKey": "subvalue",
* // "subSubObject": Map { "subSubKey": "ha ha ha!" }
* // }
* // }
* ```
*
* Plain JavaScript Object or Arrays may be nested within an Immutable.js
* Collection, and setIn() can update those values as well, treating them
* immutably by creating new copies of those values with the changes applied.
*
* <!-- runkit:activate -->
* ```js
* const { Map } = require('immutable')
* const originalMap = Map({
* subObject: {
* subKey: 'subvalue',
* subSubObject: {
* subSubKey: 'subSubValue'
* }
* }
* })
*
* originalMap.setIn(['subObject', 'subKey'], 'ha ha!')
* // Map {
* // "subObject": {
* // subKey: "ha ha!",
* // subSubObject: { subSubKey: "subSubValue" }
* // }
* // }
* ```
*
* If any key in the path exists but cannot be updated (such as a primitive
* like number or a custom Object like Date), an error will be thrown.
*
* Note: `setIn` can be used in `withMutations`.
*/
setIn(keyPath: Iterable<unknown>, value: unknown): this;
/**
* Returns a new Map having removed the value at this `keyPath`. If any keys
* in `keyPath` do not exist, no change will occur.
*
* Note: `deleteIn` can be used in `withMutations`.
*
* @alias removeIn
*/
deleteIn(keyPath: Iterable<unknown>): this;
removeIn(keyPath: Iterable<unknown>): this;
/**
* Returns a new Map having applied the `updater` to the entry found at the
* keyPath.
*
* This is most commonly used to call methods on collections nested within a
* structure of data. For example, in order to `.push()` onto a nested `List`,
* `updateIn` and `push` can be used together:
*
* <!-- runkit:activate -->
* ```js
* const { Map, List } = require('immutable')
* const map = Map({ inMap: Map({ inList: List([ 1, 2, 3 ]) }) })
* const newMap = map.updateIn(['inMap', 'inList'], list => list.push(4))
* // Map { "inMap": Map { "inList": List [ 1, 2, 3, 4 ] } }
* ```
*
* If any keys in `keyPath` do not exist, new Immutable `Map`s will
* be created at those keys. If the `keyPath` does not already contain a
* value, the `updater` function will be called with `notSetValue`, if
* provided, otherwise `undefined`.
*
* <!-- runkit:activate
* { "preamble": "const { Map } = require('immutable')" }
* -->
* ```js
* const map = Map({ a: Map({ b: Map({ c: 10 }) }) })
* const newMap = map.updateIn(['a', 'b', 'c'], val => val * 2)
* // Map { "a": Map { "b": Map { "c": 20 } } }
* ```
*
* If the `updater` function returns the same value it was called with, then
* no change will occur. This is still true if `notSetValue` is provided.
*
* <!-- runkit:activate
* { "preamble": "const { Map } = require('immutable')" }
* -->
* ```js
* const map = Map({ a: Map({ b: Map({ c: 10 }) }) })
* const newMap = map.updateIn(['a', 'b', 'x'], 100, val => val)
* // Map { "a": Map { "b": Map { "c": 10 } } }
* assert.strictEqual(newMap, aMap)
* ```
*
* For code using ES2015 or later, using `notSetValue` is discourged in
* favor of function parameter default values. This helps to avoid any
* potential confusion with identify functions as described above.
*
* The previous example behaves differently when written with default values:
*
* <!-- runkit:activate
* { "preamble": "const { Map } = require('immutable')" }
* -->
* ```js
* const map = Map({ a: Map({ b: Map({ c: 10 }) }) })
* const newMap = map.updateIn(['a', 'b', 'x'], (val = 100) => val)
* // Map { "a": Map { "b": Map { "c": 10, "x": 100 } } }
* ```
*
* Plain JavaScript Object or Arrays may be nested within an Immutable.js
* Collection, and updateIn() can update those values as well, treating them
* immutably by creating new copies of those values with the changes applied.
*
* <!-- runkit:activate
* { "preamble": "const { Map } = require('immutable')" }
* -->
* ```js
* const map = Map({ a: { b: { c: 10 } } })
* const newMap = map.updateIn(['a', 'b', 'c'], val => val * 2)
* // Map { "a": { b: { c: 20 } } }
* ```
*
* If any key in the path exists but cannot be updated (such as a primitive
* like number or a custom Object like Date), an error will be thrown.
*
* Note: `updateIn` can be used in `withMutations`.
*/
updateIn(
keyPath: Iterable<unknown>,
notSetValue: unknown,
updater: (value: unknown) => unknown
): this;
updateIn(
keyPath: Iterable<unknown>,
updater: (value: unknown) => unknown
): this;
/**
* A combination of `updateIn` and `merge`, returning a new Map, but
* performing the merge at a point arrived at by following the keyPath.
* In other words, these two lines are equivalent:
*
* ```js
* map.updateIn(['a', 'b', 'c'], abc => abc.merge(y))
* map.mergeIn(['a', 'b', 'c'], y)
* ```
*
* Note: `mergeIn` can be used in `withMutations`.
*/
mergeIn(keyPath: Iterable<unknown>, ...collections: Array<unknown>): this;
/**
* A combination of `updateIn` and `mergeDeep`, returning a new Map, but
* performing the deep merge at a point arrived at by following the keyPath.
* In other words, these two lines are equivalent:
*
* ```js
* map.updateIn(['a', 'b', 'c'], abc => abc.mergeDeep(y))
* map.mergeDeepIn(['a', 'b', 'c'], y)
* ```
*
* Note: `mergeDeepIn` can be used in `withMutations`.
*/
mergeDeepIn(
keyPath: Iterable<unknown>,
...collections: Array<unknown>
): this;
// Transient changes
/**
* Every time you call one of the above functions, a new immutable Map is
* created. If a pure function calls a number of these to produce a final
* return value, then a penalty on performance and memory has been paid by
* creating all of the intermediate immutable Maps.
*
* If you need to apply a series of mutations to produce a new immutable
* Map, `withMutations()` creates a temporary mutable copy of the Map which
* can apply mutations in a highly performant manner. In fact, this is
* exactly how complex mutations like `merge` are done.
*
* As an example, this results in the creation of 2, not 4, new Maps:
*
* <!-- runkit:activate -->
* ```js
* const { Map } = require('immutable')
* const map1 = Map()
* const map2 = map1.withMutations(map => {
* map.set('a', 1).set('b', 2).set('c', 3)
* })
* assert.equal(map1.size, 0)
* assert.equal(map2.size, 3)
* ```
*
* Note: Not all methods can be used on a mutable collection or within
* `withMutations`! Read the documentation for each method to see if it
* is safe to use in `withMutations`.
*/
withMutations(mutator: (mutable: this) => unknown): this;
/**
* Another way to avoid creation of intermediate Immutable maps is to create
* a mutable copy of this collection. Mutable copies *always* return `this`,
* and thus shouldn't be used for equality. Your function should never return
* a mutable copy of a collection, only use it internally to create a new
* collection.
*
* If possible, use `withMutations` to work with temporary mutable copies as
* it provides an easier to use API and considers many common optimizations.
*
* Note: if the collection is already mutable, `asMutable` returns itself.
*
* Note: Not all methods can be used on a mutable collection or within
* `withMutations`! Read the documentation for each method to see if it
* is safe to use in `withMutations`.
*
* @see `Map#asImmutable`
*/
asMutable(): this;
/**
* Returns true if this is a mutable copy (see `asMutable()`) and mutative
* alterations have been applied.
*
* @see `Map#asMutable`
*/
wasAltered(): boolean;
/**
* The yin to `asMutable`'s yang. Because it applies to mutable collections,
* this operation is *mutable* and may return itself (though may not
* return itself, i.e. if the result is an empty collection). Once
* performed, the original mutable copy must no longer be mutated since it
* may be the immutable result.
*
* If possible, use `withMutations` to work with temporary mutable copies as
* it provides an easier to use API and considers many common optimizations.
*
* @see `Map#asMutable`
*/
asImmutable(): this;
// Sequence algorithms
/**
* Returns a new Map with values passed through a
* `mapper` function.
*
* Map({ a: 1, b: 2 }).map(x => 10 * x)
* // Map { a: 10, b: 20 }
*/
map<M>(
mapper: (value: V, key: K, iter: this) => M,
context?: unknown
): Map<K, M>;
/**
* @see Collection.Keyed.mapKeys
*/
mapKeys<M>(
mapper: (key: K, value: V, iter: this) => M,
context?: unknown
): Map<M, V>;
/**
* @see Collection.Keyed.mapEntries
*/
mapEntries<KM, VM>(
mapper: (
entry: [K, V],
index: number,
iter: this
) => [KM, VM] | undefined,
context?: unknown
): Map<KM, VM>;
/**
* Flat-maps the Map, returning a new Map.
*
* Similar to `data.map(...).flatten(true)`.
*/
flatMap<KM, VM>(
mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>,
context?: unknown
): Map<KM, VM>;
/**
* Returns a new Map with only the entries for which the `predicate`
* function returns true.
*
* Note: `filter()` always returns a new instance, even if it results in
* not filtering out any values.
*/
filter<F extends V>(
predicate: (value: V, key: K, iter: this) => value is F,
context?: unknown
): Map<K, F>;
filter(
predicate: (value: V, key: K, iter: this) => unknown,
context?: unknown
): this;
/**
* Returns a new Map with the values for which the `predicate`
* function returns false and another for which is returns true.
*/
partition<F extends V, C>(
predicate: (this: C, value: V, key: K, iter: this) => value is F,
context?: C
): [Map<K, V>, Map<K, F>];
partition<C>(
predicate: (this: C, value: V, key: K, iter: this) => unknown,
context?: C
): [this, this];
/**
* @see Collection.Keyed.flip
*/
flip(): Map<V, K>;
}
/**
* A type of Map that has the additional guarantee that the iteration order of
* entries will be the order in which they were set().
*
* The iteration behavior of OrderedMap is the same as native ES6 Map and
* JavaScript Object.
*
* Note that `OrderedMap` are more expensive than non-ordered `Map` and may
* consume more memory. `OrderedMap#set` is amortized O(log32 N), but not
* stable.
*/
namespace OrderedMap {
/**
* True if the provided value is an OrderedMap.
*/
function isOrderedMap(
maybeOrderedMap: unknown
): maybeOrderedMap is OrderedMap<unknown, unknown>;
}
/**
* Creates a new Immutable OrderedMap.
*
* Created with the same key value pairs as the provided Collection.Keyed or
* JavaScript Object or expects a Collection of [K, V] tuple entries.
*
* The iteration order of key-value pairs provided to this constructor will
* be preserved in the OrderedMap.
*
* let newOrderedMap = OrderedMap({key: "value"})
* let newOrderedMap = OrderedMap([["key", "value"]])
*
* Note: `OrderedMap` is a factory function and not a class, and does not use
* the `new` keyword during construction.
*/
function OrderedMap<K, V>(collection?: Iterable<[K, V]>): OrderedMap<K, V>;
function OrderedMap<V>(obj: { [key: string]: V }): OrderedMap<string, V>;
interface OrderedMap<K, V> extends Map<K, V> {
/**
* The number of entries in this OrderedMap.
*/
readonly size: number;
/**
* Returns a new OrderedMap also containing the new key, value pair. If an
* equivalent key already exists in this OrderedMap, it will be replaced
* while maintaining the existing order.
*
* <!-- runkit:activate -->
* ```js
* const { OrderedMap } = require('immutable')
* const originalMap = OrderedMap({a:1, b:1, c:1})
* const updatedMap = originalMap.set('b', 2)
*
* originalMap
* // OrderedMap {a: 1, b: 1, c: 1}
* updatedMap
* // OrderedMap {a: 1, b: 2, c: 1}
* ```
*
* Note: `set` can be used in `withMutations`.
*/
set(key: K, value: V): this;
/**
* Returns a new OrderedMap resulting from merging the provided Collections
* (or JS objects) into this OrderedMap. In other words, this takes each
* entry of each collection and sets it on this OrderedMap.
*
* Note: Values provided to `merge` are shallowly converted before being
* merged. No nested values are altered.
*
* <!-- runkit:activate -->
* ```js
* const { OrderedMap } = require('immutable')
* const one = OrderedMap({ a: 10, b: 20, c: 30 })
* const two = OrderedMap({ b: 40, a: 50, d: 60 })
* one.merge(two) // OrderedMap { "a": 50, "b": 40, "c": 30, "d": 60 }
* two.merge(one) // OrderedMap { "b": 20, "a": 10, "d": 60, "c": 30 }
* ```
*
* Note: `merge` can be used in `withMutations`.
*
* @alias concat
*/
merge<KC, VC>(
...collections: Array<Iterable<[KC, VC]>>
): OrderedMap<K | KC, V | VC>;
merge<C>(
...collections: Array<{ [key: string]: C }>
): OrderedMap<K | string, V | C>;
concat<KC, VC>(
...collections: Array<Iterable<[KC, VC]>>
): OrderedMap<K | KC, V | VC>;
concat<C>(
...collections: Array<{ [key: string]: C }>
): OrderedMap<K | string, V | C>;
// Sequence algorithms
/**
* Returns a new OrderedMap with values passed through a
* `mapper` function.
*
* OrderedMap({ a: 1, b: 2 }).map(x => 10 * x)
* // OrderedMap { "a": 10, "b": 20 }
*
* Note: `map()` always returns a new instance, even if it produced the same
* value at every step.
*/
map<M>(
mapper: (value: V, key: K, iter: this) => M,
context?: unknown
): OrderedMap<K, M>;
/**
* @see Collection.Keyed.mapKeys
*/
mapKeys<M>(
mapper: (key: K, value: V, iter: this) => M,
context?: unknown
): OrderedMap<M, V>;
/**
* @see Collection.Keyed.mapEntries
*/
mapEntries<KM, VM>(
mapper: (
entry: [K, V],
index: number,
iter: this
) => [KM, VM] | undefined,
context?: unknown
): OrderedMap<KM, VM>;
/**
* Flat-maps the OrderedMap, returning a new OrderedMap.
*
* Similar to `data.map(...).flatten(true)`.
*/
flatMap<KM, VM>(
mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>,
context?: unknown
): OrderedMap<KM, VM>;
/**
* Returns a new OrderedMap with only the entries for which the `predicate`
* function returns true.
*
* Note: `filter()` always returns a new instance, even if it results in
* not filtering out any values.
*/
filter<F extends V>(
predicate: (value: V, key: K, iter: this) => value is F,
context?: unknown
): OrderedMap<K, F>;
filter(
predicate: (value: V, key: K, iter: this) => unknown,
context?: unknown
): this;
/**
* Returns a new OrderedMap with the values for which the `predicate`
* function returns false and another for which is returns true.
*/
partition<F extends V, C>(
predicate: (this: C, value: V, key: K, iter: this) => value is F,
context?: C
): [OrderedMap<K, V>, OrderedMap<K, F>];
partition<C>(
predicate: (this: C, value: V, key: K, iter: this) => unknown,
context?: C
): [this, this];
/**
* @see Collection.Keyed.flip
*/
flip(): OrderedMap<V, K>;
}
/**
* A Collection of unique values with `O(log32 N)` adds and has.
*
* When iterating a Set, the entries will be (value, value) pairs. Iteration
* order of a Set is undefined, however is stable. Multiple iterations of the
* same Set will iterate in the same order.
*
* Set values, like Map keys, may be of any type. Equality is determined using
* `Immutable.is`, enabling Sets to uniquely include other Immutable
* collections, custom value types, and NaN.
*/
namespace Set {
/**
* True if the provided value is a Set
*/
function isSet(maybeSet: unknown): maybeSet is Set<unknown>;
/**
* Creates a new Set containing `values`.
*/
function of<T>(...values: Array<T>): Set<T>;
/**
* `Set.fromKeys()` creates a new immutable Set containing the keys from
* this Collection or JavaScript Object.
*/
function fromKeys<T>(iter: Collection<T, unknown>): Set<T>;
function fromKeys(obj: { [key: string]: unknown }): Set<string>;
/**
* `Set.intersect()` creates a new immutable Set that is the intersection of
* a collection of other sets.
*
* ```js
* const { Set } = require('immutable')
* const intersected = Set.intersect([
* Set([ 'a', 'b', 'c' ])
* Set([ 'c', 'a', 't' ])
* ])
* // Set [ "a", "c" ]
* ```
*/
function intersect<T>(sets: Iterable<Iterable<T>>): Set<T>;
/**
* `Set.union()` creates a new immutable Set that is the union of a
* collection of other sets.
*
* ```js
* const { Set } = require('immutable')
* const unioned = Set.union([
* Set([ 'a', 'b', 'c' ])
* Set([ 'c', 'a', 't' ])
* ])
* // Set [ "a", "b", "c", "t" ]
* ```
*/
function union<T>(sets: Iterable<Iterable<T>>): Set<T>;
}
/**
* Create a new immutable Set containing the values of the provided
* collection-like.
*
* Note: `Set` is a factory function and not a class, and does not use the
* `new` keyword during construction.
*/
function Set<T>(collection?: Iterable<T> | ArrayLike<T>): Set<T>;
interface Set<T> extends Collection.Set<T> {
/**
* The number of items in this Set.
*/
readonly size: number;
// Persistent changes
/**
* Returns a new Set which also includes this value.
*
* Note: `add` can be used in `withMutations`.
*/
add(value: T): this;
/**
* Returns a new Set which excludes this value.
*
* Note: `delete` can be used in `withMutations`.
*
* Note: `delete` **cannot** be safely used in IE8, use `remove` if
* supporting old browsers.
*
* @alias remove
*/
delete(value: T): this;
remove(value: T): this;
/**
* Returns a new Set containing no values.
*
* Note: `clear` can be used in `withMutations`.
*/
clear(): this;
/**
* Returns a Set including any value from `collections` that does not already
* exist in this Set.
*
* Note: `union` can be used in `withMutations`.
* @alias merge
* @alias concat
*/
union<C>(...collections: Array<Iterable<C>>): Set<T | C>;
merge<C>(...collections: Array<Iterable<C>>): Set<T | C>;
concat<C>(...collections: Array<Iterable<C>>): Set<T | C>;
/**
* Returns a Set which has removed any values not also contained
* within `collections`.
*
* Note: `intersect` can be used in `withMutations`.
*/
intersect(...collections: Array<Iterable<T>>): this;
/**
* Returns a Set excluding any values contained within `collections`.
*
* <!-- runkit:activate -->
* ```js
* const { OrderedSet } = require('immutable')
* OrderedSet([ 1, 2, 3 ]).subtract([1, 3])
* // OrderedSet [2]
* ```
*
* Note: `subtract` can be used in `withMutations`.
*/
subtract(...collections: Array<Iterable<T>>): this;
// Transient changes
/**
* Note: Not all methods can be used on a mutable collection or within
* `withMutations`! Check the documentation for each method to see if it
* mentions being safe to use in `withMutations`.
*
* @see `Map#withMutations`
*/
withMutations(mutator: (mutable: this) => unknown): this;
/**
* Note: Not all methods can be used on a mutable collection or within
* `withMutations`! Check the documentation for each method to see if it
* mentions being safe to use in `withMutations`.
*
* @see `Map#asMutable`
*/
asMutable(): this;
/**
* @see `Map#wasAltered`
*/
wasAltered(): boolean;
/**
* @see `Map#asImmutable`
*/
asImmutable(): this;
// Sequence algorithms
/**
* Returns a new Set with values passed through a
* `mapper` function.
*
* Set([1,2]).map(x => 10 * x)
* // Set [10,20]
*/
map<M>(
mapper: (value: T, key: T, iter: this) => M,
context?: unknown
): Set<M>;
/**
* Flat-maps the Set, returning a new Set.
*
* Similar to `set.map(...).flatten(true)`.
*/
flatMap<M>(
mapper: (value: T, key: T, iter: this) => Iterable<M>,
context?: unknown
): Set<M>;
/**
* Returns a new Set with only the values for which the `predicate`
* function returns true.
*
* Note: `filter()` always returns a new instance, even if it results in
* not filtering out any values.
*/
filter<F extends T>(
predicate: (value: T, key: T, iter: this) => value is F,
context?: unknown
): Set<F>;
filter(
predicate: (value: T, key: T, iter: this) => unknown,
context?: unknown
): this;
/**
* Returns a new Set with the values for which the `predicate` function
* returns false and another for which is returns true.
*/
partition<F extends T, C>(
predicate: (this: C, value: T, key: T, iter: this) => value is F,
context?: C
): [Set<T>, Set<F>];
partition<C>(
predicate: (this: C, value: T, key: T, iter: this) => unknown,
context?: C
): [this, this];
}
/**
* A type of Set that has the additional guarantee that the iteration order of
* values will be the order in which they were `add`ed.
*
* The iteration behavior of OrderedSet is the same as native ES6 Set.
*
* Note that `OrderedSet` are more expensive than non-ordered `Set` and may
* consume more memory. `OrderedSet#add` is amortized O(log32 N), but not
* stable.
*/
namespace OrderedSet {
/**
* True if the provided value is an OrderedSet.
*/
function isOrderedSet(maybeOrderedSet: unknown): boolean;
/**
* Creates a new OrderedSet containing `values`.
*/
function of<T>(...values: Array<T>): OrderedSet<T>;
/**
* `OrderedSet.fromKeys()` creates a new immutable OrderedSet containing
* the keys from this Collection or JavaScript Object.
*/
function fromKeys<T>(iter: Collection<T, unknown>): OrderedSet<T>;
function fromKeys(obj: { [key: string]: unknown }): OrderedSet<string>;
}
/**
* Create a new immutable OrderedSet containing the values of the provided
* collection-like.
*
* Note: `OrderedSet` is a factory function and not a class, and does not use
* the `new` keyword during construction.
*/
function OrderedSet<T>(
collection?: Iterable<T> | ArrayLike<T>
): OrderedSet<T>;
interface OrderedSet<T> extends Set<T> {
/**
* The number of items in this OrderedSet.
*/
readonly size: number;
/**
* Returns an OrderedSet including any value from `collections` that does
* not already exist in this OrderedSet.
*
* Note: `union` can be used in `withMutations`.
* @alias merge
* @alias concat
*/
union<C>(...collections: Array<Iterable<C>>): OrderedSet<T | C>;
merge<C>(...collections: Array<Iterable<C>>): OrderedSet<T | C>;
concat<C>(...collections: Array<Iterable<C>>): OrderedSet<T | C>;
// Sequence algorithms
/**
* Returns a new Set with values passed through a
* `mapper` function.
*
* OrderedSet([ 1, 2 ]).map(x => 10 * x)
* // OrderedSet [10, 20]
*/
map<M>(
mapper: (value: T, key: T, iter: this) => M,
context?: unknown
): OrderedSet<M>;
/**
* Flat-maps the OrderedSet, returning a new OrderedSet.
*
* Similar to `set.map(...).flatten(true)`.
*/
flatMap<M>(
mapper: (value: T, key: T, iter: this) => Iterable<M>,
context?: unknown
): OrderedSet<M>;
/**
* Returns a new OrderedSet with only the values for which the `predicate`
* function returns true.
*
* Note: `filter()` always returns a new instance, even if it results in
* not filtering out any values.
*/
filter<F extends T>(
predicate: (value: T, key: T, iter: this) => value is F,
context?: unknown
): OrderedSet<F>;
filter(
predicate: (value: T, key: T, iter: this) => unknown,
context?: unknown
): this;
/**
* Returns a new OrderedSet with the values for which the `predicate`
* function returns false and another for which is returns true.
*/
partition<F extends T, C>(
predicate: (this: C, value: T, key: T, iter: this) => value is F,
context?: C
): [OrderedSet<T>, OrderedSet<F>];
partition<C>(
predicate: (this: C, value: T, key: T, iter: this) => unknown,
context?: C
): [this, this];
/**
* Returns an OrderedSet of the same type "zipped" with the provided
* collections.
*
* Like `zipWith`, but using the default `zipper`: creating an `Array`.
*
* ```js
* const a = OrderedSet([ 1, 2, 3 ])
* const b = OrderedSet([ 4, 5, 6 ])
* const c = a.zip(b)
* // OrderedSet [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
* ```
*/
zip<U>(other: Collection<unknown, U>): OrderedSet<[T, U]>;
zip<U, V>(
other1: Collection<unknown, U>,
other2: Collection<unknown, V>
): OrderedSet<[T, U, V]>;
zip(
...collections: Array<Collection<unknown, unknown>>
): OrderedSet<unknown>;
/**
* Returns a OrderedSet of the same type "zipped" with the provided
* collections.
*
* Unlike `zip`, `zipAll` continues zipping until the longest collection is
* exhausted. Missing values from shorter collections are filled with `undefined`.
*
* ```js
* const a = OrderedSet([ 1, 2 ]);
* const b = OrderedSet([ 3, 4, 5 ]);
* const c = a.zipAll(b); // OrderedSet [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]
* ```
*
* Note: Since zipAll will return a collection as large as the largest
* input, some results may contain undefined values. TypeScript cannot
* account for these without cases (as of v2.5).
*/
zipAll<U>(other: Collection<unknown, U>): OrderedSet<[T, U]>;
zipAll<U, V>(
other1: Collection<unknown, U>,
other2: Collection<unknown, V>
): OrderedSet<[T, U, V]>;
zipAll(
...collections: Array<Collection<unknown, unknown>>
): OrderedSet<unknown>;
/**
* Returns an OrderedSet of the same type "zipped" with the provided
* collections by using a custom `zipper` function.
*
* @see Seq.Indexed.zipWith
*/
zipWith<U, Z>(
zipper: (value: T, otherValue: U) => Z,
otherCollection: Collection<unknown, U>
): OrderedSet<Z>;
zipWith<U, V, Z>(
zipper: (value: T, otherValue: U, thirdValue: V) => Z,
otherCollection: Collection<unknown, U>,
thirdCollection: Collection<unknown, V>
): OrderedSet<Z>;
zipWith<Z>(
zipper: (...values: Array<unknown>) => Z,
...collections: Array<Collection<unknown, unknown>>
): OrderedSet<Z>;
}
/**
* Stacks are indexed collections which support very efficient O(1) addition
* and removal from the front using `unshift(v)` and `shift()`.
*
* For familiarity, Stack also provides `push(v)`, `pop()`, and `peek()`, but
* be aware that they also operate on the front of the list, unlike List or
* a JavaScript Array.
*
* Note: `reverse()` or any inherent reverse traversal (`reduceRight`,
* `lastIndexOf`, etc.) is not efficient with a Stack.
*
* Stack is implemented with a Single-Linked List.
*/
namespace Stack {
/**
* True if the provided value is a Stack
*/
function isStack(maybeStack: unknown): maybeStack is Stack<unknown>;
/**
* Creates a new Stack containing `values`.
*/
function of<T>(...values: Array<T>): Stack<T>;
}
/**
* Create a new immutable Stack containing the values of the provided
* collection-like.
*
* The iteration order of the provided collection is preserved in the
* resulting `Stack`.
*
* Note: `Stack` is a factory function and not a class, and does not use the
* `new` keyword during construction.
*/
function Stack<T>(collection?: Iterable<T> | ArrayLike<T>): Stack<T>;
interface Stack<T> extends Collection.Indexed<T> {
/**
* The number of items in this Stack.
*/
readonly size: number;
// Reading values
/**
* Alias for `Stack.first()`.
*/
peek(): T | undefined;
// Persistent changes
/**
* Returns a new Stack with 0 size and no values.
*
* Note: `clear` can be used in `withMutations`.
*/
clear(): Stack<T>;
/**
* Returns a new Stack with the provided `values` prepended, shifting other
* values ahead to higher indices.
*
* This is very efficient for Stack.
*
* Note: `unshift` can be used in `withMutations`.
*/
unshift(...values: Array<T>): Stack<T>;
/**
* Like `Stack#unshift`, but accepts a collection rather than varargs.
*
* Note: `unshiftAll` can be used in `withMutations`.
*/
unshiftAll(iter: Iterable<T>): Stack<T>;
/**
* Returns a new Stack with a size ones less than this Stack, excluding
* the first item in this Stack, shifting all other values to a lower index.
*
* Note: this differs from `Array#shift` because it returns a new
* Stack rather than the removed value. Use `first()` or `peek()` to get the
* first value in this Stack.
*
* Note: `shift` can be used in `withMutations`.
*/
shift(): Stack<T>;
/**
* Alias for `Stack#unshift` and is not equivalent to `List#push`.
*/
push(...values: Array<T>): Stack<T>;
/**
* Alias for `Stack#unshiftAll`.
*/
pushAll(iter: Iterable<T>): Stack<T>;
/**
* Alias for `Stack#shift` and is not equivalent to `List#pop`.
*/
pop(): Stack<T>;
// Transient changes
/**
* Note: Not all methods can be used on a mutable collection or within
* `withMutations`! Check the documentation for each method to see if it
* mentions being safe to use in `withMutations`.
*
* @see `Map#withMutations`
*/
withMutations(mutator: (mutable: this) => unknown): this;
/**
* Note: Not all methods can be used on a mutable collection or within
* `withMutations`! Check the documentation for each method to see if it
* mentions being safe to use in `withMutations`.
*
* @see `Map#asMutable`
*/
asMutable(): this;
/**
* @see `Map#wasAltered`
*/
wasAltered(): boolean;
/**
* @see `Map#asImmutable`
*/
asImmutable(): this;
// Sequence algorithms
/**
* Returns a new Stack with other collections concatenated to this one.
*/
concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): Stack<T | C>;
/**
* Returns a new Stack with values passed through a
* `mapper` function.
*
* Stack([ 1, 2 ]).map(x => 10 * x)
* // Stack [ 10, 20 ]
*
* Note: `map()` always returns a new instance, even if it produced the same
* value at every step.
*/
map<M>(
mapper: (value: T, key: number, iter: this) => M,
context?: unknown
): Stack<M>;
/**
* Flat-maps the Stack, returning a new Stack.
*
* Similar to `stack.map(...).flatten(true)`.
*/
flatMap<M>(
mapper: (value: T, key: number, iter: this) => Iterable<M>,
context?: unknown
): Stack<M>;
/**
* Returns a new Set with only the values for which the `predicate`
* function returns true.
*
* Note: `filter()` always returns a new instance, even if it results in
* not filtering out any values.
*/
filter<F extends T>(
predicate: (value: T, index: number, iter: this) => value is F,
context?: unknown
): Set<F>;
filter(
predicate: (value: T, index: number, iter: this) => unknown,
context?: unknown
): this;
/**
* Returns a Stack "zipped" with the provided collections.
*
* Like `zipWith`, but using the default `zipper`: creating an `Array`.
*
* ```js
* const a = Stack([ 1, 2, 3 ]);
* const b = Stack([ 4, 5, 6 ]);
* const c = a.zip(b); // Stack [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
* ```
*/
zip<U>(other: Collection<unknown, U>): Stack<[T, U]>;
zip<U, V>(
other: Collection<unknown, U>,
other2: Collection<unknown, V>
): Stack<[T, U, V]>;
zip(...collections: Array<Collection<unknown, unknown>>): Stack<unknown>;
/**
* Returns a Stack "zipped" with the provided collections.
*
* Unlike `zip`, `zipAll` continues zipping until the longest collection is
* exhausted. Missing values from shorter collections are filled with `undefined`.
*
* ```js
* const a = Stack([ 1, 2 ]);
* const b = Stack([ 3, 4, 5 ]);
* const c = a.zipAll(b); // Stack [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]
* ```
*
* Note: Since zipAll will return a collection as large as the largest
* input, some results may contain undefined values. TypeScript cannot
* account for these without cases (as of v2.5).
*/
zipAll<U>(other: Collection<unknown, U>): Stack<[T, U]>;
zipAll<U, V>(
other: Collection<unknown, U>,
other2: Collection<unknown, V>
): Stack<[T, U, V]>;
zipAll(...collections: Array<Collection<unknown, unknown>>): Stack<unknown>;
/**
* Returns a Stack "zipped" with the provided collections by using a
* custom `zipper` function.
*
* ```js
* const a = Stack([ 1, 2, 3 ]);
* const b = Stack([ 4, 5, 6 ]);
* const c = a.zipWith((a, b) => a + b, b);
* // Stack [ 5, 7, 9 ]
* ```
*/
zipWith<U, Z>(
zipper: (value: T, otherValue: U) => Z,
otherCollection: Collection<unknown, U>
): Stack<Z>;
zipWith<U, V, Z>(
zipper: (value: T, otherValue: U, thirdValue: V) => Z,
otherCollection: Collection<unknown, U>,
thirdCollection: Collection<unknown, V>
): Stack<Z>;
zipWith<Z>(
zipper: (...values: Array<unknown>) => Z,
...collections: Array<Collection<unknown, unknown>>
): Stack<Z>;
}
/**
* Returns a Seq.Indexed of numbers from `start` (inclusive) to `end`
* (exclusive), by `step`, where `start` defaults to 0, `step` to 1, and `end` to
* infinity. When `start` is equal to `end`, returns empty range.
*
* Note: `Range` is a factory function and not a class, and does not use the
* `new` keyword during construction.
*
* ```js
* const { Range } = require('immutable')
* Range() // [ 0, 1, 2, 3, ... ]
* Range(10) // [ 10, 11, 12, 13, ... ]
* Range(10, 15) // [ 10, 11, 12, 13, 14 ]
* Range(10, 30, 5) // [ 10, 15, 20, 25 ]
* Range(30, 10, 5) // [ 30, 25, 20, 15 ]
* Range(30, 30, 5) // []
* ```
*/
function Range(
start?: number,
end?: number,
step?: number
): Seq.Indexed<number>;
/**
* Returns a Seq.Indexed of `value` repeated `times` times. When `times` is
* not defined, returns an infinite `Seq` of `value`.
*
* Note: `Repeat` is a factory function and not a class, and does not use the
* `new` keyword during construction.
*
* ```js
* const { Repeat } = require('immutable')
* Repeat('foo') // [ 'foo', 'foo', 'foo', ... ]
* Repeat('bar', 4) // [ 'bar', 'bar', 'bar', 'bar' ]
* ```
*/
function Repeat<T>(value: T, times?: number): Seq.Indexed<T>;
/**
* A record is similar to a JS object, but enforces a specific set of allowed
* string keys, and has default values.
*
* The `Record()` function produces new Record Factories, which when called
* create Record instances.
*
* ```js
* const { Record } = require('immutable')
* const ABRecord = Record({ a: 1, b: 2 })
* const myRecord = ABRecord({ b: 3 })
* ```
*
* Records always have a value for the keys they define. `remove`ing a key
* from a record simply resets it to the default value for that key.
*
* ```js
* myRecord.get('a') // 1
* myRecord.get('b') // 3
* const myRecordWithoutB = myRecord.remove('b')
* myRecordWithoutB.get('b') // 2
* ```
*
* Values provided to the constructor not found in the Record type will
* be ignored. For example, in this case, ABRecord is provided a key "x" even
* though only "a" and "b" have been defined. The value for "x" will be
* ignored for this record.
*
* ```js
* const myRecord = ABRecord({ b: 3, x: 10 })
* myRecord.get('x') // undefined
* ```
*
* Because Records have a known set of string keys, property get access works
* as expected, however property sets will throw an Error.
*
* Note: IE8 does not support property access. Only use `get()` when
* supporting IE8.
*
* ```js
* myRecord.b // 3
* myRecord.b = 5 // throws Error
* ```
*
* Record Types can be extended as well, allowing for custom methods on your
* Record. This is not a common pattern in functional environments, but is in
* many JS programs.
*
* However Record Types are more restricted than typical JavaScript classes.
* They do not use a class constructor, which also means they cannot use
* class properties (since those are technically part of a constructor).
*
* While Record Types can be syntactically created with the JavaScript `class`
* form, the resulting Record function is actually a factory function, not a
* class constructor. Even though Record Types are not classes, JavaScript
* currently requires the use of `new` when creating new Record instances if
* they are defined as a `class`.
*
* ```
* class ABRecord extends Record({ a: 1, b: 2 }) {
* getAB() {
* return this.a + this.b;
* }
* }
*
* var myRecord = new ABRecord({b: 3})
* myRecord.getAB() // 4
* ```
*
*
* **Flow Typing Records:**
*
* Immutable.js exports two Flow types designed to make it easier to use
* Records with flow typed code, `RecordOf<TProps>` and `RecordFactory<TProps>`.
*
* When defining a new kind of Record factory function, use a flow type that
* describes the values the record contains along with `RecordFactory<TProps>`.
* To type instances of the Record (which the factory function returns),
* use `RecordOf<TProps>`.
*
* Typically, new Record definitions will export both the Record factory
* function as well as the Record instance type for use in other code.
*
* ```js
* import type { RecordFactory, RecordOf } from 'immutable';
*
* // Use RecordFactory<TProps> for defining new Record factory functions.
* type Point3DProps = { x: number, y: number, z: number };
* const defaultValues: Point3DProps = { x: 0, y: 0, z: 0 };
* const makePoint3D: RecordFactory<Point3DProps> = Record(defaultValues);
* export makePoint3D;
*
* // Use RecordOf<T> for defining new instances of that Record.
* export type Point3D = RecordOf<Point3DProps>;
* const some3DPoint: Point3D = makePoint3D({ x: 10, y: 20, z: 30 });
* ```
*
* **Flow Typing Record Subclasses:**
*
* Records can be subclassed as a means to add additional methods to Record
* instances. This is generally discouraged in favor of a more functional API,
* since Subclasses have some minor overhead. However the ability to create
* a rich API on Record types can be quite valuable.
*
* When using Flow to type Subclasses, do not use `RecordFactory<TProps>`,
* instead apply the props type when subclassing:
*
* ```js
* type PersonProps = {name: string, age: number};
* const defaultValues: PersonProps = {name: 'Aristotle', age: 2400};
* const PersonRecord = Record(defaultValues);
* class Person extends PersonRecord<PersonProps> {
* getName(): string {
* return this.get('name')
* }
*
* setName(name: string): this {
* return this.set('name', name);
* }
* }
* ```
*
* **Choosing Records vs plain JavaScript objects**
*
* Records offer a persistently immutable alternative to plain JavaScript
* objects, however they're not required to be used within Immutable.js
* collections. In fact, the deep-access and deep-updating functions
* like `getIn()` and `setIn()` work with plain JavaScript Objects as well.
*
* Deciding to use Records or Objects in your application should be informed
* by the tradeoffs and relative benefits of each:
*
* - *Runtime immutability*: plain JS objects may be carefully treated as
* immutable, however Record instances will *throw* if attempted to be
* mutated directly. Records provide this additional guarantee, however at
* some marginal runtime cost. While JS objects are mutable by nature, the
* use of type-checking tools like [Flow](https://medium.com/@gcanti/immutability-with-flow-faa050a1aef4)
* can help gain confidence in code written to favor immutability.
*
* - *Value equality*: Records use value equality when compared with `is()`
* or `record.equals()`. That is, two Records with the same keys and values
* are equal. Plain objects use *reference equality*. Two objects with the
* same keys and values are not equal since they are different objects.
* This is important to consider when using objects as keys in a `Map` or
* values in a `Set`, which use equality when retrieving values.
*
* - *API methods*: Records have a full featured API, with methods like
* `.getIn()`, and `.equals()`. These can make working with these values
* easier, but comes at the cost of not allowing keys with those names.
*
* - *Default values*: Records provide default values for every key, which
* can be useful when constructing Records with often unchanging values.
* However default values can make using Flow and TypeScript more laborious.
*
* - *Serialization*: Records use a custom internal representation to
* efficiently store and update their values. Converting to and from this
* form isn't free. If converting Records to plain objects is common,
* consider sticking with plain objects to begin with.
*/
namespace Record {
/**
* True if `maybeRecord` is an instance of a Record.
*/
function isRecord(maybeRecord: unknown): maybeRecord is Record<{}>;
/**
* Records allow passing a second parameter to supply a descriptive name
* that appears when converting a Record to a string or in any error
* messages. A descriptive name for any record can be accessed by using this
* method. If one was not provided, the string "Record" is returned.
*
* ```js
* const { Record } = require('immutable')
* const Person = Record({
* name: null
* }, 'Person')
*
* var me = Person({ name: 'My Name' })
* me.toString() // "Person { "name": "My Name" }"
* Record.getDescriptiveName(me) // "Person"
* ```
*/
function getDescriptiveName(record: Record<any>): string;
/**
* A Record.Factory is created by the `Record()` function. Record instances
* are created by passing it some of the accepted values for that Record
* type:
*
* <!-- runkit:activate
* { "preamble": "const { Record } = require('immutable')" }
* -->
* ```js
* // makePerson is a Record Factory function
* const makePerson = Record({ name: null, favoriteColor: 'unknown' });
*
* // alan is a Record instance
* const alan = makePerson({ name: 'Alan' });
* ```
*
* Note that Record Factories return `Record<TProps> & Readonly<TProps>`,
* this allows use of both the Record instance API, and direct property
* access on the resulting instances:
*
* <!-- runkit:activate
* { "preamble": "const { Record } = require('immutable');const makePerson = Record({ name: null, favoriteColor: 'unknown' });const alan = makePerson({ name: 'Alan' });" }
* -->
* ```js
* // Use the Record API
* console.log('Record API: ' + alan.get('name'))
*
* // Or direct property access (Readonly)
* console.log('property access: ' + alan.name)
* ```
*
* **Flow Typing Records:**
*
* Use the `RecordFactory<TProps>` Flow type to get high quality type checking of
* Records:
*
* ```js
* import type { RecordFactory, RecordOf } from 'immutable';
*
* // Use RecordFactory<TProps> for defining new Record factory functions.
* type PersonProps = { name: ?string, favoriteColor: string };
* const makePerson: RecordFactory<PersonProps> = Record({ name: null, favoriteColor: 'unknown' });
*
* // Use RecordOf<T> for defining new instances of that Record.
* type Person = RecordOf<PersonProps>;
* const alan: Person = makePerson({ name: 'Alan' });
* ```
*/
namespace Factory {}
interface Factory<TProps extends object> {
(values?: Partial<TProps> | Iterable<[string, unknown]>): Record<TProps> &
Readonly<TProps>;
new (
values?: Partial<TProps> | Iterable<[string, unknown]>
): Record<TProps> & Readonly<TProps>;
/**
* The name provided to `Record(values, name)` can be accessed with
* `displayName`.
*/
displayName: string;
}
function Factory<TProps extends object>(
values?: Partial<TProps> | Iterable<[string, unknown]>
): Record<TProps> & Readonly<TProps>;
}
/**
* Unlike other types in Immutable.js, the `Record()` function creates a new
* Record Factory, which is a function that creates Record instances.
*
* See above for examples of using `Record()`.
*
* Note: `Record` is a factory function and not a class, and does not use the
* `new` keyword during construction.
*/
function Record<TProps extends object>(
defaultValues: TProps,
name?: string
): Record.Factory<TProps>;
interface Record<TProps extends object> {
// Reading values
has(key: string): key is keyof TProps & string;
/**
* Returns the value associated with the provided key, which may be the
* default value defined when creating the Record factory function.
*
* If the requested key is not defined by this Record type, then
* notSetValue will be returned if provided. Note that this scenario would
* produce an error when using Flow or TypeScript.
*/
get<K extends keyof TProps>(key: K, notSetValue?: unknown): TProps[K];
get<T>(key: string, notSetValue: T): T;
// Reading deep values
hasIn(keyPath: Iterable<unknown>): boolean;
getIn(keyPath: Iterable<unknown>): unknown;
// Value equality
equals(other: unknown): boolean;
hashCode(): number;
// Persistent changes
set<K extends keyof TProps>(key: K, value: TProps[K]): this;
update<K extends keyof TProps>(
key: K,
updater: (value: TProps[K]) => TProps[K]
): this;
merge(
...collections: Array<Partial<TProps> | Iterable<[string, unknown]>>
): this;
mergeDeep(
...collections: Array<Partial<TProps> | Iterable<[string, unknown]>>
): this;
mergeWith(
merger: (oldVal: unknown, newVal: unknown, key: keyof TProps) => unknown,
...collections: Array<Partial<TProps> | Iterable<[string, unknown]>>
): this;
mergeDeepWith(
merger: (oldVal: unknown, newVal: unknown, key: unknown) => unknown,
...collections: Array<Partial<TProps> | Iterable<[string, unknown]>>
): this;
/**
* Returns a new instance of this Record type with the value for the
* specific key set to its default value.
*
* @alias remove
*/
delete<K extends keyof TProps>(key: K): this;
remove<K extends keyof TProps>(key: K): this;
/**
* Returns a new instance of this Record type with all values set
* to their default values.
*/
clear(): this;
// Deep persistent changes
setIn(keyPath: Iterable<unknown>, value: unknown): this;
updateIn(
keyPath: Iterable<unknown>,
updater: (value: unknown) => unknown
): this;
mergeIn(keyPath: Iterable<unknown>, ...collections: Array<unknown>): this;
mergeDeepIn(
keyPath: Iterable<unknown>,
...collections: Array<unknown>
): this;
/**
* @alias removeIn
*/
deleteIn(keyPath: Iterable<unknown>): this;
removeIn(keyPath: Iterable<unknown>): this;
// Conversion to JavaScript types
/**
* Deeply converts this Record to equivalent native JavaScript Object.
*
* Note: This method may not be overridden. Objects with custom
* serialization to plain JS may override toJSON() instead.
*/
toJS(): DeepCopy<TProps>;
/**
* Shallowly converts this Record to equivalent native JavaScript Object.
*/
toJSON(): TProps;
/**
* Shallowly converts this Record to equivalent JavaScript Object.
*/
toObject(): TProps;
// Transient changes
/**
* Note: Not all methods can be used on a mutable collection or within
* `withMutations`! Only `set` may be used mutatively.
*
* @see `Map#withMutations`
*/
withMutations(mutator: (mutable: this) => unknown): this;
/**
* @see `Map#asMutable`
*/
asMutable(): this;
/**
* @see `Map#wasAltered`
*/
wasAltered(): boolean;
/**
* @see `Map#asImmutable`
*/
asImmutable(): this;
// Sequence algorithms
toSeq(): Seq.Keyed<keyof TProps, TProps[keyof TProps]>;
[Symbol.iterator](): IterableIterator<[keyof TProps, TProps[keyof TProps]]>;
}
/**
* RecordOf<T> is used in TypeScript to define interfaces expecting an
* instance of record with type T.
*
* This is equivalent to an instance of a record created by a Record Factory.
*/
type RecordOf<TProps extends object> = Record<TProps> & Readonly<TProps>;
/**
* `Seq` describes a lazy operation, allowing them to efficiently chain
* use of all the higher-order collection methods (such as `map` and `filter`)
* by not creating intermediate collections.
*
* **Seq is immutable** — Once a Seq is created, it cannot be
* changed, appended to, rearranged or otherwise modified. Instead, any
* mutative method called on a `Seq` will return a new `Seq`.
*
* **Seq is lazy** — `Seq` does as little work as necessary to respond to any
* method call. Values are often created during iteration, including implicit
* iteration when reducing or converting to a concrete data structure such as
* a `List` or JavaScript `Array`.
*
* For example, the following performs no work, because the resulting
* `Seq`'s values are never iterated:
*
* ```js
* const { Seq } = require('immutable')
* const oddSquares = Seq([ 1, 2, 3, 4, 5, 6, 7, 8 ])
* .filter(x => x % 2 !== 0)
* .map(x => x * x)
* ```
*
* Once the `Seq` is used, it performs only the work necessary. In this
* example, no intermediate arrays are ever created, filter is called three
* times, and map is only called once:
*
* ```js
* oddSquares.get(1); // 9
* ```
*
* Any collection can be converted to a lazy Seq with `Seq()`.
*
* <!-- runkit:activate -->
* ```js
* const { Map } = require('immutable')
* const map = Map({ a: 1, b: 2, c: 3 })
* const lazySeq = Seq(map)
* ```
*
* `Seq` allows for the efficient chaining of operations, allowing for the
* expression of logic that can otherwise be very tedious:
*
* ```js
* lazySeq
* .flip()
* .map(key => key.toUpperCase())
* .flip()
* // Seq { A: 1, B: 1, C: 1 }
* ```
*
* As well as expressing logic that would otherwise seem memory or time
* limited, for example `Range` is a special kind of Lazy sequence.
*
* <!-- runkit:activate -->
* ```js
* const { Range } = require('immutable')
* Range(1, Infinity)
* .skip(1000)
* .map(n => -n)
* .filter(n => n % 2 === 0)
* .take(2)
* .reduce((r, n) => r * n, 1)
* // 1006008
* ```
*
* Seq is often used to provide a rich collection API to JavaScript Object.
*
* ```js
* Seq({ x: 0, y: 1, z: 2 }).map(v => v * 2).toObject();
* // { x: 0, y: 2, z: 4 }
* ```
*/
namespace Seq {
/**
* True if `maybeSeq` is a Seq, it is not backed by a concrete
* structure such as Map, List, or Set.
*/
function isSeq(
maybeSeq: unknown
): maybeSeq is
| Seq.Indexed<unknown>
| Seq.Keyed<unknown, unknown>
| Seq.Set<unknown>;
/**
* `Seq` which represents key-value pairs.
*/
namespace Keyed {}
/**
* Always returns a Seq.Keyed, if input is not keyed, expects an
* collection of [K, V] tuples.
*
* Note: `Seq.Keyed` is a conversion function and not a class, and does not
* use the `new` keyword during construction.
*/
function Keyed<K, V>(collection?: Iterable<[K, V]>): Seq.Keyed<K, V>;
function Keyed<V>(obj: { [key: string]: V }): Seq.Keyed<string, V>;
interface Keyed<K, V> extends Seq<K, V>, Collection.Keyed<K, V> {
/**
* Deeply converts this Keyed Seq to equivalent native JavaScript Object.
*
* Converts keys to Strings.
*/
toJS(): { [key in string | number | symbol]: DeepCopy<V> };
/**
* Shallowly converts this Keyed Seq to equivalent native JavaScript Object.
*
* Converts keys to Strings.
*/
toJSON(): { [key in string | number | symbol]: V };
/**
* Shallowly converts this collection to an Array.
*/
toArray(): Array<[K, V]>;
/**
* Returns itself
*/
toSeq(): this;
/**
* Returns a new Seq with other collections concatenated to this one.
*
* All entries will be present in the resulting Seq, even if they
* have the same key.
*/
concat<KC, VC>(
...collections: Array<Iterable<[KC, VC]>>
): Seq.Keyed<K | KC, V | VC>;
concat<C>(
...collections: Array<{ [key: string]: C }>
): Seq.Keyed<K | string, V | C>;
/**
* Returns a new Seq.Keyed with values passed through a
* `mapper` function.
*
* ```js
* const { Seq } = require('immutable')
* Seq.Keyed({ a: 1, b: 2 }).map(x => 10 * x)
* // Seq { "a": 10, "b": 20 }
* ```
*
* Note: `map()` always returns a new instance, even if it produced the
* same value at every step.
*/
map<M>(
mapper: (value: V, key: K, iter: this) => M,
context?: unknown
): Seq.Keyed<K, M>;
/**
* @see Collection.Keyed.mapKeys
*/
mapKeys<M>(
mapper: (key: K, value: V, iter: this) => M,
context?: unknown
): Seq.Keyed<M, V>;
/**
* @see Collection.Keyed.mapEntries
*/
mapEntries<KM, VM>(
mapper: (
entry: [K, V],
index: number,
iter: this
) => [KM, VM] | undefined,
context?: unknown
): Seq.Keyed<KM, VM>;
/**
* Flat-maps the Seq, returning a Seq of the same type.
*
* Similar to `seq.map(...).flatten(true)`.
*/
flatMap<KM, VM>(
mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>,
context?: unknown
): Seq.Keyed<KM, VM>;
/**
* Returns a new Seq with only the entries for which the `predicate`
* function returns true.
*
* Note: `filter()` always returns a new instance, even if it results in
* not filtering out any values.
*/
filter<F extends V>(
predicate: (value: V, key: K, iter: this) => value is F,
context?: unknown
): Seq.Keyed<K, F>;
filter(
predicate: (value: V, key: K, iter: this) => unknown,
context?: unknown
): this;
/**
* Returns a new keyed Seq with the values for which the `predicate`
* function returns false and another for which is returns true.
*/
partition<F extends V, C>(
predicate: (this: C, value: V, key: K, iter: this) => value is F,
context?: C
): [Seq.Keyed<K, V>, Seq.Keyed<K, F>];
partition<C>(
predicate: (this: C, value: V, key: K, iter: this) => unknown,
context?: C
): [this, this];
/**
* @see Collection.Keyed.flip
*/
flip(): Seq.Keyed<V, K>;
[Symbol.iterator](): IterableIterator<[K, V]>;
}
/**
* `Seq` which represents an ordered indexed list of values.
*/
namespace Indexed {
/**
* Provides an Seq.Indexed of the values provided.
*/
function of<T>(...values: Array<T>): Seq.Indexed<T>;
}
/**
* Always returns Seq.Indexed, discarding associated keys and
* supplying incrementing indices.
*
* Note: `Seq.Indexed` is a conversion function and not a class, and does
* not use the `new` keyword during construction.
*/
function Indexed<T>(
collection?: Iterable<T> | ArrayLike<T>
): Seq.Indexed<T>;
interface Indexed<T> extends Seq<number, T>, Collection.Indexed<T> {
/**
* Deeply converts this Indexed Seq to equivalent native JavaScript Array.
*/
toJS(): Array<DeepCopy<T>>;
/**
* Shallowly converts this Indexed Seq to equivalent native JavaScript Array.
*/
toJSON(): Array<T>;
/**
* Shallowly converts this collection to an Array.
*/
toArray(): Array<T>;
/**
* Returns itself
*/
toSeq(): this;
/**
* Returns a new Seq with other collections concatenated to this one.
*/
concat<C>(
...valuesOrCollections: Array<Iterable<C> | C>
): Seq.Indexed<T | C>;
/**
* Returns a new Seq.Indexed with values passed through a
* `mapper` function.
*
* ```js
* const { Seq } = require('immutable')
* Seq.Indexed([ 1, 2 ]).map(x => 10 * x)
* // Seq [ 10, 20 ]
* ```
*
* Note: `map()` always returns a new instance, even if it produced the
* same value at every step.
*/
map<M>(
mapper: (value: T, key: number, iter: this) => M,
context?: unknown
): Seq.Indexed<M>;
/**
* Flat-maps the Seq, returning a a Seq of the same type.
*
* Similar to `seq.map(...).flatten(true)`.
*/
flatMap<M>(
mapper: (value: T, key: number, iter: this) => Iterable<M>,
context?: unknown
): Seq.Indexed<M>;
/**
* Returns a new Seq with only the values for which the `predicate`
* function returns true.
*
* Note: `filter()` always returns a new instance, even if it results in
* not filtering out any values.
*/
filter<F extends T>(
predicate: (value: T, index: number, iter: this) => value is F,
context?: unknown
): Seq.Indexed<F>;
filter(
predicate: (value: T, index: number, iter: this) => unknown,
context?: unknown
): this;
/**
* Returns a new indexed Seq with the values for which the `predicate`
* function returns false and another for which is returns true.
*/
partition<F extends T, C>(
predicate: (this: C, value: T, index: number, iter: this) => value is F,
context?: C
): [Seq.Indexed<T>, Seq.Indexed<F>];
partition<C>(
predicate: (this: C, value: T, index: number, iter: this) => unknown,
context?: C
): [this, this];
/**
* Returns a Seq "zipped" with the provided collections.
*
* Like `zipWith`, but using the default `zipper`: creating an `Array`.
*
* ```js
* const a = Seq([ 1, 2, 3 ]);
* const b = Seq([ 4, 5, 6 ]);
* const c = a.zip(b); // Seq [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
* ```
*/
zip<U>(other: Collection<unknown, U>): Seq.Indexed<[T, U]>;
zip<U, V>(
other: Collection<unknown, U>,
other2: Collection<unknown, V>
): Seq.Indexed<[T, U, V]>;
zip(
...collections: Array<Collection<unknown, unknown>>
): Seq.Indexed<unknown>;
/**
* Returns a Seq "zipped" with the provided collections.
*
* Unlike `zip`, `zipAll` continues zipping until the longest collection is
* exhausted. Missing values from shorter collections are filled with `undefined`.
*
* ```js
* const a = Seq([ 1, 2 ]);
* const b = Seq([ 3, 4, 5 ]);
* const c = a.zipAll(b); // Seq [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]
* ```
*/
zipAll<U>(other: Collection<unknown, U>): Seq.Indexed<[T, U]>;
zipAll<U, V>(
other: Collection<unknown, U>,
other2: Collection<unknown, V>
): Seq.Indexed<[T, U, V]>;
zipAll(
...collections: Array<Collection<unknown, unknown>>
): Seq.Indexed<unknown>;
/**
* Returns a Seq "zipped" with the provided collections by using a
* custom `zipper` function.
*
* ```js
* const a = Seq([ 1, 2, 3 ]);
* const b = Seq([ 4, 5, 6 ]);
* const c = a.zipWith((a, b) => a + b, b);
* // Seq [ 5, 7, 9 ]
* ```
*/
zipWith<U, Z>(
zipper: (value: T, otherValue: U) => Z,
otherCollection: Collection<unknown, U>
): Seq.Indexed<Z>;
zipWith<U, V, Z>(
zipper: (value: T, otherValue: U, thirdValue: V) => Z,
otherCollection: Collection<unknown, U>,
thirdCollection: Collection<unknown, V>
): Seq.Indexed<Z>;
zipWith<Z>(
zipper: (...values: Array<unknown>) => Z,
...collections: Array<Collection<unknown, unknown>>
): Seq.Indexed<Z>;
[Symbol.iterator](): IterableIterator<T>;
}
/**
* `Seq` which represents a set of values.
*
* Because `Seq` are often lazy, `Seq.Set` does not provide the same guarantee
* of value uniqueness as the concrete `Set`.
*/
namespace Set {
/**
* Returns a Seq.Set of the provided values
*/
function of<T>(...values: Array<T>): Seq.Set<T>;
}
/**
* Always returns a Seq.Set, discarding associated indices or keys.
*
* Note: `Seq.Set` is a conversion function and not a class, and does not
* use the `new` keyword during construction.
*/
function Set<T>(collection?: Iterable<T> | ArrayLike<T>): Seq.Set<T>;
interface Set<T> extends Seq<T, T>, Collection.Set<T> {
/**
* Deeply converts this Set Seq to equivalent native JavaScript Array.
*/
toJS(): Array<DeepCopy<T>>;
/**
* Shallowly converts this Set Seq to equivalent native JavaScript Array.
*/
toJSON(): Array<T>;
/**
* Shallowly converts this collection to an Array.
*/
toArray(): Array<T>;
/**
* Returns itself
*/
toSeq(): this;
/**
* Returns a new Seq with other collections concatenated to this one.
*
* All entries will be present in the resulting Seq, even if they
* are duplicates.
*/
concat<U>(...collections: Array<Iterable<U>>): Seq.Set<T | U>;
/**
* Returns a new Seq.Set with values passed through a
* `mapper` function.
*
* ```js
* Seq.Set([ 1, 2 ]).map(x => 10 * x)
* // Seq { 10, 20 }
* ```
*
* Note: `map()` always returns a new instance, even if it produced the
* same value at every step.
*/
map<M>(
mapper: (value: T, key: T, iter: this) => M,
context?: unknown
): Seq.Set<M>;
/**
* Flat-maps the Seq, returning a Seq of the same type.
*
* Similar to `seq.map(...).flatten(true)`.
*/
flatMap<M>(
mapper: (value: T, key: T, iter: this) => Iterable<M>,
context?: unknown
): Seq.Set<M>;
/**
* Returns a new Seq with only the values for which the `predicate`
* function returns true.
*
* Note: `filter()` always returns a new instance, even if it results in
* not filtering out any values.
*/
filter<F extends T>(
predicate: (value: T, key: T, iter: this) => value is F,
context?: unknown
): Seq.Set<F>;
filter(
predicate: (value: T, key: T, iter: this) => unknown,
context?: unknown
): this;
/**
* Returns a new set Seq with the values for which the `predicate`
* function returns false and another for which is returns true.
*/
partition<F extends T, C>(
predicate: (this: C, value: T, key: T, iter: this) => value is F,
context?: C
): [Seq.Set<T>, Seq.Set<F>];
partition<C>(
predicate: (this: C, value: T, key: T, iter: this) => unknown,
context?: C
): [this, this];
[Symbol.iterator](): IterableIterator<T>;
}
}
/**
* Creates a Seq.
*
* Returns a particular kind of `Seq` based on the input.
*
* * If a `Seq`, that same `Seq`.
* * If an `Collection`, a `Seq` of the same kind (Keyed, Indexed, or Set).
* * If an Array-like, an `Seq.Indexed`.
* * If an Iterable Object, an `Seq.Indexed`.
* * If an Object, a `Seq.Keyed`.
*
* Note: An Iterator itself will be treated as an object, becoming a `Seq.Keyed`,
* which is usually not what you want. You should turn your Iterator Object into
* an iterable object by defining a Symbol.iterator (or @@iterator) method which
* returns `this`.
*
* Note: `Seq` is a conversion function and not a class, and does not use the
* `new` keyword during construction.
*/
function Seq<S extends Seq<unknown, unknown>>(seq: S): S;
function Seq<K, V>(collection: Collection.Keyed<K, V>): Seq.Keyed<K, V>;
function Seq<T>(collection: Collection.Set<T>): Seq.Set<T>;
function Seq<T>(
collection: Collection.Indexed<T> | Iterable<T> | ArrayLike<T>
): Seq.Indexed<T>;
function Seq<V>(obj: { [key: string]: V }): Seq.Keyed<string, V>;
function Seq<K = unknown, V = unknown>(): Seq<K, V>;
interface Seq<K, V> extends Collection<K, V> {
/**
* Some Seqs can describe their size lazily. When this is the case,
* size will be an integer. Otherwise it will be undefined.
*
* For example, Seqs returned from `map()` or `reverse()`
* preserve the size of the original `Seq` while `filter()` does not.
*
* Note: `Range`, `Repeat` and `Seq`s made from `Array`s and `Object`s will
* always have a size.
*/
readonly size: number | undefined;
// Force evaluation
/**
* Because Sequences are lazy and designed to be chained together, they do
* not cache their results. For example, this map function is called a total
* of 6 times, as each `join` iterates the Seq of three values.
*
* var squares = Seq([ 1, 2, 3 ]).map(x => x * x)
* squares.join() + squares.join()
*
* If you know a `Seq` will be used multiple times, it may be more
* efficient to first cache it in memory. Here, the map function is called
* only 3 times.
*
* var squares = Seq([ 1, 2, 3 ]).map(x => x * x).cacheResult()
* squares.join() + squares.join()
*
* Use this method judiciously, as it must fully evaluate a Seq which can be
* a burden on memory and possibly performance.
*
* Note: after calling `cacheResult`, a Seq will always have a `size`.
*/
cacheResult(): this;
// Sequence algorithms
/**
* Returns a new Seq with values passed through a
* `mapper` function.
*
* ```js
* const { Seq } = require('immutable')
* Seq([ 1, 2 ]).map(x => 10 * x)
* // Seq [ 10, 20 ]
* ```
*
* Note: `map()` always returns a new instance, even if it produced the same
* value at every step.
*/
map<M>(
mapper: (value: V, key: K, iter: this) => M,
context?: unknown
): Seq<K, M>;
/**
* Returns a new Seq with values passed through a
* `mapper` function.
*
* ```js
* const { Seq } = require('immutable')
* Seq([ 1, 2 ]).map(x => 10 * x)
* // Seq [ 10, 20 ]
* ```
*
* Note: `map()` always returns a new instance, even if it produced the same
* value at every step.
* Note: used only for sets.
*/
map<M>(
mapper: (value: V, key: K, iter: this) => M,
context?: unknown
): Seq<M, M>;
/**
* Flat-maps the Seq, returning a Seq of the same type.
*
* Similar to `seq.map(...).flatten(true)`.
*/
flatMap<M>(
mapper: (value: V, key: K, iter: this) => Iterable<M>,
context?: unknown
): Seq<K, M>;
/**
* Flat-maps the Seq, returning a Seq of the same type.
*
* Similar to `seq.map(...).flatten(true)`.
* Note: Used only for sets.
*/
flatMap<M>(
mapper: (value: V, key: K, iter: this) => Iterable<M>,
context?: unknown
): Seq<M, M>;
/**
* Returns a new Seq with only the values for which the `predicate`
* function returns true.
*
* Note: `filter()` always returns a new instance, even if it results in
* not filtering out any values.
*/
filter<F extends V>(
predicate: (value: V, key: K, iter: this) => value is F,
context?: unknown
): Seq<K, F>;
filter(
predicate: (value: V, key: K, iter: this) => unknown,
context?: unknown
): this;
/**
* Returns a new Seq with the values for which the `predicate` function
* returns false and another for which is returns true.
*/
partition<F extends V, C>(
predicate: (this: C, value: V, key: K, iter: this) => value is F,
context?: C
): [Seq<K, V>, Seq<K, F>];
partition<C>(
predicate: (this: C, value: V, key: K, iter: this) => unknown,
context?: C
): [this, this];
}
/**
* The `Collection` is a set of (key, value) entries which can be iterated, and
* is the base class for all collections in `immutable`, allowing them to
* make use of all the Collection methods (such as `map` and `filter`).
*
* Note: A collection is always iterated in the same order, however that order
* may not always be well defined, as is the case for the `Map` and `Set`.
*
* Collection is the abstract base class for concrete data structures. It
* cannot be constructed directly.
*
* Implementations should extend one of the subclasses, `Collection.Keyed`,
* `Collection.Indexed`, or `Collection.Set`.
*/
namespace Collection {
/**
* @deprecated use `const { isKeyed } = require('immutable')`
*/
function isKeyed(
maybeKeyed: unknown
): maybeKeyed is Collection.Keyed<unknown, unknown>;
/**
* @deprecated use `const { isIndexed } = require('immutable')`
*/
function isIndexed(
maybeIndexed: unknown
): maybeIndexed is Collection.Indexed<unknown>;
/**
* @deprecated use `const { isAssociative } = require('immutable')`
*/
function isAssociative(
maybeAssociative: unknown
): maybeAssociative is
| Collection.Keyed<unknown, unknown>
| Collection.Indexed<unknown>;
/**
* @deprecated use `const { isOrdered } = require('immutable')`
*/
function isOrdered(maybeOrdered: unknown): boolean;
/**
* Keyed Collections have discrete keys tied to each value.
*
* When iterating `Collection.Keyed`, each iteration will yield a `[K, V]`
* tuple, in other words, `Collection#entries` is the default iterator for
* Keyed Collections.
*/
namespace Keyed {}
/**
* Creates a Collection.Keyed
*
* Similar to `Collection()`, however it expects collection-likes of [K, V]
* tuples if not constructed from a Collection.Keyed or JS Object.
*
* Note: `Collection.Keyed` is a conversion function and not a class, and
* does not use the `new` keyword during construction.
*/
function Keyed<K, V>(collection?: Iterable<[K, V]>): Collection.Keyed<K, V>;
function Keyed<V>(obj: { [key: string]: V }): Collection.Keyed<string, V>;
interface Keyed<K, V> extends Collection<K, V> {
/**
* Deeply converts this Keyed collection to equivalent native JavaScript Object.
*
* Converts keys to Strings.
*/
toJS(): { [key in string | number | symbol]: DeepCopy<V> };
/**
* Shallowly converts this Keyed collection to equivalent native JavaScript Object.
*
* Converts keys to Strings.
*/
toJSON(): { [key in string | number | symbol]: V };
/**
* Shallowly converts this collection to an Array.
*/
toArray(): Array<[K, V]>;
/**
* Returns Seq.Keyed.
* @override
*/
toSeq(): Seq.Keyed<K, V>;
// Sequence functions
/**
* Returns a new Collection.Keyed of the same type where the keys and values
* have been flipped.
*
* <!-- runkit:activate -->
* ```js
* const { Map } = require('immutable')
* Map({ a: 'z', b: 'y' }).flip()
* // Map { "z": "a", "y": "b" }
* ```
*/
flip(): Collection.Keyed<V, K>;
/**
* Returns a new Collection with other collections concatenated to this one.
*/
concat<KC, VC>(
...collections: Array<Iterable<[KC, VC]>>
): Collection.Keyed<K | KC, V | VC>;
concat<C>(
...collections: Array<{ [key: string]: C }>
): Collection.Keyed<K | string, V | C>;
/**
* Returns a new Collection.Keyed with values passed through a
* `mapper` function.
*
* ```js
* const { Collection } = require('immutable')
* Collection.Keyed({ a: 1, b: 2 }).map(x => 10 * x)
* // Seq { "a": 10, "b": 20 }
* ```
*
* Note: `map()` always returns a new instance, even if it produced the
* same value at every step.
*/
map<M>(
mapper: (value: V, key: K, iter: this) => M,
context?: unknown
): Collection.Keyed<K, M>;
/**
* Returns a new Collection.Keyed of the same type with keys passed through
* a `mapper` function.
*
* <!-- runkit:activate -->
* ```js
* const { Map } = require('immutable')
* Map({ a: 1, b: 2 }).mapKeys(x => x.toUpperCase())
* // Map { "A": 1, "B": 2 }
* ```
*
* Note: `mapKeys()` always returns a new instance, even if it produced
* the same key at every step.
*/
mapKeys<M>(
mapper: (key: K, value: V, iter: this) => M,
context?: unknown
): Collection.Keyed<M, V>;
/**
* Returns a new Collection.Keyed of the same type with entries
* ([key, value] tuples) passed through a `mapper` function.
*
* <!-- runkit:activate -->
* ```js
* const { Map } = require('immutable')
* Map({ a: 1, b: 2 })
* .mapEntries(([ k, v ]) => [ k.toUpperCase(), v * 2 ])
* // Map { "A": 2, "B": 4 }
* ```
*
* Note: `mapEntries()` always returns a new instance, even if it produced
* the same entry at every step.
*
* If the mapper function returns `undefined`, then the entry will be filtered
*/
mapEntries<KM, VM>(
mapper: (
entry: [K, V],
index: number,
iter: this
) => [KM, VM] | undefined,
context?: unknown
): Collection.Keyed<KM, VM>;
/**
* Flat-maps the Collection, returning a Collection of the same type.
*
* Similar to `collection.map(...).flatten(true)`.
*/
flatMap<KM, VM>(
mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>,
context?: unknown
): Collection.Keyed<KM, VM>;
/**
* Returns a new Collection with only the values for which the `predicate`
* function returns true.
*
* Note: `filter()` always returns a new instance, even if it results in
* not filtering out any values.
*/
filter<F extends V>(
predicate: (value: V, key: K, iter: this) => value is F,
context?: unknown
): Collection.Keyed<K, F>;
filter(
predicate: (value: V, key: K, iter: this) => unknown,
context?: unknown
): this;
/**
* Returns a new keyed Collection with the values for which the
* `predicate` function returns false and another for which is returns
* true.
*/
partition<F extends V, C>(
predicate: (this: C, value: V, key: K, iter: this) => value is F,
context?: C
): [Collection.Keyed<K, V>, Collection.Keyed<K, F>];
partition<C>(
predicate: (this: C, value: V, key: K, iter: this) => unknown,
context?: C
): [this, this];
[Symbol.iterator](): IterableIterator<[K, V]>;
}
/**
* Indexed Collections have incrementing numeric keys. They exhibit
* slightly different behavior than `Collection.Keyed` for some methods in order
* to better mirror the behavior of JavaScript's `Array`, and add methods
* which do not make sense on non-indexed Collections such as `indexOf`.
*
* Unlike JavaScript arrays, `Collection.Indexed`s are always dense. "Unset"
* indices and `undefined` indices are indistinguishable, and all indices from
* 0 to `size` are visited when iterated.
*
* All Collection.Indexed methods return re-indexed Collections. In other words,
* indices always start at 0 and increment until size. If you wish to
* preserve indices, using them as keys, convert to a Collection.Keyed by
* calling `toKeyedSeq`.
*/
namespace Indexed {}
/**
* Creates a new Collection.Indexed.
*
* Note: `Collection.Indexed` is a conversion function and not a class, and
* does not use the `new` keyword during construction.
*/
function Indexed<T>(
collection?: Iterable<T> | ArrayLike<T>
): Collection.Indexed<T>;
interface Indexed<T> extends Collection<number, T> {
/**
* Deeply converts this Indexed collection to equivalent native JavaScript Array.
*/
toJS(): Array<DeepCopy<T>>;
/**
* Shallowly converts this Indexed collection to equivalent native JavaScript Array.
*/
toJSON(): Array<T>;
/**
* Shallowly converts this collection to an Array.
*/
toArray(): Array<T>;
// Reading values
/**
* Returns the value associated with the provided index, or notSetValue if
* the index is beyond the bounds of the Collection.
*
* `index` may be a negative number, which indexes back from the end of the
* Collection. `s.get(-1)` gets the last item in the Collection.
*/
get<NSV>(index: number, notSetValue: NSV): T | NSV;
get(index: number): T | undefined;
// Conversion to Seq
/**
* Returns Seq.Indexed.
* @override
*/
toSeq(): Seq.Indexed<T>;
/**
* If this is a collection of [key, value] entry tuples, it will return a
* Seq.Keyed of those entries.
*/
fromEntrySeq(): Seq.Keyed<unknown, unknown>;
// Combination
/**
* Returns a Collection of the same type with `separator` between each item
* in this Collection.
*/
interpose(separator: T): this;
/**
* Returns a Collection of the same type with the provided `collections`
* interleaved into this collection.
*
* The resulting Collection includes the first item from each, then the
* second from each, etc.
*
* <!-- runkit:activate
* { "preamble": "require('immutable')"}
* -->
* ```js
* const { List } = require('immutable')
* List([ 1, 2, 3 ]).interleave(List([ 'A', 'B', 'C' ]))
* // List [ 1, "A", 2, "B", 3, "C" ]
* ```
*
* The shortest Collection stops interleave.
*
* <!-- runkit:activate
* { "preamble": "const { List } = require('immutable')" }
* -->
* ```js
* List([ 1, 2, 3 ]).interleave(
* List([ 'A', 'B' ]),
* List([ 'X', 'Y', 'Z' ])
* )
* // List [ 1, "A", "X", 2, "B", "Y" ]
* ```
*
* Since `interleave()` re-indexes values, it produces a complete copy,
* which has `O(N)` complexity.
*
* Note: `interleave` *cannot* be used in `withMutations`.
*/
interleave(...collections: Array<Collection<unknown, T>>): this;
/**
* Splice returns a new indexed Collection by replacing a region of this
* Collection with new values. If values are not provided, it only skips the
* region to be removed.
*
* `index` may be a negative number, which indexes back from the end of the
* Collection. `s.splice(-2)` splices after the second to last item.
*
* <!-- runkit:activate -->
* ```js
* const { List } = require('immutable')
* List([ 'a', 'b', 'c', 'd' ]).splice(1, 2, 'q', 'r', 's')
* // List [ "a", "q", "r", "s", "d" ]
* ```
*
* Since `splice()` re-indexes values, it produces a complete copy, which
* has `O(N)` complexity.
*
* Note: `splice` *cannot* be used in `withMutations`.
*/
splice(index: number, removeNum: number, ...values: Array<T>): this;
/**
* Returns a Collection of the same type "zipped" with the provided
* collections.
*
* Like `zipWith`, but using the default `zipper`: creating an `Array`.
*
*
* <!-- runkit:activate
* { "preamble": "const { List } = require('immutable')" }
* -->
* ```js
* const a = List([ 1, 2, 3 ]);
* const b = List([ 4, 5, 6 ]);
* const c = a.zip(b); // List [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
* ```
*/
zip<U>(other: Collection<unknown, U>): Collection.Indexed<[T, U]>;
zip<U, V>(
other: Collection<unknown, U>,
other2: Collection<unknown, V>
): Collection.Indexed<[T, U, V]>;
zip(
...collections: Array<Collection<unknown, unknown>>
): Collection.Indexed<unknown>;
/**
* Returns a Collection "zipped" with the provided collections.
*
* Unlike `zip`, `zipAll` continues zipping until the longest collection is
* exhausted. Missing values from shorter collections are filled with `undefined`.
*
* ```js
* const a = List([ 1, 2 ]);
* const b = List([ 3, 4, 5 ]);
* const c = a.zipAll(b); // List [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]
* ```
*/
zipAll<U>(other: Collection<unknown, U>): Collection.Indexed<[T, U]>;
zipAll<U, V>(
other: Collection<unknown, U>,
other2: Collection<unknown, V>
): Collection.Indexed<[T, U, V]>;
zipAll(
...collections: Array<Collection<unknown, unknown>>
): Collection.Indexed<unknown>;
/**
* Returns a Collection of the same type "zipped" with the provided
* collections by using a custom `zipper` function.
*
* <!-- runkit:activate
* { "preamble": "const { List } = require('immutable')" }
* -->
* ```js
* const a = List([ 1, 2, 3 ]);
* const b = List([ 4, 5, 6 ]);
* const c = a.zipWith((a, b) => a + b, b);
* // List [ 5, 7, 9 ]
* ```
*/
zipWith<U, Z>(
zipper: (value: T, otherValue: U) => Z,
otherCollection: Collection<unknown, U>
): Collection.Indexed<Z>;
zipWith<U, V, Z>(
zipper: (value: T, otherValue: U, thirdValue: V) => Z,
otherCollection: Collection<unknown, U>,
thirdCollection: Collection<unknown, V>
): Collection.Indexed<Z>;
zipWith<Z>(
zipper: (...values: Array<unknown>) => Z,
...collections: Array<Collection<unknown, unknown>>
): Collection.Indexed<Z>;
// Search for value
/**
* Returns the first index at which a given value can be found in the
* Collection, or -1 if it is not present.
*/
indexOf(searchValue: T): number;
/**
* Returns the last index at which a given value can be found in the
* Collection, or -1 if it is not present.
*/
lastIndexOf(searchValue: T): number;
/**
* Returns the first index in the Collection where a value satisfies the
* provided predicate function. Otherwise -1 is returned.
*/
findIndex(
predicate: (value: T, index: number, iter: this) => boolean,
context?: unknown
): number;
/**
* Returns the last index in the Collection where a value satisfies the
* provided predicate function. Otherwise -1 is returned.
*/
findLastIndex(
predicate: (value: T, index: number, iter: this) => boolean,
context?: unknown
): number;
// Sequence algorithms
/**
* Returns a new Collection with other collections concatenated to this one.
*/
concat<C>(
...valuesOrCollections: Array<Iterable<C> | C>
): Collection.Indexed<T | C>;
/**
* Returns a new Collection.Indexed with values passed through a
* `mapper` function.
*
* ```js
* const { Collection } = require('immutable')
* Collection.Indexed([1,2]).map(x => 10 * x)
* // Seq [ 1, 2 ]
* ```
*
* Note: `map()` always returns a new instance, even if it produced the
* same value at every step.
*/
map<M>(
mapper: (value: T, key: number, iter: this) => M,
context?: unknown
): Collection.Indexed<M>;
/**
* Flat-maps the Collection, returning a Collection of the same type.
*
* Similar to `collection.map(...).flatten(true)`.
*/
flatMap<M>(
mapper: (value: T, key: number, iter: this) => Iterable<M>,
context?: unknown
): Collection.Indexed<M>;
/**
* Returns a new Collection with only the values for which the `predicate`
* function returns true.
*
* Note: `filter()` always returns a new instance, even if it results in
* not filtering out any values.
*/
filter<F extends T>(
predicate: (value: T, index: number, iter: this) => value is F,
context?: unknown
): Collection.Indexed<F>;
filter(
predicate: (value: T, index: number, iter: this) => unknown,
context?: unknown
): this;
/**
* Returns a new indexed Collection with the values for which the
* `predicate` function returns false and another for which is returns
* true.
*/
partition<F extends T, C>(
predicate: (this: C, value: T, index: number, iter: this) => value is F,
context?: C
): [Collection.Indexed<T>, Collection.Indexed<F>];
partition<C>(
predicate: (this: C, value: T, index: number, iter: this) => unknown,
context?: C
): [this, this];
[Symbol.iterator](): IterableIterator<T>;
}
/**
* Set Collections only represent values. They have no associated keys or
* indices. Duplicate values are possible in the lazy `Seq.Set`s, however
* the concrete `Set` Collection does not allow duplicate values.
*
* Collection methods on Collection.Set such as `map` and `forEach` will provide
* the value as both the first and second arguments to the provided function.
*
* ```js
* const { Collection } = require('immutable')
* const seq = Collection.Set([ 'A', 'B', 'C' ])
* // Seq { "A", "B", "C" }
* seq.forEach((v, k) =>
* assert.equal(v, k)
* )
* ```
*/
namespace Set {}
/**
* Similar to `Collection()`, but always returns a Collection.Set.
*
* Note: `Collection.Set` is a factory function and not a class, and does
* not use the `new` keyword during construction.
*/
function Set<T>(collection?: Iterable<T> | ArrayLike<T>): Collection.Set<T>;
interface Set<T> extends Collection<T, T> {
/**
* Deeply converts this Set collection to equivalent native JavaScript Array.
*/
toJS(): Array<DeepCopy<T>>;
/**
* Shallowly converts this Set collection to equivalent native JavaScript Array.
*/
toJSON(): Array<T>;
/**
* Shallowly converts this collection to an Array.
*/
toArray(): Array<T>;
/**
* Returns Seq.Set.
* @override
*/
toSeq(): Seq.Set<T>;
// Sequence algorithms
/**
* Returns a new Collection with other collections concatenated to this one.
*/
concat<U>(...collections: Array<Iterable<U>>): Collection.Set<T | U>;
/**
* Returns a new Collection.Set with values passed through a
* `mapper` function.
*
* ```
* Collection.Set([ 1, 2 ]).map(x => 10 * x)
* // Seq { 1, 2 }
* ```
*
* Note: `map()` always returns a new instance, even if it produced the
* same value at every step.
*/
map<M>(
mapper: (value: T, key: T, iter: this) => M,
context?: unknown
): Collection.Set<M>;
/**
* Flat-maps the Collection, returning a Collection of the same type.
*
* Similar to `collection.map(...).flatten(true)`.
*/
flatMap<M>(
mapper: (value: T, key: T, iter: this) => Iterable<M>,
context?: unknown
): Collection.Set<M>;
/**
* Returns a new Collection with only the values for which the `predicate`
* function returns true.
*
* Note: `filter()` always returns a new instance, even if it results in
* not filtering out any values.
*/
filter<F extends T>(
predicate: (value: T, key: T, iter: this) => value is F,
context?: unknown
): Collection.Set<F>;
filter(
predicate: (value: T, key: T, iter: this) => unknown,
context?: unknown
): this;
/**
* Returns a new set Collection with the values for which the
* `predicate` function returns false and another for which is returns
* true.
*/
partition<F extends T, C>(
predicate: (this: C, value: T, key: T, iter: this) => value is F,
context?: C
): [Collection.Set<T>, Collection.Set<F>];
partition<C>(
predicate: (this: C, value: T, key: T, iter: this) => unknown,
context?: C
): [this, this];
[Symbol.iterator](): IterableIterator<T>;
}
}
/**
* Creates a Collection.
*
* The type of Collection created is based on the input.
*
* * If an `Collection`, that same `Collection`.
* * If an Array-like, an `Collection.Indexed`.
* * If an Object with an Iterator defined, an `Collection.Indexed`.
* * If an Object, an `Collection.Keyed`.
*
* This methods forces the conversion of Objects and Strings to Collections.
* If you want to ensure that a Collection of one item is returned, use
* `Seq.of`.
*
* Note: An Iterator itself will be treated as an object, becoming a `Seq.Keyed`,
* which is usually not what you want. You should turn your Iterator Object into
* an iterable object by defining a Symbol.iterator (or @@iterator) method which
* returns `this`.
*
* Note: `Collection` is a conversion function and not a class, and does not
* use the `new` keyword during construction.
*/
function Collection<I extends Collection<unknown, unknown>>(collection: I): I;
function Collection<T>(
collection: Iterable<T> | ArrayLike<T>
): Collection.Indexed<T>;
function Collection<V>(obj: {
[key: string]: V;
}): Collection.Keyed<string, V>;
function Collection<K = unknown, V = unknown>(): Collection<K, V>;
interface Collection<K, V> extends ValueObject {
// Value equality
/**
* True if this and the other Collection have value equality, as defined
* by `Immutable.is()`.
*
* Note: This is equivalent to `Immutable.is(this, other)`, but provided to
* allow for chained expressions.
*/
equals(other: unknown): boolean;
/**
* Computes and returns the hashed identity for this Collection.
*
* The `hashCode` of a Collection is used to determine potential equality,
* and is used when adding this to a `Set` or as a key in a `Map`, enabling
* lookup via a different instance.
*
* <!-- runkit:activate
* { "preamble": "const { Set, List } = require('immutable')" }
* -->
* ```js
* const a = List([ 1, 2, 3 ]);
* const b = List([ 1, 2, 3 ]);
* assert.notStrictEqual(a, b); // different instances
* const set = Set([ a ]);
* assert.equal(set.has(b), true);
* ```
*
* If two values have the same `hashCode`, they are [not guaranteed
* to be equal][Hash Collision]. If two values have different `hashCode`s,
* they must not be equal.
*
* [Hash Collision]: https://en.wikipedia.org/wiki/Collision_(computer_science)
*/
hashCode(): number;
// Reading values
/**
* Returns the value associated with the provided key, or notSetValue if
* the Collection does not contain this key.
*
* Note: it is possible a key may be associated with an `undefined` value,
* so if `notSetValue` is not provided and this method returns `undefined`,
* that does not guarantee the key was not found.
*/
get<NSV>(key: K, notSetValue: NSV): V | NSV;
get(key: K): V | undefined;
/**
* True if a key exists within this `Collection`, using `Immutable.is`
* to determine equality
*/
has(key: K): boolean;
/**
* True if a value exists within this `Collection`, using `Immutable.is`
* to determine equality
* @alias contains
*/
includes(value: V): boolean;
contains(value: V): boolean;
/**
* In case the `Collection` is not empty returns the first element of the
* `Collection`.
* In case the `Collection` is empty returns the optional default
* value if provided, if no default value is provided returns undefined.
*/
first<NSV = undefined>(notSetValue?: NSV): V | NSV;
/**
* In case the `Collection` is not empty returns the last element of the
* `Collection`.
* In case the `Collection` is empty returns the optional default
* value if provided, if no default value is provided returns undefined.
*/
last<NSV = undefined>(notSetValue?: NSV): V | NSV;
// Reading deep values
/**
* Returns the value found by following a path of keys or indices through
* nested Collections.
*
* <!-- runkit:activate -->
* ```js
* const { Map, List } = require('immutable')
* const deepData = Map({ x: List([ Map({ y: 123 }) ]) });
* deepData.getIn(['x', 0, 'y']) // 123
* ```
*
* Plain JavaScript Object or Arrays may be nested within an Immutable.js
* Collection, and getIn() can access those values as well:
*
* <!-- runkit:activate -->
* ```js
* const { Map, List } = require('immutable')
* const deepData = Map({ x: [ { y: 123 } ] });
* deepData.getIn(['x', 0, 'y']) // 123
* ```
*/
getIn(searchKeyPath: Iterable<unknown>, notSetValue?: unknown): unknown;
/**
* True if the result of following a path of keys or indices through nested
* Collections results in a set value.
*/
hasIn(searchKeyPath: Iterable<unknown>): boolean;
// Persistent changes
/**
* This can be very useful as a way to "chain" a normal function into a
* sequence of methods. RxJS calls this "let" and lodash calls it "thru".
*
* For example, to sum a Seq after mapping and filtering:
*
* <!-- runkit:activate -->
* ```js
* const { Seq } = require('immutable')
*
* function sum(collection) {
* return collection.reduce((sum, x) => sum + x, 0)
* }
*
* Seq([ 1, 2, 3 ])
* .map(x => x + 1)
* .filter(x => x % 2 === 0)
* .update(sum)
* // 6
* ```
*/
update<R>(updater: (value: this) => R): R;
// Conversion to JavaScript types
/**
* Deeply converts this Collection to equivalent native JavaScript Array or Object.
*
* `Collection.Indexed`, and `Collection.Set` become `Array`, while
* `Collection.Keyed` become `Object`, converting keys to Strings.
*/
toJS():
| Array<DeepCopy<V>>
| { [key in string | number | symbol]: DeepCopy<V> };
/**
* Shallowly converts this Collection to equivalent native JavaScript Array or Object.
*
* `Collection.Indexed`, and `Collection.Set` become `Array`, while
* `Collection.Keyed` become `Object`, converting keys to Strings.
*/
toJSON(): Array<V> | { [key in string | number | symbol]: V };
/**
* Shallowly converts this collection to an Array.
*
* `Collection.Indexed`, and `Collection.Set` produce an Array of values.
* `Collection.Keyed` produce an Array of [key, value] tuples.
*/
toArray(): Array<V> | Array<[K, V]>;
/**
* Shallowly converts this Collection to an Object.
*
* Converts keys to Strings.
*/
toObject(): { [key: string]: V };
// Conversion to Collections
/**
* Converts this Collection to a Map, Throws if keys are not hashable.
*
* Note: This is equivalent to `Map(this.toKeyedSeq())`, but provided
* for convenience and to allow for chained expressions.
*/
toMap(): Map<K, V>;
/**
* Converts this Collection to a Map, maintaining the order of iteration.
*
* Note: This is equivalent to `OrderedMap(this.toKeyedSeq())`, but
* provided for convenience and to allow for chained expressions.
*/
toOrderedMap(): OrderedMap<K, V>;
/**
* Converts this Collection to a Set, discarding keys. Throws if values
* are not hashable.
*
* Note: This is equivalent to `Set(this)`, but provided to allow for
* chained expressions.
*/
toSet(): Set<V>;
/**
* Converts this Collection to a Set, maintaining the order of iteration and
* discarding keys.
*
* Note: This is equivalent to `OrderedSet(this.valueSeq())`, but provided
* for convenience and to allow for chained expressions.
*/
toOrderedSet(): OrderedSet<V>;
/**
* Converts this Collection to a List, discarding keys.
*
* This is similar to `List(collection)`, but provided to allow for chained
* expressions. However, when called on `Map` or other keyed collections,
* `collection.toList()` discards the keys and creates a list of only the
* values, whereas `List(collection)` creates a list of entry tuples.
*
* <!-- runkit:activate -->
* ```js
* const { Map, List } = require('immutable')
* var myMap = Map({ a: 'Apple', b: 'Banana' })
* List(myMap) // List [ [ "a", "Apple" ], [ "b", "Banana" ] ]
* myMap.toList() // List [ "Apple", "Banana" ]
* ```
*/
toList(): List<V>;
/**
* Converts this Collection to a Stack, discarding keys. Throws if values
* are not hashable.
*
* Note: This is equivalent to `Stack(this)`, but provided to allow for
* chained expressions.
*/
toStack(): Stack<V>;
// Conversion to Seq
/**
* Converts this Collection to a Seq of the same kind (indexed,
* keyed, or set).
*/
toSeq(): Seq<K, V>;
/**
* Returns a Seq.Keyed from this Collection where indices are treated as keys.
*
* This is useful if you want to operate on an
* Collection.Indexed and preserve the [index, value] pairs.
*
* The returned Seq will have identical iteration order as
* this Collection.
*
* <!-- runkit:activate -->
* ```js
* const { Seq } = require('immutable')
* const indexedSeq = Seq([ 'A', 'B', 'C' ])
* // Seq [ "A", "B", "C" ]
* indexedSeq.filter(v => v === 'B')
* // Seq [ "B" ]
* const keyedSeq = indexedSeq.toKeyedSeq()
* // Seq { 0: "A", 1: "B", 2: "C" }
* keyedSeq.filter(v => v === 'B')
* // Seq { 1: "B" }
* ```
*/
toKeyedSeq(): Seq.Keyed<K, V>;
/**
* Returns an Seq.Indexed of the values of this Collection, discarding keys.
*/
toIndexedSeq(): Seq.Indexed<V>;
/**
* Returns a Seq.Set of the values of this Collection, discarding keys.
*/
toSetSeq(): Seq.Set<V>;
// Iterators
/**
* An iterator of this `Collection`'s keys.
*
* Note: this will return an ES6 iterator which does not support
* Immutable.js sequence algorithms. Use `keySeq` instead, if this is
* what you want.
*/
keys(): IterableIterator<K>;
/**
* An iterator of this `Collection`'s values.
*
* Note: this will return an ES6 iterator which does not support
* Immutable.js sequence algorithms. Use `valueSeq` instead, if this is
* what you want.
*/
values(): IterableIterator<V>;
/**
* An iterator of this `Collection`'s entries as `[ key, value ]` tuples.
*
* Note: this will return an ES6 iterator which does not support
* Immutable.js sequence algorithms. Use `entrySeq` instead, if this is
* what you want.
*/
entries(): IterableIterator<[K, V]>;
[Symbol.iterator](): IterableIterator<unknown>;
// Collections (Seq)
/**
* Returns a new Seq.Indexed of the keys of this Collection,
* discarding values.
*/
keySeq(): Seq.Indexed<K>;
/**
* Returns an Seq.Indexed of the values of this Collection, discarding keys.
*/
valueSeq(): Seq.Indexed<V>;
/**
* Returns a new Seq.Indexed of [key, value] tuples.
*/
entrySeq(): Seq.Indexed<[K, V]>;
// Sequence algorithms
/**
* Returns a new Collection of the same type with values passed through a
* `mapper` function.
*
* <!-- runkit:activate -->
* ```js
* const { Collection } = require('immutable')
* Collection({ a: 1, b: 2 }).map(x => 10 * x)
* // Seq { "a": 10, "b": 20 }
* ```
*
* Note: `map()` always returns a new instance, even if it produced the same
* value at every step.
*/
map<M>(
mapper: (value: V, key: K, iter: this) => M,
context?: unknown
): Collection<K, M>;
/**
* Note: used only for sets, which return Collection<M, M> but are otherwise
* identical to normal `map()`.
*
* @ignore
*/
map(...args: Array<never>): unknown;
/**
* Returns a new Collection of the same type with only the entries for which
* the `predicate` function returns true.
*
* <!-- runkit:activate -->
* ```js
* const { Map } = require('immutable')
* Map({ a: 1, b: 2, c: 3, d: 4}).filter(x => x % 2 === 0)
* // Map { "b": 2, "d": 4 }
* ```
*
* Note: `filter()` always returns a new instance, even if it results in
* not filtering out any values.
*/
filter<F extends V>(
predicate: (value: V, key: K, iter: this) => value is F,
context?: unknown
): Collection<K, F>;
filter(
predicate: (value: V, key: K, iter: this) => unknown,
context?: unknown
): this;
/**
* Returns a new Collection of the same type with only the entries for which
* the `predicate` function returns false.
*
* <!-- runkit:activate -->
* ```js
* const { Map } = require('immutable')
* Map({ a: 1, b: 2, c: 3, d: 4}).filterNot(x => x % 2 === 0)
* // Map { "a": 1, "c": 3 }
* ```
*
* Note: `filterNot()` always returns a new instance, even if it results in
* not filtering out any values.
*/
filterNot(
predicate: (value: V, key: K, iter: this) => boolean,
context?: unknown
): this;
/**
* Returns a new Collection with the values for which the `predicate`
* function returns false and another for which is returns true.
*/
partition<F extends V, C>(
predicate: (this: C, value: V, key: K, iter: this) => value is F,
context?: C
): [Collection<K, V>, Collection<K, F>];
partition<C>(
predicate: (this: C, value: V, key: K, iter: this) => unknown,
context?: C
): [this, this];
/**
* Returns a new Collection of the same type in reverse order.
*/
reverse(): this;
/**
* Returns a new Collection of the same type which includes the same entries,
* stably sorted by using a `comparator`.
*
* If a `comparator` is not provided, a default comparator uses `<` and `>`.
*
* `comparator(valueA, valueB)`:
*
* * Returns `0` if the elements should not be swapped.
* * Returns `-1` (or any negative number) if `valueA` comes before `valueB`
* * Returns `1` (or any positive number) if `valueA` comes after `valueB`
* * Alternatively, can return a value of the `PairSorting` enum type
* * Is pure, i.e. it must always return the same value for the same pair
* of values.
*
* When sorting collections which have no defined order, their ordered
* equivalents will be returned. e.g. `map.sort()` returns OrderedMap.
*
* <!-- runkit:activate -->
* ```js
* const { Map } = require('immutable')
* Map({ "c": 3, "a": 1, "b": 2 }).sort((a, b) => {
* if (a < b) { return -1; }
* if (a > b) { return 1; }
* if (a === b) { return 0; }
* });
* // OrderedMap { "a": 1, "b": 2, "c": 3 }
* ```
*
* Note: `sort()` Always returns a new instance, even if the original was
* already sorted.
*
* Note: This is always an eager operation.
*/
sort(comparator?: Comparator<V>): this;
/**
* Like `sort`, but also accepts a `comparatorValueMapper` which allows for
* sorting by more sophisticated means:
*
* <!-- runkit:activate -->
* ```js
* const { Map } = require('immutable')
* const beattles = Map({
* John: { name: "Lennon" },
* Paul: { name: "McCartney" },
* George: { name: "Harrison" },
* Ringo: { name: "Starr" },
* });
* beattles.sortBy(member => member.name);
* ```
*
* Note: `sortBy()` Always returns a new instance, even if the original was
* already sorted.
*
* Note: This is always an eager operation.
*/
sortBy<C>(
comparatorValueMapper: (value: V, key: K, iter: this) => C,
comparator?: Comparator<C>
): this;
/**
* Returns a `Map` of `Collection`, grouped by the return
* value of the `grouper` function.
*
* Note: This is always an eager operation.
*
* <!-- runkit:activate -->
* ```js
* const { List, Map } = require('immutable')
* const listOfMaps = List([
* Map({ v: 0 }),
* Map({ v: 1 }),
* Map({ v: 1 }),
* Map({ v: 0 }),
* Map({ v: 2 })
* ])
* const groupsOfMaps = listOfMaps.groupBy(x => x.get('v'))
* // Map {
* // 0: List [ Map{ "v": 0 }, Map { "v": 0 } ],
* // 1: List [ Map{ "v": 1 }, Map { "v": 1 } ],
* // 2: List [ Map{ "v": 2 } ],
* // }
* ```
*/
groupBy<G>(
grouper: (value: V, key: K, iter: this) => G,
context?: unknown
): Map<G, this>;
// Side effects
/**
* The `sideEffect` is executed for every entry in the Collection.
*
* Unlike `Array#forEach`, if any call of `sideEffect` returns
* `false`, the iteration will stop. Returns the number of entries iterated
* (including the last iteration which returned false).
*/
forEach(
sideEffect: (value: V, key: K, iter: this) => unknown,
context?: unknown
): number;
// Creating subsets
/**
* Returns a new Collection of the same type representing a portion of this
* Collection from start up to but not including end.
*
* If begin is negative, it is offset from the end of the Collection. e.g.
* `slice(-2)` returns a Collection of the last two entries. If it is not
* provided the new Collection will begin at the beginning of this Collection.
*
* If end is negative, it is offset from the end of the Collection. e.g.
* `slice(0, -1)` returns a Collection of everything but the last entry. If
* it is not provided, the new Collection will continue through the end of
* this Collection.
*
* If the requested slice is equivalent to the current Collection, then it
* will return itself.
*/
slice(begin?: number, end?: number): this;
/**
* Returns a new Collection of the same type containing all entries except
* the first.
*/
rest(): this;
/**
* Returns a new Collection of the same type containing all entries except
* the last.
*/
butLast(): this;
/**
* Returns a new Collection of the same type which excludes the first `amount`
* entries from this Collection.
*/
skip(amount: number): this;
/**
* Returns a new Collection of the same type which excludes the last `amount`
* entries from this Collection.
*/
skipLast(amount: number): this;
/**
* Returns a new Collection of the same type which includes entries starting
* from when `predicate` first returns false.
*
* <!-- runkit:activate -->
* ```js
* const { List } = require('immutable')
* List([ 'dog', 'frog', 'cat', 'hat', 'god' ])
* .skipWhile(x => x.match(/g/))
* // List [ "cat", "hat", "god" ]
* ```
*/
skipWhile(
predicate: (value: V, key: K, iter: this) => boolean,
context?: unknown
): this;
/**
* Returns a new Collection of the same type which includes entries starting
* from when `predicate` first returns true.
*
* <!-- runkit:activate -->
* ```js
* const { List } = require('immutable')
* List([ 'dog', 'frog', 'cat', 'hat', 'god' ])
* .skipUntil(x => x.match(/hat/))
* // List [ "hat", "god" ]
* ```
*/
skipUntil(
predicate: (value: V, key: K, iter: this) => boolean,
context?: unknown
): this;
/**
* Returns a new Collection of the same type which includes the first `amount`
* entries from this Collection.
*/
take(amount: number): this;
/**
* Returns a new Collection of the same type which includes the last `amount`
* entries from this Collection.
*/
takeLast(amount: number): this;
/**
* Returns a new Collection of the same type which includes entries from this
* Collection as long as the `predicate` returns true.
*
* <!-- runkit:activate -->
* ```js
* const { List } = require('immutable')
* List([ 'dog', 'frog', 'cat', 'hat', 'god' ])
* .takeWhile(x => x.match(/o/))
* // List [ "dog", "frog" ]
* ```
*/
takeWhile(
predicate: (value: V, key: K, iter: this) => boolean,
context?: unknown
): this;
/**
* Returns a new Collection of the same type which includes entries from this
* Collection as long as the `predicate` returns false.
*
* <!-- runkit:activate -->
* ```js
* const { List } = require('immutable')
* List([ 'dog', 'frog', 'cat', 'hat', 'god' ])
* .takeUntil(x => x.match(/at/))
* // List [ "dog", "frog" ]
* ```
*/
takeUntil(
predicate: (value: V, key: K, iter: this) => boolean,
context?: unknown
): this;
// Combination
/**
* Returns a new Collection of the same type with other values and
* collection-like concatenated to this one.
*
* For Seqs, all entries will be present in the resulting Seq, even if they
* have the same key.
*/
concat(
...valuesOrCollections: Array<unknown>
): Collection<unknown, unknown>;
/**
* Flattens nested Collections.
*
* Will deeply flatten the Collection by default, returning a Collection of the
* same type, but a `depth` can be provided in the form of a number or
* boolean (where true means to shallowly flatten one level). A depth of 0
* (or shallow: false) will deeply flatten.
*
* Flattens only others Collection, not Arrays or Objects.
*
* Note: `flatten(true)` operates on Collection<unknown, Collection<K, V>> and
* returns Collection<K, V>
*/
flatten(depth?: number): Collection<unknown, unknown>;
// tslint:disable-next-line unified-signatures
flatten(shallow?: boolean): Collection<unknown, unknown>;
/**
* Flat-maps the Collection, returning a Collection of the same type.
*
* Similar to `collection.map(...).flatten(true)`.
*/
flatMap<M>(
mapper: (value: V, key: K, iter: this) => Iterable<M>,
context?: unknown
): Collection<K, M>;
/**
* Flat-maps the Collection, returning a Collection of the same type.
*
* Similar to `collection.map(...).flatten(true)`.
* Used for Dictionaries only.
*/
flatMap<KM, VM>(
mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>,
context?: unknown
): Collection<KM, VM>;
// Reducing a value
/**
* Reduces the Collection to a value by calling the `reducer` for every entry
* in the Collection and passing along the reduced value.
*
* If `initialReduction` is not provided, the first item in the
* Collection will be used.
*
* @see `Array#reduce`.
*/
reduce<R>(
reducer: (reduction: R, value: V, key: K, iter: this) => R,
initialReduction: R,
context?: unknown
): R;
reduce<R>(
reducer: (reduction: V | R, value: V, key: K, iter: this) => R
): R;
/**
* Reduces the Collection in reverse (from the right side).
*
* Note: Similar to this.reverse().reduce(), and provided for parity
* with `Array#reduceRight`.
*/
reduceRight<R>(
reducer: (reduction: R, value: V, key: K, iter: this) => R,
initialReduction: R,
context?: unknown
): R;
reduceRight<R>(
reducer: (reduction: V | R, value: V, key: K, iter: this) => R
): R;
/**
* True if `predicate` returns true for all entries in the Collection.
*/
every(
predicate: (value: V, key: K, iter: this) => boolean,
context?: unknown
): boolean;
/**
* True if `predicate` returns true for any entry in the Collection.
*/
some(
predicate: (value: V, key: K, iter: this) => boolean,
context?: unknown
): boolean;
/**
* Joins values together as a string, inserting a separator between each.
* The default separator is `","`.
*/
join(separator?: string): string;
/**
* Returns true if this Collection includes no values.
*
* For some lazy `Seq`, `isEmpty` might need to iterate to determine
* emptiness. At most one iteration will occur.
*/
isEmpty(): boolean;
/**
* Returns the size of this Collection.
*
* Regardless of if this Collection can describe its size lazily (some Seqs
* cannot), this method will always return the correct size. E.g. it
* evaluates a lazy `Seq` if necessary.
*
* If `predicate` is provided, then this returns the count of entries in the
* Collection for which the `predicate` returns true.
*/
count(): number;
count(
predicate: (value: V, key: K, iter: this) => boolean,
context?: unknown
): number;
/**
* Returns a `Seq.Keyed` of counts, grouped by the return value of
* the `grouper` function.
*
* Note: This is not a lazy operation.
*/
countBy<G>(
grouper: (value: V, key: K, iter: this) => G,
context?: unknown
): Map<G, number>;
// Search for value
/**
* Returns the first value for which the `predicate` returns true.
*/
find(
predicate: (value: V, key: K, iter: this) => boolean,
context?: unknown,
notSetValue?: V
): V | undefined;
/**
* Returns the last value for which the `predicate` returns true.
*
* Note: `predicate` will be called for each entry in reverse.
*/
findLast(
predicate: (value: V, key: K, iter: this) => boolean,
context?: unknown,
notSetValue?: V
): V | undefined;
/**
* Returns the first [key, value] entry for which the `predicate` returns true.
*/
findEntry(
predicate: (value: V, key: K, iter: this) => boolean,
context?: unknown,
notSetValue?: V
): [K, V] | undefined;
/**
* Returns the last [key, value] entry for which the `predicate`
* returns true.
*
* Note: `predicate` will be called for each entry in reverse.
*/
findLastEntry(
predicate: (value: V, key: K, iter: this) => boolean,
context?: unknown,
notSetValue?: V
): [K, V] | undefined;
/**
* Returns the key for which the `predicate` returns true.
*/
findKey(
predicate: (value: V, key: K, iter: this) => boolean,
context?: unknown
): K | undefined;
/**
* Returns the last key for which the `predicate` returns true.
*
* Note: `predicate` will be called for each entry in reverse.
*/
findLastKey(
predicate: (value: V, key: K, iter: this) => boolean,
context?: unknown
): K | undefined;
/**
* Returns the key associated with the search value, or undefined.
*/
keyOf(searchValue: V): K | undefined;
/**
* Returns the last key associated with the search value, or undefined.
*/
lastKeyOf(searchValue: V): K | undefined;
/**
* Returns the maximum value in this collection. If any values are
* comparatively equivalent, the first one found will be returned.
*
* The `comparator` is used in the same way as `Collection#sort`. If it is not
* provided, the default comparator is `>`.
*
* When two values are considered equivalent, the first encountered will be
* returned. Otherwise, `max` will operate independent of the order of input
* as long as the comparator is commutative. The default comparator `>` is
* commutative *only* when types do not differ.
*
* If `comparator` returns 0 and either value is NaN, undefined, or null,
* that value will be returned.
*/
max(comparator?: Comparator<V>): V | undefined;
/**
* Like `max`, but also accepts a `comparatorValueMapper` which allows for
* comparing by more sophisticated means:
*
* <!-- runkit:activate -->
* ```js
* const { List, } = require('immutable');
* const l = List([
* { name: 'Bob', avgHit: 1 },
* { name: 'Max', avgHit: 3 },
* { name: 'Lili', avgHit: 2 } ,
* ]);
* l.maxBy(i => i.avgHit); // will output { name: 'Max', avgHit: 3 }
* ```
*/
maxBy<C>(
comparatorValueMapper: (value: V, key: K, iter: this) => C,
comparator?: Comparator<C>
): V | undefined;
/**
* Returns the minimum value in this collection. If any values are
* comparatively equivalent, the first one found will be returned.
*
* The `comparator` is used in the same way as `Collection#sort`. If it is not
* provided, the default comparator is `<`.
*
* When two values are considered equivalent, the first encountered will be
* returned. Otherwise, `min` will operate independent of the order of input
* as long as the comparator is commutative. The default comparator `<` is
* commutative *only* when types do not differ.
*
* If `comparator` returns 0 and either value is NaN, undefined, or null,
* that value will be returned.
*/
min(comparator?: Comparator<V>): V | undefined;
/**
* Like `min`, but also accepts a `comparatorValueMapper` which allows for
* comparing by more sophisticated means:
*
* <!-- runkit:activate -->
* ```js
* const { List, } = require('immutable');
* const l = List([
* { name: 'Bob', avgHit: 1 },
* { name: 'Max', avgHit: 3 },
* { name: 'Lili', avgHit: 2 } ,
* ]);
* l.minBy(i => i.avgHit); // will output { name: 'Bob', avgHit: 1 }
* ```
*/
minBy<C>(
comparatorValueMapper: (value: V, key: K, iter: this) => C,
comparator?: Comparator<C>
): V | undefined;
// Comparison
/**
* True if `iter` includes every value in this Collection.
*/
isSubset(iter: Iterable<V>): boolean;
/**
* True if this Collection includes every value in `iter`.
*/
isSuperset(iter: Iterable<V>): boolean;
}
/**
* The interface to fulfill to qualify as a Value Object.
*/
interface ValueObject {
/**
* True if this and the other Collection have value equality, as defined
* by `Immutable.is()`.
*
* Note: This is equivalent to `Immutable.is(this, other)`, but provided to
* allow for chained expressions.
*/
equals(other: unknown): boolean;
/**
* Computes and returns the hashed identity for this Collection.
*
* The `hashCode` of a Collection is used to determine potential equality,
* and is used when adding this to a `Set` or as a key in a `Map`, enabling
* lookup via a different instance.
*
* <!-- runkit:activate -->
* ```js
* const { List, Set } = require('immutable');
* const a = List([ 1, 2, 3 ]);
* const b = List([ 1, 2, 3 ]);
* assert.notStrictEqual(a, b); // different instances
* const set = Set([ a ]);
* assert.equal(set.has(b), true);
* ```
*
* Note: hashCode() MUST return a Uint32 number. The easiest way to
* guarantee this is to return `myHash | 0` from a custom implementation.
*
* If two values have the same `hashCode`, they are [not guaranteed
* to be equal][Hash Collision]. If two values have different `hashCode`s,
* they must not be equal.
*
* Note: `hashCode()` is not guaranteed to always be called before
* `equals()`. Most but not all Immutable.js collections use hash codes to
* organize their internal data structures, while all Immutable.js
* collections use equality during lookups.
*
* [Hash Collision]: https://en.wikipedia.org/wiki/Collision_(computer_science)
*/
hashCode(): number;
}
/**
* Deeply converts plain JS objects and arrays to Immutable Maps and Lists.
*
* `fromJS` will convert Arrays and [array-like objects][2] to a List, and
* plain objects (without a custom prototype) to a Map. [Iterable objects][3]
* may be converted to List, Map, or Set.
*
* If a `reviver` is optionally provided, it will be called with every
* collection as a Seq (beginning with the most nested collections
* and proceeding to the top-level collection itself), along with the key
* referring to each collection and the parent JS object provided as `this`.
* For the top level, object, the key will be `""`. This `reviver` is expected
* to return a new Immutable Collection, allowing for custom conversions from
* deep JS objects. Finally, a `path` is provided which is the sequence of
* keys to this value from the starting value.
*
* `reviver` acts similarly to the [same parameter in `JSON.parse`][1].
*
* If `reviver` is not provided, the default behavior will convert Objects
* into Maps and Arrays into Lists like so:
*
* <!-- runkit:activate -->
* ```js
* const { fromJS, isKeyed } = require('immutable')
* function (key, value) {
* return isKeyed(value) ? value.toMap() : value.toList()
* }
* ```
*
* Accordingly, this example converts native JS data to OrderedMap and List:
*
* <!-- runkit:activate -->
* ```js
* const { fromJS, isKeyed } = require('immutable')
* fromJS({ a: {b: [10, 20, 30]}, c: 40}, function (key, value, path) {
* console.log(key, value, path)
* return isKeyed(value) ? value.toOrderedMap() : value.toList()
* })
*
* > "b", [ 10, 20, 30 ], [ "a", "b" ]
* > "a", {b: [10, 20, 30]}, [ "a" ]
* > "", {a: {b: [10, 20, 30]}, c: 40}, []
* ```
*
* Keep in mind, when using JS objects to construct Immutable Maps, that
* JavaScript Object properties are always strings, even if written in a
* quote-less shorthand, while Immutable Maps accept keys of any type.
*
* <!-- runkit:activate -->
* ```js
* const { Map } = require('immutable')
* let obj = { 1: "one" };
* Object.keys(obj); // [ "1" ]
* assert.equal(obj["1"], obj[1]); // "one" === "one"
*
* let map = Map(obj);
* assert.notEqual(map.get("1"), map.get(1)); // "one" !== undefined
* ```
*
* Property access for JavaScript Objects first converts the key to a string,
* but since Immutable Map keys can be of any type the argument to `get()` is
* not altered.
*
* [1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Example.3A_Using_the_reviver_parameter
* "Using the reviver parameter"
* [2]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Indexed_collections#working_with_array-like_objects
* "Working with array-like objects"
* [3]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol
* "The iterable protocol"
*/
function fromJS<JSValue>(
jsValue: JSValue,
reviver?: undefined
): FromJS<JSValue>;
function fromJS(
jsValue: unknown,
reviver?: (
key: string | number,
sequence: Collection.Keyed<string, unknown> | Collection.Indexed<unknown>,
path?: Array<string | number>
) => unknown
): Collection<unknown, unknown>;
type FromJS<JSValue> = JSValue extends FromJSNoTransform
? JSValue
: JSValue extends Array<any>
? FromJSArray<JSValue>
: JSValue extends {}
? FromJSObject<JSValue>
: any;
type FromJSNoTransform =
| Collection<any, any>
| number
| string
| null
| undefined;
type FromJSArray<JSValue> = JSValue extends Array<infer T>
? List<FromJS<T>>
: never;
type FromJSObject<JSValue> = JSValue extends {}
? Map<keyof JSValue, FromJS<JSValue[keyof JSValue]>>
: never;
/**
* Value equality check with semantics similar to `Object.is`, but treats
* Immutable `Collection`s as values, equal if the second `Collection` includes
* equivalent values.
*
* It's used throughout Immutable when checking for equality, including `Map`
* key equality and `Set` membership.
*
* <!-- runkit:activate -->
* ```js
* const { Map, is } = require('immutable')
* const map1 = Map({ a: 1, b: 1, c: 1 })
* const map2 = Map({ a: 1, b: 1, c: 1 })
* assert.equal(map1 !== map2, true)
* assert.equal(Object.is(map1, map2), false)
* assert.equal(is(map1, map2), true)
* ```
*
* `is()` compares primitive types like strings and numbers, Immutable.js
* collections like `Map` and `List`, but also any custom object which
* implements `ValueObject` by providing `equals()` and `hashCode()` methods.
*
* Note: Unlike `Object.is`, `Immutable.is` assumes `0` and `-0` are the same
* value, matching the behavior of ES6 Map key equality.
*/
function is(first: unknown, second: unknown): boolean;
/**
* The `hash()` function is an important part of how Immutable determines if
* two values are equivalent and is used to determine how to store those
* values. Provided with any value, `hash()` will return a 31-bit integer.
*
* When designing Objects which may be equal, it's important that when a
* `.equals()` method returns true, that both values `.hashCode()` method
* return the same value. `hash()` may be used to produce those values.
*
* For non-Immutable Objects that do not provide a `.hashCode()` functions
* (including plain Objects, plain Arrays, Date objects, etc), a unique hash
* value will be created for each *instance*. That is, the create hash
* represents referential equality, and not value equality for Objects. This
* ensures that if that Object is mutated over time that its hash code will
* remain consistent, allowing Objects to be used as keys and values in
* Immutable.js collections.
*
* Note that `hash()` attempts to balance between speed and avoiding
* collisions, however it makes no attempt to produce secure hashes.
*
* *New in Version 4.0*
*/
function hash(value: unknown): number;
/**
* True if `maybeImmutable` is an Immutable Collection or Record.
*
* Note: Still returns true even if the collections is within a `withMutations()`.
*
* <!-- runkit:activate -->
* ```js
* const { isImmutable, Map, List, Stack } = require('immutable');
* isImmutable([]); // false
* isImmutable({}); // false
* isImmutable(Map()); // true
* isImmutable(List()); // true
* isImmutable(Stack()); // true
* isImmutable(Map().asMutable()); // true
* ```
*/
function isImmutable(
maybeImmutable: unknown
): maybeImmutable is Collection<unknown, unknown>;
/**
* True if `maybeCollection` is a Collection, or any of its subclasses.
*
* <!-- runkit:activate -->
* ```js
* const { isCollection, Map, List, Stack } = require('immutable');
* isCollection([]); // false
* isCollection({}); // false
* isCollection(Map()); // true
* isCollection(List()); // true
* isCollection(Stack()); // true
* ```
*/
function isCollection(
maybeCollection: unknown
): maybeCollection is Collection<unknown, unknown>;
/**
* True if `maybeKeyed` is a Collection.Keyed, or any of its subclasses.
*
* <!-- runkit:activate -->
* ```js
* const { isKeyed, Map, List, Stack } = require('immutable');
* isKeyed([]); // false
* isKeyed({}); // false
* isKeyed(Map()); // true
* isKeyed(List()); // false
* isKeyed(Stack()); // false
* ```
*/
function isKeyed(
maybeKeyed: unknown
): maybeKeyed is Collection.Keyed<unknown, unknown>;
/**
* True if `maybeIndexed` is a Collection.Indexed, or any of its subclasses.
*
* <!-- runkit:activate -->
* ```js
* const { isIndexed, Map, List, Stack, Set } = require('immutable');
* isIndexed([]); // false
* isIndexed({}); // false
* isIndexed(Map()); // false
* isIndexed(List()); // true
* isIndexed(Stack()); // true
* isIndexed(Set()); // false
* ```
*/
function isIndexed(
maybeIndexed: unknown
): maybeIndexed is Collection.Indexed<unknown>;
/**
* True if `maybeAssociative` is either a Keyed or Indexed Collection.
*
* <!-- runkit:activate -->
* ```js
* const { isAssociative, Map, List, Stack, Set } = require('immutable');
* isAssociative([]); // false
* isAssociative({}); // false
* isAssociative(Map()); // true
* isAssociative(List()); // true
* isAssociative(Stack()); // true
* isAssociative(Set()); // false
* ```
*/
function isAssociative(
maybeAssociative: unknown
): maybeAssociative is
| Collection.Keyed<unknown, unknown>
| Collection.Indexed<unknown>;
/**
* True if `maybeOrdered` is a Collection where iteration order is well
* defined. True for Collection.Indexed as well as OrderedMap and OrderedSet.
*
* <!-- runkit:activate -->
* ```js
* const { isOrdered, Map, OrderedMap, List, Set } = require('immutable');
* isOrdered([]); // false
* isOrdered({}); // false
* isOrdered(Map()); // false
* isOrdered(OrderedMap()); // true
* isOrdered(List()); // true
* isOrdered(Set()); // false
* ```
*/
function isOrdered(maybeOrdered: unknown): boolean;
/**
* True if `maybeValue` is a JavaScript Object which has *both* `equals()`
* and `hashCode()` methods.
*
* Any two instances of *value objects* can be compared for value equality with
* `Immutable.is()` and can be used as keys in a `Map` or members in a `Set`.
*/
function isValueObject(maybeValue: unknown): maybeValue is ValueObject;
/**
* True if `maybeSeq` is a Seq.
*/
function isSeq(
maybeSeq: unknown
): maybeSeq is
| Seq.Indexed<unknown>
| Seq.Keyed<unknown, unknown>
| Seq.Set<unknown>;
/**
* True if `maybeList` is a List.
*/
function isList(maybeList: unknown): maybeList is List<unknown>;
/**
* True if `maybeMap` is a Map.
*
* Also true for OrderedMaps.
*/
function isMap(maybeMap: unknown): maybeMap is Map<unknown, unknown>;
/**
* True if `maybeOrderedMap` is an OrderedMap.
*/
function isOrderedMap(
maybeOrderedMap: unknown
): maybeOrderedMap is OrderedMap<unknown, unknown>;
/**
* True if `maybeStack` is a Stack.
*/
function isStack(maybeStack: unknown): maybeStack is Stack<unknown>;
/**
* True if `maybeSet` is a Set.
*
* Also true for OrderedSets.
*/
function isSet(maybeSet: unknown): maybeSet is Set<unknown>;
/**
* True if `maybeOrderedSet` is an OrderedSet.
*/
function isOrderedSet(
maybeOrderedSet: unknown
): maybeOrderedSet is OrderedSet<unknown>;
/**
* True if `maybeRecord` is a Record.
*/
function isRecord(maybeRecord: unknown): maybeRecord is Record<{}>;
/**
* Returns the value within the provided collection associated with the
* provided key, or notSetValue if the key is not defined in the collection.
*
* A functional alternative to `collection.get(key)` which will also work on
* plain Objects and Arrays as an alternative for `collection[key]`.
*
* <!-- runkit:activate -->
* ```js
* const { get } = require('immutable')
* get([ 'dog', 'frog', 'cat' ], 2) // 'frog'
* get({ x: 123, y: 456 }, 'x') // 123
* get({ x: 123, y: 456 }, 'z', 'ifNotSet') // 'ifNotSet'
* ```
*/
function get<K, V>(collection: Collection<K, V>, key: K): V | undefined;
function get<K, V, NSV>(
collection: Collection<K, V>,
key: K,
notSetValue: NSV
): V | NSV;
function get<TProps extends object, K extends keyof TProps>(
record: Record<TProps>,
key: K,
notSetValue: unknown
): TProps[K];
function get<V>(collection: Array<V>, key: number): V | undefined;
function get<V, NSV>(
collection: Array<V>,
key: number,
notSetValue: NSV
): V | NSV;
function get<C extends object, K extends keyof C>(
object: C,
key: K,
notSetValue: unknown
): C[K];
function get<V>(collection: { [key: string]: V }, key: string): V | undefined;
function get<V, NSV>(
collection: { [key: string]: V },
key: string,
notSetValue: NSV
): V | NSV;
/**
* Returns true if the key is defined in the provided collection.
*
* A functional alternative to `collection.has(key)` which will also work with
* plain Objects and Arrays as an alternative for
* `collection.hasOwnProperty(key)`.
*
* <!-- runkit:activate -->
* ```js
* const { has } = require('immutable')
* has([ 'dog', 'frog', 'cat' ], 2) // true
* has([ 'dog', 'frog', 'cat' ], 5) // false
* has({ x: 123, y: 456 }, 'x') // true
* has({ x: 123, y: 456 }, 'z') // false
* ```
*/
function has(collection: object, key: unknown): boolean;
/**
* Returns a copy of the collection with the value at key removed.
*
* A functional alternative to `collection.remove(key)` which will also work
* with plain Objects and Arrays as an alternative for
* `delete collectionCopy[key]`.
*
* <!-- runkit:activate -->
* ```js
* const { remove } = require('immutable')
* const originalArray = [ 'dog', 'frog', 'cat' ]
* remove(originalArray, 1) // [ 'dog', 'cat' ]
* console.log(originalArray) // [ 'dog', 'frog', 'cat' ]
* const originalObject = { x: 123, y: 456 }
* remove(originalObject, 'x') // { y: 456 }
* console.log(originalObject) // { x: 123, y: 456 }
* ```
*/
function remove<K, C extends Collection<K, unknown>>(
collection: C,
key: K
): C;
function remove<
TProps extends object,
C extends Record<TProps>,
K extends keyof TProps
>(collection: C, key: K): C;
function remove<C extends Array<unknown>>(collection: C, key: number): C;
function remove<C, K extends keyof C>(collection: C, key: K): C;
function remove<C extends { [key: string]: unknown }, K extends keyof C>(
collection: C,
key: K
): C;
/**
* Returns a copy of the collection with the value at key set to the provided
* value.
*
* A functional alternative to `collection.set(key, value)` which will also
* work with plain Objects and Arrays as an alternative for
* `collectionCopy[key] = value`.
*
* <!-- runkit:activate -->
* ```js
* const { set } = require('immutable')
* const originalArray = [ 'dog', 'frog', 'cat' ]
* set(originalArray, 1, 'cow') // [ 'dog', 'cow', 'cat' ]
* console.log(originalArray) // [ 'dog', 'frog', 'cat' ]
* const originalObject = { x: 123, y: 456 }
* set(originalObject, 'x', 789) // { x: 789, y: 456 }
* console.log(originalObject) // { x: 123, y: 456 }
* ```
*/
function set<K, V, C extends Collection<K, V>>(
collection: C,
key: K,
value: V
): C;
function set<
TProps extends object,
C extends Record<TProps>,
K extends keyof TProps
>(record: C, key: K, value: TProps[K]): C;
function set<V, C extends Array<V>>(collection: C, key: number, value: V): C;
function set<C, K extends keyof C>(object: C, key: K, value: C[K]): C;
function set<V, C extends { [key: string]: V }>(
collection: C,
key: string,
value: V
): C;
/**
* Returns a copy of the collection with the value at key set to the result of
* providing the existing value to the updating function.
*
* A functional alternative to `collection.update(key, fn)` which will also
* work with plain Objects and Arrays as an alternative for
* `collectionCopy[key] = fn(collection[key])`.
*
* <!-- runkit:activate -->
* ```js
* const { update } = require('immutable')
* const originalArray = [ 'dog', 'frog', 'cat' ]
* update(originalArray, 1, val => val.toUpperCase()) // [ 'dog', 'FROG', 'cat' ]
* console.log(originalArray) // [ 'dog', 'frog', 'cat' ]
* const originalObject = { x: 123, y: 456 }
* update(originalObject, 'x', val => val * 6) // { x: 738, y: 456 }
* console.log(originalObject) // { x: 123, y: 456 }
* ```
*/
function update<K, V, C extends Collection<K, V>>(
collection: C,
key: K,
updater: (value: V | undefined) => V | undefined
): C;
function update<K, V, C extends Collection<K, V>, NSV>(
collection: C,
key: K,
notSetValue: NSV,
updater: (value: V | NSV) => V
): C;
function update<
TProps extends object,
C extends Record<TProps>,
K extends keyof TProps
>(record: C, key: K, updater: (value: TProps[K]) => TProps[K]): C;
function update<
TProps extends object,
C extends Record<TProps>,
K extends keyof TProps,
NSV
>(
record: C,
key: K,
notSetValue: NSV,
updater: (value: TProps[K] | NSV) => TProps[K]
): C;
function update<V>(
collection: Array<V>,
key: number,
updater: (value: V | undefined) => V | undefined
): Array<V>;
function update<V, NSV>(
collection: Array<V>,
key: number,
notSetValue: NSV,
updater: (value: V | NSV) => V
): Array<V>;
function update<C, K extends keyof C>(
object: C,
key: K,
updater: (value: C[K]) => C[K]
): C;
function update<C, K extends keyof C, NSV>(
object: C,
key: K,
notSetValue: NSV,
updater: (value: C[K] | NSV) => C[K]
): C;
function update<V, C extends { [key: string]: V }, K extends keyof C>(
collection: C,
key: K,
updater: (value: V) => V
): { [key: string]: V };
function update<V, C extends { [key: string]: V }, K extends keyof C, NSV>(
collection: C,
key: K,
notSetValue: NSV,
updater: (value: V | NSV) => V
): { [key: string]: V };
/**
* Returns the value at the provided key path starting at the provided
* collection, or notSetValue if the key path is not defined.
*
* A functional alternative to `collection.getIn(keypath)` which will also
* work with plain Objects and Arrays.
*
* <!-- runkit:activate -->
* ```js
* const { getIn } = require('immutable')
* getIn({ x: { y: { z: 123 }}}, ['x', 'y', 'z']) // 123
* getIn({ x: { y: { z: 123 }}}, ['x', 'q', 'p'], 'ifNotSet') // 'ifNotSet'
* ```
*/
function getIn(
collection: unknown,
keyPath: Iterable<unknown>,
notSetValue?: unknown
): unknown;
/**
* Returns true if the key path is defined in the provided collection.
*
* A functional alternative to `collection.hasIn(keypath)` which will also
* work with plain Objects and Arrays.
*
* <!-- runkit:activate -->
* ```js
* const { hasIn } = require('immutable')
* hasIn({ x: { y: { z: 123 }}}, ['x', 'y', 'z']) // true
* hasIn({ x: { y: { z: 123 }}}, ['x', 'q', 'p']) // false
* ```
*/
function hasIn(collection: unknown, keyPath: Iterable<unknown>): boolean;
/**
* Returns a copy of the collection with the value at the key path removed.
*
* A functional alternative to `collection.removeIn(keypath)` which will also
* work with plain Objects and Arrays.
*
* <!-- runkit:activate -->
* ```js
* const { removeIn } = require('immutable')
* const original = { x: { y: { z: 123 }}}
* removeIn(original, ['x', 'y', 'z']) // { x: { y: {}}}
* console.log(original) // { x: { y: { z: 123 }}}
* ```
*/
function removeIn<C>(collection: C, keyPath: Iterable<unknown>): C;
/**
* Returns a copy of the collection with the value at the key path set to the
* provided value.
*
* A functional alternative to `collection.setIn(keypath)` which will also
* work with plain Objects and Arrays.
*
* <!-- runkit:activate -->
* ```js
* const { setIn } = require('immutable')
* const original = { x: { y: { z: 123 }}}
* setIn(original, ['x', 'y', 'z'], 456) // { x: { y: { z: 456 }}}
* console.log(original) // { x: { y: { z: 123 }}}
* ```
*/
function setIn<C>(
collection: C,
keyPath: Iterable<unknown>,
value: unknown
): C;
/**
* Returns a copy of the collection with the value at key path set to the
* result of providing the existing value to the updating function.
*
* A functional alternative to `collection.updateIn(keypath)` which will also
* work with plain Objects and Arrays.
*
* <!-- runkit:activate -->
* ```js
* const { updateIn } = require('immutable')
* const original = { x: { y: { z: 123 }}}
* updateIn(original, ['x', 'y', 'z'], val => val * 6) // { x: { y: { z: 738 }}}
* console.log(original) // { x: { y: { z: 123 }}}
* ```
*/
function updateIn<C>(
collection: C,
keyPath: Iterable<unknown>,
updater: (value: unknown) => unknown
): C;
function updateIn<C>(
collection: C,
keyPath: Iterable<unknown>,
notSetValue: unknown,
updater: (value: unknown) => unknown
): C;
/**
* Returns a copy of the collection with the remaining collections merged in.
*
* A functional alternative to `collection.merge()` which will also work with
* plain Objects and Arrays.
*
* <!-- runkit:activate -->
* ```js
* const { merge } = require('immutable')
* const original = { x: 123, y: 456 }
* merge(original, { y: 789, z: 'abc' }) // { x: 123, y: 789, z: 'abc' }
* console.log(original) // { x: 123, y: 456 }
* ```
*/
function merge<C>(
collection: C,
...collections: Array<
| Iterable<unknown>
| Iterable<[unknown, unknown]>
| { [key: string]: unknown }
>
): C;
/**
* Returns a copy of the collection with the remaining collections merged in,
* calling the `merger` function whenever an existing value is encountered.
*
* A functional alternative to `collection.mergeWith()` which will also work
* with plain Objects and Arrays.
*
* <!-- runkit:activate -->
* ```js
* const { mergeWith } = require('immutable')
* const original = { x: 123, y: 456 }
* mergeWith(
* (oldVal, newVal) => oldVal + newVal,
* original,
* { y: 789, z: 'abc' }
* ) // { x: 123, y: 1245, z: 'abc' }
* console.log(original) // { x: 123, y: 456 }
* ```
*/
function mergeWith<C>(
merger: (oldVal: unknown, newVal: unknown, key: unknown) => unknown,
collection: C,
...collections: Array<
| Iterable<unknown>
| Iterable<[unknown, unknown]>
| { [key: string]: unknown }
>
): C;
/**
* Like `merge()`, but when two compatible collections are encountered with
* the same key, it merges them as well, recursing deeply through the nested
* data. Two collections are considered to be compatible (and thus will be
* merged together) if they both fall into one of three categories: keyed
* (e.g., `Map`s, `Record`s, and objects), indexed (e.g., `List`s and
* arrays), or set-like (e.g., `Set`s). If they fall into separate
* categories, `mergeDeep` will replace the existing collection with the
* collection being merged in. This behavior can be customized by using
* `mergeDeepWith()`.
*
* Note: Indexed and set-like collections are merged using
* `concat()`/`union()` and therefore do not recurse.
*
* A functional alternative to `collection.mergeDeep()` which will also work
* with plain Objects and Arrays.
*
* <!-- runkit:activate -->
* ```js
* const { mergeDeep } = require('immutable')
* const original = { x: { y: 123 }}
* mergeDeep(original, { x: { z: 456 }}) // { x: { y: 123, z: 456 }}
* console.log(original) // { x: { y: 123 }}
* ```
*/
function mergeDeep<C>(
collection: C,
...collections: Array<
| Iterable<unknown>
| Iterable<[unknown, unknown]>
| { [key: string]: unknown }
>
): C;
/**
* Like `mergeDeep()`, but when two non-collections or incompatible
* collections are encountered at the same key, it uses the `merger` function
* to determine the resulting value. Collections are considered incompatible
* if they fall into separate categories between keyed, indexed, and set-like.
*
* A functional alternative to `collection.mergeDeepWith()` which will also
* work with plain Objects and Arrays.
*
* <!-- runkit:activate -->
* ```js
* const { mergeDeepWith } = require('immutable')
* const original = { x: { y: 123 }}
* mergeDeepWith(
* (oldVal, newVal) => oldVal + newVal,
* original,
* { x: { y: 456 }}
* ) // { x: { y: 579 }}
* console.log(original) // { x: { y: 123 }}
* ```
*/
function mergeDeepWith<C>(
merger: (oldVal: unknown, newVal: unknown, key: unknown) => unknown,
collection: C,
...collections: Array<
| Iterable<unknown>
| Iterable<[unknown, unknown]>
| { [key: string]: unknown }
>
): C;
}
/**
* Defines the main export of the immutable module to be the Immutable namespace
* This supports many common module import patterns:
*
* const Immutable = require("immutable");
* const { List } = require("immutable");
* import Immutable from "immutable";
* import * as Immutable from "immutable";
* import { List } from "immutable";
*
*/
export = Immutable;
/**
* A global "Immutable" namespace used by UMD modules which allows the use of
* the full Immutable API.
*
* If using Immutable as an imported module, prefer using:
*
* import Immutable from 'immutable'
*
*/
export as namespace Immutable;