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.

77 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
7 votes
0 answers
518 views

Kattis problem Amanda Lounges

I wrote this solution to Kattis problem Amanda Lounges in Scala. TL;DR: It's a graph theory problem where I read in a list of edges from stdin and try to compute the minimum number of nodes that ...
user avatar
6 votes
1 answer
153 views

Readable unit test - lists of complex objects

Goal: Writing more readable tests. I have a couple of functions, which basically merge and converts two lists of Datasets together, written using Scala and Spark. Each of these Datasets has a lot of ...
user avatar
  • 161
5 votes
0 answers
66 views

HListSum - Sum of HList's Nat's

I wrote HListSum, whose type parameter is an input HList. Its Out type member represents the ...
user avatar
5 votes
0 answers
862 views

Akka Streams Flow through a cache

Assume I have a cache: ...
user avatar
  • 151
5 votes
0 answers
713 views

RandomForest multi-class classification

Below is the code I have for a RandomForest multiclass-classification model. I am reading from a CSV file and doing various transformations as seen in the code. I ...
user avatar
  • 153
4 votes
0 answers
100 views

Distributing work in scala

Below is a script to distribute jobs amongst workers while trying to maintain an even distribution of work and considering that not every worker can do every task. The solution I used is to find ...
user avatar
  • 2,381
4 votes
0 answers
139 views

VerbalExpressions in Scala

I forked the original implementation of VerbalExpressions in Scala here: https://github.com/pathikrit/ScalaVerbalExpressions I am looking forward to these things in the code review: ...
user avatar
  • 205
4 votes
0 answers
570 views

Custom Scala implementation of generic Future.sequence

I'm trying to make sure I understand how to write clean and robust idiomatic Scala, so I wrote a custom generic implementation sequence of type ...
user avatar
  • 141
4 votes
0 answers
1k views

Configuring a JMS Component in akka-camel

I'm trying to write a JMS Consumer using Akka-Camel. For now, I'm using FFMQ as a JMS server. I want to listen on the JMS queue myqueue. Creating the JMS ...
user avatar
3 votes
0 answers
176 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
0 answers
85 views

Finite State Machine to segment Thai syllables

I am developing a FSM to segment Thai syllables with the following rules: Here are my util functions: ...
user avatar
  • 896
3 votes
0 answers
2k views

Apache spark compaction script to handle small files in hdfs

I have some use cases where I have small parquet files in Hadoop, say, 10-100 MB. I would to compact them so as to have files at least say 100 MB or 200 MB. The logic of my code is to: * find a ...
user avatar
  • 131
3 votes
0 answers
82 views

Scala code that loops through Java annotations decorating Scala classes

I have code written in Scala that reads annotations decorating other Scala classes. These annotations are written in Java. The sticking point is that annotations don't allow advanced data structures, ...
user avatar
  • 131
3 votes
0 answers
2k views

Adding columns in Spark dataframe based on rules

I have a dataframe df, which contains below data: ...
user avatar
3 votes
0 answers
39 views

Simplified Kata of BankOCR using Shapeless

I attempted to solve a simplification of User Story 2 using shapeless: Namely, define the implementation of: ...
user avatar
3 votes
0 answers
197 views

Simple picture app for storing and viewing

Update: git repo: https://github.com/muhsinali/picture-example-minified This is my first project that I've written using Scala and the Play framework. It's a simple application that allows the user ...
user avatar
3 votes
0 answers
355 views

Finding the most frequent words in Scala using Akka

I'm new to akka and would like to get some feedback on my first attempt. The code takes text from stdin and finds the top 10 most frequently occurring words. Specifically, I would like to know Is ...
user avatar
3 votes
0 answers
521 views

Immutable queue implementation in Scala

I created a queue in which we can perform Enqueue, Dequeue and Traversing in Scala. ...
user avatar
3 votes
0 answers
664 views

Parallel Merge Sort in Scala

I have been trying to implement parallel merge sort in Scala. My current implementation is about as fast as .sorted, but I have no idea what would be the right ...
user avatar
  • 251
3 votes
0 answers
1k views

Combining pagination and non query grouping in Slick 3.0

I have the following tables: val postTable = TableQuery[Posts] val postTagTable = TableQuery[PostTags] val tagTable = TableQuery[Tags] One post can have multiple ...
user avatar
  • 131
3 votes
0 answers
461 views

A Timer Construct to Simplify Timing Blocks of Code

This is fairly simple, so I'm just looking for ideas on anything that can be cleaned up, places it can be extended, and suggestions regarding style/naming (I'm terrible at naming). It allows you to ...
user avatar
3 votes
0 answers
328 views

Functionally Typed I/O Streams

I thought up a function that provides types with InputStream and OutputStream: ...
user avatar
3 votes
0 answers
442 views

Slick database throttling trait based on the Playframework Slick plugin

I implemented a throttled database service trait for wrapping my service code in a future, supplying a slick session and throttling the # of requests in accordance to the length of the thread pool ...
user avatar
  • 131
3 votes
0 answers
919 views

Testing Scala code which depends on objects

I am writing a small oauth2 library for Play! 2.1 scala. As I am still learning I got stuck trying to TDD and ended up writing the code first, then refactoring for testability. By testability I mean ...
user avatar
  • 528
2 votes
0 answers
82 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
2 votes
0 answers
80 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
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
0 answers
676 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
2 votes
0 answers
178 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
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
2 votes
0 answers
298 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
2 votes
0 answers
268 views

Synchronous use of Mongo-Scala Driver

The Mongo-Scala Driver (v2.6) currently only supports asynchronous operations, although my use cases often seem to lend themselves well to synchronous reads. This may be to block downstream code ...
user avatar
2 votes
2 answers
130 views

Get the highest role of a user across all the organizations he is member of

I have a function that looks like this: ...
user avatar
2 votes
0 answers
99 views

Purely functional minecraft-like mesh compiler

I'm creating a minecraft clone (for practice), in scala, using largely functional programming. When a chunk doesn't have a mesh loaded into VRAM, it create a Future for the vertex and index arrays, ...
user avatar
  • 267
2 votes
0 answers
312 views

Scala Performance in Solving Sudoku

I translated Peter Norvig Python Sudoku solver to Scala and my Scala implementation was slower in the order of few magnitudes e.g. instantaneous, in Python, vs 4 to 5 seconds. I suspected I didn't ...
user avatar
  • 121
2 votes
0 answers
158 views

Reduce sample rate of GPS data based on distance between points

The algorithm needs to reduce an RDD[GPSRecord] based on the distance between several points, e.g. "give me only GPS records when the distance between them exceeds ...
user avatar
2 votes
0 answers
197 views

Calculating Pi to a tolerance

I'm taking my first steps in the Scala world, though I'm not wholly unfamiliar with functional style. Apparently one way of calculating Pi is to sum the terms of the infinite series: $$4 * (\frac{1}{...
user avatar
  • 839
2 votes
0 answers
174 views

GitHub user graph crawler using akka

This code queries the GitHub followers API and stores the graph in a mongodb collection: ...
user avatar
  • 1,429
2 votes
0 answers
261 views

Union-find implementation

Here are a few questions on my mind: What improvements to the above code can you think of? I want to say new UnionFind(x) where ...
user avatar
2 votes
0 answers
281 views

Needleman Wunsch algorithm in Scala

The Needleman–Wunsch algorithm is an algorithm used in bioinformatics to align protein or nucleotide sequences. Here is an implementation in Scala: ...
user avatar
  • 1,429
2 votes
0 answers
170 views

Frequency of words in all files of a directory using Future - Scala

I created a program to get frequency of word in all files in a directory using Future API ...
user avatar
2 votes
0 answers
66 views

Console User Interface Framework

I've been learning Scala and I'd love to get your feedback in order to improve. As an exercise I made a simple framework for creating command-line user interfaces. Gist ...
user avatar
  • 121
2 votes
0 answers
51 views

Functional, Loaner-Like Pattern For Consuming SQS Queues, Deleting Queue Items On Success

My program fetches input from a RabbitMQ or Amazaon SQS-like queue. There is not always input available in the queue. If a message is available, it triggers work. If that work is successful, ...
user avatar
2 votes
0 answers
524 views

Scalaz state monad exercise to model sampling of coloured balls

Here is a self imposed exercise and solution to learn Scalaz state monad. How can I refactor it to take it to the next level? So far I've only studied the state monad so would welcome suggestions on ...
user avatar
  • 121
1 vote
0 answers
22 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
1 vote
0 answers
32 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
0 answers
287 views

KMP algorithm in scala

I implemented KMP pattern matching algorithm in Scala. My code works but it looks more imperative and a scala translation of C/C++ implementation. I am not able to figure out how to manage multiple ...
user avatar
  • 345
1 vote
0 answers
119 views

Closest 3Sum in Scala

This question is taken from Leet code. Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three ...
user avatar
  • 345
1 vote
0 answers
49 views

NQueen solution in scala

This is my solution for NQueen problem in scala. I just want to know how to make it more easy to read, modular and areas i need to improve. ...
user avatar
1 vote
0 answers
458 views

Add an attribute to specific XML Elements in Scala

supposed I have an XML like ...
user avatar
  • 113