Do we have a simple find/remove algorithm?
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Sat Sep 26 12:57:53 UTC 2020
On 9/26/20 8:46 AM, Adam D. Ruppe wrote:
> On Saturday, 26 September 2020 at 12:22:52 UTC, Andrei Alexandrescu wrote:
>> 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)
>
> Something I often end up wanting in this is replace first occurrence,
> and return the remainder.
>
> So I have "abc" and you do replace a with ab, want:
>
> result == "abbc"
> remainder = "bc"
>
> So then I can replace one and keep going without getting stuck in a
> loop. I often do this myself with indexOf and slicing.
>
>
> I guess it might be best to do it with findSplit but it would be cool if
> a findAndReplaceFirst could return the remainder somehow too.
I think it's easy IF findSplit worked with individual elements. On your
code:
auto r = range.findSplit(x);
r[1] = x;
range = r[2];
More information about the Digitalmars-d
mailing list