Module ddash.functional.trybind

Bind a function to a Try

Example

import std.algorithm: map, each;
import ddash.utils: match;

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

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

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

Templates

NameDescription
tryCall Creates a range expression out of a throwing functions