Current section
Files
Jump to
Current section
Files
src/deriv@example@foo.erl
-module(deriv@example@foo).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([decoder_foo/0, encode_foo/1, decoder_bar/0]).
-export_type([foo/0, bar/0]).
-type foo() :: {foo,
youid@uuid:uuid(),
integer(),
binary(),
boolean(),
float(),
gleam@option:option(binary()),
list(binary())}.
-type bar() :: {bar, boolean()}.
-file("src/deriv/example/foo.gleam", 25).
-spec decoder_foo() -> decode:decoder(foo()).
decoder_foo() ->
_pipe = decode:into(
begin
decode:parameter(
fun(Uuid) ->
decode:parameter(
fun(Id) ->
decode:parameter(
fun(Name) ->
decode:parameter(
fun(Active) ->
decode:parameter(
fun(Ratio) ->
decode:parameter(
fun(Maybe) ->
decode:parameter(
fun(Words) ->
{foo,
Uuid,
Id,
Name,
Active,
Ratio,
Maybe,
Words}
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
),
_pipe@1 = decode:field(_pipe, <<"uuid"/utf8>>, deriv@util:decoder_uuid()),
_pipe@2 = decode:field(
_pipe@1,
<<"id"/utf8>>,
{decoder, fun gleam@dynamic:int/1}
),
_pipe@3 = decode:field(
_pipe@2,
<<"name"/utf8>>,
{decoder, fun gleam@dynamic:string/1}
),
_pipe@4 = decode:field(
_pipe@3,
<<"active"/utf8>>,
{decoder, fun gleam@dynamic:bool/1}
),
_pipe@5 = decode:field(
_pipe@4,
<<"ratio"/utf8>>,
{decoder, fun gleam@dynamic:float/1}
),
_pipe@6 = decode:field(
_pipe@5,
<<"maybe"/utf8>>,
decode:optional({decoder, fun gleam@dynamic:string/1})
),
decode:field(
_pipe@6,
<<"words"/utf8>>,
decode:list({decoder, fun gleam@dynamic:string/1})
).
-file("src/deriv/example/foo.gleam", 46).
-spec encode_foo(foo()) -> gleam@json:json().
encode_foo(Value) ->
gleam@json:object(
[{<<"uuid"/utf8>>, deriv@util:encode_uuid(erlang:element(2, Value))},
{<<"id"/utf8>>, gleam@json:int(erlang:element(3, Value))},
{<<"name"/utf8>>, gleam@json:string(erlang:element(4, Value))},
{<<"active"/utf8>>, gleam@json:bool(erlang:element(5, Value))},
{<<"ratio"/utf8>>, gleam@json:float(erlang:element(6, Value))},
{<<"maybe"/utf8>>,
gleam@json:nullable(
erlang:element(7, Value),
fun gleam@json:string/1
)},
{<<"words"/utf8>>,
gleam@json:preprocessed_array(
gleam@list:map(
erlang:element(8, Value),
fun gleam@json:string/1
)
)}]
).
-file("src/deriv/example/foo.gleam", 58).
-spec decoder_bar() -> decode:decoder(bar()).
decoder_bar() ->
_pipe = decode:into(
begin
decode:parameter(fun(Baz) -> {bar, Baz} end)
end
),
decode:field(_pipe, <<"baz"/utf8>>, {decoder, fun gleam@dynamic:bool/1}).