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.

learn more… | top users | synonyms

0
votes
1answer
57 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: ...
3
votes
1answer
38 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 ...
1
vote
1answer
71 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
32 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 ...
0
votes
0answers
31 views

Using actors to collect paged data structures exposed through REST API

I've come up with a small exercise to learn scala consisting of making a client that assembles a graph available as a resource. The API server responds with a paged list of edges, in the form of ...
1
vote
0answers
24 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
37 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 ...
0
votes
0answers
31 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
44 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
49 views

Building a Tree from Breadcrumbs

I need to transform List("home", "mens", "clothing", "jackets") into ...
2
votes
1answer
63 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
0answers
44 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
46 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: ...
1
vote
2answers
115 views

Longest palindromes

I've been tasked to solve this exercise lately, and this is what I wrote: ...
4
votes
2answers
121 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
71 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
28 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
22 views

Stronger Functor TypeClass

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

Object to YAML (and viceversa) conversion in Scala

In order to learn Scala, I'm writing a simple module that takes a Service object I defined and serializes it in YAML format. This is the definition of my ...
2
votes
0answers
60 views

Immutable queue implementation in Scala

I created a queue in which we can perform Enqueue, Dequeue and Traversing in Scala. ...
1
vote
1answer
35 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 ...
2
votes
1answer
41 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
85 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: ...
3
votes
3answers
48 views

Producing uniform lists in Scala

When writing an answer to another question here, I came across the problem of producing lists of integers having a certain total and only consisting of a certain number and an optional rest. So for ...
4
votes
2answers
66 views

Functional translation of dice simulation

I have tried my hands at "functionalising" a toy problem I had: find the expected number of throws of a six sided die until all sides have been seen (the answer is 14.7) My starting point is my ...
1
vote
1answer
24 views

Similar 2 classes in Scala need to refactoring

I am newbie in scala don't know how to refactor to make it better because currently it kinds of boring when read it. I have 2 classes BidWinPostData and BidEventPostData. They are kind similar the ...
0
votes
0answers
28 views

PBKDF2 and HMAC implementation in Scala

First of all: I know that rolling your own cryptographic functions is bad. The SHA256 implementation i use is from Bouncycastle, but i think both HMAC and PBKDF2 are not vulnerable to timing attacks ...
0
votes
2answers
50 views

Adding polynomials represented as maps

I'm using maps to represent a polynomial. The key is the exponent and the value is the coefficient : Map(exp -> coef) e.g. ...
7
votes
3answers
122 views

Distinct sums of integers

I need to get the distinct sums of naturals of a natural What I came up with is: ...
1
vote
0answers
61 views

collect and parallelize in spark performance

the below code is working fine, but as this is new for me, please help to improve performance. as I have not included yet my complex logic but confused over collect and parallelize. Aim is to collect ...
6
votes
0answers
77 views

Caching side effects

Is this a proper way to cache side effects (occurring on job.tryLoad)? ...
4
votes
1answer
171 views

Solution to part 1 of Day 7 Advent of Code in Scala

Does someone want to review my solution to part 1 of Day 7 Advent of Code in Scala? The assignment is here: http://adventofcode.com/day/7 Without repeating the whole text, in short: Given a text file ...
4
votes
1answer
77 views

Return different type of response based on Accept header

I'm a novice to Scala and Akka-Http and am experimenting with Akka-Http for writing rest services. I have to return JSON or protobuf based on the Accept-Header. ...
3
votes
1answer
139 views

Handling HTTP requests and saving user to database

I am using Play Framework and Slick. In userController.scala I am handling HTTP post requests and sending to personRepository.scala. Is this controller and method written in the correct way? ...
4
votes
0answers
88 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 ...
0
votes
2answers
109 views

Divide list into n parts in scala [closed]

The problem is to divide a list into n parts according to a predicate. I found recursive solution but I am sure that a more elegant solution also exists. ...
14
votes
4answers
245 views

Ising Model - Atom Vibration Simulation in Scala

I am an experienced Java developer (12+ years) and have recently switched to Scala and I love it. However I feel not comfy yet and I have a feeling that I might use to many paradigms from the good old ...
1
vote
0answers
21 views

Handling state in actor

The following Actor monitors file by getting events from watchservice actor that sends a message to the actor and notifies for event (create,modify or delete), would love to know how I may improve ...
1
vote
0answers
29 views

Let user add rows to table

I'd like the user to be able to add rows to a table in my Play application written in Scala. The row is defined in a custom tag and makes use of Bootstrap via the plugin by Adrian Hurt. My current ...
2
votes
1answer
133 views

Scala list to tuple conversion

...
2
votes
1answer
79 views

Scala code to print a Sudoku board and any possible unsolved values

I'm working through a Sudoku solver problem that I found at UPenn (no it's not my homework ;)). I'm a beginner at Scala, and I'm trying to write good functional code (not that this particular method ...
6
votes
2answers
147 views

String Calculator Kata in Scala

This is my solution of string calulator kata in scala(i'm new of tdd). I'd like a general review of this. String Calculator Create a simple String calculator with a method int Add(string ...
3
votes
1answer
68 views

Generating the maximum number possible from an array

I have the following code in Scala as a solution to the problem: Find the maximum number possible from the given Seq of Integers while keeping the individual numbers intact e.g. Seq(2,5,9,4) ...
1
vote
1answer
113 views

Early-termination foldLeft for Scala Streams

The foldRight and foldLeft methods for Scala Streams cannot terminate early, so here is my ...
3
votes
0answers
108 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
2answers
90 views

Bubble sort in Scala

I wanted to implement a bubble sort in Scala following the steps described in: http://www.bbc.co.uk/education/guides/z22wwmn/revision/3 ...
3
votes
1answer
131 views

Scala Binary Search Tree

In an attempt to get deeper down into Scala, I decided to make a BST using as many interesting concepts as possible in order to explore everything Scala has to offer. Taking inspiration from this ...
2
votes
1answer
101 views

A Scala script for beautify scientific notation strings from Excel

Excel renders scientific notation in the engineering fashion, e.g. “4.2E-5”. That’s OK, but when you are writing a scientific paper, it’s likely that you want it to look like this: “4.2×10⁻⁵”. I have ...
2
votes
0answers
47 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 ...
1
vote
1answer
50 views

Euler #25 Scala

I usually write Euler solutions in Javascript. On problems requiring very large integers I have decided to learn Scala and take advantage of BigInt. I wrote a ...