Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add Encode and Decode instances to Identity
  • Loading branch information
arthurxavierx committed Feb 26, 2019
commit e45b90c40b499993ac129c78ee84e943b25e5916
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"purescript-ordered-collections": "^1.0.0",
"purescript-proxy": "^3.0.0",
"purescript-exceptions": "^4.0.0",
"purescript-record": "^1.0.0"
"purescript-record": "^1.0.0",
"purescript-identity": "^4.1.0"
},
"devDependencies": {
"purescript-assert": "^4.0.0",
Expand Down
8 changes: 8 additions & 0 deletions src/Foreign/Class.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import Control.Monad.Except (except, mapExcept)
import Data.Array ((..), zipWith, length)
import Data.Bifunctor (lmap)
import Data.Either (Either(..))
import Data.Identity (Identity(..))
import Data.Maybe (Maybe, maybe)
import Data.Newtype (unwrap)
import Data.Traversable (sequence)
import Foreign (F, Foreign, ForeignError(..), readArray, readBoolean, readChar, readInt, readNumber, readString, unsafeToForeign)
import Foreign.Internal (readObject)
Expand Down Expand Up @@ -56,6 +58,9 @@ instance numberDecode :: Decode Number where
instance intDecode :: Decode Int where
decode = readInt

instance identityDecode :: Decode a => Decode (Identity a) where
decode = map Identity <<< decode

instance arrayDecode :: Decode a => Decode (Array a) where
decode = readArray >=> readElements where
readElements :: Array Foreign -> F (Array a)
Expand Down Expand Up @@ -112,6 +117,9 @@ instance numberEncode :: Encode Number where
instance intEncode :: Encode Int where
encode = unsafeToForeign

instance identityEncode :: Encode a => Encode (Identity a) where
encode = encode <<< unwrap

instance arrayEncode :: Encode a => Encode (Array a) where
encode = unsafeToForeign <<< map encode

Expand Down