aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastian <s@porto5.com>2020-12-17 14:34:20 +1100
committerLouis Pilfold <louis@lpil.uk>2020-12-17 10:12:57 +0000
commit095d936bfcbf239d84e329b267aea0d6ebf15d33 (patch)
tree80be1a092edc71965165e2ce1acd230d9737c4e0 /src
parent78c90457dad39639dc384c046846d899c15f7cef (diff)
downloadgleam_stdlib-095d936bfcbf239d84e329b267aea0d6ebf15d33.tar.gz
gleam_stdlib-095d936bfcbf239d84e329b267aea0d6ebf15d33.zip
Add int.absolute_value
Diffstat (limited to 'src')
-rw-r--r--src/gleam/int.gleam17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/gleam/int.gleam b/src/gleam/int.gleam
index 002a155..a4a956a 100644
--- a/src/gleam/int.gleam
+++ b/src/gleam/int.gleam
@@ -3,6 +3,23 @@ import gleam/order.{Order}
pub type Int =
Int
+/// Returns the absolute value of the input.
+///
+/// ## Examples
+///
+/// > absolute_value(-12)
+/// 12
+///
+/// > absolute_value(10)
+/// 10
+///
+pub fn absolute_value(num: Int) -> Int {
+ case num >= 0 {
+ True -> num
+ False -> num * -1
+ }
+}
+
/// Parse a given string as an int if possible.
///
/// ## Examples