Skip to content

Commit da46957

Browse files
authored
Merge pull request #6 from anttih/is-null
Add `isNull` predicate
2 parents 3d7955d + 1764db9 commit da46957

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

src/JSON.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import Data.Function.Uncurried (runFn2, runFn3, runFn7)
3030
import Data.Int as Int
3131
import Data.Maybe (Maybe(..))
3232
import JSON.Internal (JArray, JObject, JSON)
33-
import JSON.Internal (JArray, JObject, JSON) as Exports
33+
import JSON.Internal (JArray, JObject, JSON, isNull) as Exports
3434
import JSON.Internal as Internal
3535

3636
-- | Attempts to parse a string as a JSON value. If parsing fails, an error message detailing the

src/JSON/Internal.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,5 @@ export const _index = (nothing, just, ix, arr) =>
5757
ix >= 0 && ix < arr.length ? just(arr[ix]) : nothing;
5858

5959
export const _append = (xs, ys) => xs.concat(ys);
60+
61+
export const isNull = (json) => json == null;

src/JSON/Internal.purs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,5 @@ foreign import _append
140140
JArray
141141
JArray
142142
JArray
143+
144+
foreign import isNull :: JSON -> Boolean

test/Main.purs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ main = do
3535
assertTrue $ J.fromJObject (JO.fromEntries [ Tuple "a" (J.fromInt 1) ]) == J.fromJObject (JO.fromEntries [ Tuple "a" (J.fromInt 1) ])
3636
assertTrue $ J.fromJObject (JO.fromEntries [ Tuple "a" (J.fromInt 1) ]) < J.fromJObject (JO.fromEntries [ Tuple "a" (J.fromInt 2) ])
3737

38+
log "Check isNull"
39+
assertTrue $ J.isNull J.null
40+
assertTrue $ not $ J.isNull (J.fromInt 1)
41+
3842
log "Check array index"
3943
assertTrue $ JA.index (-1) (JA.fromArray (J.fromInt <$> [ 0, 2, 4 ])) == Nothing
4044
assertTrue $ JA.index 0 (JA.fromArray (J.fromInt <$> [ 0, 2, 4 ])) == Just (J.fromInt 0)

0 commit comments

Comments
 (0)