index.html
92.4 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
<!doctype html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="tocdoc.css" />
</head>
<body>
<div class="toc"><ul><li><a href="#introduction">Introduction</a><ul><li><a href="#places">Places</a></li><li><a href="#why-underscore-contrib">Why underscore-contrib?</a></li><li><a href="#use">Use</a><ul><li><a href="#in-the-browser">In the Browser</a></li><li><a href="#in-node.js">In Node.js</a></li></ul></li><li><a href="#license">License</a></li></ul></li><li><a href="#sub-libraries">Sub-libraries</a><ul><li><a href="#array.builders">array.builders</a><ul><li><a href="#cat">cat</a></li><li><a href="#chunk">chunk</a></li><li><a href="#chunkall">chunkAll</a></li><li><a href="#cons">cons</a></li><li><a href="#cycle">cycle</a></li><li><a href="#interpose">interpose</a></li><li><a href="#iterateuntil">iterateUntil</a></li><li><a href="#keepindexed">keepIndexed</a></li><li><a href="#mapcat">mapcat</a></li><li><a href="#reductions">reductions</a></li><li><a href="#repeat">repeat</a></li><li><a href="#splitat">splitAt</a></li><li><a href="#takeskipping">takeSkipping</a></li><li><a href="#weave">weave</a></li></ul></li><li><a href="#array.selectors">array.selectors</a><ul><li><a href="#best">best</a></li><li><a href="#dropwhile">dropWhile</a></li><li><a href="#keep">keep</a></li><li><a href="#nth">nth</a></li><li><a href="#partitionby">partitionBy</a></li><li><a href="#second">second</a></li><li><a href="#takewhile">takeWhile</a></li><li><a href="#third">third</a></li></ul></li><li><a href="#collections.walk">collections.walk</a></li><li><a href="#function.arity">function.arity</a><ul><li><a href="#arity">arity</a></li><li><a href="#binary">binary</a></li><li><a href="#curry">curry</a></li><li><a href="#curry2">curry2</a></li><li><a href="#curry3">curry3</a></li><li><a href="#fix">fix</a></li><li><a href="#quaternary">quaternary</a></li><li><a href="#ternary">ternary</a></li><li><a href="#unary">unary</a></li><li><a href="#rcurry">rCurry</a></li><li><a href="#rcurry2">rcurry2</a></li><li><a href="#rcurry3">rcurry3</a></li></ul></li><li><a href="#function.combinators">function.combinators</a><ul><li><a href="#always">always</a></li><li><a href="#bound">bound</a></li><li><a href="#comparator">comparator</a></li><li><a href="#complement">complement</a></li><li><a href="#conjoin">conjoin</a></li><li><a href="#disjoin">disjoin</a></li><li><a href="#juxt">juxt</a></li><li><a href="#flip">flip</a></li><li><a href="#flip2">flip2</a></li><li><a href="#fnull">fnull</a></li><li><a href="#functionalize">functionalize</a></li><li><a href="#mapargs">mapArgs</a></li><li><a href="#mapargswith">mapArgsWith</a></li><li><a href="#methodize">methodize</a></li><li><a href="#pipeline">pipeline</a></li><li><a href="#splat">splat</a></li><li><a href="#unsplat">unsplat</a></li><li><a href="#unsplatl">unsplatl</a></li></ul></li><li><a href="#function.iterators">function.iterators</a><ul><li><a href="#iterators.accumulate">iterators.accumulate</a></li><li><a href="#iterators.accumulatewithreturn">iterators.accumulateWithReturn</a></li><li><a href="#iterators.drop">iterators.drop</a></li><li><a href="#iterators.foldl">iterators.foldl</a></li><li><a href="#iterators.k">iterators.K</a></li><li><a href="#iterators.list">iterators.List</a></li><li><a href="#iterators.map">iterators.map</a></li><li><a href="#iterators.mapcat">iterators.mapcat</a></li><li><a href="#iterators.numbers">iterators.numbers</a></li><li><a href="#iterators.range">iterators.range</a></li><li><a href="#iterators.reject">iterators.reject</a></li><li><a href="#iterators.select">iterators.select</a></li><li><a href="#iterators.slice">iterators.slice</a></li><li><a href="#iterators.take">iterators.take</a></li><li><a href="#iterators.tree">iterators.Tree</a></li><li><a href="#iterators.unfold">iterators.unfold</a></li><li><a href="#iterators.unfoldwithreturn">iterators.unfoldWithReturn</a></li></ul></li><li><a href="#function.predicates">function.predicates</a><ul><li><a href="#isassociative">isAssociative</a></li><li><a href="#isdecreasing">isDecreasing</a></li><li><a href="#iseven">isEven</a></li><li><a href="#isfloat">isFloat</a></li><li><a href="#isincreasing">isIncreasing</a></li><li><a href="#isindexed">isIndexed</a></li><li><a href="#isinstanceof">isInstanceOf</a></li><li><a href="#isinteger">isInteger</a></li><li><a href="#isjson">isJSON</a></li><li><a href="#isnegative">isNegative</a></li><li><a href="#isnumeric">isNumeric</a></li><li><a href="#isodd">isOdd</a></li><li><a href="#isplainobject">isPlainObject</a></li><li><a href="#ispositive">isPositive</a></li><li><a href="#issequential">isSequential</a></li><li><a href="#isvaliddate">isValidDate</a></li><li><a href="#iszero">isZero</a></li></ul></li><li><a href="#object.builders">object.builders</a><ul><li><a href="#frequencies">frequencies</a></li><li><a href="#merge">merge</a></li><li><a href="#renamekeys">renameKeys</a></li><li><a href="#setpath">setPath</a></li><li><a href="#snapshot">snapshot</a></li></ul></li><li><a href="#object.selectors">object.selectors</a><ul><li><a href="#accessor">accessor</a></li><li><a href="#dictionary">dictionary</a></li><li><a href="#getpath">getPath</a></li><li><a href="#haspath">hasPath</a></li><li><a href="#kv">kv</a></li><li><a href="#omitwhen">omitWhen</a></li><li><a href="#pickwhen">pickWhen</a></li><li><a href="#selectkeys">selectKeys</a></li></ul></li><li><a href="#util.existential">util.existential</a><ul><li><a href="#exists">exists</a></li><li><a href="#falsey">falsey</a></li><li><a href="#firstexisting">firstExisting</a></li><li><a href="#not">not</a></li><li><a href="#truthy">truthy</a></li></ul></li><li><a href="#util.operators">util.operators</a><ul><li><a href="#add">add</a></li><li><a href="#bitwiseand">bitwiseAnd</a></li><li><a href="#bitwiseleft">bitwiseLeft</a></li><li><a href="#bitwiseright">bitwiseRight</a></li><li><a href="#bitwisenot">bitwiseNot</a></li><li><a href="#bitwiseor">bitwiseOr</a></li><li><a href="#bitwisexor">bitwiseXor</a></li><li><a href="#bitwisez">bitwiseZ</a></li><li><a href="#dec">dec</a></li><li><a href="#div">div</a></li><li><a href="#eq">eq</a></li><li><a href="#gt">gt</a></li><li><a href="#gte">gte</a></li><li><a href="#inc">inc</a></li><li><a href="#lt">lt</a></li><li><a href="#lte">lte</a></li><li><a href="#mul">mul</a></li><li><a href="#mod">mod</a></li><li><a href="#neg">neg</a></li><li><a href="#neq">neq</a></li><li><a href="#not-1">not</a></li><li><a href="#seq">seq</a></li><li><a href="#sneq">sneq</a></li><li><a href="#sub">sub</a></li></ul></li><li><a href="#util.strings">util.strings</a><ul><li><a href="#camelcase">camelCase</a></li><li><a href="#explode">explode</a></li><li><a href="#fromquery">fromQuery</a></li><li><a href="#implode">implode</a></li><li><a href="#strcontains">strContains</a></li><li><a href="#todash">toDash</a></li><li><a href="#toquery">toQuery</a></li></ul></li><li><a href="#util.trampolines">util.trampolines</a></li><li><a href="#changelog">Changelog</a><ul><li><a href="#0.3.0">0.3.0</a></li></ul></li></ul></li></ul></div>
<h1 id="underscore-contrib-0-3-0-">Underscore-contrib (0.3.0)</h1>
<blockquote>
<p>The brass buckles on Underscore's utility belt - a contributors' library for <a href="http://underscorejs.org/">Underscore</a>.</p>
</blockquote>
<h2 id="introduction"><a href="#introduction" name="introduction">Introduction</a></h2>
<h3 id="places"><a href="#places" name="places">Places</a></h3>
<ul>
<li><a href="http://documentcloud.github.io/underscore-contrib/">Documentation</a></li>
<li><a href="https://github.com/documentcloud/underscore-contrib">Source repository</a></li>
<li><a href="https://github.com/documentcloud/underscore-contrib/issues?state=open">Tickets and bug reports</a></li>
<li><a href="http://www.fogus.me">Maintainer's website</a></li>
</ul>
<h3 id="why-underscore-contrib-"><a href="#why-underscore-contrib" name="why-underscore-contrib">Why underscore-contrib?</a></h3>
<p>While Underscore provides a bevy of useful tools to support functional programming in JavaScript, it can't
(and shouldn't) be everything to everyone. Underscore-contrib is intended as a home for functions that, for
various reasons, don't belong in Underscore proper. In particular, it aims to be:</p>
<ul>
<li>a home for functions that are limited in scope, but solve certain point problems, and</li>
<li>a proving ground for features that belong in Underscore proper, but need some advocacy and/or evolution
(or devolution) to get them there.</li>
</ul>
<h3 id="use"><a href="#use" name="use">Use</a></h3>
<h4 id="in-the-browser"><a href="#in-the-browser" name="in-the-browser">In the Browser</a></h4>
<p>First, you'll need Underscore <strong>version 1.6.0 or higher</strong>. Then you can grab the relevant underscore-contrib sub-libraries and simply add something like
the following to your pages:</p>
<pre><code class="lang-html"><script type="text/javascript" src="underscore.js"></script>
<script type="text/javascript" src="underscore.object.builders.js"></script></code></pre>
<p>At the moment there are no cross-contrib dependencies (i.e. each sub-library
can stand by itself), but that may change in the future.</p>
<h4 id="in-node-js"><a href="#in-node.js" name="in-node.js">In Node.js</a></h4>
<p>Using contrib in Node is very simple. Just install it with npm:</p>
<pre><code>npm install underscore-contrib --save</code></pre>
<p>Then require it within your project like so:</p>
<pre><code class="lang-javascript">var _ = require('underscore-contrib');</code></pre>
<p>The <code>_</code> variable will be a copy of Underscore with contrib's methods already
mixed in.</p>
<h3 id="license"><a href="#license" name="license">License</a></h3>
<p>_.contrib is open sourced under the <a href="https://github.com/documentcloud/underscore-contrib/blob/master/LICENSE">MIT license</a>.</p>
<h2 id="sub-libraries"><a href="#sub-libraries" name="sub-libraries">Sub-libraries</a></h2>
<p>The _.contrib library currently contains a number of related capabilities, aggregated into the following files.</p>
<ul>
<li><a href="#array.builders">underscore.array.builders</a> - functions to build arrays</li>
<li><a href="#array.selectors">underscore.array.selectors</a> - functions to take things from arrays</li>
<li><a href="#collections.walk">underscore.collections.walk</a> - functions to walk and transform nested JavaScript objects</li>
<li><a href="#function.arity">underscore.function.arity</a> - functions to manipulate and fix function argument arity</li>
<li><a href="#function.combinators">underscore.function.combinators</a> - functions to combine functions to make new functions</li>
<li><a href="#function.iterators">underscore.function.iterators</a> - functions to lazily produce, manipulate and consume sequence iterators</li>
<li><a href="#function.predicates">underscore.function.predicates</a> - functions that return <code>true</code> or <code>false</code> based on some criteria</li>
<li><a href="#object.builders">underscore.object.builders</a> - functions to build JavaScript objects</li>
<li><a href="#object.selectors">underscore.object.selectors</a> - functions to pick things from JavaScript objects</li>
<li><a href="#util.existential">underscore.util.existential</a> - functions that check for the existence or truthiness of JavaScript data types</li>
<li><a href="#util.operators">underscore.util.operators</a> - functions that wrap common (or missing) JavaScript operators</li>
<li><a href="#util.strings">underscore.util.strings</a> - functions to work with strings</li>
<li><a href="#util.trampolines">underscore.util.trampolines</a> - functions to facilitate calling functions recursively without blowing the stack</li>
</ul>
<p>The links above are to the annotated source code. Full-blown _.contrib documentation is in the works. Contributors welcomed.</p>
<h3 id="array-builders"><a href="#array.builders" name="array.builders">array.builders</a></h3>
<blockquote>
<p>Functions to build arrays. <a href="docs/underscore.array.builders.js.html" class="btn btn-primary btn-xs">View Annotated Source</a></p>
</blockquote>
<hr>
<h4 id="cat"><a href="#cat" name="cat">cat</a></h4>
<p>Signature: <code>_.cat(... arrays:Array ...)</code></p>
<p>The <code>_.cat</code> function provides a way to concatenate zero or more heterogeneous arrays into one.</p>
<pre><code class="lang-javascript">_.cat(); // 0-args
//=> []
_.cat([]); // 1-arg, empty array
//=> []
_.cat([1,2,3]); // 1-arg
//=> [1,2,3]
_.cat([1,2,3],[4,5,6]); // 2-args
//=> [1,2,3,4,5,6]
_.cat([1,2,3],[4,5,6],[7]); // 3+ args
//=> [1,2,3,4,5,6,7]</code></pre>
<p>Not every argument to <code>_.cat</code> needs to be an array; other types are accepted.</p>
<p>Signature: <code>_.cat(... elems:Any ...)</code></p>
<pre><code class="lang-javascript">_.cat(1,[2],3,4); // mixed args
//=> [1,2,3,4]</code></pre>
<p>The <code>_.cat</code> function will also work with the <code>arguments</code> object as if it were an array.</p>
<p>Signature: <code>_.cat(... elems:Arguments ...)</code></p>
<pre><code class="lang-javascript">function f(){ return _.cat(arguments, 4,5,6); }
f(1,2,3);
//=> [1,2,3,4,5,6]</code></pre>
<hr>
<h4 id="chunk"><a href="#chunk" name="chunk">chunk</a></h4>
<p>The <code>_.chunk</code> function, by default, accepts an array and a number and splits and returns a new array representing the original array split into some number of arrays of the given size:</p>
<pre><code class="lang-javascript">_.chunk([0,1,2,3], 2);
//=> , [[0,1],[2,3]]</code></pre>
<p>If the original array cannot completely fulfill the chunk scheme then the array returned will drop the undersized final chunk:</p>
<pre><code class="lang-javascript">_.chunk([0,1,2,3,4], 2);
//=> , [[0,1],[2,3]]</code></pre>
<p>You can pass an optional third argument to <code>_.chunk</code> to pad out the final array chunk should it fall short. If the value given as the third argument is <em>not</em> an array then it is repeated the needed number of times:</p>
<pre><code class="lang-javascript">_.chunk([0,1,2,3,4], 3, '_');
//=> , [[0,1,2],[3,'_','_']]</code></pre>
<p>If you given an array as the optional third argument then that array is used to pad in-place as needed:</p>
<pre><code class="lang-javascript">_.chunk([0,1,2,3,4], 3, ['a', 'b']);
//=> , [[0,1,2],[3,'a','b']]</code></pre>
<hr>
<h4 id="chunkall"><a href="#chunkall" name="chunkall">chunkAll</a></h4>
<p>The <code>_.chunkAll</code> function is similar to <code>_.chunk</code> except for the following. First, <code>_.chunkAll</code> will never drop short chunks from the end:</p>
<pre><code class="lang-javascript">_.chunkAll([0,1,2,3,4], 3);
//=> , [[0,1,2],[3]]</code></pre>
<p>Also, <code>_.chunkAll</code> takes an optional third argument signifying that paritions should be built from skipped regions:</p>
<pre><code class="lang-javascript">_.chunkAll(_.range(1), 2, 4);
//=> [[0,1],[4,5],[8,9]]</code></pre>
<hr>
<h4 id="cons"><a href="#cons" name="cons">cons</a></h4>
<p>Signature: <code>_.cons(head:Any, tail:Array)</code></p>
<p>The <code>_.cons</code> function provides a way to "construct" a new array by taking some element and putting it at the front of another array.</p>
<pre><code class="lang-javascript">_.cons(0, []);
//=> [0]
_.cons(1, [2]);
//=> [1,2]
_.cons([0], [1,2,3]);
//=> [0,1,2,3]</code></pre>
<p>The <code>_.cons</code> function also can be used to create pairs if the second argument is not an array.</p>
<p>Signature: <code>_.cons(head:Any, tail:Any)</code></p>
<pre><code class="lang-javascript">_.cons(1, 2);
//=> [1,2]
_.cons([1], 2);
//=> [[1],2]</code></pre>
<p>Finally, <code>_.cons</code> will operate with the <code>arguments</code> object.</p>
<p>Signature: <code>_.cons(head:Any, tail:Arguments)</code></p>
<pre><code class="lang-javascript">function f() { return _.cons(0, arguments) }
f(1,2,3);
//=> [0,1,2,3]</code></pre>
<hr>
<h4 id="cycle"><a href="#cycle" name="cycle">cycle</a></h4>
<p>The <code>_.cycle</code> function takes an integer value used to build an array of that size containing the number of iterations through the given array, strung end-to-end as many times as needed. An example is probably more instructive:</p>
<pre><code class="lang-javascript">_.cycle(5, [1,2,3]);
//=> [1,2,3,1,2]</code></pre>
<hr>
<h4 id="interpose"><a href="#interpose" name="interpose">interpose</a></h4>
<p>The <code>_.interpose</code> function takes an array and an element and returns a new array with the given element inserted betwixt every element in the original array:</p>
<pre><code class="lang-javascript">_.interpose([1,2,3], 0);
//=> [1,0,2,0,3]</code></pre>
<p>If there are no betweens (i.e. empty and single-element arrays), then the original array is returned:</p>
<pre><code class="lang-javascript">_.interpose([1], 0);
//=> [1]
_.interpose([], 0);
//=> []</code></pre>
<hr>
<h4 id="iterateuntil"><a href="#iterateuntil" name="iterateuntil">iterateUntil</a></h4>
<p>The <code>_.iterateUntil</code> function takes a function used as a result generator, a function used as a stop-check and a seed value and returns an array of each generated result. The operation of <code>_.iterateUntil</code> is such that the result generator is passed the seed to start and each subsequent result which will continue <strong>until</strong> a result fails the check function (i.e. returns falsey). An example is best:</p>
<pre><code class="lang-javascript">var dec = function(n) { return n - 1; };
var isPos = function(n) { return n > 0; };</code></pre>
<p>The <code>dec</code> result generator takes a number and decrements it by one. The <code>isPos</code> predicate takes a number and returns <code>true</code> if it's positive. Using these two functions you can build an array of every number from <code>6</code> to <code>0</code>, inclusive:</p>
<pre><code class="lang-javascript">_.iterateUntil(dec, isPos, 6);
//=> [5,4,3,2,1]</code></pre>
<p>That is, the array only contains every number from <code>5</code> down to <code>1</code> because when the result of <code>dec</code> got to <code>0</code> the <code>isPos</code> check failed (i.e. went falsey) thus terminating the execution.</p>
<hr>
<h4 id="keepindexed"><a href="#keepindexed" name="keepindexed">keepIndexed</a></h4>
<p>The <code>_.keepIndexed</code> function takes an array and a function and returns a new array filled with the <em>non-null</em> return results of the given function on the elements or keys in the given array:</p>
<pre><code class="lang-javascript">_.keepIndexed([1,2,3], function(k) {
return i === 1 || i === 2;
});
//=> [false, true, true]</code></pre>
<p>If you return either <code>null</code> or <code>undefined</code> then the result is dropped from the resulting array:</p>
<pre><code class="lang-javascript">_.keepIndexed(['a','b','c'], function(k, v) {
if (k === 1) return v;
});
//=> ['b']</code></pre>
<hr>
<h4 id="mapcat"><a href="#mapcat" name="mapcat">mapcat</a></h4>
<p>There are times when a mapping operation produces results contained in arrays, but the final result should be flattened one level. For these circumstances you can use <code>_.mapcat</code> to produce results:</p>
<pre><code class="lang-javascript">var array = [1,2,null,4,undefined,6];
var errors = _.mapcat(array, function(e,i) {
if (e == null) {
return ["Element @" + i + " is bad"];
}
else {
return [];
}
});</code></pre>
<p>Inspecting the contents of <code>errors</code> shows:</p>
<pre><code class="lang-javascript">["Element @2 is bad", "Element @4 is bad"]</code></pre>
<p>The <code>_.mapcat</code> function is equivalent to <code>_.cat.apply(array, _.map(array,fun))</code>.</p>
<hr>
<h4 id="reductions"><a href="#reductions" name="reductions">reductions</a></h4>
<p>The <code>_.reductions</code> function is similar to Underscore's builtin <code>_.reduce</code> function except that it returns an array of every intermediate value in the folding operation:</p>
<pre><code class="lang-javascript">_.reductions([1,2,3,4,5], function(agg, n) {
return agg + n;
}, 0);
//=> [1,3,6,10,15]</code></pre>
<p>The last element in the array returned from <code>_.reductions</code> is the answer that you would get if you had just chosen to use <code>_.reduce</code>.</p>
<hr>
<h4 id="repeat"><a href="#repeat" name="repeat">repeat</a></h4>
<p>Signature: <code>_.repeat(t:Integer, value:Any)</code></p>
<p>The <code>_.repeat</code> function takes an integer value used to build an array of that size containing the value given:</p>
<pre><code class="lang-javascript">_.repeat(5, 'a');
//=> ['a','a','a','a','a']</code></pre>
<hr>
<h4 id="splitat"><a href="#splitat" name="splitat">splitAt</a></h4>
<p>The <code>_.splitAt</code> function takes an array and a numeric index and returns a new array with two embedded arrays representing a split of the original array at the index provided:</p>
<pre><code class="lang-javascript">_.splitAt([1,2,3,4,5], 2);
//=> [[1,2],[3,4,5]]
_.splitAt([1,2,3,4,5], 0);
//=> [[],[1,2,3,4,5]]</code></pre>
<p>The operation of <code>_.splitAt</code> is safe if the index provided is outside the range of legal indices:</p>
<pre><code class="lang-javascript">_.splitAt([1,2,3,4,5], 20000);
//=> [[1,2,3,4,5],[]]
_.splitAt([1,2,3,4,5], -1000);
//=> [[],[1,2,3,4,5]]
_.splitAt([], 0);
//=> [[],[]]</code></pre>
<hr>
<h4 id="takeskipping"><a href="#takeskipping" name="takeskipping">takeSkipping</a></h4>
<p>The <code>_.takeSkipping</code> function takes an array and a number and returns a new array containing every nth element in the original array:</p>
<pre><code class="lang-javascript">_.takeSkipping(_.range(10), 2);
//=> [0,2,4,6,8]</code></pre>
<p>The <code>_.takeSkipping</code> function is safe against numbers larger or smaller than the array size:</p>
<pre><code class="lang-javascript">_.takeSkipping(_.range(10), 100000);
//=> [0]
_.takeSkipping(_.range(10), -100);
//=> []</code></pre>
<hr>
<h4 id="weave"><a href="#weave" name="weave">weave</a></h4>
<p>The <code>_.weave</code> function works similarly to <code>_.interpose</code> (shown above) except that it accepts an array used as the interposition values. In other words, <code>_.weave</code> takes two arrays and returns a new array with the original elements woven together. An example would help:</p>
<pre><code class="lang-javascript">_.weave(['a','b','c'], [1,2,3]);
//=> ['a',1,'b',2,'c',3]</code></pre>
<p>The array returned from <code>_.weave</code> will be as long as the longest array given with the woven entries stopping according to the shortest array:</p>
<pre><code class="lang-javascript">_.weave(['a','b','c'], [1]);
//=> ['a',1,'b','c']</code></pre>
<p>The <code>_.interleave</code> function is an alias for <code>_.weave</code>.</p>
<hr>
<h3 id="array-selectors"><a href="#array.selectors" name="array.selectors">array.selectors</a></h3>
<blockquote>
<p>Functions to take things from arrays. <a href="docs/underscore.array.selectors.js.html" class="btn btn-primary btn-xs">View Annotated Source</a></p>
</blockquote>
<hr>
<h4 id="best"><a href="#best" name="best">best</a></h4>
<p><strong>Signature:</strong> <code>_.best(array:Array, fun:Function)</code></p>
<p>Returns the "best" value in an array based on the result of a given function.</p>
<pre><code class="lang-javascript">_.best([1, 2, 3, 4, 5], function(x, y) {
return x > y;
});
//=> 5</code></pre>
<hr>
<h4 id="dropwhile"><a href="#dropwhile" name="dropwhile">dropWhile</a></h4>
<p><strong>Signature:</strong> <code>_.dropWhile(array:Array, pred:Function)</code></p>
<p>Drops elements for which the given function returns a truthy value.</p>
<pre><code class="lang-javascript">_.dropWhile([-2,-1,0,1,2], isNeg);
//=> [0,1,2]</code></pre>
<hr>
<h4 id="keep"><a href="#keep" name="keep">keep</a></h4>
<p><strong>Signature:</strong> <code>_.keep(array:Array, fun:Function)</code></p>
<p>Returns an array of existy results of a function over a source array.</p>
<pre><code class="lang-javascript">_.keep([1, 2, 3, 4, 5], function(val) {
if (val % 3 === 0) {
return val;
}
});
// => [3]</code></pre>
<hr>
<h4 id="nth"><a href="#nth" name="nth">nth</a></h4>
<p><strong>Signature:</strong> <code>_.nth(array:Array, index:Number[, guard:Any])</code></p>
<p>The <code>_.nth</code> function is a convenience for the equivalent <code>array[n]</code>. The
optional <code>guard</code> value allows <code>_.nth</code> to work correctly as a callback for
<code>_.map</code>.</p>
<pre><code class="lang-javascript">_.nth(['a','b','c'], 2);
//=> 'c'</code></pre>
<p>If given an index out of bounds then <code>_.nth</code> will return <code>undefined</code>:</p>
<pre><code class="lang-javascript">_.nth(['a','b','c'], 2000);
//=> undefined</code></pre>
<p>The <code>_.nth</code> function can also be used in conjunction with <code>_.map</code> and <code>_.compact</code> like so:</p>
<pre><code class="lang-javascript">var b = [['a'],['b'],[]];
_.compact(_.map(b, function(e) { return _.nth(e,0) }));
//=> ['a','b']</code></pre>
<p>If wrapping a function around <code>_.nth</code> is too tedious or you'd like to partially apply the index then Underscore-contrib offers any of <code>_.flip2</code>, <code>_.fix</code> or <code>rcurry2</code> to solve this.</p>
<hr>
<h4 id="partitionby"><a href="#partitionby" name="partitionby">partitionBy</a></h4>
<p><strong>Signature:</strong> <code>_.keep(array:Array, fun:Function)</code></p>
<p>Takes an array and partitions it into sub-arrays as the given predicate changes
truth sense.</p>
<pre><code class="lang-javascript">_.partitionBy([1,2,2,3,1,1,5], _.isEven);
// => [[1],[2,2],[3,1,1,5]]
_.partitionBy([1,2,2,3,1,1,5], _.identity);
// => [[1],[2,2],[3],[1,1],[5]]</code></pre>
<hr>
<h4 id="second"><a href="#second" name="second">second</a></h4>
<p><strong>Signature:</strong> <code>_.second(array:Array, index:Number[, guard:Any])</code></p>
<p>The <code>_.second</code> function is a convenience for the equivalent <code>array[1]</code>. The
optional <code>guard</code> value allows <code>_.second</code> to work correctly as a callback for
<code>_.map</code>.</p>
<pre><code class="lang-javascript">_.second(['a','b']);
//=> 'b'
_.map([['a','b'], _.range(10,20)], _.second);
//=> ['b',11]</code></pre>
<p>You can also pass an optional number to the <code>_.second</code> function to take a number of elements from an array starting with the second element and ending at the given index:</p>
<pre><code class="lang-javascript">_.second(_.range(10), 5)
//=> [1, 2, 3, 4]</code></pre>
<hr>
<h4 id="takewhile"><a href="#takewhile" name="takewhile">takeWhile</a></h4>
<p><strong>Signature:</strong> <code>_.takeWhile(array:Array, pred:Function)</code></p>
<p>The <code>_.takeWhile</code> function takes an array and a function and returns a new array containing the first n elements in the original array for which the given function returns a truthy value:</p>
<pre><code class="lang-javascript">var isNeg = function(n) { return n < 0; };
_.takeWhile([-2,-1,0,1,2], isNeg);
//=> [-2,-1]</code></pre>
<hr>
<h4 id="third"><a href="#third" name="third">third</a></h4>
<p><strong>Signature:</strong> <code>_.third(array:Array, index:Number[, guard:Any])</code></p>
<p>The <code>_.third</code> function is a convenience for the equivalent <code>array[2]</code>. The
optional <code>guard</code> value allows <code>_.third</code> to work correctly as a callback for
<code>_.map</code>.</p>
<pre><code class="lang-javascript">_.third(['a','b','c']);
//=> 'c'
_.map([['a','b','c'], _.range(10,20)], _.third);
//=> ['c',12]</code></pre>
<p>You can also pass an optional number to the <code>_.third</code> function to take a number of elements from an array starting with the third element and ending at the given index:</p>
<pre><code class="lang-javascript">_.third(_.range(10), 5)
//=> [2, 3, 4]</code></pre>
<hr>
<h3 id="collections-walk"><a href="#collections.walk" name="collections.walk">collections.walk</a></h3>
<blockquote>
<p>Functions to recursively walk collections which are trees.</p>
</blockquote>
<p>Documentation should use <a href="https://github.com/jashkenas/journo">Journo</a> formats and standards.</p>
<pre><code> _.walk = walk;
postorder: function(obj, visitor, context)
preorder: function(obj, visitor, context)
walk(obj, visitor, null, context)
map: function(obj, strategy, visitor, context)
pluck: function(obj, propertyName)
pluckRec: function(obj, propertyName)
_.walk.collect = _.walk.map;</code></pre>
<h3 id="function-arity"><a href="#function.arity" name="function.arity">function.arity</a></h3>
<blockquote>
<p>Functions which manipulate the way functions work with their arguments.</p>
</blockquote>
<hr>
<h4 id="arity"><a href="#arity" name="arity">arity</a></h4>
<p><strong>Signature:</strong> <code>_.arity(numberOfArgs:Number, fun:Function)</code></p>
<p>Returns a new function which is equivalent to <code>fun</code>, except that the new
function's <code>length</code> property is equal to <code>numberOfArgs</code>. This does <strong>not</strong> limit
the function to using that number of arguments. It's only effect is on the
reported length.</p>
<pre><code class="lang-javascript">function addAll() {
var sum = 0;
for (var i = 0; i < arguments.length; i++) {
sum = sum + arguments[i];
}
return sum;
}
addAll.length
// => 0
var addAllWithFixedLength = _.arity(2, addAll);
addAllWithFixedLength.length
// => 2
addAllWithFixedLength(1, 1, 1, 1);
// => 4</code></pre>
<hr>
<h4 id="binary"><a href="#binary" name="binary">binary</a></h4>
<p><strong>Signature:</strong> <code>_.binary(fun:Function)</code></p>
<p>Returns a new function which accepts only two arguments and passes these
arguments to <code>fun</code>. Additional arguments are discarded.</p>
<pre><code class="lang-javascript">function addAll() {
var sum = 0;
for (var i = 0; i < arguments.length; i++) {
sum = sum + arguments[i];
}
return sum;
}
var add2 = _.binary(addAll);
add2(1, 1);
// => 2
add2(1, 1, 1, 1);
// => 2</code></pre>
<hr>
<h4 id="curry"><a href="#curry" name="curry">curry</a></h4>
<p><strong>Signature:</strong> <code>_.curry(func:Function[, reverse:Boolean])</code></p>
<p>Returns a curried version of <code>func</code>. If <code>reverse</code> is true, arguments will be
processed from right to left.</p>
<pre><code class="lang-javascript">function add3 (x, y, z) {
return x + y + z;
}
var curried = _.curry(add3);
// => function
curried(1);
// => function
curried(1)(2);
// => function
curried(1)(2)(3);
// => 6</code></pre>
<hr>
<h4 id="curry2"><a href="#curry2" name="curry2">curry2</a></h4>
<p><strong>Signature:</strong> <code>_.curry2(fun:Function)</code></p>
<p>Returns a curried version of <code>func</code>, but will curry exactly two arguments, no
more or less.</p>
<pre><code class="lang-javascript">function add2 (a, b) {
return a + b;
}
var curried = _.curry2(add2);
// => function
curried(1);
// => function
curried(1)(2);
// => 3</code></pre>
<hr>
<h4 id="curry3"><a href="#curry3" name="curry3">curry3</a></h4>
<p><strong>Signature:</strong> <code>_.curry3(fun:Function)</code></p>
<p>Returns a curried version of <code>func</code>, but will curry exactly three arguments, no
more or less.</p>
<pre><code class="lang-javascript">function add3 (a, b, c) {
return a + b + c;
}
var curried = _.curry3(add3);
// => function
curried(1);
// => function
curried(1)(2);
// => function
curried(1)(2)(3);
// => 6</code></pre>
<hr>
<h4 id="fix"><a href="#fix" name="fix">fix</a></h4>
<p><strong>Signature:</strong> <code>_.fix(fun:Function[, value:Any...])</code></p>
<p>Fixes the arguments to a function based on the parameter template defined by
the presence of values and the <code>_</code> placeholder.</p>
<pre><code class="lang-javascript">function add3 (a, b, c) {
return a + b + c;
}
var fixedFirstAndLast = _.fix(add3, 1, _, 3);
// => function
fixedFirstAndLast(2);
// => 6
fixedFirstAndLast(10);
// => 14</code></pre>
<hr>
<h4 id="quaternary"><a href="#quaternary" name="quaternary">quaternary</a></h4>
<p><strong>Signature:</strong> <code>_.quaternary(fun:Function)</code></p>
<p>Returns a new function which accepts only four arguments and passes these
arguments to <code>fun</code>. Additional arguments are discarded.</p>
<pre><code class="lang-javascript">function addAll() {
var sum = 0;
for (var i = 0; i < arguments.length; i++) {
sum = sum + arguments[i];
}
return sum;
}
var add4 = _.quaternary(addAll);
add4(1, 1, 1, 1);
// => 4
add4(1, 1, 1, 1, 1, 1);
// => 4</code></pre>
<hr>
<h4 id="ternary"><a href="#ternary" name="ternary">ternary</a></h4>
<p><strong>Signature:</strong> <code>_.ternary(fun:Function)</code></p>
<p>Returns a new function which accepts only three arguments and passes these
arguments to <code>fun</code>. Additional arguments are discarded.</p>
<pre><code class="lang-javascript">function addAll() {
var sum = 0;
for (var i = 0; i < arguments.length; i++) {
sum = sum + arguments[i];
}
return sum;
}
var add3 = _.ternary(addAll);
add3(1, 1, 1);
// => 3
add3(1, 1, 1, 1, 1, 1);
// => 3</code></pre>
<hr>
<h4 id="unary"><a href="#unary" name="unary">unary</a></h4>
<p><strong>Signature:</strong> <code>_.unary(fun:Function)</code></p>
<p>Returns a new function which accepts only one argument and passes this
argument to <code>fun</code>. Additional arguments are discarded.</p>
<pre><code class="lang-javascript">function logArgs() {
console.log(arguments);
}
var logOneArg = _.unary(logArgs);
logOneArg("first");
// => ["first"]
logOneArg("first", "second");
// => ["first"]</code></pre>
<hr>
<h4 id="rcurry"><a href="#rcurry" name="rcurry">rCurry</a></h4>
<p><strong>Signature:</strong> <code>_.rCurry(func:Function)</code></p>
<p>Returns a curried version of <code>func</code> where arguments are processed from right
to left.</p>
<pre><code class="lang-javascript">function divide (a, b) {
return a / b;
}
var curried = _.rCurry(divide);
// => function
curried(1);
// => function
curried(1)(2);
// => 2
curried(2)(1);
// => 0.5</code></pre>
<hr>
<h4 id="rcurry2"><a href="#rcurry2" name="rcurry2">rcurry2</a></h4>
<p><strong>Signature:</strong> <code>_.rcurry2(func:Function)</code></p>
<p>Returns a curried version of <code>func</code> where a maxium of two arguments are
processed from right to left.</p>
<pre><code class="lang-javascript">function concat () {
var str = "";
for (var i = 0; i < arguments.length; i++) {
str = str + arguments[i];
}
return str;
}
var curried = _.rcurry2(concat);
// => function
curried("a");
// => function
curried("a")("b");
// => "ba"</code></pre>
<hr>
<h4 id="rcurry3"><a href="#rcurry3" name="rcurry3">rcurry3</a></h4>
<p><strong>Signature:</strong> <code>_.rcurry3(func:Function)</code></p>
<p>Returns a curried version of <code>func</code> where a maxium of three arguments are
processed from right to left.</p>
<pre><code class="lang-javascript">function concat () {
var str = "";
for (var i = 0; i < arguments.length; i++) {
str = str + arguments[i];
}
return str;
}
var curried = _.rcurry3(concat);
// => function
curried("a");
// => function
curried("a")("b");
// => function
curried("a")("b")("c");
// => "cba"</code></pre>
<h3 id="function-combinators"><a href="#function.combinators" name="function.combinators">function.combinators</a></h3>
<blockquote>
<p>Functions that are combinators.</p>
</blockquote>
<hr>
<h4 id="always"><a href="#always" name="always">always</a></h4>
<p><strong>Signature:</strong> <code>_.always(value:Any)</code></p>
<p><strong>Aliases:</strong> <code>_.k</code></p>
<p>Takes <code>value</code> and returns a function that will always return <code>value</code>.</p>
<pre><code class="lang-javascript">var platonicForm = _.always("Eternal & Unchangeable");
platonicForm();
// => "Eternal & Unchangeable"</code></pre>
<hr>
<h4 id="bound"><a href="#bound" name="bound">bound</a></h4>
<p><strong>Signature:</strong> <code>_.bound(obj:Object, fname:String)</code></p>
<p>Returns function property of an object by name, bound to object.</p>
<pre><code class="lang-javascript">var aristotle = {
name: "Aristotle",
telos: "flourishing",
stateTelos: function() {
return this.name + "'s telos is " + this.telos;
}
};
var stateAristotlesTelos = _.bound(aristotle, "stateTelos");
stateAristotlesTelos();
// => "Aristotle's Telos is flourishing"</code></pre>
<hr>
<h4 id="comparator"><a href="#comparator" name="comparator">comparator</a></h4>
<p><strong>Signature:</strong> <code>_.comparator(fun:Function)</code></p>
<p>Takes a binary predicate-like function and returns a comparator function (return
values of <code>-1</code>, <code>0</code>, <code>1</code>) which can be used as a callback for <code>_.sort</code> or
<code>Array.prototype.sort</code>.</p>
<pre><code class="lang-javascript">var lessOrEqual = function(x, y) { return x <= y; };
var arr = [0, 1, -2];
arr.sort(_.comparator(lessOrEqual));
// => [-2, 0, 1]</code></pre>
<hr>
<h4 id="complement"><a href="#complement" name="complement">complement</a></h4>
<p><strong>Signature:</strong> <code>_.complement(pred:Function)</code></p>
<p>Returns a function that reverses the sense of a given predicate-like.</p>
<pre><code class="lang-javascript">function isAugustine (val) {
return val === "Augustine";
}
isNotAugustine = _.complement(isAugustine);
isNotAugustine("Dionysius");
// => True</code></pre>
<hr>
<h4 id="conjoin"><a href="#conjoin" name="conjoin">conjoin</a></h4>
<p><strong>Signature:</strong> <code>_.conjoin(pred:Function...)</code></p>
<p>Composes multiple predicates into a single predicate that checks all elements
of an array for conformance to <strong>all</strong> of the original predicates.</p>
<pre><code class="lang-javascript">function startsWithA (val) {
return val[0] === "A";
}
function endsWithE (val) {
return val[val.length - 1] === "e";
}
var names = ["Aristotle", "Aquinas", "Plato", "Augustine"];
var startsAAndEndsE = _.conjoin(startsWithA, endsWithE);
startsAAndEndsE(names);
// => ["Aristotle", "Augustine"]</code></pre>
<hr>
<h4 id="disjoin"><a href="#disjoin" name="disjoin">disjoin</a></h4>
<p><strong>Signature:</strong> <code>_.disjoin(pred:Function...)</code></p>
<p>Composes multiple predicates into a single predicate that checks all elements
of an array for conformance to <strong>any</strong> of the original predicates.</p>
<pre><code class="lang-javascript">function startsWithA (val) {
return val[0] === "A";
}
function endsWithE (val) {
return val[val.length - 1] === "e";
}
var names = ["Aristotle", "Aquinas", "Plato", "Augustine"];
var startsAOrEndsE = _.disjoin(startsWithA, endsWithE);
startsAOrEndsE(names);
// => ["Aristotle", "Aquinas", "Augustine"]</code></pre>
<hr>
<h4 id="juxt"><a href="#juxt" name="juxt">juxt</a></h4>
<p><strong>Signature:</strong> <code>_.juxt(fun:Function...)</code></p>
<p>Returns a function whose return value is an array of the results of calling
each of the original functions with the arguments.</p>
<pre><code class="lang-javascript">function firstChar (val) {
return val[0];
}
function lastChar (val) {
return val[val.length - 1];
}
var firstAndLastChars = _.juxt(firstChar, lastChar);
firstAndLastChars("Etruria");
// => ["E", "a"]</code></pre>
<hr>
<h4 id="flip"><a href="#flip" name="flip">flip</a></h4>
<p><strong>Signature:</strong> <code>_.flip(fun:Function)</code></p>
<p>Returns a function that works identically to <code>fun</code>, but accepts the arguments
in reverse order.</p>
<pre><code class="lang-javascript">function regionCapitol (region, capitol) {
return "The capitol of " + region + " is " + capitol;
}
capitolRegion = _.flip(regionCapitol);
capitolRegion("Thessalonica", "Illyrica");
// => "The capitol of Illyrica is Thessalonica"</code></pre>
<hr>
<h4 id="flip2"><a href="#flip2" name="flip2">flip2</a></h4>
<p><strong>Signature:</strong> <code>_.flip2(fun:Function)</code></p>
<p>Returns a function that works identically to <code>fun</code>, but accepts the first two
arguments in reverse order. The order of all other arguments remains the same.</p>
<pre><code class="lang-javascript">function regionCapitol (region, capitol) {
return "The capitol of " + region + " is " + capitol;
}
capitolRegion = _.flip2(regionCapitol);
capitolRegion("Thessalonica", "Illyrica");
// => "The capitol of Illyrica is Thessalonica"</code></pre>
<hr>
<h4 id="fnull"><a href="#fnull" name="fnull">fnull</a></h4>
<p><strong>Signature:</strong> <code>_.fnull(fun:Function[, default:Any...])</code></p>
<p>Returns a function that protects <code>fun</code> from receiving non-existy values. Each
subsequent value provided to <code>fnull</code> acts as the default to the original
<code>fun</code> should a call receive non-existy values in the defaulted arg slots.</p>
<pre><code class="lang-javascript">function getLength (val) {
return val.length;
}
safeGetLength = _.fnull(getLength, []);
safeGetLength([1, 2, 3]);
// => 3
safeGetLength(null);
// => 0</code></pre>
<hr>
<h4 id="functionalize"><a href="#functionalize" name="functionalize">functionalize</a></h4>
<p><strong>Signature:</strong> <code>_.functionalize(fun:Function[, default:Any...])</code></p>
<p>Takes a method-style function (one which uses <code>this</code>) and pushes <code>this</code> into the
argument list. The returned function uses its first argument as the
receiver/context of the original function, and the rest of the arguments are
used as the original's entire argument list.</p>
<pre><code class="lang-javascript">var militaryUnits = {
centuria: "80 men",
cohort: "480 men",
getDescription: function (unitName) {
return this[unitName];
}
};
var getDescription = _.functionalize(militaryUnits.getDescription);
var rulers = {
Leonidas: "King of Sparta",
Augustus: "First Roman Emperor"
};
getDescription(rulers, "Augustus");
// => "First Roman Emperor"</code></pre>
<hr>
<h4 id="mapargs"><a href="#mapargs" name="mapargs">mapArgs</a></h4>
<p><strong>Signature:</strong> <code>_.mapArgs(fun:Function)</code></p>
<p>Takes a target function and returns a new function which accepts a mapping
function, which in turn returns a function that will map its arguments before
calling the original target function.</p>
<pre><code class="lang-javascript">function doubleNum (x) { return 2 * x; }
function squareNum (x) { return x * x; }
var squareThenDouble = _.mapArgs(doubleNum)(squareNum);
squareThenDouble(3);
// => 18</code></pre>
<hr>
<h4 id="mapargswith"><a href="#mapargswith" name="mapargswith">mapArgsWith</a></h4>
<p><strong>Signature:</strong> <code>_.mapArgs(mapFun:Function)</code></p>
<p>Takes a mapping function and returns a new combinator function which will take
a target function and return a new version which maps its arguments with the
mapping function before executing the body of the target function.</p>
<pre><code class="lang-javascript">function doubleNum (x) { return 2 * x; }
function squareNum (x) { return x * x; }
var squareArgs = _.mapArgsWith(squareNum);
var squareThenDouble = squareArgs(doubleNum);
squareThenDouble(3);
// => 18</code></pre>
<hr>
<h4 id="methodize"><a href="#methodize" name="methodize">methodize</a></h4>
<p><strong>Signature:</strong> <code>_.methodize(func:Function)</code></p>
<p>Takes a function and pulls the first argument out of the argument list and into
<code>this</code> position. The returned function calls the original with its receiver
(<code>this</code>) prepending the argument list. The original is called with a receiver
of <code>null</code>.</p>
<pre><code class="lang-javascript">function describe (obj) {
return obj.name + ": " + obj.description;
}
var democritus = {
name: "Democritus",
description: "originator of the atomic hypothesis",
describe: _.methodize(describe)
};
democritus.describe();
// => "Democritus: originator of the atomic hypothesis"</code></pre>
<hr>
<h4 id="pipeline"><a href="#pipeline" name="pipeline">pipeline</a></h4>
<p><strong>Signature:</strong> <code>_.pipeline(func:Function[, func2:Function...])</code> or <code>_.pipeline(funcArr:Array)</code></p>
<p><strong>Aliases:</strong> <code>_.t</code></p>
<p>Takes a list of functions, either as an array or as individual arguments
and returns a function that takes some value as its first argument and runs it
through a pipeline of the original functions given.</p>
<pre><code class="lang-javascript">function halveNum (x) { return x / 2; };
function squareNum (x) { return x * x; };
function doubleNum (x) { return 2 * x; };
var halveSquareDouble = _.pipeline(halveNum, squareNum, doubleNum);
halveSquareDouble(1);
// => 0.5
var doubleSquareHalve = _.pipeline([doubleNum, squareNum, halveNum]);
doubleSquareHalve(1);
// => 2</code></pre>
<hr>
<h4 id="splat"><a href="#splat" name="splat">splat</a></h4>
<p><strong>Signature:</strong> <code>_.splat(fun:Function)</code></p>
<p>Takes a function expecting one or more arguments and returns a function
that takes an array and uses its elements as the arguments to the original
function. This roughly corresponds to the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator">spread operator</a> in
ECMAScript 6.</p>
<pre><code class="lang-javascript">function listTwoNames (a, b) {
return a.name + " & " + b.name;
}
var listTwoNamesFromArray = _.splat(listTwoNames);
listTwoNamesFromArray([{ name: "Zeno" }, { name: "Parmenides"}]);
// => "Zeno & Parmenides"</code></pre>
<hr>
<h4 id="unsplat"><a href="#unsplat" name="unsplat">unsplat</a></h4>
<p><strong>Signature:</strong> <code>_.unsplat(fun:Function)</code></p>
<p><strong>Aliases:</strong> <code>_.unsplatr</code></p>
<p>Takes a function expecting an array as its <em>last</em> argument and returns a function
which works identically, but takes a list of trailing arguments instead. Roughly
corresponds to <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/rest_parameters">rest parameters</a> in ECMAScript 6.</p>
<pre><code class="lang-javascript">function joinWith (joiner, arr) {
return arr.join(joiner);
}
var joinArgsWith = _.unsplat(joinWith);
joinArgsWith(" & ", "Plutarch", "Proclus");
// => "Plutarch & Proclus"</code></pre>
<hr>
<h4 id="unsplatl"><a href="#unsplatl" name="unsplatl">unsplatl</a></h4>
<p><strong>Signature:</strong> <code>_.unsplatl(fun:Function)</code></p>
<p>Similar to <a href="#unsplat">unsplat</a>, but takes a function expecting an array as its
<em>first</em> argument and returns a function which works identically, but takes a
list of leading arguments instead. Roughly corresponds to
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/rest_parameters">rest parameters</a> in ECMAScript 6.</p>
<pre><code class="lang-javascript">function joinWith (arr, joiner) {
return arr.join(joiner);
}
var joinArgsWith = _.unsplat(joinWith);
joinArgsWith("Olympiodorus", "Syrianus", " & ");
// => "Olympiodorus & Syrianus"</code></pre>
<hr>
<h3 id="function-iterators"><a href="#function.iterators" name="function.iterators">function.iterators</a></h3>
<blockquote>
<p>Functions to iterate over collections.</p>
</blockquote>
<hr>
<h4 id="iterators-accumulate"><a href="#iterators.accumulate" name="iterators.accumulate">iterators.accumulate</a></h4>
<p><strong>Signature:</strong> <code>_.iterators.accumulate(iter:Function, binaryFn:Function, initial:Any)</code></p>
<p>Returns a function that when called will iterate one step with <code>iter</code> and return
the value currently accumulated by using <code>binaryFn</code>. The function will return <code>undefined</code> once all values have been iterated over.</p>
<pre><code class="lang-javascript">var generalsIterator = _.iterators.List(["Hannibal", "Scipio"]);
function countLetters(memo, element) {
return memo + element.length;
}
var generalsAcc = _.iterators.accumulate(generalsIterator, countLetters, 0);
generalsAcc();
// => 8
generalsAcc();
// => 14
generalsAcc();
// => undefined</code></pre>
<hr>
<h4 id="iterators-accumulatewithreturn"><a href="#iterators.accumulatewithreturn" name="iterators.accumulatewithreturn">iterators.accumulateWithReturn</a></h4>
<p><strong>Signature:</strong> <code>_.iterators.accumulateWithReturn(iter:Function, binaryFn:Function, initial:Any)</code></p>
<p>Acts similarly to accumulate, except that <code>binaryFn</code> is expected to return an
array of two elements. The value of the first element is given to the next run
of <code>binaryFn</code>. The value of the second element is yielded by the iterator.</p>
<pre><code class="lang-javascript">var fiveIter = _.iterators.List([1, 2, 3, 4, 5]);
function adderWithMessage (state, element) {
return [state + element, 'Total is ' + (state + element)];
}
var i = _.iterators.accumulateWithReturn(fiveIter, adderWithMessage, 0);
i();
// => "Total is 1"
i();
// => "Total is 3"
i();
// => "Total is 6"</code></pre>
<hr>
<h4 id="iterators-drop"><a href="#iterators.drop" name="iterators.drop">iterators.drop</a></h4>
<p><strong>Signature:</strong> <code>_.iterators.drop(iter:Function[, numberToDrop:Number])</code></p>
<p>Given an iterator function <code>iter</code>, will return a new iterator which iterates
over the same values as <code>iter</code>, except that the first <code>numberToDrop</code> values
will be omitted. If <code>numberToDrop</code> is not provided, it will default to <code>1</code>.</p>
<pre><code class="lang-javascript">var deityIter = _.iterators.List(["Zeus", "Apollo", "Athena", "Aphrodite"]);
var goddessIter = _.iterators.drop(deityIter, 2);
goddessIter();
// => "Athena"
goddessIter();
// => "Aphrodite"</code></pre>
<hr>
<h4 id="iterators-foldl"><a href="#iterators.foldl" name="iterators.foldl">iterators.foldl</a></h4>
<p><strong>Signature:</strong> <code>_.iterators.foldl(iter:Function, binaryFn:Function[, seed:Any])</code></p>
<p><strong>Aliases:</strong> <code>iterators.reduce</code></p>
<p>Boils down the values given by <code>iter</code> into a single value. The <code>seed</code> is the
initial state. The <code>binaryFn</code> is given two arguments: the <code>seed</code> and the
current value yielded by <code>iter</code>.</p>
<pre><code class="lang-javascript">var sybylIter = _.iterators.List(["cumaean", "tiburtine"]);
function commaString (a, b) { return a + ", " + b; }
_.iterators.foldl(sybylIter, commaString);
// => "cumaean, tiburtine"</code></pre>
<hr>
<h4 id="iterators-k"><a href="#iterators.k" name="iterators.k">iterators.K</a></h4>
<p><strong>Signature:</strong> <code>_.iterators.K(value:Any)</code></p>
<p><strong>Aliases:</strong> <code>iterators.constant</code></p>
<p>Returns a function that when invoked will always return <code>value</code>.</p>
<pre><code class="lang-javascript">var ceasar = _.iterators.K("Ceasar");
ceasar();
// => "ceasar"</code></pre>
<hr>
<h4 id="iterators-list"><a href="#iterators.list" name="iterators.list">iterators.List</a></h4>
<p><strong>Signature:</strong> <code>_.iterators.List(array:Array)</code></p>
<p>Returns an iterater that when invoked will iterate over the contents of <code>array</code>.</p>
<pre><code class="lang-javascript">var triumvirIter = _.iterators.List(["Ceasar", "Pompey", "Crassus"];
triumvirIter();
// => "Ceasar"
triumvirIter();
// => "Pompey"
triumvirIter();
// => "Crassus"</code></pre>
<hr>
<h4 id="iterators-map"><a href="#iterators.map" name="iterators.map">iterators.map</a></h4>
<p><strong>Signature:</strong> <code>_.iterators.map(iter:Function, unaryFn:Function)</code></p>
<p>Returns a new iterator function which on each iteration will return the result
of running <code>iter</code>'s current value through <code>unaryFn</code>.</p>
<pre><code class="lang-javascript">var notablesIter = _.iterators.List(["Socrates", "Plato"]);
function postfixAthenian (val) {
return val + ", Athenian";
}
var notableAtheniansIter = _.iterators.map(notablesIter, postfixAthenian);
notableAtheniansIter();
// => "Socrates, Athenian"
notableAtheniansIter();
// => "Plato, Athenian"</code></pre>
<hr>
<h4 id="iterators-mapcat"><a href="#iterators.mapcat" name="iterators.mapcat">iterators.mapcat</a></h4>
<p><strong>Signature:</strong> <code>_.iterators.mapcat(iter:Function, unaryFn:Function)</code></p>
<p>Returns an iterator which is the result of flattening the contents of <code>iter</code>,
and mapping the results with <code>unaryFn</code>.</p>
<pre><code class="lang-javascript">function naturalSmallerThan (x) {
return _.iterators.List(_.range(0, x));
}
var treeIter = _.iterators.Tree([1, [2]]);
var smallerThanIter = _.iterators.mapcat(treeIter, naturalSmallerThan);
smallerThanIter();
// => 0
smallerThanIter();
// => 0
smallerThanIter();
// => 1</code></pre>
<hr>
<h4 id="iterators-numbers"><a href="#iterators.numbers" name="iterators.numbers">iterators.numbers</a></h4>
<p><strong>Signature:</strong> <code>_.iterators.numbers([start:Number])</code></p>
<p>Returns an iterator of integers which will begin with <code>start</code> and increment by
one for each invocation. If <code>start</code> is not provided it will default to <code>1</code>.</p>
<pre><code class="lang-javascript">var twoAndUp = _.iterators.numbers(2);
twoAndUp();
// => 2
twoAndUp();
// => 3
twoAndUp();
// => 4</code></pre>
<hr>
<h4 id="iterators-range"><a href="#iterators.range" name="iterators.range">iterators.range</a></h4>
<p><strong>Signature:</strong> `_.iterators.range([from:Number, to:Number, by:Number]);</p>
<p>Returns an iterator whose values consist of numbers beginning with <code>from</code>, ending with <code>to</code>, in steps of size <code>by</code>.</p>
<pre><code class="lang-javascript">var by5 = _.iterators.range(5, Infinity, 5);
by5();
// => 5
by5();
// => 10
by5();
// => 15</code></pre>
<hr>
<h4 id="iterators-reject"><a href="#iterators.reject" name="iterators.reject">iterators.reject</a></h4>
<p><strong>Signature:</strong> <code>_.iterators.reject(iter:Function, unaryPredicatFn:Function)</code></p>
<p>Returns an iterator consisting of the values of <code>iter</code> which are not flagged
<code>true</code> by <code>unaryPredicateFn</code>.</p>
<pre><code class="lang-javascript">var philosophers = ["Anaximander", "Socrates", "Heraclitus"];
var philosophersIter = _.iterators.List(philosophers);
function isSocrates (val) {
return val === "Socrates";
}
var preSocraticsIter = _.iterators.reject(philosophersIter, isSocrates);
preSocraticsIter()
// => "Anaximander"
preSocraticsIter()
// => "Heraclitus"</code></pre>
<hr>
<h4 id="iterators-select"><a href="#iterators.select" name="iterators.select">iterators.select</a></h4>
<p><strong>Signature:</strong> <code>_.iterators.select(iter:Function, unaryPredicatFn:Function)</code></p>
<p><strong>Aliases:</strong> <code>iterators.find</code>, <code>iteraters.filter</code></p>
<p>Returns an iterator consisting of the values of <code>iter</code> which are flagged
<code>true</code> by <code>unaryPredicateFn</code>.</p>
<pre><code class="lang-javascript">var philosophers = ["Anaximander", "Socrates", "Heraclitus"];
var philosophersIter = _.iterators.List(philosophers);
function isSocrates (val) {
return val === "Socrates";
}
var socraticIter = _.iterators.select(philosophersIter, isSocrates);
socraticIter()
// => "Socrates"</code></pre>
<hr>
<h4 id="iterators-slice"><a href="#iterators.slice" name="iterators.slice">iterators.slice</a></h4>
<p><strong>Signature:</strong> <code>_.iterators.slice(iter:Function, numberToDrop:Number, numberToTake:Number)</code></p>
<p>Returns an iterator whose values consist of <code>iter</code>'s after removing
<code>numberToDrop</code> from the head, and a maxiumum of <code>numberToTake</code> of the remaining.
If <code>numberToTake</code> is not specified, all of <code>iter</code>'s remaining values will be
used.</p>
<pre><code class="lang-javascript">var emperors = ["Augustus", "Tiberius", "Caligula", "Claudius"];
var emperorsIter = _.iterators.List(emperors);
var middleEmperorsIter = _.iterators.slice(emperorsIter, 1, 2);
middleEmperorsIter();
// => "Tiberius"
middleEmperorsIter();
// => "Caligula"
middleEmperorsIter();
// => undefined</code></pre>
<hr>
<h4 id="iterators-take"><a href="#iterators.take" name="iterators.take">iterators.take</a></h4>
<p><strong>Signature:</strong> <code>_.iterators.take(iter:Function[, numberToTake:Number])</code></p>
<p>Returns an iterator consisting of the first <code>numberToTake</code> values yielded by
<code>iter</code>. If <code>numberToTake</code> is not provided, it will default to <code>1</code>.</p>
<pre><code class="lang-javascript">var byzantineEmperors = ["Constantine", "Constantius", "Constans"];
var byzantineEmperorsIter = _.iterators.List(byzantineEmperors);
var firstTwoEmperorsIter = _.iterators.take(byzantineEmperorsIter, 2);
firstTwoEmperorsIter();
// => "Constantine"
firstTwoEmperorsIter();
// => "Constantius"
firstTwoEmperorsIter();
// => undefined</code></pre>
<hr>
<h4 id="iterators-tree"><a href="#iterators.tree" name="iterators.tree">iterators.Tree</a></h4>
<p><strong>Signature:</strong> <code>_.iterators.Tree(array:Array);</code></p>
<p>Returns an iterator that yields the individual values of a tree <code>array</code>.</p>
<pre><code class="lang-javascript">var rulers = ["Augustus", ["Constantine"], ["Leo", ["Charlemagne"]]];
var rulersIter = _.iterators.Tree(rulers);
rulersIter();
// => "Augustus"
rulersIter();
// => "Constantine"
rulersIter();
// => "Leo"
rulersIter();
// => "Charlemagne"</code></pre>
<hr>
<h4 id="iterators-unfold"><a href="#iterators.unfold" name="iterators.unfold">iterators.unfold</a></h4>
<p><strong>Signature:</strong> <code>_.iterators.unfold(seed:Any, unaryFn:Function)</code></p>
<pre><code class="lang-javascript">function greatify (val) {
return val + " the Great";
}
var greatIter = _.iterators.unfold("Constantine", greatify);
greatIter();
// => "Constantine the Great"
greatIter();
// => "Constantine the Great the Great"
greatIter();
// => "Constantine the Great the Great the Great"</code></pre>
<hr>
<h4 id="iterators-unfoldwithreturn"><a href="#iterators.unfoldwithreturn" name="iterators.unfoldwithreturn">iterators.unfoldWithReturn</a></h4>
<p><strong>Signature:</strong> <code>_.iterators.unfold(seed:Any, unaryFn:Function)</code></p>
<p>Acts similarly to unfold, except that <code>unaryFn</code> is expected to return an array
with two elements. The value of the first element is given to the next run of
<code>unaryFn</code>. The value of the second element is yielded by the iterator.</p>
<pre><code class="lang-javascript">var i = _.iterators.unfoldWithReturn(1, function(n) {
return [n + 1, n * n];
});
i();
// => 1
i();
// => 4
i();
// => 9</code></pre>
<h3 id="function-predicates"><a href="#function.predicates" name="function.predicates">function.predicates</a></h3>
<blockquote>
<p>Functions which return whether the input meets a condition.</p>
</blockquote>
<hr>
<h4 id="isassociative"><a href="#isassociative" name="isassociative">isAssociative</a></h4>
<p><strong>Signature:</strong> <code>isAssociative(value:Any)</code></p>
<p>Returns a boolean indicating whether or not the value is an associative object.
An associative object is one where its elements can be accessed via a key or
index (e.g. arrays, <code>arguments</code>, objects).</p>
<pre><code class="lang-javascript">_.isAssociative(["Athens", "Sparta"]);
// => true
_.isAssociative(42);
// => false</code></pre>
<hr>
<h4 id="isdecreasing"><a href="#isdecreasing" name="isdecreasing">isDecreasing</a></h4>
<p><strong>Signature:</strong> <code>_.isDecreasing(values:Any...)</code></p>
<p>Checks whether the arguments are monotonically decreasing values (i.e. whether
each argument is less than the previous argument.)</p>
<pre><code class="lang-javascript">_.isDecreasing(3, 2, 1);
// => true
_.isDecreasing(15, 12, 2);
// => true
_.isDecreasing(2, 3);
// => false</code></pre>
<hr>
<h4 id="iseven"><a href="#iseven" name="iseven">isEven</a></h4>
<p><strong>Signature:</strong> <code>_.isEven(value:Any)</code></p>
<p>Checks whether the value is an even number.</p>
<pre><code class="lang-javascript">_.isEven(12);
// => true
_.isEven(3);
// => false
_.isEven({});
// => false</code></pre>
<hr>
<h4 id="isfloat"><a href="#isfloat" name="isfloat">isFloat</a></h4>
<p><strong>Signature:</strong> <code>_.isFloat(value:Any)</code></p>
<p>Checks whether the value is a "float." For the purposes of this function, a float
is a numeric value that is not an integer. A numeric value may be a number, a
string containing a number, a <code>Number</code> object, etc.</p>
<p><strong>NOTE:</strong> JavaScript itself makes no distinction between integers and floats. For
the purposes of this function both <code>1</code> and <code>1.0</code> are considered integers.</p>
<pre><code class="lang-javascript">_.isFloat(1.1);
// => true
_.isFloat(1);
// => false
_.isFloat(1.0);
// => false
_.isFloat("2.15");
// => true</code></pre>
<hr>
<h4 id="isincreasing"><a href="#isincreasing" name="isincreasing">isIncreasing</a></h4>
<p><strong>Signature:</strong> <code>_.isIncreasing(value:Any...)</code></p>
<p>Checks whether the arguments are monotonically increasing values (i.e. each
argument is greater than the previous argument.)</p>
<pre><code class="lang-javascript">_.isIncreasing(1, 12, 15);
// => true
_.isIncreasing(1);
// => true
_.isIncreasing(5, 4);
// => false</code></pre>
<hr>
<h4 id="isindexed"><a href="#isindexed" name="isindexed">isIndexed</a></h4>
<p><strong>Signature:</strong> <code>_.isIndexed(value:Any)</code></p>
<p>Checks whether the value is "indexed." An indexed value is one which accepts a
numerical index to access its elements. (e.g. arrays and strings)</p>
<p><strong>NOTE:</strong> Underscore does not support cross-browser consistent use of strings as
array-like values, so be wary in IE 8 when using string objects and in IE7 and
earlier when using string literals & objects.</p>
<pre><code class="lang-javascript">_.isIndexed("Socrates");
// => true
_.isIndexed({poison: "hemlock"});
// => false</code></pre>
<hr>
<h4 id="isinstanceof"><a href="#isinstanceof" name="isinstanceof">isInstanceOf</a></h4>
<p><strong>Signature:</strong> <code>_.isInstanceOf(value:Any, constructor:Function)</code></p>
<p>Checks whether the value is an instance of the constructor.</p>
<pre><code class="lang-javascript">_.isInstanceOf(new Date(), Date);
// => true
_.isInstanceOf("Hippocrates", RegExp);
// => false</code></pre>
<hr>
<h4 id="isinteger"><a href="#isinteger" name="isinteger">isInteger</a></h4>
<p><strong>Signature:</strong> <code>_.isInteger(value:Any)</code></p>
<p>Checks whether the value is a numeric integer. A numeric value can be a string
containing a number, a <code>Number</code> object, etc.</p>
<pre><code class="lang-javascript">_.isInteger(18);
// => true
_.isInteger("18");
// => true
_.isInteger(2.5);
// => false
_.isInteger(-1);
// => true</code></pre>
<hr>
<h4 id="isjson"><a href="#isjson" name="isjson">isJSON</a></h4>
<p><strong>Signature:</strong> <code>_.isJSON(value:Any)</code></p>
<p>Checks whether the value is valid JSON. <a href="http://www.json.org/">See the spec</a> for
more information on what constitutes valid JSON.</p>
<p><strong>NOTE:</strong> This function relies on <code>JSON.parse</code> which is not available in IE7 and
earlier.</p>
<pre><code class="lang-javascript">_.isJSON('{ "name": "Crockford" }');
// => true
_.isJSON({ name: "Crocket" });
// => false</code></pre>
<hr>
<h4 id="isnegative"><a href="#isnegative" name="isnegative">isNegative</a></h4>
<p><strong>Signature:</strong> <code>_.isNegative(value:Any)</code></p>
<p>Checks whether the value is a negative number.</p>
<pre><code class="lang-javascript">_.isNegative(-2);
// => true
_.isNegative(5);
// => false</code></pre>
<hr>
<h4 id="isnumeric"><a href="#isnumeric" name="isnumeric">isNumeric</a></h4>
<p><strong>Signature:</strong> <code>_.isNumeric(value:Any)</code></p>
<p>A numeric is something that contains a numeric value, regardless of its type. It
can be a string containing a numeric value, exponential notation, a <code>Number</code>
object, etc.</p>
<pre><code class="lang-javascript">_.isNumeric("14");
// => true
_.isNumeric("fourteen");
// => false</code></pre>
<hr>
<h4 id="isodd"><a href="#isodd" name="isodd">isOdd</a></h4>
<p><strong>Signature:</strong> <code>_.isOdd(value:Any)</code></p>
<p>Checks whether the value is an odd number.</p>
<pre><code class="lang-javascript">_.isOdd(3);
// => true
_.isOdd(2);
// => false
_.isOdd({});
// => false</code></pre>
<hr>
<h4 id="isplainobject"><a href="#isplainobject" name="isplainobject">isPlainObject</a></h4>
<p><strong>Signature:</strong> <code>_.isPlainObject(value:Any);</code></p>
<p>Checks whether the value is a "plain" object created as an object literal (<code>{}</code>)
or explicitly constructed with <code>new Object()</code>. Instances of other constructors
are <strong>not</strong> plain objects.</p>
<pre><code class="lang-javascript">_.isPlainObject({});
// => true
_.isPlainObject(new Date());
// => false
_.isPlainObject([]);
// => false</code></pre>
<hr>
<h4 id="ispositive"><a href="#ispositive" name="ispositive">isPositive</a></h4>
<p><strong>Signature:</strong> <code>_.isPositive(value:Any)</code></p>
<p>Checks whether the value is a positive number.</p>
<pre><code class="lang-javascript">_.isPositive(21);
// => true
_.isPositive(-3);
// => false</code></pre>
<hr>
<h4 id="issequential"><a href="#issequential" name="issequential">isSequential</a></h4>
<p><strong>Signature:</strong> <code>_.isSequential(value:Any)</code></p>
<p>Checks whether the value is a sequential composite type (i.e. arrays and
<code>arguments</code>).</p>
<pre><code class="lang-javascript">_.isSequential(["Herodotus", "Thucidydes");
// => true
_.isSequential(new Date);
// => false</code></pre>
<hr>
<h4 id="isvaliddate"><a href="#isvaliddate" name="isvaliddate">isValidDate</a></h4>
<p><strong>Signature:</strong> <code>_.isValidDate(value:Any)</code></p>
<p>Checks whether the value is a valid date. That is, the value is both an instance
of <code>Date</code> and it represents an actual date.</p>
<p><span class="label label-danger">Warning:</span> This function does not verify
whether the original input to <code>Date</code> is a real date. For instance,
<code>new Date("02/30/2014")</code> is considered a valid date because <code>Date</code> coerces that
into a representation of 03/02/2014. To validate strings representing a date,
consider using a date/time library like <a href="http://momentjs.com/">Moment.js.</a></p>
<pre><code class="lang-javascript">_.isValidDate(new Date("January 1, 1900"));
// => true
_.isValidDate(new Date("The Last Great Time War"));
// => false</code></pre>
<hr>
<h4 id="iszero"><a href="#iszero" name="iszero">isZero</a></h4>
<p><strong>Signature:</strong> <code>_.isZero(value:Any)</code></p>
<p>Checks whether the value is <code>0</code>.</p>
<pre><code class="lang-javascript">_.isZero(0);
// => true
_.isZero("Pythagoras");
// => false</code></pre>
<hr>
<h3 id="object-builders"><a href="#object.builders" name="object.builders">object.builders</a></h3>
<blockquote>
<p>Functions to build objects.</p>
</blockquote>
<hr>
<h4 id="frequencies"><a href="#frequencies" name="frequencies">frequencies</a></h4>
<p><strong>Signature:</strong> <code>_.frequencies(arr:Array)</code></p>
<p>Returns an object whose property keys are the values of <code>arr</code>'s elements. The
property values are a count of how many times that value appeared in <code>arr</code>.</p>
<pre><code class="lang-javascript">var citations = ["Plato", "Aristotle", "Plotinus", "Plato"];
_.frequencies(citations);
// => { Plato: 2, Aristotle: 1, Plotinus: 1 }</code></pre>
<hr>
<h4 id="merge"><a href="#merge" name="merge">merge</a></h4>
<p><strong>Signature:</strong> <code>_.merge(obj1:Object[, obj:Object...])</code></p>
<p>Merges two or more objects starting with the left-most and applying the keys
rightward.</p>
<pre><code class="lang-javascript">_.merge({ a: "alpha" }, { b: "beta" });
// => { a: "alpha", b: "beta" }</code></pre>
<hr>
<h4 id="renamekeys"><a href="#renamekeys" name="renamekeys">renameKeys</a></h4>
<p><strong>Signature:</strong> <code>_.renameKeys(obj:Object, keyMap:Object)</code></p>
<p>Takes an object (<code>obj</code>) and a map of keys (<code>keyMap</code>) and returns a new object
where the keys of <code>obj</code> have been renamed as specified in <code>keyMap</code>.</p>
<pre><code class="lang-javascript">_.renameKeys({ a: 1, b: 2 }, { a: "alpha", b: "beta" });
// => { alpha: 1, beta: 2 }</code></pre>
<hr>
<h4 id="setpath"><a href="#setpath" name="setpath">setPath</a></h4>
<p><strong>Signature:</strong> <code>_.setPath(obj:Object, value:Any, ks:Array, defaultValue:Any)</code></p>
<p>Sets the value of a property at any depth in <code>obj</code> based on the path described
by the <code>ks</code> array. If any of the properties in the <code>ks</code> path don't exist, they
will be created with <code>defaultValue</code>.</p>
<pre><code class="lang-javascript">_.setPath({}, "Plotinus", ["Platonism", "Neoplatonism"], {});
// => { Platonism: { Neoplatonism: "Plotinus" } }</code></pre>
<hr>
<h4 id="snapshot"><a href="#snapshot" name="snapshot">snapshot</a></h4>
<p><strong>Signature:</strong> <code>_.snapshot(obj:Object)</code></p>
<p>Snapshots/clones an object deeply.</p>
<pre><code class="lang-javascript">var schools = { plato: "Academy", aristotle: "Lyceum" };
_.snapshot(schools);
// => { plato: "Academy", aristotle: "Lyceum" }
schools === _.snapshot(schools);
// => false</code></pre>
<hr>
<p><strong>Signature:</strong> <code>_.updatePath(obj:Object, fun:Function, ks:Array, defaultValue:Any)</code></p>
<p>Updates the value at any depth in a nested object based on the path described by
the <code>ks</code> array. The function <code>fun</code> is called with the current value and is
expected to return a replacement value. If no keys are provided, then the
object itself is presented to <code>fun</code>. If a property in the path is missing, then
it will be created with <code>defaultValue</code>.</p>
<pre><code class="lang-javascript">var imperialize = function (val) {
if (val == "Republic) return "Empire";
else return val;
};
_.updatePath({ rome: "Republic" }, imperialize, ["rome"]);
// => { rome: "Empire" }</code></pre>
<h3 id="object-selectors"><a href="#object.selectors" name="object.selectors">object.selectors</a></h3>
<blockquote>
<p>Functions to select values from an object.</p>
</blockquote>
<hr>
<h4 id="accessor"><a href="#accessor" name="accessor">accessor</a></h4>
<p><strong>Signature:</strong> <code>_.accessor(field:String)</code></p>
<p>Returns a function that will attempt to look up a named field in any object
that it is given.</p>
<pre><code class="lang-javascript">var getName = _.accessor('name');
getName({ name: 'Seneca' });
// => 'Seneca'</code></pre>
<hr>
<h4 id="dictionary"><a href="#dictionary" name="dictionary">dictionary</a></h4>
<p><strong>Signature:</strong> <code>_.dictionary(obj:Object)</code></p>
<p>Given an object, returns a function that will attempt to look up a field that
it is given.</p>
<pre><code class="lang-javascript">var generals = {
rome: "Scipio",
carthage: "Hannibal"
};
var getGeneralOf = _.dictionary(generals);
_.getGeneralOf("rome");
// => "Scipio"</code></pre>
<hr>
<h4 id="getpath"><a href="#getpath" name="getpath">getPath</a></h4>
<p><strong>Signature:</strong> <code>_.getPath(obj:Object, ks:String|Array)</code></p>
<p>Gets the value at any depth in a nested object based on the path described by
the keys given. Keys may be given as an array or as a dot-separated string.
Returns <code>undefined</code> if the path cannot be reached.</p>
<pre><code class="lang-javascript">var countries = {
greece: {
athens: {
playwright: "Sophocles"
}
}
}
};
_.getPath(countries, "greece.athens.playwright");
// => "Sophocles"
_.getPath(countries, "greece.sparta.playwright");
// => undefined
_.getPath(countries, ["greece", "athens", "playwright"]);
// => "Sophocles"
_.getPath(countries, ["greece", "sparta", "playwright"]);
// => undefined</code></pre>
<hr>
<h4 id="haspath"><a href="#haspath" name="haspath">hasPath</a></h4>
<p><strong>Signature:</strong> <code>_.hasPath(obj:Object, ks:String|Array)</code></p>
<p>Returns a boolean indicating whether there is a property at the path described
by the keys given. Keys may be given as an array or as a dot-separated string.</p>
<pre><code class="lang-javascript">var countries = {
greece: {
athens: {
playwright: "Sophocles"
}
}
}
};
_.hasPath(countries, "greece.athens.playwright");
// => true
_.hasPath(countries, "greece.sparta.playwright");
// => false
_.hasPath(countries, ["greece", "athens", "playwright"]);
// => true
_.hasPath(countries, ["greece", "sparta", "playwright"]);
// => false</code></pre>
<hr>
<h4 id="kv"><a href="#kv" name="kv">kv</a></h4>
<p><strong>Signature:</strong> <code>_.kv(obj:Object, key:String)</code></p>
<p>Returns the key/value pair for a given property in an object, undefined if not found.</p>
<pre><code class="lang-javascript">var playAuthor = {
"Medea": "Aeschylus"
};
_.kv(playAuthor, "Medea");
// => ["Medea", "Aeschylus"]
_.kv(playAuthor, "Hamlet");
// => undefined</code></pre>
<hr>
<h4 id="omitwhen"><a href="#omitwhen" name="omitwhen">omitWhen</a></h4>
<p><strong>Signature:</strong> <code>_.omitWhen(obj, pred:Function)</code></p>
<p>Returns a copy of <code>obj</code> omitting any properties that the predicate (<code>pred</code>)
function returns <code>true</code> for. The predicat function is invoked with each
property value, like so: <code>pred(propValue)</code>.</p>
<pre><code class="lang-javascript">var playwrights = {
euripedes: "Greece",
shakespere: "England"
};
_.omitWhen(obj, function (country) { return country == "England" });
// => { euripedes: "Greece" }</code></pre>
<hr>
<h4 id="pickwhen"><a href="#pickwhen" name="pickwhen">pickWhen</a></h4>
<p><strong>Signature:</strong> <code>_.pickWhen(obj:Object, pred:Function)</code></p>
<p>Returns a copy of <code>obj</code> containing only properties that the predicate (<code>pred</code>)
function returns <code>true</code> for. The predicate function is invoked with each
property value, like so: <code>pred(propValue)</code>.</p>
<pre><code class="lang-javascript">var playwrights = {
euripedes: "Greece",
shakespere: "England"
};
_.pickWhen(obj, function (country) { return country == "England" });
// => { shakespeare: "England" }</code></pre>
<hr>
<h4 id="selectkeys"><a href="#selectkeys" name="selectkeys">selectKeys</a></h4>
<p><strong>Signature:</strong> `_.selectKeys(obj:Object, ks:Array);</p>
<p>Returns a copy of <code>obj</code> containing only the properties listed in the <code>ks</code> array.</p>
<pre><code class="lang-javascript">var philosopherCities = {
Philo: "Alexandria",
Plato: "Athens",
Plotinus: "Rome"
}
_.selectKeys(philosopherCities, ["Plato", "Plotinus"]);
// => { Plato: "Athens", Plotinus: "Rome" }</code></pre>
<h3 id="util-existential"><a href="#util.existential" name="util.existential">util.existential</a></h3>
<blockquote>
<p>Functions which deal with whether a value "exists."</p>
</blockquote>
<hr>
<h4 id="exists"><a href="#exists" name="exists">exists</a></h4>
<p><strong>Signature:</strong> <code>_.exists(value:Any)</code></p>
<p>Checks whether or not the value is "existy." Both <code>null</code> and <code>undefined</code> are
considered non-existy values. All other values are existy.</p>
<pre><code class="lang-javascript">_.exists(null);
// => false
_.exists(undefined);
// => false
_.exists({});
// = > true
_.exists("Sparta");
// => true</code></pre>
<hr>
<h4 id="falsey"><a href="#falsey" name="falsey">falsey</a></h4>
<p><strong>Signature:</strong> <code>_.falsey(value:Any)</code></p>
<p>Checks whether the value is falsey. A falsey value is one which coerces to
<code>false</code> in a boolean context.</p>
<pre><code class="lang-javascript">_.falsey(0);
// => true
_.falsey("");
// => true
_.falsey({});
// => false
_.falsey("Corinth");
// => false</code></pre>
<hr>
<h4 id="firstexisting"><a href="#firstexisting" name="firstexisting">firstExisting</a></h4>
<p><strong>Signature:</strong> <code>_.firstExisting(value:Any[, value:Any...])</code></p>
<p>Returns the first existy argument from the argument list.</p>
<pre><code class="lang-javascript">_.firstExisting("Socrates", "Plato");
// => "Socrates"
_.firstExisting(null, undefined, "Heraclitus");
// => "Heraclitus"</code></pre>
<hr>
<h4 id="not"><a href="#not" name="not">not</a></h4>
<p><strong>Signature:</strong> <code>_.not(value:Any)</code></p>
<p>Returns a boolean which is the opposite of the truthiness of the original value.</p>
<pre><code class="lang-javascript">_.not(0);
// => true
_.not(1);
// => false
_.not(true);
// => false
_.not(false);
// => true
_.not({});
// => false
_.not(null);
// => true</code></pre>
<hr>
<h4 id="truthy"><a href="#truthy" name="truthy">truthy</a></h4>
<p><strong>Signature:</strong> <code>_.truthy(value:Any)</code></p>
<p>Checks whether the value is truthy. A truthy value is one which coerces to
<code>true</code> in a boolean context.</p>
<pre><code class="lang-javascript">_.truthy({});
// => true
_.truthy("Athens");
// => true
_.truthy(0);
// => false
_.truthy("");
// => false</code></pre>
<hr>
<h3 id="util-operators"><a href="#util.operators" name="util.operators">util.operators</a></h3>
<blockquote>
<p>Functions which wrap JavaScript's operators.</p>
</blockquote>
<hr>
<h4 id="add"><a href="#add" name="add">add</a></h4>
<p><strong>Signature:</strong> <code>_.add(value:Number, value:Number[, value:Number...])</code></p>
<p>Returns the sum of the arguments.</p>
<pre><code class="lang-javascript">_.add(1, 2, 3, 4);
// => 10</code></pre>
<hr>
<h4 id="bitwiseand"><a href="#bitwiseand" name="bitwiseand">bitwiseAnd</a></h4>
<p><strong>Signature:</strong> <code>_.bitwiseAnd(value:Any, value:Any[, value:Any...])</code></p>
<p>Returns the result of using the <code>&</code> operator on the arguments.</p>
<pre><code class="lang-javascript">_.bitwiseAnd(1, 3);
// => 1
_.bitwiseAnd(1, 3, 2);
// => 0</code></pre>
<hr>
<h4 id="bitwiseleft"><a href="#bitwiseleft" name="bitwiseleft">bitwiseLeft</a></h4>
<p><strong>Signature:</strong> <code>_.bitwiseLeft(value:Any, value:Any[, value:Any...])</code></p>
<p>Returns the result of using the <code><<</code> operator on the arguments.</p>
<pre><code class="lang-javascript">_.bitwiseLeft(1, 3);
// => 8
_.bitwiseLeft(1, 3, 2);
// => 32</code></pre>
<hr>
<h4 id="bitwiseright"><a href="#bitwiseright" name="bitwiseright">bitwiseRight</a></h4>
<p><strong>Signature:</strong> <code>_.bitwiseRight(value:Any, value:Any[, value:Any...])</code></p>
<p>Returns the result of using the <code>>></code> operator on the arguments.</p>
<pre><code class="lang-javascript">_.bitwiseRight(3, 1);
// => 1
_.bitwiseRight(3, 1, 3);
// => 0</code></pre>
<hr>
<h4 id="bitwisenot"><a href="#bitwisenot" name="bitwisenot">bitwiseNot</a></h4>
<p><strong>Signature:</strong> <code>_.bitwiseNot(value:Any)</code></p>
<p>Returns the result of using the <code>~</code> operator on the value.</p>
<pre><code class="lang-javascript">_.bitwiseNot(1);
// => -2
_.bitwiseOr(2);
// => -3</code></pre>
<hr>
<h4 id="bitwiseor"><a href="#bitwiseor" name="bitwiseor">bitwiseOr</a></h4>
<p><strong>Signature:</strong> <code>_.bitwiseOr(value:Any, value:Any[, value:Any...])</code></p>
<p>Returns the result of using the <code>|</code> operator on the arguments.</p>
<pre><code class="lang-javascript">_.bitwiseOr(1, 3);
// => 3
_.bitwiseOr(1, 3, 4);
// => 7</code></pre>
<hr>
<h4 id="bitwisexor"><a href="#bitwisexor" name="bitwisexor">bitwiseXor</a></h4>
<p><strong>Signature:</strong> <code>_.bitwiseXor(value:Any, value:Any[, value:Any...])</code></p>
<p>Returns the result of using the <code>^</code> operator on the arguments.</p>
<pre><code class="lang-javascript">_.bitwiseXor(1, 3);
// => 2
_.bitwiseXor(1, 3, 3);
// => 1</code></pre>
<hr>
<h4 id="bitwisez"><a href="#bitwisez" name="bitwisez">bitwiseZ</a></h4>
<p><strong>Signature:</strong> <code>_.bitwiseZ(value:Any, value:Any[, value:Any...])</code></p>
<p>Returns the result of using the <code>>>></code> operator on the arguments.</p>
<pre><code class="lang-javascript">_.bitwiseZ(72, 32);
// => 72
_.bitwiseZ(72, 32, 2);
// => 18</code></pre>
<hr>
<h4 id="dec"><a href="#dec" name="dec">dec</a></h4>
<p><strong>Signature:</strong> <code>_.dec(value:Number)</code></p>
<p>Returns the result of decrementing the value by <code>1</code>.</p>
<pre><code class="lang-javascript">_.dec(2);
// => 1</code></pre>
<hr>
<h4 id="div"><a href="#div" name="div">div</a></h4>
<p><strong>Signature:</strong> <code>_.div(value:Number, value:Number[, value:Number...])</code></p>
<p>Returns the quotient of the arguments.</p>
<pre><code class="lang-javascript">_.div(8, 2);
// => 4
_.div(8, 2, 2);
// => 2</code></pre>
<hr>
<h4 id="eq"><a href="#eq" name="eq">eq</a></h4>
<p><strong>Signature:</strong> <code>_.eq(value:Any, value:Any[, value:Any...])</code></p>
<p>Compares the arguments with loose equality (<code>==</code>).</p>
<pre><code class="lang-javascript">_.eq(1, "1");
// => true
_.eq(1, 15);
// => false
_.eq(1, true, "1");
// => true
_.eq(1, 1, 15);
// => false</code></pre>
<hr>
<h4 id="gt"><a href="#gt" name="gt">gt</a></h4>
<p><strong>Signature:</strong> <code>_.gt(value:Any, value:Any[, value:Any...])</code></p>
<p>Checks whether each argument is greater than the previous argument.</p>
<pre><code class="lang-javascript">_.gt(1, 2);
// => true
_.gt(1, 2, 3);
// => true
_.gt(1, 6, 2);
// => false</code></pre>
<hr>
<h4 id="gte"><a href="#gte" name="gte">gte</a></h4>
<p><strong>Signature:</strong> <code>_.gte(value:Any, value:Any[, value:Any...])</code></p>
<p>Checks whether each argument is greater than or equal to the previous argument.</p>
<pre><code class="lang-javascript">_.gte(1, 2);
// => true
_.gte(1, 1, 3);
// => true
_.gte(1, 6, 2);
// => false</code></pre>
<hr>
<h4 id="inc"><a href="#inc" name="inc">inc</a></h4>
<p><strong>Signature:</strong> <code>_.inc(value:Number)</code></p>
<p>Returns the result of incrementing the value by <code>1</code>.</p>
<pre><code class="lang-javascript">_.inc(2);
// => 3</code></pre>
<hr>
<h4 id="lt"><a href="#lt" name="lt">lt</a></h4>
<p><strong>Signature:</strong> <code>_.lt(value:Any, value:Any[, value:Any...])</code></p>
<p>Checks whether each argument is less than the previous argument.</p>
<pre><code class="lang-javascript">_.lt(2, 1);
// => true
_.lt(2, 1, 0);
// => true
_.lt(2, 1, 12);
// => false</code></pre>
<hr>
<h4 id="lte"><a href="#lte" name="lte">lte</a></h4>
<p><strong>Signature:</strong> <code>_.lte(value:Any, value:Any[, value:Any...])</code></p>
<p>Checks whether each argument is less than or equal to the previous argument.</p>
<pre><code class="lang-javascript">_.lte(2, 1);
// => true
_.lte(2, 1, 1);
// => true
_.lte(2, 1, 12);
// => false</code></pre>
<hr>
<h4 id="mul"><a href="#mul" name="mul">mul</a></h4>
<p><strong>Signature:</strong> <code>_.mul(value:Number, value:Number[, value:Number...])</code></p>
<p>Returns the product of the arguments.</p>
<pre><code class="lang-javascript">_.mul(1, 2, 3, 4);
// => 24</code></pre>
<hr>
<h4 id="mod"><a href="#mod" name="mod">mod</a></h4>
<p><strong>Signature:</strong> <code>_.mod(dividend:Number, divisor:Number)</code></p>
<p>Returns the remainder of dividing <code>dividend</code> by <code>divisor</code>.</p>
<pre><code class="lang-javascript">_.mod(26, 5);
// => 1
_.mod(14, 3);
// => 2</code></pre>
<hr>
<h4 id="neg"><a href="#neg" name="neg">neg</a></h4>
<p><strong>Signature:</strong> <code>_.neg(num:Number)</code></p>
<p>Returns a new number with the opposite sign value of <code>num</code>.</p>
<pre><code class="lang-javascript">_.neg(5);
// => -5
_.neg(-3);
// => 3</code></pre>
<hr>
<h4 id="neq"><a href="#neq" name="neq">neq</a></h4>
<p><strong>Signature:</strong> <code>_.neq(value:Any, value:Any[, value:Any...])</code></p>
<p>Checks whether each argument is not equal to the previous argument, using loose
inequality (<code>!=</code>).</p>
<pre><code class="lang-javascript">_.neq(2, 1);
// => true
_.neq(2, 1, 1);
// => true
_.neq(1, 1);
// => false</code></pre>
<hr>
<h4 id="not"><a href="#not-1" name="not-1">not</a></h4>
<p><strong>Signature:</strong> <code>_.not(value:Any)</code></p>
<p>Returns a boolean which is the opposite of the truthiness of the original value.</p>
<pre><code class="lang-javascript">_.not(0);
// => true
_.not(1);
// => false
_.not(true);
// => false
_.not(false);
// => true
_.not({});
// => false
_.not(null);
// => true</code></pre>
<hr>
<h4 id="seq"><a href="#seq" name="seq">seq</a></h4>
<p><strong>Signature:</strong> <code>_.seq(value:Any, value:Any[, value:Any...])</code></p>
<p>Checks whether the arguments are strictly equal (<code>===</code>) to each other.</p>
<pre><code class="lang-javascript">_.seq(2, 2);
// => true
_.seq(2, "2");
// => false
_.seq(2, 2, 2);
// => true</code></pre>
<hr>
<h4 id="sneq"><a href="#sneq" name="sneq">sneq</a></h4>
<p><strong>Signature:</strong> <code>_.sneq(value:Any, value:Any[, value:Any...])</code></p>
<p>Checks whether the arguments are strictly not equal (<code>!==</code>) to each other.</p>
<pre><code class="lang-javascript">_.sneq(2, 2);
// => false
_.sneq(2, "2");
// => true
_.sneq(2, 2, 2);
// => false</code></pre>
<hr>
<h4 id="sub"><a href="#sub" name="sub">sub</a></h4>
<p><strong>Signature:</strong> <code>_.sub(value:Number, value:Number[, value:Number...])</code></p>
<p>Returns the difference of the arguments.</p>
<pre><code class="lang-javascript">_.sub(10, 3);
// => 7
_.sub(10, 3, 5);
// => 2</code></pre>
<h3 id="util-strings"><a href="#util.strings" name="util.strings">util.strings</a></h3>
<blockquote>
<p>Functions for working with strings.</p>
</blockquote>
<hr>
<h4 id="camelcase"><a href="#camelcase" name="camelcase">camelCase</a></h4>
<p><strong>Signature:</strong> <code>_.camelCase(string:String)</code></p>
<p>Converts a dash-separated string to camel case. Opposite of <a href="#todash">toDash</a>.</p>
<pre><code class="lang-javascript">_.camelCase("ancient-greece");
// => "ancientGreece"</code></pre>
<hr>
<h4 id="explode"><a href="#explode" name="explode">explode</a></h4>
<p><strong>Signature:</strong> <code>_.explode(s:String)</code></p>
<p>Explodes a string into an array of characters. Opposite of <a href="#implode">implode</a>.</p>
<pre><code class="lang-javascript">_.explode("Plato");
// => ["P", "l", "a", "t", "o"]</code></pre>
<hr>
<h4 id="fromquery"><a href="#fromquery" name="fromquery">fromQuery</a></h4>
<p><strong>Signature:</strong> <code>_.fromQuery(str:String)</code></p>
<p>Takes a URL query string and converts it into an equivalent JavaScript object.
Opposite of <a href="#toquery">toQuery</a></p>
<pre><code class="lang-javascript">_.fromQuery("forms%5Bperfect%5D=circle&forms%5Bimperfect%5D=square");
// => { forms: { perfect: "circle", imperfect: "square" } }</code></pre>
<hr>
<h4 id="implode"><a href="#implode" name="implode">implode</a></h4>
<p><strong>Signature:</strong> <code>_.implode(a:Array)</code></p>
<p>Implodes an array of strings into a single string. Opposite of <a href="#explode">explode</a>.</p>
<pre><code class="lang-javascript">_.implode(["H", "o", "m", "e", "r"]);
// => "Homer"</code></pre>
<hr>
<h4 id="strcontains"><a href="#strcontains" name="strcontains">strContains</a></h4>
<p><strong>Signature:</strong> <code>_.strContains(str:String, search:String)</code></p>
<p>Reports whether a string contains a search string.</p>
<pre><code class="lang-javascript">_.strContains("Acropolis", "polis");
// => true</code></pre>
<hr>
<h4 id="todash"><a href="#todash" name="todash">toDash</a></h4>
<p><strong>Signature:</strong> <code>_.toDash(string:String)</code></p>
<p>Converts a camel case string to a dashed string. Opposite of <a href="#camelcase">camelCase</a>.</p>
<pre><code class="lang-javascript">_.toDash("thisIsSparta");
// => "this-is-sparta"</code></pre>
<hr>
<h4 id="toquery"><a href="#toquery" name="toquery">toQuery</a></h4>
<p><strong>Signature:</strong> <code>_.toQuery(obj:Object)</code></p>
<p>Takes an object and converts it into an equivalent URL query string. Opposite
of <a href="#fromquery">fromQuery</a>.</p>
<pre><code class="lang-javascript">_.toQuery({ forms: { perfect: "circle", imperfect: "square" } });
// => "forms%5Bperfect%5D=circle&forms%5Bimperfect%5D=square"</code></pre>
<hr>
<h3 id="util-trampolines"><a href="#util.trampolines" name="util.trampolines">util.trampolines</a></h3>
<blockquote>
<p>Trampoline functions.</p>
</blockquote>
<p>Documentation should use <a href="https://github.com/jashkenas/journo">Journo</a> formats and standards.</p>
<pre><code>done: function(value) {
trampoline: function(fun /*, args */) {</code></pre>
<hr>
<h3 id="changelog"><a href="#changelog" name="changelog">Changelog</a></h3>
<h4 id="0-3-0"><a href="#0.3.0" name="0.3.0">0.3.0</a></h4>
<ul>
<li>Contrib now requires Underscore 1.6.0 or higher.</li>
<li>Rename <code>partition</code> and <code>partitionAll</code> to <code>chunk</code> and <code>chunkAll</code> to avoid name conflicts with Underscore's <code>partition</code> - <a href="https://github.com/documentcloud/underscore-contrib/issues/115">#115</a></li>
<li>Added <code>toQuery</code> and <code>fromQuery</code> - <a href="https://github.com/documentcloud/underscore-contrib/issues/134">#134</a></li>
<li>Switch <code>always</code> to an alias of Underscore's <code>constant</code>. - <a href="https://github.com/documentcloud/underscore-contrib/issues/132">#132</a></li>
<li>The combinators sub-library now supports method combinators - <a href="https://github.com/documentcloud/underscore-contrib/issues/14">#14</a></li>
</ul>
</body>
</html>