@@ -6,7 +6,9 @@ import Control.Monad.Except (except, mapExcept)
66import Data.Array ((..), zipWith , length )
77import Data.Bifunctor (lmap )
88import Data.Either (Either (..))
9+ import Data.Identity (Identity (..))
910import Data.Maybe (Maybe , maybe )
11+ import Data.Newtype (unwrap )
1012import Data.Traversable (sequence )
1113import Foreign (F , Foreign , ForeignError (..), readArray , readBoolean , readChar , readInt , readNumber , readString , unsafeToForeign )
1214import Foreign.Internal (readObject )
@@ -56,6 +58,9 @@ instance numberDecode :: Decode Number where
5658instance intDecode :: Decode Int where
5759 decode = readInt
5860
61+ instance identityDecode :: Decode a => Decode (Identity a ) where
62+ decode = map Identity <<< decode
63+
5964instance arrayDecode :: Decode a => Decode (Array a ) where
6065 decode = readArray >=> readElements where
6166 readElements :: Array Foreign -> F (Array a )
@@ -112,6 +117,9 @@ instance numberEncode :: Encode Number where
112117instance intEncode :: Encode Int where
113118 encode = unsafeToForeign
114119
120+ instance identityEncode :: Encode a => Encode (Identity a ) where
121+ encode = encode <<< unwrap
122+
115123instance arrayEncode :: Encode a => Encode (Array a ) where
116124 encode = unsafeToForeign <<< map encode
117125
0 commit comments