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
6 votes
2 answers
519 views

Improving my Tic Tac Toe Solution in Scala

I'm relatively new to Scala and made a small TicTacToe in a functional Style. Any improvement options would be highly appreciated. There are some things which I am unsure of if they are made in an ...
elauser's user avatar
  • 179
29 votes
7 answers
8k 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? ...
jcm's user avatar
  • 1,331
12 votes
3 answers
458 views

Kosaraju in Scala

I started coding in Scala some time ago, and also learning some fundamental algorithms in CS. Here's a terribly slow implementation of Kosaraju algorithm to find strongly connected components in a ...
Bacon's user avatar
  • 161
10 votes
1 answer
993 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 ...
toto2's user avatar
  • 5,390
8 votes
4 answers
8k 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 ...
chaotic3quilibrium's user avatar
7 votes
3 answers
186 views

Distinct sums of integers

I need to get the distinct sums of naturals of a natural What I came up with is: ...
Martijn's user avatar
  • 585
6 votes
4 answers
379 views

Multiple SQL queries, one per ID

ids contains 100 ids that are comma delimited. Is it fine or does it need improvement? ...
Govind Singh Nagarkoti's user avatar
5 votes
2 answers
3k 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? ...
smk's user avatar
  • 371
5 votes
2 answers
320 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 ...
Zoltan Hamori's user avatar
4 votes
1 answer
6k views

Immutable binary search tree using Scala

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 ...
user avatar
3 votes
1 answer
215 views

Improvements, TicTacToe in Scala

I've just started my journey into functional programming and tried to implement a TicTacToe game Recursively without State in Scala. What I dislike is the JOptionPane but I don't know if i can solve ...
elauser's user avatar
  • 179
3 votes
1 answer
471 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: ...
simao's user avatar
  • 155
2 votes
4 answers
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. ...
simao's user avatar
  • 155
2 votes
2 answers
700 views

Convert a String with comma separated latitudes and longitudes to a Seq[Coordinate]

I have a function that receives a String like the following: "-10.0 -10.0,10.0 10.0,0.0 0.0" And needs to translate that into ...
Rodrigo Sasaki's user avatar
1 vote
2 answers
499 views

Print matrix in spiral order in Scala

Problem: Given a square or rectangular matrix, print its element in spiral order. For example, if input matrix is this: ...
vikrant's user avatar
  • 385
0 votes
1 answer
769 views

Clockwise rotate a matrix in Scala

Given a matrix, clockwise rotate elements in it. Examples: ...
vikrant's user avatar
  • 385