scala

WeakTypeTag v. TypeTag

有些话、适合烂在心里 提交于 2021-01-21 04:35:07
问题 In the REPL, I'm writing out the examples from Reflection - TypeTags and Manifests. I'm confused by the difference between WeakTypeTag and TypeTag . scala> import scala.reflect.runtime.universe._ import scala.reflect.runtime.universe._ TypeTag scala> def paramInfo[T](x: T)(implicit tag: TypeTag[T]): Unit = { | val targs = tag.tpe match { case TypeRef(_, _, args) => args } | println(s"type tag of $x has type arguments $targs") | } paramInfo: [T](x: T)(implicit tag: reflect.runtime.universe

Spark Select with a List of Columns Scala

喜欢而已 提交于 2021-01-21 04:22:35
问题 I am trying to find a good way of doing a spark select with a List[Column, I am exploding a column than passing back all the columns I am interested in with my exploded column. var columns = getColumns(x) // Returns a List[Column] tempDf.select(columns) //trying to get Trying to find a good way of doing this I know, if it were a string I could do something like val result = dataframe.select(columnNames.head, columnNames.tail: _*) 回答1: For spark 2.0 seems that you have two options. Both

Spark Select with a List of Columns Scala

一笑奈何 提交于 2021-01-21 04:22:05
问题 I am trying to find a good way of doing a spark select with a List[Column, I am exploding a column than passing back all the columns I am interested in with my exploded column. var columns = getColumns(x) // Returns a List[Column] tempDf.select(columns) //trying to get Trying to find a good way of doing this I know, if it were a string I could do something like val result = dataframe.select(columnNames.head, columnNames.tail: _*) 回答1: For spark 2.0 seems that you have two options. Both

Execution Context and Dispatcher - Best practices, useful configurations and Documentation

半腔热情 提交于 2021-01-20 14:29:10
问题 Scala Execution Context and Dispatchers - Listing and comparison: Why ? There are a lot of questions around what/how/what is the best Execution Context to use to execute futures on in Scala and how to configure the dispatcher. Still I never was able to find a longer list with pros and cons and configuration examples. The best I could find was in the Akka Documentation: http://doc.akka.io/docs/akka/snapshot/scala/dispatchers.html and Play Documentation https://www.playframework.com

Understand how to use apply and unapply

二次信任 提交于 2021-01-20 14:24:21
问题 I'm trying to get a better understanding of the correct usage of apply and unapply methods. Considering an object that we want to serialize and deserialize, is this a correct usage (i.e. the Scala way ) of using apply and unapply ? case class Foo object Foo { apply(json: JValue): Foo = json.extract[Foo] unapply(f: Foo): JValue = //process to json } 回答1: Firstly, apply and unapply are not necessarily opposites of each other. Indeed, if you define one on a class/object, you don't have to define

Get the module symbol, given I have the module class, scala macro

瘦欲@ 提交于 2021-01-20 13:08:23
问题 I'm trying to build a simple typeclass IsEnum[T] using a macro. I use knownDirectSubclasses to get all the direct subclasses if T , ensure T is a sealed trait, and that all subclasses are of case objects (using subSymbol.asClass.isModuleClass && subSymbol.asClass.isCaseClass ). Now I'm trying to build a Seq with the case objects referred by the subclasses. It's working, using a workaround: Ident(subSymbol.asInstanceOf[scala.reflect.internal.Symbols#Symbol].sourceModule.asInstanceOf[Symbol])

Get the module symbol, given I have the module class, scala macro

。_饼干妹妹 提交于 2021-01-20 13:02:02
问题 I'm trying to build a simple typeclass IsEnum[T] using a macro. I use knownDirectSubclasses to get all the direct subclasses if T , ensure T is a sealed trait, and that all subclasses are of case objects (using subSymbol.asClass.isModuleClass && subSymbol.asClass.isCaseClass ). Now I'm trying to build a Seq with the case objects referred by the subclasses. It's working, using a workaround: Ident(subSymbol.asInstanceOf[scala.reflect.internal.Symbols#Symbol].sourceModule.asInstanceOf[Symbol])

Get the module symbol, given I have the module class, scala macro

寵の児 提交于 2021-01-20 13:01:09
问题 I'm trying to build a simple typeclass IsEnum[T] using a macro. I use knownDirectSubclasses to get all the direct subclasses if T , ensure T is a sealed trait, and that all subclasses are of case objects (using subSymbol.asClass.isModuleClass && subSymbol.asClass.isCaseClass ). Now I'm trying to build a Seq with the case objects referred by the subclasses. It's working, using a workaround: Ident(subSymbol.asInstanceOf[scala.reflect.internal.Symbols#Symbol].sourceModule.asInstanceOf[Symbol])

Get the module symbol, given I have the module class, scala macro

帅比萌擦擦* 提交于 2021-01-20 13:00:43
问题 I'm trying to build a simple typeclass IsEnum[T] using a macro. I use knownDirectSubclasses to get all the direct subclasses if T , ensure T is a sealed trait, and that all subclasses are of case objects (using subSymbol.asClass.isModuleClass && subSymbol.asClass.isCaseClass ). Now I'm trying to build a Seq with the case objects referred by the subclasses. It's working, using a workaround: Ident(subSymbol.asInstanceOf[scala.reflect.internal.Symbols#Symbol].sourceModule.asInstanceOf[Symbol])

Scala conditional compilation

自古美人都是妖i 提交于 2021-01-20 12:23:06
问题 I'm writing a Scala program and I want it to work with two version of a big library. This big library's version 2 changes the API very slightly (only one class constructor signature has an extra parameter). // Lib v1 class APIClass(a: String, b:Integer){ ... } // Lib v2 class APIClass(a: String, b: Integer, c: String){ ... } // And my code extends APIClass.. And I have no #IFDEF class MyClass() extends APIClass("x", 1){ // <-- would be APIClass("x", 1, "y") in library v2 ... } I really don't