maybeBack

Returns an Optional of the back of range

maybeBack
(
Range
)
(
Range range
)
if (
from!"std.range".isBidirectionalRange!Range
)

Examples

assert((int[]).init.maybeBack.empty == true);
assert([1, 2].maybeBack.front == 2);
1 import std.algorithm: filter;
2 import optional: some, none, dispatch;
3 struct A {
4     int x;
5     int f() {
6         return x;
7     }
8 }
9 
10 assert((A[]).init.maybeBack.dispatch.f == none);
11 assert([A(3), A(5)].maybeBack.dispatch.f == some(5));

Meta

Since

- 0.0.1