26 lines
747 B
Forth
26 lines
747 B
Forth
|
namespace Pentole
|
||
|
|
||
|
module Result =
|
||
|
let inline protect ([<InlineIfLambda>]f) x =
|
||
|
try
|
||
|
Ok (f x)
|
||
|
with e -> Error e
|
||
|
|
||
|
let inline pairwise_map fun_ (x: 'a, y: 'a) =
|
||
|
match fun_ x with
|
||
|
| Error e -> Error e
|
||
|
| Ok o ->
|
||
|
match fun_ y with | Ok o' -> Ok (o, o') | Error e -> Error e
|
||
|
|
||
|
let of_option = function | Some s -> Ok s | None -> Error ()
|
||
|
|
||
|
|
||
|
type ToStringWrapper(toString) =
|
||
|
override this.ToString() = toString ()
|
||
|
|
||
|
let Result l = ToStringWrapper(fun _ ->
|
||
|
match l with
|
||
|
| Ok o -> sprintf "Ok %O" o
|
||
|
| _ -> failwith "")
|
||
|
|