aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorE Jikan <e@vstream-corp.com>2022-04-07 17:20:55 -0700
committerLouis Pilfold <louis@lpil.uk>2022-04-16 11:17:19 +0100
commit377dcd20aa5b183eb5f66245cb8c72a7e625dff0 (patch)
tree32340bee930a1e1c6a0b402e0ae18cf7024a963b
parentf292b0bb99965e98b61f800f9f5ce61587b8328c (diff)
downloadgleam_stdlib-377dcd20aa5b183eb5f66245cb8c72a7e625dff0.tar.gz
gleam_stdlib-377dcd20aa5b183eb5f66245cb8c72a7e625dff0.zip
feat(list): Add `prepend` to list module
While this can also be done via the built-in syntax it's nice to have a complete standard library including this function.
-rw-r--r--src/gleam/list.gleam9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam
index 9acc6ce..c74bd20 100644
--- a/src/gleam/list.gleam
+++ b/src/gleam/list.gleam
@@ -488,6 +488,15 @@ if javascript {
}
}
+/// Prefixes an item to a list. This can also be done using the dedicated
+/// syntax instead
+///
+/// let new_list = [1, ..existing_list]
+///
+pub fn prepend(to list: List(a), item: a) -> List(a) {
+ [item, ..list]
+}
+
fn do_flatten(lists: List(List(a)), acc: List(a)) -> List(a) {
case lists {
[] -> acc