-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: bufio: Scanner.{Text,Bytes}Seq #70657
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
Comments
Related Issues
Related Documentation Related Discussions (Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
this doesn't address how errors should be surfaced, see #70084 for related discussion |
Also why global functions, instead of methods? |
My bad, I've copied code from my experiments. I've thought about method ofc. |
I think the naming convention is |
Thank you, changed according to this suggestion. |
The need to remember to call Scanner.Err after iterating, even with the traditional API, is already a problem; iterators may make it even easier to forget to do so. I think we should put this proposal aside until we have a consensus on how to deal with iterable sequences with the potential for errors. In the meantime, you can always write this function yourself. |
Proposal Details
Once iterators are introduced in 1.23 there is growing number of libraries based on this feature. Reading data by lines or words are quite common task and could be accomplished with
for ... range
loop. It requires just two simple methods forbufio.Scanner
:Reading whole file as collection of lines could be like:
The text was updated successfully, but these errors were encountered: