Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define package-wide default imports

Tags:

scala

How can I define package-wide default imports? I want to define a package p such that

import p._

is equivalent to

import scala.util.Try
import scala.collection.mutable.Queue
like image 386
OlivierBlanvillain Avatar asked Sep 10 '15 16:09

OlivierBlanvillain


1 Answers

Follow the pattern used in scala/package.scala to make some of the standard collection available without imports. It involves a package object with a type and a val for each import:

package object p {
  type Try[A] = scala.util.Try[A]
  val Try = scala.util.Try
  type Queue[A] = scala.collection.mutable.Queue[A]
  val Queue = scala.collection.mutable.Queue
}
like image 98
OlivierBlanvillain Avatar answered Nov 02 '22 17:11

OlivierBlanvillain