Dear all,
I am wondering, would you please let me know how can I use lift-json to serialize a simple bean class into json string (I'm using v2.0-M1).
I tried:
val r = JsonDSL.pretty(JsonAST.render(myBean))
and I am getting
[error] found : MyBean
[error] required: net.liftweb.json.JsonAST.JValue
Thanks,
-A
...
I am new to Scala and but very old to Java and had some understanding working with FP languages like "Haskell".
Here I am wondering how to implement this using Scala. There is a list of elements in an array all of them are strings and I just want to know if there is a way I can do this in Scala in a FP way. Here is my current version wh...
I'm trying to write a trait (in Scala 2.8) that can be mixed in to a case class, allowing its fields to be inspected at runtime, for a particular debugging purpose. I want to get them back in the order that they were declared in the source file, and I'd like to omit any other fields inside the case class. For example:
trait CaseClassRef...
Hi all,
I have a exception from lift-json when I want to deserialize a json string. (using v2M1).
Basically I have the following class:
@BeanInfo
case class Game(val id:Int,
val bad:Map[String,Plan],
val good:Map[String,Plan])
and I am using
net.liftweb.json.Serialization.read[Game](jsonInString)
to deserialize the jsonInString...
In Scala, I've seen the constructs
trait T extends S
and
trait T { this: S =>
used to achieve similar things (namely that the abstract methods in S must be defined before an instance may be created). What's the difference between them? Why would you use one over the other?
...
I want to copy file a.txt to newDir/ from within a scala script.
In java this would be done by creating 2 file streams for the 2 files, reading into buffer from a.txt and writing it to the FileOutputStream of the new file.
Is there a better way to achieve this in scala? May be something in scala.tools.nsc.io._. I searched around but co...
I'd like to utilize an etherpad interface on my website. Two questions:
1) is there any site with an etherpad api that I could just call remotely?
2) if not, how much trouble is it to install scala and have the two run concurrently?
Thanks
...
This is a follow-up now that Scala 2.8.0 beta is out to this question:
http://stackoverflow.com/questions/1710813/what-is-a-proper-way-to-manage-flexible-typed-immutable-data-structures-in-scal
The new technique is to copy a case class, e.g.
case class Person(name:String, email:String)
val bob = Person("Bob", "[email protected]")
val jill = ...
In Java byte[] st = new byte[4096], implies that size of array st will not exceed 4096 bytes.
The Scala equivalent is st:Array[byte] = Array() where size is unknown. If I am reading a huge file into this array, then how can I limit the size of the array?
Will there be any side effect if I don't care about the size for the above operat...
I'm part of a group that starts a new development project from scratch.
Currently it is on hobby-basis but we aim to make it our living
in the time frame of 1-2 years.
We are senior developers coming from a multitude of languages and techniques
with much of the focus on Java for the last few years.
Now, we're thinking of choice of tools...
How to make error handlers in Lift? I have html page with some snippets, if one of those snippets throws an exception I want to catch it and redirect to some user friendly error page.
How to do this in catch-all manner? I do not want to put error handling to each snippet separately. I am looking something like this in Wicket.
...
I have a Set in Scala (I can choose any implementation as I am creating the Set. The Java library I am using is expecting a java.util.Set[String].
Is the following the correct way to do this in Scala (using scala.collection.jcl.HashSet#underlying):
import com.javalibrary.Animals
var classes = new scala.collection.jcl.HashSet[String]
c...
I created a simple Java/JSP web app and added a basic Scala servlet. Everything works and I've included the Scala file and web.xml below. How can I modify my little "trainer" servlet so I can query a MySql table and generate an HTML <table>...</table>. Btw, I will look into Lift at a later time. At the moment, my plan is to add a sev...
I have the following problem: I have a function which takes a List[Double] as parameter, performs some arithmetic operations on the elements of the list and than return the result. I would like the function also to accept List[Int]. Here is an example:
def f(l: List[Double]) = {
var s = 0.0
for (i <- l)
s += i
s
}
...
I had some experience in Haskell and currently learning Scala. Am wondering whether there is something equivalent to Monads in Scala??
...
I have a Scala app with a list of items with checkboxes so the user select some, and click a button to shift them one position up (left). I decided to write a function to shift elements of some arbitrary type which meet a given predicate. So, if you have these elements:
a b c D E f g h I
and the predicate is "uppercase characters", th...
On compiling the following code with Scala 2.7.3,
package spoj
object Prime1 {
def main(args: Array[String]) {
def isPrime(n: Int) = (n != 1) && (2 to n/2 forall (n % _ != 0))
val read = new java.util.Scanner(System.in)
var nTests = read nextInt // [*]
while(nTests > 0) {
val (start, end) = (read nextInt, read n...
There are a few resources on the web that are instructive in writing Scala compiler plugins that pattern-match against the code, but these don't help in generating code (constructing symbol trees). Where should I start to figure out how to do this? (If there's an easier way than to manually build symbol trees, I'd be interested as well.)...
Was trying to compile some code from this SO question and run into this error message cannot find class manifest for element type T. Here is another snippet that shows the behavior:
scala> def f[T](a:T, b:T):Array[T] = { new Array[T](2) }
<console>:4: error: cannot find class manifest for element type T
def f[T](a:T, b:T):Array[T...
I was trying to write a testing/timing function for answers provided in this SO question. Some answers work on Array[T], some on List[T], one on Iterable[T] and one on String!
What I'd like to write is a function that takes the shift* functions from the question or the answers, an input list, a predicate and an expected output and run t...