Skip to content

Commit 0b2daa7

Browse files
docs: clarify argument order in the foldl and foldr descriptions
Fixes #892 Fixes #788
1 parent f51a715 commit 0b2daa7

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

doc/_stdlib_gen/stdlib-content.jsonnet

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,21 +1227,31 @@ local exampleDocMultiline(mid, ex) =
12271227
name: 'foldl',
12281228
params: ['func', 'arr', 'init'],
12291229
availableSince: '0.10.0',
1230-
description: |||
1231-
Classic foldl function. Calls the function on the result of the previous function call and
1232-
each array element, or <code>init</code> in the case of the initial element. Traverses the
1233-
array from left to right.
1234-
|||,
1230+
description: html.paragraphs([
1231+
|||
1232+
Classic foldl function. Calls the function for each array element, passing the result from
1233+
the previous call (or <code>init</code> for the first call), and the array element. Traverses
1234+
the array from left to right.
1235+
|||,
1236+
|||
1237+
For example: <code>foldl(f, [1,2,3], 0)</code> is equivalent to <code>f(f(f(0, 1), 2), 3)</code>.
1238+
|||,
1239+
]),
12351240
},
12361241
{
12371242
name: 'foldr',
12381243
params: ['func', 'arr', 'init'],
12391244
availableSince: '0.10.0',
1240-
description: |||
1241-
Classic foldr function. Calls the function on the result of the previous function call and
1242-
each array element, or <code>init</code> in the case of the initial element. Traverses the
1243-
array from right to left.
1244-
|||,
1245+
description: html.paragraphs([
1246+
|||
1247+
Classic foldr function. Calls the function for each array element, passing the array element
1248+
and the result from the previous call (or <code>init</code> for the first call). Traverses
1249+
the array from right to left.
1250+
|||,
1251+
|||
1252+
For example: <code>foldr(f, [1,2,3], 0)</code> is equivalent to <code>f(1, f(2, f(3, 0)))</code>.
1253+
|||,
1254+
]),
12451255
},
12461256
{
12471257
name: 'range',

doc/ref/stdlib.html

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,9 +2235,12 @@ <h4 id="foldl">
22352235
</em>
22362236
</p>
22372237
<p>
2238-
Classic foldl function. Calls the function on the result of the previous function call and
2239-
each array element, or <code>init</code> in the case of the initial element. Traverses the
2240-
array from left to right.
2238+
Classic foldl function. Calls the function for each array element, passing the result from
2239+
the previous call (or <code>init</code> for the first call), and the array element. Traverses
2240+
the array from left to right.
2241+
</p>
2242+
<p>
2243+
For example: <code>foldl(f, [1,2,3], 0)</code> is equivalent to <code>f(f(f(0, 1), 2), 3)</code>.
22412244
</p>
22422245

22432246
</div>
@@ -2264,9 +2267,12 @@ <h4 id="foldr">
22642267
</em>
22652268
</p>
22662269
<p>
2267-
Classic foldr function. Calls the function on the result of the previous function call and
2268-
each array element, or <code>init</code> in the case of the initial element. Traverses the
2269-
array from right to left.
2270+
Classic foldr function. Calls the function for each array element, passing the array element
2271+
and the result from the previous call (or <code>init</code> for the first call). Traverses
2272+
the array from right to left.
2273+
</p>
2274+
<p>
2275+
For example: <code>foldr(f, [1,2,3], 0)</code> is equivalent to <code>f(1, f(2, f(3, 0)))</code>.
22702276
</p>
22712277

22722278
</div>

0 commit comments

Comments
 (0)