aboutsummaryrefslogtreecommitdiff
path: root/aoc2023/build/packages/glint/src/glint@flag@constraint.erl
diff options
context:
space:
mode:
authorJ.J <thechairman@thechairman.info>2024-05-30 21:50:02 -0400
committerJ.J <thechairman@thechairman.info>2024-05-30 21:50:02 -0400
commit612fd986ab1e00b6d34dc1937136250e08e89325 (patch)
treea3c93952040c6afdf348b5831619a45db7ba0a2e /aoc2023/build/packages/glint/src/glint@flag@constraint.erl
parent231c2b688d1e6cf0846d46e883da30e042a9c6cf (diff)
downloadgleam_aoc-612fd986ab1e00b6d34dc1937136250e08e89325.tar.gz
gleam_aoc-612fd986ab1e00b6d34dc1937136250e08e89325.zip
cleanup
Diffstat (limited to 'aoc2023/build/packages/glint/src/glint@flag@constraint.erl')
-rw-r--r--aoc2023/build/packages/glint/src/glint@flag@constraint.erl68
1 files changed, 68 insertions, 0 deletions
diff --git a/aoc2023/build/packages/glint/src/glint@flag@constraint.erl b/aoc2023/build/packages/glint/src/glint@flag@constraint.erl
new file mode 100644
index 0000000..2978be0
--- /dev/null
+++ b/aoc2023/build/packages/glint/src/glint@flag@constraint.erl
@@ -0,0 +1,68 @@
+-module(glint@flag@constraint).
+-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function]).
+
+-export([one_of/1, none_of/1, each/1]).
+
+-spec one_of(list(FSI)) -> fun((FSI) -> {ok, nil} | {error, snag:snag()}).
+one_of(Allowed) ->
+ Allowed_set = gleam@set:from_list(Allowed),
+ fun(Val) -> case gleam@set:contains(Allowed_set, Val) of
+ true ->
+ {ok, nil};
+
+ false ->
+ snag:error(
+ <<<<<<"invalid value '"/utf8,
+ (gleam@string:inspect(Val))/binary>>/binary,
+ "', must be one of: ["/utf8>>/binary,
+ ((<<(begin
+ _pipe = Allowed,
+ _pipe@1 = gleam@list:map(
+ _pipe,
+ fun(A) ->
+ <<<<"'"/utf8,
+ (gleam@string:inspect(A))/binary>>/binary,
+ "'"/utf8>>
+ end
+ ),
+ gleam@string:join(_pipe@1, <<", "/utf8>>)
+ end)/binary,
+ "]"/utf8>>))/binary>>
+ )
+ end end.
+
+-spec none_of(list(FSL)) -> fun((FSL) -> {ok, nil} | {error, snag:snag()}).
+none_of(Disallowed) ->
+ Disallowed_set = gleam@set:from_list(Disallowed),
+ fun(Val) -> case gleam@set:contains(Disallowed_set, Val) of
+ false ->
+ {ok, nil};
+
+ true ->
+ snag:error(
+ <<<<<<"invalid value '"/utf8,
+ (gleam@string:inspect(Val))/binary>>/binary,
+ "', must not be one of: ["/utf8>>/binary,
+ (((<<(begin
+ _pipe = Disallowed,
+ _pipe@1 = gleam@list:map(
+ _pipe,
+ fun(A) ->
+ <<<<"'"/utf8,
+ (gleam@string:inspect(A))/binary>>/binary,
+ "'"/utf8>>
+ end
+ ),
+ gleam@string:join(_pipe@1, <<", "/utf8>>)
+ end)/binary,
+ "]"/utf8>>)))/binary>>
+ )
+ end end.
+
+-spec each(fun((FSO) -> {ok, nil} | {error, snag:snag()})) -> fun((list(FSO)) -> {ok,
+ nil} |
+ {error, snag:snag()}).
+each(Constraint) ->
+ fun(L) -> _pipe = L,
+ _pipe@1 = gleam@list:try_map(_pipe, Constraint),
+ gleam@result:replace(_pipe@1, nil) end.