API Reference › List › List.last
method

List.last

List.last(s) -> T

Returns the final element of s — the value at index List.len(s) - 1. Like List.first, it assumes the slice is non-empty, so guard with a length check when the slice might be empty. Use it to read the most recently pushed item without removing it; use List.pop when you want to take it off.

Parameters

sa non-empty slice

Example

program Trail {
  var points: []int = new []int

  handler Head phase Update {
    if List.len(points) > 0 {
      let newest = List.last(points)
    }
  }
}
← All symbols