-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Low-level components of "potoki"
--
-- Provides everything required for building custom instances of the
-- "potoki" abstractions. Consider this library to be the Internals
-- modules of "potoki".
@package potoki-core
@version 2
module Potoki.Core.Fetch
-- | Passive producer of elements.
newtype Fetch element
Fetch :: (IO (Maybe element)) -> Fetch element
duplicate :: Fetch element -> IO (Fetch element, Fetch element)
maybeRef :: IORef (Maybe a) -> Fetch a
list :: IORef [element] -> Fetch element
firstCachingSecond :: IORef b -> Fetch (a, b) -> Fetch a
bothFetchingFirst :: IORef b -> Fetch a -> Fetch (a, b)
rightHandlingLeft :: (left -> IO ()) -> Fetch (Either left right) -> Fetch right
rightCachingLeft :: IORef (Maybe left) -> Fetch (Either left right) -> Fetch right
eitherFetchingRight :: IORef (Maybe left) -> Fetch right -> Fetch (Either left right)
signaling :: IO () -> IO () -> Fetch a -> Fetch a
ioFetch :: IO (Fetch a) -> Fetch a
handleBytes :: Handle -> Fetch (Either IOException ByteString)
handleBytesWithChunkSize :: Int -> Handle -> Fetch (Either IOException ByteString)
handleText :: Handle -> Fetch (Either IOException Text)
mapFilter :: (input -> Maybe output) -> Fetch input -> Fetch output
filter :: (input -> Bool) -> Fetch input -> Fetch input
just :: Fetch (Maybe element) -> Fetch element
takeWhile :: (element -> Bool) -> Fetch element -> Fetch element
infiniteMVar :: MVar element -> Fetch element
finiteMVar :: MVar (Maybe element) -> Fetch element
vector :: IORef Int -> Vector element -> Fetch element
handlingElements :: (element -> IO ()) -> Fetch element -> Fetch element
instance GHC.Base.Functor Potoki.Core.Types.Fetch
instance GHC.Base.Applicative Potoki.Core.Types.Fetch
instance GHC.Base.Monad Potoki.Core.Types.Fetch
instance GHC.Base.Alternative Potoki.Core.Types.Fetch
instance GHC.Base.MonadPlus Potoki.Core.Types.Fetch
instance Control.Monad.IO.Class.MonadIO Potoki.Core.Types.Fetch
module Potoki.Core.Produce
-- | Passive producer of elements with support for early termination and
-- resource management.
newtype Produce element
Produce :: (Acquire (Fetch element)) -> Produce element
list :: [input] -> Produce input
transform :: Transform input output -> Produce input -> Produce output
vector :: Vector input -> Produce input
hashMapRows :: HashMap a b -> Produce (a, b)
-- | Read from a file by path.
--
--
-- - Exception-free
-- - Automatic resource management
--
fileBytes :: FilePath -> Produce (Either IOException ByteString)
-- | Read from a file by path.
--
--
-- - Exception-free
-- - Automatic resource management
--
fileBytesAtOffset :: FilePath -> Int -> Produce (Either IOException ByteString)
-- | Read from a file by path.
--
--
-- - Exception-free
-- - Automatic resource management
--
fileText :: FilePath -> Produce (Either IOException Text)
stdinBytes :: Produce (Either IOException ByteString)
-- | Sorted subpaths of the directory.
directoryContents :: FilePath -> Produce (Either IOException FilePath)
-- | Read from MVar. Nothing gets interpreted as the end of input.
finiteMVar :: MVar (Maybe element) -> Produce element
-- | Read from MVar. Never stops.
infiniteMVar :: MVar element -> Produce element
instance GHC.Base.Functor Potoki.Core.Types.Produce
instance GHC.Base.Applicative Potoki.Core.Types.Produce
instance GHC.Base.Alternative Potoki.Core.Types.Produce
instance GHC.Base.Monad Potoki.Core.Types.Produce
instance Control.Monad.IO.Class.MonadIO Potoki.Core.Types.Produce
module Potoki.Core.Transform
newtype Transform input output
Transform :: (Fetch input -> Acquire (Fetch output)) -> Transform input output
consume :: Consume input output -> Transform input output
produce :: (input -> Produce output) -> Transform input output
mapFetch :: (Fetch a -> Fetch b) -> Transform a b
ioTransform :: IO (Transform a b) -> Transform a b
take :: Int -> Transform input input
takeWhile :: (input -> Bool) -> Transform input input
drop :: Int -> Transform input input
mapFilter :: (input -> Maybe output) -> Transform input output
filter :: (input -> Bool) -> Transform input input
just :: Transform (Maybe input) input
list :: Transform [a] a
vector :: Transform (Vector a) a
distinctBy :: (Eq comparable, Hashable comparable) => (element -> comparable) -> Transform element element
distinct :: (Eq element, Hashable element) => Transform element element
-- | Execute the IO action.
executeIO :: Transform (IO a) a
mapInIO :: (a -> IO b) -> Transform a b
builderChunks :: Transform Builder ByteString
-- | Convert freeform bytestring chunks into chunks, which are strictly
-- separated by newline no matter how long they may be.
extractLines :: Transform ByteString ByteString
-- | Notice that you can control the emission of output of each step by
-- producing a list of outputs and then composing the transform with the
-- "list" transform.
runState :: (a -> State s b) -> s -> Transform a (s, b)
execState :: (a -> State s b) -> s -> Transform a s
evalState :: (a -> State s b) -> s -> Transform a b
-- | Lift an Attoparsec ByteString parser.
parseBytes :: Parser parsed -> Transform ByteString (Either Text parsed)
-- | Lift an Attoparsec Text parser.
parseText :: Parser parsed -> Transform Text (Either Text parsed)
bufferize :: Int -> Transform element element
-- | Execute the transform on the specified amount of threads. The order of
-- the outputs produced is indiscriminate.
concurrently :: Int -> Transform input output -> Transform input output
-- | A transform, which fetches the inputs asynchronously on the specified
-- number of threads.
async :: Int -> Transform input input
deleteFile :: Transform FilePath (Either IOException ())
appendBytesToFile :: Transform (FilePath, ByteString) (Either IOException ())
writeTextToFile :: Transform (FilePath, Text) (Either IOException ())
-- | Useful for debugging
traceWithCounter :: (Int -> String) -> Transform a a
module Potoki.Core.Consume
-- | Active consumer of input into output. Sort of like a reducer in
-- Map/Reduce.
--
-- Automates the management of resources.
newtype Consume input output
-- | An action, which executes the provided fetch in IO, while managing the
-- resources behind the scenes.
Consume :: (Fetch input -> IO output) -> Consume input output
apConcurrently :: Consume a (b -> c) -> Consume a b -> Consume a c
list :: Consume input [input]
sum :: Num num => Consume num num
transform :: Transform input1 input2 -> Consume input2 output -> Consume input1 output
count :: Consume input Int
head :: Consume input (Maybe input)
last :: Consume input (Maybe input)
-- | A faster alternative to "list", which however constructs the list in
-- the reverse order.
reverseList :: Consume input [input]
vector :: Consume input (Vector input)
concat :: Monoid monoid => Consume monoid monoid
fold :: Fold input output -> Consume input output
foldInIO :: FoldM IO input output -> Consume input output
folding :: Fold a b -> Consume a c -> Consume a (b, c)
foldingInIO :: FoldM IO a b -> Consume a c -> Consume a (b, c)
execState :: (a -> State s b) -> s -> Consume a s
-- | Overwrite a file.
--
--
-- - Exception-free
-- - Automatic resource management
--
writeBytesToFile :: FilePath -> Consume ByteString (Either IOException ())
-- | Append to a file.
--
--
-- - Exception-free
-- - Automatic resource management
--
appendBytesToFile :: FilePath -> Consume ByteString (Either IOException ())
deleteFiles :: Consume FilePath (Either IOException ())
printBytes :: Consume ByteString ()
printText :: Consume Text ()
printString :: Consume String ()
parseBytes :: Parser output -> Consume ByteString (Either Text output)
parseText :: Parser output -> Consume Text (Either Text output)
-- | Execute a Consume concurrently and consume its results.
concurrently :: Int -> Consume a b -> Consume b c -> Consume a c
instance Data.Profunctor.Unsafe.Profunctor Potoki.Core.Types.Consume
instance Data.Profunctor.Choice.Choice Potoki.Core.Types.Consume
instance GHC.Base.Functor (Potoki.Core.Types.Consume input)
instance GHC.Base.Applicative (Potoki.Core.Types.Consume a)
instance GHC.Base.Monad (Potoki.Core.Types.Consume a)
instance Control.Monad.IO.Class.MonadIO (Potoki.Core.Types.Consume a)
module Potoki.Core.IO
produceAndConsume :: Produce input -> Consume input output -> IO output
produceAndTransformAndConsume :: Produce input -> Transform input anotherInput -> Consume anotherInput output -> IO output
produce :: Produce input -> forall x. IO x -> (input -> IO x) -> IO x
consume :: IO (Maybe input) -> Consume input output -> IO output
transformList :: Transform a b -> [a] -> IO [b]