Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Enumerable#grep(klass : T.class) forall T #6143

Closed

Conversation

AlexWayfer
Copy link
Contributor

It returns Array(T).

@RX14
Copy link
Contributor

RX14 commented May 29, 2018

I'm not sure if this is useful or common enough to out in the stdlib. Not sure about the naming at least.

Surely array.compact_map { |x| x if x.is_a?(T) } is short enough to use in the rare case you need to do something like this.

@AlexWayfer
Copy link
Contributor Author

AlexWayfer commented May 29, 2018

I'm not sure if this is useful or common enough to out in the stdlib. Not sure about the naming at least.

It's from Ruby. And it works with klass === elem, but not for ary << (compiler checks is_a?, but not ===).

Surely array.compact_map { |x| x if x.is_a?(T) } is short enough to use in the rare case you need to do something like this.

I found a wish to create shortcut for .map(&.as(Type)) (from you), and now you're suggesting a longer way to the similar task.

@straight-shoota
Copy link
Member

.map(&.as(Type)) is entirely different and probably more common than filtering instances of a particular class from an array.

@RX14
Copy link
Contributor

RX14 commented Jun 2, 2018

Unfortunately I don't think we're going to merge this. If we find in the future that this is a common operation i'm fine to reopen this :)

@RX14 RX14 closed this Jun 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants