aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastian Porto <s@porto5.com>2021-05-08 00:57:56 +1000
committerGitHub <noreply@github.com>2021-05-07 14:57:56 +0000
commit7b10d02d88af84560855337e45c755686a396943 (patch)
treed5a62c86418a92753578594c3e915bb3748dabbe /src
parent26f42e83dd5a842e4463b1613729c16f0251cef4 (diff)
downloadgleam_stdlib-7b10d02d88af84560855337e45c755686a396943.tar.gz
gleam_stdlib-7b10d02d88af84560855337e45c755686a396943.zip
Add option.values (#203)
Diffstat (limited to 'src')
-rw-r--r--src/gleam/option.gleam16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/gleam/option.gleam b/src/gleam/option.gleam
index f74abbd..8045a28 100644
--- a/src/gleam/option.gleam
+++ b/src/gleam/option.gleam
@@ -1,3 +1,5 @@
+import gleam/list
+
/// Option represents a value that may be present or not. Some means the value is
/// present, None means the value is not.
///
@@ -180,3 +182,17 @@ pub fn or(first: Option(a), second: Option(a)) -> Option(a) {
None -> second
}
}
+
+/// Given a list of options
+/// Return only the values inside Some
+///
+/// ## Examples
+///
+/// ```
+/// > values([Some(1), None, Some(3)])
+/// [1, 3]
+/// ```
+///
+pub fn values(options: List(Option(a))) -> List(a) {
+ list.filter_map(options, fn(op) { to_result(op, "") })
+}