From 182f9850993cefdf89c6d1babff3ba511887a2b1 Mon Sep 17 00:00:00 2001 From: Ashley Coleman Date: Wed, 8 Nov 2023 13:27:21 -0800 Subject: [PATCH] add missing function --- json.wake | 2 +- result.wake | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 result.wake diff --git a/json.wake b/json.wake index 0a77b6e..878ebdb 100644 --- a/json.wake +++ b/json.wake @@ -1,7 +1,7 @@ package json from wake import _ -from utils import prefixError +from result import prefixError from query import _ # Anyone who depends on json will also diff --git a/result.wake b/result.wake new file mode 100644 index 0000000..fd6e5fe --- /dev/null +++ b/result.wake @@ -0,0 +1,17 @@ +package result + +# When `result` is Fail, prefixes the internal error message with `prefix` +# +# Parameters: +# - `prefix`: The message to prepend to `result` +# - `result`: The Result which may be prepended to +# +# Examples: +# ``` +# prefixError "foo" (Pass 123) -> Pass 123 +# prefixError "foo" (Fail (Error "bar" stack)) => Fail (Error "foobar" stack) +# ``` +export def prefixError (prefix: String): (result: Result a Error) => Result a Error = match _ + Pass r -> Pass r + Fail (Error msg stack) -> Fail (Error "{prefix}{msg}" stack) +