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
15 views

Binary tree implementation in Scala

This is my implementation of a binary tree in Scala. How can this be made better? ...
1
vote
1answer
33 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
150 views
+100

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
37 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: ...
1
vote
0answers
22 views

HashMap of pseudo variables of any type [closed]

I am writing simple variable system in Scala. I need a way to nicely hold these AnyVars and access them by their string names. I have this object called context to ...
3
votes
0answers
28 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
40 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
105 views

Prime number verifier

I solved this prime number verifier problem: ...
4
votes
2answers
67 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 ...
-1
votes
0answers
11 views

Scala ObservableStream

Kind of reinventing the bicycle here as an exercise. ...
2
votes
0answers
23 views

Scanner in Scala

I wanted to implement Java' Scanner in Scala. The goal for this class is to: Implement a Scala collection interface (probably Iterator[String]?) so I can access ...
4
votes
3answers
387 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
36 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: ...
4
votes
1answer
158 views

White box input stream for creating test scenarios

I need to test a specialized input stream class that takes input from a TCP/IP network connection. I particularly need to ensure that the blocking and availability behavior is correct. To help me ...
5
votes
1answer
76 views

Fight simulator

I have been learning Scala for a couple months and want to get a more concrete understanding of proper oop practice. I find it difficult to optimally use traits, abstract classes and inheritance. ...
6
votes
1answer
50 views

Return the element of collection if the collection contains only one element

Recently I have found in my code several places where I was first gathering some solutions, and then continued processing them only if the solution was unique (solution collection contained only one ...
5
votes
0answers
47 views

Mapping a file system to a tree structure

I need to write a very basic file/directory browser. The data structure I'm using is pretty simple - a Node with an optional parent and children. Along with the data structure I also need a simple ...
6
votes
1answer
61 views

Equilibrium Index Implementation

I have come up with a solution to the equilibrium index problem with help from the answers off here: ...
5
votes
1answer
41 views

Simple substitution encryption with Scala

I've just started teaching myself Scala to get my feet wet with functional programming, and I'm messing with around with some classical cryptography. The following code produces monoalphabetic simple ...
4
votes
1answer
65 views

Count unique characters in a String and group the counts

The code counts the amount of unique characters that fit in the character set ACGT (stemming from nucleobases). We take a string as input that must contain only ...
3
votes
3answers
167 views

Find anagrams in a list

Write a program that, given a word and a list of possible anagrams, selects the correct sublist. Given "listen" and a list of candidates like ...
2
votes
1answer
34 views

Clean phone number

Program that cleans up user-entered phone numbers so that they can be sent SMS messages. The rules are as follows: If the phone number is less than 10 digits assume that it is bad number If the ...
4
votes
2answers
52 views

Count chars difference between two strings

Given two strings with the same length, we check how many chars on the same positions are different. For example: ABCD and ABBD should return 1. Here is a link to a gist with tests, to have a better ...
-2
votes
2answers
84 views

How to split long lines of code? [closed]

If I have a one liner method that looks like this: ...
2
votes
2answers
52 views

Count of words in a mutable Map

The function should get some text on input and return a map in a following format: ("word1" -> 1, "word2" -> 2 ...) The keys are words from text and the ...
6
votes
2answers
83 views

Implement the method “plus”

I'm implementing a plus method that should work this way: 1 plus 2 // 3 "a" plus "b" // "a and b = ab" Here is my implementation: ...
4
votes
1answer
70 views

Game boot to some operations every second

I am building game, like Ogame, or Ikariam where you can play with other users in real-time. You train some soldiers, and build some vehicles or buildings. Every building or vehicle has some level. If ...
4
votes
1answer
35 views

Filtering a phone number

I am learning Scala still and refactoring some old code. I was hoping the community here could give me pointers to fix this code up since there are some issues I have with it visually, but don't know ...
7
votes
1answer
108 views

Validation macro

I would like a review of a Scala validation library I am writing. For now we can focus on the regular expression component. The usage is described in RegexExample.scala There is an outline of the ...
5
votes
3answers
218 views

Replacing all occurrences in a String

I have a string like this : val content = "some_text{macro1}another_text{macro2}text" I want to replace the {macro1} and ...
5
votes
1answer
74 views

Safe cracker string with all combinations

Imagine a safe with a 4-digit code, and accepting a continuous stream of code entries, such that when the 4 digits are seen in the right sequence, the safe opens. Generate a short string that ...
4
votes
1answer
70 views

Find minimum number of coins (count and list of coins too)

For a given set of denominations, you are asked to find the minimum number of coins with which a given amount of money can be paid. Assume that you can use as many coins of a particular ...
4
votes
0answers
49 views

Selecting subset of size k using recursion

Sometimes I need to implement recursive algorithms that pass a certain state from one recursive call to another. For example, a greedy subset selection: we have a set of candidate objects, and we ...
7
votes
3answers
499 views

n-digit Verification Code Generator

This is a verification code generator, which generates n-digit numeric strings. (code can be 0000, so I chose String as a return ...
5
votes
2answers
67 views

Simple load balancer model in Scala

For one of my cases in algorithms I am required to create a model of a load balancer model for multiple processors. Lately I became interested in Scala so I decided that it would be great to create ...
2
votes
3answers
49 views

Tail-Recursion to get a Map of word counts

I want to read a file and store the number of occurrences of each word in a Map, using tail recursion. I came up with the following; it seems to work; does it look like it's right? ...
1
vote
1answer
78 views

Graphs processing in Scala

I've just started to learn Scala and decided to implement small graph library to train. Here is the basic version, that describes graph and nodes structure and also provides implementation of ...
2
votes
1answer
126 views

Playframework (Scala) custom exception handling

I am using play framework with scala and here is a scenario on which I would like to have your opinion. Let's say I have 2 ...
2
votes
0answers
27 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, ...
2
votes
1answer
112 views

Memoization of Fibonacci using generic Int => Int helper

I'm trying to understand memoization using Scala. I took the Fibonacci sequence as an example because of the high cost of recursively computing numbers in the sequence without memoization. ...
3
votes
1answer
57 views

Random Plinko path using functional programming style

In order to learn both scala and functional programming, I've been rewriting the projects from my introductory CS class in scala. One of the projects was a plinko game, where the user picks a slot to ...
11
votes
2answers
146 views

Converting imperative style user input menu to functional programming style

I am currently trying to teach myself scala by rewriting projects from my intro CS class, which was taught in C++. In addition to just learning the syntax I am trying to gain understanding of how ...
3
votes
1answer
48 views

Returning preferences

I have a function that returns some preferences, but first I have to do some checks to see whether the user is authorised to read them. I'm still not happy with the result (the match is a bit ugly). ...
1
vote
1answer
62 views

File-to-fully qualified class name function

My instincts are telling me a seasoned Scala programmer will find my code less than optimal. As will no doubt be obvious, I'm a Java guy who has just started in with Scala. Is there a more ...
1
vote
0answers
37 views

NonEmptySortedSet implementation

I'm looking for feedback specifically about what I might add to this to make it more usable or general, especially with regard to scala collection traits to implement. ...
1
vote
1answer
229 views

Extracting tuples from Excel sheet

My code have too much nested option processing which makes it ugly. But it has an advantage it has no side effect and typesafe. ...
10
votes
2answers
96 views

Test runner for Scala problems

I'm learning Scala and could use another set of eyes on the code below. I'm creating a test runner for the 99 scala problems set. I figure between actually solving the problems and working through the ...
1
vote
0answers
59 views

Using Java's Fork/Join library from Scala

I am a newbie trying to learn some Java and I am reading prof. Dan Grossman's introductory lecture notes on parallel and concurrent algorithms. I wrote a version of a divide-and-conquer algorithm for ...
3
votes
2answers
341 views

BFS Maze Solver in Scala

I recently got a Scala developer position, so I'd like to get more comfortable with Scala on my own. Here is a maze solver that I wrote (previously in other languages) that I translated to Scala. Any ...
3
votes
1answer
22 views

Gathering response from a pagable service

I'm wondering how this code could be improved. I especially don't like the use of mutable Buffer but not sure what the best way to get it out cleanly. ...