2022 Developer Survey is open! Take survey.

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
1 vote
0 answers
18 views

Scala & Kafka: Getting the producer and consumer offset difference and log it

I'm looking to compare kafka's producer and consumer ...
user avatar
  • 111
2 votes
1 answer
52 views

Batching method implementation - Scala

I need to implement a function/method that operates on a sequence of values, and acts kind of like takeWhile, but with 2 differences, first, it doesn't act on a single element, it is performed on a ...
user avatar
  • 121
1 vote
1 answer
132 views

Get tennis game's state using scala

I am developing a scala function called TennisGameStatus which returns the state of tennis games between two players. To remind, here are the rules of tennis games :...
user avatar
  • 11
0 votes
0 answers
14 views

Readiness Prob for Akka and Scala Service

I want to create Readiness prob for two Akka typed actors, each actor uses Aerospike In order to fetch data, so i guess that the best way to achieve readiness prob ...
user avatar
  • 101
1 vote
0 answers
31 views

Relational join of two datasets

Front Matter I'm learning Scala and have not gotten used to functional programming and the language. I'm hoping a review of my naively implemented code can help me bridge my object-oriented ways to ...
user avatar
  • 111
1 vote
2 answers
59 views

Extracting items from comma/semicolon-delimited strings, discarding parts after a hyphen

New Scala dev here. Is there a more idiomatic or efficient way to accomplish this in Scala? Given a list of the following strings, I need to obtain the unique 'main parts' once any parts including ...
user avatar
2 votes
2 answers
558 views

Scala Parentheses Balancing in Functional Programming

I was working on the problem to check if the parenthesis are balanced using Scala. Examples: balance("(Hello (my) name is (StackOverflow))") -> ...
user avatar
  • 207
2 votes
0 answers
81 views

Deserialize a binary breadth-first in functional programming

A while back, I answered this question on Stack Overflow that involved deserializing a binary tree breadth-first using functional programming (the question itself isn't relevant). I'd like to make ...
user avatar
  • 499
1 vote
1 answer
66 views

Checking whether a graph is connected in an immutable way

I have this function at the moment ...
user avatar
0 votes
0 answers
39 views

Either without return in Scala

IntelliJ warns me that I should avoid using return. If sender is empty, the function should not continue parsing the bytes. The return value of ...
user avatar
2 votes
3 answers
87 views

Is My Function to Find Triplets in Scala running in O(N^2)

Given the classical problem to find triplets that sum to zero in an array. Is my Scala implementation correct and executed in O(N^2)? If yes, why? Can someone make a running time analysis. What other ...
user avatar
2 votes
0 answers
72 views

Scala 3 Typeclass derivation using low-level mechanisms: The `Eq`-example

I've been playing around with this example from the Scala 3 documentation, and I noticed that certain things duplicate functionality already present in the standard API; In particular, the ...
user avatar
0 votes
0 answers
63 views

Efficiently calculate value of Pascal's Triangle using memoization and recursion(updated)

Follow up to Efficiently calculate value of Pascal's Triangle using memoization and recursion Based on feedback given by jvwh in the answers ...
user avatar
3 votes
1 answer
140 views

Efficiently calculate value of Pascal's Triangle using memoization and recursion

So reading about functional programming, applications to dynamic programming, and learning Scala. I figured I would try it out with a popular example, Pascal's Triangle, tests against known values ...
user avatar
4 votes
1 answer
88 views

Improving Mancala Game

https://www.mastersofgames.com/rules/mancala-rules.htm I am trying to create a working Mancala Game in scala, Currently, I have 3 classes, Board, ...
user avatar
0 votes
1 answer
553 views

filtering element of one List from another in Scala with different tuple structure

I am trying to understand the best way to write this. This is part of my organization work so can't disclose it fully here like why such requirement. So Apologies for that. I have ListA and ListB. <...
user avatar
1 vote
2 answers
672 views

Find All Permutations of String in Scala

I created the following function, permutations, to produce all permutations of a List[A]. Example: ...
user avatar
1 vote
1 answer
101 views

Find Permutations of String in Scala

Given a smaller strings and a bigger string b, design an algorithm to find all permuta­tions of the shorter string within the longer one. ...
user avatar
1 vote
2 answers
54 views

Keyword classification in Scala... simple? [closed]

I am pretty newbie in Scala, my background expertise is basically Java and Python, and I'd like to know your thoughts about this code snippet written in Scala to know if this is a "regular piece ...
user avatar
1 vote
1 answer
76 views

Group events close in time into sessions and assign unique session IDs

The following is a trimmed-down example of my actual code, but it suffices to show the algorithmic problem I'm trying to solve. Given is a DataFrame with events, each with a user ID and a timestamp. <...
user avatar
0 votes
1 answer
434 views

Stack Implementation in Scala

I would like to get feedback on my code for Stack implementation written in scala. What can be improved to make it more like scala code. What important helper functions am i missing? ...
user avatar
1 vote
0 answers
31 views

Managing and referencing items in an immutable store [closed]

I have some things (I'll call them Items) that can either be passed around directly or referred to by reference. For the items that are referred to, there is a ...
user avatar
  • 189
2 votes
3 answers
658 views

Concatenating optional strings in Scala

I have two optional strings, any of them can be None. I want to create their combination with a delimiter between them if they both exist. I expect to be able to come with a more concise and nicer ...
user avatar
  • 226
2 votes
1 answer
105 views

Scala: drop elements in Sequence

Can I reduce the loop inside my method with map or is there a shorter implementation of this code that's dropping elements in sequence? ...
user avatar
2 votes
0 answers
41 views

Grading script in SCALA

The prompt is as follows: This script will use a text menu to give the user options. The options will include the ability to add grades of different types as well as an option to print the current ...
user avatar
2 votes
1 answer
48 views

Scala function to parse json with time fields to appropriate case classes. How can I write this better?

I have the below function which populates different time-related case classes based on what is present in the JSON input. ...
user avatar
  • 121
3 votes
0 answers
170 views

SBT Helm plugin

Description I've created simple SBT plugin which enables creating Helm Charts The main reasons: in Helm it is impossible to 'fetch' external files: https://github.com/helm/helm/issues/3276 which is ...
user avatar
  • 139
3 votes
1 answer
134 views

Rewriting scala code in object-oriented style style to reduce repetitive use of similar functions

I need help in rewriting my code to be less repetitive. I am used to coding procedural and not object-oriented. My scala program is for Databricks. how would you combine cmd 3 and 5 together? Does ...
user avatar
6 votes
2 answers
366 views

Improving my Tic Tac Toe Solution in Scala

I'm relatively new to Scala and made a small TicTacToe in a functional Style. Any improvement options would be highly appreciated. There are some things which I am unsure of if they are made in an ...
user avatar
  • 179
3 votes
1 answer
171 views

Improvements, TicTacToe in Scala

I've just started my journey into functional programming and tried to implement a TicTacToe game Recursively without State in Scala. What I dislike is the JOptionPane but I don't know if i can solve ...
user avatar
  • 179
4 votes
1 answer
84 views

Convolution function

I implemented the following function using the matrix object from breeze library. Basically it is just a glorified while loop. The convolution there is extremely ...
user avatar
  • 141
2 votes
1 answer
194 views

argmax of List of Double

Here is my implementation of arg max in Scala. q_table_test.txt contains: ...
user avatar
  • 557
2 votes
0 answers
609 views

Spark Scala: SQL rlike vs Custom UDF

I've a scenario where 10K+ regular expressions are stored in a table along with various other columns and this needs to be joined against an incoming dataset. Initially I was using "spark sql rlike" ...
user avatar
  • 43
3 votes
2 answers
285 views

Compressing string in Scala, how to do this immutably?

I have a string "abbbbccdddd" and the function should return "a1b4c2d4". This is what I have written in Scala. Iterative-version ...
user avatar
3 votes
1 answer
44 views

Scala code to insert a row into Hbase

Below is a case class and a companion object with a method putRecord which adds a new row into Hbase using Put API. This code has some repetitive parts. Is there a ...
user avatar
  • 131
3 votes
1 answer
79 views

How to make it more Scala compatible?

When you write a code in python code people always ask to make it more pythonic. I am not sure if there is a term for scala or not. However, I am pretty sure my following code use one or two scala ...
user avatar
3 votes
1 answer
57 views

Scala: Cumulative String Tokenisation

I'm trying to split an incoming stream of strings into cumulative tokens per line item using a function below, ...
user avatar
  • 43
-1 votes
2 answers
53 views

A better OOP way for solution

I am implementing a functionality in Scala to Copy files from one FileSystem to another ...
user avatar
0 votes
0 answers
49 views

how should I optimise the scala code and make it more readable

I have this ugly massive piece of code. It does many things, mostly around querying databases. Each query depends on the result of the previous query or on the parameters of the incoming request body. ...
user avatar
  • 9
4 votes
1 answer
88 views

A simple data class based on an existing collection (Scala)

I'm fairly new to Scala and I would like to learn it properly. My current task is to create a type to represent a heap, as seen in interpreters: a mapping from addresses in memory to values stored ...
user avatar
  • 93
2 votes
1 answer
71 views

What is better to use for mapping value to Map of functions: tail recursion or foreach?

I want to map functions from my functions library (Map called as chain) to input string str. ...
user avatar
  • 186
3 votes
1 answer
76 views

Clean up tags from a text

I need to generate random text for tests. I do that using alphanumeric characters and some special characters as well. For some special cases, I cannot generate the random text with tags. I have the ...
user avatar
  • 149
2 votes
1 answer
194 views

Integrating caliban, ZIO and Akka

I created a small sample project using caliban, akka-persistence and ZIO. I'm not really happy with the wiring code: ...
user avatar
  • 100
0 votes
1 answer
84 views

implementation of atoi in scala

I've implemented atoi function as described in leetcode problem string-to-integer-atoi. I am looking for some feedback on writing this in a more scala native way ...
user avatar
2 votes
0 answers
176 views

generic implementation approaches for a recursive function

Let's take the famous fibonacci problem as an example but this is a generic problem. Also, taking scala as the language as it's rather feature-rich. I want to know which solution you'd prefer. we all ...
user avatar
1 vote
1 answer
90 views

Scala graph coloring

i have solved this problem https://leetcode.com/problems/find-eventual-safe-states/submissions/ ...
user avatar
  • 1,027
2 votes
0 answers
42 views

Finite automaton library in Scala including subset construction and minimization

I built a scanner generator like flex or jflex in Scala for a class last year. Part of this project is a small library for handling and manipulating finite automata. It works completely as intended, ...
user avatar
  • 173
-1 votes
1 answer
55 views

Functional filter unique elements in sequence is not as good as imperative [closed]

Can you please help me fulfill the following? Requirements: Create an iterable with unique elements. Their order should be preserved: a | b | a | c → a | b | c ...
user avatar
2 votes
0 answers
288 views

Bellman-Ford Implementation in Scala/Java

I think the part to get shortest path from the cost table got pretty messy. Also can use some tips on how to avoid the extra O(V+E) work checking all edges from source to dest after getting the cost ...
user avatar
  • 153
1 vote
1 answer
586 views

Perfect Number usage in higher order function

I am new to Scala. I have been trying to complete an exercise where the ask was as follows: // Write a function isPerfectNumber which takes integer input and returns String output. // It finds if a ...
user avatar
  • 111

1
2 3 4 5
11