-
-
Save dminuoso/78b9e52de12306ce5511d367200dbebe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Normalize f where | |
normalize :: f -> f | |
default normalize :: (Generic f, GenericNormalize (Rep f)) => f -> f | |
normalize = to . genericNormalize . from | |
instance {-# OVERLAPPABLE #-} Normalize a where | |
normalize = id | |
instance Normalize (Maybe T.Text) where | |
normalize (Just "") = Nothing | |
normalize x = x | |
instance Normalize (Maybe [a]) where | |
normalize (Just []) = Nothing | |
normalize x = x | |
class GenericNormalize f where | |
genericNormalize :: f p -> f p | |
instance (GenericNormalize f, GenericNormalize g) => GenericNormalize (f :*: g) where | |
genericNormalize (a :*: b) = | |
genericNormalize a :*: genericNormalize b | |
instance (GenericNormalize f, GenericNormalize g) => GenericNormalize (f :+: g) where | |
genericNormalize (L1 a) = L1 (genericNormalize a) | |
genericNormalize (R1 a) = R1 (genericNormalize a) | |
instance GenericNormalize f => GenericNormalize (M1 i c f) where | |
genericNormalize (M1 a) = M1 (genericNormalize a) | |
instance (Normalize a) => GenericNormalize (Rec0 (Maybe a)) where | |
genericNormalize (K1 a) = K1 (normalize a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment