So, I noticed that one way I frequently use the chain function defined std.range is as sort of an else-clause.

ie.

  return elements
      .map!( . . . )
      .filter!( . . . )
      .chain(fallback.only)
      .front;


After transforming and filtering elements, chain would effectively append a fallback element to the resulting range, and then the first element would be taken. Hence if the result of filter (or the initial range) was empty, the result would be fallback.

My concern is that in some cases my fallback is expensive to compute, and acts as a performance sink.

I'm wondering if about the possibility of having a similar function that took a range as a lazy parameter. Specifically, a the parameter would not be evaluated unless one of the resulting range's functions were called. Thoughts?

Reply via email to