Skip to content

Commit cfc961b

Browse files
authored
Merge pull request #119 from jasalt/master
document peek function returning last item of vector or list
2 parents 3df245c + 132318d commit cfc961b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

content/documentation/data-structures.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ To create a list surround the white space separated values with parentheses or u
1717
'(1 2 3) # use a quote to create a list
1818
```
1919

20-
To access values in a list the functions `get`, `first`, `second`, `next` and `rest` can be used.
20+
To access values in a list the functions `get`, `first`, `second`, `next`, `rest` and `peek` can be used.
2121

2222
```phel
2323
(get (list 1 2 3) 0) # Evaluates to 1
2424
(first (list 1 2 3)) # Evaluates to 1
2525
(second (list 1 2 3)) # Evaluates to 2
26+
(peek (list 1 2 3)) # Evaluates to 3
2627
(next (list 1 2 3)) # Evaluates to (2 3)
2728
(next (list)) # Evaluates to nil
2829
(rest (list 1 2 3)) # Evaluates to (2 3)
@@ -54,12 +55,13 @@ To create a vector wrap the white space seperated values with brackets or use th
5455
(vector 1 2 3) # Creates a new vector with three values
5556
```
5657

57-
To get a value by its index use the `get` function. Similar to list you can use the `first` and `second` function to access the first or second values of the vector.
58+
To get a value by its index use the `get` function. Similar to list you can use the `first`, `second` and `peek` function to access the first, second and last values of the vector.
5859

5960
```phel
6061
(get [1 2 3] 0) # Evaluates to 1
6162
(first [1 2 3]) # Evaluates to 1
6263
(second [1 2 3]) # Evaluates to 2
64+
(peek [1 2 3]) # Evaluates to 3
6365
```
6466

6567
New values can be appended by using the `push` function.

0 commit comments

Comments
 (0)