Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.

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.

Filter by
Sorted by
Tagged with
0 votes
0 answers
86 views

I am working on a project where I need to transfer thousands of files (each sized between 50-60 MB) every hour from an SFTP server to local storage or AWS S3. I am using Apache Spark 3.5 with Scala 2....
Abhishek 's user avatar
1 vote
3 answers
508 views

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 ...
wrschneider's user avatar
  • 1,369
0 votes
1 answer
253 views

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) ...
AlleXyS's user avatar
  • 117
0 votes
1 answer
175 views

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 ...
Gesar's user avatar
  • 103
0 votes
2 answers
1k views

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 ...
User's user avatar
  • 23
0 votes
2 answers
331 views

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 ...
Saturnian's user avatar
  • 157
-2 votes
1 answer
693 views

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 ...
AlleXyS's user avatar
  • 117
-3 votes
2 answers
2k views

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, ...
Mike Nakis's user avatar
  • 32.8k
1 vote
1 answer
230 views

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 ...
Joe's user avatar
  • 174
3 votes
2 answers
265 views

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 ...
Sumit Jha's user avatar
  • 139
1 vote
1 answer
211 views

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. ...
Gimme the 411's user avatar
1 vote
1 answer
456 views

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 ...
Ben's user avatar
  • 121
0 votes
1 answer
358 views

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 ...
IcedDante's user avatar
  • 157
3 votes
3 answers
608 views

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 ...
ljleb's user avatar
  • 141
0 votes
2 answers
2k views

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 ...
Derek Plautz's user avatar
2 votes
2 answers
1k views

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 ...
Joseph Sible-Reinstate Monica's user avatar
2 votes
1 answer
143 views

In Scala, sometimes class extends a trait to provide some methods to extending class inside. ScalaTest import org.scalatest._ class ExampleSpec extends FlatSpec with Matchers { ... Matchers trait ...
bigwheel's user avatar
3 votes
3 answers
2k views

Is it preferable to define a single 'container event' like below: trait UserStatus case object Active extends UserStatus case object Inactive extends UserStatus case class UserStatusChanged(...
Damian's user avatar
  • 39
-1 votes
1 answer
551 views

I have some values and methods to define in a scala object. I do not know in which order I should define them. Is there a "good way" to do it? Such as private methods first then public methods? Only ...
BlueSheepToken's user avatar
2 votes
2 answers
451 views

Or simply asked WHY ? It simply does not seems logical ... if ( null.asInstanceOf[String] == null ) println ("null.asIstanceOf[String] is null") println ("BUT !!!") if ( null.asInstanceOf[...
Yordan Georgiev's user avatar
1 vote
2 answers
158 views

Suppose we need an iterative algorithm for mathematical optimisation. Each iteration takes a long and random time. After each iteration, a stopping condition is checked for the iterate x, based on ...
schrödingcöder's user avatar
2 votes
1 answer
104 views

I'm evaluating the migration of the following application's architecture: - Nginx + PHP + MySQL - Currently the infrastructure is scalable and redundant in the AWS cloud and It was designed to support ...
raul782's user avatar
  • 131
12 votes
2 answers
5k views

From what I can tell from Scala and Hack- Mixins: Can have state (ie. instance properties) Can only provide concrete methods Can have constructors, that are called in the same order that their ...
bcherny's user avatar
  • 273
4 votes
0 answers
320 views

This question came to me when I was trying implement Clean Architecture using Scala, and come across this post. In the accepted answer, @candiedorange emphasis on the separation of responsibility, and ...
Brian Hsu's user avatar
  • 201
1 vote
1 answer
316 views

I am a beginner to the event-driven data architecture using Kafka / Kinesis as the centrepiece (currently Kinesis) and I have some questions regarding how to build a WebSocket API on such a structure. ...
Julian Wilson's user avatar
2 votes
2 answers
192 views

In my previous Java job, we tended to avoid defining interfaces for everything unless we genuinely had multiple implementations for it. This may just be my opinion, but if there is only one ...
lgj's user avatar
  • 108
1 vote
1 answer
77 views

Project 1: a Java/Maven project Project 2: a Scala/sbt project Thing: generally, an immutable object instantiated in from 3rd party Java library. For example, ThingBuilder.foo("bar").build() ...
Pete's user avatar
  • 736
0 votes
2 answers
134 views

The Eclipse Scala IDE (and Intellij Idea, too) has, together with a standard REPL CLI, an artifact named Worksheet, that works like a persistent REPL log: the whole file is compiled and executed at ...
Michele Mauro's user avatar
5 votes
1 answer
896 views

I'm working on a Scala project and Wartremover shows an error about Option#get usage in my code: Option#get is disabled - use Option#fold instead While I do understand how get should often be avoided,...
Cedric Reichenbach's user avatar
3 votes
1 answer
432 views

In switching from a procedural background to "FP in the small, OO in the large" I'm grappling with the following problem. Suppose there're modules, each only containing numerical math functions ...
schrödingcöder's user avatar
1 vote
1 answer
1k views

I have the following pure function (f2 and f3 are pure too): class X { def f1(arg: Type1): Type2 = { val x = f2(arg) val y = f3(x) y } def f2... def f3... } Now, I would like ...
Ram's user avatar
  • 129
9 votes
2 answers
11k views

I have a mainly Scala application and I am interested in approaches to integrating Python code into this application in a way that is proven by you personally to be successful. In this context ...
Janek Bogucki's user avatar
0 votes
1 answer
194 views

I have some Scala code that I wish to unit test using ScalaMock: class CancellationManagerSpec extends FlatSpec with MockFactory { "Cancelling a shipment" should "check shipment is not already ...
Robo's user avatar
  • 109
5 votes
1 answer
861 views

My application's model includes a number of entities that share many common properties, and are operated on by many of the same classes. If I was using an ORM, I'd define an abstract class with the ...
FullTimeCoderPartTimeSysAdmin's user avatar
0 votes
1 answer
146 views

I've decided to implement a database wrapper to provide data operations of a web service using postgresql dbms. Models in my database are somelike complex and frameworks like slick do provide more ...
Evhz's user avatar
  • 152
5 votes
2 answers
1k views

I have written a simple class hierarchy to represent terms in Scala. Terms are recursive data types, e.g., a Sum and a Multiplication consist of the left-hand-side (lhs), which is a Term, and the ...
helios35's user avatar
  • 159
3 votes
2 answers
939 views

I have a one-way large ETL pipeline in Scala where I start with protobuf schema A and end up with protobuf schema B. I want to create a many-to-many mapping between the fields of schema A and schema B,...
Conor's user avatar
  • 109
1 vote
1 answer
127 views

Below are oversimplified examples, but I wonder which route to take what is the best practice when designing API, the simple or the more complex and robust which is better? This looks good and goes ...
Jas's user avatar
  • 507
0 votes
1 answer
891 views

Thanks Maven archetypes the barrier to start developing of services for new RESTful APIs is very straightforward - you can get more or less a project template and start filling in your code. Now as I ...
J. Doe's user avatar
  • 185
1 vote
1 answer
428 views

I'm working on a Scala project that uses DynamoDB for persistence, and does this by modelling the records as case classes. This is becoming increasingly more relational, which means we have classes ...
Matt's user avatar
  • 121
1 vote
2 answers
73 views

I have a Playframework application written in Scala. As you might expect, it's primary function is to respond to user requests. Typical request flow: Parse input and figure out what the user wants ...
FullTimeCoderPartTimeSysAdmin's user avatar
1 vote
2 answers
626 views

For example: scala> val a: String = "5" a: String = 5 scala> val b: Int = 5 b: Int = 5 scala> a == b res5: Boolean = false I expect a TypeError, like in Java: class MyClass { public ...
Akavall's user avatar
  • 455
3 votes
2 answers
255 views

In functional programming languages, such as Scala, data types and structures, are really important. I am in two minds about the use of type-defs in helping with the readability of the code ...
Maths noob's user avatar
2 votes
2 answers
459 views

I'm designing a simple scala wrapper library over a java library in order to make it more idiomatic scala. The problem I faced with is that all operations from the java library could throw an ...
alex's user avatar
  • 183
3 votes
1 answer
1k views

I wonder whether a method in a functional programming language should receive all variables from the argument list, or whether it is ok to use variables from the outer scope? But let me explain the ...
Raphael Roth's user avatar
3 votes
2 answers
907 views

Von neumann architecture allows sequential processing of instructions. So, a single core within a CPU executes instructions sequentially. Consider, OS providing 1-1 threading model(here) in a multi-...
overexchange's user avatar
  • 2,315
2 votes
1 answer
165 views

If the supervisor and its child actors are sharing the same messages, which is the right place to keep those case classes? Should it be in both Supervisor and the individual actors or should it be in ...
codingsplash's user avatar
4 votes
1 answer
692 views

I would like to solicit some general design principles and best practices to avoid creating a callback pyramid of doom particularly in the Scala language. Consider the following rudimentary and ...
Coder Guy's user avatar
  • 727
4 votes
2 answers
3k views

I have been having quite a time getting this to work reliably for 100s of thousands of terms and potentially millions of pages per source and ETL the resulting data into a database in an automated ...
user3916597's user avatar
26 votes
6 answers
7k views

Not too long ago I started using Scala instead of Java. Part of the "conversion" process between the languages for me was learning to use Eithers instead of (checked) Exceptions. I've been coding this ...
Eyal Roth's user avatar
  • 623

1
2 3 4 5