In accordance with our meta agreement, since one candidate received more votes than the others, we have a new featured language! Throughout January 2021, our Language of the Month will be:
Scala
What's a Language of the Month?
See the meta post for nominations. In short, during January, those who wish to participate should learn (at least the basics of) Scala, and use it to solve challenges. Participation is completely optional, but is anticipated to be fun!
Information about Scala
Scala is a general-purpose programming language that combines OOP and FP and improves a lot on Java. It mainly runs on the JVM, but there's also Scala Native and ScalaJS.
Some nice things about it:
- Concise (and pleasing) syntax that sometimes makes it feel like a scripting language (here is a comparison between ScalaJS and ES6 and TypeScript.
- The standard library is amazing and has useful methods such as
filter
,combinations
andcollect
. - Implicits are very powerful and can be used for everything from simply reusing values to doing logic programming at compile time.
- Type inference means you don't need to declare types explicitly, except for method parameters (and return types in recursive methods).
- For comprehensions are a lot shorter than using multiple
flatMap
s andfilter
s, and you can even create variables without using theval
keyword inside them. - Pattern matching is convenient, and helps in destructuring declarations.
- User-defined operators save bytes.
list1.concat(list2)
can be replaced withlist1 ++ list2
. Infix and postfix (the latter is deprecated) also save bytes. - Its type system is Turing complete, and using literal types and a couple dependencies, you can even do compile time operations on primitives and such.
- There's a research compiler called Dotty that adds a ton of features to Scala and is slated to be released as Scala 3.
- Scala makes immutability really easy - all you have to do is use
val
instead of usingfinal SomeType
, like in Java.
Resources
- Chat room (it's not very active, but I'll be happy to help if you ask any questions there)
- Tour of Scala
- Scala Standard Library
- Scastie - an online playground tailored to Scala that (in my opinion) is better than TIO.
- TIO
- Tips for golfing in Scala
Bounty
Answers in Scala will be eligible for a bounty of 50 rep if you have not posted an answer in Scala before. Sorry, but if it's a question that I (user) have already answered, I'll only award the bounty to an exceptional answer, since it starts at 100 rep.