git.iko.soy/typeable/servant
on master help sign in
Make default ToSample instances productive
401b44aNickolay Kudasov
servant-docs/servant-docs.cabal+1
@@ -42,6 +42,7 @@ library
42 , string-conversions
42 , string-conversions
43 , text
43 , text
44 , unordered-containers
44 , unordered-containers
45+ , control-monad-omega == 0.3.*
45 hs-source-dirs: src
46 hs-source-dirs: src
46 default-language: Haskell2010
47 default-language: Haskell2010
47 ghc-options: -Wall
48 ghc-options: -Wall
servant-docs/src/Servant/Docs/Internal.hs+5−4
@@ -23,6 +23,7 @@ module Servant.Docs.Internal where
23import Control.Applicative
23import Control.Applicative
24import Control.Arrow (second)
24import Control.Arrow (second)
25import Control.Lens hiding (List, to, from)
25import Control.Lens hiding (List, to, from)
26+import qualified Control.Monad.Omega as Omega
26import Data.ByteString.Conversion (ToByteString, toByteString)
27import Data.ByteString.Conversion (ToByteString, toByteString)
27import Data.ByteString.Lazy.Char8 (ByteString)
28import Data.ByteString.Lazy.Char8 (ByteString)
28import qualified Data.CaseInsensitive as CI
29import qualified Data.CaseInsensitive as CI
@@ -394,12 +395,12 @@ defaultSample :: forall a b. (Generic a, Generic b, GToSample (Rep a) (Rep b)) =
394defaultSample _ = to <$> gtoSample (Proxy :: Proxy (Rep a))
395defaultSample _ = to <$> gtoSample (Proxy :: Proxy (Rep a))
395
396
396defaultSamples :: forall a b. (Generic a, Generic b, GToSample (Rep a) (Rep b)) => Proxy a -> [(Text, b)]
397defaultSamples :: forall a b. (Generic a, Generic b, GToSample (Rep a) (Rep b)) => Proxy a -> [(Text, b)]
397−defaultSamples _ = second to <$> gtoSamples (Proxy :: Proxy (Rep a))
398+defaultSamples _ = Omega.runOmega $ second to <$> gtoSamples (Proxy :: Proxy (Rep a))
398
399
399class GToSample t s where
400class GToSample t s where
400 gtoSample :: proxy t -> Maybe (s x)
401 gtoSample :: proxy t -> Maybe (s x)
401− gtoSample _ = snd <$> listToMaybe (gtoSamples (Proxy :: Proxy t))
402+ gtoSample _ = snd <$> listToMaybe (Omega.runOmega (gtoSamples (Proxy :: Proxy t)))
402− gtoSamples :: proxy t -> [(Text, s x)]
403+ gtoSamples :: proxy t -> Omega.Omega (Text, s x)
403 gtoSamples _ = maybe empty (pure . ("",)) (gtoSample (Proxy :: Proxy t))
404 gtoSamples _ = maybe empty (pure . ("",)) (gtoSample (Proxy :: Proxy t))
404
405
405instance GToSample U1 U1 where
406instance GToSample U1 U1 where
@@ -426,7 +427,7 @@ instance (GToSample p p', GToSample q q') => GToSample (p :+: q) (p' :+: q') whe
426
427
427instance ToSample a b => GToSample (K1 i a) (K1 i b) where
428instance ToSample a b => GToSample (K1 i a) (K1 i b) where
428 gtoSample _ = K1 <$> toSample (Proxy :: Proxy a)
429 gtoSample _ = K1 <$> toSample (Proxy :: Proxy a)
429− gtoSamples _ = second K1 <$> toSamples (Proxy :: Proxy a)
430+ gtoSamples _ = second K1 <$> Omega.each (toSamples (Proxy :: Proxy a))
430
431
431instance (GToSample f g) => GToSample (M1 i a f) (M1 i a g) where
432instance (GToSample f g) => GToSample (M1 i a f) (M1 i a g) where
432 gtoSample _ = M1 <$> gtoSample (Proxy :: Proxy f)
433 gtoSample _ = M1 <$> gtoSample (Proxy :: Proxy f)
stack.yaml+1
@@ -14,4 +14,5 @@ packages:
14- servant-server/
14- servant-server/
15extra-deps:
15extra-deps:
16- engine-io-wai-1.0.2
16- engine-io-wai-1.0.2
17+- control-monad-omega-0.3.1
17resolver: nightly-2015-09-10
18resolver: nightly-2015-09-10