Function maybeBack

Returns an Optional of the back of range

auto auto maybeBack(Range) (
  Range range
)
if (from.std.range.isBidirectionalRange!Range);

Since

- 0.0.1

Example

assert((int[]).init.maybeBack.empty == true);
assert([1, 2].maybeBack.front == 2);

Example

import std.algorithm: filter;
import ddash.utils.optional: some, none, oc;
struct A {
    int x;
    int f() {
        return x;
    }
}

assert((A[]).init.maybeBack.oc.f == none);
assert([A(3), A(5)].maybeBack.oc.f == some(5));