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
11
votes
2answers
2k views

Disjoint sets implementation

I would like to get some feedback on the following implementation of disjoint sets, based on disjoint-sets forests (Cormen, et.al., Introduction to Algorithms, 2nd ed., p.505ff). It should have the ...
6
votes
2answers
286 views

Solving Project Euler problem #48 in Scala

I'm trying to learn some Scala and decided to try to tackle some Project Euler problems. For problem #48, coming from a Python background, my solution is the following one-liner: ...
16
votes
1answer
580 views

TDD and function injection

I'm trying to come up with a scalable way of TDD'ing my Scala code, in particular managing dependencies. In this example, I've TDD'd part of the classic river crossing problem where we have people on ...
12
votes
1answer
4k views

Simple wrapper around Java's File & FileInputStream

In an attempt to begin learning Scala, I've taken a stab at creating a simple wrapper around Java's File & FileInputStream in order to read lines from a file. This functionality already exists in ...
16
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 ...
7
votes
1answer
7k views

Handling parsing failure in Scala without exceptions

I have a Scala (Play!) application that must get and parse some data in JSON from an external service. I want to be able to gently handle failure in the response format, but it is becoming messy. What ...
6
votes
3answers
3k views

A safer way to cut a string

I want to get just the first line of a big string. Currently, here's how I do it: ...
5
votes
1answer
940 views

Matching BigInts in Scala

I'm currently in the process of learning scala, and I'm looking for some best practices/proper idioms for the use of pattern matching with BigInts. I'm writing ...
2
votes
1answer
229 views

First steps in Scala: does this look idiomatic?

I an a newcomer in the Scala world, and I would like some advice from more experienced people to find out whether what I am writing goes in the direction of idiomatic code. In particular, I have to ...
4
votes
1answer
380 views

Producing a matrix class that supports any size

I'm doing exercise 11.8 from Scala for impatient, asking to write a matrix class: Provide a class Matrix - you can choose whether you want to implement 2 x 2 ...
5
votes
2answers
299 views

Change code to use functional style

I tried to solve a programming contest problem in Scala, but I have a feeling, that it could be done in a more functional way. I compared it with the solution written in imperative style and it is not ...
11
votes
4answers
919 views

Alternate form of BufferedInputStream

I was having a problem with the TCP/IP socket communications in a web app where the server that the app was talking to would occasionally send bursts of data that would overflow the low level stream ...
5
votes
1answer
787 views

Connect Four In Idiomatic Scala

Learning Scala I'm trying to learn Scala and I'm interested in criticism about how to make my code more idiomatic. I've programmed a simple Connect-four game. Can I get some feedback? https://github....
3
votes
1answer
1k views

Defining transpose on a collection of irregular collections

I was asked to submit my request for code review on https://stackoverflow.com/questions/10672046/defining-transpose-on-a-collection-of-irregular-collections here. This is a follow-up to the post I ...
2
votes
2answers
239 views

Scala: Josephus problem with Actors

Another stab at the Josephus problem, this time using Actors. N people stand in a circle and every stepth person is eliminated ...
1
vote
1answer
45 views

Which name should I choose for private abstract functionality with a public proxy?

I have an abstract class implementing some concrete functionality for its child classes: ...
3
votes
2answers
163 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 ...
2
votes
1answer
134 views

Ideal FP/Scala way to vaildate rectangular list

I am learning Scala and FP (Functional Programming), coming from Java, OO and a strong imperative pardigm. I am now trying to implement a small puzzle solving project so I can get some deeper hands on ...
5
votes
2answers
2k views

Pouring water problem

I just began to study Scala (coming from Python I had quite a few problems with types) and I want to know if my first code to solve a real problem is nicely done or if there is some points that need ...
10
votes
1answer
312 views

OSGi-like infrastructure

I am a moderately new Scala developer working mostly by myself, so I don't have anyone to tell me what I'm doing wrong (except that the system mostly does work, so it can't be too awful). I would ...
5
votes
3answers
385 views

Finding the first stream of non-repeating elements in Scala (without recursion or side-effects)

Here are some examples: [1, 2, 3, 4, 5] => [1, 2, 3, 4, 5] [10, 15, 10, 15, 30] => [10, 15] [1, 2, 3, 4, 1, 5, 6, 7] => [1, 2, 3, 4] Here's my best (and ...
2
votes
1answer
285 views

Scala object-function balance

I am learning Scala, coming from Java background. Here I have written a small prototype proof of concept program that is a part of concept base for a simple upcoming tutorial game. There are two game ...
4
votes
1answer
714 views

Functionally retrieving rows from a database in Scala

Consider the following piece of code: ...
2
votes
1answer
283 views

Scala Direction enum with Enumeration and collection usage

I've just implement direction enum ...
1
vote
1answer
419 views

Simple factory pattern in scala (attempting to restrict use of new)

I am a Scala newbie and attempting to improve my skills. I have decided to be playful about it and work to do a conversion of the spaceinvaders game supplied with the LWJGL. It consists of 10 Java ...
3
votes
2answers
2k views

Checking if two byte arrays are the same

I have a method to compare two byte arrays. The code is Java-style, and there are many if-elses. ...
8
votes
1answer
265 views

Basic XML template

I am currently exploring the play framework. I'm about to replace the proposed templating system, using the powerful XML processing of the Scala library. Here is what I have come with: ...
2
votes
3answers
429 views

Correct use of Option in scala?

I'm somewhat new to Scala and am not sure if I'm doing things in a very Scala-esque way. In particular, I'm not sure if I'm using Option correctly, since by ...
7
votes
5answers
7k views

More functional way of writing this palindrome extractor?

I wrote this palindrome extractor. And even though it works, and I can solve the challenge with it, it feels very Java-like. I was wondering what adjustments I could make in order for it to be more ...
2
votes
1answer
406 views

Formatting as a table in Scala

I'm trying to get my head in the Scala game, and would welcome feedback on the following code, which produces a table from data. ...
6
votes
1answer
691 views

Conway life game implementation with scala

I've tried to create optimal in terms of performance and memmory consumption. But also I've tried to make it functional and scala way. I want to get you comment on how to make it more 'scala'stic <...
0
votes
1answer
670 views

Composite Design Pattern in Scala

The following is a personal attempt at implementing the Composite design pattern in Scala. Observation is abstract... ...
6
votes
3answers
3k views

FSA (finite state automaton) in Scala

I'm a beginning Scala programmer with a strong background in functional programming (ML, Haskell, Scheme) and I've just written my first Scala program. It is an implementation of a FSA (finite state ...
5
votes
1answer
564 views

Processing XML configuration which stores regular expressions and format strings for a documentation tool

I'm investigating some feature for the ScalaDoc tool, which would allow library writers to link to documentation created by third party tools like JavaDoc. My idea is to have some (XML) configuration ...
2
votes
4answers
5k views

Calculating a base price with surcharge conditions

The following code has a lot of conditionals. I am trying to write it in a functional programming way. ...
3
votes
1answer
429 views

Initialize a Sieve of Eratosthenes in Scala

I am learning Scala while solving some exercises and I am currently solving an exercise where I need to initialize a Sieve of Eratosthenes. I am using the following code: ...
5
votes
2answers
228 views

Checking a collection of Ints

I'm learning a little Scala by writing a little card game. What I want to do here is check that the Traversable[Team] supplied has the same number of team members ...
5
votes
2answers
862 views

Producing full list of Fibonacci numbers which fit in an Int

I am progressing through the problems listed at projecteuler.com as I learn Scala (my blog where I am covering this experience). I have written a function to produce all the Fibonacci numbers possible ...
2
votes
2answers
224 views

Scala list folding

I'm trying to learn scala. It's hard. I currently have a tree in the form class Node(children:List[Node], value:Int){ } I want to calculate a total cost ...
5
votes
3answers
429 views

Decided to learn Scala. Here's an attempt at a Cloth simulation

I have never done anything functional before. These two functions are hideous to look at. II think the first step to do is extract the inner bits out and then map over my arrays. What else can I do to ...
2
votes
2answers
575 views

Scala mastermind solver, which is the most scala-ish

I am trying to express the classical TDD kata of mastermind in the most idiomatic scala I can. Here is a scalatest, test suite : ...
3
votes
3answers
510 views

Alien Numbers - how Scala-ish is my solution?

I'm trying to solve an old GCJ. It's a very simple puzzle, but I'm trying to sharpen my Scala-fu. Basically, you're getting a list of triple ...

1
6 7 8 9
10