diff options
author | inoas <mail@inoas.com> | 2022-04-12 21:04:33 +0200 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2022-04-16 10:23:34 +0100 |
commit | 6a345a4c0b18ce2f0ade80a99186518579898fc9 (patch) | |
tree | 03ea450b016350ce50994ebf4097927547c38d1b /src | |
parent | 1bfccbf42ffa22c20602dc4553d200a1ca1cc658 (diff) | |
download | gleam_stdlib-6a345a4c0b18ce2f0ade80a99186518579898fc9.tar.gz gleam_stdlib-6a345a4c0b18ce2f0ade80a99186518579898fc9.zip |
add int.distance()
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/int.gleam | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/gleam/int.gleam b/src/gleam/int.gleam index 1a31c0c..f23f0f9 100644 --- a/src/gleam/int.gleam +++ b/src/gleam/int.gleam @@ -18,6 +18,21 @@ pub fn absolute_value(num: Int) -> Int { } } +/// Returns the absolute distance of the inputs as a positive Int +/// +/// ## Examples +/// +/// > distance(-10, 10) +/// 20 +/// +/// > distance(0.0, -2) +/// 2 +/// +pub fn distance(a: Int, b: Int) -> Int { + a - b + |> absolute_value() +} + /// Parses a given string as an int if possible. /// /// ## Examples |