Export VS type alias + extension

Hello,

I’ve noticed there are three ways of doing the following pattern, and would like to ask for your opinion on which is “best”.

With simple:

case class Board(lines: List[List[Piece]]){
  // Users call methods on lines explicitly
  def foo...
  def bar...
}

With export:

(case) class Board(lines: List[List[Piece]]){
  export lines._ // users can call directly on Board, but for example map(id) will not return a Board
  def foo...
  def bar...
}

With type alias + extension:

type Board = List[List[Piece]] // users can call directly on Board, and map(id) will return a Board
extension (b: Board)
  def foo...
  def bar...

When providing an answer, I encourage you to specify both what you mean by best, and in what context it is best

Would your opinion change if Board took two arguments ?

2 Likes