@@ -1520,7 +1520,7 @@ <h4 id="flattenArrays">std.flattenArrays(arrs)</h4>
1520
1520
< div class ="hgroup ">
1521
1521
< div class ="hgroup-inline ">
1522
1522
< div class ="panel ">
1523
- < h4 id ="sort "> std.sort(arr)</ h4 >
1523
+ < h4 id ="sort "> std.sort(arr, keyF=id )</ h4 >
1524
1524
</ div >
1525
1525
< div style ="clear: both "> </ div >
1526
1526
</ div >
@@ -1530,6 +1530,9 @@ <h4 id="sort">std.sort(arr)</h4>
1530
1530
< div class ="hgroup-inline ">
1531
1531
< div class ="panel ">
1532
1532
< p > Sorts the array using the < = operator.</ p >
1533
+ < p > Optional argument < code > keyF</ code > is a single argument function used to extract comparison
1534
+ key from each list element. Default value is identity function < code > keyF=function(x) x</ code > .
1535
+ </ p >
1533
1536
</ div >
1534
1537
< div style ="clear: both "> </ div >
1535
1538
</ div >
@@ -1573,6 +1576,11 @@ <h3 id="sets">Sets</h3>
1573
1576
on arrays passed to them to work. This can be guarenteed by using < code > std.set(arr)< code > .
1574
1577
If that is not the case, the functions will quietly return non-meaningful results.
1575
1578
</ p >
1579
+ < p >
1580
+ All < code > set.set*</ code > functions accept < code > keyF</ code > function of one argument, which can be
1581
+ used to extract key to use from each element. All Set operations then use extracted key for the purpose
1582
+ of identifying uniqueness. Default value is identity function < code > local id = function(x) x</ code >
1583
+ </ p >
1576
1584
</ div >
1577
1585
< div style ="clear: both "> </ div >
1578
1586
</ div >
@@ -1582,7 +1590,7 @@ <h3 id="sets">Sets</h3>
1582
1590
< div class ="hgroup ">
1583
1591
< div class ="hgroup-inline ">
1584
1592
< div class ="panel ">
1585
- < h4 id ="set "> std.set(arr)</ h4 >
1593
+ < h4 id ="set "> std.set(arr, keyF=id )</ h4 >
1586
1594
</ div >
1587
1595
< div style ="clear: both "> </ div >
1588
1596
</ div >
@@ -1601,7 +1609,7 @@ <h4 id="set">std.set(arr)</h4>
1601
1609
< div class ="hgroup ">
1602
1610
< div class ="hgroup-inline ">
1603
1611
< div class ="panel ">
1604
- < h4 id ="setInter "> std.setInter(a, b)</ h4 >
1612
+ < h4 id ="setInter "> std.setInter(a, b, keyF=id )</ h4 >
1605
1613
</ div >
1606
1614
< div style ="clear: both "> </ div >
1607
1615
</ div >
@@ -1620,7 +1628,7 @@ <h4 id="setInter">std.setInter(a, b)</h4>
1620
1628
< div class ="hgroup ">
1621
1629
< div class ="hgroup-inline ">
1622
1630
< div class ="panel ">
1623
- < h4 id ="setUnion "> std.setUnion(a, b)</ h4 >
1631
+ < h4 id ="setUnion "> std.setUnion(a, b, keyF=id )</ h4 >
1624
1632
</ div >
1625
1633
< div style ="clear: both "> </ div >
1626
1634
</ div >
@@ -1638,6 +1646,10 @@ <h4 id="setUnion">std.setUnion(a, b)</h4>
1638
1646
Example1: < code > std.setUnion([1, 2], [2, 3])</ code > yields
1639
1647
< code > [1, 2, 3]</ code > .
1640
1648
</ p >
1649
+ < p >
1650
+ Example2: < code > std.setUnion([{n:"A", v:1}, {n:"B"}], [{n:"A", v: 9999}, {n:"C"}],keyF=function(x) x.n)</ code > yields
1651
+ < code > [{n: "A", v:1}, {n: "B"}, {n: "C"}]</ code > .
1652
+ </ p >
1641
1653
</ div >
1642
1654
< div style ="clear: both "> </ div >
1643
1655
</ div >
@@ -1647,7 +1659,7 @@ <h4 id="setUnion">std.setUnion(a, b)</h4>
1647
1659
< div class ="hgroup ">
1648
1660
< div class ="hgroup-inline ">
1649
1661
< div class ="panel ">
1650
- < h4 id ="setDiff "> std.setDiff(a, b)</ h4 >
1662
+ < h4 id ="setDiff "> std.setDiff(a, b, keyF=id )</ h4 >
1651
1663
</ div >
1652
1664
< div style ="clear: both "> </ div >
1653
1665
</ div >
@@ -1666,7 +1678,7 @@ <h4 id="setDiff">std.setDiff(a, b)</h4>
1666
1678
< div class ="hgroup ">
1667
1679
< div class ="hgroup-inline ">
1668
1680
< div class ="panel ">
1669
- < h4 id ="setMember "> std.setMember(x, arr)</ h4 >
1681
+ < h4 id ="setMember "> std.setMember(x, arr, keyF=id )</ h4 >
1670
1682
</ div >
1671
1683
< div style ="clear: both "> </ div >
1672
1684
</ div >
0 commit comments