diff options
author | Marcin Puc <marcin.e.puc@gmail.com> | 2021-03-17 19:20:19 +0100 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2021-03-20 13:35:54 +0000 |
commit | aaa3bcac4757f46edae58c8d4fa30411ede2c7a2 (patch) | |
tree | 62263aeae9849fb573ce595cf850f17b1fb897e5 | |
parent | f97bc1a39a588c775d44dd4baedce3e1ac2414f5 (diff) | |
download | gleam_stdlib-aaa3bcac4757f46edae58c8d4fa30411ede2c7a2.tar.gz gleam_stdlib-aaa3bcac4757f46edae58c8d4fa30411ede2c7a2.zip |
Simplify the next_chunk_by helpers
-rw-r--r-- | src/gleam/iterator.gleam | 8 | ||||
-rw-r--r-- | src/gleam/list.gleam | 6 |
2 files changed, 2 insertions, 12 deletions
diff --git a/src/gleam/iterator.gleam b/src/gleam/iterator.gleam index 3fa74d0..7e16121 100644 --- a/src/gleam/iterator.gleam +++ b/src/gleam/iterator.gleam @@ -664,7 +664,6 @@ pub fn zip(left: Iterator(a), right: Iterator(b)) -> Iterator(tuple(a, b)) { type ChunkBy(element, key) { AnotherBy(List(element), key, element, fn() -> Action(element)) LastBy(List(element)) - NoneBy } fn next_chunk_by( @@ -674,11 +673,7 @@ fn next_chunk_by( current_chunk: List(element), ) -> ChunkBy(element, key) { case continuation() { - Stop -> - case current_chunk { - [] -> NoneBy - remaining -> LastBy(list.reverse(remaining)) - } + Stop -> LastBy(list.reverse(current_chunk)) Continue(e, next) -> { let key = f(e) case key == previous_key { @@ -696,7 +691,6 @@ fn do_chunk_by( previous_element: element, ) -> Action(List(element)) { case next_chunk_by(continuation, f, previous_key, [previous_element]) { - NoneBy -> Stop LastBy(chunk) -> Continue(chunk, stop) AnotherBy(chunk, key, el, next) -> Continue(chunk, fn() { do_chunk_by(next, f, key, el) }) diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam index 9572e36..df62886 100644 --- a/src/gleam/list.gleam +++ b/src/gleam/list.gleam @@ -1278,11 +1278,7 @@ fn do_chunk_by( acc: List(List(a)), ) -> List(List(a)) { case list { - [] -> - case current_chunk { - [] -> reverse(acc) - remaining -> reverse([reverse(remaining), ..acc]) - } + [] -> reverse([reverse(current_chunk), ..acc]) [head, ..tail] -> { let key = f(head) case key == previous_key { |