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.
2
votes
0answers
38 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 ...
1
vote
0answers
23 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
2answers
35 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
29 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
82 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
37 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
51 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
50 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?
...
2
votes
1answer
55 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
79 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 ...
2
votes
1answer
142 views
5
votes
3answers
154 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 ...
3
votes
1answer
91 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
58 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
96 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
70 views
4
votes
3answers
67 views
1
vote
2answers
79 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:
...
7
votes
0answers
80 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
57 views
Functionally Typed I/O Streams
I thought up a function that provides types with InputStream and OutputStream:
...
2
votes
1answer
42 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
148 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
99 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
101 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
99 views
Netty-based safely network reconnection
I am writing a TCP client app using netty
NettyConnectionManager.scala:
...
1
vote
0answers
32 views
Elementary foldMap implementation
I think I got the implementation right, but I'm a bit unsure if this implementation will do fine in terms of space (stack) because I'm doing a foldRight. Would I ...
3
votes
1answer
141 views
Binary search in functional-style Scala
Curious to know how I can improve it, especially the pattern matching part seems a bit repetitive at the moment (lots of case x if ds(x))
...
3
votes
1answer
101 views
Uploading a video in S3 Using Future
I've posted a similar program previously, but I have not made any major modifications in the code, so I am posting it again by deleting the previous question.
I am afraid of the thread keyword and I ...
2
votes
2answers
52 views
Branching with multiple Try
I have a series of four method calls that all return Try[Something], with the last returning Try[Unit]. Something like this:
...
3
votes
2answers
99 views
5
votes
2answers
94 views
Connecting to RabbitMQ
I would like a review for this connection to RabbitMQ. I just developed it and seems to be working well, but I would like another set of eyes on it before putting this on the sever.
...
0
votes
1answer
76 views
Updating MySQL with shuffled numbers between 1 and 50
I need to assign a number to each userId. I think this is too much of a query for updating. Is it possible to reduce the number of queries, or is it okay?
...
4
votes
3answers
189 views
Random 6 to 10 digits number
I am generating a random numerical 6-10 digit password. I need some important reviews of yours. Is it OK or are there some needed modifications?
...
6
votes
4answers
273 views
Multiple SQL queries, one per ID
ids contains 100 ids that are comma delimited. Is it fine or does it need improvement?
...
4
votes
0answers
125 views
Scala heap implementation
I'm a Scala beginner, so it'd be great if anyone would be so kind to give some feedback.
...
3
votes
1answer
104 views
Scala Tic Tac Toe Game
This is my first Scala game. I would love some feedback on my coding style, or your brief input on how you would do it.
...
5
votes
2answers
459 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).
...
4
votes
1answer
82 views
Finding the longest word from a list of words
I have a list of words (with repetitions), and I intend to find out the longest words amongst them, along with their length. My question is to know if my implementation is too verbose, is using too ...
5
votes
2answers
84 views
Beginner Project: Bunny City
I am a Java programmer, and I just recently started learning Scala for fun. I found a group of projects here, and I tried to do the graduation excercise. The problem is, my code looks a lot like java, ...
4
votes
0answers
105 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 ...
1
vote
0answers
45 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:
...
3
votes
2answers
229 views
Apache log4j in play framework
I have converted this code from Java to Scala, and I need reviews. This works fine, but I am sure that something is wrong with this coding pattern.
...
3
votes
0answers
66 views
Custom Scala implementation of generic Future.sequence
I'm trying to make sure I understand how to write clean and robust idiomatic Scala, so I wrote a custom generic implementation sequence of type ...
1
vote
1answer
98 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 ...
2
votes
1answer
74 views
Testing Promises vs Lock performance
I'm not sure if my lock usage is correct and safe. I wanted to know what will be best approach to deal with situation when one thread have to wait for being initialized by another so I written this ...
1
vote
1answer
113 views
4
votes
1answer
76 views
Neatly Transforming Anorm ResultSet Into Map[Parent , (Set[Child1], Set[Child2]))]
I have a table Bill containing Bills with 0...n relationships to Material and ...
3
votes
2answers
484 views
Pascal triangle algorithm is good but fails
I have created a function which returns the number that corresponds to the given row and column from the pascal triangle. I have used the formula for this:
n! / r! * (r-n)!
The code:
...
4
votes
1answer
89 views
Key / Value store with type classes for formatting / parsing
I'm currently working on a Scala HTTP library, fetch, mostly because I have yet to find one that suits all my needs.
As part of this library, I need a generic key / value store, which I intend to use ...
1
vote
1answer
42 views
Pattern-matching function
I am new to Scala and I have written a function which uses pattern matching to filter words based on some conditions. It seems to work correctly but I am suspect that I haven't used the Scala pattern ...