advent-0.1.0.0: Advent of Code common library
Copyright(c) Eric Mertens 2021
LicenseISC
Maintaineremertens@gmail.com
Safe HaskellSafe-Inferred
LanguageHaskell2010

Advent.Queue

Description

 
Synopsis

Documentation

data Queue a where Source #

FIFO Queue implementation

Bundled Patterns

pattern Empty :: Queue a

Empty queue

>>> Empty :: Queue Char
fromList ""
pattern (:<|) :: a -> Queue a -> Queue a

Pattern for pop

>>> let x :<| xs = fromList "abc" in (x, xs)
('a',fromList "bc")

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 #

(|>) :: 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

snoc :: a -> Queue a -> Queue a Source #

Add a new element to the end of a queue.

>>> snoc 'z' (fromList "abc")
fromList "abcz"

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")

appendList :: Queue a -> [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 (fromList "xyz") "abc"
fromList "xyzabc"