scala

In scala 2.13, why is it sometimes impossible to summon type class explicitly?

牧云@^-^@ 提交于 2021-02-08 04:42:13
问题 Here is a simple example in shapeless 2.3.3: val book = ("author" ->> "Benjamin Pierce") :: ("title" ->> "Types and Programming Languages") :: ("id" ->> 262162091) :: ("price" ->> 44.11) :: HNil val v1 = book.values assert(v1.head == "Benjamin Pierce") // works fine // summoning Values[_] type class explicitly, the HList & TypeTag are optional case class HasValues[T <: HList: TypeTag](v: T) { def vs(implicit v: Values[T]): Values[T] = v } val _vs = HasValues(book).vs val v2 = book.values(_vs)

Scala : parameterize a type with one of its inner types

谁说我不能喝 提交于 2021-02-08 04:18:31
问题 I would like to parameterize a type with one of its subclasses. Consider the following: class DataLoader { class Data { /* data specifics to this data loader */ } def getData : Data /* and so on */ } Now I want to make this loader able to asynchronously retrieve data from the network. One of the options is to have it subclass Callable. class DataLoader extends Callable[Data] { class Data { /* ... */ } def call : Data = { ... } } val futureData = executor.submit(new DataLoader) futureData.get

Dynamically merge Akka streams

一曲冷凌霜 提交于 2021-02-08 04:12:40
问题 I’m trying to use Akka streams to build a pub sub bus in the following way: Publisher adds a source stream for the topic and subscribers specify a topic and get everything for that topic. However topic may be published by multiple Publishers, and both publisher and subscribers can join at any point. What I had in mind is to combine all sources and then return the filtered source to a subscriber. However as publishers may join at any point sources may be added after a subscription has been

Dynamically merge Akka streams

喜你入骨 提交于 2021-02-08 04:11:51
问题 I’m trying to use Akka streams to build a pub sub bus in the following way: Publisher adds a source stream for the topic and subscribers specify a topic and get everything for that topic. However topic may be published by multiple Publishers, and both publisher and subscribers can join at any point. What I had in mind is to combine all sources and then return the filtered source to a subscriber. However as publishers may join at any point sources may be added after a subscription has been

Events that should be emitted by a KTable

拜拜、爱过 提交于 2021-02-08 03:42:07
问题 I am trying to test a topology that, as the last node, has a KTable. My test is using a full-blown Kafka Cluster (through confluent's Docker images) so I am not using the TopologyTestDriver . My topology has input of key-value types String -> Customer and output of String -> CustomerMapped . The serdes, schemas and integration with Schema Registry all work as expected. I am using Scala, Kafka 2.2.0, Confluent Platform 5.2.1 and kafka-streams-scala . My topology, as simplified as possible,

Events that should be emitted by a KTable

一世执手 提交于 2021-02-08 03:41:10
问题 I am trying to test a topology that, as the last node, has a KTable. My test is using a full-blown Kafka Cluster (through confluent's Docker images) so I am not using the TopologyTestDriver . My topology has input of key-value types String -> Customer and output of String -> CustomerMapped . The serdes, schemas and integration with Schema Registry all work as expected. I am using Scala, Kafka 2.2.0, Confluent Platform 5.2.1 and kafka-streams-scala . My topology, as simplified as possible,

Events that should be emitted by a KTable

我的未来我决定 提交于 2021-02-08 03:41:07
问题 I am trying to test a topology that, as the last node, has a KTable. My test is using a full-blown Kafka Cluster (through confluent's Docker images) so I am not using the TopologyTestDriver . My topology has input of key-value types String -> Customer and output of String -> CustomerMapped . The serdes, schemas and integration with Schema Registry all work as expected. I am using Scala, Kafka 2.2.0, Confluent Platform 5.2.1 and kafka-streams-scala . My topology, as simplified as possible,

In Scala, why it is impossible to infer TypeTag from type alias or dependent type?

假如想象 提交于 2021-02-08 03:30:39
问题 I have a simple scala program to test the Capability of Scala to infer type classes: import scala.reflect.ClassTag object InferTypeTag { import org.apache.spark.sql.catalyst.ScalaReflection.universe._ def infer(): Unit = { type U = (Int, String) val ttg1 = implicitly[TypeTag[(Int, String)]] val ttg2 = implicitly[TypeTag[U]] val ctg = implicitly[ClassTag[U]] } } ttg1 got inferred without problem. ttg2 triggered the following compilation error: Error:(14, 26) No TypeTag available for U val ttg2

How to get an actor reference (ActorRef) from ActorFlow?

非 Y 不嫁゛ 提交于 2021-02-08 02:21:18
问题 According to the Play documentation on WebSockets the standard way to establish a WebSocket is to use ActorFlow.actorRef , which takes a function returning the Props of my actor. My goal is to get a reference to this underlying ActorRef , for instance in order to send a first message or to pass the ActorRef to another actor's constructor. In terms of the minimal example from the documentation, I'm trying to achieve this: class WebSocketController @Inject() (implicit system: ActorSystem,

How to get an actor reference (ActorRef) from ActorFlow?

旧城冷巷雨未停 提交于 2021-02-08 02:18:28
问题 According to the Play documentation on WebSockets the standard way to establish a WebSocket is to use ActorFlow.actorRef , which takes a function returning the Props of my actor. My goal is to get a reference to this underlying ActorRef , for instance in order to send a first message or to pass the ActorRef to another actor's constructor. In terms of the minimal example from the documentation, I'm trying to achieve this: class WebSocketController @Inject() (implicit system: ActorSystem,