From 377dcd20aa5b183eb5f66245cb8c72a7e625dff0 Mon Sep 17 00:00:00 2001 From: E Jikan Date: Thu, 7 Apr 2022 17:20:55 -0700 Subject: 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. --- src/gleam/list.gleam | 9 +++++++++ 1 file changed, 9 insertions(+) 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 -- cgit v1.2.3