diff options
author | Quinn Wilton <wilton@synopsys.com> | 2020-12-02 11:39:09 -0800 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2020-12-02 20:13:15 +0000 |
commit | 88090877348a4f0c84b3ef497bab98a9a1e39e23 (patch) | |
tree | 748a2f4b9e33981d304db697858aae26ad79af82 | |
parent | e3178fb8d056b2e55f0baa041be313d9c4bd1ff4 (diff) | |
download | gleam_stdlib-88090877348a4f0c84b3ef497bab98a9a1e39e23.tar.gz gleam_stdlib-88090877348a4f0c84b3ef497bab98a9a1e39e23.zip |
Add bool.nor
-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 0792057..707d295 100644 --- a/src/gleam/bool.gleam +++ b/src/gleam/bool.gleam @@ -30,6 +30,31 @@ pub fn negate(bool: Bool) -> Bool { } } +/// Returns the nor of two bools +/// +/// ## Examples +/// +/// > nor(False, False) +/// True +/// +/// > nor(False, True) +/// False +/// +/// > nor(True, False) +/// False +/// +/// > nor(True, True) +/// False +/// +pub fn nor(a: Bool, b: Bool) -> Bool { + case a, b { + False, False -> True + False, True -> False + True, False -> False + True, True -> False + } +} + /// Returns the exclusive or of two bools /// /// ## Examples diff --git a/test/gleam/bool_test.gleam b/test/gleam/bool_test.gleam index c2ef78b..ad47ea2 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 nor_test() { + bool.nor(False, False) + |> should.be_true + + bool.nor(False, True) + |> should.be_false + + bool.nor(True, False) + |> should.be_false + + bool.nor(True, True) + |> should.be_false +} + pub fn exclusive_or_test() { bool.exclusive_or(True, True) |> should.be_false |