Module ddash.functional.try_

Functional try

Example

import std.algorithm: map, each;

int f(int i) {
    if (i % 2 == 1) {
        throw new Exception("NOT EVEN!!!");
    }
    return i;
}

auto result = [1, 2, 3]
    .map!(try_!f)
    .map!(r => r
        .match!(
            (int _) => "even",
            (Exception _) => "odd"
        )
    );

assert(result.equal(["odd", "even", "odd"]));

Structs

NameDescription
Try Creates a Try range out of an alias to a function that could throw.

Templates

NameDescription
match Pass two lambdas to the match function. The first one handles the success case and the second one handles the failure case.
try_ Creates a range expression out of a throwing functions

Manifest constants

NameTypeDescription
isTry Evaluates to true if T is a Try type