answerstu

converting par array to array in scala

How can we convert ParArray[(Double, Double, Double, Double, Double)] to Array[(Double, Double, Double, Double, Double)] I have to do this as part of creating the data frame using sc.parallelize(Array[(Double,...)])Apart from hardcoding (like below) is there any other way?for(x1 <- 0 until a.length){ new_a(x1)(0) = a(x1)._1 new_a(x1)(1) = a(x1)._2 new_a(x1)(2) = a(x1)._3 new_a(x1)(3) = a(x1)._4 new_a(x1)(4) = a(x1)._5 }...Read more

scala 2.10 - How to get some forms from request?

So, I've this form in server side:case class Employe(id: Int, name: String)val myForm = Form( mapping( "id" -> number, "name" -> text ) (Employe.apply) (Employe.unapply))So, in client side I need send three same forms to the server:<html> <body> <div class="employe"> <input type="number" class="employe_id"/> <input type="text" class="employe_name"/> </div> <div class="employe"> <input type="number" class="employe_id"/> <input type="text" class="empl...Read more

scala 2.10 - Using a BodyParser with an authenticated request in Play 2.2.1 Framework

So, my authentication process is asynchronous. I need upload file but, I don't know how I can add 'multipart/form-data' BodyParser parameter to action.This is Secured trait:trait Secured { private def username(request: RequestHeader) = request.session.get("email") private def onUnauthorized(request: RequestHeader) = Results.Redirect(routes.Auth.login) def IsAuthenticated(f: => String => Request[AnyContent] => Future[SimpleResult]) = Security.Authenticated(username, onUnauthorized) { user => Action.async { request => ...Read more

enhanced assert scala macro

I’ve come across some annoying problems when using asserts where there is eitherno good information available: why did it fails, and what the assert was aboutthe assert information is buried under a sea of unneeded information like too many layers of scala functions.I’ve kept these issues in the back of my head and, now that new scala macros are available , I plan to go on Stack Overflow and create a high-value question and answer pair for each issue. That way, the next person who has the problem won’t have to slog through so much misinformatio...Read more

simple scala macro

I would like to have a scala macro that does the following:When I write:myCreateCityMacro("paris")myCreateCityMacro("vallorbe")I would like to get:val paris = new City("paris")val vallorbe = new City("vallorbe")...Read more

scala 2.10 - get calling function with more hierarchical depth

The following code gets the calling function (like C _ _ FUNC _ _):def __func__(c: Context) = { import c.universe._ c.enclosingMethod match { case DefDef(mods, name, tparams, vparamss, tpt, rhs) => c.universe.reify(println( "\n mods "+c.literal(mods.toString).splice +"\n name "+c.literal(name.toString).splice +"\n tparams "+c.literal(tparams.toString).splice +"\n vparamss "+c.literal(vparamss.toString).splice +"\n tpt "+c.literal(tpt.toStr...Read more

scala 2.10 - ReactiveMongo : How to write macros handler to Enumeration object?

I use ReactiveMongo 0.10.0, and I have following user case class and gender Enumeration object:case class User( _id: Option[BSONObjectID] = None, name: String, gender: Option[Gender.Gender] = None)object Gender extends Enumeration { type Gender = Value val MALE = Value("male") val FEMALE = Value("female") val BOTH = Value("both")}And I declare two implicit macros handler:implicit val genderHandler = Macros.handler[Gender.Gender]implicit val userHandler = Macros.handler[User]but, when I run app...Read more