aboutsummaryrefslogtreecommitdiff
path: root/man/man3/tomo-List.pop.3
blob: aabe249d5a5ed1be27b6e90a5d9e1a5146f64bae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'\" t
.\" Copyright (c) 2025 Bruce Hill
.\" All rights reserved.
.\"
.TH List.pop 3 2025-11-29 "Tomo man-pages"
.SH NAME
List.pop \- pop an item from a list
.SH LIBRARY
Tomo Standard Library
.SH SYNOPSIS
.nf
.BI List.pop\ :\ func(list:\ &[T],\ index:\ Int\ =\ -1\ ->\ T?)
.fi
.SH DESCRIPTION
Removes and returns an item from the list. If the given index is present in the list, the item at that index will be removed and the list will become one element shorter.


.SH ARGUMENTS

.TS
allbox;
lb lb lbx lb
l l l l.
Name	Type	Description	Default
list	&[T]	The list to remove an item from. 	-
index	Int	The index from which to remove the item. 	-1
.TE
.SH RETURN
`none` if the list is empty or the given index does not exist in the list, otherwise the item at the given index.

.SH NOTES
Since negative indices are counted from the back, the default behavior is to pop the last value.

.SH EXAMPLES
.EX
list := &[10, 20, 30, 40]

assert list.pop() == 40
assert list[] == [10, 20, 30]

assert list.pop(index=2) == 20
assert list[] == [10, 30]
.EE
.SH SEE ALSO
.BR Tomo-List (3)