git.iko.soy/rowtype-yoga/purescript-yoga-json
on main help sign in
Add convenience `withStringErrors` function
commit6b9bb4a6badedc668338583fd0fb3b85709844ad authorMark Eibes <mark.eibes@gmail.com> dateMon 6 Nov 2023, 11:23 (3 years ago) parent51737ae
1 file changed+7
src/Yoga/JSON/Error.purs+7
src/Yoga/JSON/Error.purs+7
@@ -3,6 +3,10 @@ module Yoga.JSON.Error where
33import Prelude
44
55import Foreign (ForeignError(..))
6+import Data.Semigroup.Foldable (intercalateMap)
7+import Data.Bifunctor (lmap)
8+import Yoga.JSON (E)
9+import Data.Either (Either)
610
711toJSONPath ∷ ForeignError → String
812toJSONPath fe = "$" <> path
@@ -20,6 +24,9 @@ renderHumanError = errorToJSON >>> toHuman
2024 where
2125 toHuman { message, path } = message <> " at " <> path
2226
27+withStringErrors :: forall a. E a -> Either String a
28+withStringErrors = lmap (intercalateMap "\n" renderHumanError)
29+
2330errorToJSON ∷
2431 ForeignError →
2532 { message ∷ String