ludic/docs/language/list/list-last.md

803 B

id name category kind tokens sig tip order ns member
list-last List.last list namespace-method List.last List.last(s) -> T The last element of a slice. 4 List last

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:

  • s — a non-empty slice
program Trail {
  state TrailState {
    points: []int = new []int
  }

  handler Head(trail_st: TrailState) phase Update {
    if List.len(trail_st.points) > 0 {
      let newest = List.last(trail_st.points)
    }
  }
}