The OpenD Programming Language

tail

Return a range advanced to within _n elements of the end of range.

Intended as the range equivalent of the Unix _tail utility. When the length of range is less than or equal to _n, range is returned as-is.

Completes in O(1) steps for ranges that support slicing and have length. Completes in O(range.length) time for all other ranges.

tail
(
Range
)
(
Range range
,
size_t n
)
if (
isInputRange!Range &&
!isInfinite!Range
&&
(
hasLength!Range ||
)
)

Parameters

range Range

range to get tail of

n size_t

maximum number of elements to include in tail

Return Value

Type: auto

Returns the tail of range augmented with length information

Examples

// tail -c n
assert([1, 2, 3].tail(1) == [3]);
assert([1, 2, 3].tail(2) == [2, 3]);
assert([1, 2, 3].tail(3) == [1, 2, 3]);
assert([1, 2, 3].tail(4) == [1, 2, 3]);
assert([1, 2, 3].tail(0).length == 0);

// tail --lines=n
import std.algorithm.comparison : equal;
import std.algorithm.iteration : joiner;
import std.exception : assumeWontThrow;
import std.string : lineSplitter;
assert("one\ntwo\nthree"
    .lineSplitter
    .tail(2)
    .joiner("\n")
    .equal("two\nthree")
    .assumeWontThrow);

Meta