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("...
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...
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?
...
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.
...
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
...
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...
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...
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)...
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 ...
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://...
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))
...
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...
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?
...
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
...
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 ?
Here are some failed attempts:
val map = scala.collection.mutable.Map
map("mykey") = "myval"
map += "mykey" -> "myval"
map.put("mykey","myval")
...
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...
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...