roc format builtins

This commit is contained in:
Richard Feldman 2022-07-13 22:40:17 -04:00
parent 47dd3743e7
commit 7ed35eca50
No known key found for this signature in database
GPG key ID: 7E4127D1E4241798
4 changed files with 26 additions and 26 deletions

View file

@ -30,11 +30,11 @@ interface Dict
##
## populationByCity =
## Dict.empty
## |> Dict.insert "London" 8_961_989
## |> Dict.insert "Philadelphia" 1_603_797
## |> Dict.insert "Shanghai" 24_870_895
## |> Dict.insert "Delhi" 16_787_941
## |> Dict.insert "Amsterdam" 872_680
## |> Dict.insert "London" 8_961_989
## |> Dict.insert "Philadelphia" 1_603_797
## |> Dict.insert "Shanghai" 24_870_895
## |> Dict.insert "Delhi" 16_787_941
## |> Dict.insert "Amsterdam" 872_680
##
## ### Accessing keys or values
##
@ -87,7 +87,7 @@ contains : Dict k v, k -> Bool
single : k, v -> Dict k v
single = \key, value ->
Dict.empty
|> Dict.insert key value
|> Dict.insert key value
## Returns a [List] of the dictionary's keys.
keys : Dict k v -> List k

View file

@ -75,8 +75,8 @@ bool = \b -> custom \bytes, @Json {} ->
string = \s -> custom \bytes, @Json {} ->
List.append bytes (Num.toU8 '"')
|> List.concat (Str.toUtf8 s)
|> List.append (Num.toU8 '"')
|> List.concat (Str.toUtf8 s)
|> List.append (Num.toU8 '"')
list = \lst, encodeElem ->
custom \bytes, @Json {} ->
@ -90,10 +90,10 @@ record = \fields ->
writeRecord = \{ buffer, fieldsLeft }, { key, value } ->
bufferWithKeyValue =
List.append buffer (Num.toU8 '"')
|> List.concat (Str.toUtf8 key)
|> List.append (Num.toU8 '"')
|> List.append (Num.toU8 ':')
|> appendWith value (@Json {})
|> List.concat (Str.toUtf8 key)
|> List.append (Num.toU8 '"')
|> List.append (Num.toU8 ':')
|> appendWith value (@Json {})
bufferWithSuffix =
if fieldsLeft > 0 then
@ -123,13 +123,13 @@ tag = \name, payload ->
bytesHead =
List.append bytes (Num.toU8 '{')
|> List.append (Num.toU8 '"')
|> List.concat (Str.toUtf8 name)
|> List.append (Num.toU8 '"')
|> List.append (Num.toU8 ':')
|> List.append (Num.toU8 '[')
|> List.append (Num.toU8 '"')
|> List.concat (Str.toUtf8 name)
|> List.append (Num.toU8 '"')
|> List.append (Num.toU8 ':')
|> List.append (Num.toU8 '[')
{ buffer: bytesWithPayload } = List.walk payload { buffer: bytesHead, itemsLeft: List.len payload } writePayload
List.append bytesWithPayload (Num.toU8 ']')
|> List.append (Num.toU8 '}')
|> List.append (Num.toU8 '}')

View file

@ -246,8 +246,8 @@ set = \list, index, value ->
append : List a, a -> List a
append = \list, element ->
list
|> List.reserve 1
|> List.appendUnsafe element
|> List.reserve 1
|> List.appendUnsafe element
## Writes the element after the current last element unconditionally.
## In other words, it is assumed that
@ -836,8 +836,8 @@ intersperse = \list, sep ->
newList =
List.walk list init \acc, elem ->
acc
|> List.appendUnsafe elem
|> List.appendUnsafe sep
|> List.appendUnsafe elem
|> List.appendUnsafe sep
List.dropLast newList

View file

@ -26,8 +26,8 @@ insert : Set k, k -> Set k
len : Set k -> Nat
len = \set ->
set
|> Set.toDict
|> Dict.len
|> Set.toDict
|> Dict.len
## Drops the given element from the set.
remove : Set k, k -> Set k
@ -35,8 +35,8 @@ remove : Set k, k -> Set k
contains : Set k, k -> Bool
contains = \set, key ->
set
|> Set.toDict
|> Dict.contains key
|> Set.toDict
|> Dict.contains key
# toList = \set -> Dict.keys (toDict set)
toList : Set k -> List k