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

Implementation of Array.nitems #3501

Closed
wants to merge 1 commit into from
Closed

Implementation of Array.nitems #3501

wants to merge 1 commit into from

Conversation

tbrand
Copy link

@tbrand tbrand commented Nov 4, 2016

I added Array.nitems function that is one of the important feature of Ruby's array.
Array.nitems returns the number of nil elements.

[0, 1, nil].nitems # => 1
[0, 2, 3].nitems # => 0

… Ruby's array.

Array.nitems returns the number of nil elements.

[0, 1, nil].nitems # => 1
[0, 2, 3].nitems # => 0
@luislavena
Copy link
Contributor

Hello,

That can be simply expressed in Crystal using count:

puts [0, 1, nil].count &.nil? # => 1
puts [0, 2, 3].count &.nil?   # => 0

I suggest reimplement using existing enumerable functionality will be a better approach.

Also, nitems is not a very descriptive name and might not provide enough transparency on the purpose of it. Please note that while syntax is similar to Ruby, Crystal do not pursue be a 1-to-1 copy or compatible with it.

Cheers.

@tbrand
Copy link
Author

tbrand commented Nov 4, 2016

Hi luislavena!

Thanks for your early reply!
I understood the philosophy of the Crystal lang.
I really agree with it and would like to use in many scenes :)
Anyway, close this PR.

@tbrand tbrand closed this Nov 4, 2016
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

2 participants