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.

67 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
12
votes
0answers
492 views

Binary Search Tree Monad Implementation

I've written a Binary Search Tree Monad in Scala. I would like to hear your thoughts on how to improve it (e.g. making insertion/deletion/search faster and more scalable). Also, is there a better way ...
6
votes
0answers
300 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 ...
5
votes
1answer
75 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 ...
5
votes
0answers
64 views

HListSum - Sum of HList's Nat's

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

Akka Streams Flow through a cache

Assume I have a cache: ...
5
votes
0answers
690 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 ...
4
votes
0answers
78 views

Checking membership of object in set without pattern matching

I'm curious in how to best structure code that checks for membership of an instance of an ADT in a set of elements without using pattern matching. Given the following ADT, methods and functions, ...
4
votes
0answers
78 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 ...
4
votes
0answers
125 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: ...
4
votes
0answers
502 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 ...
4
votes
0answers
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 ...
3
votes
0answers
60 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: ...
3
votes
1answer
2k views

Adding columns in Spark dataframe based on rules

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

Simplified Kata of BankOCR using Shapeless

I attempted to solve a simplification of User Story 2 using shapeless: Namely, define the implementation of: ...
3
votes
0answers
187 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 ...
3
votes
0answers
245 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 ...
3
votes
0answers
439 views

Immutable queue implementation in Scala

I created a queue in which we can perform Enqueue, Dequeue and Traversing in Scala. ...
3
votes
0answers
443 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 ...
3
votes
0answers
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 ...
3
votes
0answers
436 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 ...
3
votes
0answers
319 views

Functionally Typed I/O Streams

I thought up a function that provides types with InputStream and OutputStream: ...
3
votes
0answers
416 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 ...
3
votes
0answers
864 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 ...
2
votes
0answers
64 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, ...
2
votes
0answers
200 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 ...
2
votes
0answers
132 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 ...
2
votes
0answers
140 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}{...
2
votes
0answers
169 views

GitHub user graph crawler using akka

This code queries the GitHub followers API and stores the graph in a mongodb collection: ...
2
votes
0answers
193 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 ...
2
votes
0answers
202 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: ...
2
votes
0answers
144 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 ...
2
votes
0answers
63 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 ...
2
votes
0answers
46 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, ...
1
vote
0answers
42 views

Java classes to load configuration data from a JSON file, with Scala tests

I want to implement classes in a project that will support the loading of configuration data from a JSON file. The JSON file is in the following form. Please be as critical as you can be. I'm a junior ...
1
vote
0answers
49 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 ...
1
vote
0answers
46 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 ...
1
vote
1answer
115 views

Longest Substring Without Repeating Characters in Scala

Question is taken from Leetcode and solution works for their test cases. I do see a scope of improvement and make it more functional (getting rid of vars and mutables data structures). Please suggest ...
1
vote
0answers
41 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. ...
1
vote
0answers
117 views

Add an attribute to specific XML Elements in Scala

supposed I have an XML like ...
1
vote
0answers
627 views

WebSocket example with akka-http

Akka-http supports WS connections like that: ...
1
vote
0answers
1k 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-100mb and I would to compact them so as to have files at least say 100mb or 200mb. The logic of my code is find a partition to ...
1
vote
2answers
91 views

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

I have a function that looks like this: ...
1
vote
0answers
84 views

Purely functional octree and octree priority queue

I'm programming a game in Scala, and a lot of tasks are able to be done in the background. I've created a system in which each Future can be assigned a position in 3d space, and they are stored in an ...
1
vote
0answers
67 views

Choosing names for “logic” and “implementation” traits in Stackable trait pattern

I have a trait that is to be mixed-in with existing types of Actor classes in Akka and offer a certain functionality. To offer better maintenance, I am using the stackable trait pattern. The ...
1
vote
0answers
87 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, ...
1
vote
0answers
60 views

Sample Banking System Deposit Function

I am working on a sample banking system and have the following for deposit functionality, I was wondering if this is idiomatic, and how it can be improved. I have separated the algebra of the service ...
1
vote
0answers
85 views

Scala Functional Programming ODE Solver

I'm new to both Scala and Functional programming. I've been doing the excellent course Functional Programming Principles in Scala on Coursera and I want to test out what I've learned. I've written a ...
1
vote
0answers
68 views

Extending a simple Tree parser and lexer

Yesterday, I decided to learn about scala's Parser-Combinator library. After a while, I was able to write a simple Tree parser and lexer which understands trees written like this: ...
1
vote
0answers
45 views

cake pattern object assembly - using a builder function in combination with the cake pattern

I am new to the cake pattern, this is my first attempt at using it. Am I doing something wrong if I use the apply method in ...
1
vote
0answers
44 views

Cake Pattern with implicitly added functionality

I have a scenario where I want to implement a variant of a Cake Pattern, but adding implicit functionality to a class (a Spark DataFrame). So, basically, I want to be able to run a code like the ...