-- 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.3.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 lazyByteStringRef :: IORef ByteString -> Fetch ByteString enumUntil :: (Enum a, Ord a) => IORef a -> a -> Fetch a instance GHC.Base.Functor Potoki.Core.Types.Fetch instance GHC.Base.Applicative Potoki.Core.Types.Fetch instance GHC.Base.Alternative 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 vector input => vector input -> Produce input vectorWithIndices :: Vector vector a => vector a -> Produce (Int, a) hashMapRows :: HashMap a b -> Produce (a, b) -- | Read from a file by path. -- -- fileBytes :: FilePath -> Produce (Either IOException ByteString) -- | Read from a file by path. -- -- fileBytesAtOffset :: FilePath -> Int -> Produce (Either IOException ByteString) -- | Read from a file by path. -- -- 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 lazyByteString :: ByteString -> Produce ByteString enumInRange :: (Enum a, Ord a) => a -> a -> Produce a -- | Merge two ordered sequences into one mergeOrdering :: (a -> a -> Bool) -> Produce a -> Produce a -> Produce a 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 instance GHC.Base.Semigroup (Potoki.Core.Types.Produce a) instance GHC.Base.Monoid (Potoki.Core.Types.Produce a) 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 :: Vector vector a => Transform (vector a) a -- | Chunk the stream to vector batches of the given size. -- -- It's useful in combination with concurrently in cases where -- the lifted transform's iteration is too light. Actually, there is a -- composed variation of concurrently, which utilizes it: -- concurrentlyWithBatching. batch :: Vector vector a => Int -> Transform a (vector 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 reportProgress :: (Text -> IO ()) -> Transform a a handleProgressAndCountOnInterval :: NominalDiffTime -> (Int -> Int -> IO ()) -> Transform a a 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 extractLinesWithoutTrail :: Transform ByteString ByteString extractLinesConcurrently :: Int -> 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 :: (input -> State state output) -> state -> Transform input (output, state) execState :: (input -> State state output) -> state -> Transform input state evalState :: (input -> State state output) -> state -> Transform input output scan :: Scanner a -> Transform ByteString (Either Text a) -- | 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) -- | Lift an Attoparsec ByteString parser to a transform, which parses the -- lines concurrently. parseLineBytesConcurrently :: NFData a => Int -> Parser a -> Transform ByteString (Either Text a) -- | Lift an Attoparsec ByteString parser to a transform, which parses the -- lines concurrently. parseNonEmptyLineBytesConcurrently :: NFData a => Int -> Parser a -> Transform ByteString (Either Text a) bufferize :: NFData element => Int -> Transform element element bufferizeFlushing :: Int -> Transform input [input] -- | Execute the transform on the specified amount of threads. The order of -- the outputs produced is indiscriminate. concurrently :: NFData output => Int -> Transform input output -> Transform input output concurrentlyInOrder :: NFData b => Int -> Transform a b -> Transform a b unsafeConcurrently :: NFData output => Int -> Transform input output -> Transform input output -- | A transform, which fetches the inputs asynchronously on the specified -- number of threads. async :: NFData input => Int -> Transform input input concurrentlyWithBatching :: (NFData a, NFData b) => Int -> Int -> Transform a b -> Transform a b concurrentlyInOrderWithBatching :: (NFData b) => Int -> Int -> Transform a b -> Transform a b deleteFile :: Transform FilePath (Either IOException ()) appendBytesToFile :: Transform (FilePath, ByteString) (Either IOException ()) writeTextToFile :: Transform (FilePath, Text) (Either IOException ()) count :: Transform a Int mapInIOWithCounter :: (Int -> a -> IO b) -> Transform a b handleCount :: (Int -> IO ()) -> Transform a a -- | Provides for progress monitoring by means of periodic measurement. handleCountOnInterval :: NominalDiffTime -> (Int -> IO ()) -> Transform a a -- | 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 :: (Semigroup monoid, 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 writeBytesToStdout :: Consume ByteString () -- | Overwrite a file. -- -- writeBytesToFile :: FilePath -> Consume ByteString (Either IOException ()) -- | A more efficient implementation than just writing to file without -- buffering. It uses an explicit buffer of input chunks and flushes all -- the chunks that have been so far aggregated at once. writeBytesToFileWithoutBuffering :: FilePath -> Consume ByteString (Either IOException ()) -- | Append to a file. -- -- 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 :: NFData b => 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]