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

Commit fdbb6d7

Browse files
authored
Add Generic a => Generic (Identity a) instance
1 parent 552c4f3 commit fdbb6d7

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

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)