diff options
Diffstat (limited to 'stdlib')
-rw-r--r-- | stdlib/source/lux/data/error.lux | 35 | ||||
-rw-r--r-- | stdlib/test/test/lux/data/error.lux | 24 |
2 files changed, 30 insertions, 29 deletions
diff --git a/stdlib/source/lux/data/error.lux b/stdlib/source/lux/data/error.lux index 56f60ac2b..94b2c40cb 100644 --- a/stdlib/source/lux/data/error.lux +++ b/stdlib/source/lux/data/error.lux @@ -11,33 +11,34 @@ ## [Types] (type: #export (Error a) - (Either Text a)) + (#Error Text) + (#Success a)) ## [Structures] (struct: #export _ (Functor Error) (def: (map f ma) (case ma - (#;Left msg) (#;Left msg) - (#;Right datum) (#;Right (f datum))))) + (#Error msg) (#Error msg) + (#Success datum) (#Success (f datum))))) (struct: #export _ (Applicative Error) (def: functor Functor<Error>) (def: (wrap a) - (#;Right a)) + (#Success a)) (def: (apply ff fa) (case ff - (#;Right f) + (#Success f) (case fa - (#;Right a) - (#;Right (f a)) + (#Success a) + (#Success (f a)) - (#;Left msg) - (#;Left msg)) + (#Error msg) + (#Error msg)) - (#;Left msg) - (#;Left msg)) + (#Error msg) + (#Error msg)) )) (struct: #export _ (Monad Error) @@ -45,8 +46,8 @@ (def: (join mma) (case mma - (#;Left msg) (#;Left msg) - (#;Right ma) ma))) + (#Error msg) (#Error msg) + (#Success ma) ma))) (struct: #export (ErrorT Monad<M>) (All [M] (-> (Monad M) (Monad (All [a] (M (Error a)))))) @@ -55,10 +56,10 @@ (do Monad<M> [eMea MeMea] (case eMea - (#;Left error) - (wrap (#;Left error)) + (#Error error) + (wrap (#Error error)) - (#;Right Mea) + (#Success Mea) Mea)))) (def: #export (lift-error Monad<M>) @@ -67,4 +68,4 @@ (def: #export (fail message) (All [a] (-> Text (Error a))) - (#;Left message)) + (#Error message)) diff --git a/stdlib/test/test/lux/data/error.lux b/stdlib/test/test/lux/data/error.lux index 6127c37c1..880c2e0f1 100644 --- a/stdlib/test/test/lux/data/error.lux +++ b/stdlib/test/test/lux/data/error.lux @@ -16,22 +16,22 @@ (let [(^open "&/") &;Monad<Error>] ($_ seq (assert "Functor correctly handles both cases." - (and (|> (: (&;Error Int) (#;Right 10)) + (and (|> (: (&;Error Int) (#&;Success 10)) (&/map i.inc) - (case> (#;Right 11) true _ false)) + (case> (#&;Success 11) true _ false)) - (|> (: (&;Error Int) (#;Left "YOLO")) + (|> (: (&;Error Int) (#&;Error "YOLO")) (&/map i.inc) - (case> (#;Left "YOLO") true _ false)) + (case> (#&;Error "YOLO") true _ false)) )) (assert "Applicative correctly handles both cases." (and (|> (&/wrap 20) - (case> (#;Right 20) true _ false)) + (case> (#&;Success 20) true _ false)) (|> (&/apply (&/wrap i.inc) (&/wrap 10)) - (case> (#;Right 11) true _ false)) - (|> (&/apply (&/wrap i.inc) (#;Left "YOLO")) - (case> (#;Left "YOLO") true _ false)))) + (case> (#&;Success 11) true _ false)) + (|> (&/apply (&/wrap i.inc) (#&;Error "YOLO")) + (case> (#&;Error "YOLO") true _ false)))) (assert "Monad correctly handles both cases." (and (|> (do &;Monad<Error> @@ -39,13 +39,13 @@ a (wrap 10) b (wrap 20)] (wrap (f a b))) - (case> (#;Right 30) true _ false)) + (case> (#&;Success 30) true _ false)) (|> (do &;Monad<Error> [f (wrap i.+) - a (#;Left "YOLO") + a (#&;Error "YOLO") b (wrap 20)] (wrap (f a b))) - (case> (#;Left "YOLO") true _ false)) + (case> (#&;Error "YOLO") true _ false)) )) ))) @@ -57,5 +57,5 @@ [a (lift (io/wrap 123)) b (wrap 456)] (wrap (i.+ a b)))) - (case> (#;Right 579) true + (case> (#&;Success 579) true _ false))))) |