Creates a Try range out of an alias to a function that could throw.
Creates a range expression out of a throwing functions
1 import std.algorithm: map, each; 2 3 auto arr = [1, 2, 3]; 4 5 int f(int i) { 6 if (i % 2 == 1) { 7 throw new Exception("NOT EVEN!!!"); 8 } 9 return i; 10 } 11 12 auto result = arr 13 .map!(try_!f) 14 .map!(r => r 15 .match!( 16 (int _) => "even", 17 (Exception _) => "odd" 18 ) 19 ); 20 21 assert(result.equal(["odd", "even", "odd"]));
Functional try