novah.linkedList
This module defines an immutable linked list. A List should almost always be prefered as lists make for good linked lists.
Types
LinkedList
visibility: public+
constructors: Nil, Cons
An immutable linked list.
A List should almost always be prefered over this type as lists make for good linked lists.
Most linked list operations are O(n) like size
.
Declarations
Nil
visibility: public
type: LinkedList t38
Cons
visibility: public
type: t38 -> LinkedList t38 -> LinkedList t38
::
visibility: public
type: a -> LinkedList a -> LinkedList a
Appends the element as the new head of the linked list.
An alias to Cons
.
head
visibility: public
type: LinkedList a -> Option a
Returns the head of this linked list if it's not empty. Runtime: O(1)
tail
visibility: public
type: LinkedList a -> Option (LinkedList a)
Returns the tail of this linked list if it's not empty. Runtime: O(1)
singleton
visibility: public
type: a -> LinkedList a
Produces a linked list with a single element. Runtime: O(1)
take
visibility: public
type: Int32 -> LinkedList a -> LinkedList a
Takes the first n elements of this linked list and returns it. Runtime: O(n)
drop
visibility: public
type: Int32 -> LinkedList a -> LinkedList a
Drops the first n elements of this linked list and returns it. Runtime: O(n)
nth
visibility: public
type: Int32 -> LinkedList a -> Option a
Returns some value at index for this linked list if it exists or none. Runtime: O(n)
takeWhile
visibility: public
type: (a -> Boolean) -> LinkedList a -> LinkedList a
Keeps taking elements of this linked list while the predicate holds. Runtime: O(n)
dropWhile
visibility: public
type: (a -> Boolean) -> LinkedList a -> LinkedList a
Keeps removing elements from this linked list while the predicate holds. Runtime: O(n)
isEmpty
visibility: public
type: LinkedList a -> Boolean
Returns true if this linked list is empty. Runtime: O(1)
isNotEmpty
visibility: public
type: LinkedList a -> Boolean
Returns true if this linked list is not empty. Runtime: O(1)
containedLinkedList
visibility: public
type: {{ Equals a }} -> Contained a (LinkedList a)
Returns true if the element is inside this linked list. Runtime: O(n)
map
visibility: public
type: (a -> b) -> LinkedList a -> LinkedList b
Maps function f over all elements of this linked list returning a linked list of the same size. Runtime: O(n)
forEach
visibility: public
type: LinkedList a -> (a -> b) -> Unit
Runs function f for every element of this linked list, ignoring the result. Runtime: O(n)
filter
visibility: public
type: (a -> Boolean) -> LinkedList a -> LinkedList a
Returns a linked list of the elements that match the given predicate. Runtime: O(n)
find
visibility: public
type: (a -> Boolean) -> LinkedList a -> Option a
Returns the first occurrence of elem in this linked list for which the predicate returns true. Runtime: O(n)
flatMap
visibility: public
type: (a -> LinkedList b) -> LinkedList a -> LinkedList b
Like map
but it will flatten the resulting linked list.
Runtime: O(n)
size
visibility: public
type: LinkedList a -> Int32
Returns the size of this linked list. Runtime: O(n)
showLinkedList_
visibility: private
type: Show a -> LinkedList a -> String
showLinkedList
visibility: public
type: {{ Show a }} -> Show (LinkedList a)
eqLinkedList_
visibility: private
type: Equals a -> LinkedList a -> LinkedList a -> Boolean
eqLinkedList
visibility: public
type: {{ Equals a }} -> Equals (LinkedList a)
concatLinkedList_
visibility: private
type: LinkedList a -> LinkedList a -> LinkedList a
concatLinkedList
visibility: public
type: Concat (LinkedList a)
reverse
visibility: public
type: LinkedList a -> LinkedList a
Returns a reversed version of this linked list. Runtime: O(n)
foldl
visibility: public
type: (b -> a -> b) -> b -> LinkedList a -> b
Reduces this linked list to a single value according to the reducing function. Goes from the left to the right. Runtime: O(n)
foldr
visibility: public
type: (a -> b -> b) -> b -> LinkedList a -> b
Reduces this linked list to a single value according to the reducing function. Goes from the right to the left. Runtime: O(n)
flatten
visibility: public
type: LinkedList (LinkedList a) -> LinkedList a
Flattens a linked list of linked lists into a single linked list by concatenating them together. Runtime: O(n)
reduce
visibility: public
type: (a -> a -> a) -> LinkedList a -> Option a
A specialized version of foldl
where the first element of the linked list is used as initial value.
Returns none if the linked list is empty
Runtime: O(n)
rangeTo
visibility: public
type: Int32 -> Int32 -> LinkedList Int32
Returns a linked list in the range from begin (inclusive) to end (exclusive). Runtime: O(n)
fromList
visibility: public
type: List a -> LinkedList a
Creates a linked list with the same elements as the given list. Runtime: O(n)
sortBy
visibility: public
type: (a -> a -> Ordering) -> LinkedList a -> LinkedList a
Sorts this linked list according to the comparing function. Runtime: O(n log(n))
sort
visibility: public
type: {{ Ord a }} -> LinkedList a -> LinkedList a
Sorts this linked list according to the element's Ord instance. Runtime: O(n log(n))