ddash.range.back

Provides methods for accessing the back of a range

Members

Functions

backOr
auto backOr(Range range, lazy T defaultValue)

Retrieves the back of a range or a default value

maybeBack
auto maybeBack(Range range)

Returns an Optional of the back of range

withBack
auto withBack(Range range)

Takes a unary function that is called on back of range if it is there

Examples

1 import std.algorithm: filter;
2 import std.range: iota, takeNone, array;
3 import optional: some, none;
4 auto evens = 10.iota.filter!"a % 2 == 0".array;
5 assert(evens.withBack!"a" == some(8));
6 assert(evens.takeNone.maybeBack == none);
7 assert(evens.takeNone.backOr(100) == 100);

Meta