Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Sort any traversable. Idea from here, but parameterized over the heap type.
Parts can be thought of as a safe version of unsafePartsOf
from lens.
- data Parts f g a b r where
- liftParts :: (IndexedQueue g a, IndexedQueue f x) => x -> Parts f g x a a
- queueTraversable :: (MeldableIndexedQueue f a, Traversable t) => p f -> t a -> t a
- runParts :: forall a b f. Parts f f b b a -> a
- queueTraversal :: (IndexedQueue f b, IndexedQueue f a) => ((a -> Parts f f a b b) -> t -> Parts f f a a t) -> t -> t
- runPartsWith :: forall a b c f g. (forall n. f n a -> g n b) -> Parts f g a b c -> c
- transformTraversal :: (IndexedQueue g b, IndexedQueue f a) => (forall n. f n a -> g n b) -> ((a -> Parts f g a b b) -> t -> Parts f g a b t) -> t -> t
- transformTraversable :: (MeldableIndexedQueue f a, IndexedQueue g b, Traversable t) => (forall n. f n a -> g n b) -> t a -> t b
Documentation
data Parts f g a b r where Source #
A queue with a certain number of elements, and a function which extracts exactly that many elements from a larger queue. You can transform the queue (i.e., reversing, etc.) before running the function, effectively transforming the contents of a traversable safely. If the underlying queue is a priority queue, then inserting elements will sort them as you go.
Functor (Parts f g a b) Source # | |
(IndexedQueue f x, MeldableIndexedQueue f x) => Applicative (Parts f g x y) Source # | |
liftParts :: (IndexedQueue g a, IndexedQueue f x) => x -> Parts f g x a a Source #
Lift a value into the running queue.
queueTraversable :: (MeldableIndexedQueue f a, Traversable t) => p f -> t a -> t a Source #
Enqueue every element of a traversable into a queue, and then dequeue them back into the same traversable. This is useful if, for instance, the queue is a priority queue: then this function will perform a sort. If the queue is first-in last-out, this function will perform a reversal.
runParts :: forall a b f. Parts f f b b a -> a Source #
Run the built-up function on the stored queue.
queueTraversal :: (IndexedQueue f b, IndexedQueue f a) => ((a -> Parts f f a b b) -> t -> Parts f f a a t) -> t -> t Source #
Queues a traversal.
runPartsWith :: forall a b c f g. (forall n. f n a -> g n b) -> Parts f g a b c -> c Source #
Perform a length-preserving transformation on the stored queue, and run the built-up function on the transformed version.
transformTraversal :: (IndexedQueue g b, IndexedQueue f a) => (forall n. f n a -> g n b) -> ((a -> Parts f g a b b) -> t -> Parts f g a b t) -> t -> t Source #
Perform an arbitrary length-preserving transformation on a lens-style traversal.
transformTraversable :: (MeldableIndexedQueue f a, IndexedQueue g b, Traversable t) => (forall n. f n a -> g n b) -> t a -> t b Source #
Apply a function which transforms a queue without changing its size to an arbitrary traversable.