Why does `filterBidirectional` exist, and why isn't it called `filter`?

jmh530 john.michael.hall at gmail.com
Thu Mar 9 19:18:55 UTC 2023


On Thursday, 9 March 2023 at 17:07:40 UTC, Paul Backus wrote:
> [snip]
>
> I think probably you have to go on a case-by-case basis. 
> `File.byLine`, for example, does not and should not precompute 
> `front`, because doing so is potentially very expensive. OTOH, 
> `iota` does and should precompute `front`, because doing so is 
> essentially free and makes the implementation much simpler.
>
> In general, I think we should err on the side of laziness, 
> because it makes range composition easier. For example, when 
> the user writes something like `chain(a(), b(), c())` or 
> `choose(cond, a(), b())`, they probably do not want to spend 
> unnecessary cycles precomputing `b().front` and `c().front`.

Or, provide the option to allow the user to make the choice at 
compile-time.


More information about the Digitalmars-d mailing list