Questions tagged [scala]

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. Its key features are: an advanced static type system with type inference; function types; pattern-matching; implicit parameters and conversions; operator overloading; full interoperability with Java; concurrency

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 and styles. Its key features are:

  • Static typing
  • Advanced type system with type inference and declaration-site variance
  • Function types (including anonymous) which support lexical closures
  • Pattern-matching
  • Implicit parameters and conversions which support the typeclass and enrich-my-library patterns
  • Mixin composition
  • Full interoperability with Java
  • Powerful concurrency constructs
  • Advanced language constructs such as delimited continuations and an experimental macro system

For more information, see the official Scala Introduction and Scala Documentation.

To search for Scala symbols such as => in Stack Overflow, you can use symbolhound search.

To search Scala documentation, you can use scalex.

A community list of available libraries is available at Awesome Scala

There is Scala Library Index by Scala Center: Scaladex.

Free Scala programming books and guides

Stack Overflow Scala Tutorial

  1. Introduction to Scala
  1. Variables/values
  1. Methods
  1. Literals, statements and blocks
  1. Loops/recursion
  1. Data structures / Collections
  1. For-comprehension
  1. Enumeration
  1. Pattern matching
  1. Classes, objects and types
  1. Packages, imports and visibility identifiers
  1. Inheritance
  1. Extractors
  1. Case classes
  1. Parameterized types
  1. Traits
  1. Self references
  1. Error handling
  1. Type handling
  1. Annotations
  1. Functions/Function literals
  1. Type safety
  1. Implicits
  1. Reflection
  1. Enrich-my-library pattern (formerly known as pimp-my-library)
  1. Concurrency overview
  2. Actors
  1. Use Java from Scala and vice versa
  1. XML literals
  • Explanation
  1. Scala Swing
  1. Type Programming
  1. Functional Scala

Further learning

  1. Learning Resources
  1. REPL
  1. Working with scalac and scala
  1. Operator precedence
  1. Scala style
  1. Functional Programming Principles in Scala, a functional programming course on Coursera taught by Martin Odersky, the creator of Scala.
  2. Principles of Reactive Programming, a reactive functional programming course on Coursera taught by Martin Odersky, Erik Meijer, Roland Kuhn.
  3. Parallel Programming, a parallel programming course on Coursera taught by Viktor Kuncak and Aleksandar Prokopec.
111781 questions
287
votes
4 answers

What is "lifting" in Scala?

Sometimes when I read articles in the Scala ecosystem I read the term "lifting" / "lifted". Unfortunately, it is not explained what that exactly means. I did some research, and it seems that lifting has something to do with functional values or…
user573215
  • 4,679
  • 5
  • 22
  • 25
281
votes
12 answers

Difference between method and function in Scala

I read Scala Functions (part of Another tour of Scala). In that post he stated: Methods and functions are not the same thing But he didn't explain anything about it. What was he trying to say?
Anantha Kumaran
  • 10,101
  • 8
  • 33
  • 36
274
votes
1 answer

How to use Shapeless in a Quasiquote?

I'm trying to call a Shapeless macro from inside a quasiquote with Scala and I'm not getting what I would like to get. My macro doesn't return any errors but it doesn't expand Witness(fieldName) into Witness.Lt[String] val implicits =…
Roch
  • 21,741
  • 29
  • 77
  • 120
273
votes
5 answers

Scala: Abstract types vs generics

I was reading A Tour of Scala: Abstract Types. When is it better to use abstract types? For example, abstract class Buffer { type T val element: T } rather that generics, for example, abstract class Buffer[T] { val element: T }
thatismatt
  • 9,832
  • 10
  • 42
  • 54
272
votes
7 answers

What does a lazy val do?

I noticed that Scala provide lazy vals. But I don't get what they do. scala> val x = 15 x: Int = 15 scala> lazy val y = 13 y: Int = scala> x res0: Int = 15 scala> y res1: Int = 13 The REPL shows that y is a lazy val, but how is it…
kiritsuku
  • 52,967
  • 18
  • 114
  • 136
263
votes
9 answers

Scala Programming for Android

I have followed the tutorial at Scala and Android with Scala 2.7.3 final. The resulting Android App works but even the most basic application takes several minutes (!) to compile and needs 900 kb compressed, which is a show stopper for mobile…
Lemmy
  • 3,177
  • 3
  • 17
  • 16
261
votes
26 answers

How do I parse command line arguments in Scala?

What is a good way of parsing command line arguments in Scala? Related: How do I parse command line arguments in Java?
Eugene Yokota
  • 94,654
  • 45
  • 215
  • 319
257
votes
17 answers

Call by name vs call by value in Scala, clarification needed

As I understand it, in Scala, a function may be called either by-value or by-name For example, given the following declarations, do we know how the function will be called? Declaration: def f (x:Int, y:Int) = x; Call f (1,2) f (23+55,5) f…
James Raitsev
  • 92,517
  • 154
  • 335
  • 470
256
votes
6 answers

Appending an element to the end of a list in Scala

I can't add an element of type T into a list List[T]. I tried with myList ::= myElement but it seems it creates a strange object and accessing to myList.last always returns the first element that was put inside the list. How can I solve this…
Masiar
  • 20,450
  • 31
  • 97
  • 140
256
votes
11 answers

Task not serializable: java.io.NotSerializableException when calling function outside closure only on classes not objects

Getting strange behavior when calling function outside of a closure: when function is in a object everything is working when function is in a class get : Task not serializable: java.io.NotSerializableException: testing The problem is I need my…
Nimrod007
  • 9,825
  • 8
  • 48
  • 71
251
votes
14 answers

Case objects vs Enumerations in Scala

Are there any best-practice guidelines on when to use case classes (or case objects) vs extending Enumeration in Scala? They seem to offer some of the same benefits.
Alex Miller
  • 69,183
  • 25
  • 122
  • 167
248
votes
7 answers

Difference between case object and object

Is there any difference between case object and object in scala?
Wojciech Durczyński
  • 2,627
  • 2
  • 16
  • 11
245
votes
4 answers

Get item in the list in Scala?

How in the world do you get just an element at index i from the List in scala? I tried get(i), and [i] - nothing works. Googling only returns how to "find" an element in the list. But I already know the index of the element! Here is the code that…
Andriy Drozdyuk
  • 58,435
  • 50
  • 171
  • 272
241
votes
9 answers

What is the difference between "def" and "val" to define a function

What is the difference between: def even: Int => Boolean = _ % 2 == 0 and val even: Int => Boolean = _ % 2 == 0 Both can be called like even(10).
Amir Karimi
  • 5,401
  • 4
  • 32
  • 51
240
votes
4 answers

What does `:_*` (colon underscore star) do in Scala?

I have the following piece of code from this question: def addChild(n: Node, newChild: Node) = n match { case Elem(prefix, label, attribs, scope, child @ _*) => Elem(prefix, label, attribs, scope, child ++ newChild : _*) case _ => error("Can…
amorfis
  • 15,390
  • 15
  • 77
  • 125