Some Name
Some Name

Reputation: 9521

Importing declarations from multiple objects at once

I have multiple objects containing case class declarations. For example:

object model1{
   //case classes
}

object model2{
   //case classes
}

object model3{
   //case classses
}

Importing each of those models separately is cumbersome. Is it possible to import it at once somehow?

The following does not work

object all{
    import model1._
    import model2._
    import model3._
}

import all._

Maybe some macro can be useful here?

Upvotes: 0

Views: 86

Answers (1)

Mateusz Kubuszok
Mateusz Kubuszok

Reputation: 27535

Theoretically you could take a look at all definitions in each of these objects, and generate code, that basically delegates implicit, val, def, type to definition in original object, but that would be:

  1. slow, because macros,
  2. not supported by IDEs, because macros.

If you are on Scala 2.13 you can try using something like -Yimports to configure global imports, if you use imports very often - it should be supported by newest IntelliJ.

On Scala 3 you will have export as mentioned by @Luis Miguel Mejía Suárez.

Upvotes: 2

Related Questions