Scala is a general purpose programming language principally targeting the Java Virtual Machine. Designed to express common programming patterns in a concise, elegant, and type-safe way, it fuses both imperative and functional programming styles.

learn more… | top users | synonyms

0
votes
0answers
30 views

Idiomatic Scala way to come a list of Eithers into a Left or Right depending on the lists content [migrated]

I have a list of Eithers val list: List[Either[String, Int]] = List(Right(5), Left("abc"), Right(42)) As a result I want a Right if everything in the list is a Right else I want a Left. This sounds ...
18
votes
5answers
2k views

If Scala runs on the JVM, how can Scala do things that Java seemingly cannot? [duplicate]

I just learned about Scala yesterday, and I'd like to learn more about it. One thing that came to mind, however, from reading the Scala website is that if Scala runs on the JVM, then how is it ...
1
vote
2answers
91 views

best practices for packaging in Scala projects?

Scala runs on the JVM, but that doesn't mean we have to write it like Java. Eclipse discourages use of the default package. What are some considerations (e.g. size of project) that determine how ...
1
vote
1answer
48 views

Are Serverlet Containers' Characteristics Against Scalability and Fault-Tolerance of a Web Application?

We most likely deploy a JVM-based Web application (e.g., Scala) on a container (e.g., TOMCAT, Jetty, etc.). Does the following points about a serverlet container goes against us to create a scalable ...
0
votes
0answers
31 views

Accessing intermittently available resources with transactions and post-access cleanup in a generalized, functional, composable way

The following psuedo-code illustrates what I'd like to be able to do. Is there a way to accomplish something like this in Scala?: trait IntermittentlyAvailableResource trait ...
0
votes
1answer
66 views

FP: Capturing the characteristics of a process which blocks, causes side-effects, and may fail

I have a driver function modifyFile that interacts with many sources in the outside world (e.g. HTTP, filesystem). Let's say the code is as such: def downloadFile(from: String, to: String): Try[Unit] ...
2
votes
0answers
71 views

Migrating a Grails application to Scala Play/Spray

We have a moderately sized Grails web application using GORM/Hibernate over PostgreSQL and GSPs serving HTML, and also a few REST APIs. We are standardising on Scala, and would like to migrate this ...
24
votes
3answers
2k views

Introducing Scala to a Technical Manager

I've been promoting Scala at work as something we should try out for things like testing with Specs http://code.google.com/p/specs/ and rapid prototyping of web services with tools like Scalatra ...
0
votes
1answer
95 views

How can I condense a case class with ~20 constructor arguments into 5 or 6 arguments in Scala?

Let's say I have a case class with ~20 constructor arguments? This is obviously very clunky to type. What would be the best way to condense these arguments into maybe 5 or 6 arguments? There are some ...
2
votes
5answers
468 views

I have generally read that having many (>4) arguments to a function/constructor is a bad practice. Is this still considered a bad practice? [closed]

I have generally read that having many (>4) arguments to a function/constructor is a bad practice. Is this still considered a bad practice? And is there a non-obvious reason? In something like a ...
28
votes
4answers
5k views

What limitations does the JVM impose on tail-call optimization

Clojure does not perform tail call optimization on its own: when you have a tail recursive function and you want to have it optimized, you have to use the special form recur. Similarly, if you have ...
23
votes
8answers
12k views

Why was Scala not implemented with C or C++

Does anybody know why was Scala implemented in Java and .NET instead of C or C++? Most languages are implemented with Cor C++ [i.e Erlang, Python, PHP, Ruby, Perl]. What are the advantages for Scala ...
3
votes
2answers
170 views

Scala and exception handling [closed]

I am curious why exception handling is a topic often ignored in Scala. Is it the goal of the language (or the style) to not rely on exception handling except for external input/code? I was hoping ...
31
votes
6answers
3k views

Re-inventing system design for Scala

Many, many, moons ago, I did my masters in Object Orientated Software Engineering. I covered everything: project initiation, requirements, analysis, design, architecture, development, etc, etc. My ...
3
votes
2answers
72 views

How to use scala case classes when delegation is needed

Let's assume in our application we want to model cars. We also want to model a car repository where we store some registered cars. How should that be modeled in scala? Here comes my approach: First, ...
1
vote
2answers
62 views

What Scala type to use for a list of meeting participants

I want to store a number of participants for a meeting. The order of them is not important. The only thing I want to make sure is, that I will be able to add and remove participants, use filter ...
1
vote
2answers
123 views

The reason for scala not supporting Multiple Inheritance [closed]

I've searched around for a long time now and haven't come up with any official reason why scala doesn't support multiple inheritance. I know traits solve a lot of things, but the developers of C# for ...
1
vote
1answer
124 views

Generic delegates (C#) in Scala?

I wanted to know if there is an equivalent of the C# generic delegates in Scala. The reference website is: http://msdn.microsoft.com/en-us/library/dd233060.aspx I'm trying to make a complete ...
0
votes
1answer
42 views

Actors in a sequential protocol handshake

I am new to actors and trying to implement a very sequential protocol handshake (over websockets). This is in Scala/Akka. It goes something like this: HTTPs connection is established then upgraded ...
8
votes
2answers
518 views

Why can't the Scala compiler give pattern matching warning for nonsealed classes/traits?

If I use an unsealed trait or abstract class in Scala and then use pattern matching, I wonder, does the compiler not know at compile time for this particular patternmatch what possible implementations ...
7
votes
1answer
149 views

Why are Scala's Either and Option types not interfaces/traits but classes?

I wanted to create a class CompileResult, that can be treated like an Either type but has some additional useful methods. It should be a CompileSuccess or a CompileFailure (which, too, has some ...
27
votes
5answers
8k views

What is the difference between a Future and a Promise?

What is the difference between a Future and a promise? (In Akka and Gpars.) They look the same to me as both block and return the value of the future when get is called and a promise is to get the ...
2
votes
2answers
157 views

Scala infix notation

Is it possible to call a method using infix notation? For example, in Haskell, I could write the following fucntion: x `isAFactorOf` y = x % y == 0 and then use it like: if 2 `isAFactorOf` 10 ... ...
3
votes
2answers
126 views

What's the rationale behind the ordering of Scala's value/variable declaration when including a type identifier?

I'm trying to wrap my head around Scala, and one thing that keeps throwing me is the ordering of a variable/value declaration when specifying the type. val a = 0 makes perfect sense. This looks ...
0
votes
1answer
52 views

in scala type linearization explain first step in algorithm [closed]

I saw this explanation Where first step is: "start building a list of types, the first element is the type we’re linearizing right now," however the result of this is: // start with D1: B ...
9
votes
1answer
2k views

Why does Scala have return but not break and continue

Scala does not have break or continue, so some loop behavior takes a bit more of thinking. Ending a loop early requires tail recursion, exceptions, or scala.util.control.Breaks (which uses ...
1
vote
1answer
207 views

What was the influence of Chris Okasaki's data structures on Scala? [closed]

I heard a friend say: The first real use of Chris Okasaki's book was in Clojure's data structures I heard another friend say: No, they influenced the design of Scala in quite a subtle way. ...
2
votes
2answers
201 views

Is it possible to have Ad-Hoc polymorphism with runtime dispatch?

As I did understand, and as it's described here, ad-hoc polymorphism is limited to compile-time dispatch. That is, if we have a function that expects an argument that belongs to a typeclass, we must ...
0
votes
0answers
79 views

Controllers passing Request objects to backend logic that forward Request data: Good or Bad?

Currently working on a server-side front-end Scala Play app that does a lot of grabbing of HTML snippets and JSON from many other web apps before piecing everything together and sending it in a ...
0
votes
0answers
51 views

Is there a pattern for deserialization involving repository access? Or what is wrong with my design?

Let us have case class Money(amount: BigDecimal, currency: Currency) case class Currency(code: String, alpha3: String) Money is a value object and Currency is an entity. When transforming Money to ...
1
vote
3answers
441 views

Help me to understand 'stateless' software in functional programming

I'm an experienced software engineer, and have experience in a range of languages from PHP, Ruby, C#, Java - the last few years I've primarily worked in Java. I'm now learning Scala, and it's my ...
35
votes
12answers
4k views

Why do most programming languages have special keyword or syntax for declaring functions? [closed]

Most programming languages (both dynamically and statically typed languages) have special keyword and/or syntax that looks much different than declaring variables for declaring functions. I see ...
9
votes
3answers
1k views

What is a “lifted representation”?

Just ran across this term here: http://www.codemesh.io/codemesh2014/viktor-klang "We'll demonstrate the Flow API—a lifted representation—as well as a pluggable way of transforming the lifted ...
1
vote
0answers
215 views

ZeroMQ and Majordomo protocol

I am learning ZeroMQ and came across the Majordomo Protocol. I am wondering if I'm understanding this correctly, is the use case the same as.. for example.. the Microsoft Azure AppFabric service? ...
2
votes
3answers
224 views

Is 'design with types first' ultimately the same as 'design with interfaces first'?

In Object Oriented Programming, we're taught to think in terms of Polymorphism (the idea that the implementation is decoupled from the interface - and that it makes sense to think of the interface ...
0
votes
1answer
41 views

Where to put sample data in project structure

I am working on a Scala project and I want to include some sample data somewhere in the project. Specifically, my Scala project includes code that performs various natural language processing tasks ...
0
votes
2answers
78 views

Map multiple functions over a single data item [closed]

I'm in the process of learning Scala and I came across a scenario today where I need to map multiple functions over a single piece of data and wondered if there was a formal name for this. It sort of ...
1
vote
2answers
171 views

If there's no problem treating a statement as an expression, why was there a distinction in the first place in some programming languages? [duplicate]

Why do we have the distinction between statements and expressions in most programming languages? For example, in Java, assuming f and g return ints, this still won't compile because it's a statement ...
5
votes
1answer
72 views

Coping with build order requirements in automated builds

I have three Scala packages being built as separate sbt projects in separate repos with a dependency graph like this: M---->D ^ ^ | | +--+--+ ^ | S S is a service. ...
2
votes
1answer
93 views

Is it good practice to use NoStackTrace in scala?

I came across the NoStackTrace mixin for Exceptions in scala. Is it good practice to use it, or should it be considered "internal" to scala and left alone?
2
votes
2answers
271 views

Java: method takes varargs of unrelated types

I have a Java factory method with a varargs array of Objects at the end. The array can contain any combination of Strings and ScaledJpegs. The theory being that an HTML table cell can contain any ...
3
votes
1answer
285 views

When to declare @throws with a Scala annotation - abstract parent or concrete implementation?

In this StackOverflow question I asked about the behavior of the @throws annotation in Scala. Now that I understand how it works I want to ask about best practices with using it. Here's a repost of my ...
0
votes
2answers
167 views

SOAP message testing

I am working in Scala/Java. I'm testing the messaging infrastructure of a part of my system that I did several years ago with CXF and Java. More specifically, I'm re-writing the specification of the ...
8
votes
3answers
1k views

Is duplicate syntax for defining named functions a bad language design decision?

I am modelling a programming language for fun, and the syntax is heavily influenced by Scala - specifically function definitions. I have encountered a design problem because my language does not ...
5
votes
5answers
1k views

What negative consequences can arise from this language design rule?

Clarification: the rule is meant to prevent accessing variables that are not declared yet. Clarification 2: the rule mandates that the compiler follows calls to functions which are defined in the ...
3
votes
1answer
129 views

Why is subclassing TraversableOnce not recommended

Reading http://www.scala-lang.org/api/2.11.1/index.html#scala.collection.TraversableOnce: Directly subclassing TraversableOnce is not recommended - instead, consider declaring an Iterator with a ...
-1
votes
1answer
82 views

What is the session about simplicity that Martin Odersky suggested during the “Scala with style” talk? [closed]

The video of Scala with style is here: http://parleys.com/play/51c1994ae4b0d38b54f4621b/chapter21/about It's around 41:10 that he suggested another talk. I can not hear the name of speaker or the ...
1
vote
1answer
853 views

Why the Scala fascination with flatmap? (This doesn't seem to be the same for mapcat in the Clojure world) [closed]

In the Scala community - there is an apparent fascination with the FlatMap function. Now I understand that FlatMap is significant because it is used for the bind part of a Monad. (and that the ...
1
vote
1answer
328 views

Should we push for more JavaScript on the JVM, alongside Java and Scala? Or, if not, why? [closed]

With JavaScript becoming one of the most widely used languages around, I began asking myself why people do not find ways to use it extensively on the JVM. As a programmer who spends half day writing ...
1
vote
1answer
235 views

Type Safety of Spray.io

Yesterday I read a tweet disparaging Jersey with JAX-RS due to run-time errors. Spray.io was mentioned in the tweet: Not even 5 minutes using Jersey / JAX-RS and already a runtime error due to a ...