    -- | Helpful segment combinators.
    module Data.Conduit.Shell.Segments where

    import Control.Monad (void)
    import qualified Data.ByteString.Char8 as S8
    import Data.Conduit
    import qualified Data.Conduit.List as CL
    import qualified Data.Conduit.Binary as CB
    import Data.Conduit.Shell.Process
    import Data.Text (Text)
    import qualified Data.Text.Encoding as T
    import UnliftIO (MonadUnliftIO)

    -- | Extract the 'String' values from a segment.
    strings :: MonadUnliftIO m => Segment m () -> Segment m [String]
    strings :: forall (m :: * -> *).
    MonadUnliftIO m =>
    Segment m () -> Segment m [String]
    strings Segment m ()
    s = Segment m ()
    s Segment m () -> Segment m [String] -> Segment m [String]
    forall (m :: * -> *) b.
    MonadUnliftIO m =>
    Segment m () -> Segment m b -> Segment m b
    $| ConduitT ByteString ByteString m [String] -> Segment m [String]
    forall a (m :: * -> *) r.
    (a ~ ByteString, Monad m) =>
    ConduitT a ByteString m r -> Segment m r
    conduit (ConduitT ByteString ByteString m ()
    forall (m :: * -> *).
    Monad m =>
    ConduitT ByteString ByteString m ()
    CB.lines ConduitT ByteString ByteString m ()
    -> ConduitT ByteString ByteString m [String]
    -> ConduitT ByteString ByteString m [String]
    forall (m :: * -> *) a b c r.
    Monad m =>
    ConduitT a b m () -> ConduitT b c m r -> ConduitT a c m r
    .| (ByteString -> String) -> ConduitT ByteString String m ()
    forall (m :: * -> *) a b. Monad m => (a -> b) -> ConduitT a b m ()
    CL.map ByteString -> String
    S8.unpack ConduitT ByteString String m ()
    -> ConduitT String ByteString m [String]
    -> ConduitT ByteString ByteString m [String]
    forall (m :: * -> *) a b c r.
    Monad m =>
    ConduitT a b m () -> ConduitT b c m r -> ConduitT a c m r
    .| ConduitT String ByteString m [String]
    forall (m :: * -> *) a o. Monad m => ConduitT a o m [a]
    CL.consume)

    -- | Extract the 'Text' values from a segment.
    texts :: MonadUnliftIO m => Segment m () -> Segment m [Text]
    texts :: forall (m :: * -> *).
    MonadUnliftIO m =>
    Segment m () -> Segment m [Text]
    texts Segment m ()
    s = Segment m ()
    s Segment m () -> Segment m [Text] -> Segment m [Text]
    forall (m :: * -> *) b.
    MonadUnliftIO m =>
    Segment m () -> Segment m b -> Segment m b
    $| ConduitT ByteString ByteString m [Text] -> Segment m [Text]
    forall a (m :: * -> *) r.
    (a ~ ByteString, Monad m) =>
    ConduitT a ByteString m r -> Segment m r
    conduit (ConduitT ByteString ByteString m ()
    forall (m :: * -> *).
    Monad m =>
    ConduitT ByteString ByteString m ()
    CB.lines ConduitT ByteString ByteString m ()
    -> ConduitT ByteString ByteString m [Text]
    -> ConduitT ByteString ByteString m [Text]
    forall (m :: * -> *) a b c r.
    Monad m =>
    ConduitT a b m () -> ConduitT b c m r -> ConduitT a c m r
    .| (ByteString -> Text) -> ConduitT ByteString Text m ()
    forall (m :: * -> *) a b. Monad m => (a -> b) -> ConduitT a b m ()
    CL.map ByteString -> Text
    T.decodeUtf8 ConduitT ByteString Text m ()
    -> ConduitT Text ByteString m [Text]
    -> ConduitT ByteString ByteString m [Text]
    forall (m :: * -> *) a b c r.
    Monad m =>
    ConduitT a b m () -> ConduitT b c m r -> ConduitT a c m r
    .| ConduitT Text ByteString m [Text]
    forall (m :: * -> *) a o. Monad m => ConduitT a o m [a]
    CL.consume)

    -- | Ignore any output from a segment.
    ignore :: MonadUnliftIO m => Segment m () -> Segment m ()
    ignore :: forall (m :: * -> *).
    MonadUnliftIO m =>
    Segment m () -> Segment m ()
    ignore Segment m ()
    s = Segment m [ByteString] -> Segment m ()
    forall (f :: * -> *) a. Functor f => f a -> f ()
    void (Segment m ()
    s Segment m () -> Segment m [ByteString] -> Segment m [ByteString]
    forall (m :: * -> *) b.
    MonadUnliftIO m =>
    Segment m () -> Segment m b -> Segment m b
    $| ConduitT ByteString ByteString m [ByteString]
    -> Segment m [ByteString]
    forall a (m :: * -> *) r.
    (a ~ ByteString, Monad m) =>
    ConduitT a ByteString m r -> Segment m r
    conduit ConduitT ByteString ByteString m [ByteString]
    forall (m :: * -> *) a o. Monad m => ConduitT a o m [a]
    CL.consume)