# Standard Library - List Functions

## `len`

``````fn len [any] -> num
``````

### Description

Returns the length of the given list.

### Example

``````print len([1, 2, 3]) # 3
``````

## `push`

``````sub push [any] any
``````

### Description

Adds the given value to the end of the given list.

### Example

``````list = [1, 2, 3]
push list, 4
print list # [1, 2, 3, 4]
``````

## `pop`

``````fn pop [any] -> any
``````

### Description

Removes and returns the last element of the given list.

### Example

``````list = [1, 2, 3]
print pop(list) # 3
print list # [1, 2]
``````

## `shift`

``````fn shift [any] -> any
``````

### Description

Removes and returns the first element of the given list.

### Example

``````list = [1, 2, 3]
print shift(list) # 1
print list # [2, 3]
``````

## `unshift`

``````sub unshift [any] any
``````

### Description

Adds the given value to the beginning of the given list.

### Example

``````list = [1, 2, 3]
unshift list, 0
print list # [0, 1, 2, 3]
``````

## `join`

``````fn join [any], str -> str
``````

### Description

Returns a string containing the elements of the given list joined by the given separator.

### Example

``````print join([1, 2, 3], ", ") # "1, 2, 3"
``````

## `map`

``````fn map [any], (fn any -> any) -> [any]
``````

### Description

Returns a new list containing the results of applying the given function to each element of the given list.

### Example

``````print map([1, 2, 3], lambda x -> x * 2) # [2, 4, 6]
``````

## `map!`

``````sub map! [any], (fn any -> any)
``````

### Description

Applies the given function to each element of the given list.

### Example

``````list = [1, 2, 3]
map! list, lambda x -> x * 2
print list # [2, 4, 6]
``````

## `filter`

``````fn filter [any], (fn any -> bool) -> [any]
``````

### Description

Returns a new list containing the elements of the given list for which the given function returns true.

### Example

``````print filter([1, 2, 3], lambda x -> x % 2 == 0) # 
``````

## `filter!`

``````sub filter! [any], (fn any -> bool)
``````

### Description

Removes all elements from the given list for which the given function returns false.

### Example

``````list = [1, 2, 3]
filter! list, lambda x -> x % 2 == 0
print list # 
``````

## `reduce`

``````fn reduce [any], any, (fn any any -> any) -> any
``````

### Description

Applies the given function to each element of the given list, accumulating the result.

### Example

``````print reduce([1, 2, 3], 0, lambda x y -> x + y) # 6
``````

## `upTo`

``````fn upTo num -> [num]
``````

### Description

Returns a list of numbers from 0 up to the given number.

### Example

``````print upTo(3) # [0, 1, 2, 3]
``````

## `downTo`

``````fn downTo num -> [num]
``````

### Description

Returns a list of numbers from the given number down to 0.

### Example

``````print downTo(3) # [3, 2, 1, 0]
``````