Returns the tail of range augmented with length information
1 // tail -c n 2 assert([1, 2, 3].tail(1) == [3]); 3 assert([1, 2, 3].tail(2) == [2, 3]); 4 assert([1, 2, 3].tail(3) == [1, 2, 3]); 5 assert([1, 2, 3].tail(4) == [1, 2, 3]); 6 assert([1, 2, 3].tail(0).length == 0); 7 8 // tail --lines=n 9 import std.algorithm.comparison : equal; 10 import std.algorithm.iteration : joiner; 11 import std.exception : assumeWontThrow; 12 import std.string : lineSplitter; 13 assert("one\ntwo\nthree" 14 .lineSplitter 15 .tail(2) 16 .joiner("\n") 17 .equal("two\nthree") 18 .assumeWontThrow);
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.