mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-20 15:27:45 +03:00
Revert "Show that putting the decoder in a different module works"
This reverts commit 7f1a850bef12aa9f55dbbed34030c8a07f82d2a4.
This commit is contained in:
parent
8b80f10e56
commit
6a0abdd32d
@ -1,45 +0,0 @@
|
||||
interface Inter
|
||||
exposes [
|
||||
theDecoder
|
||||
]
|
||||
imports [
|
||||
Decode
|
||||
]
|
||||
|
||||
theDecoder =
|
||||
Decode.custom \bytes, fmt ->
|
||||
Decode.decodeWith
|
||||
bytes
|
||||
(Decode.record
|
||||
{f0: Err NoField, f1: Err NoField}
|
||||
(\state, field ->
|
||||
when field is
|
||||
"first" ->
|
||||
Keep (Decode.custom \bytes1, fmt1 ->
|
||||
when Decode.decodeWith bytes1 Decode.decoder fmt1 is
|
||||
rec ->
|
||||
{
|
||||
result: (when rec.result is
|
||||
Ok val -> Ok {state & f0: Ok val}
|
||||
Err e -> Err e),
|
||||
rest: rec.rest
|
||||
})
|
||||
"second" ->
|
||||
Keep (Decode.custom \bytes1, fmt1 ->
|
||||
when Decode.decodeWith bytes1 Decode.decoder fmt1 is
|
||||
rec ->
|
||||
{
|
||||
result: (when rec.result is
|
||||
Ok val -> Ok {state & f1: Ok val}
|
||||
Err e -> Err e),
|
||||
rest: rec.rest
|
||||
})
|
||||
_ -> Skip)
|
||||
(\stateRecord ->
|
||||
when stateRecord.f0 is
|
||||
Ok first ->
|
||||
when stateRecord.f1 is
|
||||
Ok second -> Ok {first, second}
|
||||
Err NoField -> Err TooShort
|
||||
Err NoField -> Err TooShort))
|
||||
fmt
|
@ -1,10 +1,48 @@
|
||||
app "helloWorld"
|
||||
packages { pf: "platform/main.roc" }
|
||||
imports [Inter, Decode, Json]
|
||||
imports [Decode, Decode.{Decoder, Decoding, DecoderFormatting}, Json]
|
||||
provides [main] to pf
|
||||
|
||||
theDecoder =
|
||||
Decode.custom \bytes, fmt ->
|
||||
Decode.decodeWith
|
||||
bytes
|
||||
(Decode.record
|
||||
{f0: Err NoField, f1: Err NoField}
|
||||
(\state, field ->
|
||||
when field is
|
||||
"first" ->
|
||||
Keep (Decode.custom \bytes1, fmt1 ->
|
||||
when Decode.decodeWith bytes1 Decode.decoder fmt1 is
|
||||
rec ->
|
||||
{
|
||||
result: (when rec.result is
|
||||
Ok val -> Ok {state & f0: Ok val}
|
||||
Err e -> Err e),
|
||||
rest: rec.rest
|
||||
})
|
||||
"second" ->
|
||||
Keep (Decode.custom \bytes1, fmt1 ->
|
||||
when Decode.decodeWith bytes1 Decode.decoder fmt1 is
|
||||
rec ->
|
||||
{
|
||||
result: (when rec.result is
|
||||
Ok val -> Ok {state & f1: Ok val}
|
||||
Err e -> Err e),
|
||||
rest: rec.rest
|
||||
})
|
||||
_ -> Skip)
|
||||
(\stateRecord ->
|
||||
when stateRecord.f0 is
|
||||
Ok first ->
|
||||
when stateRecord.f1 is
|
||||
Ok second -> Ok {first, second}
|
||||
Err NoField -> Err TooShort
|
||||
Err NoField -> Err TooShort))
|
||||
fmt
|
||||
|
||||
main =
|
||||
when Str.toUtf8 "{\"first\":\"ab\",\"second\":[\"cd\",\"ef\"]}" |> Decode.decodeWith Inter.theDecoder Json.fromUtf8 is
|
||||
when Str.toUtf8 "{\"first\":\"ab\",\"second\":[\"cd\",\"ef\"]}" |> Decode.decodeWith theDecoder Json.fromUtf8 is
|
||||
{result, rest: _} ->
|
||||
when result is
|
||||
Ok { first, second } -> Str.concat first (Str.joinWith second ",")
|
||||
|
Loading…
Reference in New Issue
Block a user