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

1
vote
0answers
11 views

A Timer Construct to Simplify Timing Blocks of Code

This is fairly simple, so I'm just looking for ideas on anything that can be cleaned up, places it can be extended, and suggestions regarding style/naming (I'm terrible at naming). It allows you to ...
13
votes
0answers
93 views
+100

API for looking up Japanese postal code

Most of my experience is in Python, Java and embedded C, and I need to learn Scala and Play for a new job. As an exercise, I decided to create a very simple API for looking up area by postal code, ...
1
vote
0answers
22 views

A Simple Thread Pool in Scala

I wrote the following that spawns n threads, uses them to process a queue of jobs, then returns a result. As well as any general suggestions, I'd like feedback on the following: How safe is ...
0
votes
0answers
13 views

Gathering emails, phones, URIs, and tag related to a room

I've made a strange method with multiples conditionals, creating a lot of Lists and I was wondering if I could write it in a better and more legible way. ...
4
votes
2answers
65 views

“Functionalizing” this tree walking method and cleaning it up

I have a MessageTree class that represents a binary tree of negative/positive. I'm looking to improve my walkTree method and ...
2
votes
2answers
63 views

List.containsSlice

In an effort to strengthen my functional programming, I'm reading Functional Programming in Scala. One of the assignments is to implement a function that does the same operation as ...
2
votes
3answers
58 views

Refactor jaccard similarity the “Scala way”

I'm trying to pick Scala up. This is a simple heuristic that checks a similarity value between two sets. I've done this a million times in Java or Python. The function works, but I'm certain I am not ...
3
votes
1answer
56 views

A simple “Tamagotchi” like game that uses math questions as food

I wrote a Tamagotchi-like game where to feed the pet, you do math questions instead of just pressing a button. It's persistent, in that on loading, it figures out long it's been since the last save, ...
6
votes
3answers
163 views

Checking for balanced parentheses

I wrote a method to check if each parenthesis in a string is closed. It should take into account the order in which a parenthesis is presented, e.g. "hello)goodbye(" should return false even though ...
2
votes
0answers
42 views

Scala BitSet implemented with Java BitSet, for use in Scala Enumerations to replace ValueSet

Due to a performance profiling hot spot detailed in http://stackoverflow.com/questions/27632554/scala-enumeration-valueset-slow-replacement-based-on-java-bitset , I implemented my own BitSet using ...
13
votes
1answer
92 views

Oh ye beloved bejeweled

Before @bazola asked his recent question we chatted about it for a bit. I figured that I could try implementing something similar myself. As I've heard that Scala has all the advantages of Java but ...
1
vote
0answers
51 views

Scala Case Classes

Please take a look at the following Scala program and give me suggestions for improvement. I'm sure there would be plenty. This is my very first Scala code, so please don't be frustrated because of ...
2
votes
3answers
79 views

A Cipher with 2 methods for encryption/decryption

I'd like advice on how this could be written more efficiently, idiomatically, or just anything that could be improved upon. I'd also like to know if there's an alternative to my ...
1
vote
0answers
62 views

Idiomatic Scala for nested map/flatmap

Does anybody have an idea on how to make this code more idiomatic? I tried to use scalaz Traverse, but it didn't really help. Given the types and method signatures: ...
11
votes
1answer
93 views

First four Project Euler in Scala

I was working on teaching myself some Scala and decided to tackle some Project Euler problems. The first four of these turned out to be one liners. ...
5
votes
3answers
66 views

Generating a game board with squares in a rectangle

I am trying to generate a game board (similar to a Monopoly board). I am new to Scala and am thinking that there may be a better way to do this. But improvements to the code are also welcome. ...
3
votes
2answers
73 views

zipWith function in Scala

My implementation works, but it looks very ugly. Curious to see how it's better implemented. The zipWith function takes a list of lists (...
2
votes
3answers
69 views

Removing nested blocks from a string

I wrote this function in scala that uses tail recursion to remove nested blocks from a text. Usage examples: ...
2
votes
1answer
62 views

Dealing with state

I am working on something that involves the observer pattern. A simple version of that looks like this: ...
10
votes
2answers
137 views

“Pure” functional simple Scala battle game simulation

I am a long time imperative programmer (mostly C++) taking my first forays into functional programming with Scala. I am following some online tutorials about functional programming and Scala and I'm ...
2
votes
1answer
77 views

Ported C# scheduling to Scala - does not feel idiomatic

I'm taking a design workshop, we've received a short task which is: To parse an input file of processor jobs. To simulate scheduling of those jobs on a parallel computer (each job needs X ...
2
votes
1answer
34 views

Access case class parameter inside a map with default [closed]

I have a map whose values are case classes, and I want to access one parameter of that case class with a default value if they map doesn't contain the provided key. ...
5
votes
2answers
111 views

Simple search engine using TF-IDF (200 LOC)

I wrote simple search engine based on TF-IDF statistic and cosine similarity. I am still learning Scala, so would be glad to hear comments (here or at GitHub) regarding my code from Scala ...
2
votes
2answers
222 views

Comparing equivalent Scala and C# string-manipulation code - with Scala running much slower

I am very early in my journey of learning Scala, and I was doing challenges on hackerrank.com to get used to the syntax. As I finished one (very trivial) challenge, I noticed that the run times seem ...
10
votes
2answers
110 views

Value Mapper service

I have some data I'm getting from an external source that I don't control and have been told that I have to map some of it to "user friendly" display values. So I wrote a little utility service to do ...
3
votes
2answers
166 views

Removing asInstance[T] from scala code

I've written this scala code and I cannot work out how/if it is possible to remove the asInstance in the definition of class ...
2
votes
1answer
229 views

Distributing workload using Akka Router with exception handling

I am fairly new to Akka and I am interested in any feedback about the following code. Is this the correct way to go about distributing workload across a number of threads? Do I use the Akka API ...
1
vote
3answers
157 views

Realizing a SQL ResultSet into a Map in Scala

I am trying to realize a java.sql.ResultSet into a map, in Scala. ...
2
votes
0answers
42 views

MySQL natural search and like search

I have written two queries for searching, but I want to simplify them as it seems needed. ...
5
votes
2answers
125 views

Project Euler #17

Project Euler presents problem 17: If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total. If all the ...
5
votes
1answer
67 views

Dictionary synonym lookup via networking

I have a small TCP service running on port 4444 which, given a word, will look up synonyms in a dictionary. Below is my Scala code for connecting to the socket, sending the lookup command and parsing ...
6
votes
1answer
121 views

BFS and DFS tree traversal

I posted some code as part of an answer to another question and I thought it would be a good idea to get that code reviewed also. Any comments are welcomed, but I am mostly annoyed by ...
3
votes
2answers
125 views

BFS tree traversal Scala

I would love some feedback on the following code for BFS traversal in a binary tree. Is there a cleaner way to write this? ...
3
votes
2answers
104 views

Cleaning up file resources in a DRY manner

I've written a function that generates a report, and then sends it as an attachment to an email. I don't want to clutter the function with a lot of calls to close up the filesystem, if there was an ...
3
votes
2answers
115 views

Hamiltonian Monte Carlo in Scala

I'm writing a program in Scala to perform Hamiltonian Monte Carlo (HMC), coupled with Gibbs sampling of some variables. The algorithm, with the modifications such as perturbing epsilon and l and ...
3
votes
2answers
220 views
7
votes
3answers
286 views

Reducing boilerplate when validating parameters and using a tuple for the parameter list of a case class

I had designed a simple case class that looks like this: case class StreetSecondary(designator: String, value: Option[String]) I needed to add validation (to ...
4
votes
1answer
173 views

Writing a new Finagle protocol

The following is a fairly naive implementation of a Finagle protocol that uses the scodec library for binary encoding and decoding. I'll assume something like the following SBT setup: ...
1
vote
1answer
64 views

Combinations with replacement

I am still new to Scala and wrote a small snippet to find all the combinations with replacement of a sequence (e.g. cwr(ab, 3) should give aaa, aab, abb, bbb). The slow way would be to generate all ...
8
votes
1answer
112 views

Dungeon generation in Scala

I've recently begun learning Scala, and while I've run into its concepts before (immutability, tuples, first-class functions) I'm not sure whether I'm using the language how it's supposed to be used. ...
5
votes
1answer
78 views

Too many nested Types?

I have the following Scala code: ...
4
votes
3answers
74 views

Idiomatic Scala Generics

I'm working on some Scala problems given here, specifically: ...
1
vote
2answers
147 views

Finding Duplicate (Key, Value) in Map

I wrote a function for checking if a Map[(String, String)] contains an element with a matching key and value: ...
8
votes
0answers
121 views

Implementing a generic and covariant Set in Scala

I'm struggling with manually implementing a simple purely functional Set that's also generic and covariant on its type parameter: ...
4
votes
0answers
67 views

Functionally Typed I/O Streams

I thought up a function that provides types with InputStream and OutputStream: ...
2
votes
1answer
67 views

Aggregating values of a path-dependent type

I have a type representing an immutable order which contains immutable order lines that belong to it. I want to use path-dependent types for this. Obviously you cannot instantiate a path-dependent ...
10
votes
2answers
220 views

Sending SMS through twilio from play framework

I am trying to send SMS using Twilio with Scala 2.10 in Playframework 2.2, but this code is looking odd to me, maybe due to lots of conditions. I'm sure it needs some important reviews. ...
3
votes
2answers
104 views

Timing Project Euler Problem 1

Is there a better way to time the functions and print the result and function name dynamically? ...
1
vote
4answers
114 views

Transforming a list of maps representing bands

I have the following code, it takes a list of maps representing bands and transforms the band properties via the pipeline_each method. As you can see in the code, ...
2
votes
0answers
202 views

Netty-based safely network reconnection

I am writing a TCP client app using netty NettyConnectionManager.scala: ...