aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAl Dee <amyalicedee@gmail.com>2020-05-22 13:34:23 +0100
committerLouis Pilfold <louis@lpil.uk>2020-05-26 19:19:29 +0100
commit33bbf866ed3be72ccce955e5b2ee1bb99fa45e97 (patch)
treea757a075abfdf8f50114890e7035c9eaa24f79c6 /src
parentd33db5b1bcc1f48b9c311419c3d76bb0d17531df (diff)
downloadgleam_stdlib-33bbf866ed3be72ccce955e5b2ee1bb99fa45e97.tar.gz
gleam_stdlib-33bbf866ed3be72ccce955e5b2ee1bb99fa45e97.zip
Add the Option type.
Diffstat (limited to 'src')
-rw-r--r--src/gleam/option.gleam38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/gleam/option.gleam b/src/gleam/option.gleam
new file mode 100644
index 0000000..30bc1e2
--- /dev/null
+++ b/src/gleam/option.gleam
@@ -0,0 +1,38 @@
+/// Option represents a value that may be present or not. Some means the value is
+/// present, None means the value is not.
+///
+/// This is Gleam's alternative to having a value that could be Null, as is
+/// possible in some other languages.
+///
+pub type Option(a) {
+ Some(a)
+ None
+}
+
+/// Check whether the option is a Some value.
+///
+/// ## Examples
+///
+/// > is_some(Some(1))
+/// True
+///
+/// > is_some(None)
+/// False
+///
+pub fn is_some(option: Option(a)) -> Bool {
+ option != None
+}
+
+/// Check whether the option is a None value.
+///
+/// ## Examples
+///
+/// > is_none(Some(1))
+/// False
+///
+/// > is_none(None)
+/// True
+///
+pub fn is_none(option: Option(a)) -> Bool {
+ option == None
+}