avh4 / elm-fifo / Fifo

Creating FIFOs


type Fifo a

A FIFO containing items of type a.

empty : Fifo a

Creates an empty Fifo.

Fifo.empty
    -- == Fifo.fromList []

fromList : List a -> Fifo a

Creates a Fifo from a List.

Fifo.fromList [3,4,5]
|> Fifo.remove
|> Tuple.first
    -- == Just 3

Inserting/Removing

insert : a -> Fifo a -> Fifo a

Inserts an item into a Fifo

Fifo.empty
|> Fifo.insert 7
|> Fifo.insert 8
    -- == Fifo.fromList [7,8]

remove : Fifo a -> ( Maybe a, Fifo a )

Removes the next (oldest) item from a Fifo, returning the item (if any), and the updated Fifo.

Fifo.fromList [3,7]
|> Fifo.remove
    -- == (Just 3, Fifo.fromList [7])

To List

toList : Fifo a -> List a

Converts a Fifo to a List.

Fifo.empty
|> Fifo.insert 7
|> Fifo.insert 9
|> Fifo.toList
    -- == [7,9]