A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

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
2
votes
2answers
366 views

A Scala Maze Generator in Functional Style

I'm wondering if there is more I can do to incorporate more idiomatic scala and functional programming principles. I know the maze itself is mutable but i didn't see an easy solution to making it ...
2
votes
1answer
85 views

Building and querying an immutable phone book

I wanted to get your opinion on this immutable implementation of a Phone Book using recursion to process a stream. I am especially interested in ways to speed up the code execution. Here is an ...
1
vote
2answers
108 views

Record parsing to Scala object with some unknown fields

I am getting some customer data but don't know the complete schema beforehand. I want to parse this data and create a Scala object from it. But due to unknown fields in the record, I fill only the ...
4
votes
0answers
82 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 ...
1
vote
1answer
122 views

Triangle numbers finder in Scala

I'm new to Scala and learn it by solving some Project Euler problems. Here is the solution to problem 42 from Project Euler. The task is to read words from file, then sum ordinal numbers of each ...
0
votes
1answer
160 views

Extract Element and its Followers from List

I wrote the following function to convert List[Int] => List[List[Int]]. Its intended purpose is to extract 1, followed by ...
3
votes
1answer
87 views

Classifying and counting database entries using Scala map and flatMap

I am new to Spark and Scala and I have solved the following problem. I have a table in database with following structure: ...
2
votes
1answer
308 views

List-manipulation exercises in Scala

I have been using Scala as a means to learn Functional Programming and writing better code. However, I have some questions regarding some exercises or if there's a better way to approach them. In the ...
6
votes
2answers
626 views

Monte-Carlo method to estimate Pi runs slower in multiple threads, than in single thread

I'm learning Scala, and I wrote a program to estimate the value of Pi. When I'm using multiple threads, it takes 5-6 times longer to calculate the same iterations. I wrote a similar program in Java, ...
0
votes
1answer
165 views

Generic Int conversion to scalar

I'm new to Scala and I'm trying to write a generic function to convert from Int to any scalar. For example: ...
4
votes
1answer
159 views

Solving a digitwise addition equation in Scala

I've written the following codes in Scala and Java to solve cryptarithmatic problems. E.g. For SEND+SOME=MONEY, assign the digits 0 to 9 such that the equation holds true. The algorithm I've used is ...
1
vote
2answers
227 views

Applying Function to `Seq[B]` in `Seq[Either[A, B]]`

Given: ...
1
vote
1answer
2k views

Building a query URL in Scala

I'm working on a webapp in ScalaJS and want to create a query url for requesting some JSON. Right now I'm using a method called urlBuilder to take the query options from an Options case class and ...
0
votes
1answer
60 views

Unifying trait for tabular data in Scala

This trait is meant to be a simple interface for tabular data from different file types, such as csv, excel, open office etc. Right now I'm only asking about some of the top level code for now and ...
0
votes
1answer
4k views

Unit testing Spark transformation on DataFrame

Looking for suggestions on how to unit test a Spark transformation with ScalaTest. The test class generates a DataFrame from static data and passes it to a transformation, then makes assertion on the ...
8
votes
1answer
288 views

Game of Life in Scala with a sparse representation

While reviewing another Scala implementation of the Game of Life, I ended up drastically rewriting it. The board is represented as a Set[(Int, Int)] containing the ...
1
vote
1answer
90 views

Parsing latitude and longitude, using Try[T] to ignore errors

I wrote this question asking about how to implement my error handling while still maintaining functional code and based on 200_success's very interesting note on the spaces, I decided to ...
6
votes
1answer
413 views

Conway's Game of Life in Scala

To learn Scala, coming from Java and Python, I'm attempting to program an implementation of Conway's Game of Life. I've implemented two different approaches so far, with the first being so bad I'm ...
2
votes
2answers
568 views

Convert a String with comma separated latitudes and longitudes to a Seq[Coordinate]

I have a function that receives a String like the following: "-10.0 -10.0,10.0 10.0,0.0 0.0" And needs to translate that into ...
0
votes
2answers
754 views

Recursive Scala Case class Reduction

I have a case class that is recursive and looks like this: ...
2
votes
0answers
171 views

GitHub user graph crawler using akka

This code queries the GitHub followers API and stores the graph in a mongodb collection: ...
0
votes
1answer
384 views

Simple Scala money library

for some fun, I decided to start working on something that let me work with Money calculations. I realise there are libraries out there like Joda Money, but I'm doing this mainly for fun. I was ...
1
vote
1answer
611 views

Hamming distance in Scala

Problem Write a program that can calculate the Hamming difference between two DNA strands. GAGCCTACTAACGGGAT CATCGTAATGACGGCCT ^ ^ ^ ^ ^ ^^ Code ...
2
votes
1answer
751 views

Anagram in Scala

Code ...
5
votes
3answers
152 views

Nucleotide count in Scala

This is my second day in learning Scala and I still need to develop a taste of functional programming, I often find myself doing imperative coding. Below is the result of my TDD practice. Code ...
2
votes
1answer
366 views
1
vote
1answer
213 views

Little Sudoku solver

I always have enormous difficulty working out 2D grid addresses, so for me it is easier to work with the List functions. All tests pass and I'm looking for feedback ...
1
vote
1answer
421 views

Akka streams: Bidirectional flow that completes the stage when one side is completed

This is meant to be a bidirectional flow BidiFlow that works exactly as BidiFlow.identity, except that it completes the stage as soon as one of the Flows (in1 -> ...
5
votes
2answers
503 views

Rate limiter utility class

I had a problem in my system where the class that sends messages to other systems sometimes gets flooded and so I needed to add rate limiting. I threw together something that would work, but I would ...
1
vote
1answer
182 views

Implementation of API to create a company account in a database

I'm working on an API that has a lot of controller functions like this: ...
2
votes
1answer
117 views

Anagram counter

Homework prompt was: You are given two strings, a ‘parent’ string and a ‘query’ string respectively. Your task is to determine how many times the query string – or an anagram of the query string ...
2
votes
1answer
93 views

Checking whether a game board is full

I have a method in Scala that checks if a game board is full or not. To speed this method up, I return inside the nested for loop to break out of both of them and stop execution. How would I achieve ...
2
votes
0answers
202 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 ...
1
vote
0answers
29 views

Getting all timeDuration from a day which are not in a list of timeDuration in Scala

I have a list of timestamp tuples of the form List((startTime,endTime)), which are basically denoting periods of time throughout the day. For example: ...
2
votes
1answer
46 views

Pushing data to an analytics API

This is code that handles pushing data to an analytics API, and IMO it feels too much like Java. logActivity is a method that uses ...
1
vote
0answers
204 views

Merging trees in scalaz

I just built a function to merge a set of List[A]s into a single scalaz.Tree[A]. Specifically, if I have the following three <...
4
votes
1answer
205 views

Segmented Sieve of Eratosthenes in Scala

I'm trying to solve PRIME1 in SPOJ with the following Scala snippet: Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between ...
3
votes
2answers
88 views

Building a Tree from Breadcrumbs

I need to transform List("home", "mens", "clothing", "jackets") into ...
2
votes
1answer
74 views

Print Trace Debugger

Notice: The original library has since been replaced by: https://github.com/JohnReedLOL/scala-trace-debug See my Scala print trace debugger. This project is used for lightweight debugging sort of ...
4
votes
1answer
804 views

Determining the HTTP status code to return for a request

I have a piece of code that I would like to refactor but can't figure how to do it. This is a method from a Play controller where I have to verify many precondition and respond different status for ...
2
votes
0answers
219 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
2answers
203 views

Longest palindromes

I've been tasked to solve this exercise lately, and this is what I wrote: ...
4
votes
2answers
2k views

Limit HTTP request rate for spray/akka-http

I want to limit the request rate in a spray/akka-http route. I'm not an expert with both scala and spray/akka but learning. So I came up with the following custom directive: ...
3
votes
0answers
259 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 ...
2
votes
0answers
149 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 ...
1
vote
0answers
35 views

Stronger Functor TypeClass

I'm working on arrow library for scala I've come with some new typeclass, which looks like generalized Functor ...
3
votes
0answers
473 views

Immutable queue implementation in Scala

I created a queue in which we can perform Enqueue, Dequeue and Traversing in Scala. ...
3
votes
1answer
64 views

Implicit type class for updating maps

With the help of SO I got my code working, but I think it still could be improved, in particular I do not like using asInstanceOf. Is there some way how to avoid it?...
3
votes
1answer
3k views

List of Files in any Folder - Scala

I have written a code to count the number of files in a folder and if there are any folder inside folder it will count the files in that folder too. ...
8
votes
1answer
167 views

Scala implementation of @rolfl's integer-partitioning algorithm

While reviewing @Martijn's Distinct sums of integers (finding all combinations of positive integers that sum to a given number), I proposed the following solution: ...