Skip to content

Commit 8ac54da

Browse files
redbaronsparkprime
authored andcommitted
Document keyF arguments for std.set* and std.sort functions (#602)
1 parent 0ebb1b3 commit 8ac54da

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

doc/ref/stdlib.html

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,7 +1520,7 @@ <h4 id="flattenArrays">std.flattenArrays(arrs)</h4>
15201520
<div class="hgroup">
15211521
<div class="hgroup-inline">
15221522
<div class="panel">
1523-
<h4 id="sort">std.sort(arr)</h4>
1523+
<h4 id="sort">std.sort(arr, keyF=id)</h4>
15241524
</div>
15251525
<div style="clear: both"></div>
15261526
</div>
@@ -1530,6 +1530,9 @@ <h4 id="sort">std.sort(arr)</h4>
15301530
<div class="hgroup-inline">
15311531
<div class="panel">
15321532
<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>
15331536
</div>
15341537
<div style="clear: both"></div>
15351538
</div>
@@ -1573,6 +1576,11 @@ <h3 id="sets">Sets</h3>
15731576
on arrays passed to them to work. This can be guarenteed by using <code>std.set(arr)<code>.
15741577
If that is not the case, the functions will quietly return non-meaningful results.
15751578
</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>
15761584
</div>
15771585
<div style="clear: both"></div>
15781586
</div>
@@ -1582,7 +1590,7 @@ <h3 id="sets">Sets</h3>
15821590
<div class="hgroup">
15831591
<div class="hgroup-inline">
15841592
<div class="panel">
1585-
<h4 id="set">std.set(arr)</h4>
1593+
<h4 id="set">std.set(arr, keyF=id)</h4>
15861594
</div>
15871595
<div style="clear: both"></div>
15881596
</div>
@@ -1601,7 +1609,7 @@ <h4 id="set">std.set(arr)</h4>
16011609
<div class="hgroup">
16021610
<div class="hgroup-inline">
16031611
<div class="panel">
1604-
<h4 id="setInter">std.setInter(a, b)</h4>
1612+
<h4 id="setInter">std.setInter(a, b, keyF=id)</h4>
16051613
</div>
16061614
<div style="clear: both"></div>
16071615
</div>
@@ -1620,7 +1628,7 @@ <h4 id="setInter">std.setInter(a, b)</h4>
16201628
<div class="hgroup">
16211629
<div class="hgroup-inline">
16221630
<div class="panel">
1623-
<h4 id="setUnion">std.setUnion(a, b)</h4>
1631+
<h4 id="setUnion">std.setUnion(a, b, keyF=id)</h4>
16241632
</div>
16251633
<div style="clear: both"></div>
16261634
</div>
@@ -1638,6 +1646,10 @@ <h4 id="setUnion">std.setUnion(a, b)</h4>
16381646
Example1: <code>std.setUnion([1, 2], [2, 3])</code> yields
16391647
<code>[1, 2, 3]</code>.
16401648
</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>
16411653
</div>
16421654
<div style="clear: both"></div>
16431655
</div>
@@ -1647,7 +1659,7 @@ <h4 id="setUnion">std.setUnion(a, b)</h4>
16471659
<div class="hgroup">
16481660
<div class="hgroup-inline">
16491661
<div class="panel">
1650-
<h4 id="setDiff">std.setDiff(a, b)</h4>
1662+
<h4 id="setDiff">std.setDiff(a, b, keyF=id)</h4>
16511663
</div>
16521664
<div style="clear: both"></div>
16531665
</div>
@@ -1666,7 +1678,7 @@ <h4 id="setDiff">std.setDiff(a, b)</h4>
16661678
<div class="hgroup">
16671679
<div class="hgroup-inline">
16681680
<div class="panel">
1669-
<h4 id="setMember">std.setMember(x, arr)</h4>
1681+
<h4 id="setMember">std.setMember(x, arr, keyF=id)</h4>
16701682
</div>
16711683
<div style="clear: both"></div>
16721684
</div>

0 commit comments

Comments
 (0)