Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

Filter/require exports to match the members of a type #134

Open
er2 opened this issue Aug 30, 2020 · 2 comments
Open

Filter/require exports to match the members of a type #134

er2 opened this issue Aug 30, 2020 · 2 comments

Comments

@er2
Copy link

er2 commented Aug 30, 2020

When I first learned of the new export feature, I imagined a more disciplined version of Groovy's @delegate feature. The use case that jumped to mind is having a class which is functionally similar to a particular data structure, but with some domain specific enhancements. So you want to extend a collection interface and delegate it to a field but not be bound to the specific implementation, nor do you want to reimplement anything.

class Books extends Collection[Book] {

   private val books: List[Book]

   export Collection[Book] from books

   def authors: Set[Author] = books.map(_.author).toSet

}

I'd think this could be implemented as sugar on what currently exists. Picking a syntax might be harder at this point.

@bishabosha bishabosha changed the title Export all methods of a trait Filter exports by the members of a type Nov 2, 2020
@bishabosha
Copy link
Member

bishabosha commented Nov 2, 2020

so in this case Collection[Book] has some subset of the List API?

And does this impose an error if not all definitions can be satisfied?

@bishabosha bishabosha changed the title Filter exports by the members of a type Filter/require exports to match the members of a type Nov 2, 2020
@er2
Copy link
Author

er2 commented Nov 2, 2020

so in this case Collection[Book] has some subset of the List API?

Yes. I'm more familiar with Java where List and Set both implement Collection. I assumed that was so in Scala also. Maybe a slightly better example is you start using a Set and then later realize you need to allow duplicates, so you migrate to a List. But since you declared Collection, your API consumers haven't assumed set or list behavior for handling duplicates.

And does this impose an error if not all definitions can be satisfied?

Yes, a compile error.

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

No branches or pull requests

2 participants