Skip to content

Commit 56717ef

Browse files
committed
Derive various instances for NullOrUndefined
1 parent e88dae6 commit 56717ef

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/Data/Foreign/NullOrUndefined.purs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module Data.Foreign.NullOrUndefined where
22

33
import Prelude
44

5+
import Data.Function (on)
6+
import Data.Newtype (class Newtype, unwrap)
57
import Data.Maybe (Maybe(..))
68
import Data.Foreign (F, Foreign, isUndefined, isNull)
79

@@ -12,6 +14,17 @@ import Data.Foreign (F, Foreign, isUndefined, isNull)
1214
-- | or `undefined`.
1315
newtype NullOrUndefined a = NullOrUndefined (Maybe a)
1416

17+
derive instance newtypeNullOrUndefined :: Newtype (NullOrUndefined a) _
18+
19+
instance showNullOrUndefined :: (Show a) => Show (NullOrUndefined a) where
20+
show x = "NullOrUndefined " <> show (unwrap x)
21+
22+
instance eqNullOrUndefined :: (Eq a) => Eq (NullOrUndefined a) where
23+
eq = eq `on` unwrap
24+
25+
instance ordNullOrUndefined :: (Ord a) => Ord (NullOrUndefined a) where
26+
compare = compare `on` unwrap
27+
1528
-- | Unwrap a `NullOrUndefined` value
1629
unNullOrUndefined :: forall a. NullOrUndefined a -> Maybe a
1730
unNullOrUndefined (NullOrUndefined m) = m

0 commit comments

Comments
 (0)