aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcin Puc <marcin.e.puc@gmail.com>2021-03-17 19:27:49 +0100
committerLouis Pilfold <louis@lpil.uk>2021-03-20 13:35:54 +0000
commitbfc3589325a94c68d5dd08ebbecb8d1767dfdef2 (patch)
treeee48a6fc9776865452c86549a5006fd00ef39bc1 /src
parentaaa3bcac4757f46edae58c8d4fa30411ede2c7a2 (diff)
downloadgleam_stdlib-bfc3589325a94c68d5dd08ebbecb8d1767dfdef2.tar.gz
gleam_stdlib-bfc3589325a94c68d5dd08ebbecb8d1767dfdef2.zip
Rename chunk_by to chunk
Diffstat (limited to 'src')
-rw-r--r--src/gleam/iterator.gleam22
-rw-r--r--src/gleam/list.gleam13
2 files changed, 17 insertions, 18 deletions
diff --git a/src/gleam/iterator.gleam b/src/gleam/iterator.gleam
index 7e16121..3a939d0 100644
--- a/src/gleam/iterator.gleam
+++ b/src/gleam/iterator.gleam
@@ -661,39 +661,39 @@ pub fn zip(left: Iterator(a), right: Iterator(b)) -> Iterator(tuple(a, b)) {
|> Iterator
}
-type ChunkBy(element, key) {
+type Chunk(element, key) {
AnotherBy(List(element), key, element, fn() -> Action(element))
LastBy(List(element))
}
-fn next_chunk_by(
+fn next_chunk(
continuation: fn() -> Action(element),
f: fn(element) -> key,
previous_key: key,
current_chunk: List(element),
-) -> ChunkBy(element, key) {
+) -> Chunk(element, key) {
case continuation() {
Stop -> LastBy(list.reverse(current_chunk))
Continue(e, next) -> {
let key = f(e)
case key == previous_key {
- True -> next_chunk_by(next, f, key, [e, ..current_chunk])
+ True -> next_chunk(next, f, key, [e, ..current_chunk])
False -> AnotherBy(list.reverse(current_chunk), key, e, next)
}
}
}
}
-fn do_chunk_by(
+fn do_chunk(
continuation: fn() -> Action(element),
f: fn(element) -> key,
previous_key: key,
previous_element: element,
) -> Action(List(element)) {
- case next_chunk_by(continuation, f, previous_key, [previous_element]) {
+ case next_chunk(continuation, f, previous_key, [previous_element]) {
LastBy(chunk) -> Continue(chunk, stop)
AnotherBy(chunk, key, el, next) ->
- Continue(chunk, fn() { do_chunk_by(next, f, key, el) })
+ Continue(chunk, fn() { do_chunk(next, f, key, el) })
}
}
@@ -702,17 +702,17 @@ fn do_chunk_by(
///
/// ## Examples
///
-/// > from_list([1, 2, 2, 3, 4, 4, 6, 7, 7]) |> chunk_by(fn(n) { n % 2 }) |> to_list
+/// > from_list([1, 2, 2, 3, 4, 4, 6, 7, 7]) |> chunk(by: fn(n) { n % 2 }) |> to_list
/// [[1], [2, 2], [3], [4, 4, 6], [7, 7]]
///
-pub fn chunk_by(
+pub fn chunk(
over iterator: Iterator(element),
- with f: fn(element) -> key,
+ by f: fn(element) -> key,
) -> Iterator(List(element)) {
fn() {
case iterator.continuation() {
Stop -> Stop
- Continue(e, next) -> do_chunk_by(next, f, f(e), e)
+ Continue(e, next) -> do_chunk(next, f, f(e), e)
}
}
|> Iterator
diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam
index df62886..066c584 100644
--- a/src/gleam/list.gleam
+++ b/src/gleam/list.gleam
@@ -1270,7 +1270,7 @@ pub fn take_while(
do_take_while(list, predicate, [])
}
-fn do_chunk_by(
+fn do_chunk(
list: List(a),
f: fn(a) -> key,
previous_key: key,
@@ -1282,9 +1282,8 @@ fn do_chunk_by(
[head, ..tail] -> {
let key = f(head)
case key == previous_key {
- False ->
- do_chunk_by(tail, f, key, [head], [reverse(current_chunk), ..acc])
- True -> do_chunk_by(tail, f, key, [head, ..current_chunk], acc)
+ False -> do_chunk(tail, f, key, [head], [reverse(current_chunk), ..acc])
+ True -> do_chunk(tail, f, key, [head, ..current_chunk], acc)
}
}
}
@@ -1295,12 +1294,12 @@ fn do_chunk_by(
///
/// ## Examples
///
-/// > [1, 2, 2, 3, 4, 4, 6, 7, 7] |> chunk_by(fn(n) { n % 2 })
+/// > [1, 2, 2, 3, 4, 4, 6, 7, 7] |> chunk(by: fn(n) { n % 2 })
/// [[1], [2, 2], [3], [4, 4, 6], [7, 7]]
///
-pub fn chunk_by(in list: List(a), with f: fn(a) -> key) -> List(List(a)) {
+pub fn chunk(in list: List(a), by f: fn(a) -> key) -> List(List(a)) {
case list {
[] -> []
- [head, ..tail] -> do_chunk_by(tail, f, f(head), [head], [])
+ [head, ..tail] -> do_chunk(tail, f, f(head), [head], [])
}
}