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.
239 questions
1vote
3answers
442views
Scala Option vs. conditional branches
If I'm writing Scala functions and have to check for nulls in situations where I can't avoid it (say, working with Spark UDFs and some legacy Java types), is it better to turn things into Option or to ...
0votes
1answer
240views
Sharing akka actors on multiple backend instances
I have a web applications (angular) which is connected to backend using websockets. The role of web app is to display data from multiple sources (which are updated constantly by some Scala Spark apps) ...
0votes
1answer
167views
Postgres: Storing a task instruction to be run on a schedule, with multiple workers
As a prerequisite I will say that we are wedded to postgres to provide this solution. This is a very broad problem, and I think it must be solved many times over, but unfortunately as it's so general ...
0votes
2answers
1kviews
Good design for a class with multiple methods to test but one public method
I've been trying to refactor some existing code which is in essence a giant nested procedural call inside what should otherwise be an object oriented architecture. The entry point to the relevant code ...
0votes
2answers
300views
Trying to understand how this class representation truly represents Natural numbers in Scala
Following Martin Odersky's course on coursera - Functional Programming with Scala and I'm on Week 4 where we're learning about Types and Pattern Matching. In the video lecture, this is the ...
-2votes
1answer
665views
Export huge excel file
I develop a web application in Angular (frontend) and Scala (backend) for a big data team. Because they use large files for export/import, I build a module which is a copy of Microsoft Excel. So, what ...
-3votes
2answers
2kviews
What is the benefit of Java collection streams over C# or Scala collections?
Java collection streams were introduced in Java 8, which came out in March of 2014. By that time, we already had well-established mechanisms for manipulating collections in several other languages, ...
1vote
1answer
208views
How to avoid code duplication from handling "structually similar types" in Scala?
Often, when programming, you'll have different degrees of information to you in different contexts. For example, a web server may have two routes, which recieve information about a Person, one of ...
3votes
2answers
248views
Operate on data that doesn't fit into JVM
We have a service where we have billions of key-value data stored in some storage. Before actually querying the data, we query the bloom filter to determine if the key may exist or definitely does not ...
1vote
1answer
186views
Is my server design safe regarding multiple threads and concurrent database reads/writes?
I'm making a chat server using sockets and a MySQL database, and after it's working I want to expand it to become a more complex game server. I want to know whether my design is missing anything. ...
1vote
1answer
435views
Preferable design for overriding sealed trait method in Scala case classes/objects
Say I have a sealed trait Person that requires the definition of a method work :: Unit -> Unit. I then have three case objects Accountant, Doctor, and Lawyer. I can think of two ways to implement ...
0votes
1answer
349views
Why is this "more efficient" version of a Scala Collatz solution slower than tail recursion?
I implememted two versions of the collatz problem and felt an icy terror in the pit of my stomach as an optimized solution was slower than tail. The tail recursion is simple: // calculate the next ...
3votes
3answers
574views
Does variance make sense in a fully immutable language?
In many OOP programming languages, types can be made co-, contra- or in- variant. Most (if not all of these languages) are able to let variables be mutated in place, i.e. they are not fully immutable ...
0votes
2answers
2kviews
Scala Option apply method when passed a None
Not sure if this is an appropriate question for here, please let me know! In Scala, the ever so useful Option class has an apply method in its companion object that allows us to quickly wrap any ...
2votes
2answers
1kviews
Is it a good idea to use "lazy val" for correctness?
In Scala, declaring a val as lazy means that its value won't be evaluated until it's used for the first time. This is often explained/demonstrated as being useful for optimization, in case a value ...