Scala: How to always make certain utils available to sub packages?

276 Views Asked by At

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)?

1

There are 1 best solutions below

2
On

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
}