Data dodania Pytanie
2017-01-07 10:01 cake pattern - why is it so complicated »
I am trying to learn about the cake pattern. I am reading this blog about it. The example code from that blog is: case class User (name:String,emai...
(1) odpowiedzi
2017-01-07 10:01 Scala - Types and Instantiation »
scala> val a1 = scala.concurrent.Promise[Int] a1: scala.concurrent.Promise[Int] = scala.concurrent.impl.Promise$DefaultPromise@10d59286 I'm not a...
(1) odpowiedzi
2017-01-06 21:01 Is it possible to force named parameters in scala? »
In some method I would like to force parameters to be named. The reason being autogenerated code for which the order of parameters is unspecified (and...
(4) odpowiedzi
2017-01-06 18:01 Why does creating a map function whose parameter is of type `Nothing => U` appear to work? »
I'm writing Scala code that uses an API where calls to the API can either succeed, fail, or return an exception. I'm trying to make an ApiCallResult m...
(2) odpowiedzi
2017-01-06 06:01 explanation on scala for comprehension with Option »
I have the following definition: def f: Option[String] = Some(null) the following evaluates to None: for {x:String <- f} yield { x } th...
(2) odpowiedzi
2017-01-05 22:01 Print ALL defined variables/method signatures in Spark Shell - Scala REPL »
When I use the spark-shell I end up defining many var, val, and methods. At some point I forget what I have available in my session. How do I print th...
(1) odpowiedzi
2017-01-05 19:01 Convert CompletableFuture (Java 8) to Future (Scala) »
I want to change the return type of the method below to Future[Unit] def send(data: Array[Byte]): CompletableFuture[Void] = { val f:CompletableFutu...
(1) odpowiedzi
2017-01-05 15:01 What is the usage of _ in Int => Int = _ + 1 »
In the code below, what is the classification (or technical name) of the usage of the underscore character? scala> def f: Int => Int = _ + 1 f:...
(2) odpowiedzi
2017-01-04 23:01 Why can't I match on a Seq.empty? »
I tried matching a seq like this: val users: Seq[User] = .... users match { case Seq.empty => .... case .. } I got an error saying: stable...
(2) odpowiedzi
2017-01-04 20:01 Single Element Lists Have Same Head But Are Not Equal? »
Given two List[A] instances, under what circumstance could the following be true? list.head == otherList.head // returns true list.size == 1 ...
(1) odpowiedzi
2017-01-04 19:01 Scala - Multiple inheritance with App trait »
Consider two traits, TestTrait1 and TestTrait and assume NewObject extends both. The idea is to make use of variable in TestTrait1 in TestTrait. The b...
(1) odpowiedzi
2017-01-03 16:01 A compiling error about scala type inference »
I am doing a simple exercise which asks me to implement a standalone 'map' function on a list using foldRight. And the solution I came up with is this...
(1) odpowiedzi
2017-01-03 15:01 Meaning of `A >: Null`? »
I attempted to write a function that won't compile if null is passed: $scala Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_1...
(3) odpowiedzi
2017-01-03 10:01 Tail recursive fold on a binary tree in Scala »
I am trying to find a tail recursive fold function for a binary tree. Given the following definitions: // From the book "Functional Programming in Sc...
(1) odpowiedzi
2017-01-03 05:01 How in Scala , trait "Null" can be instantiated producing "null"? »
From the API doc I found that Null is a trait, but it says its sole instance is null. abstract final class Null extends AnyRef Null is - toget...
(1) odpowiedzi
2017-01-02 17:01 How to fold a collection of endomorphism with cats »
Given a function def f(i: I) : S => S I would like to write a pretty common combinator g def g(is : Seq[I], init: S) : S The easy implementat...
(1) odpowiedzi
2017-01-02 13:01 Object creation syntax difference »
Is there a difference between new ClassName and new ClassName()? Is it only a syntax difference or is there a scala magic happening in the background?...
(1) odpowiedzi
2017-01-02 07:01 What is special about case classes in Akka? »
I have read that case classes can be used with pattern matching. But, I am able to use a regular class with pattern matching as well. This question gi...
(1) odpowiedzi
2017-01-01 21:01 contramap method doesn't make any sense to me »
I am reading about the contramap method in Functors. What I understand about them is that if I have a type class F[B] (for example List[Int]) and I ha...
(0) odpowiedzi
2017-01-01 20:01 Reset Akka actors to initial state »
I have actors that do a simulation, and then send back data. I would like to be able to run the simulation multiple times, so I need to reset the inte...
(1) odpowiedzi
2017-01-01 18:01 Why defining a wrapping method over another method with an implicit argument doesn't work? »
writing this fails type check: val list = List(1,3,5,2,4) list sortBy (i => -i) //this is ok def wrappedSort[A,B](a: List[A])(by: A => B): L...
(1) odpowiedzi
2017-01-01 15:01 How to add new content to a record using Spark »
I have a text file containing several records like: aaaaa bbbbb ccccc I want to add a string (ex. "record:") in front of each record, so each ...
(1) odpowiedzi
2016-12-31 22:12 How to get classes incrementally compiled by SBT? »
The result of compile task in sbt is of type Analysis. I want to find all java.lang.Classes that are compiled in last compilation. Is that possible at...
(0) odpowiedzi
2016-12-31 21:12 Clean way to handle future and option »
My code block looks like this currently which seems ugly: for { maybeUser <- getUser(1) } yield { if (maybeUser.isDefined) { someFunction...
(3) odpowiedzi
2016-12-31 11:12 How to use cats and State Monad »
I've used cats for the first time to solve day 1 of advent of code and I'm wondering if it's possible to improve things. Given a method update with t...
(1) odpowiedzi
2016-12-30 21:12 How to check if types are Tuple in compile time »
I have the following case class: case class MyClass[A,B](a:A, b:B) I want to add a function like unzip to MyClass so if A and B are Tuple types the...
(2) odpowiedzi
2016-12-30 21:12 Scala inner class typing »
Suppose I have the following: class Deck[+T] { class Card(value: T) class Pile(val cards: List[Card]) { val deck = Deck.this ...
(1) odpowiedzi
2016-12-30 18:12 How to make a class fully immutable in Scala »
I am trying to make the following class immutable. I know the theory of how to do this but I think my implementation is wrong. Can you help? Thanks ...
(2) odpowiedzi
2016-12-30 15:12 Akka flow for multiple http requests »
In a project of mine I have an akka actor for sending post requests to my google fcm server. The actor takes a list of ids and should make as many req...
(1) odpowiedzi
2016-12-29 16:12 Tail Recursive function for the sum of fractions »
I am trying to convert this recursive function into a tail recursive function def sumOfFractions(n: Int): Double = { require(n > 0, "Parameter n...
(2) odpowiedzi
2016-12-29 12:12 How to get Plugin's dependencies in custom SBT task? »
I need to create custom SBT task, and I need to get Plugin dependencies in it. The task goal is to create .zip with all the .jars the Plugin needs. I ...
(0) odpowiedzi
2016-12-29 11:12 Applicative functors vs monad composing performance in Scala »
I have two monad instances val a: M[A] and val b: M[B]. Would there be any performance difference in the following code cases? def f: (A, B) => C...
(1) odpowiedzi
2016-12-29 05:12 Scala optional pattern matching »
I find myself frequently using pattern matching that returns an Option with the no match case returning None, e.g. x match { case A(a) => Some...
(3) odpowiedzi
2016-12-29 02:12 Nice syntax for function composition in Scala »
I would like to arrive to a syntax as productive as Haskell's desort = (reverse . sort) in Scala... Here is my attempt: implicit class Composition[A,...
(1) odpowiedzi
2016-12-28 17:12 Elegant way of reusing akka-stream flows »
I am looking for a way to easily reuse akka-stream flows. I treat the Flow I intend to reuse as a function, so I would like to keep its signature lik...
(2) odpowiedzi