Module ddash.utils.try_
Try utiltity that turns an exception-throwing function in to a ranged result
Example
import std.typecons: tuple;
import std.algorithm: map, each;
import ddash.utils: match;
int f(int i) {
if (i % 2 == 1) {
throw new Exception("NOT EVEN!!!");
}
return i;
}
static if (FeatureFlag.tryUntil) {
assert(tryUntil(f(2), f(4), f(6)).front == tuple(2, 4, 6));
}
auto result = [1, 2, 3]
.map!(a => Try!(() => f(a)))
.map!(r => r
.match!(
(int _) => "even",
(Exception _) => "odd"
)
);
assert(result.equal(["odd", "even", "odd"]));
Functions
Name | Description |
frontOrRethrow(tryInstance, file, line)
|
This the the hook implementation for orElseThrow. The makeThrowable predicate
is given the exception in this Try if there is one, and the result is throw.
Or or the front of the try is returned
|
Try()
|
Creates a Try range out of an alias to a function that could throw.
|
tryUntil(expressions)
|
tryUntil will take a number of lazy expressions and execute them in order
until they all pass or one of them fails
|
Manifest constants
Name | Type | Description |
isTry
|
|
Evaluates to true if T is a Try type
|