-
Notifications
You must be signed in to change notification settings - Fork 157
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 function slice start end = take (end − start) . drop start
?
#576
Comments
When I encounter However, if we extend |
We can use |
I agree, this is terrible. But convenience also matters.
It hurts me that there is no function out of the box that does what |
You can't take a substring of a UTF-8 string in constant time, because characters have encodings of variable lengths. In Python, strings are byte-indexed, i.e., they're really Haskell's vector has a |
Yes, of course. I meant «constant space» but I guess I was sleepy.
|
If we add Not saying that this is enough reason to reject
It's a little more complicated. Python strings are arrays of whatever the the largest code point in the string is: PEP-393 In Javascript, Strings are sequences of UTF-16 code units, which means |
Many languages offer a feature that lets you take a substring by indices real quick. It is handy. Here is an example from JavaScript:
One frequent use case is when you have a parse tree annotated with locations and you want to recover the literal source of a given syntactic element. With
slice
, this is done at once.Can we add such a function to
text
? Maybe it can have a more efficient implementation thantake … . drop …
?The text was updated successfully, but these errors were encountered: