-
-
Notifications
You must be signed in to change notification settings - Fork 113
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
Make it easier to String.slice
to the end of a string
#1566
Comments
If ranges were to be used instead then wouldn't you still have the same problem of not being able to use a shortcut? For example you'd still have to call |
Grain has |
Yes but you'd still have to call |
Yeah, we haven't really talked about negative indexing on ranges. |
I suppose a hacky alternative would be to allow |
This isn't a problem once we have optional arguments, so I'd vote that we don't "solve" it until then. Once optional arguments exist, the "end" argument will be optional |
currently if i wanted to do something similar to
"test".slice(1)
in js to get"est"
, In Grain the only way to currently do this would beString.slice(1, String.length("test"), "test") == "est"
Negative indexing feels like a fix to this butString.slice(1, -1, "test") == "es"
, My solutiin to this wasString.slice(0, -0, "test") == "est"
but after asking @ospencer about this in the discord it was noted that we should never ever use-0
, One possible solution to this would be to makeString.slice
use ranges then we could have inclusive or exclusive ranges but this is somewhat blocked by #1404 and would be a breaking change, another possible nonbreaking solution would be adding aString.sliceIndex(<splitIndex>, "string")
but that would be less flexible and might get confusing.TLDR: currently slicing from an index to the end of a string is extremly verbose, it would be nice if it was made simplier.
The text was updated successfully, but these errors were encountered: