Skip to content

Commit

Permalink
Merge pull request #7 from zudov/update-to-0.7
Browse files Browse the repository at this point in the history
Update for purescript-generics-0.7
  • Loading branch information
garyb committed Nov 20, 2015
2 parents c1e9278 + 2cefcb1 commit f0b9994
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
7 changes: 3 additions & 4 deletions bower.json
Expand Up @@ -23,11 +23,10 @@
"license": "MIT",
"dependencies": {
"purescript-argonaut-core": "^0.2.0",
"purescript-integers": "^0.2.1",
"purescript-generics": "^0.6.1"
"purescript-generics": "^0.7.0",
"purescript-integers": "^0.2.1"
},
"devDependencies": {
"purescript-strongcheck": "^0.14.1",
"purescript-strongcheck-generics": "^0.2.0"
"purescript-strongcheck-generics": "^0.3.0"
}
}
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -6,6 +6,6 @@
"gulp": "^3.9.0",
"gulp-purescript": "^0.7.0",
"gulp-run": "^1.6.8",
"purescript": "^0.7.5"
"purescript": "^0.7.6-rc.1"
}
}
10 changes: 6 additions & 4 deletions src/Data/Argonaut/Decode.purs
Expand Up @@ -14,7 +14,7 @@ import Data.Argonaut.Core (Json(), foldJsonNull, foldJsonBoolean, foldJsonNumber
import Data.Array (zipWithA)
import Data.Either (either, Either(..))
import Data.Foldable (find)
import Data.Generic (Generic, GenericSpine(..), GenericSignature(..), Proxy(..), fromSpine, toSignature)
import Data.Generic (Generic, GenericSpine(..), GenericSignature(..), fromSpine, toSignature)
import Data.Int (fromNumber)
import Data.List (List(..), toList)
import Data.Map as Map
Expand All @@ -23,6 +23,7 @@ import Data.String (charAt, toChar)
import Data.StrMap as M
import Data.Traversable (traverse, for)
import Data.Tuple (Tuple(..))
import Type.Proxy (Proxy(..))

class DecodeJson a where
decodeJson :: Json -> Either String a
Expand All @@ -49,9 +50,10 @@ gDecodeJson' signature json = case signature of
pf <- mFail ("'" <> lbl <> "' property missing") (M.lookup lbl jObj)
sp <- gDecodeJson' (val unit) pf
pure { recLabel: lbl, recValue: const sp }
SigProd alts -> do
jObj <- mFail "Expected an object" $ toObject json
tag <- mFail "'tag' string property is missing" (toString =<< M.lookup "tag" jObj)
SigProd typeConstr alts -> do
let decodingErr msg = "When decoding " ++ typeConstr ++ " " ++ msg
jObj <- mFail (decodingErr "expected an object") (toObject json)
tag <- mFail (decodingErr "'tag' string property is missing") (toString =<< M.lookup "tag" jObj)
case find ((tag ==) <<< _.sigConstructor) alts of
Nothing -> Left ("'" <> tag <> "' isn't a valid constructor")
Just { sigValues: sigValues } -> do
Expand Down
2 changes: 1 addition & 1 deletion src/Data/Argonaut/Encode.purs
Expand Up @@ -12,7 +12,7 @@ import Data.Either (Either(..))
import Data.Foldable (foldr)
import Data.Generic (Generic, GenericSpine(..), toSpine)
import Data.Int (toNumber)
import Data.List (List(..), fromList)
import Data.List (List(), fromList)
import Data.Map as M
import Data.Maybe (Maybe(..))
import Data.String (fromChar)
Expand Down

0 comments on commit f0b9994

Please sign in to comment.