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
29
votes
7 answers

How do you serialize a Map to JSON in Scala?

So I have a Map in Scala like this: val m = Map[String, String]( "a" -> "theA", "b" -> "theB", "c" -> "theC", "d" -> "theD", "e" -> "theE" ) and I want to serialize this structure into a JSON string using lift-json. Do any of…
Jay Taylor
  • 13,185
  • 11
  • 60
  • 85
29
votes
6 answers

New line character in Scala

Is there a shorthand for a new line character in Scala? In Java (on Windows) I usually just use "\n", but that doesn't seem to work in Scala - specifically val s = """abcd efg""" val s2 = s.replace("\n", "") println(s2) outputs abcd efg in…
Luigi Plinge
  • 50,650
  • 20
  • 113
  • 180
29
votes
4 answers

Git workflow - changing branch and slow recompiles

I work on a large Scala project where we use Git for version control. My workflow is to work on new features in my own branch and switch when needed. Various releases of the code are in their own branches. All very standard. If I have to fix a bug…
David
  • 1,862
  • 2
  • 22
  • 35
29
votes
2 answers

How do I convert an Array[String] to a Set[String]?

I have an array of strings. What's the best way to turn it into an immutable set of strings? I presume this is a single method call, but I can't find it in the scala docs. I'm using scala 2.8.1.
dave4420
  • 46,404
  • 6
  • 118
  • 152
29
votes
2 answers

Scala catching confusion

I've recently seen code like this: val maybeInt = catching(classOf[NFE]) opt arg.toInt What is this opt? An Option? Why isn't it using getOrElse to extract the value? In the above code, will maybeInt be None if a NumberFormatException gets thrown?
Geo
  • 93,257
  • 117
  • 344
  • 520
29
votes
3 answers

One REPL to bind them all?

I'd like to know if there is a REPL which is not language-specific. I spend a lot of time dipping in and out of REPLs (mainly for Clojure, Scala and Haskell), and the bundled ones all frustrate me to a greater or lesser extent. It seems like the…
29
votes
2 answers

Example of contravariance

I am thinking of the following example to illustrate why contravariance is useful. Let's consider a GUI framework with Widgets, Events, and Event Listeners. abstract class Event; class KeyEvent extends Event class MouseEvent extends Event trait…
Michael
  • 10,185
  • 12
  • 59
  • 110
29
votes
3 answers

Spark save(write) parquet only one file

if i write dataFrame.write.format("parquet").mode("append").save("temp.parquet") in temp.parquet folder i got the same file numbers as the row numbers i think i'm not fully understand about parquet but is it natural?
Easyhyum
  • 307
  • 1
  • 3
  • 5
29
votes
6 answers

How to use Environment Variables in build.sbt?

I would like to use environment variables to pass my repo credentials when using built.sbt. I have tried things like this but the details arent picked up. credentials += Credentials("Some Nexus Repository Manager", "my.artifact.repo.net",…
Glef
  • 363
  • 1
  • 4
  • 12
29
votes
3 answers

Using Scala 2.12 with Spark 2.x

At the Spark 2.1 docs it's mentioned that Spark runs on Java 7+, Python 2.6+/3.4+ and R 3.1+. For the Scala API, Spark 2.1.0 uses Scala 2.11. You will need to use a compatible Scala version (2.11.x). at the Scala 2.12 release news it's also…
NetanelRabinowitz
  • 1,534
  • 2
  • 14
  • 26
29
votes
4 answers

SparkSQL - Read parquet file directly

I am migrating from Impala to SparkSQL, using the following code to read a table: my_data = sqlContext.read.parquet('hdfs://my_hdfs_path/my_db.db/my_table') How do I invoke SparkSQL above, so it can return something like: 'select col_A, col_B from…
Edamame
  • 23,718
  • 73
  • 186
  • 320
29
votes
5 answers

Migrating Java to Scala

What are the most important points to be aware of, and the workarounds, when gradually migrating an existing Java codebase to Scala? With a (potentially very long) intermediate phase where both languages are in use. The sort of things I'm thinking…
Kevin Wright
  • 49,540
  • 9
  • 105
  • 155
29
votes
6 answers

Remove whitespaces in string with Scala

I want to remove the whitespaces in a string. Input: "le ngoc ky quang" Output: "lengockyquang" I tried the replace and replaceAll methods but that did't work.
madagascar
  • 309
  • 1
  • 3
  • 6
29
votes
4 answers

Reading JSON with Apache Spark - `corrupt_record`

I have a json file, nodes that looks like…
LearningSlowly
  • 8,641
  • 19
  • 55
  • 78
29
votes
3 answers

Right Arrow meanings in Scala

In Chapter 9 of Programming In Scala, there is an example method like this: def twice(op: Double => Double, x: Double) = op(op(x)) The author said in the book: The type of op in this example is Double => Double, which means it is a function that…
Sawyer
  • 15,581
  • 27
  • 88
  • 124
1 2 3
99
100