An ordered list that contains unique elements.
Create a UniqueList from a List.
Note: Elements are placed in the position at which they occurred last.
fromList [ 3, 1, 2, 3 ]
--> fromList [ 1, 2, 3 ]Create an empty UniqueList.
empty
--> fromList []Add an element to the front of a UniqueList.
Note: If the element was already in the list, it will be moved to the front of the list.
-- Add an element
cons 1 (fromList [ 2, 3, 4 ])
--> fromList [ 1, 2, 3, 4 ]
-- Move an element
cons 3 (fromList [ 1, 2, 3 ])
--> fromList [ 3, 1, 2 ]Remove a value from a UniqueList if the value is present.
remove 2 (fromList [ 1, 2, 3 ])
--> fromList [ 1, 3 ]
remove 0 (fromList [ 1, 2, 3 ])
--> fromList [ 1, 2, 3 ]Reverse a UniqueList.
reverse (fromList [ "second", "first" ])
--> fromList [ "first", "second" ]
reverse (fromList [ 3, 2, 1 ])
--> fromList [ 1, 2, 3, 3 ]Add an element to a UniqueList before another element.
Note: If the added element is already in the list, it will be moved to the new position.
-- Add an element
addBefore 2 6 (fromList [ 0, 2, 1 ])
--> fromList [ 0, 6, 2, 1 ]
-- Move an element
addBefore 4 1 (fromList [ 1, 2, 3, 4 ])
--> fromList [ 2, 3, 1, 4 ]
-- No effect
addBefore 0 1 (fromList [ 1, 2 ])
--> fromList [ 1, 2 ]Add an element to a UniqueList after another element
Note: If the added element is already in the list, it will be moved to the new position.
-- Add an element
addAfter 2 3 (fromList [ 1, 2, 4, 5 ])
--> fromList [ 1, 2, 3, 4, 5 ]
-- Move an element
addAfter 4 1 (fromList [ 1, 2, 3, 4 ])
--> fromList [ 2, 3, 4, 1 ]
-- No effect
addAfter 0 1 (fromList [ 1, 2 ])
--> fromList [ 1, 2 ]Turn a UniqueList into a List.
toList (fromList [ 1, 1 ])
--> [1]Determine the number of elements in a UniqueList.
-- Without duplicates
length (fromList [ 1, 2, 3 ])
--> 3
-- With duplicates
length (fromList [ 2, 2, 2 ])
--> 1Determine if a UniqueList contains a value.
member 4 (fromList [ 1, 4, 6 ])
--> True
member "cat" (fromList [ "dog", "bird" ])
--> FalseCheck if a UniqueList is empty.
isEmpty (fromList [])
--> True
isEmpty (fromList [ 1 ])
--> FalseCheck if an element is the first in a UniqueList.
Returns Nothing if the list is empty.
isFirst 1 (fromList [1,2,3])
--> Just True
isFirst 1 empty
--> NothingCheck if an element is before another in a UniqueList.
Returns Nothing if either of the elements being queried are not in the list.
('A' |> isBefore 'C') (fromList [ 'A', 'B', 'C' ])
--> Just True
('D' |> isBefore 'B') (fromList [ 'B', 'C', 'D' ])
--> Just False
('Z' |> isBefore 'B') (fromList [ 'A', 'B' ])
--> NothingCheck if an element is after another in a UniqueList.
Returns Nothing if either of the elements being queried are not in the list.
('D' |> isAfter 'B') (fromList [ 'B', 'C', 'D' ])
--> Just True
('A' |> isAfter 'C') (fromList [ 'A', 'B', 'C' ])
--> Just False
('Z' |> isAfter 'B') (fromList [ 'A', 'B' ])
--> NothingRemove duplicates from a list without using the UniqueList type.
Note: Elements are placed in the position at which they occurred last.
Similar to the unique function in elm-community/list-extra,
however List.Extra.unique only works on List comparable.
filterDuplicates [ True, True ]
--> [ True ]
filterDuplicates [ 1, 1, 2, 3, 5 ]
--> [ 1, 2, 3, 5 ]
filterDuplicates [ 1, 2, 3, 4, 1 ]
--> [ 2, 3, 4, 1 ]
A list that has no duplicate elements, much like a
Set. However,UniqueListpreserves the initial order of elements and does not require that elements becomparable.