Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
0answers
13 views

Clean tests in Scala Akka

I am new to Scala and Akka and struggle with testing persistent actors in scala. Right now, we have tests like this (Bank Account example): import akka.actor.ActorSystem import akka.persistence....
0
votes
0answers
22 views

What design pattern should I apply to enable external services in this Scala module?

Let me show you a excerpt of the project I'm working on: trait TerminationChecker { val program: Program { val trees: Trees } val context: inox.Context ... def terminates(fd: FunDef): ...
0
votes
2answers
67 views

Scala: what has been the desired design consideration for the null instantiation in the example

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[...
1
vote
2answers
112 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 ...
2
votes
1answer
44 views

Architecture and Database re-design for migration and support of multiple clients

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 ...
2
votes
2answers
381 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
0answers
48 views

Should I pass presenter to use case when implement clean archeiture using scala

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, ...
1
vote
1answer
89 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. ...
2
votes
2answers
90 views

Trait and Implementation vs just Implementation

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 ...
1
vote
1answer
44 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() ...
0
votes
2answers
74 views

Do Scala worksheet (or REPL logs) belong to the SCM?

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 ...
4
votes
1answer
133 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 ...
2
votes
0answers
111 views

Dependencies between functions-only modules: hardcoding vs alternatives

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 ...
1
vote
1answer
372 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
0answers
33 views

Expose slick tables directly to upper layers of application or hide them?

I have an application that uses Slick 3.2 for data access. Currently the data access layer consists of DAO's with methods that return the results of queries marshalled into case classes. (So return ...
1
vote
2answers
924 views

Which approach for integrating Python code into a mainly Scala application did you use a second time because it was successful? [closed]

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 ...
0
votes
1answer
93 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 ...
2
votes
0answers
294 views

Class table inheritance using Slick: always an anti-pattern?

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 ...
0
votes
1answer
99 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 ...
5
votes
2answers
481 views

Avoiding instanceof for recursive data types

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 ...
3
votes
2answers
472 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,...
1
vote
1answer
78 views

Simplified API one case class vs robust and multi ADT case class? [duplicate]

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 ...
0
votes
1answer
451 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
1answer
164 views

Modelling relational database entities in a functional language

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 ...
1
vote
2answers
50 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 ...
0
votes
2answers
214 views

Why doesn't scala do type checking when checking for equality

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 ...
0
votes
0answers
165 views

iodiomatic future failures in scala

what would be the more idiomatic way to recover from a failed future val fut: Future[Option[Int]] = Future.failed(new RuntimeException("Hi, I have failed")) case class ApplicationException(msg: ...
3
votes
2answers
157 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 ...
1
vote
2answers
216 views

Designing Scala library which wraps a Java library

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 ...
3
votes
1answer
369 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 ...
3
votes
2answers
318 views

Using actor model, how can one program concurrent portion (critical section) of code as self contained nuggets?

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-...
2
votes
1answer
99 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 ...
5
votes
1answer
338 views

Scala Callback Pyramid of Doom

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 ...
5
votes
1answer
970 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 ...
11
votes
3answers
2k views

Why use Either over (checked) Exception?

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 ...
0
votes
1answer
99 views

In scala is it acceptable to have id variables written as `_id` instead of the regular camel case notation?

In Scala is it acceptable to have id variables written as _id instead of the regular camel case notation? In the code most variables respect the camel case notation. However for variables referring ...
1
vote
1answer
259 views

Future and Try duality [closed]

I was looking at this lecture, https://class.coursera.org/reactive-002/lecture/135 at 2:15. The lecturer talks about the duality of Future and Try in Scala. For his demonstration he changes the type: ...
1
vote
2answers
114 views

Type of map for Try[T]

I was looking at the type of map for Try[T] in Scala, which is: def map[S](f: T=>S): Try[S] From Haskell, I am used to the type of map being: map :: (a->b)->[a]->[b] This seems very ...
4
votes
1answer
80 views

Code style for parse-methods in Scala?

Say I have a class with multiple parameters: case class Foo(a: String, b: String, c: String, d: String, ... ) Now say I want to parse an instance of Foo from a Map[String, String]: // returns ...
3
votes
2answers
170 views

Designing a centralised command api

I'm working on a personal project that has a fairly complex UI. As much as possible I would like to remove mouse interaction. To help with that I am working on a kind of in app command line, where you ...
4
votes
1answer
745 views

Right way to read from token list to implement parse tree

I'm trying to tackle the While Language problem on HackerRank using Scala. I've been given a set of grammar rules and have to implement the actual interpreter underlying it. I've decided to approach ...
0
votes
1answer
116 views

Determine execution order based on declarative definition?

We want to create a DSL in Scala where you can declaratively list the ingredients that a product consist of. These ingredients can consist of for example "Create product a", "Create product b", "Send ...
4
votes
1answer
1k views

When to use Future[T] vs. Future[Try[T]] when the call might fail

I am slightly confused when to use which because futures are allowed to fail. If futures are allowed to fail, then to me, that sounds like a Try[] in itself. And if the Try[] is wrapped inside a ...
4
votes
1answer
64 views

What is the best pattern to define own type with definitive collection of values?

I want to define own data type, say a Digit, which would have definite type of values ( 0 to 9 ) and I'm struggling with defining this in a way it's practical. What's the best way (design pattern) to ...
0
votes
0answers
429 views

SQL/HQL in a Play framework controller and Service Layer pattern

I started using the Play Framework a couple of months ago. It "redefines" many conventions from the traditional Java world (like the way of using static methods among other things). I was browsing the ...
7
votes
3answers
1k views

Should databases be viewed as Monads?

Because any kind of persistence updates/inserts/deletes represents in some sense a kind of state change in a database, it makes me wonder whether databases can be considered monads. We say the same ...
61
votes
4answers
9k views

Is functional programming faster in multithreading because I write things differently or because things are compiled differently?

I'm diving into the world of functional programming and I keep reading everywhere that functional languages are better for multithreading/multicore programs. I understand how functional languages do a ...
2
votes
1answer
612 views

Why use tuples as function parameters in languages that support currying?

In languages that support currying, I can't think of many cases where using a tuple as function input parameters would be better than breaking the tuple apart into multiple parameters, which then ...
5
votes
2answers
1k views

Why does Scala name monadic composition as “for comprehension”?

Not sure if it's an appropriate question, but here it goes. I know Haskell's do notation pretty well. And I realized that Scala's "for comprehension" really is just mostly the same as do notation in ...
2
votes
1answer
140 views

How to represent data objects gradually getting augmented in a pipeline [closed]

I'm working on a Scala data-processing program. Essentially we start with a collection of many small data objects, say, (eventId: String, basicInfo: Basic) and gradually filter out some objects and ...