Basic List Functions Flashcards
head
Takes a list and returns its first element
tail
Takes a list and returns the list after removing the head
init
Takes a list and returns all elements except the last as a list
last
Takes a list and returns the last element
length
returns the length of a given list
null
Checks if the list is empty
reverse
reverses the list
take
Params: a number and a list This function extracts given number of elements from the list. For example, take 2 [1,2,3,4] will return [1,2]
drop
Similar to take, but drops number of elements from the beginning of the list
maximum
takes a list, put it in order and returns the maximum element
minimum
Similar to maximum but returns the minimum element
sum
takes a list of numbers and returns the sum of all elements
product
similar to sum and returns product of all elements
elem
takes a thing and a list and returns if the ‘thing’ is an element of the list
cycle
Takes a list and cycles it into an infinite list.