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

Str\split should return remainder independent of parts #60

Closed
rob0rt opened this issue Oct 2, 2018 · 2 comments
Closed

Str\split should return remainder independent of parts #60

rob0rt opened this issue Oct 2, 2018 · 2 comments

Comments

@rob0rt
Copy link

rob0rt commented Oct 2, 2018

In Str\split, if $limit is provided, the last element of the return is special, in that it contains the entire remainder of the string. This could be better structured as a tuple of (vec<string> $parts, string $remainder).

Regex\split suffers from a similar issue.

@fredemmott
Copy link
Contributor

fredemmott commented Oct 2, 2018

Perhaps it might be best to make seprate functions for with-and-without limits?

list($parts, $_) = Str\split($haystack, $delim) feels verbose/confusing for the common case

@billf
Copy link
Contributor

billf commented Mar 17, 2020

Perhaps it might be best to make seprate[sic] functions for with-and-without limits?

list($parts, $_) = Str\split($haystack, $delim) feels verbose/confusing for the common case

... and expensive. creating a 2-element tuple where one element is almost always ignored feels wasteful.

if the caller is providing $limit, they could also $remainder = C\lastx($parts), splice it, or overwrite it via $parts[C\count($parts) - 1] = ''.

i suggest this old issue be closed until a push request is attached to it w/ the second function (Str\split_remainder?).

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

No branches or pull requests

3 participants