frontOrThrow

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

  1. auto frontOrThrow(T value)
    frontOrThrow
    (
    alias makeThrowable
    T
    )
    (
    auto ref T value
    )
  2. auto frontOrThrow(T value, U throwable)

Parameters

value T

the value to resolve

makeThrowable

the predicate that creates exception value cannot be resolved

Return Value

Type: auto
  • Nullable!T: value.get or throw
  • Optional!T: value.front or throw
  • Range!T: value.front or throw
  • Examples

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

    Meta