Scala: How to always make certain utilities available for subpackages?

All my code is under package com.company.project

. Almost all of my files, I introduce some of the common things such as import scala.util.{Failure, Try, Success}

and import scala.util.control.NonFatal

etc. Is it possible in some way to customize the package object so that all these utilities are always available for all subpackages in com.company.project.sub

(view of my own project level Predef )?

+3


source to share


1 answer


Just create an 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
}

      

0


source







All Articles