generated from tpl/purs
fix: serializable nea
This commit is contained in:
parent
3c146ae4c6
commit
939f6d1dcd
@ -5,6 +5,7 @@ workspace:
|
|||||||
dependencies:
|
dependencies:
|
||||||
- aff
|
- aff
|
||||||
- aff-promise
|
- aff-promise
|
||||||
|
- arrays
|
||||||
- bifunctors
|
- bifunctors
|
||||||
- effect
|
- effect
|
||||||
- either
|
- either
|
||||||
|
@ -5,6 +5,7 @@ package:
|
|||||||
dependencies:
|
dependencies:
|
||||||
- aff
|
- aff
|
||||||
- aff-promise
|
- aff-promise
|
||||||
|
- arrays
|
||||||
- bifunctors
|
- bifunctors
|
||||||
- effect
|
- effect
|
||||||
- either
|
- either
|
||||||
|
@ -2,8 +2,10 @@ module Node.Worker.Serializable where
|
|||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
import Control.Monad.Error.Class (throwError)
|
import Control.Monad.Error.Class (liftMaybe, throwError)
|
||||||
import Control.Monad.Except (runExcept)
|
import Control.Monad.Except (runExcept)
|
||||||
|
import Data.Array.NonEmpty (NonEmptyArray)
|
||||||
|
import Data.Array.NonEmpty as Array.NonEmpty
|
||||||
import Data.Bifunctor (lmap)
|
import Data.Bifunctor (lmap)
|
||||||
import Data.Either (Either(..))
|
import Data.Either (Either(..))
|
||||||
import Data.Maybe (Maybe(..))
|
import Data.Maybe (Maybe(..))
|
||||||
@ -59,6 +61,10 @@ instance Serializable a => Serializable (Array a) where
|
|||||||
serialize a = unsafeToForeign a
|
serialize a = unsafeToForeign a
|
||||||
deserialize = flip bind (traverse deserialize) <<< lmap show <<< runExcept <<< readArray
|
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
|
instance Serializable a => Serializable (Object a) where
|
||||||
serialize a = unsafeToForeign a
|
serialize a = unsafeToForeign a
|
||||||
deserialize a =
|
deserialize a =
|
||||||
|
Loading…
Reference in New Issue
Block a user