aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
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, "") })
+}