frontOrThrow

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

  1. auto frontOrThrow(T value)
  2. auto frontOrThrow(T value, U throwable)
    frontOrThrow
    (
    T
    U : Throwable
    )
    (
    auto ref T value
    ,
    lazy U throwable
    )

Parameters

value T

the value to resolve

throwable U

the value to throw if 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