Current section

Files

Jump to
parser_gleam src parser_gleam@stream.erl
Raw

src/parser_gleam@stream.erl

-module(parser_gleam@stream).
-compile(no_auto_import).
-export([stream/2, get/1, at_end/1, get_and_next/1, get_eq/1]).
-export_type([stream/1, it_and_next/1]).
-type stream(JYN) :: {stream, list(JYN), integer()}.
-type it_and_next(JYO) :: {it_and_next, JYO, stream(JYO)}.
-spec stream(list(JYR), gleam@option:option(integer())) -> stream(JYR).
stream(Buffer, Cursor) ->
{stream,
Buffer,
begin
_pipe = Cursor,
gleam@option:unwrap(_pipe, 0)
end}.
-spec get(stream(JYV)) -> gleam@option:option(JYV).
get(S) ->
_pipe = erlang:element(2, S),
_pipe@1 = gleam@list:at(_pipe, erlang:element(3, S)),
gleam@option:from_result(_pipe@1).
-spec at_end(stream(any())) -> boolean().
at_end(S) ->
erlang:element(3, S) >= gleam@list:length(erlang:element(2, S)).
-spec get_and_next(stream(JZC)) -> gleam@option:option(it_and_next(JZC)).
get_and_next(S) ->
_pipe = get(S),
gleam@option:map(
_pipe,
fun(Value) ->
{it_and_next,
Value,
{stream, erlang:element(2, S), erlang:element(3, S) + 1}}
end
).
-spec get_eq(fp_gl@eq:eq(JZG)) -> fp_gl@eq:eq(stream(JZG)).
get_eq(E) ->
fp_gl@eq:from_equals(
fun(X, Y) ->
Ea = fp_gl@flist:get_eq(E),
(erlang:element(3, X)
=:= erlang:element(3, Y))
andalso (erlang:element(2, Ea))(
erlang:element(2, X),
erlang:element(2, Y)
)
end
).