Tag Info

New answers tagged

3

Scala encourages the use of constructs like options and futures for error handling. First of all, lazy evaluation makes exceptions problematic, because there is a different stack when a function is executed than when it's queued to execute. Scala isn't lazy by default, but it can be lazy when you choose. Also, options and futures are much more powerful ...


1

First off, check out akka.io. It provides actor-based processing for your input and output needs. There are a number of good examples of creating servers using akka.io that are well worth your while to study. To answer part of your question ... You would create an actor whose sole responsibility is to set up and maintain the connection. It would receive ...


2

It can be done (at least for all classes known at compile time), it's just expensive. You'd completely destroy incremental compilation, because everything that contains a pattern match would effectively have to be recompiled every time any other file changed. And what are you buying? It's a code smell to write pattern matches that need to change ...


11

Figuring out all subclasses of a class is called Class Hierarchy Analysis, and doing static CHA in a language with dynamic code loading is equivalent to solving the Halting Problem. Plus, one of the goals of Scala is separate compilation and deployment of independent modules, so the compiler simply cannot know whether or not a class is subclassed in another ...


8

The change to Either was made on April 24th, 2008 in commit c0b21797bde81861305dd68853add2d8bd46e484 "Changed isLeft and isRight to use less memory.": Changed isLeft and isRight to use less memory. Changed either from a sealed trait to a sealed abstract class to allow exhaustiveness checking. All changes per the discussion in #797. The ...


1

I'll add a bit here because I have been working with a plethora of Futures in Java as of late but have a background in Scala/Akka development as well. This answer will mostly duplicate what has been said but will point out the plethora of implementations in popular use today on the JVM. First, original poster mentions using get and blocking - please never ...


4

To expand on the answer by @eques, starting with version 2.10, Scala introduced implicit Classes to handle precisely this issue. This will perform an implicit conversion on a given type to a wrapped class, which can contain your own methods and values. In your specific case, you'd use something like this: implicit class RichInt(x: Int) { def ...


1

Essentially, in Scala you can't call a function in an infix manner, but you can define a method on a type, which the left argument can be converted to implicitly. So for your example, you can define a class which has a method isAFactorOf (taking an Int) and indicate that an Int can be implicitly converted to an instance of this class. If you look at this ...


10

stand out from other languages No. As Jörg already commented, this form is actually used in many languages. It is probably the most common form of variable declaration by number of languages that use it. It was used back then with Pascal and related languages and it is now being used by all the new ones like TypeScript, Go, Rust—and Scala. type ...


2

You're thinking about it the wrong way. The type isn't immediately to the left of the assignment, it's immediately to the right of the declarator. This syntax has the advantage of being unambiguous, whereas for example val a = 0 : Int is ambiguous: does the type specifier refer to the literal, the declaration, or the entire statement? And if the initializer ...



Top 50 recent answers are included