Removing an element from an array

ag0aep6g anonymous at example.com
Fri Nov 11 09:43:09 UTC 2022


On Friday, 11 November 2022 at 06:10:33 UTC, Alexander Zhirov 
wrote:
> On Friday, 11 November 2022 at 05:36:37 UTC, Alexander Zhirov 
> wrote:
>> On Friday, 11 November 2022 at 00:02:09 UTC, Alexander Zhirov 
>> wrote:
>>>```d
>>>import std.algorithm;
>>>arr = arr.remove(arr.countUntil(fragment));
>>>```
>>
>> And will this method work?
>>
>> ```d
>> A[] arr;
>> A fragment = new A;
>> ...
>> remove(current => current == fragment)(arr);
>> ```
>
> And it will be even more accurate so as not to cause an error:
>
> ```d
> A[] arr;
> A fragment = new A;
> ...
> arr = remove(current => current == fragment)(arr);
> ```

You forgot the exclamation mark. And UFCS allows you to put `arr` 
in front, making it a bit easier on the eyes:

     arr = arr.remove!(current => current == fragment);


More information about the Digitalmars-d-learn mailing list