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

2
votes
0answers
9 views

Immutable queue implementation in Scala

I created a queue in which we can perform Enqueue, Dequeue and Traversing in Scala. ...
1
vote
0answers
14 views

Avoid asInstanceOf in a type class implementation

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
16 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. ...
-1
votes
0answers
10 views

Pattern Matching Function Call in Scala [on hold]

I am a newbie in Scala and functional programming. I want to call a function several times, with combination of parameters based on two variables. Basically, What I am doing right now is this: ...
8
votes
1answer
58 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: ...
2
votes
3answers
39 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
54 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
19 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
20 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
44 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
108 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
31 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
58 views

Caching side effects

Is this a proper way to cache side effects (occurring on job.tryLoad)? ...
4
votes
1answer
153 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
53 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
127 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
55 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
102 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
225 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
16 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
22 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
64 views

Scala list to tuple conversion

...
2
votes
1answer
62 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 ...
7
votes
2answers
115 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
64 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
69 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
91 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
59 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
86 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
60 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
46 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
47 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 ...
4
votes
1answer
69 views

Extending SeqLike - move an element to the front of the sequence

I wrote a method called bringToFront, which moves an element a to the first position of a sequence ...
1
vote
0answers
59 views

Design of Basic Dominion Game Cards [closed]

I thought it would be fun to implement the card game Dominion in Scala. I have implemented the basic card types and wanted to see if there was a better way to implement the card types. So far this is ...
0
votes
0answers
36 views

TrieMap based Simple Graph API

Looking for some feedback regarding elegance, about my code below implementing a simple graph API basing on scala.collection.concurrent.TrieMap. Background: I am ...
2
votes
1answer
101 views

Project Euler 4 The Functional Way

I'm learning Scala (and functional programming). Is there a better way to solve Euler problem 4 than either of these two solutions. Euler 4 I like this array comprehension solution, but it wastes so ...
-1
votes
1answer
48 views

Why does this scala code only execute the last future when necessary? [closed]

From https://www.chrisstucchio.com/blog/2013/actors_vs_futures.html: A very nice feature of Futures is that they are highly composable. Consider the following problem. I want to return an HTTP ...
1
vote
0answers
75 views

Getting branches of a tree

Given a tree structure (in this example it a list of some nested group nodes), what is the best way to get all branches (branch = list of nodes from root to the leaf element)? My solution (here root ...
6
votes
2answers
75 views

Text tokenizer example

Here is a partial example of a text tokenizer. I'm looking for ways to improve one particular line in this code: ...
5
votes
1answer
358 views

Binary tree implementation in Scala

This is my implementation of a binary tree in Scala. How can this be made better? ...
3
votes
1answer
47 views

Override values for overlapping objects between two scala lists

Let's say I have a bunch of Widget, where a Widget is class Widget (sku: Int, label: String, name: String, description: String) And I have 2 sources of Widgets: ...
11
votes
3answers
226 views

Kosaraju in Scala

I started coding in Scala some time ago, and also learning some fundamental algorithms in CS. Here's a terribly slow implementation of Kosaraju algorithm to find strongly connected components in a ...
4
votes
1answer
55 views

A rename utility in Scala

I made a commandline tool for renaming files, similar to the rename command in Ubuntu. Here is the code: ...
3
votes
0answers
209 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 ...
-1
votes
2answers
91 views

Seq[Either[A, B]] => Either[A, Seq[B]] Function

I wrote a function of type Seq[Either[String,Int]] => Either[String, Seq[Int]] ...
3
votes
1answer
122 views

Prime number verifier

I solved this prime number verifier problem: ...
4
votes
2answers
135 views

Scala fraction addition

This just adds fractions. For example, if we have a text file with: 1/3 1/2 It will print: 5/6 I would love to hear some ...
10
votes
1answer
203 views

Scanner in Scala

I wanted to implement Java's Scanner in Scala. The goal for this class is to: Implement a Scala collection interface (probably ...
4
votes
3answers
426 views

Debounce in Scala

This is my attempt at implementing debounce in Scala without any 3rd party library. How can I improve the code/make it more idiomatic (and any bugs I might have missed)? ...
4
votes
1answer
54 views

Vigenère cipher encryption in Scala

I've worked out a functioning Vigenère encryption in Scala, and while it doesn't seem like my code is too hideous, I'm sure I could make it more functional and Scala-esque. Primarily, it seems like: ...