@@ -20,9 +20,11 @@ import Data.Array (null, length, sortBy, zipWith)
2020import Data.Either (Either (..))
2121import Data.Foldable (all , and , find , fold , intercalate )
2222import Data.Maybe (Maybe (..))
23+ import Data.NonEmpty (NonEmpty (..))
2324import Data.String (joinWith )
2425import Data.Traversable (traverse )
2526import Data.Tuple (Tuple (..))
27+
2628import Type.Proxy (Proxy (..))
2729
2830-- | The Generic typeclass provides methods for sending data to/from spine
@@ -164,6 +166,28 @@ instance genericOrdering :: Generic Ordering where
164166 SProd " Data.Ordering.GT" [] -> Just GT
165167 _ -> Nothing
166168
169+ instance genericNonEmpty :: (Generic (f a ), Generic a ) => Generic (NonEmpty f a ) where
170+ toSpine (NonEmpty x xs) =
171+ SProd " Data.NonEmpty.NonEmpty" [\_ -> toSpine x, \_ -> toSpine xs]
172+ toSignature x =
173+ SigProd
174+ " Data.NonEmpty.NonEmpty"
175+ [ { sigConstructor: " Data.NonEmpty.NonEmpty"
176+ , sigValues:
177+ [ \_ -> toSignature (headProxy x)
178+ , \_ -> toSignature (tailProxy x)
179+ ]
180+ }
181+ ]
182+ where
183+ headProxy :: Proxy (NonEmpty f a ) -> Proxy a
184+ headProxy _ = Proxy
185+ tailProxy :: Proxy (NonEmpty f a ) -> Proxy (f a )
186+ tailProxy _ = Proxy
187+ fromSpine (SProd " Data.NonEmpty.NonEmpty" [x, xs]) =
188+ NonEmpty <$> fromSpine (force x) <*> fromSpine (force xs)
189+ fromSpine _ = Nothing
190+
167191-- | A GenericSpine is a universal representation of an arbitrary data
168192-- | structure (that does not contain function arrows).
169193data GenericSpine
0 commit comments