Tagged Questions
Scala is a general purpose programming language principally targeting the Java Virtual Machine. Designed to express common programming patterns in a concise, elegant, and type-safe way, it fuses both imperative and functional programming styles. Its key features are: advanced static type system ...
0
votes
0answers
10 views
Declare variable whose type is a function's return type
I'm currently using a type alias:
type FooType = Int
val foo = (_: Int) * 2
def takeFooRet(x: FooType) = ...
however, I'd like to do something like:
val foo = (_: Int) * 2
def takeFooRate(x: ...
0
votes
0answers
7 views
Using FunSuite to test Spark throws NullPointerException
I would like to use FunSuite to test my Spark jobs by extending FunSuite with a new function, called localTest, that runs a test with a default SparkContext:
class SparkFunSuite extends FunSuite {
...
3
votes
1answer
54 views
Difference between isInstance and isInstanceOf
Is there a difference between classOf[String].isInstance("42") and "42".isInstanceOf[String] ?
If yes, can you explain ?
0
votes
1answer
14 views
How to set amount of Spark executors?
How could I configure from Java (or Scala) code amount of executors having SparkConfig and SparkContext? I see constantly 2 executors. Looks like spark.default.parallelism does not work and is about ...
0
votes
1answer
13 views
Scala - StdTokenParsers parse not exactly as expected
I have an assignment to parse a demo language, this is the code that has problems in it, the other work as I expected:
def sttment: Parser[Any] = sttm | "{" ~ rep(attributes) ~ rep(sttment) ~ "}"
...
1
vote
3answers
50 views
Multiple statements in for loop's
In java you can do something like this:
Boolean foo = true;
for(int i=0; i<10 && foo; i++){
doSomething();
}
Is it also possible in Scala?
1
vote
2answers
17 views
How to create a function that will only accept types that can be converted toJson with spray-json
I have a function that will take a parameter of some type, convert that parameter toJson and then return it. The issue here is that my function can't call .toJson on the parameter because it's not ...
1
vote
1answer
25 views
No implicit view available for partially applied method
So I have the following method that wraps a Seq-like object in an Option.
def noneIfEmpty[S <% Seq[_]](seq: S): Option[S] = {
if (seq.isEmpty) None else Some(seq)
}
I'd like to be able to use ...
1
vote
3answers
50 views
Idiomatically evaluate true if Option contains specific value
I want to write a method that returns true if an Option[Int] contains a specific value and false otherwise. What is the idiomatic way of doing this?
var trueIf5(intOption: Option[Int]): Boolean {
...
0
votes
1answer
32 views
Group By including empty rows
I want to create a query that returns all groups with users count (including empty groups)
SELECT g.id, count(relation.user_id) FROM groups g
FULL JOIN users2groups relation ON g.id=r.group_id
...
1
vote
1answer
26 views
decoding scalacheck and scalatest code
I was trying to decipher what this actually means
check { (n: Int) =>
n > 1 ==> n / 2 > 0
}
from http://www.scalatest.org/user_guide/writing_scalacheck_style_properties
I am first ...
0
votes
1answer
46 views
PHP vs Scala / Akka for high performance & scaling [on hold]
I really need some help with this.
I'm currently developing a web application that needs to be server scalable , fast and cpu intensive (generating reports from million of rows in Riak DB)
Can PHP ...
5
votes
1answer
46 views
How to run sequence over List[F[G[A]]] to get F[G[List[A]]]
Is it possible to transform a List[F[G[A]]] into F[G[List[A]]] nicely?
I can do this in Scalaz the following way:
val x: List[Future[Option[Int]]] = ???
val transformed: Future[Option[List[Int]]] = ...
0
votes
1answer
14 views
Making key value pairs from an HDFS sequence file using Apache Spark
What is the best way to make key value pairs out of a HDFS sequence file? The reason why I am asking, I have to sort a sequence file. The sortByKey method is not available unless your RDD is in the ...
0
votes
1answer
19 views
How to define a trait so that we extend with classes that have context bounds?
Suppose I want to be able to do:
trait MyTrait[T: Numeric] {
val numeric = implicitly[Numeric[T]]
import numeric.mkNumericOps
// more code
}
Then extend with
class MyClass[T: Numeric] ...
1
vote
3answers
75 views
Is there an equivalent of Scala's Either in Java 8?
Just like java.util.Optional<T> in Java 8 is (somewhat) equivalent to Scala's Option[T] type, is there an equivalent to Scala's Either[L, R]?
1
vote
0answers
45 views
Syntax to dynamically add mixin to an actor
I have an actor that sends messages to another actor. It also creates this other actor and does not know its type at compile time. On creation it needs to add a mixin. I am wondering how to solve this ...
2
votes
1answer
55 views
Currying in Scala: multiple parameter lists vs returning a function
When using the following syntax to define functions with currying enabled:
def sum(x: Int)(y: Int)(z: Int) = x + y + z
one still has to suffix any calls to curried calls of sum with _:
sum _
...
0
votes
0answers
15 views
How to resolve error “play - Cannot invoke the action, eventually got an error: java.lang.IllegalArgumentException: can't serialize class” in scala?
I am using scala case classes and play framework to process some data.
Here is a my code:
case class myClass(
datastores: Option[List[DataStores]])
case class DataStores(
name: Option[String],
...
0
votes
0answers
24 views
Play Framework 2.3: using scala action composition in java controller
For reasons stemming from this question I need to write a custom action composition in scala that can be then used in java controller, something like this:
LogAction.scala (Scala Custom Action ...
0
votes
0answers
12 views
Import a new library on Android causes OutOfMemoryException While Dexing
I have added in the SBT build the library https://github.com/JoanZapata/android-pdfview
But now my project can't be compiled anymore, It arrives at dexing time and then said:
at ...
0
votes
0answers
7 views
how to aggregate multiple collections in salat mongodb
I have three collections like WindowsCollection,EsxCollection and
LinuxCollection in these all three collections documents i have
cpuUtilization,memoryUtilization,hostID keys. Now i have to find top
...
0
votes
1answer
35 views
Play Framework 2.3: custom action composition to log request and response
I'm working on Play 2.3 (Java) application and I need a custom Action Composition to log request and response. With what I've got so far I am able to get the body of request, but not response:
import ...
0
votes
1answer
42 views
How do I get the TypeTag for an Array's element type?
Given a variable x of type X <: Any, a type tag for X and pattern matching recovers that x is an Array[_] I would like to map over that array with a function that wants a type tag for the elements. ...
1
vote
1answer
20 views
How to reference a custom SBT Setting in sub-projects
Somewhat similar to this question, how can reference a custom setting in a sub project.
In build.sbt:
import sbt.Keys._
val finagleVersion = settingKey[String]("Defines the Finagle version")
val ...
1
vote
1answer
11 views
Handling json data with angularjs on play scala 2.3.4
I would like to render Json to angularJs in my view, so in a file events.scala.html I have this :
@(events: play.api.libs.json.JsValue)
@events
And it works fine, my Json data is displayed on my ...
0
votes
1answer
28 views
Apache Spark - Reduce Step Output (K, (V1,V2, V3, …)
I have a chronological sequence of events (T1,K1,V1),(T2,K2,V3),(T3,K1,V2),(T4,K2,V4),(T5,K1,V5).
Both keys and values are strings.
I am trying to achieve the following using Spark
K1,(V1,V2,V5)
...
0
votes
2answers
66 views
In Scala, how can I merge maps as below?
I would like to know how I can merge maps in Scala.
val prevMap = Map(1-> Set("a"), 2-> Set("b"))
val newMap = Map(2-> Set("a","b"),1-> Set("c"))
val expected = Map(1->Set("a","c"), ...
0
votes
1answer
45 views
Limit number of active threads/cores a JVM can use [duplicate]
I have a piece of code in Scala (using Java execution context) that spawns many threads.
Also I have an 8 core CPU.
When the process runs it uses up all the juice my computer has and I cannot do ...
0
votes
0answers
38 views
Error using Spring, Play Framework, Hibernate and MySql
I'm a long time trying to turn the architecture play-spring-hibernate but everytime I try the the following error:
I've tried reset and reconfigure often.
Is it that I am missing some dependency?
...
2
votes
1answer
69 views
Scala: implicits, subclassing and member types
Lets say we want to use type classes to implement pretty printing:
trait Printer[T] {def print(t: T)}
with default implementation for ints:
implicit object IntPrinter extends Printer[Int] {
...
2
votes
1answer
72 views
Extending a scala class with less ceremony
I am probably doing something wrong.
When I extend a class, I specify the mapping between the extendee's constructor and the extended class constructor:
class Base(one: String, two: String)
case ...
1
vote
2answers
57 views
Wait for an actor response indefinitely in a future akka java
I have a non-actor-based piece of code which delegates some operations to an akka actor and I would like to wait this actor response indefinitely, I mean, until this actor returns a response whatever ...
1
vote
1answer
49 views
scala curried function with yield
I try to learn curried functions in Scala,
see the code
def isEven(v: Int): Boolean = v % 2 == 0
def evens(numbers: List[Int])(even: Int => Unit) {
for (number <- numbers; if ...
0
votes
1answer
56 views
Scala reference to 'tupled' generically from case class
I'm trying to write a boilerplate function that can take a pair of generic case class objects and perform some operations on their set of vals and then return a new instance of the case class.
On a ...
0
votes
1answer
29 views
Scala parsing package doesn't recognized
I try to import the scala.util.parsing library and the eclipse compiler doesn't recognized it.
How can I fix it?
-5
votes
0answers
55 views
How to write code to define a for comprehension in scala [on hold]
I can't seem to find this and I know how to write a for loop(say with my own method named forLoop instead of a for), but how would one write a for comprehension function.
There is a great example on ...
0
votes
0answers
27 views
Conditional get in Spring framework using scala
As soon as I use
@Context req : Request
It throws me exception as below
"exception": "org.springframework.beans.BeanInstantiationException",
"message": "Could not instantiate bean class ...
0
votes
0answers
21 views
Akka FSM timer stops sending message
I have a Akka FSM actor that uses a SetTimer indefinitely. I have seen it few times that the timer does not dispatch the message. Has anyone seen this behavior or any gotcha that I have to avoid while ...
5
votes
2answers
80 views
Group List elements with a distance less than x
I'm trying to figure out a way to group all the objects in a list depending on an x distance between the elements.
For instance, if distance is 1 then
List(2,3,1,6,10,7,11,12,14)
would give
...
2
votes
2answers
65 views
Scala: Condense Array[(String, Array[Double])] to Array[(String)]
I have an array that looks like this Array((1,Array(1.0,0.0,3.0)), (2,Array(0.0,2.0,1.0))) that I want to turn into and array that looks like: Array((1,1.0,0.0,3.0),(2,0.0,2.0,1.0)).
Is there an easy ...
1
vote
1answer
57 views
Assign an operator to a variable in Scala
Given this spinet of code in Scala:
val mapMerge : (Map[VertexId, Factor], Map[VertexId, Factor]) => Map[VertexId, Factor] = (d1, d2) => d1 ++ d2
That can be shortened to:
val mapMerge : ...
0
votes
1answer
23 views
Scala Future exception contract compared to Objective-C NSError **
I have strong Objective-C background and I'm trying to write Scala.
In Objective-C exceptions are used to indicate unrecoverable (mostly) errors. And there is NSError ** contract in methods which ...
0
votes
2answers
36 views
How can I run a single failed test in Intellij?
I'm running a bunch of Scala tests in IntelliJ. One is failing. I can't seem to be able to run just that one failing test (ala Visual Studio) - surely there must be a way to do this in the IDE?
0
votes
1answer
41 views
How to run Scala code in SBT Build.scala just before compile of Scala files?
I'm trying to run some Scala code, just for the moment to println out "Hello", but I wish to run the Scala code just before compile of Scala code in SBT project. I found that in build.sbt the ...
1
vote
2answers
55 views
what to choose between require and assert in scala
Both require and assert are used to perform certain checks during runtime to verify certain conditions.
So what is the basic difference between them ,the only I seem is that
require throw ...
1
vote
1answer
25 views
what options can be passed to flashing in play framework
Hello there Grammarians,
The documentation only shows:
flashing("success")
Do failures never happen if i use play? ive tried "failure" & "error" they dont do anything
thanks
1
vote
0answers
17 views
Scala / Play2 - dynamic constraints based on checkbox value
I hava a template that creates a checkbox and a text input field:
@helper.checkbox(inputForm("live"), 'checked -> true, 'onclick -> "hideTextFields()")
@helper.inputText(inputForm("target"), ...
1
vote
1answer
18 views
Spark AccumulatorParam Generic Parameters
I have a problem with using accumulators in Spark. As seen on the Spark website, if you want custom accumulators you can simply extend (with an object) the AccumulatorParamtrait. The problem is that I ...
1
vote
0answers
26 views
Scala http client for large files
I need to write an HTTP client that will periodically download (and dump on disk) files that are much larger than the available memory.
What's the most appropriate strategies and HTTP client ...