Rich Oliver
unread,Oct 19, 2012, 9:36:29 AM10/19/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to scala-...@googlegroups.com
One common pattern I find myself using a lot is compile time lists built through inheritance. At the moment I'm using this trick from a Stack Overflow answer:
trait Base {
protected def contribute : List[String] = List("Beginning")
val list = contribute.reverse
}
trait TrA extends Base
{ override protected def contribute = "A" :: super.contribute }
trait TrB extends TrA
{ override protected def contribute = "B" :: super.contribute }
trait TrC extends TrB
{ override protected def contribute = "C" :: super.contribute }
val x = new TrC{}
x.list //> res0: List[String] = List(Beginning, A, B, C)
Do others use this and is it worthy of language support? Now obviously I can write my own type abbreviations, but I think its much better to use standardised abbreviations, than us all writing our own for the same thing. Also it seems odd that we keep having to type out "List[String]". Should we have more abbreviations. Common types that I'm always using are:
type ListF[T] = scala.collection.immutable.List[Function0[T]] //I particularly use these as compile time inheritance lists
type ListS = scala.collection.immutable.List[String]
type ListFS = ListF[String]
Just on a side note, during development I often want a place holder function that takes no parameters, returns nothing and does nothing. Am I right that () => {} is the shortest way of doing this.
Rich