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
proposal: net: net.Listener.Iter #65520
Comments
Could you show us some use cases for your proposal? What drove you to make this proposal? |
cc @neild |
IMO Something like |
Using product types to express sum types is an unreasonable thing in itself. I think we can't make any mistakes anymore. It's time to make some changes. Maybe this can be the first place to change. I know there are currently some proposals related to the sum type, but nothing has changed for a long time and no one seems willing to move forward with them. The use of struct design here was forced to make some choices. |
The convention in slices and maps is to call this “All” not “Iter”. |
The proposed new iteration APIs in #61897 provide alternatives to existing functions which return a slice of results, permitting the caller to iterate over results without allocating the entire result slice.
vs.
This is at most one line less code, or the same number of lines if we assign Leaving aside the fact that |
I wonder how many applications have more than a single call to Listener.Accept; extra syntactic convenience wouldn't help very often. And Accept is such a significant enough operation that perhaps it warrants being explicit within the loop, not hidden in an iterator. |
Closing it, for no compelling reason other than to copy the same capabilities from rust. And due to the lack of type system support for sum type, there has not been much change in usage. |
Proposal Details
Finally, we had
Iterator
api in std.So I propose add
net.Litener.Iter
that returns aniter.Seq
to producenet.Conn or error
sequential.The api may looks like:
While I personally don't like
iter.Seq2
to expressEither
semantics,because we don't succeed and fail at the same time, or neither succeed nor fail at the same time.
Strictly speaking, this situation should be expressed using the
sum type
, so the additionalResult monad
is introduced.The text was updated successfully, but these errors were encountered: