[Proposal] List.delete support for delete multiple fields inside a list

49 views
Skip to first unread message

Randson

unread,
Jun 7, 2022, 11:31:08 AM6/7/22
to elixir-lang-core
Currently, the function `List.delete` only works for a single field. What I want to add is the possibility to delete multiple fields by passing a list of fields I want to remove.

Can be like this one:

```elixir
List.delete([:a, :b, :c, :d, :e], [:a, :b])
#=> [:c, :d, :e]
```

Or, it can be a new function to totally deal with that. like:

```elixir
List.delete_many([:a, :b, :c, :d, :e], [:a, :b])
#=> [:c, :d, :e]
```

What do you guys think about that?

Cheers,
Randson

Andrey Yugai

unread,
Jun 7, 2022, 11:38:15 AM6/7/22
to elixir-l...@googlegroups.com
Hey Randson, have you seen `Enum.filter`? It does almost exactly what you want, except for any enumerable, not just list.








-------- Original Message --------
--

You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.

To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/fdbd07d7-22af-4af8-b5cf-2823727e33ebn%40googlegroups.com.

Randson Oliveira

unread,
Jun 7, 2022, 11:42:02 AM6/7/22
to elixir-l...@googlegroups.com

Nice, thanks for the heads up.

 

Yep, it works exactly the way I want. However, it would be nice to have that pattern matching option. Without having to call the Enum module.

 

But yeah, if you guys think just using `Enum.filter` is enough. I’m okay.

 

Thanks,

Randson

--
You received this message because you are subscribed to a topic in the Google Groups "elixir-lang-core" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elixir-lang-core/AyVo9hhqxlY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/H1mZSgNhjjzBqpJUZA-kQNGcDSJOvNG1ax1Qjhy4DRYUq5HRp793gA2uCewhNXzfeWExVechxk0qTniq5_JquJ-faOnti-lphV8N5cH1iVU%3D%40pm.me.

 

Andrey Yugai

unread,
Jun 7, 2022, 12:02:04 PM6/7/22
to elixir-l...@googlegroups.com
From the top of the head I can think of `Enum/Stream.chunk_every(list, n, 1) |> Enum.filter(...)` to delete matching sequences of length n. Perhaps there's better data structure choice in your particular case.







-------- Original Message --------

On 7 Jun 2022, 18:41, Randson Oliveira < oran...@gmail.com> wrote:

<!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0cm; font-size:11.0pt; font-family:"Calibri",sans-serif;} a:link, span.MsoHyperlink {mso-style-priority:99; color:blue; text-decoration:underline;} .MsoChpDefault {mso-style-type:export-only;} @page WordSection1 {size:612.0pt 792.0pt; margin:72.0pt 72.0pt 72.0pt 72.0pt;} div.WordSection1 {page:WordSection1;} -->
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/408AC7DA-48A9-4AAB-B09D-965F12328479%40hxcore.ol.

Zach Daniel

unread,
Jun 7, 2022, 12:55:58 PM6/7/22
to elixir-l...@googlegroups.com
You wouldn't be able to pattern match on the input being a list regardless because you could have a list of lists and be wanting to delete one of those lists.

For example:
```elixir
List.delete([[:a, :b], [:c, :d]], [:a, :b])
#=> [[:c, :d]]
```

And I generally agree with others that the Enum module is sufficient for this, i.e `Enum.reject([:a, :b, :c, :d, :e], &(&1 in [:a, :b]))` reads pretty clear to me.


--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.

Wojtek Mach

unread,
Jun 7, 2022, 1:30:26 PM6/7/22
to elixir-l...@googlegroups.com
The  --/2 operator already does this. :)

iex(1)> [:a, :b, :c, :d, :e] -- [:a, :b]
[:c, :d, :e]

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.

Zach Daniel

unread,
Jun 7, 2022, 1:31:54 PM6/7/22
to elixir-l...@googlegroups.com
The `--` operator has an important difference in behavior from Enum.filter/reject, though.

[:a, :a, :a] -- [:a]
[:a, :a]


On Tue, Jun 07, 2022 at 1:30 PM, Wojtek Mach <woj...@wojtekmach.pl> wrote:
The  --/2 operator already does this. :)

iex(1)> [:a, :b, :c, :d, :e] -- [:a, :b]
[:c, :d, :e]
On 7 Jun 2022, at 17:31, Randson <orandson@gmail.com> wrote:

Currently, the function `List.delete` only works for a single field. What I want to add is the possibility to delete multiple fields by passing a list of fields I want to remove.

Can be like this one:

```elixir
List.delete([:a, :b, :c, :d, :e], [:a, :b])
#=> [:c, :d, :e]
```

Or, it can be a new function to totally deal with that. like:

```elixir
List.delete_many([:a, :b, :c, :d, :e], [:a, :b])
#=> [:c, :d, :e]
```

What do you guys think about that?

Cheers,
Randson

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/A68DF5BE-1899-4873-98BE-F58319E70150%40wojtekmach.pl.

Reply all
Reply to author
Forward
0 new messages