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#to_h(&block) #7150

Merged
merged 3 commits into from
Dec 7, 2018
Merged

Conversation

Sija
Copy link
Contributor

@Sija Sija commented Dec 5, 2018

Re: 🎄 shopping spree at Ruby 2.6 land ;)

Copy link
Member

@asterite asterite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is inefficient. You should create a Hash, call each and assume it's a tuple and add that to the hash.

@Sija Sija force-pushed the feature/to_h-with-block branch from 9863fca to c8a14db Compare December 5, 2018 23:32
@Sija
Copy link
Contributor Author

Sija commented Dec 5, 2018

@asterite spot on, fixed.

Copy link
Member

@asterite asterite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead of U you can use Tuple(X, Y) forall X, Y and use those types to initialize the Hash.

@Sija
Copy link
Contributor Author

Sija commented Dec 5, 2018

I was thinking of that but then it would have to be Array(X | Y) | Tuple(X, Y).

@asterite
Copy link
Member

asterite commented Dec 5, 2018

Why Array? Tuple is enough. If you have an Array as the block value the caller can always convert that to a duple. Enforcing tuple guarantees a minimum level of performance.

@Sija
Copy link
Contributor Author

Sija commented Dec 5, 2018

Fair 'nuff, pushed an update.

src/enumerable.cr Outdated Show resolved Hide resolved
src/enumerable.cr Outdated Show resolved Hide resolved
@RX14 RX14 added this to the 0.27.1 milestone Dec 7, 2018
@RX14 RX14 merged commit 24f545a into crystal-lang:master Dec 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants