Skip to content

Commit

Permalink
error at index for reading array contents
Browse files Browse the repository at this point in the history
  • Loading branch information
justinwoo committed Apr 24, 2019
1 parent 625b496 commit 200ba88
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Simple/JSON.purs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import Data.Maybe (Maybe(..), maybe)
import Data.Nullable (Nullable, toMaybe, toNullable)
import Data.Symbol (class IsSymbol, SProxy(..), reflectSymbol)
import Data.Traversable (sequence, traverse)
import Data.TraversableWithIndex (traverseWithIndex)
import Data.Variant (Variant, inj, on)
import Effect.Exception (message, try)
import Effect.Uncurried as EU
Expand Down Expand Up @@ -163,7 +164,9 @@ instance readBoolean :: ReadForeign Boolean where
readImpl = readBoolean

instance readArray :: ReadForeign a => ReadForeign (Array a) where
readImpl = traverse readImpl <=< readArray
readImpl = traverseWithIndex readAtIdx <=< readArray
where
readAtIdx i f = withExcept (map (ErrorAtIndex i)) (readImpl f)

instance readMaybe :: ReadForeign a => ReadForeign (Maybe a) where
readImpl = readNullOrUndefined readImpl
Expand Down

0 comments on commit 200ba88

Please sign in to comment.