Novah Documentation

novah.list

Functions to work with persistent lists. They can also be used as queues or stacks. Literal lists can be created using [].

Types

Declarations


stream

visibility: public
type: List a -> Stream a

Returns a stream for this list.


fromStream

visibility: public
type: Stream a -> List a

Collects this stream into a list. Runtime: O(n)


forEach

visibility: public
type: List a -> (a -> Unit) -> Unit

Runs function f for every element of this list, ignoring the result. Runtime: O(n)


forEachIndexed

visibility: public
type: List a -> (Int32 -> a -> Unit) -> Unit

Runs function f for every index and element of this list, ignoring the result. Runtime: O(n)


map

visibility: public
type: (a -> b) -> List a -> List b

Maps function f over all elements of this list returning a list of the same size. Runtime: O(n)


mapIndexed

visibility: public
type: (Int32 -> a -> b) -> List a -> List b

Maps function f over all elements of this list returning a list of the same size. Also receives the index of the element as a parameter. Runtime: O(n)


mapSome

visibility: public
type: (a -> Option b) -> List a -> List b

Maps a function over a list and returns only the non-empty values. Runtime: O(n)


nth

visibility: public
type: Int32 -> List a -> Option a

Returns some value at index for this list if it exists or none. This is a safe version of the index operator: list.[index]. Runtime: ~O(1)


size

visibility: public
type: List a -> Int32

Returns the size of this list. Runtime: O(1)


lastIndex

visibility: public
type: List a -> Int32

Returns the index of the last element of this list or -1 if the list is empty. Runtime: O(1)


first

visibility: public
type: List a -> Option a

Returns the first element of this list if it's not empty. Runtime: ~O(1)


last

visibility: public
type: List a -> Option a

Returns the last element of this list if it's not empty. Runtime: ~O(1)


isEmpty

visibility: public
type: List a -> Boolean

Returns true if this list is empty. Runtime: O(1)


isNotEmpty

visibility: public
type: List a -> Boolean

Returns true if this list is not empty. Runtime: O(1)


randNth

visibility: public
type: List a -> Option a

Returns a random element of this list if the list is not empty. Runtime: O(1)


shuffle

visibility: public
type: List a -> List a

Returns a list with the same values as the input list in random order. Runtime: O(n)


toTypedArray

visibility: public
type: Class a -> List a -> Array a

Converts this list into a typed array. Runtime: O(n)


toArray

visibility: public
type: List a -> Array Object

Converts this list into an object array. Runtime: O(n)


fromArray

visibility: public
type: Array a -> List a

Converts this array into a list. Runtime: O(n)


filter

visibility: public
type: (a -> Boolean) -> List a -> List a

Returns a list of the elements that match the given predicate. Runtime: O(n)


filterIndexed

visibility: public
type: (Int32 -> a -> Boolean) -> List a -> List a

Returns a list of the elements that match the given predicate. Also receives the index of the list as parameter. Runtime: O(n)


remove

visibility: public
type: (a -> Boolean) -> List a -> List a

Returns a list of the elements that do not match the given predicate. Does the opposite of filter. Runtime: O(n)


removeIndexed

visibility: public
type: (Int32 -> a -> Boolean) -> List a -> List a

Returns a list of the elements that does not match the given predicate. Also receives the index of the list as parameter. Runtime: O(n)


find

visibility: public
type: (a -> Boolean) -> List a -> Option a

Returns the first occurrence of elem in this list for which the predicate returns true. Runtime: O(n)


findIndex

visibility: public
type: (a -> Boolean) -> List a -> Option Int32

Returns the first index in this list for which the predicate returns true. Runtime: O(n)


sortWith

visibility: public
type: (a -> a -> Ordering) -> List a -> List a

Sorts this list according to the comparing function.


sort

visibility: public
type: {{ Ord a }} -> List a -> List a

Sorts this list according to the element's Ord instance.


sortBy

visibility: public
type: {{ Ord b }} -> (a -> b) -> List a -> List a

Sorts this list based on the natural sort order of the values returned by the function.


push

visibility: public
type: a -> List a -> List a

An alias to addFirst. Should be used when using this list as a stack. Runtime: ~O(1)


pop

visibility: public
type: List a -> List a

An alias to removeFirst. Should be used when using this list as a stack. Runtime: ~O(1)


tail

visibility: public
type: List a -> Option (List a)

Returns the tail of this list if it's not empty. Runtime: ~O(1)


slice

visibility: public
type: Int32 -> Int32 -> List a -> List a

Returns a slice of this list starting at from (inclusive) and ending at to (exclusive). Runtime: ~O(1)


splitIndex

visibility: public
type: Int32 -> List a -> Tuple (List a) (List a)

Splits this list into elements before the index and elements after the index. Runtime: ~O(1)


split

visibility: public
type: {{ Equals a }} -> a -> List a -> Tuple (List a) (List a)

Splits this list into elements before the given element and elements after it. Considers only the first occurence of the element. Runtime: O(n)


take

visibility: public
type: Int32 -> List a -> List a

Returns the first n elements of this list. Runtime: ~O(1)


drop

visibility: public
type: Int32 -> List a -> List a

Returns this list without the first n elements. Runtime: ~O(1)


takeWhile

visibility: public
type: (a -> Boolean) -> List a -> List a

Keeps taking elements of this list while the predicate holds. Runtime: O(n)


dropWhile

visibility: public
type: (a -> Boolean) -> List a -> List a

Keeps droping elements from this list while the predicate holds. Runtime: O(n)


foldl

visibility: public
type: (b -> a -> b) -> b -> List a -> b

Reduces this list to a single value according to the reducing function. Goes from the left to the right. Runtime: O(n)


reduce

visibility: public
type: (a -> a -> a) -> List a -> Option a

A specialized version of foldl where the first element of the list is used as initial value. Returns none if the list is empty Runtime: O(n)


foldr

visibility: public
type: (a -> b -> b) -> b -> List a -> b

Reduces this list to a single value according to the reducing function. Goes from the right to the left. Runtime: O(n)


flatten

visibility: public
type: List (List a) -> List a

Flattens a list of lists into a single list by concatenating them together. Runtime: O(n)


flatMap

visibility: public
type: (a -> List b) -> List a -> List b

Like map, but the mapping function should return a list. Flattens the result. Runtime: O(n)


reverse

visibility: public
type: List a -> List a

Returns a reversed version of this list. Runtime: O(n)


all

visibility: public
type: (a -> Boolean) -> List a -> Boolean

Returns true if the predicate is true for all elements in this list. Runtime: O(n)


any

visibility: public
type: (a -> Boolean) -> List a -> Boolean

Returns true if the predicate is true for any element in this list. Runtime: O(n)


count

visibility: public
type: (a -> Boolean) -> List a -> Int32

Returns the number of elements matching the given predicate. Runtime: O(n)


min

visibility: public
type: {{ NumberOps a }} -> List a -> Option a

Returns the smallest number in the list, if the list is not empty. Runtime: O(n)


minOr

visibility: public
type: {{ NumberOps a }} -> a -> List a -> a

Returns the smallest number in the list, or the default value. Runtime: O(n)


minBy

visibility: public
type: {{ Ord b }} -> (a -> b) -> List a -> Option a

Returns the smallest element in the list according to the given function, if the list is not empty. Runtime: O(n)


minOf

visibility: public
type: {{ NumberOps b }} -> (a -> b) -> List a -> Option b

Returns the smallest element returned by applying the function to every element in the list, if the list is not empty. Runtime: O(n)


max

visibility: public
type: {{ NumberOps a }} -> List a -> Option a

Returns the biggest number in the list, if the list is not empty. Runtime: O(n)


maxOr

visibility: public
type: {{ NumberOps a }} -> a -> List a -> a

Returns the biggest number in the list, or the default value. Runtime: O(n)


maxBy

visibility: public
type: {{ Ord b }} -> (a -> b) -> List a -> Option a

Returns the biggest element in the list according to the given function, if the list is not empty. Runtime: O(n)


maxOf

visibility: public
type: {{ NumberOps b }} -> (a -> b) -> List a -> Option b

Returns the biggest element returned by applying the function to every element in the list, if the list is not empty. Runtime: O(n)


sum

visibility: public
type: {{ Plus a }} -> List a -> a

Returns the sum of all elements in this list. Runtime: O(n)


sumOf

visibility: public
type: {{ Plus b }} -> (a -> b) -> List a -> b

Returns the sum of all elements by first applying the function to every element in this list. Runtime: O(n)


product

visibility: public
type: {{ Mult a }} -> List a -> a

Returns the product of all elements in this list. Runtime: O(n)


productOf

visibility: public
type: {{ Mult b }} -> (a -> b) -> List a -> b

Returns the product of all elements by first applying the function to every element in this list. Runtime: O(n)


fromByteArray

visibility: public
type: ByteArray -> List Byte

Converts this byte array to a list of bytes. Runtime: O(n)


fromInt16Array

visibility: public
type: Int16Array -> List Int16

Converts this int16 array to a list of int16s. Runtime: O(n)


fromInt32Array

visibility: public
type: Int32Array -> List Int32

Converts this int array to a list of ints. Runtime: O(n)


fromInt64Array

visibility: public
type: Int64Array -> List Int64

Converts this int64 array to a list of int64s. Runtime: O(n)


fromFloat32Array

visibility: public
type: Float32Array -> List Float32

Converts this float32 array to a list of float32s. Runtime: O(n)


fromFloat64Array

visibility: public
type: Float64Array -> List Float64

Converts this float64 array to a list of float64s. Runtime: O(n)


fromBooleanArray

visibility: public
type: BooleanArray -> List Boolean

Converts this boolean array to a list of booleans. Runtime: O(n)


fromCharArray

visibility: public
type: CharArray -> List Char

Converts this char array to a list of chars. Runtime: O(n)


toByteArray

visibility: public
type: List Byte -> ByteArray

Converts this list of bytes to a byte array. Runtime: O(n)


toInt16Array

visibility: public
type: List Int16 -> Int16Array

Converts this list of int16s to a int16 array. Runtime: O(n)


toInt32Array

visibility: public
type: List Int32 -> Int32Array

Converts this list of ints to a int array. Runtime: O(n)


toInt64Array

visibility: public
type: List Int64 -> Int64Array

Converts this list of int64s to a int64 array. Runtime: O(n)


toFloat32Array

visibility: public
type: List Float32 -> Float32Array

Converts this list of float32s to a float32 array. Runtime: O(n)


toFloat64Array

visibility: public
type: List Float64 -> Float64Array

Converts this list of float64s to a float64 array. Runtime: O(n)


toBooleanArray

visibility: public
type: List Boolean -> BooleanArray

Converts this list of booleans to a boolean array. Runtime: O(n)


toCharArray

visibility: public
type: List Char -> CharArray

Converts this list of chars to a char array. Runtime: O(n)


groupBy

visibility: public
type: (a -> b) -> List a -> Map b (List a)

Groups the elements of the list according to the the function. Ex:

groupBy isOdd [1, 2, 3, 4, 5, 6]
// => { true: [1, 3, 5], false: [2, 4, 6] }

partitionStep

visibility: public
type: Int32 -> Int32 -> List a -> List (List a)

Returns the list partitioned in lists of size n and going forward by step. Ex:

partitionStep 3L 2L [1, 2, 3, 4, 5, 6, 7, 8]
// => [[1, 2, 3], [3, 4, 5], [5, 6, 7]]

partitionAllStep

visibility: public
type: Int32 -> Int32 -> List a -> List (List a)

Returns the list partitioned in lists of size n and going forward by step. May include sub lists smaller than n if there's some leftovers. Ex:

partitionAllStep 3L 2L [1, 2, 3, 4, 5, 6, 7, 8]
// => [[1, 2, 3], [3, 4, 5], [5, 6, 7], [7, 8]]

partition

visibility: public
type: Int32 -> List a -> List (List a)

Returns the list partitioned in lists of size n. Ex:

partition 3L [1, 2, 3, 4, 5, 6, 7, 8]
// => [[1, 2, 3], [4, 5, 6]]

partitionAll

visibility: public
type: Int32 -> List a -> List (List a)

Returns the list partitioned in lists of size n. May include sub lists smaller than n if there's some leftovers. Ex:

partitionAll 3L [1, 2, 3, 4, 5, 6, 7, 8]
// => [[1, 2, 3], [4, 5, 6], [7, 8]]

repeat

visibility: public
type: Int32 -> a -> List a

Returns a list consisting of the given element repeated n times. Runtime: O(n)


indices

visibility: public
type: List a -> List Int32

Returns a list of all the indices from the input list. Ex:

indices ["a", "b", "c"] // => [0, 1, 2]

zip

visibility: public
type: List a -> List b -> List (Tuple a b)

Zips the two lists together. The resulting list will be as big as the smallest one. Ex:

zip [1, 2, 3, 4, 5] ["a", "b", "c"]
// => [1 ; "a", 2 ; "b", 3 ; "c"]

Runtime: O(n)


zipWith

visibility: public
type: (a -> b -> c) -> List a -> List b -> List c

Zips the two lists together according to the function. The resulting list will be as big as the smallest one. Ex:

zipWith (+) [1, 2, 3, 4, 5] [10, 11, 12]
// => [11, 13, 15]

Runtime: O(n)


zipAll

visibility: public
type: List (List a) -> List (List a)

Zips all lists together. The resulting list will as big as the smallest sub list. Ex:

zipAll [[1, 2, 3], [4, 5], [6, 7, 8]]
// => [[1, 4, 6], [2, 5, 7]]

Runtime: O(n*m)


unzip

visibility: public
type: List (Tuple a b) -> Tuple (List a) (List b)

Unzips a list into two lists. The opposite of zip. Ex:

unzip [1 ; "a", 2 ; "b", 3 ; "c"]
// => [1, 2, 3, 4, 5] ; ["a", "b", "c"]

Runtime: O(n)


removeNones

visibility: public
type: List (Option a) -> List a

Removes all empty options from the list. Runtime: O(n)


toLinear

visibility: public
type: List a -> LinearList a

Returns a linear (mutable) list out of this list


withLinear

visibility: public
type: List a -> (List a -> b) -> List a

Creates a linear (mutable) version of the given list and applies the function to it. Returns a forked (persistent) version of the returned linear list. This function should be used when lots of expensive mutating operations have to be run on a list and can be seen as a builder for the resulting list. All functions that alter lists like addFirst, setAt, removeLast, etc. will mutate a linear list. Ex: withLinear [1, 2, 3] \list -> addFirst 0 list addLast 4 list

-> [0, 1, 2, 3, 4]