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
234
votes
5 answers

How to clone a case class instance and change just one field in Scala?

Let's say I have a case class that represents personas, people on different social networks. Instances of that class are fully immutable, and are held in immutable collections, to be eventually modified by an Akka actor. Now, I have a case class…
François Beausoleil
  • 16,265
  • 11
  • 67
  • 90
232
votes
4 answers

Scala 2.8 breakOut

In Scala 2.8, there is an object in scala.collection.package.scala: def breakOut[From, T, To](implicit b : CanBuildFrom[Nothing, T, To]) = new CanBuildFrom[From, T, To] { def apply(from: From) = b.apply() ; def apply() = b.apply() } I…
oxbow_lakes
  • 133,303
  • 56
  • 317
  • 449
227
votes
1 answer

How to get started with Akka Streams?

The Akka Streams library already comes with quite a wealth of documentation. However, the main problem for me is that it provides too much material - I feel quite overwhelmed by the number of concepts that I have to learn. Lots of examples shown…
kiritsuku
  • 52,967
  • 18
  • 114
  • 136
224
votes
4 answers

Akka Kill vs. Stop vs. Poison Pill?

Newbie question of Akka - I'm reading over Akka Essentials, could someone please explain the difference between Akka Stop/Poison Pill vs. Kill ? The book offers just a small explaination "Kill is synchronous vs. Poison pill is asynchronous." But in…
LaloInDublin
  • 5,379
  • 4
  • 22
  • 26
218
votes
8 answers

difference between foldLeft and reduceLeft in Scala

I have learned the basic difference between foldLeft and reduceLeft foldLeft: initial value has to be passed reduceLeft: takes first element of the collection as initial value throws exception if collection is empty Is there any other difference…
Rajesh Pitty
  • 2,823
  • 2
  • 18
  • 28
217
votes
6 answers

When should I choose Vector in Scala?

It seems that Vector was late to the Scala collections party, and all the influential blog posts had already left. In Java ArrayList is the default collection - I might use LinkedList but only when I've thought through an algorithm and care enough…
Duncan McGregor
  • 17,665
  • 12
  • 64
  • 118
217
votes
8 answers

Good scalaz introduction

Recently scalaz caught my eye. It looks very interesting, but I have not found any good introduction to the library. Seems that scalaz incorporates a lot of ideas from haskell and mathematics. Most articles that I found assume that you already feel…
tenshi
  • 26,268
  • 8
  • 76
  • 90
215
votes
1 answer

Spark performance for Scala vs Python

I prefer Python over Scala. But, as Spark is natively written in Scala, I was expecting my code to run faster in the Scala than the Python version for obvious reasons. With that assumption, I thought to learn & write the Scala version of some very…
Mrityunjay
  • 2,211
  • 3
  • 14
  • 8
212
votes
4 answers

What do <:<, <%<, and =:= mean in Scala 2.8, and where are they documented?

I can see in the API docs for Predef that they're subclasses of a generic function type (From) => To, but that's all it says. Um, what? Maybe there's documentation somewhere, but search engines don't handle "names" like "<:<" very well, so I…
Jeff
  • 14,831
  • 15
  • 49
  • 59
209
votes
7 answers

Add JAR files to a Spark job - spark-submit

True... it has been discussed quite a lot. However, there is a lot of ambiguity and some of the answers provided ... including duplicating JAR references in the jars/executor/driver configuration or options. The ambiguous and/or omitted details The…
YoYo
  • 9,157
  • 8
  • 57
  • 74
208
votes
4 answers

What is the difference between JavaConverters and JavaConversions in Scala?

In scala.collection, there are two very similar objects JavaConversions and JavaConverters. What is the difference between these two objects? Why do they both exist? When do I want to use one vs. the other?
Michael Ekstrand
  • 28,379
  • 9
  • 61
  • 93
202
votes
3 answers

Reduce, fold or scan (Left/Right)?

When should I use reduceLeft, reduceRight, foldLeft, foldRight, scanLeft or scanRight? I want an intuition/overview of their differences - possibly with some simple examples.
Marc Grue
  • 5,865
  • 3
  • 16
  • 23
200
votes
2 answers

How do I cast a variable in Scala?

Given a variable with type Graphics, how do I cast it to Graphics2D in Scala?
Eugene Yokota
  • 94,654
  • 45
  • 215
  • 319
198
votes
18 answers

What Scala web-frameworks are available?

I've just started learning Scala, and the first thing I'm going to implement is a tiny web application. I've been using Erlang for the last year to implement server-side software, but I've never wrote web applications before. It will be a great…
Prikrutil
  • 2,610
  • 3
  • 18
  • 12
197
votes
5 answers

ScalaTest in sbt: is there a way to run a single test without tags?

I know that a single test can be ran by running, in sbt, testOnly *class -- -n Tag Is there a way of telling sbt/scalatest to run a single test without tags? For example: testOnly *class -- -X 2 it would mean "run the second test in the class.…
Nacht
  • 10,488
  • 8
  • 31
  • 39