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
19
votes
4answers
409 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
90 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 it....
1
vote
0answers
73 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
5k views

Scala list to tuple conversion

...
2
votes
1answer
217 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
360 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
77 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) ...
2
votes
1answer
1k 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
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
2answers
1k 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
2k 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
843 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
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 ...
1
vote
1answer
66 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
167 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
328 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
126 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
141 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
278 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
99 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: ...
8
votes
2answers
9k 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
69 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: ...
12
votes
3answers
380 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
494 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
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 ...
0
votes
2answers
2k 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
274 views

Prime number verifier

I solved this prime number verifier problem: ...
6
votes
2answers
2k 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 ...
11
votes
1answer
1k 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
2answers
667 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
222 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
264 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
217 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
147 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 ...
6
votes
1answer
965 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
77 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
455 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
929 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
2k 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
119 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 phone ...
4
votes
2answers
2k 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 ...
-1
votes
2answers
6k views

How to split long lines of code? [closed]

If I have a one liner method that looks like this: ...
2
votes
2answers
1k 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
3answers
330 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
87 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
88 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
188 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 ...
6
votes
4answers
8k 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
390 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 contains ...
4
votes
1answer
262 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 denomination ...