From cff5a0dfa89ab3a7f95512382cedf88f8e1709d1 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Fri, 9 Dec 2022 18:16:41 +0200 Subject: Fix purity issue --- core/result.milch | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'core/result.milch') diff --git a/core/result.milch b/core/result.milch index f122ee6..903ca38 100644 --- a/core/result.milch +++ b/core/result.milch @@ -1,3 +1,5 @@ +(import "core/common") + (record Result/Ok value) (record Result/Ex value) @@ -23,3 +25,8 @@ (match (kind m) :Result/Ok (Result/Ok/get-value m) :Result/Ex (catch-f (Result/Ex/get-value m))))) + +; converts the given impure function that can throw a fatal error +; to an impure function that returns a Result +(let Result/safe! (\![fn! arg] + (try! Result/ex (.! Result/ok fn!) arg))) -- cgit v1.3