Function frontOrThrow

Same as frontOr except it throws an error if it can't get the value

auto frontOrThrow(alias makeThrowable, T) (
  auto ref T value
);

auto frontOrThrow(T, U) (
  auto ref T value,
  lazy U throwable
);

Parameters

NameDescription
value the value to resolve
makeThrowable the predicate that creates exception value cannot be resolved
throwable the value to throw if value cannot be resolved

Returns

  • Nullable!T: value.get or throw
  • Optional!T: value.front or throw
  • Range!T: value.front or throw
  • Example

    import std.exception: assertThrown, assertNotThrown;
    
    ""
        .frontOrThrow(new Exception(""))
        .assertThrown!Exception;
    
    auto b = "yo"
        .frontOrThrow(new Exception(""))
        .assertNotThrown!Exception;
    
    assert(b == 'y');