Add getProperty method to JSON
This commit is contained in:
parent
e91db14c11
commit
b5547ccb58
|
@ -108,6 +108,18 @@ dFoldL f acc (VBool b) = f acc _ (VBool b)
|
|||
dFoldL f acc VNull = f acc _ VNull
|
||||
```
|
||||
|
||||
Look up a property in an object
|
||||
|
||||
```idris
|
||||
export
|
||||
getProperty : (prop : String) -> (object : JSONValue TObject)
|
||||
-> Maybe (type : JSONType ** JSONValue type)
|
||||
getProperty prop (VObject xs) =
|
||||
case dFind (\_, (key, _) => key == prop) xs of
|
||||
Nothing => Nothing
|
||||
Just (type ** (_, val)) => Just (type ** val)
|
||||
```
|
||||
|
||||
## Parsers
|
||||
|
||||
We are going to get mutually recursive here. Instead of using a `mutual` block,
|
||||
|
|
Loading…
Reference in a new issue