Skip to content

Commit

Permalink
Merge pull request #17 from purescript-contrib/int
Browse files Browse the repository at this point in the history
Add encode/decode for Int
  • Loading branch information
garyb committed May 19, 2015
2 parents e883e54 + 34ab576 commit f63cd77
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"purescript-control": "~0.2.1",
"purescript-lens": "~0.7.0",
"purescript-optic": "~0.5.0",
"purescript-index": "~0.3.0"
"purescript-index": "~0.3.0",
"purescript-integers": "~0.1.0"
},
"devDependencies": {
"purescript-strongcheck": "~0.9.0"
Expand Down
4 changes: 4 additions & 0 deletions src/Data/Argonaut/Decode.purs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module Data.Argonaut.Decode
)
import Data.Argonaut.Encode (encodeJson, EncodeJson)
import Data.Either (either, Either(..))
import Data.Int (Int(), fromNumber)
import Data.Maybe (maybe, Maybe(..))
import Data.Foldable (Foldable, foldl, foldMap, foldr)
import Data.Traversable (Traversable, traverse)
Expand Down Expand Up @@ -66,6 +67,9 @@ module Data.Argonaut.Decode
instance decodeJsonNumber :: DecodeJson Number where
decodeJson = foldJsonNumber (Left "Not a Number.") Right

instance decodeJsonInt :: DecodeJson Int where
decodeJson = foldJsonNumber (Left "Not a Number.") (Right <<< fromNumber)

instance decodeJsonString :: DecodeJson String where
decodeJson = foldJsonString (Left "Not a String.") Right

Expand Down
6 changes: 5 additions & 1 deletion src/Data/Argonaut/Encode.purs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module Data.Argonaut.Encode
import Data.Char
import Data.Maybe
import Data.Either
import Data.Int (Int(), toNumber)
import Data.Foldable (foldr)
import Data.Tuple (Tuple(..))

Expand Down Expand Up @@ -49,6 +50,9 @@ module Data.Argonaut.Encode
instance encodeJsonJNumber :: EncodeJson Number where
encodeJson = fromNumber

instance encodeJsonInt :: EncodeJson Int where
encodeJson = fromNumber <<< toNumber

instance encodeJsonJString :: EncodeJson String where
encodeJson = fromString

Expand All @@ -65,4 +69,4 @@ module Data.Argonaut.Encode
encodeJson m = fromObject (encodeJson <$> m)

instance encodeMap :: (Ord a, EncodeJson a, EncodeJson b) => EncodeJson (Map.Map a b) where
encodeJson = encodeJson <<< Map.toList
encodeJson = encodeJson <<< Map.toList
14 changes: 14 additions & 0 deletions src/Data/Argonaut/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,13 @@ instance decodeJsonNumber :: DecodeJson Number
```


#### `decodeJsonInt`

``` purescript
instance decodeJsonInt :: DecodeJson Int
```


#### `decodeJsonString`

``` purescript
Expand Down Expand Up @@ -629,6 +636,13 @@ instance encodeJsonJNumber :: EncodeJson Number
```


#### `encodeJsonInt`

``` purescript
instance encodeJsonInt :: EncodeJson Int
```


#### `encodeJsonJString`

``` purescript
Expand Down

0 comments on commit f63cd77

Please sign in to comment.