Skip to content

Update for purescript-generics-0.7 #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions bower.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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