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.
240 questions
0
votes
0
answers
88
views
How to connect to SFTP using Apache Spark 3.5 with Scala 2.12 for parallel file transfers?
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....
0
votes
1
answer
253
views
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) ...
0
votes
2
answers
1k
views
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 ...
-2
votes
1
answer
693
views
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 ...
1
vote
1
answer
230
views
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 ...
1
vote
1
answer
212
views
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.
...
0
votes
1
answer
358
views
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 ...
0
votes
2
answers
2k
views
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 ...
2
votes
1
answer
143
views
Extends for feature (aka mix-in) in Scala is bad practice, isn't it?
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 ...
-1
votes
1
answer
551
views
In which order functions should be defined scala methods
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 ...
1
vote
2
answers
158
views
How can an iterative algorithm be controlled dynamically?
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 ...
12
votes
2
answers
5k
views
What's the difference between a Mixin and a Trait?
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 ...
1
vote
1
answer
316
views
Building a real-time API on a Kafka/Kinesis-centric structure
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. ...
1
vote
1
answer
77
views
Java/Maven and Scala/sbt projects share immutable thing
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()
...
5
votes
1
answer
896
views
Is using Option#get really a bad idea here?
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,...
1
vote
1
answer
1k
views
Does dependency injection fly in the face of functional programming?
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 ...
0
votes
1
answer
194
views
Unit testing certain tasks are done in a process
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 ...
0
votes
1
answer
146
views
Can a database wrapper be implemented in Scala using Traits? Is there a better way?
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 ...
3
votes
2
answers
939
views
Reverse engineering an ETL pipeline
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,...
0
votes
1
answer
891
views
RESTful API with Scala using Jersey?
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 ...
1
vote
2
answers
73
views
In my use case, does it make sense to make every major method return an async result?
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 ...
3
votes
2
answers
255
views
functional programming: impact of typedef-ing datatypes on code readability and maintenance
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 ...
3
votes
1
answer
1k
views
Should I pass all arguments to a method explicitly in functional programming?
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 ...
2
votes
1
answer
165
views
Placing case classes
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 ...
4
votes
2
answers
3k
views
How to make a webdriver run reliably in Selenium?
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 ...