Packages

A fork of the Gleam standard library for Glistix's Nix target

Current section

Files

Jump to
glistix_stdlib src gleam@result.erl
Raw

src/gleam@result.erl

-module(gleam@result).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([is_ok/1, is_error/1, map/2, map_error/2, flatten/1, 'try'/2, then/2, unwrap/2, lazy_unwrap/2, unwrap_error/2, unwrap_both/1, nil_error/1, 'or'/2, lazy_or/2, all/1, partition/1, replace/2, replace_error/2, values/1, try_recover/2]).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/result.gleam", 20).
-spec is_ok({ok, any()} | {error, any()}) -> boolean().
is_ok(Result) ->
case Result of
{error, _} ->
false;
{ok, _} ->
true
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/result.gleam", 41).
-spec is_error({ok, any()} | {error, any()}) -> boolean().
is_error(Result) ->
case Result of
{ok, _} ->
false;
{error, _} ->
true
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/result.gleam", 66).
-spec map({ok, BMQ} | {error, BMR}, fun((BMQ) -> BMU)) -> {ok, BMU} |
{error, BMR}.
map(Result, Fun) ->
case Result of
{ok, X} ->
{ok, Fun(X)};
{error, E} ->
{error, E}
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/result.gleam", 91).
-spec map_error({ok, BMX} | {error, BMY}, fun((BMY) -> BNB)) -> {ok, BMX} |
{error, BNB}.
map_error(Result, Fun) ->
case Result of
{ok, X} ->
{ok, X};
{error, Error} ->
{error, Fun(Error)}
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/result.gleam", 120).
-spec flatten({ok, {ok, BNE} | {error, BNF}} | {error, BNF}) -> {ok, BNE} |
{error, BNF}.
flatten(Result) ->
case Result of
{ok, X} ->
X;
{error, Error} ->
{error, Error}
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/result.gleam", 158).
-spec 'try'({ok, BNM} | {error, BNN}, fun((BNM) -> {ok, BNQ} | {error, BNN})) -> {ok,
BNQ} |
{error, BNN}.
'try'(Result, Fun) ->
case Result of
{ok, X} ->
Fun(X);
{error, E} ->
{error, E}
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/result.gleam", 170).
-spec then({ok, BNV} | {error, BNW}, fun((BNV) -> {ok, BNZ} | {error, BNW})) -> {ok,
BNZ} |
{error, BNW}.
then(Result, Fun) ->
'try'(Result, Fun).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/result.gleam", 192).
-spec unwrap({ok, BOE} | {error, any()}, BOE) -> BOE.
unwrap(Result, Default) ->
case Result of
{ok, V} ->
V;
{error, _} ->
Default
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/result.gleam", 214).
-spec lazy_unwrap({ok, BOI} | {error, any()}, fun(() -> BOI)) -> BOI.
lazy_unwrap(Result, Default) ->
case Result of
{ok, V} ->
V;
{error, _} ->
Default()
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/result.gleam", 236).
-spec unwrap_error({ok, any()} | {error, BON}, BON) -> BON.
unwrap_error(Result, Default) ->
case Result of
{ok, _} ->
Default;
{error, E} ->
E
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/result.gleam", 258).
-spec unwrap_both({ok, BOQ} | {error, BOQ}) -> BOQ.
unwrap_both(Result) ->
case Result of
{ok, A} ->
A;
{error, A@1} ->
A@1
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/result.gleam", 279).
-spec nil_error({ok, BOT} | {error, any()}) -> {ok, BOT} | {error, nil}.
nil_error(Result) ->
map_error(Result, fun(_) -> nil end).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/result.gleam", 307).
-spec 'or'({ok, BOZ} | {error, BPA}, {ok, BOZ} | {error, BPA}) -> {ok, BOZ} |
{error, BPA}.
'or'(First, Second) ->
case First of
{ok, _} ->
First;
{error, _} ->
Second
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/result.gleam", 338).
-spec lazy_or({ok, BPH} | {error, BPI}, fun(() -> {ok, BPH} | {error, BPI})) -> {ok,
BPH} |
{error, BPI}.
lazy_or(First, Second) ->
case First of
{ok, _} ->
First;
{error, _} ->
Second()
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/result.gleam", 364).
-spec all(list({ok, BPP} | {error, BPQ})) -> {ok, list(BPP)} | {error, BPQ}.
all(Results) ->
gleam@list:try_map(Results, fun(X) -> X end).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/result.gleam", 384).
-spec do_partition(list({ok, BQE} | {error, BQF}), list(BQE), list(BQF)) -> {list(BQE),
list(BQF)}.
do_partition(Results, Oks, Errors) ->
case Results of
[] ->
{Oks, Errors};
[{ok, A} | Rest] ->
do_partition(Rest, [A | Oks], Errors);
[{error, E} | Rest@1] ->
do_partition(Rest@1, Oks, [E | Errors])
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/result.gleam", 380).
-spec partition(list({ok, BPX} | {error, BPY})) -> {list(BPX), list(BPY)}.
partition(Results) ->
do_partition(Results, [], []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/result.gleam", 406).
-spec replace({ok, any()} | {error, BQN}, BQQ) -> {ok, BQQ} | {error, BQN}.
replace(Result, Value) ->
case Result of
{ok, _} ->
{ok, Value};
{error, Error} ->
{error, Error}
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/result.gleam", 427).
-spec replace_error({ok, BQT} | {error, any()}, BQX) -> {ok, BQT} | {error, BQX}.
replace_error(Result, Error) ->
case Result of
{ok, X} ->
{ok, X};
{error, _} ->
{error, Error}
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/result.gleam", 443).
-spec values(list({ok, BRA} | {error, any()})) -> list(BRA).
values(Results) ->
gleam@list:filter_map(Results, fun(R) -> R end).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/result.gleam", 474).
-spec try_recover(
{ok, BRG} | {error, BRH},
fun((BRH) -> {ok, BRG} | {error, BRK})
) -> {ok, BRG} | {error, BRK}.
try_recover(Result, Fun) ->
case Result of
{ok, Value} ->
{ok, Value};
{error, Error} ->
Fun(Error)
end.