Function backOr

Retrieves the back of a range or a default value

auto auto backOr(Range, T) (
  Range range,
  lazy T defaultValue
)
if (isBidirectionalRangeAndElementConvertibleTo!(Range, T));

auto auto backOr(alias defaultFunc, Range) (
  Range range
)
if (isBidirectionalRangeAndElementConvertibleTo!(Range, typeof(defaultFunc())));

Parameters

NameDescription
range the range to get the back of
defaultValue the lazy var to return if the range has no back
defaultFunc function to call that returns a value if there is no back

Since

- 0.0.1

Example

assert((int[]).init.backOr(7) == 7);
assert([1, 2].backOr(3) == 2);