advent2021-0.1.0.0: Advent of Code 2021 Solutions
Copyright(c) Eric Mertens 2018
LicenseISC
Maintaineremertens@gmail.com
Safe HaskellNone
LanguageHaskell2010

Advent.Queue

Description

 
Synopsis

Documentation

data Queue a Source #

FIFO Queue implementation

Constructors

Queue [a] [a] !Int 

Instances

Instances details
Foldable Queue Source #

Fold over elements in the order they would be returned by pop

>>> toList (fromList "abc")
"abc"
Instance details

Defined in Advent.Queue

Methods

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 #

toList :: Queue a -> [a] #

null :: Queue a -> Bool #

length :: Queue a -> Int #

elem :: Eq a => a -> Queue a -> Bool #

maximum :: Ord a => Queue a -> a #

minimum :: Ord a => Queue a -> a #

sum :: Num a => Queue a -> a #

product :: Num a => Queue a -> a #

Read a => Read (Queue a) Source # 
Instance details

Defined in Advent.Queue

Show a => Show (Queue a) Source #

Renders using fromList syntax.

>>> show (fromList "example")
"fromList \"example\""
Instance details

Defined in Advent.Queue

Methods

showsPrec :: Int -> Queue a -> ShowS #

show :: Queue a -> String #

showList :: [Queue a] -> ShowS #

pattern Empty :: Queue a Source #

Empty queue

>>> Empty :: Queue Char
fromList ""

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"

exec :: [a] -> [a] -> Int -> Queue a Source #

rotate