Skip to content

Commit 6dadc27

Browse files
committed
Add Nullable
1 parent 594c94e commit 6dadc27

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

GHCJS/Nullable.hs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module GHCJS.Nullable ( Nullable(..)
2+
, nullableToMaybe
3+
, maybeToNullable
4+
) where
5+
6+
import GHCJS.Prim (JSRef(..))
7+
import GHCJS.Marshal.Pure (PToJSRef(..), PFromJSRef(..))
8+
9+
newtype Nullable a = Nullable JSRef
10+
11+
nullableToMaybe :: PFromJSRef a => Nullable a -> Maybe a
12+
nullableToMaybe (Nullable r) = pFromJSRef r
13+
{-# INLINE nullableToMaybe #-}
14+
15+
maybeToNullable :: PToJSRef a => Maybe a -> Nullable a
16+
maybeToNullable = Nullable . pToJSRef
17+
{-# INLINE maybeToNullable #-}
18+
19+

ghcjs-base.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ library
7070
GHCJS.Marshal
7171
GHCJS.Marshal.Internal
7272
GHCJS.Marshal.Pure
73+
GHCJS.Nullable
7374
GHCJS.Types
7475
JavaScript.Array
7576
JavaScript.Array.Internal

0 commit comments

Comments
 (0)