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 a proposal for count(where:) #840

Merged
merged 1 commit into from Jul 20, 2018
Merged

Add a proposal for count(where:) #840

merged 1 commit into from Jul 20, 2018

Conversation

@khanlou
Copy link
Contributor

@khanlou khanlou commented Apr 23, 2018

This is a proposal for count(where:).

Pitch thread: https://forums.swift.org/t/count-where-on-sequence/11186

Recommended implementation: apple/swift#16099


Counting the number of objects that pass a test has a wide range of uses in many domains. However, Swift currently doesn't give its users a simple way to perform this operation. While the behavior can currently be approximated with a `filter` and a `count`, this approach creates an intermediate array which it immediately discards. This is a bit wasteful.

[1, 2, 3, -1, -2].filter({ $0 > 0 }).count // => 3

This comment has been minimized.

@BasThomas

BasThomas Apr 23, 2018
Contributor

You can, instead of adding the four spaces, wrap these in backticks (```) and add syntax highlighting (```swift on the first line)

@khanlou
Copy link
Contributor Author

@khanlou khanlou commented Jun 12, 2018

Just double checking on the status of this! Anything else I can do to push it forward?

@tkremenek
Copy link
Member

@tkremenek tkremenek commented Jul 19, 2018

This review is going to be scheduled for the week of August 6.

@khanlou
Copy link
Contributor Author

@khanlou khanlou commented Jul 20, 2018

That sounds great. Thanks for heads up, Ted!

@fbartho
Copy link

@fbartho fbartho commented Jul 20, 2018

Why not use reduce to count things?

My specific point in raising this is that it bypasses the "extra intermediate array" concern (for filter + count) that was raised in the proposal.

@lattner lattner merged commit 59635bf into apple:master Jul 20, 2018
@lattner
Copy link
Collaborator

@lattner lattner commented Jul 20, 2018

Scheduled for review August 6 - 12, 2018

@lattner
Copy link
Collaborator

@lattner lattner commented Jul 20, 2018

Now AKA SE-0220

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants