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

804 B

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

Returns element 0 of s — the same as s[0], named for readability. The slice must hold at least one element; calling it on an empty slice reads out of bounds, so guard with List.len(s) > 0 when that is possible. Use it to peek at the head of a queue or the front of an ordered list.

Parameters:

  • s — a non-empty slice
program Queue {
  state QueueState {
    waiting: []int = new []int
  }

  handler Serve(queue_st: QueueState) phase Update {
    if List.len(queue_st.waiting) > 0 {
      let next = List.first(queue_st.waiting)
    }
  }
}