Return explicitly "empty" MapResult (fail-fast)

monkyyy crazymonkyyy at gmail.com
Thu Jan 1 19:21:04 UTC 2026


On Thursday, 1 January 2026 at 19:06:44 UTC, monkyyy wrote:
> 
>

also worth considering if you abuse the range api:

```d
import std;
template innate(T,int line){
	T innate;
}
auto panicswitch(int line=__LINE__,R)(R r){
	struct panicable{
		R r;
		auto front()=>r.front;
		void popFront(){r.popFront;}
		auto empty()=>innate!(bool,line) || r.empty;
		bool* getbutton()=>&innate!(bool,line);
	}
	innate!(bool,line)=false;
	return panicable(r);
}
unittest{
	auto r=iota(10)
		.map!(a=>a*2)
		.filter!(a=>a%3)
		.panicswitch;
	auto panic=r.getbutton;
	foreach(e;r){
		if(e>5){
			*panic=true;
		}
		e.writeln;
	}
}
```


More information about the Digitalmars-d-learn mailing list