TakeLast
TakeLast is a term used in programming to describe an operation that yields the final N elements of a sequence, list, array, or stream while preserving their original order. The function takes a single integer parameter n and returns a collection containing the last n elements. If the source contains fewer than n elements, the entire source is returned.
In finite collections, takeLast can be implemented by indexing or slicing the end of the collection. In
Edge cases include n <= 0, which yields an empty collection, and n >= size, which yields the
Common usage examples illustrate its cross-language presence. In Kotlin, list.takeLast(3) returns the last three elements. In
Related concepts include take, drop, and tail, as well as takeRight in languages that distinguish between end-based