w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
  Home » SCALA » Page 1
Can I change SORM id type to UUID?
I didn't find nothing related in the Web today. But I checked the source code that is on https://github.com/sorm/sorm and everything that is related with ID is using Long. On the core they are using this class https://github.com/sorm/sorm/blob/master/src/main/scala/sorm/core/Util.scala to ensure that the id will be converted property to a Long value. In other words this framework seems to be pre

Categories : Scala

Regarding FoldLeft with list and map in scala
// define case class case class Definition(name: String, status: String) // read objects from json // i use test data to simplify example val list = List( Definition("name1", "status1"), Definition("name2", "status2"), Definition("name3", "status3") ) // transform list to map list.map(d => d.name -> d).toMap To convert from json you can use: val objectList = definitionList .fo

Categories : Scala

Error:scalac: bad option: -P (IntelliJ IDEA)
Just change the scala compiler parameters to -Xplugin:/your/user/home/.m2/repository/org/scalamacros/paradise_2.10.4/2.0.1/paradise_2.10.4-2.0.1.jar (of course giving your valid home folder) in Preferences -> Build, Execution, Deployment -> Compiler -> Scala compiler -> Additional compiler options = <some parameters> (as said in the question) This s

Categories : Scala

Play Framework 2.4 scala application/form-urlencoded
scala> Map("email" -> collection.mutable.ArrayBuffer("maskedinesh@gmail.com")) res5: scala.collection.immutable.Map[String,scala.collection.mutable.ArrayBuffer[String]] = Map(email -> ArrayBuffer(maskedinesh@gmail.com)) scala> res5.get("email").get(0) res6: String = maskedinesh@gmail.com

Categories : Scala

Scala: Weird result from 'if' statement
scala> val index = "male-names" index: String = male-names there is a little typo error scala> val kind = if (index == "male-mames") "mn" else "fn" ^ kind: String = fn

Categories : Scala

How to hold hexadecimal values in Scala?
Try BigInt. Usage example: scala> val i = BigInt("0000030000010000010000020000090000030000040000070000EF", 16) i: scala.math.BigInt = 18831305580304483748966372317094081267935079240643756687599 scala> i.toString(16) res3: String = 30000010000010000020000090000030000040000070000ef

Categories : Scala

Thymeleaf with springboot and Scala not rendering HTML page
If you want the response to render a view, annotate your class with @Controller rather than @RestController @RestController tells Spring that the return value is the body of the response, i.e. no view rendering will occur. It's the equivalent of annotating the class with @Controller and each method with @ResponseBody.

Categories : Scala

How to use AspectJ with Sbt to generate SWF client classes
AspectJ is not used to generate client classes. It is used only to inject interceptors for @Asynchronous and @ExponentialRetry annotations. The client side classes are generated using SWF annotation processor. I don't know anything about Scala. But in Java you can write workflows without generated client classes using generic API that generated code relies on. To get these generic clients use ge

Categories : Scala

Creating a HashMap from a file
You have two mistakes in line invMap = invMap ++ List(temp(0),(temp(1),temp(2))): method ++ accepts Map argument but Iterable if you want add new key-value pair to your map use -> to create pair and += to add it to map. Use invMap += temp(0) -> (temp(1),temp(2)) instead of that line.

Categories : Scala

Putting out the Bonfire of the Arities with Shapeless?
If I understand the problem well, you would like a function that given an HList of DimensionConfig[T] would give you a Dimension with the type parameters All and Configs set to the right types and an implementation of extractAll. (Correct me if I'm wrong :-) So a dependent function à la shapeless should be able to provide that: trait DimensionsOf[L <: HList] extends DepFn1[L] { type All &l

Categories : Scala

Scala build.sbt: Solving dependency recursions
This isn't really an SBT problem, but a module dependency problem. Ignoring A for a moment, since B needs C to compile and C needs B to compile, this cycle cannot be resolved by any build system. The only way to solve this is to change the structure of the modules themselves. For example, if possible, you could create a D project that contains the common classes and have them both rely on it. Or,

Categories : Scala

Scala map() on a Map[..] much slower than mapValues()
mapValues actually returns a view on the original map, which can lead to unexpected performance issues. From this blog post: ...here is a catch: map and mapValues are different in a not-so-subtle way. mapValues, unlike map, returns a view on the original map. This view holds references to both the original map and to the transformation function (here (_ + 1)). Every time the returned ma

Categories : Scala

Scala: Array of Maps
First, let me ask you a question: what is the type of your ArrayOfMaps variable? If you were to annotate the type explicitly, what would you declare it as? Even though Scala has type inference, it is still a statically typed language. Your variable will have a (static) type, and this will determine what methods are available on it. And this is a problem here, because the value type of some key

Categories : Scala

Spark scala : iterable to individual key-value pairs
Here's something that produces the pairs (and removes repeated ones). I couldn't work out how to use CompactBuffer so it uses ArrayBuffer, since the source for CompactBuffer says it's a more efficient ArrayBuffer. You may need to convert your CompactBuffer in the flatMap to something that supports .combinations. object sparkapp extends App { import org.apache.spark.SparkContext import org.apache.

Categories : Scala

Customize slick code generator
For RichTable you need to override def code of Table. See https://github.com/slick/slick/blob/2.1/slick-codegen/src/main/scala/scala/slick/codegen/AbstractSourceCodeGenerator.scala#L128

Categories : Scala

Play Framework: Block the bootstrap thread onStart
Yes, Global.onStart will block before the first request. The GlobalSettings object in Play is a plugin. When the application is started, the routes are loaded first, then the plugins are loaded serially by calling the onStart method of each. The GlobalSettings plugin comes last in this initialization, which ensures that all other plugins are loaded first so that all of your db connections, cache,

Categories : Scala

Saving a string to HDFS creates line feeds for each character
I wasn't able to get this working exactly as I wanted, but I did come up with a work around. I saved the device locally and then called a shell command through Scala to upload the completed file to HDFS. Pretty straightforward. Would still appreciate if anyone could tell me how to copy a string directly to a file in HDFS though.

Categories : Scala

Play with Activator Issue on IntelliJ Idea 14
Have you tried File | Import Project and select build.sbt file? IDEA imports it as an SBT project, with all the dependencies properly resolved. It works fine for me on IDEA 14 and on 13.

Categories : Scala

How to check if element exist in three lists using scala?
Try this: list1.filter(e => e._1.intersect(list2(0)) == list2(0) // check if first element contains second list && list3.contains(e._2)) // check if third list contains second element

Categories : Scala

correlation in gatling tool
For correct correlation you should add into variables all changing data (the data, which can change per request). For example: user session, username, password, depart, date, number of passengers, address etc. It's depend on what data you need to change. .param("""arrive""", """London""") -> Correlation you should apply to string "London", .param("""numPassengers""", """1""") -> Correlation you s

Categories : Scala

How to implement master/slave structure with squeryl and play framework
I don't tend to use MySQL myself, but here's an idea: Based on the documentation here, the MySQL JDBC driver will round robin amongst the slaves if the readOnly attribute is properly set on the Connnection. In order to retrieve and change the current Connection you'll want to use code like transaction { val conn = Session.currentSession.connection conn.setReadOnly(true) //Your code here }

Categories : Scala

Order by value in spark pair RDD
This should work: //Assuming the pair's second type has an Ordering, which is the case for Int rdd.sortBy(_._2) // same as rdd.sortBy(pair => pair._2) (Though you might want to take the key to account too when there are ties.)

Categories : Scala

Spark SQL: automatic schema from csv
val schemaString = "name age".split(" ") // Generate the schema based on the string of schema val schema = StructType(schemaString.map(fieldName => StructField(fieldName, StringType, true))) val lines = people.flatMap(x=> x.split(" ")) val rowRDD = lines.map(line=>{ Row.fromSeq(line.split(" ")) }) val peopleSchemaRDD = sqlContext.applySchema(rowRDD, schema) May be this link will hel

Categories : Scala

scala api document in REPL
Is it true that only way to find api document is by browsing document with web form or am I missing? It sort of is true at this point. I wrote an sbt plugin sbt-man but its ability is limited. > man Traversable /: [man] scala.collection.Traversable [man] def /:[B](z: B)(op: (B ⇒ A ⇒ B)): B [man] Applies a binary operator to a start value and all elements of this collection, going lef

Categories : Scala

How to import Maven libraries with SBT?
You just treat remote Maven repositories normally. Unless you want to utilize your local .m2/repository. See below for an example Build.scala using both: object myBuild extends Build { lazy val mainProject = Project( id="root", base=file("."), settings = Project.defaultSettings ++ Seq( name := "Root project", scalaVersion := "2.11.4", version := "0.1", resolv

Categories : Scala

What to do when website not responding with HTTP error code?
You can use HttpAsyncClient for your request https://hc.apache.org/httpcomponents-asyncclient-dev/quickstart.html So your call will be: val futureResponse: Future<HttpResponse> = httpclient.execute(request1, null); And you can make further processing using onComplete for a Future. Another option is to use some Scala native library, like http://dispatch.databinder.net/Bargaining+with+f

Categories : Scala

Is it correct to use `Future` to run some loop task which is never finished?
If you are just running one thread (aside from the main thread), it won't matter. If you do this repeatedly, and you really want lots of separate threads, you should use Thread since that is what it is for. Futures are built with the assumption that they'll terminate, so you might run out of pool threads.

Categories : Scala

Scala, GUI and immutability
Despite the extra effort, take the second approach. Create small mutable "view" instances for each of your model. Bind the views to the widgets and install observers or hooks that update the view proxies based on changes in your model. Don't let the GUI API dictate how your concurrency approach and model should look like. I believe there are a few open source libraries around that provide a more

Categories : Scala

SORM Framework: whereContains
It seems like in whereContains the path should refer to some collection, for example if you were searching for a name within a set of nested names of some entity. What you want is to use whereLike("name", "Pavel"), which uses an SQL LIKE clause used for substring matching.

Categories : Scala

akka simple cluster with two seed nodes
Make the seed-node to have the same port 2551 and specify under remote as below. remote{ transport = "akka.remote.netty.NettyRemoteTransport" cluster { seed-nodes = [ "akka.tcp://myCluster@10.0.0.5:2551", "akka.tcp://myCluster@10.0.0.5:2551"] use-dispatcher = cluster-dispatcher } cluster-dispatcher { type = "Dispatcher" executor = "fork-join-executor"

Categories : Scala

akka timeout when using spray client for multiple request
Akka ask timeout is implemented via firstCompletedOf, so the timer starts when the ask is initialized. What you seem to be doing, is spawning a Future for each line (during the map) - so all your calls execute nearly at the same time. The timeouts start counting when the futures are initialized, but there are no executor threads left for all the spawned actors to do their work. Hence the asks tim

Categories : Scala

How to change function context
Generically no. The usual approach to building a DSL is to use some kind of "command" objects, perhaps with the Free Monad: object MyClass { sealed trait Command case class CallMyMethod() extends Command def myMethod() = liftF[Command, Unit](CallMyMethod()) } case class MyClass(param: String)(body: Free[Command, Unit]) { ... body.resume.fold({ case CallMyMethod() => mymethod()

Categories : Scala

Is it possible to join two instances of the same RDDs
Why go the trouble of joining the rdd? You could just map the initial rdd to the desired outcome: val firstFirst= secondFirst.map{case (second, first) => (first, first)}

Categories : Scala

Unable to use ScalaCheck with Scala IDE for Eclipse
When I added this jar to the project I was able to build the example files: http://search.maven.org/#artifactdetails%7Corg.scala-lang.modules%7Cscala-parser-combinators_2.11%7C1.0.2%7Cbundle

Categories : Scala

why the constructor doesn't work with covariance in scala
why replace works but not this? Constructors can't take type parameters (and that's the message I get in 2.10 instead of can't find symbol U). But even if they could, replace returns C[U] and the constructor must return C[T]. and the right way to do this Make it a method in companion object: object C { def apply[U](value: U) = new C(value, Nil) // note that you no longer need T here

Categories : Scala

Finding right type class to use
There you go. See my comment for details. import java.util.concurrent.{TimeoutException, ExecutionException} type Result = String val badRequest: Result = "BadRequest" val requestTimeout: Result = "RequestTimeout" val serviceUnavailable: Result = "ServiceUnavailable" class Logger { def error(s: String) = println(s + " ") } trait ResponseError[E] { def report(e: E)(impl

Categories : Scala

Extracting a value of a given type from a case class
I guess you have to pass ga explicitly with the call, because otherwise it will not be in scope for the called function (i.e. fromCaseClass): def getByType[C, X](value: C)(implicit ga: Generic.Aux[C, X]): X = { fromCaseClass(value)(ga).select[X] } Other way would be to bring this parameter into scope before fromCaseClass is called: def getByType[C, X](value: C)(implicit ga: Generic.Aux[C, X]

Categories : Scala

error: ')' expected but '(' found
Just wrap the spark master URL inside double quotes as its just a string. Hence it should look like, val sc = new SparkContext("spark://hdn1001.local:7077", "Scala Word Count",System.getenv("SPARK_HOME"), SparkContext.jarOfClass(this.getClass))

Categories : Scala

ScalaMock verifying a generic method returning Unit gives method overloading compile error
You've got wrong type for 'verify' method, it should be Int. stubService is type of Service[Int] and container is also Container[Int] => in DoesMatch you pass Int to service (stubService.doWork _).verify(container.value)

Categories : Scala




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.