Navigating tradeoffs in bidirectional filter design
monkyyy
crazymonkyyy at gmail.com
Fri Jan 10 03:16:51 UTC 2025
On Friday, 10 January 2025 at 02:47:24 UTC, Salih Dincer wrote:
> On Thursday, 9 January 2025 at 21:56:59 UTC, monkyyy wrote:
>> Im aware phoboes takes ....more complexity to implement filter
>> and there should be *some* extra complexity to make a
>> bidirectional filter, but when I ussally look into phoboes
>> 1000 line functions I usually make different tradeoffs. What
>> are the actual considerations here?
>
> I don't really understand, what needs to be considerations?
> Isn't the interface below sufficient?
>
> ```d
> auto filter(alias F,R)(R r)
> {
> struct Filter
> {
> R r;
> auto back() => r.back;
> auto front() => r.front;
> auto popFront() => r = r.findNext!F;
> auto popBack() => r = r.findPrevious!F;
> auto empty() => r.empty;
> auto save() => r.save;
> }
> return Filter(r.find!F);
> }
> ```
>
> SDB at 79
Well:
1) `[1,2,3,4,5].Filter!(a=>a==3).back` should equal 3, in yours
it will equal 5
2) your no longer supporting unidirectional ranges
And that only what I notice without any testing; I feel worse
about being eager for back then front
More information about the Digitalmars-d-learn
mailing list