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

Monkyyy crazymonkyyy at gmail.com
Thu Mar 9 18:46:55 UTC 2023


On Thursday, 9 March 2023 at 17:07:40 UTC, Paul Backus wrote:
> On Thursday, 9 March 2023 at 13:16:07 UTC, Steven Schveighoffer 
> wrote:
>> [...]
>
> 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`.

In general if someone would want to precompute a range shouldnt 
front just be a varible?


More information about the Digitalmars-d mailing list