dropBackOne

Convenience function which calls range.popFront() and returns range. dropOne makes it easier to pop an element from a range and then pass it to another function within a single expression, whereas popFront would require multiple statements.

dropBackOne provides the same functionality but instead calls range.popBack().

  1. R dropOne(R range)
  2. R dropBackOne(R range)
    R
    dropBackOne
    (
    R
    )
    ()

Examples

1 import std.algorithm.comparison : equal;
2 import std.algorithm.iteration : filterBidirectional;
3 import std.container.dlist : DList;
4 
5 auto dl = DList!int(9, 1, 2, 3, 9);
6 assert(dl[].dropOne().dropBackOne().equal([1, 2, 3]));
7 
8 auto a = [1, 2, 3];
9 assert(a.dropOne() == [2, 3]);
10 assert(a.dropBackOne() == [1, 2]);
11 
12 string s = "日本語";
13 import std.exception : assumeWontThrow;
14 assert(assumeWontThrow(s.dropOne() == "本語"));
15 assert(assumeWontThrow(s.dropBackOne() == "日本"));
16 
17 auto bd = filterBidirectional!"true"([1, 2, 3]);
18 assert(bd.dropOne().equal([2, 3]));
19 assert(bd.dropBackOne().equal([1, 2]));

Meta

Suggestion Box / Bug Report