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.
1
vote
0answers
23 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).
...
2
votes
2answers
64 views
Tail Recursive Fibonacci
Please critique my implementation of a tail-recursive method for generating the Fibonacci sequence:
...
1
vote
1answer
41 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 ...
2
votes
2answers
194 views
What is the best way to conditionally add to an immutable collection in Scala? [closed]
I find myself frequently trying to build up Seq's based on some conditionals, but the code I end up with feels verbose and clunky. An example:
...
10
votes
2answers
68 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
1answer
56 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.
...
0
votes
0answers
41 views
Scala TryWith that closes resources automatically
I'm quite new to Scala and was surprised that there doesn't seem to be anything like Java's try-with-resources block. So of course I wrote my own little construct. Is there anything I could improve?
...
3
votes
2answers
136 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 ...
1
vote
0answers
28 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
0answers
25 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 ...
2
votes
1answer
129 views
Converting object oriented style code to functional in Scala
I came across Java like Scala code that I am trying to refactor to make it functional and immutable. The first obvious flaw is that it's violating thread safety by using mutable public class level ...
3
votes
1answer
18 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.
...
4
votes
0answers
135 views
Binary Search Tree Monad Implementation
I've written a Binary Search Tree Monad in Scala. I would like to hear your thoughts on how to improve it (e.g. making insertion/deletion/search faster and more scalable). Also, is there a better way ...
3
votes
1answer
87 views
Ported C# scheduling to Scala
I'm taking a design workshop and we've received a short task:
To parse an input file of processor jobs.
To simulate scheduling of those jobs on a parallel computer (each job needs X processors)
The ...
7
votes
1answer
72 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 ...
16
votes
2answers
235 views
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, ...
10
votes
2answers
171 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
90 views
Async Controller Play 2.3
Is this example the correct way of writing an Async controller end point in Scala using Play 2.3?
...
1
vote
0answers
24 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 ...
1
vote
0answers
44 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
18 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.
...
2
votes
3answers
68 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 ...
4
votes
2answers
79 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
67 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 ...
4
votes
2answers
142 views
Attempting to eliminate var (and imperative style) from my Piece class
I've been cooking with gas since I got Daniel C Sobral's help on my last question. I am now re-reading Odersky's "Programming in Scala, 2nd Edition" (finished my first reading about this time last ...
3
votes
1answer
60 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
196 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 ...
4
votes
2answers
2k views
Option type in C# and implicit conversions
I have decided to create a simple Option type for C#. I have essentially based it on the
Scala's Option.
It was mostly a fun ...
14
votes
1answer
102 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 ...
2
votes
0answers
59 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 ...
1
vote
0answers
61 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 ...
5
votes
3answers
72 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.
...
2
votes
3answers
109 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
83 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:
...
1
vote
3answers
243 views
Realizing a SQL ResultSet into a Map in Scala
I am trying to realize a java.sql.ResultSet into a map, in Scala.
...
11
votes
1answer
108 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.
...
2
votes
3answers
71 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:
...
12
votes
1answer
2k views
Simple anagram finder using Scala and some Scalaz
I'd like to hear some thoughts on my simple anagram finder, written in Scala. I mainly wrote this as a first go at writing some serious Scala, and I wanted to try out the Scalaz library.
I'm coming ...
3
votes
2answers
92 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 (...
4
votes
0answers
88 views
VerbalExpressions in Scala
I forked the original implementation of VerbalExpressions in Scala here: https://github.com/pathikrit/ScalaVerbalExpressions
I am looking forward to these things in the code review:
...
2
votes
1answer
38 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.
...
2
votes
1answer
64 views
Dealing with state
I am working on something that involves the observer pattern. A simple version of that looks like this:
...
2
votes
1answer
323 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 ...
5
votes
2answers
153 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 ...
3
votes
2answers
174 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 ...
5
votes
2answers
759 views
Parsing JSON to a Map and Set structure
How do I make these line of codes more scala-ish (shorter?). I still get the Java feeling in it (which I want to stay away from).
...
15
votes
5answers
1k views
First Scala FizzBuzz implementation
Would love some feedback on this. I'm coming from a Java background and kinda feel like I've just done exactly what I would do in Java. Is there a better way?
...
3
votes
2answers
227 views
3
votes
0answers
706 views
Configuring a JMS Component in akka-camel
I'm trying to write a JMS Consumer using Akka-Camel.
For now, I'm using FFMQ as a JMS server. I want to listen on the JMS queue myqueue.
Creating the JMS ...
3
votes
2answers
115 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 ...