diff --git a/src/Parser/JSON.md b/src/Parser/JSON.md index 7699d29..b69db49 100644 --- a/src/Parser/JSON.md +++ b/src/Parser/JSON.md @@ -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,