3
votes
2answers
81 views

Timing Project Euler Problem 1

Is there a better way to time the functions and print the result and function name dynamically? ...
3
votes
1answer
93 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
56 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
79 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, ...
1
vote
1answer
79 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 ...
4
votes
0answers
43 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 ...
2
votes
1answer
84 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
334 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 ...
1
vote
2answers
112 views

More functional approach

I wonder if there is a more "functional" way of implementing something like this: ...
3
votes
2answers
266 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? ...
3
votes
2answers
161 views
1
vote
1answer
84 views

Simple Comonads in Scala?

...
2
votes
3answers
114 views

is there a better and more functional way to write this

I'm learning Scala and functional programming. Can I make it more functional? Thanks ...
3
votes
1answer
89 views

Replacing a sequence of real numbers with another sequence

I have a simple task: Given a sequence of real numbers, replace all of its members larger than Z by Z and count the number of replacements. I solved this task using Scala, but my code looks ...
2
votes
2answers
689 views

Option type in C# and implicit conversions

Good morning everyone, I have decided to create a simple Option type for C#. I have essentially based it on the Scala's Option. ...
5
votes
2answers
370 views

Typesafe Tic-Tac-Toe API

So I've been working on Tony Morris' Tic-Tac-Toe challenge. The rules are as follows: Write an API for playing tic-tac-toe. There should be no side-effects (or variables), at all, for real. The ...
2
votes
3answers
182 views

Cleaner way for coding a repetitive application of a function

I have this function definition which takes an r and applies the function f n times: ...
4
votes
1answer
834 views

Tail-recursive factorial

Is there anything what could be improved on this code? def factorial(n: Int, offset: Int = 1): Int = { if(n == 0) offset else factorial(n - 1, (offset * n)) } ...
6
votes
3answers
808 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
2answers
211 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 ...
2
votes
1answer
170 views

Defining transpose on a collection of irregular collections

I was asked to submit my request for code review on http://stackoverflow.com/questions/10672046/defining-transpose-on-a-collection-of-irregular-collections here. This is a follow-up to the post I ...
4
votes
2answers
128 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
103 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 ...
4
votes
4answers
270 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
211 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 ...
3
votes
1answer
348 views

Functionally retrieving rows from a database in Scala

Consider the following piece of code: ...
2
votes
4answers
438 views

Multiple if conditons in scala using funcional programming

The following code has a lot of conditionals. I am trying to write it in a functional programming way. ...
1
vote
2answers
387 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 : ...