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

0
votes
0answers
26 views

Find Pythagorean Triple with Perimeter == 24

Learn You a Haskell gives this exercise: Here's a problem that combines tuples and list comprehensions: which right triangle that has integers for all sides and all sides equal to or smaller ...
4
votes
2answers
80 views

Ugly number implementation in scala

I am trying to implement ugly number sequence generation in Scala. Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15... I have ...
1
vote
1answer
43 views

Construct date sequence in Scala

I want to have a continuous date sequence like ['2014-01-01','2014-01-02', ...] Then I define a stream to do that. ...
6
votes
1answer
85 views

Dijkstra-like routing algorithm

I've got the following code to find the shortest path between two nodes using almost-Dijkstra's-algorithm which was written for an exercise, and I'm looking for things to improve my general Scala ...
7
votes
2answers
116 views

How can I make my isSorted function faster?

I made an isSorted function in Scala and Java as well and when I measured the time of functions' run I saw that the Scala version was very slow. It ran about 3.2 ...
1
vote
1answer
36 views

Transform a MongoDb parent reference tree into a deep nested tree

Given a mongodb collection that stores trees as nodes with parent references this methods returns a deep nested tree where every child nodes are stored in a property childs[Seq] ...
1
vote
3answers
68 views

Get lowest integer that is not in set

Is there a better (functional or more idiomatic) way to get the first positive number that is not included in a set? ...
3
votes
2answers
49 views

Range Minimum Query Implementation in Scala

I would like to heat some feedback on this. I'm coming from a Java background and this is my first program in Scala. I solved Range Minimum Query problem. ...
13
votes
4answers
635 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? ...
5
votes
3answers
103 views

Pair matching elements from two lists

Here is a method that takes two lists (l1 and l2) and pairs up elements that "match". As you can see at the end of the code ...
1
vote
1answer
46 views

Implementing Option#map2

Working on an example from Functional Programming in Scala, I'm working on Option#map2: ...
3
votes
1answer
38 views

Writing Traverse Instance for Option

Working on an exercise from Functional Programming in Scala, I implemented a Traverse instance for Option: ...
3
votes
2answers
62 views

Partial octree implementation

I am just now learning Scala a bit on my own time. I wrote some code that works, but was wondering if you could eyeball it to see if its structure can be improved. It is a partial octree ...
3
votes
1answer
158 views

Is this base 62 encoding algorithm okay?

This Scala code snippet is supposed to encode a SHA1 hash in base 62. Can you find any issues? I'm asking since I might not be able to change the algorithm and, for example, fix issues in the future. ...
1
vote
1answer
76 views

How to ensure file exists, and get the absolutePath? [closed]

I need to: create an object with the absolute path of a file ensure the file exists My approach is to create a new Path and call toFile to make sure it exists - ...
2
votes
1answer
62 views

Functional Re-Write in Scala: Rows of Strings with a Max Width

I came across an issue the other day where I really just could not think of a functional solution. So I fell back on my imperative programming skills. Since a functional solution still eludes me, I ...
5
votes
1answer
84 views

Singly Linked List Implementation in Scala

My implementation for single linked list is as follow ...
5
votes
1answer
135 views

Code with many “early returns (exits)” into the functional style

I have some Scala code that uses Internet to authorize a user. Therefore, it can throw Exceptions like IOException in the method. The original code was written in ...
3
votes
1answer
177 views

Case class design in Scala

In the Java world while writing the data access layer (for CRUD) and the model layer, I have done something like this: ...
3
votes
1answer
188 views

Why does the LR on spark run so slowly?

Because the MLlib does not support the sparse input, I ran the following code, which supports the sparse input format, on spark clusters. The settings are: 5 nodes, each node with 8 cores (all the ...
2
votes
2answers
251 views

Given an array, find any three numbers which sum to zero

Given an array, find any three numbers which sum to zero. This problem is a continuation of a code kata in Python . I'm learning Scala and would like feedback on more efficient, cleaner, and ...
2
votes
1answer
64 views

Interface for Spotify API

I'm trying to make a scala interface to the spotify API. I'm using it to learn Scala. I come from mostly a python background. ...
6
votes
1answer
76 views

Idiomatic Scala try option code block

Trying to learn scala. Wanted to know if this is the standard way of doing things in Scala - or is there a better way to write this code ? Basically, this function returns a list of flights for an ...
1
vote
1answer
49 views

Scala for processing files in a directory tree

I'm new to Scala, and would appreciate any notes about a better approach, correctness, or style. ...
4
votes
1answer
41 views

What is a better approach for operating on an arbitrary map value in Scala?

Coming from an imperative background, I have written the following code in Scala. I need to attempt to find a value in a map. If the value exists, I need to pass the value to another function and ...
2
votes
1answer
94 views

Is this a reasonable Scala monad?

I found myself writing code of the form... ...
2
votes
1answer
77 views

Is there any way to simplify this code

I'd like to simplify this Scala code: ...
1
vote
1answer
134 views

Better way of calculating Project Euler #2 (Fibonacci sequence)

Even Fibonacci numbers Problem 2 Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, ...
3
votes
1answer
76 views

is this future map scala syntax good?

I'm new to scala and have been working to understand the syntax so that I can be more efficient. How does this look in terms of functional syntax and scala idioms? In particular, I'd like to know if ...
1
vote
0answers
120 views

Scalaz state monad exercise

I can't tag this with scalaz and state-monad yet since I don't have sufficient reputation to add tags. Below is a self imposed exercise and solution to learn Scalaz state monad. How can I ...
1
vote
2answers
107 views

More functional approach

I wonder if there is a more "functional" way of implementing something like this: ...
4
votes
2answers
197 views

Whether or not to name Boolean parameters in Scala [closed]

def execute(parameterName : scala.Boolean = { /* compiled code */ }) When calling this method, you can go with ...
1
vote
1answer
78 views

Counting inversions

I'm trying to implement an inversion counting routine in Scala in a functional way (I don't want to port Java solution) but have real troubles with it. The sorting routine works fine but adding the ...
2
votes
1answer
222 views

How to write better an sqrt (square root) function in Scala

As an exercise in learning Scala, I implemented a square root function like this: ...
5
votes
1answer
105 views

Maximum path problem using Scala

I am very new to Scala. I have done an exercise using Scala to solve the maximum path problem. Basically, I have a triangle of integers, I want to find the path from the top to bottom which the ...
3
votes
2answers
255 views

How to rewrite this code in functional way?

My code looks like imperative style code. I want to make my code more functional. How I can rewrite my program so it become functional style code? ...
4
votes
1answer
383 views

BFS and DFS in Scala

I would love it if someone could give me some suggestions for these 2 graph search functions. I am new to scala and would love to get some insight into making these more idiomatic. ...
3
votes
2answers
150 views

Improve scala functional string transformation

How could this scala code be made more concise and/or idiomatic? Do I need to define each functions as a val in order to pass them as values, or is there a ...
1
vote
1answer
422 views

rxjava observables and scala futures

In a simple webapp I have been using as a playground, I am playing with using rxjava to perform a number of operations in a reactive manner. I have been using reactivemongo to connect to my Mongo ...
0
votes
0answers
101 views

Scala: Pointillism

I'm relatively new to Scala and tried to copy one of the language examples of Processing: Pointillism. The original image can be retrieved here. I've used the Standard Widget Toolkit for drawing. ...
4
votes
2answers
136 views

Refactor to reduce code duplication

I have four methods like these (here are only two of them): ...
3
votes
1answer
850 views

Scala Binary Search Tree Implementation?

I have written a sample immutable binary search tree using Scala. However, I am not sure whether or not I was doing it the proper way since I am not an expert at functional programming. Is there a ...
3
votes
1answer
645 views

Recursive branch and bound for knapsack problem

I've got the imperative styled solution working perfectly. What I'm wondering is how to make a recursive branch and bound. This is my code below, Evaluate function returns the optimistic estimate, ...
3
votes
2answers
153 views
1
vote
1answer
62 views

Is this class name for my commenting system confusing?

In my project (which is a discussion system) there are approved and unapproved comments. There's a class that tells if unapproved comments should be shown. But I cannot think of a good name for this ...
2
votes
1answer
87 views

Printing out a tree set using pattern matching in Scala

I'm working on some exercises Scala by Example and I've implemented an excl() method on sets which removes an element from a set, and a toString method that converts a set to a string. I'm practicing ...
1
vote
1answer
65 views
0
votes
1answer
84 views

Scala: Are assertions acceptable outside of test context?

In the case that Type is not an option, data must exist so I just use an assert to clarify and throw an exception if data is missing. Is there a better way to do this? I think in Java this would be ...
1
vote
1answer
171 views

Subclass of AtomicReference with atomic function application

Update: Now that https://github.com/bionicspirit/scala-atomic is available, I have less of a need for this. Am I doing anything bad? I wrote this class to allow modifying an atomic reference with the ...
5
votes
1answer
357 views

First Scala Program - CSV Parsing - is it idiomatic?

This is my first real attempt at a scala program. I come from a predominantly java background, so I'd like to know if the program sticks to scala conventions well. Is it well readable or should it ...