811 B
811 B
| id | name | category | kind | tokens | sig | tip | order | ns | member |
|---|---|---|---|---|---|---|---|---|---|
| list-pop | List.pop | list | namespace-method | List.pop | List.pop(s) -> T | Remove and return the last element. | 5 | List | pop |
Removes the final element of s and returns it, shortening the slice by one. Together with List.push this makes a slice work as a stack: push to add, pop to take the most recent back off. The slice must be non-empty. Use it to unwind a history, process a work list, or undo the last action.
Parameters:
s— a non-empty slice
program UndoStack {
state UndoStackState {
history: []int = new []int
}
handler Undo(undo_stack_st: UndoStackState) phase Update {
if List.len(undo_stack_st.history) > 0 {
let last_action = List.pop(undo_stack_st.history)
}
}
}