ddash.range.front

Provides methods for accessing the front of a range

Members

Functions

frontOr
auto frontOr(Range range, lazy T defaultValue)

Retrieves the front of a range or a default value

maybeFront
auto maybeFront(Range range)

Returns an Optional of the front of a range

withFront
auto withFront(Range range)

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

Examples

1 import std.algorithm: filter;
2 import std.range: iota, takeNone, drop;
3 import optional: some, none;
4 auto evens = 10.iota.filter!"a % 2 == 0".drop(2);
5 assert(evens.withFront!"a" == some(4));
6 assert(evens.takeNone.maybeFront == none);
7 assert(evens.takeNone.frontOr(100) == 100);

Meta