pathikrit
pathikrit

Reputation: 33479

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

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

Upvotes: 3

Views: 279

Answers (1)

Sean Vieira
Sean Vieira

Reputation: 160005

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
}

Upvotes: 0

Related Questions