3

All my code is under package com.company.project. In almost all of my files, I end up importing some common things like import scala.util.{Failure, Try, Success} and import scala.util.control.NonFatal etc. Is it possible to somehow setup a package object in such a way that all these utils are always available to all sub packages in com.company.project.sub (kind of my own project level Predef)?

pathikrit
  • 32,469
  • 37
  • 142
  • 221

1 Answers1

0

Simply create a package object with type aliases:

package com.company.project

import scala.util

package object sub {
  type Failure = util.Failure
  type Try = util.Try
  type Success = util.Success
  type NonFatal = util.control.NonFatal
}
Community
  • 1
  • 1
Sean Vieira
  • 155,703
  • 32
  • 311
  • 293
  • But, I have many different `sub` e.g. `com.company.project.foo` and `com.company.project.bar` etc and I want these utils to be available for all **sub** packages of `com.company.project.*.*.*...` – pathikrit Oct 16 '14 at 16:54
  • No way there without importing `com.company.project.sub._` - but that does limit the boilerplate to one line. – Sean Vieira Oct 16 '14 at 17:27