You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: crates/compiler/builtins/roc/Decode.roc
+27-31Lines changed: 27 additions & 31 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,4 @@
1
1
module [
2
-
DecodeError,
3
2
DecodeResult,
4
3
Decoder,
5
4
Decoding,
@@ -49,9 +48,6 @@ import Num exposing [
49
48
]
50
49
import Boolexposing [Bool]
51
50
52
-
## Error types when decoding a `List U8` of utf-8 bytes using a [Decoder]
53
-
DecodeError : [TooShort]
54
-
55
51
## Return type of a [Decoder].
56
52
##
57
53
## This can be useful when creating a [custom](#custom) decoder or when
@@ -65,43 +61,43 @@ DecodeError : [TooShort]
65
61
##
66
62
## actual.result == expected
67
63
## ```
68
-
DecodeResult val : { result : Result val DecodeError, rest : ListU8 }
64
+
DecodeResult val err : { result : Result val err, rest : ListU8 }
69
65
70
66
## Decodes a `List U8` of utf-8 bytes where `val` is the type of the decoded
71
67
## value, and `fmt` is a [Decoder] which implements the [DecoderFormatting]
72
68
## ability
73
-
Decoder val fmt := ListU8, fmt -> DecodeResult val where fmt implements DecoderFormatting
69
+
Decoder val fmt err := ListU8, fmt -> DecodeResult val err where fmt implements DecoderFormatting
74
70
75
71
## Definition of the [Decoding] ability
76
72
Decoding implements
77
-
decoder : Decoder val fmt where val implements Decoding, fmt implements DecoderFormatting
73
+
decoder : Decoder val fmt err where val implements Decoding, fmt implements DecoderFormatting
78
74
79
75
## Definition of the [DecoderFormatting] ability
80
76
DecoderFormatting implements
81
-
u8 : DecoderU8 fmt where fmt implements DecoderFormatting
82
-
u16 : DecoderU16 fmt where fmt implements DecoderFormatting
83
-
u32 : DecoderU32 fmt where fmt implements DecoderFormatting
84
-
u64 : DecoderU64 fmt where fmt implements DecoderFormatting
85
-
u128 : DecoderU128 fmt where fmt implements DecoderFormatting
86
-
i8 : DecoderI8 fmt where fmt implements DecoderFormatting
87
-
i16 : DecoderI16 fmt where fmt implements DecoderFormatting
88
-
i32 : DecoderI32 fmt where fmt implements DecoderFormatting
89
-
i64 : DecoderI64 fmt where fmt implements DecoderFormatting
90
-
i128 : DecoderI128 fmt where fmt implements DecoderFormatting
91
-
f32 : DecoderF32 fmt where fmt implements DecoderFormatting
92
-
f64 : DecoderF64 fmt where fmt implements DecoderFormatting
93
-
dec : DecoderDec fmt where fmt implements DecoderFormatting
94
-
bool : DecoderBool fmt where fmt implements DecoderFormatting
95
-
string : DecoderStr fmt where fmt implements DecoderFormatting
96
-
list : Decoder elem fmt -> Decoder (List elem) fmt where fmt implements DecoderFormatting
77
+
u8 : DecoderU8 fmt err where fmt implements DecoderFormatting
78
+
u16 : DecoderU16 fmt err where fmt implements DecoderFormatting
79
+
u32 : DecoderU32 fmt err where fmt implements DecoderFormatting
80
+
u64 : DecoderU64 fmt err where fmt implements DecoderFormatting
81
+
u128 : DecoderU128 fmt err where fmt implements DecoderFormatting
82
+
i8 : DecoderI8 fmt err where fmt implements DecoderFormatting
83
+
i16 : DecoderI16 fmt err where fmt implements DecoderFormatting
84
+
i32 : DecoderI32 fmt err where fmt implements DecoderFormatting
85
+
i64 : DecoderI64 fmt err where fmt implements DecoderFormatting
86
+
i128 : DecoderI128 fmt err where fmt implements DecoderFormatting
87
+
f32 : DecoderF32 fmt err where fmt implements DecoderFormatting
88
+
f64 : DecoderF64 fmt err where fmt implements DecoderFormatting
89
+
dec : DecoderDec fmt err where fmt implements DecoderFormatting
90
+
bool : DecoderBool fmt err where fmt implements DecoderFormatting
91
+
string : DecoderStr fmt err where fmt implements DecoderFormatting
92
+
list : Decoder elem fmt err -> Decoder (List elem) fmt err where fmt implements DecoderFormatting
97
93
98
94
## `record state stepField finalizer` decodes a record field-by-field.
99
95
##
100
96
## `stepField` returns a decoder for the given field in the record, or
101
97
## `Skip` if the field is not a part of the decoded record.
102
98
##
103
99
## `finalizer` should produce the record value from the decoded `state`.
104
-
record : state, (state, Str -> [Keep (Decoder state fmt), Skip]), (state, fmt -> Result val DecodeError) -> Decoder val fmt where fmt implements DecoderFormatting
100
+
record : state, (state, Str -> [Keep (Decoder state fmt err), Skip]), (state, fmt -> Result val err) -> Decoder val fmt err where fmt implements DecoderFormatting
105
101
106
102
## `tuple state stepElem finalizer` decodes a tuple element-by-element.
107
103
##
@@ -110,7 +106,7 @@ DecoderFormatting implements
110
106
## index passed to `stepElem` is 0-indexed.
111
107
##
112
108
## `finalizer` should produce the tuple value from the decoded `state`.
113
-
tuple : state, (state, U64 -> [Next (Decoder state fmt), TooLong]), (state -> Result val DecodeError) -> Decoder val fmt where fmt implements DecoderFormatting
109
+
tuple : state, (state, U64 -> [Next (Decoder state fmt err), TooLong]), (state -> Result val err) -> Decoder val fmt err where fmt implements DecoderFormatting
114
110
115
111
## Build a custom [Decoder] function. For example the implementation of
0 commit comments