about summary refs log tree commit diff
path: root/users/grfn/xanthous/src/Xanthous/Orphans.hs
diff options
context:
space:
mode:
Diffstat (limited to 'users/grfn/xanthous/src/Xanthous/Orphans.hs')
-rw-r--r--users/grfn/xanthous/src/Xanthous/Orphans.hs12
1 files changed, 12 insertions, 0 deletions
diff --git a/users/grfn/xanthous/src/Xanthous/Orphans.hs b/users/grfn/xanthous/src/Xanthous/Orphans.hs
index 2a9a7a7ebc29..e6ea1310319b 100644
--- a/users/grfn/xanthous/src/Xanthous/Orphans.hs
+++ b/users/grfn/xanthous/src/Xanthous/Orphans.hs
@@ -300,9 +300,21 @@ deriving stock instance Ord Attr
 
 --------------------------------------------------------------------------------
 
+instance (SemiSequence a, Arbitrary (Element a), Arbitrary a)
+         => Arbitrary (NonNull a) where
+  arbitrary = ncons <$> arbitrary <*> arbitrary
+
+instance ToJSON a => ToJSON (NonNull a) where
+  toJSON = toJSON . toNullable
+
+instance (FromJSON a, MonoFoldable a) => FromJSON (NonNull a) where
+  parseJSON = maybe (fail "Found empty list") pure . fromNullable <=< parseJSON
+
 instance NFData a => NFData (NonNull a) where
   rnf xs = xs `seq` toNullable xs `deepseq` ()
 
+--------------------------------------------------------------------------------
+
 instance forall t name. (NFData t, Monoid t, NFData name)
                  => NFData (Editor t name) where
   rnf ed = getName @_ @name ed `deepseq` getEditContents ed `deepseq` ()