Do we have a simple find/remove algorithm?
H. S. Teoh
hsteoh at quickfur.ath.cx
Sat Sep 26 16:20:41 UTC 2020
On Sat, Sep 26, 2020 at 02:00:34PM +0000, Sebastiaan Koppe via Digitalmars-d wrote:
> On Saturday, 26 September 2020 at 12:22:52 UTC, Andrei Alexandrescu wrote:
> > On 9/25/20 11:45 PM, mipri wrote:
> > > This removes two elements however:
> > >
> > > [1,2,3,4,5,3].remove!(x => x==3)
> >
> > Yah, removing all is not too difficult. Removing one is oddly
> > missing. I think we should add a findRemove algorithm. Question is,
> > should it go in iteration.d or mutation.d? :o)
>
> I usually do r.remove(r.countUntil(3)), but its not intuitive.
And also countUntil can return -1, which is invalid input for .remove.
So writing it this way is not safe against corner cases.
T
--
Doubt is a self-fulfilling prophecy.
More information about the Digitalmars-d
mailing list