diff options
author | Quinn Wilton <wilton@synopsys.com> | 2020-12-02 11:29:02 -0800 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2020-12-02 20:13:15 +0000 |
commit | 32d9d1622940323ec41ae991a62cf82427e16561 (patch) | |
tree | 0a495f2eba0f098848de59d1814b7dca7095dffa | |
parent | f040d1a317604c6f0c8e14b4149c5fd6771ada90 (diff) | |
download | gleam_stdlib-32d9d1622940323ec41ae991a62cf82427e16561.tar.gz gleam_stdlib-32d9d1622940323ec41ae991a62cf82427e16561.zip |
Add bool.exclusive_or
-rw-r--r-- | src/gleam/bool.gleam | 25 | ||||
-rw-r--r-- | test/gleam/bool_test.gleam | 14 |
2 files changed, 39 insertions, 0 deletions
diff --git a/src/gleam/bool.gleam b/src/gleam/bool.gleam index 4a9cebf..e5b079f 100644 --- a/src/gleam/bool.gleam +++ b/src/gleam/bool.gleam @@ -30,6 +30,31 @@ pub fn negate(bool: Bool) -> Bool { } } +/// Returns the exclusive or of two bools +/// +/// ## Examples +/// +/// > exclusive_or(False, False) +/// False +/// +/// > exclusive_or(False, True) +/// True +/// +/// > exclusive_or(True, False) +/// True +/// +/// > exclusive_or(True, True) +/// False +/// +pub fn exclusive_or(a: Bool, b: Bool) -> Bool { + case a, b { + False, False -> False + False, True -> True + True, False -> True + True, True -> False + } +} + /// Compares two bools and returns the first values Order to the second. /// /// ## Examples diff --git a/test/gleam/bool_test.gleam b/test/gleam/bool_test.gleam index a05327f..aced02b 100644 --- a/test/gleam/bool_test.gleam +++ b/test/gleam/bool_test.gleam @@ -10,6 +10,20 @@ pub fn negate_test() { |> should.be_true } +pub fn exclusive_or_test() { + bool.exclusive_or(True, True) + |> should.be_false + + bool.exclusive_or(False, False) + |> should.be_false + + bool.exclusive_or(True, False) + |> should.be_true + + bool.exclusive_or(False, True) + |> should.be_true +} + pub fn compare_test() { bool.compare(True, True) |> should.equal(order.Eq) |