Add JSON dFoldL

This commit is contained in:
Nathan McCarty 2025-01-27 18:30:30 -05:00
parent aa33fe6004
commit 83afb8a7c4

View file

@ -82,6 +82,30 @@ Eq (JSONValue t) where
%hide Language.Reflection.TT.WithFC.value
```
### JSON Functions
`foldl` Analog for consuming a JSON structure by values. Ignores the keys in
objects.
```idris
export
dFoldL : {t : JSONType}
-> (acc -> (type : JSONType) -> (val : JSONValue type) -> acc)
-> acc -> JSONValue t -> acc
dFoldL f acc' (VObject xs) =
let recur : acc -> (v : JSONType) -> (String, JSONValue v) -> acc
recur acc' v (key, value) = dFoldL f acc' value
in DList.dFoldL recur acc' xs
dFoldL f acc' (VArray xs) =
let recur : acc -> (v : JSONType) -> JSONValue v -> acc
recur acc' v value = dFoldL f acc' value
in DList.dFoldL recur acc' xs
dFoldL f acc (VString s) = f acc _ (VString s)
dFoldL f acc (VNumber d) = f acc _ (VNumber d)
dFoldL f acc (VBool b) = f acc _ (VBool b)
dFoldL f acc VNull = f acc _ VNull
```
## Parsers
We are going to get mutually recursive here. Instead of using a `mutual` block,