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 Indexable#fetch #6293

Closed

Conversation

AlexWayfer
Copy link
Contributor

Like the Hash#fetch.

I found very similar, but not identical Indexable#at.

And I didn't find alias_method.

@asterite
Copy link
Member

asterite commented Jun 29, 2018

Thank you! But Crystal's policy is to not have aliases.

@AlexWayfer
Copy link
Contributor Author

Thank you! But Crystal's policy is to not have aliases.

At all? I mean… what about Indexable#[] and Indexable#at? #fetch use the same construction. And it has more implementations (with default value without block, you would not write [1, 2].at(2, 4)). And it's make Indexable (and Array) more similar to Hash (which is also Indexable).

@asterite
Copy link
Member

at is a bit of an exception, because [] can't receive a block. And it would be weird to have [] (no block) and at() { ... } (with a block), so at without a block exists too. But the non-block variant could be removed, and maybe even at removed and renamed to fetch, for consistency with Hash.

@AlexWayfer AlexWayfer closed this Jun 29, 2018
@AlexWayfer AlexWayfer deleted the stdlib/add/Indexable#fetch branch June 29, 2018 15:27
@AlexWayfer
Copy link
Contributor Author

AlexWayfer commented Jun 29, 2018

at is a bit of an exception, because [] can't receive a block. And it would be weird to have [] (no block) and at() { ... } (with a block), so at without a block exists too. But the non-block variant could be removed, and maybe even at removed and renamed to fetch, for consistency with Hash.

Sounds reasonable. I've created a new PR #6296 (from renamed branch).

@asterite
Copy link
Member

Just note that this doesn't mean it will get merged. It was just a suggestion to open a discussion. I guess it will be fine because I doubt many are using at ([]? is more common), but since it will be a breaking change there will be more resistance to accept that code.

@AlexWayfer
Copy link
Contributor Author

Just note that this doesn't mean it will get merged. It was just a suggestion to open a discussion. I guess it will be fine because I doubt many are using at ([]? is more common), but since it will be a breaking change there will be more resistance to accept that code.

Thank you, I know. I just tried to rename the branch for this PR and it closed PR. 😅

I'm ready to discuss and change solutions.

I just want to change something like this:

port = (ARGV[0]?.try &.to_i?) || DFLT_TCP_PORT_NUM

to this:

port = ARGV.fetch(0, DFLT_TCP_PORT_NUM)

(Example by @DRVTiny)

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