I want to make my Scala code more readable, so I added custom types for all parametrized types.
So I have in package object, for simplicity,
type IntSeq = Seq[Int]
However, now I cannot do simple apply
on companion object. From REPL:
scala> IntSeq(1, 2, 3)
<console>:8: error: not found: value IntSeq
IntSeq(1, 2, 3)
^
What to do?
(just to make sure: my actual aliased objects are more complicated than Seq[Int]
)
edit: There is a similar question - Scala type alias including companion object [beginner]
On that question, there are two replies, both of them not working.
One is to define my custom object with apply, but I am not sure how to do that in my case, plus it is a little verbose.
The other - to write val IntSeq = Seq
produces the error
warning: previously defined trait Seq is not a companion to value IntSeq. Companions must be defined together; you may wish to use :paste mode for this.
:paste
? – Debilski:paste
means :( apparently, it's something to do with REPL, but I want it to work outside of REPL too, of course – Karel Bílektype
alias and theval
assignment after another. This is a REPL-only problem so it should not matter in other code. – Debilski