scala

Akka Stream connect to multiple sinks

微笑、不失礼 提交于 2021-02-07 18:29:13
问题 I have implemented a custom component in akka stream which takes elements as input, groups and merges them based on a key and sends them out through one of a dozen outlets. You can think of this component as a kind of GroupBy component which does not partition the flow into subflows, but actual flows. In addition to partitioning incoming elements, it merges them into one element, i.e. there is some buffering happening inside the component such that 1 element in does not necessarily mean 1

scala.math.BigDecimal : 1.2 and 1.20 are equal

左心房为你撑大大i 提交于 2021-02-07 17:32:06
问题 How to keep precision and the trailing zero while converting a Double or a String to scala.math.BigDecimal ? Use Case - In a JSON message, an attribute is of type String and has a value of "1.20". But while reading this attribute in Scala and converting it to a BigDecimal, I am loosing the precision and it is converted to 1.2 回答1: @Saurabh What a nice question! It is crucial that you shared the use case! I think my answer lets to solve it in a most safe and efficient way... In a short form it

scala.math.BigDecimal : 1.2 and 1.20 are equal

冷暖自知 提交于 2021-02-07 17:31:16
问题 How to keep precision and the trailing zero while converting a Double or a String to scala.math.BigDecimal ? Use Case - In a JSON message, an attribute is of type String and has a value of "1.20". But while reading this attribute in Scala and converting it to a BigDecimal, I am loosing the precision and it is converted to 1.2 回答1: @Saurabh What a nice question! It is crucial that you shared the use case! I think my answer lets to solve it in a most safe and efficient way... In a short form it

scala.math.BigDecimal : 1.2 and 1.20 are equal

三世轮回 提交于 2021-02-07 17:30:39
问题 How to keep precision and the trailing zero while converting a Double or a String to scala.math.BigDecimal ? Use Case - In a JSON message, an attribute is of type String and has a value of "1.20". But while reading this attribute in Scala and converting it to a BigDecimal, I am loosing the precision and it is converted to 1.2 回答1: @Saurabh What a nice question! It is crucial that you shared the use case! I think my answer lets to solve it in a most safe and efficient way... In a short form it

In Scala - Converting a case class List into a List of tuples

风流意气都作罢 提交于 2021-02-07 17:24:47
问题 i have a case class case class table(a: String, b: Option[String]) and i have a list of that type - lets call it list1 val list1: List[table] = tabele.get() // just filling the list from an SQL now I want to change the list of "table" into a simple list of (String,Option[String]) What i allready found on this board was how to convert a case class into a tuple like that: case class table(a:String, b:Int) val (str, in) = table.unapply(table("test", 123)).get() But i don't know how to use this

Play Scala and thread safety

被刻印的时光 ゝ 提交于 2021-02-07 15:40:15
问题 The project is written using Play framework and Scala language. I have implemented compile time dependency . I have followed this example from Play: https://github.com/playframework/play-scala-compile-di-example Looking at the MyApplicationLoader.scala : import play.api._ import play.api.routing.Router class MyApplicationLoader extends ApplicationLoader { private var components: MyComponents = _ def load(context: ApplicationLoader.Context): Application = { components = new MyComponents

Why is Scalas Either not a monad?

与世无争的帅哥 提交于 2021-02-07 14:28:42
问题 I'm interested in knowing the design decisions why scala.Either was not done as a monad. There already exists some discussion on how to right-biasing Either , for example: right-biasing Either fixing Either Fixing scala.Either - unbiased vs biased But there are mentioned too much details and I couldn't get an complete overview about why it is done as it is done. Can someone give an overview about the benefits of having a right-biased Either , about the problems to do it that way and about the

Why blocking on future considered a bad practice?

此生再无相见时 提交于 2021-02-07 14:28:30
问题 I'm trying to understand rational behind the statement For cases where blocking is absolutely necessary, futures can be blocked on (although it is discouraged) Idea behind ForkJoinPool is to join processes which is blocking operation, and this is main implementation of executor context for futures and actors. It should be effective for blocking joins. I wrote small benchmark and seems like old style futures(scala 2.9) are 2 times faster in this very simple scenario. @inline def futureResult[T

Why is Scalas Either not a monad?

ぐ巨炮叔叔 提交于 2021-02-07 14:27:13
问题 I'm interested in knowing the design decisions why scala.Either was not done as a monad. There already exists some discussion on how to right-biasing Either , for example: right-biasing Either fixing Either Fixing scala.Either - unbiased vs biased But there are mentioned too much details and I couldn't get an complete overview about why it is done as it is done. Can someone give an overview about the benefits of having a right-biased Either , about the problems to do it that way and about the

get all the class names in a package with scala

旧巷老猫 提交于 2021-02-07 14:13:29
问题 I have a package package one.two.three and in that package I have public trait first public class Second and pubic class Third I want to get all the classes and interface(in one.two.three) names as Strings. heard that the best way to do it is using reflection. can someone tell me a way to do that thing please. 回答1: Well, that is a bit more complex task than one would thought. For instance, you may have classes in the same package but in different locations (e.g., 2 JAR files loaded by an