streaming-sort-0.1.0.0: Sorting streams

CopyrightIvan Lazar Miljenovic
LicenseMIT
MaintainerIvan.Miljenovic@gmail.com
Safe HaskellNone
LanguageHaskell2010

Streaming.Sort.Lifted

Contents

Description

 

Synopsis

In-memory sorting

These functions require reading all the values from the Stream before being able to sort them. As such, it is highly recommended you only use them for short Streams.

sort :: (Monad m, Ord a) => Stream (Of a) m r -> Stream (Of a) m r Source #

Sort the values based upon their Ord instance.

sortBy :: Monad m => (a -> a -> Ordering) -> Stream (Of a) m r -> Stream (Of a) m r Source #

Use the specified comparison function to sort the values.

sortOn :: (Ord b, Monad m) => (a -> b) -> Stream (Of a) m r -> Stream (Of a) m r Source #

Use the provided function to be able to compare values.

File-based sorting

For large Streams it may not be possible to sort it entirely in memory. As such, these functions work by sorting chunks of the Stream and storing them in temporary files before merging them all together.

These functions may throw a SortException.

withFileSort :: (Ord a, Binary a, Withable w, MonadMask (WithMonad w), MonadIO (WithMonad w), MonadThrow m, MonadIO m) => Config -> Stream (Of a) (WithMonad w) v -> w (Stream (Of a) m ()) Source #

Use external files to temporarily store partially sorted (using the comparison function) results (splitting into chunks of the specified size if one is provided).

These files are stored inside the specified directory if provided; if no such directory is provided then the system temporary directory is used.

withFileSortBy :: (Ord a, Binary a, Withable w, MonadMask (WithMonad w), MonadIO (WithMonad w), MonadThrow m, MonadIO m) => Config -> (a -> a -> Ordering) -> Stream (Of a) (WithMonad w) v -> w (Stream (Of a) m ()) Source #

Use external files to temporarily store partially sorted (using the comparison function) results (splitting into chunks of the specified size if one is provided).

These files are stored inside the specified directory if provided; if no such directory is provided then the system temporary directory is used.

Exceptions

Configuration

data Config Source #

Instances

defaultConfig :: Config Source #

Default settings for sorting using external files:

  • Have a chunk size of 1000.
  • No more than 100 temporary files to be open at a time.
  • Use the system temporary directory.

setConfig :: (forall f. Functor f => (a -> f a) -> Config -> f Config) -> a -> Config -> Config Source #

A specialised variant of set from lens, microlens, etc. defined here in case you're not using one of those libraries.

chunkSize :: Functor f => (Int -> f Int) -> Config -> f Config Source #

maxFiles :: Functor f => (Int -> f Int) -> Config -> f Config Source #