- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
WIP: eachline method for strings #6933
Conversation
This seems like nice functionality (and a +1 for including tests), but I think we should have a discussion about API and naming. Isn't this just an iterator version of |
The way this is typically done is to use io = IOBuffer(str)
for eachline(io)
# ... do stuff
end I would think this is sufficient, but perhaps it should be documented better? |
I kinda like it, and I'd certainly never (think to) create an IOBuffer just to do it. A |
Another option would be to define eachline(s::String) = eachline(IOBuffer(s)) That doesn't handle @ninjin, the code itself looks quite nice, very Julian. Cheers! |
@ivarne: I tend to agree that a If we had a
And we could get some rather awesome string processing loops, like this slightly artificial example for TSV data:
It is getting a bit late here (JST), but I will try to take the time to cook something up this weekend. First, I will have a look at the current Taking the risk to sound a bit controversial, but the the |
The iterator object should not be mutable here; this kind of iteration could work exactly like normal string iteration (by character), just advancing to the next delimiter instead of to the next character boundary. It's also a good idea to generalize |
I just had some pleasant time to sink into this. What I did was that I went with the simple one-liner from @kmsquire, kept the tests, force-pushed to my branch. The reasoning behind this is that it is most likely better to create a new branch for Also, thanks to @JeffBezanson for the feedback. I think I get the intended usage of the iterator protocol now, but more about that in the upcoming WIP |
The build failed for clang and passed for gcc, I am pretty sure the failure is unrelated to the PR. |
This seems pretty unobjectionable to me, though I realized that |
Yes, this seems like a good thing to me. I suspsect that the best way to shake out issues and see how pressing they are may be to merge this part and then see what happens. |
Or if we merge #7027, this is not necessary. |
I tend to agree with the last statement by @JeffBezanson, once I get around to implementing #7027 it would be more natural to use it since it will work for any |
6c7c7e3
to
1a4c02f
Compare
|
eachline
variant for strings with tests included. It should be compatible witheachline(stream::IO)
and produce the same results for the same textual input.Any and all style/implementation feedback is very much welcome, I am very much a novice when it comes to Julia and the standard library code base.