Jon Schoning 4fb612c2e8 [haskell-http-client] update documentation; refactoring; add 'strictFields' cli option (#6458)
* update readme; remove unused DeriveAnyClass extension

* refactor request/param utility functions

* add strictFields cli option

* add CONTRIBUTING.md
2017-09-09 17:11:46 +08:00

56 lines
1.3 KiB
Plaintext

{-# OPTIONS_GHC -fno-warn-unused-imports #-}
module Instances where
import Data.Text (Text, pack)
import Data.Char (isSpace)
import Data.List (sort)
import Data.Time.Calendar (Day(..))
import Data.Time.Clock (UTCTime(..), secondsToDiffTime)
import Test.QuickCheck
import qualified Data.HashMap.Strict as HM
import qualified Data.Set as Set
import ApproxEq
import {{title}}.Model
instance Arbitrary Text where
arbitrary = pack <$> arbitrary
instance Arbitrary Day where
arbitrary = ModifiedJulianDay . (2000 +) <$> arbitrary
shrink = (ModifiedJulianDay <$>) . shrink . toModifiedJulianDay
instance Arbitrary UTCTime where
arbitrary =
UTCTime <$> arbitrary <*> (secondsToDiffTime <$> choose (0, 86401))
-- | Checks if a given list has no duplicates in _O(n log n)_.
hasNoDups
:: (Ord a)
=> [a] -> Bool
hasNoDups = go Set.empty
where
go _ [] = True
go s (x:xs)
| s' <- Set.insert x s
, Set.size s' > Set.size s = go s' xs
| otherwise = False
instance ApproxEq Day where
(=~) = (==)
-- * Models
{{#models}}
{{#model}}
instance Arbitrary {{classname}} where
arbitrary =
{{classname}}
<$> {{#vars}}arbitrary -- {{name}} :: {{^required}}Maybe {{/required}}{{datatype}}
{{#hasMore}}<*> {{/hasMore}}{{/vars}}
{{/model}}
{{/models}}