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

Should String/Array.slice accept 0 as an end argument #699

Closed
dannyob opened this Issue Aug 24, 2016 · 3 comments

Comments

Projects
None yet
5 participants
@dannyob

dannyob commented Aug 24, 2016

It seems very weird that you can easily slice from the start of a String or Array, but not to its end:

> String.slice 0 3 "Hello"
"Hel" : String

> String.slice 0 -1 "Hello"
"ell" : String

> String.slice -3 -1 "Hello"
"ll" : String

-- But how do we get "lo"?
> String.slice -2 0 "Hello"
"" : String

I think this is a side effect of Elm borrowing from Python -- Python slice indices can be negative, but they can also be None, which indicates either the start or the end of the list, depending on where they are used.

Conceivably we could use 0 as an end argument for this function, just as 0 as a start argument means "before the start." But it's all feeling a bit like null values here...

It feels like @sindikat might have some thoughts on this...

@process-bot

This comment has been minimized.

Show comment
Hide comment
@process-bot

process-bot Aug 24, 2016

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

process-bot commented Aug 24, 2016

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

@lukewestby lukewestby added the request label Aug 24, 2016

@andreaazzini

This comment has been minimized.

Show comment
Hide comment
@andreaazzini

andreaazzini Aug 30, 2016

The slice functions behave exactly like their Javascript counterparts. IMHO, it wouldn't be right to make the Elm slice work differently. You can (and probably should) use the String.right function in this specific case.

> String.right 2 "Hello"
"lo" : String

However, the right function is not available in the Array module. Maybe we should discuss how to avoid this specific asymmetry.

andreaazzini commented Aug 30, 2016

The slice functions behave exactly like their Javascript counterparts. IMHO, it wouldn't be right to make the Elm slice work differently. You can (and probably should) use the String.right function in this specific case.

> String.right 2 "Hello"
"lo" : String

However, the right function is not available in the Array module. Maybe we should discuss how to avoid this specific asymmetry.

@evancz evancz referenced this issue Sep 22, 2016

Open

API Ideas #322

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Sep 22, 2016

Member

Added to #322 that tracks all these ideas in one place. That way we can try to make more coherent API choices so things match across all core libraries.

Member

evancz commented Sep 22, 2016

Added to #322 that tracks all these ideas in one place. That way we can try to make more coherent API choices so things match across all core libraries.

@evancz evancz closed this Sep 22, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment