Skinney / elm-deque / Deque

A double ended queue (deque, pronounced 'deck')

Type


type Deque a

The deque datatype

Deque equality with (==) is unreliable (equivalent deques can have a different distribution of elements between the back and the front) and should not be used.

Construct

empty : Deque a

The empty deque

singleton : a -> Deque a

Create a deque consisting of a single element

initialize : Basics.Int -> (Basics.Int -> a) -> Deque a

Initialize a list of some length with some function.

initialize n f creates a list of length n with the element at index i initialized to the result of f i.

repeat : Basics.Int -> a -> Deque a

Create a list with n copies of a value:

repeat 3 ( 0, 0 ) == [ ( 0, 0 ), ( 0, 0 ), ( 0, 0 ) ]

range : Basics.Int -> Basics.Int -> Deque Basics.Int

Create a list of numbers, every element increasing by one. You give the lowest and highest number that should be in the list.

range 3 6 == [ 3, 4, 5, 6 ]

range 3 3 == [ 3 ]

range 6 3 == []

Modify

pushFront : a -> Deque a -> Deque a

Adds an element to the front of the deque

pushBack : a -> Deque a -> Deque a

Adds an element as the last element of the deque

append : Deque a -> Deque a -> Deque a

Create a new deque containing all the elements of the provided deques. Order is preserved.

Deconstruct

popFront : Deque a -> ( Maybe a, Deque a )

Returns a tuple of the first element and the remaining elements of the deque. The first element of the tuple will be Nothing íf this is run on the empty deque.

popBack : Deque a -> ( Maybe a, Deque a )

Returns a tuple containing the last element and the remaining elements of the deque. The first element of the tuple will be Nothing if this function is run on the empty deque.

left : Basics.Int -> Deque a -> Deque a

Take n number of elements from the left

right : Basics.Int -> Deque a -> Deque a

Take n number of elements from the right

dropLeft : Basics.Int -> Deque a -> Deque a

Drop n number of elements from the left

dropRight : Basics.Int -> Deque a -> Deque a

Drop n number of elements from the right

Lists

fromList : List a -> Deque a

Converts a List to a deque.

toList : Deque a -> List a

Converts the deque to a List

Query

isEmpty : Deque a -> Basics.Bool

Check if the deque holds no elements

member : a -> Deque a -> Basics.Bool

Check if the provided element exists in this deque (using ==).

length : Deque a -> Basics.Int

Get the length of the deque

first : Deque a -> Maybe a

Get the first element of the deque

last : Deque a -> Maybe a

Get the last element of the deque

equals : Deque a -> Deque a -> Basics.Bool

Check if two deques contain the same elements

Transform

map : (a -> b) -> Deque a -> Deque b

Create a new deque where every element is the result of running fn on every element.

filter : (a -> Basics.Bool) -> Deque a -> Deque a

Create a new deque which only contains the elements where the provided fn returned True

filterMap : (a -> Maybe b) -> Deque a -> Deque b

Allows running both filter and map in the same operation. The provided function is run on every element and returns a Maybe. Only the Just values will be kept in the resulting deque

foldl : (a -> b -> b) -> b -> Deque a -> b

Fold over the elements of the deque starting from the front.

foldr : (a -> b -> b) -> b -> Deque a -> b

Fold over the elements of the deque starting from the back.

partition : (a -> Basics.Bool) -> Deque a -> ( Deque a, Deque a )

Returns a tuple of deques, where the first deque contains every element where the function returned True, while the second deque contains the other elements.