Skip to content

Commit 823b832

Browse files
Add toInt
1 parent c9e053d commit 823b832

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

bower.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"dependencies": {
2323
"purescript-prelude": "^6.0.1",
2424
"purescript-functions": "^6.0.0",
25+
"purescript-integers": "^6.0.0",
2526
"purescript-maybe": "^6.0.0",
2627
"purescript-either": "^6.1.0",
2728
"purescript-tuples": "^7.0.0",

src/JSON.purs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import Prelude
2727
import Data.Either (Either(..))
2828
import Data.Function.Uncurried (runFn2, runFn3, runFn7)
2929
import Data.Maybe (Maybe(..))
30+
import Data.Int as Int
3031
import JSON.Internal (JArray, JObject, JSON) as Exports
3132
import JSON.Internal (JArray, JObject, JSON)
3233
import JSON.Internal as Internal
@@ -119,6 +120,12 @@ toBoolean json = runFn7 Internal._case fail Just fail fail fail fail json
119120
toNumber :: JSON -> Maybe Number
120121
toNumber json = runFn7 Internal._case fail fail Just fail fail fail json
121122

123+
-- | Converts a `JSON` `Number` into an `Int`.
124+
-- |
125+
-- | This is provided for convenience only.
126+
toInt :: Json -> Maybe Int
127+
toInt = toNumber >=> Int.fromNumber
128+
122129
-- | Converts a `JSON` value to `String` if the `JSON` is a string.
123130
toString :: JSON -> Maybe String
124131
toString json = runFn7 Internal._case fail fail fail Just fail fail json

0 commit comments

Comments
 (0)