Adds ParseFields/ParseRecord instances for NonEmpty

This commit is contained in:
Nick Partridge 2016-10-05 09:37:35 +10:00
parent 08bfce911b
commit c78565b058
2 changed files with 10 additions and 1 deletions

View File

@ -30,7 +30,9 @@ Library
optparse-applicative >= 0.11.0 && < 0.14,
time >= 1.5 && < 1.7 ,
void < 0.8 ,
bytestring < 0.11
bytestring < 0.11,
semigroups >= 0.18.1
if impl(ghc < 7.8)
Build-Depends:
singletons >= 0.10.0 && < 1.0 ,

View File

@ -235,6 +235,7 @@ import Control.Applicative
import Control.Monad.IO.Class (MonadIO(..))
import Data.Char (toLower, toUpper)
import Data.Monoid
import Data.List.NonEmpty (NonEmpty((:|)))
import Data.Proxy
import Data.Text (Text)
import Data.Typeable (Typeable)
@ -476,6 +477,9 @@ instance (Num a, ParseField a) => ParseFields (Product a) where
instance ParseField a => ParseFields [a] where
parseFields = parseListOfField
instance ParseField a => ParseFields (NonEmpty a) where
parseFields h m = (:|) <$> parseField h m <*> parseListOfField h m
{-| Use this to annotate a field with a type-level string (i.e. a `Symbol`)
representing the help description for that field:
@ -589,6 +593,9 @@ instance (Num a, ParseField a) => ParseRecord (Product a) where
instance ParseField a => ParseRecord [a] where
parseRecord = fmap getOnly parseRecord
instance ParseField a => ParseRecord (NonEmpty a) where
parseRecord = fmap getOnly parseRecord
instance (ParseFields a, ParseFields b) => ParseRecord (a, b)
instance (ParseFields a, ParseFields b, ParseFields c) => ParseRecord (a, b, c)
instance (ParseFields a, ParseFields b, ParseFields c, ParseFields d) => ParseRecord (a, b, c, d)