Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Commit d301acf

Browse files
authored
Merge pull request #45 from tslawler/patch-1
Add `Generic a => Generic (Identity a)` instance
2 parents 552c4f3 + a169524 commit d301acf

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

bower.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"dependencies": {
2323
"purescript-arrays": "^3.0.0",
2424
"purescript-either": "^2.0.0",
25+
"purescript-identity": "^2.0.0",
2526
"purescript-proxy": "^1.0.0",
2627
"purescript-strings": "^2.0.0"
2728
},

src/Data/Generic.purs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Prelude
1919
import Data.Array (null, length, sortBy, zipWith)
2020
import Data.Either (Either(..))
2121
import Data.Foldable (all, and, find, fold, intercalate)
22+
import Data.Identity (Identity(..))
2223
import Data.Maybe (Maybe(..))
2324
import Data.NonEmpty (NonEmpty(..))
2425
import Data.String (joinWith)
@@ -148,6 +149,21 @@ instance genericEither :: (Generic a, Generic b) => Generic (Either a b) where
148149
fromSpine (SProd "Data.Either.Right" [x]) = Right <$> fromSpine (force x)
149150
fromSpine _ = Nothing
150151

152+
instance genericIdentity :: (Generic a) => Generic (Identity a) where
153+
toSpine (Identity a) = SProd "Data.Identity.Identity" [\_ -> toSpine a]
154+
toSignature x =
155+
SigProd
156+
"Data.Identity.Identity"
157+
[ { sigConstructor: "Data.Identity.Identity"
158+
, sigValues: [\_ -> toSignature (iproxy x)]
159+
}
160+
]
161+
where
162+
iproxy :: Proxy (Identity a) -> Proxy a
163+
iproxy _ = Proxy
164+
fromSpine (SProd "Data.Identity.Identity" [x]) = Identity <$> fromSpine (force x)
165+
fromSpine _ = Nothing
166+
151167
instance genericOrdering :: Generic Ordering where
152168
toSpine = case _ of
153169
LT -> SProd "Data.Ordering.LT" []

0 commit comments

Comments
 (0)