git.iko.soy/rowtype-yoga/psfp
on 3d6eb2f help sign in
19 lines 549 B history raw
1module Shared.Json (readJsonAff, readAff) where
3import Prelude
5import Data.Either (Either, either)
6import Effect.Aff (Aff)
7import Effect.Class (liftEffect)
8import Effect.Exception (throw)
9import Foreign (Foreign)
10import Simple.JSON (class ReadForeign, read, readJSON)
12readJsonAff ∷ ∀ a. ReadForeign a => String -> Aff a
13readJsonAff = readJSON >>> orThrow
15readAff ∷ ∀ a. ReadForeign a => Foreign -> Aff a
16readAff = read >>> orThrow
18orThrow ∷ ∀ a s. Show s => Either s a -> Aff a
19orThrow = either (show >>> throw >>> liftEffect) pure