aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Puc <marcin.e.puc@gmail.com>2021-04-12 13:43:44 +0200
committerLouis Pilfold <louis@lpil.uk>2021-04-13 10:50:44 +0100
commit82aec2d14a7494120d0054d04d8679190abb7351 (patch)
tree0251a2c84cf691157c3269b9e1f9581bdb78a52a
parentffeb3757f291dbff55c772b7d622e22dac79352c (diff)
downloadgleam_stdlib-82aec2d14a7494120d0054d04d8679190abb7351.tar.gz
gleam_stdlib-82aec2d14a7494120d0054d04d8679190abb7351.zip
Rename `map_reduce` to `map_fold`
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/gleam/list.gleam4
-rw-r--r--test/gleam/list_test.gleam4
3 files changed, 5 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 663be69..619771b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,7 +7,7 @@
- The `dynamic` module gains the `tuple3`, `tuple4`, `tuple5`, `tuple6`
functions and their typed equivalents `typed_tuple3`, `typed_tuple4`,
`typed_tuple5`, `typed_tuple6`.
-- The `list` module gains the `drop_while`, `map_reduce`, `take_while`,
+- The `list` module gains the `drop_while`, `map_fold`, `take_while`,
`chunk` and `sized_chunk` functions.
- The `iterator` module gains the `index`, `iterate`, `zip`, `scan`,
`take_while`, `drop_while`, `chunk`, `sized_chunk`, `intersperse`, `any` and `all` functions.
diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam
index 972da23..dc03ec1 100644
--- a/src/gleam/list.gleam
+++ b/src/gleam/list.gleam
@@ -251,7 +251,7 @@ pub fn map(list: List(a), with fun: fn(a) -> b) -> List(b) {
/// ## Examples
///
/// ```
-/// > map_reduce(
+/// > map_fold(
/// over: [1, 2, 3],
/// from: 100,
/// with: fn(i, memo) { tuple(i * 2, memo + i) }
@@ -259,7 +259,7 @@ pub fn map(list: List(a), with fun: fn(a) -> b) -> List(b) {
/// tuple([2, 4, 6], 106)
/// ```
///
-pub fn map_reduce(
+pub fn map_fold(
over list: List(a),
from memo: memo,
with fun: fn(a, memo) -> tuple(b, memo),
diff --git a/test/gleam/list_test.gleam b/test/gleam/list_test.gleam
index fc8ea11..bf93203 100644
--- a/test/gleam/list_test.gleam
+++ b/test/gleam/list_test.gleam
@@ -99,9 +99,9 @@ pub fn map_test() {
|> should.equal([0, 8, 10, 14, 6])
}
-pub fn map_reduce_test() {
+pub fn map_fold_test() {
[1, 2, 3, 4]
- |> list.map_reduce(from: 0, with: fn(i, acc) { tuple(i * 2, acc + i) })
+ |> list.map_fold(from: 0, with: fn(i, acc) { tuple(i * 2, acc + i) })
|> should.equal(tuple([2, 4, 6, 8], 10))
}