-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: port to Melange v2 * update opam and makefile * better constraint for opam-check-npm-deps --------- Co-authored-by: Javier Chavarri <[email protected]>
- Loading branch information
1 parent
bfeb902
commit 276aef9
Showing
7 changed files
with
175 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,28 @@ | ||
(* Decoding a fixed JSON data structure using Json.Decode *) | ||
let mapJsonObjectString f decoder (encoder: int -> Js.Json.t) str = | ||
let mapJsonObjectString f decoder (encoder : int -> Js.Json.t) str = | ||
let json = Json.parseOrRaise str in | ||
Json.Decode.(dict decoder json) | ||
|> Js.Dict.map ((fun v -> f v) [@bs]) | ||
|> Json.Encode.dict encoder | ||
|> Json.stringify | ||
|> Js.Dict.map (fun [@u] v -> f v) | ||
|> Json.Encode.dict encoder |> Json.stringify | ||
|
||
let sum = | ||
Array.fold_left (+) 0 | ||
let sum = Array.fold_left ( + ) 0 | ||
|
||
(* prints `{ "foo": 6, "bar": 24 }` *) | ||
let _ = | ||
Js.log @@ | ||
(mapJsonObjectString sum Json.Decode.(array int) Json.Encode.int {| | ||
Js.log | ||
@@ mapJsonObjectString sum | ||
Json.Decode.(array int) | ||
Json.Encode.int | ||
{| | ||
{ | ||
"foo": [1, 2, 3], | ||
"bar": [9, 8, 7] | ||
} | ||
|}) | ||
|} | ||
|
||
(* Error handling *) | ||
let _ = | ||
let json = {|{ "y": 42 } |} |> Json.parseOrRaise in | ||
match Json.Decode.(field "x" int json) with | ||
| x -> | ||
Js.log x | ||
| exception Json.Decode.DecodeError msg -> | ||
Js.log ("Error:" ^ msg) | ||
| x -> Js.log x | ||
| exception Json.Decode.DecodeError msg -> Js.log ("Error:" ^ msg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.