List
reverse
(let reverse (fun (_L) (...)))
Reverse a given list and return a new one
Note: The original list is not modified
Author: @SuperFola
Parameter
list: the list to reverse
Example
(list:reverse [1 2 3]) # [3 2 1]
find
(let find (fun (_L _x) (...)))
Search an element in a List
Note: The original list is not modified
Author: @SuperFola
Parameters
list: the List to search invalue: the element to search
Example
(list:find [1 2 3] 1) # 0
(list:find [1 2 3] 0) # -1
slice
(let slice (fun (_L _start _end _step) (...)))
Get a slice from a List
Note: The original list is not modified
Author: @SuperFola
Parameters
list: the list to reversestart: included, must be positiveend: not included, must be positive and smaller than the liststep: must be greater than 0
Example
(list:slice [1 2 3 4 5] 1 4 2) # [2 4]
sort
(let sort (fun (_L) (...)))
Sort a List and return a new one
Note: The original list is not modified
Author: @SuperFola
Parameter
list: the list to sort
Example
(list:sort [4 2 3]) # [1 2 4]
fill
(let fill (fun (_val _count) (...)))
Generate a List of n copies of an element
Author: @SuperFola
Parameters
count: the number of copiesvalue: the element to copy
Example
(list:fill 4 nil) # [nil nil nil nil]
size
(let size (fun (_L) (...)))
Function to call the len operator on a list
Author: @SuperFola
Parameter
_L: list to get the size of
Example
(print (list:size [1 2 3 4])) # 4
setAt
(let setAt (fun (_L _index _x) (...)))
Modify a given list and return a new one
Note: The original list is not modified
Author: @SuperFola
Parameters
list: the list to modifyindex: the index of the element to modifyvalue: the new element
Example
(list:setAt [1 2 3] 0 5) # [5 2 3]
forEach
(let forEach (fun (_L _func) (...)))
Iterate over a given list and run a given function on every element.
Note: The original list is not modified.
Author: @SuperFola
Parameters
_L: the list to iterate over_func: the function to call on each element
Example
(let collection [1 2 5 12])
(list:forEach collection (fun (element) {
(print element) }))
enumerate
(let enumerate (fun (_L _func) (...)))
Iterate over a given list and run a given function on every element, passing its index as well.
Note: The original list is not modified.
Author: @SuperFola
Parameters
_L: the list to iterate over_func: a binary function to call on each element with (index, element)
Example
(let collection [1 2 5 12])
(list:enumerate collection (fun (idx element) {
(print idx " " element) }))
product
(let product (fun (_L) (...)))
Iterate over a given list and multiply all the elements with the others.
Note: The original list is not modified.
Author: @Unactived
Parameter
_L: the list to iterate over
Example
(let collection [1 2 5 12])
(let p (list:product collection)) # => 120
sum
(let sum (fun (_L) (...)))
Iterate over a given list and sum all the elements.
Note: The original list is not modified.
Author: @Unactived
Parameter
_L: the list to iterate over
Example
(let collection [1 2 5 12])
(let p (list:sum collection)) # => 20
min
(let min (fun (_L) (...)))
Find the minimum in a list of numbers
Note: The original list is not modified.
Author: @SuperFola
Parameter
_L: list of numbers
Example
(let value (list:min [0 1 2 3 5 8])) # 0
max
(let max (fun (_L) (...)))
Find the maximum in a list of numbers
Note: The original list is not modified.
Author: @SuperFola
Parameter
_L: list of numbers
Example
(let value (list:max [0 1 2 3 5 8])) # 8
drop
(let drop (fun (_L _n) (...)))
Drop the first n elements of a list
Note: The original list is not modified.
Authors: @rstefanic, @SuperFola
Parameters
_L: the list to work on_n: the number of elements to drop
Example
(let cool-stuff [1 2 3 4 5 6 7 8 9])
(print (list:drop cool-stuff 4)) # [5 6 7 8 9]
dropWhile
(let dropWhile (fun (_L _f) (...)))
Drop the first elements of a list, while they match a given predicate
Note: The original list is not modified.
Author: @SuperFola
Parameters
_L: the list to work on_f: the predicate
Example
(let cool-stuff [1 2 3 4 5 6 7 8 9])
(print (list:dropWhile cool-stuff (fun (a) (< a 4)))) # [4 5 6 7 8 9]
filter
(let filter (fun (_L _f) (...)))
Keep elements in a given list if they follow a predicate
Note: The original list is not modified.
Author: @rstefanic
Parameters
_L: the list to work on_f: the predicate
Example
(import std.Math)
(print (list:filter [1 2 3 4 5 6 7 8 9] math:even?)) # [2 4 6 8]
map
(let map (fun (_L _f) (...)))
Apply a given function to each element of a list
Note: The original list is not modified.
Author: @rstefanic
Parameters
_L: the list to work on_f: the function to apply to each element
Example
(print (list:map [1 2 3 4 5 6 7 8 9] (fun (e) (* e e)))) # [1 4 9 25 36 49 64 81]
reduce
(let reduce (fun (_L _f) (...)))
Apply a function to the elements of a list to reduce it
Note: The original list is not modified.
Author: @Unactived
Parameters
_L: the list to work on_f: the function to apply
Example
(let cool [1 2 3 4 5 6 7 8 9])
(print (list:reduce cool (fun (a b) (+ a b)))) # 45
flatten
(let flatten (fun (_L) (...)))
Flatten a list
Note: The original list is not modified.
Author: @SuperFola
Parameter
_L: the list to work on
Example
(let cool [[1 2 3] [4] 5 6 [7 8] 9])
(print (list:flatten cool)) # [1 2 3 4 5 6 7 8 9]
flatMap
(let flatMap (fun (_L _f) (...)))
Apply a given function to each element of a list and then flatten it
Note: The original list is not modified.
Author: @SuperFola
Parameters
_L: the list to work on_f: the function to apply to each element
Example
(let cool [1 2 3 4])
(print (list:flatMap cool (fun (a) [a a]))) # [1 1 2 2 3 3 4 4]
take
(let take (fun (_L _n) (...)))
Take the first n elements of
Note: The original list is not modified.
Author: @rstefanic
Parameters
_L: the list to work on_n: the number of elements to take
Example
(print (list:take [1 2 3 4 5 6 7 8 9] 4)) # [1 2 3 4]
takeWhile
(let takeWhile (fun (_L _f) (...)))
Take the first n elements of a list, given a predicate
Note: The original list is not modified.
Author: @rakista112
Parameters
_L: the list to work on_f: the predicate
Example
(print (list:takeWhile [1 2 3 4 5 6 7 8 9 10] (fun (a) (< a 4)))) # [1 2 3]
partition
(let partition (fun (_L _f) (...)))
Partition a list in two, given a predicate
Note: The original list is not modified.
Author: @rakista112
Parameters
_L: the list to work on_f: the predicate, accepting the value and its index
Example
(let a [1 2 3])
(print (list:partition a (fun (c i) (= 0 (mod c 2))))) # [[2] [1 3]]
unzip
(let unzip (fun (_L) (...)))
Unzip a list of [[a b] [c d]…] into [[a c …] [b d …]]
Note: The original list is not modified.
Author: @Unactived
Parameter
_L: the list to work on
Example
(let zipped [[1 5] [2 6] [3 7] [4 8]])
(print (list:unzip zipped)) # [[1 2 3 4] [5 6 7 8]]
zip
(let zip (fun (_a _b) (...)))
Zip two lists into one: [1 2 3 4] and [5 6 7 8] will give [[1 5] [2 6] [3 7] [4 8]]
Note: The original lists are not modified.
Author: @Unactived
Parameters
_a: the first list to work on_b: the second list to work on
Example
(let a [1 2 3 4])
(let b [5 6 7 8])
(print (list:zip a b)) # [[1 5] [2 6] [3 7] [4 8]]
zipWithIndex
(let zipWithIndex (fun (_L) (...)))
Zip a list elements with their index. [5 6 7 8] will give [[0 5] [1 6] [2 7] [3 8]]
Note: The original list is not modified.
Author: @SuperFola
Parameter
_L: the list to iterate over
Example
(let a [5 6 7 8])
(print (list:zipWithIndex a)) # [[0 5] [1 6] [2 7] [3 8]]
foldLeft
(let foldLeft (fun (_L _init _f) (...)))
Fold a given list, starting from the left side
Note: The original list is not modified.
Author: @SuperFola
Parameters
_L: the list to work on_init: an init value_f: a function to apply to the list
Example
(let a [1 2 3 4])
(print (list:foldLeft a 0 (fun (a b) (+ a b)))) # 10
forAll
(let forAll (fun (_L _f) (...)))
Check if a condition is verified for all elements of a list
Author: @Gryfenfer97
Parameters
_L: the list to work on_f: the condition
Example
(let a [1 2 3 4])
(let f (fun (e) (< e 5)))
(print (list:forAll a f)) # true
any
(let any (fun (_L _f) (...)))
Check if a condition if verified for one or more elements of a list
Author: @Gryfenfer97
Parameters
_L: the list to work on_f: the condition
Example
(let a [1 2 3 4])
(let f (fun (e) (< e 3)))
(print (list:any a f)) # true
none
(let none (fun (_L _f) (...)))
Check if a condition can’t be verified for any element of a list
Author: @SuperFola
Parameters
_L: the list to work on_f: the condition
Example
(let a [1 2 3 4])
(let f (fun (e) (< e 3)))
(print (list:none a f)) # false
(print (list:none [4 5 6] f)) # true
countIf
(let countIf (fun (_L _f) (...)))
Count the number of elements in a list that match a condition
Author: @SuperFola
Parameters
_L: the list to work on_f: the condition
Example
(let lst [1 2 3 4 5 6 7 8 9])
(let is_even (fun (e) (= 0 (mod e 2))))
(print (list:countIf lst is_even)) # 4
iterate
(let iterate (fun (_init _f _length) (...)))
Generate a sequence based on a unary function, initial value and length
Author: @SuperFola
Parameters
_init: initial value of the sequence_f: unary function to generate values_length: the sequence length
Example
(let f (fun (x) (+ 7 x)))
(print (list:iterate 0 f 10)) # [0 7 14 21 28 35 42 49 56 63]
iota
(let iota (fun (_init _length) (...)))
Generate a sequence of numbers
Author: @SuperFola
Parameters
_init: initial value of the sequence_length: the sequence length
Example
(print (list:iota 0 10)) # [0 1 2 3 4 5 6 7 8 9]
chunkBy
(let chunkBy (fun (_L _length) (...)))
Chunk a list in sub-lists of size n
Author: @SuperFola
Parameters
_L: list to chunk_length: size of the chunks
Example
(let indices (list:iota 1 9)) # [1 2 3 4 5 6 7 8 9]
(print (list:chunkBy indices 3)) # [[1 2 3] [4 5 6] [7 8 9]]
insert
(let insert (fun (_L _index _value) (...)))
Insert an element (or expand a list) at a given position inside a list
Note: The original list is not modified
Author: @SuperFola
Parameters
_L: list to insert element(s) in_index: where to insert_value: value to insert
Example
(let a [0])
(print (list:insert a 1 4)) # [0 4]
(print (list:insert a 1 [1 2])) # [0 1 2]
(let b [0 9])
(print (list:insert b 1 4)) # [0 4 9]
(print (list:insert b 1 [1 2])) # [0 1 2 9]
window
(let window (fun (_L _size _f) (...)))
Create a sliding window of a given size on a list
Note: The original list is not modified
Author: @SuperFola
Parameters
_L: list to iterate over_size: window size, must be at least 1_f: function to call with the window
Example
(let f (fun (lst) (print lst))
(list:window [1 2 3 4 5] 3 f)
# [1 2 3]
# [2 3 4]
# [3 4 5]