aboutsummaryrefslogtreecommitdiff
path: root/aoc2023/build/packages/gleam_stdlib/src/gleam@bool.erl
diff options
context:
space:
mode:
authorHJ <thechairman@thechairman.info>2024-02-03 15:09:54 -0500
committerHJ <thechairman@thechairman.info>2024-02-03 15:09:54 -0500
commit96a3c5c179d8d3fff24eb2953e45f8dd15e2714c (patch)
tree0a67bc0cfeabe51740bb049c61f16f1ac3bdd4ff /aoc2023/build/packages/gleam_stdlib/src/gleam@bool.erl
parent547fe03cf43105f46160e2dd9afff21637eaaf47 (diff)
downloadgleam_aoc-96a3c5c179d8d3fff24eb2953e45f8dd15e2714c.tar.gz
gleam_aoc-96a3c5c179d8d3fff24eb2953e45f8dd15e2714c.zip
cleanup
Diffstat (limited to 'aoc2023/build/packages/gleam_stdlib/src/gleam@bool.erl')
-rw-r--r--aoc2023/build/packages/gleam_stdlib/src/gleam@bool.erl162
1 files changed, 162 insertions, 0 deletions
diff --git a/aoc2023/build/packages/gleam_stdlib/src/gleam@bool.erl b/aoc2023/build/packages/gleam_stdlib/src/gleam@bool.erl
new file mode 100644
index 0000000..cd55358
--- /dev/null
+++ b/aoc2023/build/packages/gleam_stdlib/src/gleam@bool.erl
@@ -0,0 +1,162 @@
+-module(gleam@bool).
+-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function]).
+
+-export(['and'/2, 'or'/2, negate/1, nor/2, nand/2, exclusive_or/2, exclusive_nor/2, compare/2, max/2, min/2, to_int/1, to_string/1, guard/3, lazy_guard/3]).
+
+-spec 'and'(boolean(), boolean()) -> boolean().
+'and'(A, B) ->
+ A andalso B.
+
+-spec 'or'(boolean(), boolean()) -> boolean().
+'or'(A, B) ->
+ A orelse B.
+
+-spec negate(boolean()) -> boolean().
+negate(Bool) ->
+ case Bool of
+ true ->
+ false;
+
+ false ->
+ true
+ end.
+
+-spec nor(boolean(), boolean()) -> boolean().
+nor(A, B) ->
+ case {A, B} of
+ {false, false} ->
+ true;
+
+ {false, true} ->
+ false;
+
+ {true, false} ->
+ false;
+
+ {true, true} ->
+ false
+ end.
+
+-spec nand(boolean(), boolean()) -> boolean().
+nand(A, B) ->
+ case {A, B} of
+ {false, false} ->
+ true;
+
+ {false, true} ->
+ true;
+
+ {true, false} ->
+ true;
+
+ {true, true} ->
+ false
+ end.
+
+-spec exclusive_or(boolean(), boolean()) -> boolean().
+exclusive_or(A, B) ->
+ case {A, B} of
+ {false, false} ->
+ false;
+
+ {false, true} ->
+ true;
+
+ {true, false} ->
+ true;
+
+ {true, true} ->
+ false
+ end.
+
+-spec exclusive_nor(boolean(), boolean()) -> boolean().
+exclusive_nor(A, B) ->
+ case {A, B} of
+ {false, false} ->
+ true;
+
+ {false, true} ->
+ false;
+
+ {true, false} ->
+ false;
+
+ {true, true} ->
+ true
+ end.
+
+-spec compare(boolean(), boolean()) -> gleam@order:order().
+compare(A, B) ->
+ case {A, B} of
+ {true, true} ->
+ eq;
+
+ {true, false} ->
+ gt;
+
+ {false, false} ->
+ eq;
+
+ {false, true} ->
+ lt
+ end.
+
+-spec max(boolean(), boolean()) -> boolean().
+max(A, B) ->
+ case A of
+ true ->
+ true;
+
+ false ->
+ B
+ end.
+
+-spec min(boolean(), boolean()) -> boolean().
+min(A, B) ->
+ case A of
+ false ->
+ false;
+
+ true ->
+ B
+ end.
+
+-spec to_int(boolean()) -> integer().
+to_int(Bool) ->
+ case Bool of
+ false ->
+ 0;
+
+ true ->
+ 1
+ end.
+
+-spec to_string(boolean()) -> binary().
+to_string(Bool) ->
+ case Bool of
+ false ->
+ <<"False"/utf8>>;
+
+ true ->
+ <<"True"/utf8>>
+ end.
+
+-spec guard(boolean(), DDZ, fun(() -> DDZ)) -> DDZ.
+guard(Requirement, Consequence, Alternative) ->
+ case Requirement of
+ true ->
+ Consequence;
+
+ false ->
+ Alternative()
+ end.
+
+-spec lazy_guard(boolean(), fun(() -> DEA), fun(() -> DEA)) -> DEA.
+lazy_guard(Requirement, Consequence, Alternative) ->
+ case Requirement of
+ true ->
+ Consequence();
+
+ false ->
+ Alternative()
+ end.