aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRyan M. Moore <rmm1047@gmail.com>2024-04-28 18:32:16 -0400
committerLouis Pilfold <louis@lpil.uk>2024-04-30 16:16:20 +0100
commit45014c39ae35a9f9471cf3334aaeee7237128f91 (patch)
tree6e469b55f07e6ebc3efa3f39fe9770fee8abdea4 /src
parent867cd81c3ce1548133a4ef9c27299a253b8a0e88 (diff)
downloadgleam_stdlib-45014c39ae35a9f9471cf3334aaeee7237128f91.tar.gz
gleam_stdlib-45014c39ae35a9f9471cf3334aaeee7237128f91.zip
Add `list.wrap`
Diffstat (limited to 'src')
-rw-r--r--src/gleam/list.gleam20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam
index d53e95e..a01460c 100644
--- a/src/gleam/list.gleam
+++ b/src/gleam/list.gleam
@@ -582,6 +582,26 @@ pub fn new() -> List(a) {
[]
}
+/// Returns the given item wrapped in a list.
+///
+/// ## Examples
+///
+/// ```gleam
+/// wrap(1)
+/// // -> [1]
+///
+/// wrap(["a", "b", "c"])
+/// // -> [["a", "b", "c"]]
+///
+/// wrap([[]])
+/// // -> [[[]]]
+/// ```
+///
+///
+pub fn wrap(item: a) -> List(a) {
+ [item]
+}
+
/// Joins one list onto the end of another.
///
/// This function runs in linear time, and it traverses and copies the first