List
reverse
(let reverse (fun (_L) (...)))
Reverse a given list and return a new one
Note: The original list is not modified
Parameter
list
: the list to reverse
Author
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
Parameters
list
: the List to search invalue
: the element to search
Author
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
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
Author
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
Parameter
list
: the list to sort
Author
Example
(list:sort [4 2 3]) # [1 2 4]
fill
(let fill (fun (_val _count) (...)))
Generate a List of n copies of an element
Parameters
count
: the number of copiesvalue
: the element to copy
Author
Example
(list:fill 4 nil) # [nil nil nil nil]
setAt
(let setAt (fun (_L _index _x) (...)))
Modify a given list and return a new one
Note: The original list is not modified
Parameters
list
: the list to modifyindex
: the index of the element to modifyvalue
: the new element
Author
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 left unmodified.
Parameters
_L
: the list to iterate over_func
: the function to call on each element
Author
Example
(import std.List)
(let collection [1 2 5 12])
(forEach collection (fun (element) {
(print element)
}))
product
(let product (fun (_L) (...)))
Iterate over a given list and multiply all the elements with the others.
Note: The original list is left unmodified.
Parameter
_L
: the list to iterate over
Author
Example
(import std.List)
(let collection [1 2 5 12])
(let p (product collection)) # => 120
sum
(let sum (fun (_L) (...)))
Iterate over a given list and sum all the elements.
Note: The original list is left unmodified.
Parameter
_L
: the list to iterate over
Author
Example
(import std.List)
(let collection [1 2 5 12])
(let p (sum collection)) # => 20
drop
(let drop (fun (_L _n) (...)))
Drop the first n elements of a list
Note: The original list is left unmodified.
Parameters
_L
: the list to work on_n
: the number of elements to drop
Authors
Example
(let cool-stuff [1 2 3 4 5 6 7 8 9])
(print (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 left unmodified.
Parameters
_L
: the list to work on_f
: the predicate
Author
Example
(let cool-stuff [1 2 3 4 5 6 7 8 9])
(print (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 left unmodified.
Parameters
_L
: the list to work on_f
: the predicate
Author
Example
(import std.Math)
(print (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 left unmodified.
Parameters
_L
: the list to work on_f
: the function to apply to each element
Author
Example
(print (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 left unmodified.
Parameters
_L
: the list to work on_f
: the function to apply
Author
Example
(let cool [1 2 3 4 5 6 7 8 9])
(print (reduce cool (fun (a b) (+ a b)))) # 45
flatten
(let flatten (fun (_L) (...)))
Flatten a list
Note: The original list is left unmodified.
Parameter
_L
: the list to work on
Author
Example
(let cool [[1 2 3] [4] 5 6 [7 8] 9])
(print (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 left unmodified.
Parameters
_L
: the list to work on_f
: the function to apply to each element
Author
Example
(let cool [1 2 3 4])
(print (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 left unmodified.
Parameters
_L
: the list to work on_n
: the number of elements to take
Author
Example
(print (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 left unmodified.
Parameters
_L
: the list to work on_f
: the predicate
Author
Example
(print (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 left unmodified.
Parameters
_L
: the list to work on_f
: the predicate, accepting the value and its index
Author
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 left unmodified.
Parameter
_L
: the list to work on
Author
Example
(let zipped [[1 5] [2 6] [3 7] [4 8]])
(print (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 left unmodified.
Parameters
_a
: the first list to work on_b
: the second list to work on
Author
Example
(let a [1 2 3 4])
(let b [5 6 7 8])
(print (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 left unmodified.
Parameter
_L
: the list to iterate over
Author
Example
(let a [5 6 7 8])
(print (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 left unmodified.
Parameters
_L
: the list to work on_init
: an init value_f
: a function to apply to the list
Author
Example
(let a [1 2 3 4])
(print (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
Parameters
_L
: the list to work on_f
: the conditon
Author
Example
(let a [1 2 3 4])
(let f (fun (e) (< e 5)))
(print (forAll a f)) # true
any
(let any (fun (_L _f) (...)))
Check if a condition if verified for one or more elements of a list
Parameters
_L
: the list to work on_f
: the condition
Author
Example
(let a [1 2 3 4])
(let f (fun (e) (< e 3)))
(print (any a f)) # true
countIf
(let countIf (fun (_L _f) (...)))
Count the number of elements in a list that match a condition
Parameters
_L
: the list to work on_f
: the condition
Author
Example
(let lst [1 2 3 4 5 6 7 8 9])
(let is_even (fun (e) (= 0 (mod e 2))))
(print (countIf lst is_even)) # 4
iterate
(let iterate (fun (_init _f _length) (...)))
Generate a sequence based on a unary function, initial value and length
Parameters
_init
: initial value of the sequence_f
: unary function to generate values_length
: the sequence length
Author
Example
(let f (fun (x) (+ 7 x)))
(print (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
Parameters
_init
: initial value of the sequence_length
: the sequence length
Author
Example
(print (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
Parameters
_L
: list to chunk_length
: size of the chunks
Author
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: Original list is left unmodified
Parameters
_L
: list to insert element(s) in_index
: where to insert_value
: value to insert
Author
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]