Skip to content

Commit b725319

Browse files
khalidbelklpil
authored andcommitted
feat: add index_fold examples
1 parent fa71fd6 commit b725319

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/gleam/list.gleam

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,14 @@ pub fn fold_right(
785785
///
786786
/// ```gleam
787787
/// ["a", "b", "c"]
788-
/// |> index_fold([], fn(acc, item, index) { ... })
788+
/// |> index_fold("", fn(acc, item, index) { acc <> int.to_string(index) <> ":" <> item <> " " })
789+
/// // -> 0:a 1:b 2:c
790+
/// ```
791+
///
792+
/// ```gleam
793+
/// [10, 20, 30]
794+
/// |> index_fold(0, fn(acc, item, index) { acc + item * index })
795+
/// // -> 80
789796
/// ```
790797
///
791798
pub fn index_fold(

0 commit comments

Comments
 (0)