scala

How do I idiomatically handle null checks from within Scala/Lift ?

Even with the prevalence of the Box and Option monads, we still have to check for null values here and there. The best I've come up with so far is by using the Box#!! method: (Box !! possiblyNull).map(_.toString).openOr("") Is there a better way to do this? I tried using Box's apply method: Box(possiblyNull).map(_.toString).openOr("...

scala lift actor, error: type mismatch;

Greetings I'm using the scala version 2.8.0 and version 2.1 of lift to compile my project with maven I mark the following error: error: type mismatch; [INFO] required: **scala.actors.Actor** [INFO] Auctioneer !? AddListener(**this**, this.itemId) match { [INFO] ^ error: type mismatch; [INFO] requ...

How to represent lists of blocks in Configgy?

Configgy supports lists of strings as values and blocks of key/value pairs. But it seems it does not support lists of blocks of key/value pairs as values. Am I missing something? ...

License banners for Scala when using ENSIME

I'm trying to start using ENSIME for Scala development with SBT. How should I manage license headers? I used to use Copyright Wizard in Eclipse and that seemed fine. ...

Emulating != in scala using <>

I am trying to emulate != with <> in Scala. implicit def conditional[A](left : A) = new { | def<>[A](right : A) = (left != right) | } What are the case in which this emulation won't work ...

how do i throw exceptions with meaningful messages with a scala combination parser?

I'd like to throw an exception when the language doesn't conform to the grammar for a scala combination parser. Here's an example of a rule: def record: Parser[Record] = "-" ~ opt(recordLabel) ~ repsep(column, ",") ^^ { case "-" ~ label ~ columns => new Record(label, columns) } Let's say in the repsep(column, ",") part, they accid...

want to create an dropdown menu in popup.

This code that i taken from here is now workig for me .great now i want to create one autocomplete dropdown menu in it .so can u please help me out on this. class PopupMenu extends Component { override lazy val peer : JPopupMenu = new JPopupMenu def add(item:MenuItem) : Unit = { peer.add(item.peer) } def setVisible(visible:Boole...

Using specs matchers in scalacheck properties

I'm trying to use specs mathers inside scalacheck properties. For example, I have a matcher that works like this: x must matchMyMatcher(y) When I want to use this matcher inside scalacheck property, I do the following: import org.scalacheck._ import org.specs._ ... val prop = Prop.forAll(myGen){ (x,y) => new matchMyMatcher(x)(y)...

Scala Set implementation to use within business model?

Let's say we want to build a big social network (because social networks are all the rage at the moment). We'll start with a simple premise that anyone who wants to use our social network should be able to register under their name and then become friends or fall out with other people registred with us: import scala.collection._ class ...

Implementing a security typed variant of Scala - which method is best?

Hio there Scala folks, I'm actually writing my master thesis and I have to implement a security typed language in Scala. So this means I have to add annotations to specify the special permissions levels for the variables and other programming constructs in Scala. The idea to add this comes from Jif (a real security typed language http://...

How to format strings in Scala?

I need to print a formatted string containing scala.Long. java.lang.String.format() is incompatible with scala.Long (compile time) and RichLong (java.util.IllegalFormatConversionException) Compiler warns about deprecation of Integer on the following working code: val number:Long = 3243 String.format("%d", new java.lang.Long(number)) ...

Best explanation for Languages without Null

Every so often when programmers are bitching about null errors/exceptions someone asks what we do without null. I myself have some basic idea of the coolness of option types but I don't have the knowledge or languages skill to best express it. It would be useful if someone could point to or write an GREAT explanation of The undesirab...

Could you share a link to an URL parsing implementation?

...

++ operator in Scala

Is there any reason for Scala not support the ++ operator to increment primitive types by default? For example, you can not write: var i=0 i++ Thanks ...

How to manually specify an integer value bound to a particular enumeration value in Scala?

How to manually specify an integer value bound to a particular enumeration value in Scala? ...

Design Patterns and Scala

I'm writing this question to maintain a register of design patterns associated with Scala, standards patterns or only from this language. Associated questions: Scala Catalog of functional Design Patterns Thanks to all who contribute ...

How to use ScalaQuery to insert a BLOB field?

I used ScalaQuery and Scala. If I have an Array[Byte] object, how do I insert it into the table? object TestTable extends BasicTable[Test]("test") { def id = column[Long]("mid", O.NotNull) def extInfo = column[Blob]("mbody", O.Nullable) def * = id ~ extInfo <> (Test, Test.unapply _) } case class Test(id: Long, extInfo: Blob) ...

What is the syntax for adding an element to a scala.collection.mutable.Map ?

What is the syntax for adding an element to a scala.collection.mutable.Map ? Here are some failed attempts: val map = scala.collection.mutable.Map map("mykey") = "myval" map += "mykey" -> "myval" map.put("mykey","myval") ...

Class Constructor/Setter

Hi, I'm fairly new to Scala, coming from a basic Java background. I looked at how to implement class constructors and how to provide some logic in the setter for a field of that class. class SetterTest(private var _x: Int) { def x: Int = _x def x_=(x: Int) { if (x < 0) this._x = x * (-1) } } The constructor pa...

How to test presence of a set of types in a collection of object of base type?

I need to intersect types of incoming objects with a set of predefined ones. The raw approach is to scan an incoming collection for each predefined type: trait Field class Field1 extends Field class Field2 extends Field class Field3 extends Field ... class FieldManager(shownFields:Iterable[Field]) { var hiddenFields = new ArrayBuffe...