[Feature] Add #except to Array

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

[Feature] Add #except to Array

Alex Golubenko
Hi guys!

Time to time I meet questions on SO about how to take elements from array avoid some indexes.

I think it might be helpful for many developers to have something like `Hash#except` but for `Array`.

I would like to add PR with it if someone interested in it.

Thanks in advance for any thoughts about this idea.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/479e2902-3cb1-4bb3-9347-5aeefe27379d%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Feature] Add #except to Array

Josh Brody
Would this alias Array#excluding? I think the Array#except is natural and I’ve found myself asking why it’s not aliased already many times but I’m not the one to ask. 🙂

Sent from my iPhone

On Feb 25, 2020, at 10:21 PM, Alex Golubenko <[hidden email]> wrote:


Hi guys!

Time to time I meet questions on SO about how to take elements from array avoid some indexes.

I think it might be helpful for many developers to have something like `Hash#except` but for `Array`.

I would like to add PR with it if someone interested in it.

Thanks in advance for any thoughts about this idea.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/479e2902-3cb1-4bb3-9347-5aeefe27379d%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/CAECA2F2-A2E4-4AD1-842B-1FCB9331CB78%40josh.mn.
Reply | Threaded
Open this post in threaded view
|

Re: [Feature] Add #except to Array

Alex Golubenko
It wouldn't be alias 😅
The main idea is to implement method which we can use to exclude elements from array by their indexes.

For example: 
%w( a b c d e f).except(0, -1) 
=> ['b', 'c', 'd', 'e']

ср, 26 февр. 2020 г., 06:34 Josh Brody <[hidden email]>:
Would this alias Array#excluding? I think the Array#except is natural and I’ve found myself asking why it’s not aliased already many times but I’m not the one to ask. 🙂

Sent from my iPhone

On Feb 25, 2020, at 10:21 PM, Alex Golubenko <[hidden email]> wrote:


Hi guys!

Time to time I meet questions on SO about how to take elements from array avoid some indexes.

I think it might be helpful for many developers to have something like `Hash#except` but for `Array`.

I would like to add PR with it if someone interested in it.

Thanks in advance for any thoughts about this idea.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/479e2902-3cb1-4bb3-9347-5aeefe27379d%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/CAECA2F2-A2E4-4AD1-842B-1FCB9331CB78%40josh.mn.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/CAAYv6Fxj538iTWUX%3DMOHkdK0fwswc6kFOxGKsC%2Bd_%2B9UOFMLzQ%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Feature] Add #except to Array

Nicholas Schwaderer
Nice suggestion! :) 

I see how it would replicate the Hash#except syntax as seen here: https://apidock.com/rails/Hash/except

However, could this be confusing for those who don't anticipate the index stripping behavior but more of a reject/excluding behavior?

i.e.:

```
%w( 1 5 6 8 0 9 0 ).except(0)
#=> [5,6,8,0,9,0]
```

Would it be better to explicitly add the index to the name such as `#except_index` or more verbose `#except_with_index` ? 



On Wednesday, February 26, 2020 at 8:49:07 AM UTC, Alex Golubenko wrote:
It wouldn't be alias 😅
The main idea is to implement method which we can use to exclude elements from array by their indexes.

For example: 
%w( a b c d e f).except(0, -1) 
=> ['b', 'c', 'd', 'e']

ср, 26 февр. 2020 г., 06:34 Josh Brody <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="16a7LINHCAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jo...@...>:
Would this alias Array#excluding? I think the Array#except is natural and I’ve found myself asking why it’s not aliased already many times but I’m not the one to ask. 🙂

Sent from my iPhone

On Feb 25, 2020, at 10:21 PM, Alex Golubenko <<a href="javascript:" rel="nofollow" target="_blank" gdf-obfuscated-mailto="16a7LINHCAAJ" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">alexandr1...@...> wrote:


Hi guys!

Time to time I meet questions on SO about how to take elements from array avoid some indexes.

I think it might be helpful for many developers to have something like `Hash#except` but for `Array`.

I would like to add PR with it if someone interested in it.

Thanks in advance for any thoughts about this idea.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" rel="nofollow" target="_blank" gdf-obfuscated-mailto="16a7LINHCAAJ" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonra...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-core/479e2902-3cb1-4bb3-9347-5aeefe27379d%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/479e2902-3cb1-4bb3-9347-5aeefe27379d%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/479e2902-3cb1-4bb3-9347-5aeefe27379d%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-core/479e2902-3cb1-4bb3-9347-5aeefe27379d%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" rel="nofollow" target="_blank" gdf-obfuscated-mailto="16a7LINHCAAJ" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonra...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-core/CAECA2F2-A2E4-4AD1-842B-1FCB9331CB78%40josh.mn?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/CAECA2F2-A2E4-4AD1-842B-1FCB9331CB78%40josh.mn?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/CAECA2F2-A2E4-4AD1-842B-1FCB9331CB78%40josh.mn?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-core/CAECA2F2-A2E4-4AD1-842B-1FCB9331CB78%40josh.mn.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/6904f0ef-9b96-432d-95a4-f35d8892303b%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Feature] Add #except to Array

Alex Golubenko
I'm totally agree that it might be confusing so yeah, maybe `#except_index` will be the best variant 😅

ср, 26 февр. 2020 г., 14:19 Nicholas Schwaderer <[hidden email]>:
Nice suggestion! :) 

I see how it would replicate the Hash#except syntax as seen here: https://apidock.com/rails/Hash/except

However, could this be confusing for those who don't anticipate the index stripping behavior but more of a reject/excluding behavior?

i.e.:

```
%w( 1 5 6 8 0 9 0 ).except(0)
#=> [5,6,8,0,9,0]
```

Would it be better to explicitly add the index to the name such as `#except_index` or more verbose `#except_with_index` ? 



On Wednesday, February 26, 2020 at 8:49:07 AM UTC, Alex Golubenko wrote:
It wouldn't be alias 😅
The main idea is to implement method which we can use to exclude elements from array by their indexes.

For example: 
%w( a b c d e f).except(0, -1) 
=> ['b', 'c', 'd', 'e']

ср, 26 февр. 2020 г., 06:34 Josh Brody <[hidden email]>:
Would this alias Array#excluding? I think the Array#except is natural and I’ve found myself asking why it’s not aliased already many times but I’m not the one to ask. 🙂

Sent from my iPhone

On Feb 25, 2020, at 10:21 PM, Alex Golubenko <[hidden email]> wrote:


Hi guys!

Time to time I meet questions on SO about how to take elements from array avoid some indexes.

I think it might be helpful for many developers to have something like `Hash#except` but for `Array`.

I would like to add PR with it if someone interested in it.

Thanks in advance for any thoughts about this idea.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/479e2902-3cb1-4bb3-9347-5aeefe27379d%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/CAECA2F2-A2E4-4AD1-842B-1FCB9331CB78%40josh.mn.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/6904f0ef-9b96-432d-95a4-f35d8892303b%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/CAAYv6Fy6%2BdCi_hTkuugF-59h8Lzy1no7RAMgufh5jcybjVJEMg%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Feature] Add #except to Array

Thushara Wijeratna
What would be a typical use case for such a function - I can understand the special case of wanting to remove the first / last items in the array, but an arbitrary one?

On Wednesday, February 26, 2020 at 4:25:52 AM UTC-8, Alex Golubenko wrote:
I'm totally agree that it might be confusing so yeah, maybe `#except_index` will be the best variant 😅

ср, 26 февр. 2020 г., 14:19 Nicholas Schwaderer <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="dpUUDFdTCAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">nicholas....@...>:
Nice suggestion! :) 

I see how it would replicate the Hash#except syntax as seen here: <a href="https://apidock.com/rails/Hash/except" style="font-size:medium" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2FHash%2Fexcept\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGY2b6xahObd1_sWcblfnxmWF7vvQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2FHash%2Fexcept\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGY2b6xahObd1_sWcblfnxmWF7vvQ&#39;;return true;">https://apidock.com/rails/Hash/except

However, could this be confusing for those who don't anticipate the index stripping behavior but more of a reject/excluding behavior?

i.e.:

```
%w( 1 5 6 8 0 9 0 ).except(0)
#=> [5,6,8,0,9,0]
```

Would it be better to explicitly add the index to the name such as `#except_index` or more verbose `#except_with_index` ? 



On Wednesday, February 26, 2020 at 8:49:07 AM UTC, Alex Golubenko wrote:
It wouldn't be alias 😅
The main idea is to implement method which we can use to exclude elements from array by their indexes.

For example: 
%w( a b c d e f).except(0, -1) 
=> ['b', 'c', 'd', 'e']

ср, 26 февр. 2020 г., 06:34 Josh Brody <[hidden email]>:
Would this alias Array#excluding? I think the Array#except is natural and I’ve found myself asking why it’s not aliased already many times but I’m not the one to ask. 🙂

Sent from my iPhone

On Feb 25, 2020, at 10:21 PM, Alex Golubenko <[hidden email]> wrote:


Hi guys!

Time to time I meet questions on SO about how to take elements from array avoid some indexes.

I think it might be helpful for many developers to have something like `Hash#except` but for `Array`.

I would like to add PR with it if someone interested in it.

Thanks in advance for any thoughts about this idea.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-core/479e2902-3cb1-4bb3-9347-5aeefe27379d%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/479e2902-3cb1-4bb3-9347-5aeefe27379d%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/479e2902-3cb1-4bb3-9347-5aeefe27379d%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-core/479e2902-3cb1-4bb3-9347-5aeefe27379d%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-core/CAECA2F2-A2E4-4AD1-842B-1FCB9331CB78%40josh.mn?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/CAECA2F2-A2E4-4AD1-842B-1FCB9331CB78%40josh.mn?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/CAECA2F2-A2E4-4AD1-842B-1FCB9331CB78%40josh.mn?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-core/CAECA2F2-A2E4-4AD1-842B-1FCB9331CB78%40josh.mn.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" rel="nofollow" target="_blank" gdf-obfuscated-mailto="dpUUDFdTCAAJ" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonra...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-core/6904f0ef-9b96-432d-95a4-f35d8892303b%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/6904f0ef-9b96-432d-95a4-f35d8892303b%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/6904f0ef-9b96-432d-95a4-f35d8892303b%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-core/6904f0ef-9b96-432d-95a4-f35d8892303b%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/887de265-c458-4538-bbb5-fe8a98d07507%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Feature] Add #except to Array

Alex Golubenko
I think your question is kinda abstractive because many Rails/Ruby methods is mostly for special cases and many of them might be not used ever by most of the projects.


четверг, 27 февраля 2020 г., 0:31:38 UTC+2 пользователь Thushara Wijeratna написал:
What would be a typical use case for such a function - I can understand the special case of wanting to remove the first / last items in the array, but an arbitrary one?

On Wednesday, February 26, 2020 at 4:25:52 AM UTC-8, Alex Golubenko wrote:
I'm totally agree that it might be confusing so yeah, maybe `#except_index` will be the best variant 😅

ср, 26 февр. 2020 г., 14:19 Nicholas Schwaderer <[hidden email]>:
Nice suggestion! :) 

I see how it would replicate the Hash#except syntax as seen here: <a href="https://apidock.com/rails/Hash/except" style="font-size:medium" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2FHash%2Fexcept\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGY2b6xahObd1_sWcblfnxmWF7vvQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2FHash%2Fexcept\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGY2b6xahObd1_sWcblfnxmWF7vvQ&#39;;return true;">https://apidock.com/rails/Hash/except

However, could this be confusing for those who don't anticipate the index stripping behavior but more of a reject/excluding behavior?

i.e.:

```
%w( 1 5 6 8 0 9 0 ).except(0)
#=> [5,6,8,0,9,0]
```

Would it be better to explicitly add the index to the name such as `#except_index` or more verbose `#except_with_index` ? 



On Wednesday, February 26, 2020 at 8:49:07 AM UTC, Alex Golubenko wrote:
It wouldn't be alias 😅
The main idea is to implement method which we can use to exclude elements from array by their indexes.

For example: 
%w( a b c d e f).except(0, -1) 
=> ['b', 'c', 'd', 'e']

ср, 26 февр. 2020 г., 06:34 Josh Brody <[hidden email]>:
Would this alias Array#excluding? I think the Array#except is natural and I’ve found myself asking why it’s not aliased already many times but I’m not the one to ask. 🙂

Sent from my iPhone

On Feb 25, 2020, at 10:21 PM, Alex Golubenko <[hidden email]> wrote:


Hi guys!

Time to time I meet questions on SO about how to take elements from array avoid some indexes.

I think it might be helpful for many developers to have something like `Hash#except` but for `Array`.

I would like to add PR with it if someone interested in it.

Thanks in advance for any thoughts about this idea.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-core/479e2902-3cb1-4bb3-9347-5aeefe27379d%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/479e2902-3cb1-4bb3-9347-5aeefe27379d%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/479e2902-3cb1-4bb3-9347-5aeefe27379d%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-core/479e2902-3cb1-4bb3-9347-5aeefe27379d%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-core/CAECA2F2-A2E4-4AD1-842B-1FCB9331CB78%40josh.mn?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/CAECA2F2-A2E4-4AD1-842B-1FCB9331CB78%40josh.mn?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/CAECA2F2-A2E4-4AD1-842B-1FCB9331CB78%40josh.mn?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-core/CAECA2F2-A2E4-4AD1-842B-1FCB9331CB78%40josh.mn.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-core/6904f0ef-9b96-432d-95a4-f35d8892303b%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/6904f0ef-9b96-432d-95a4-f35d8892303b%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/6904f0ef-9b96-432d-95a4-f35d8892303b%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-core/6904f0ef-9b96-432d-95a4-f35d8892303b%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/c0640f5d-3775-46be-9783-eefeca65b075%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Feature] Add #except to Array

Ян Матвейчук
In reply to this post by Thushara Wijeratna
I think there should be a lot of use cases. It's not gonna be the fastest method, but it will be quite popular. From my side I implemented such a method and used it for complex data parsing. I would recommend to add ranges to arguments.   

On Thursday, February 27, 2020 at 12:31:38 AM UTC+2, Thushara Wijeratna wrote:
What would be a typical use case for such a function - I can understand the special case of wanting to remove the first / last items in the array, but an arbitrary one?

On Wednesday, February 26, 2020 at 4:25:52 AM UTC-8, Alex Golubenko wrote:
I'm totally agree that it might be confusing so yeah, maybe `#except_index` will be the best variant 😅

ср, 26 февр. 2020 г., 14:19 Nicholas Schwaderer <[hidden email]>:
Nice suggestion! :) 

I see how it would replicate the Hash#except syntax as seen here: <a href="https://apidock.com/rails/Hash/except" style="font-size:medium" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2FHash%2Fexcept\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGY2b6xahObd1_sWcblfnxmWF7vvQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2FHash%2Fexcept\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGY2b6xahObd1_sWcblfnxmWF7vvQ&#39;;return true;">https://apidock.com/rails/Hash/except

However, could this be confusing for those who don't anticipate the index stripping behavior but more of a reject/excluding behavior?

i.e.:

```
%w( 1 5 6 8 0 9 0 ).except(0)
#=> [5,6,8,0,9,0]
```

Would it be better to explicitly add the index to the name such as `#except_index` or more verbose `#except_with_index` ? 



On Wednesday, February 26, 2020 at 8:49:07 AM UTC, Alex Golubenko wrote:
It wouldn't be alias 😅
The main idea is to implement method which we can use to exclude elements from array by their indexes.

For example: 
%w( a b c d e f).except(0, -1) 
=> ['b', 'c', 'd', 'e']

ср, 26 февр. 2020 г., 06:34 Josh Brody <[hidden email]>:
Would this alias Array#excluding? I think the Array#except is natural and I’ve found myself asking why it’s not aliased already many times but I’m not the one to ask. 🙂

Sent from my iPhone

On Feb 25, 2020, at 10:21 PM, Alex Golubenko <[hidden email]> wrote:


Hi guys!

Time to time I meet questions on SO about how to take elements from array avoid some indexes.

I think it might be helpful for many developers to have something like `Hash#except` but for `Array`.

I would like to add PR with it if someone interested in it.

Thanks in advance for any thoughts about this idea.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-core/479e2902-3cb1-4bb3-9347-5aeefe27379d%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/479e2902-3cb1-4bb3-9347-5aeefe27379d%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/479e2902-3cb1-4bb3-9347-5aeefe27379d%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-core/479e2902-3cb1-4bb3-9347-5aeefe27379d%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-core/CAECA2F2-A2E4-4AD1-842B-1FCB9331CB78%40josh.mn?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/CAECA2F2-A2E4-4AD1-842B-1FCB9331CB78%40josh.mn?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/CAECA2F2-A2E4-4AD1-842B-1FCB9331CB78%40josh.mn?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-core/CAECA2F2-A2E4-4AD1-842B-1FCB9331CB78%40josh.mn.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-core/6904f0ef-9b96-432d-95a4-f35d8892303b%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/6904f0ef-9b96-432d-95a4-f35d8892303b%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/6904f0ef-9b96-432d-95a4-f35d8892303b%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-core/6904f0ef-9b96-432d-95a4-f35d8892303b%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/17070217-7d53-41f7-8432-c2fd2ac6d5d5%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Feature] Add #except to Array

Alex Golubenko
In reply to this post by Alex Golubenko
I opened PR: https://github.com/rails/rails/pull/38611

среда, 26 февраля 2020 г., 6:21:35 UTC+2 пользователь Alex Golubenko написал:
Hi guys!

Time to time I meet questions on SO about how to take elements from array avoid some indexes.

I think it might be helpful for many developers to have something like `Hash#except` but for `Array`.

I would like to add PR with it if someone interested in it.

Thanks in advance for any thoughts about this idea.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/d6a23d12-aeb6-497c-8ae1-761f8595b855%40googlegroups.com.