Copyright | (c) Eric Mertens 2018 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- data Queue a = Queue [a] [a] !Int
- pattern Empty :: Queue a
- pattern (:<|) :: a -> Queue a -> Queue a
- (|>) :: Queue a -> a -> Queue a
- singleton :: a -> Queue a
- fromList :: [a] -> Queue a
- appendList :: [a] -> Queue a -> Queue a
- pop :: Queue a -> Maybe (a, Queue a)
- snoc :: a -> Queue a -> Queue a
- exec :: [a] -> [a] -> Int -> Queue a
- rotate
Documentation
FIFO Queue implementation
Instances
Foldable Queue Source # | Fold over elements in the order they would be returned by pop
|
Defined in Advent.Queue fold :: Monoid m => Queue m -> m # foldMap :: Monoid m => (a -> m) -> Queue a -> m # foldMap' :: Monoid m => (a -> m) -> Queue a -> m # foldr :: (a -> b -> b) -> b -> Queue a -> b # foldr' :: (a -> b -> b) -> b -> Queue a -> b # foldl :: (b -> a -> b) -> b -> Queue a -> b # foldl' :: (b -> a -> b) -> b -> Queue a -> b # foldr1 :: (a -> a -> a) -> Queue a -> a # foldl1 :: (a -> a -> a) -> Queue a -> a # elem :: Eq a => a -> Queue a -> Bool # maximum :: Ord a => Queue a -> a # minimum :: Ord a => Queue a -> a # | |
Read a => Read (Queue a) Source # | |
Show a => Show (Queue a) Source # | Renders using
|
pattern (:<|) :: a -> Queue a -> Queue a Source #
Pattern for pop
>>>
let x :<| xs = fromList "abc" in (x, xs)
('a',fromList "bc")
(|>) :: Queue a -> a -> Queue a Source #
Add an element to the end of a queue. See: snoc
>>>
fromList "abc" |> 'z'
fromList "abcz"
singleton :: a -> Queue a Source #
Construct a queue from a single element.
>>>
singleton 'a'
fromList "a"
fromList :: [a] -> Queue a Source #
Construct a queue from a list. The head of the list will
be the first element returned by pop
appendList :: [a] -> Queue a -> Queue a Source #
Append many items onto a queue. The items will pop from the queue in the same order as they are in the given list.
>>>
appendList "abc" (fromList "xyz")
fromList "xyzabc"
pop :: Queue a -> Maybe (a, Queue a) Source #
Remove an element from the front of a queue and a new queue without that element.
>>>
pop (fromList "abc")
Just ('a',fromList "bc")
snoc :: a -> Queue a -> Queue a Source #
Add a new element to the end of a queue.
>>>
snoc 'z' (fromList "abc")
fromList "abcz"
rotate