Skip to content

Commit

Permalink
Add Dyn.result (#9419)
Browse files Browse the repository at this point in the history
As the result can now be considered a base type it seems to make sense
to have it as a basic Dyn.builder shipped with the dyn library.
This would prove quite convenient for `ppx_deriving_dyn` as well.

Signed-off-by: Nathan Rebours <[email protected]>
  • Loading branch information
NathanReb authored Dec 8, 2023
1 parent b3567f2 commit c8fa675
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions otherlibs/dyn/dyn.ml
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,8 @@ let variant s args = Variant (s, args)
let hash = Stdlib.Hashtbl.hash
let compare x y = Ordering.of_int (compare x y)
let equal x y = x = y

let result ok err = function
| Ok e -> variant "Ok" [ ok e ]
| Error e -> variant "Error" [ err e ]
;;
1 change: 1 addition & 0 deletions otherlibs/dyn/dyn.mli
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ val option : 'a builder -> 'a option builder
val opaque : _ builder
val record : (string * t) list -> t
val variant : string -> t list -> t
val result : 'a builder -> 'error builder -> ('a, 'error) result builder

0 comments on commit c8fa675

Please sign in to comment.