fix: serializable nea

This commit is contained in:
orion 2023-12-23 19:28:46 -06:00
parent 3c146ae4c6
commit 939f6d1dcd
Signed by: orion
GPG Key ID: 6D4165AE4C928719
3 changed files with 9 additions and 1 deletions

View File

@ -5,6 +5,7 @@ workspace:
dependencies:
- aff
- aff-promise
- arrays
- bifunctors
- effect
- either

View File

@ -5,6 +5,7 @@ package:
dependencies:
- aff
- aff-promise
- arrays
- bifunctors
- effect
- either

View File

@ -2,8 +2,10 @@ module Node.Worker.Serializable where
import Prelude
import Control.Monad.Error.Class (throwError)
import Control.Monad.Error.Class (liftMaybe, throwError)
import Control.Monad.Except (runExcept)
import Data.Array.NonEmpty (NonEmptyArray)
import Data.Array.NonEmpty as Array.NonEmpty
import Data.Bifunctor (lmap)
import Data.Either (Either(..))
import Data.Maybe (Maybe(..))
@ -59,6 +61,10 @@ instance Serializable a => Serializable (Array a) where
serialize a = unsafeToForeign a
deserialize = flip bind (traverse deserialize) <<< lmap show <<< runExcept <<< readArray
instance Serializable a => Serializable (NonEmptyArray a) where
serialize a = unsafeToForeign $ Array.NonEmpty.toArray a
deserialize = flip bind (liftMaybe "expected non-empty array" <<< Array.NonEmpty.fromArray) <<< deserialize
instance Serializable a => Serializable (Object a) where
serialize a = unsafeToForeign a
deserialize a =