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

Move some of Sink/Source member functions to extensions #335

Open
fzhinkin opened this issue Jun 3, 2024 · 2 comments
Open

Move some of Sink/Source member functions to extensions #335

fzhinkin opened this issue Jun 3, 2024 · 2 comments

Comments

@fzhinkin
Copy link
Collaborator

fzhinkin commented Jun 3, 2024

Sink/Source interfaces declare several member functions that could be easily implemented as extension functions. For example, Source::peek, Source::transferTo, and Sink::transferFrom.

Having such functions implemented as member functions does not provide any obvious benefits but requires us to write similar implementations several times. It would be nice to have a single implementation instead.

@joffrey-bion
Copy link

joffrey-bion commented Aug 19, 2024

Having such functions implemented as member functions does not provide any obvious benefits

It allows for different implementations to optimize these methods, specifically by offering the option to implement them differently. If those are moved to extension functions, then we face the same hell as with extensions on collections which cannot be easily optimized for specific collection implementations.

Typically, you faced it yourself already: #342, #343

but requires us to write similar implementations several times

I may be missing something, but why not just have a default implementation in the interface itself?

@fzhinkin
Copy link
Collaborator Author

I may be missing something, but why not just have a default implementation in the interface itself?

That's definitely an option to consider

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

2 participants