Current section
Files
Jump to
Current section
Files
src/stdin.erl
-module(stdin).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([read_lines/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-file("src/stdin.gleam", 10).
-spec read_line() -> {ok, binary()} | {error, nil}.
read_line() ->
_pipe = io:get_line(<<""/utf8>>),
_pipe@1 = gleam@dynamic@decode:run(
_pipe,
{decoder, fun gleam@dynamic@decode:decode_string/1}
),
gleam@result:replace_error(_pipe@1, nil).
-file("src/stdin.gleam", 16).
-spec assert_upwrap({ok, ETG} | {error, any()}) -> ETG.
assert_upwrap(Res) ->
{ok, A} = case Res of
{ok, _} -> Res;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail,
module => <<"stdin"/utf8>>,
function => <<"assert_upwrap"/utf8>>,
line => 17})
end,
A.
-file("src/stdin.gleam", 22).
?DOC(" Reads and yields lines from stdin until EOF.\n").
-spec read_lines() -> gleam@yielder:yielder(binary()).
read_lines() ->
_pipe = gleam@yielder:repeatedly(fun read_line/0),
_pipe@1 = gleam@yielder:take_while(_pipe, fun gleam@result:is_ok/1),
gleam@yielder:map(_pipe@1, fun assert_upwrap/1).