HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleservant-0.20.2Haskell2010

Servant.Types.SourceT

  • 2 types
  • 14 values
  • Packageservant-0.20.2
  • Exports16
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceSourceT.hs
Example5 expressions
:set -XNoOverloadedStringsimport Data.String (fromString)import Control.Monad.Except (runExcept)import Data.Foldable (toList)import qualified Data.Attoparsec.ByteString.Char8 as A8
newtypenewtype SourceT (m :: Type -> Type) a
#

This is CPSised ListT.

Constructors

Instances10MFunctor, FromSourceIO, ToSourceIO, Functor, Foldable, Show1, …
  • MFunctor SourceTDefined in servant-0.20.2 · Servant.Types.SourceT
    Example1 expression
    hoist (Just . runIdentity) (source [1..3]) :: SourceT Maybe IntfromStepT (Effect (Just (Yield 1 (Yield 2 (Yield 3 Stop)))))
  • MonadIO m => FromSourceIO a (SourceT m a)Defined in servant-0.20.2 · Servant.API.Stream
  • SourceToSourceIO m => ToSourceIO chunk (SourceT m chunk)Defined in servant-0.20.2 · Servant.API.Stream

    Relax to use auxiliary class, have m

  • Functor m => Functor (SourceT m)Defined in servant-0.20.2 · Servant.Types.SourceT
  • Identity ~ m => Foldable (SourceT m)Defined in servant-0.20.2 · Servant.Types.SourceT
    Example1 expression
    toList (source [1::Int .. 10])[1,2,3,4,5,6,7,8,9,10]
  • (Applicative m, Show1 m) => Show1 (SourceT m)Defined in servant-0.20.2 · Servant.Types.SourceT
  • (Applicative m, Show1 m, Show a) => Show (SourceT m a)Defined in servant-0.20.2 · Servant.Types.SourceT
  • Functor m => Semigroup (SourceT m a)Defined in servant-0.20.2 · Servant.Types.SourceT
    Example1 expression
    source "xy" <> source "z" :: SourceT Identity CharfromStepT (Effect (Identity (Yield 'x' (Yield 'y' (Yield 'z' Stop)))))
  • Functor m => Monoid (SourceT m a)Defined in servant-0.20.2 · Servant.Types.SourceT
    Example1 expression
    mempty :: SourceT Maybe IntfromStepT (Effect (Just Stop))
  • (Arbitrary a, Monad m) => Arbitrary (SourceT m a)Defined in servant-0.20.2 · Servant.Types.SourceT

    Doesn't generate Error constructors. SourceT doesn't shrink.

datadata StepT (m :: Type -> Type) a
#

ListT with additional constructors.

Constructors

Instances8MFunctor, Functor, Foldable, Show1, Show, Semigroup, …
valuesource :: Foldable f => f a -> SourceT m a
#

Create pure SourceT.

Example1 expression
source "foo" :: SourceT Identity CharfromStepT (Effect (Identity (Yield 'f' (Yield 'o' (Yield 'o' Stop)))))
valuerunSourceT :: Monad m => SourceT m a -> ExceptT String m [a]
#

Get the answers.

Example1 expression
runSourceT (source "foo" :: SourceT Identity Char)ExceptT (Identity (Right "foo"))
Example1 expression
runSourceT (source "foo" :: SourceT [] Char)ExceptT [Right "foo"]
valuemapMaybe :: Functor m => (a -> Maybe b) -> SourceT m a -> SourceT m b
#

Filter values.

Example1 expression
toList $ mapMaybe (\x -> if odd x then Just x else Nothing) (source [0..10]) :: [Int][1,3,5,7,9]
Example1 expression
mapMaybe (\x -> if odd x then Just x else Nothing) (source [0..2]) :: SourceT Identity IntfromStepT (Effect (Identity (Skip (Yield 1 (Skip Stop)))))

Illustrates why we need Skip.

valueforeach
  1. :: Monad m
  2. => (String -> m ())

    error handler

  3. -> (a -> m ())
  4. -> SourceT m a
  5. -> m ()
#

Run action for each value in the SourceT.

Example1 expression
foreach fail print $ source ("abc" :: String)'a''b''c'

Transform using attoparsec parser.

Note: parser should not accept empty input!

Example1 expression
let parser = A.skipWhile A8.isSpace_w8 >> A.takeWhile1 A8.isDigit_w8
Example1 expression
runExcept $ runSourceT $ transformWithAtto parser (source $ [fromString "1 2 3"])Right ["1","2","3"]
Example1 expression
runExcept $ runSourceT $ transformWithAtto parser (source $ map fromString ["1", "2", "3"])Right ["123"]
Example1 expression
runExcept $ runSourceT $ transformWithAtto parser (source $ map fromString ["1", "2 3", "4"])Right ["12","34"]
Example1 expression
runExcept $ runSourceT $ transformWithAtto parser (source [fromString "foobar"])Left "Failed reading: takeWhile1"