January 13
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?

January 14

On Monday, 13 January 2025 at 21:48:15 UTC, monkyyy wrote:

>

Is there a clean idea someone has?

There's no state kept after each reduction step; each comparison is done independently of the previous ones. So this really is just a negated 'find' operation, for which you can use all:

bool issorted(R)(R r) => r.slide(2).all!(a => a[0] < a[1]);