whats the best way to write short ciruitable reductions?

monkyyy crazymonkyyy at gmail.com
Mon Jan 13 21:48:15 UTC 2025


```d
void issorted(R)(R r){
   foreach(a,b;r.slide(2)){
    if(a>b){return false;}
   }
   return true;
}
```
the first pair of elements to be unsorted make issorted false; 
but my current `reduce` uses `last` which eagerly goes to the end 
of the list

---

I can imagine 3 possible solutions(all ugly) for writing 
"shortablereduce" so it can implement lazier `issorted`; but 
roughly what would others expect? Is there a clean idea someone 
has?


More information about the Digitalmars-d-learn mailing list