Skip to content

Commit

Permalink
added Encode state
Browse files Browse the repository at this point in the history
  • Loading branch information
roboteng committed Jul 5, 2024
1 parent 40bb3a6 commit 0c69b70
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions crates/compiler/builtins/roc/Encode.roc
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,31 @@ import Num exposing [
]
import Bool exposing [Bool]

Encoder fmt := List U8, fmt -> List U8 where fmt implements EncoderFormatting
Encoder state fmt := state, fmt -> state where fmt implements EncoderFormatting

Encoding implements
toEncoder : val -> Encoder fmt where val implements Encoding, fmt implements EncoderFormatting
toEncoder : val -> Encoder state fmt where val implements Encoding, fmt implements EncoderFormatting

EncoderFormatting implements
u8 : U8 -> Encoder fmt where fmt implements EncoderFormatting
u16 : U16 -> Encoder fmt where fmt implements EncoderFormatting
u32 : U32 -> Encoder fmt where fmt implements EncoderFormatting
u64 : U64 -> Encoder fmt where fmt implements EncoderFormatting
u128 : U128 -> Encoder fmt where fmt implements EncoderFormatting
i8 : I8 -> Encoder fmt where fmt implements EncoderFormatting
i16 : I16 -> Encoder fmt where fmt implements EncoderFormatting
i32 : I32 -> Encoder fmt where fmt implements EncoderFormatting
i64 : I64 -> Encoder fmt where fmt implements EncoderFormatting
i128 : I128 -> Encoder fmt where fmt implements EncoderFormatting
f32 : F32 -> Encoder fmt where fmt implements EncoderFormatting
f64 : F64 -> Encoder fmt where fmt implements EncoderFormatting
dec : Dec -> Encoder fmt where fmt implements EncoderFormatting
bool : Bool -> Encoder fmt where fmt implements EncoderFormatting
string : Str -> Encoder fmt where fmt implements EncoderFormatting
list : List elem, (elem -> Encoder fmt) -> Encoder fmt where fmt implements EncoderFormatting
record : List { key : Str, value : Encoder fmt } -> Encoder fmt where fmt implements EncoderFormatting
tuple : List (Encoder fmt) -> Encoder fmt where fmt implements EncoderFormatting
tag : Str, List (Encoder fmt) -> Encoder fmt where fmt implements EncoderFormatting
u8 : U8 -> Encoder state fmt where fmt implements EncoderFormatting
u16 : U16 -> Encoder state fmt where fmt implements EncoderFormatting
u32 : U32 -> Encoder state fmt where fmt implements EncoderFormatting
u64 : U64 -> Encoder state fmt where fmt implements EncoderFormatting
u128 : U128 -> Encoder state fmt where fmt implements EncoderFormatting
i8 : I8 -> Encoder state fmt where fmt implements EncoderFormatting
i16 : I16 -> Encoder state fmt where fmt implements EncoderFormatting
i32 : I32 -> Encoder state fmt where fmt implements EncoderFormatting
i64 : I64 -> Encoder state fmt where fmt implements EncoderFormatting
i128 : I128 -> Encoder state fmt where fmt implements EncoderFormatting
f32 : F32 -> Encoder state fmt where fmt implements EncoderFormatting
f64 : F64 -> Encoder state fmt where fmt implements EncoderFormatting
dec : Dec -> Encoder state fmt where fmt implements EncoderFormatting
bool : Bool -> Encoder state fmt where fmt implements EncoderFormatting
string : Str -> Encoder state fmt where fmt implements EncoderFormatting
list : List elem, (elem -> Encoder state fmt) -> Encoder state fmt where fmt implements EncoderFormatting
record : List { key : Str, value : Encoder state fmt } -> Encoder state fmt where fmt implements EncoderFormatting
tuple : List (Encoder state fmt) -> Encoder state fmt where fmt implements EncoderFormatting
tag : Str, List (Encoder state fmt) -> Encoder state fmt where fmt implements EncoderFormatting

## Creates a custom encoder from a given function.
##
Expand All @@ -83,10 +83,10 @@ EncoderFormatting implements
##
## actual == expected
## ```
custom : (List U8, fmt -> List U8) -> Encoder fmt where fmt implements EncoderFormatting
custom : (state, fmt -> state) -> Encoder state fmt where fmt implements EncoderFormatting
custom = \encoder -> @Encoder encoder

appendWith : List U8, Encoder fmt, fmt -> List U8 where fmt implements EncoderFormatting
appendWith : state, Encoder state fmt, fmt -> state where fmt implements EncoderFormatting
appendWith = \lst, @Encoder doEncoding, fmt -> doEncoding lst fmt

## Appends the encoded representation of a value to an existing list of bytes.
Expand All @@ -98,7 +98,7 @@ appendWith = \lst, @Encoder doEncoding, fmt -> doEncoding lst fmt
##
## actual == expected
## ```
append : List U8, val, fmt -> List U8 where val implements Encoding, fmt implements EncoderFormatting
append : state, val, fmt -> state where val implements Encoding, fmt implements EncoderFormatting
append = \lst, val, fmt -> appendWith lst (toEncoder val) fmt

## Encodes a value to a list of bytes (`List U8`) according to the specified format.
Expand Down

0 comments on commit 0c69b70

Please sign in to comment.