Combining export and extension

Moving back from that other discussion (Supporting import in extension method blocks - #38 by Russ - Language Design - Scala Contributors) to here, then yes, I think the use of an export suits your use-case better.

I’m assuming you want to achieve a similar effect to widening an inherited OO interface and its implementation with extra methods, but have to work with objects and delegation instead - and that is what exports offer.

That’s what’s going on with Copier in the example here: Export Clauses, playing a similar role with its scanUnit and printUnit as Tracks could with its tracks instance.

Copier.status plays a similar role to your originally intended use of extension methods, I suspect. In the example, it happens to delegate to two similar methods on the inside, but there’s nothing stopping you from adding completely new methods unrelated to the delegatee’s interface.

1 Like