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
11 views

All combinations of 2-value variables

This code was part of one of my projects where it was used to generate boolean input values for truth tables. I have since generalized it for combinations of variables with only 2 values, and added a ...
5
votes
1answer
25 views

Sieve of Eratosthenes performance; Scala very slow compared to Node.js

I am new to Scala so it might show. I am learning it for one of my classes and have to write a performance benchmark. I have written the Sieve of Eratosthenes in both Node.js and Scala, and my Node.js ...
0
votes
0answers
15 views

Banking operations in Akka, to be adapted to a multi-host environment

Being fairly new to Akka, I am looking for feedback and changes needed to go for multi hosts solution with self healing capabilities. I am trying to fit an analogy with my existing problem to more ...
4
votes
0answers
24 views

Kattis problem Amanda Lounges

I wrote this solution to Kattis problem Amanda Lounges in Scala. TL;DR: It's a graph theory problem where I read in a list of edges from stdin and try to compute the minimum number of nodes that ...
3
votes
1answer
65 views

Find maximum distance between elements of an array

I have written a program in scala which actually does the below For every number between the maximum and minimum value of the array calculate the distance for each and every element in the array ...
2
votes
2answers
50 views

Alternate Tree implementation

I am trying to implement algorithms related to trees in Scala. I have dabbled with the following implementations of a tree. Are there any pros and cons of preferring the non-...
4
votes
0answers
27 views

HListSum - Sum of HList's Nat's

I wrote HListSum, whose type parameter is an input HList. Its Out type member represents the ...
2
votes
1answer
105 views

Sum of HList (where all elements are Nat's)

I wrote the following to output, at the type level, the sum, Nat, of an input HList: ...
2
votes
3answers
99 views

Find next prime

I wrote small app finding next prime number starting from number passed as argument: ...
3
votes
0answers
28 views

Simplified Kata of BankOCR using Shapeless

I attempted to solve a simplification of User Story 2 using shapeless: Namely, define the implementation of: ...
1
vote
1answer
82 views

Haskell Parsec library implementation in Scala

I've been developing a compiler for a programming language I'm working on in Scala, and after having used Haskell's Parsec a lot for this sort of thing in the past I decided to reimplement the library ...
3
votes
1answer
89 views

Functional API wrapper written in Scala

I've been working on an small API wrapper for the GitHub API using Scala (full source on GitHub). I'm still very new to the language, so I was hoping to get some feedback about a couple of design ...
2
votes
1answer
49 views

Heap Sort in Scala

Trying to implement Heap Sort in Scala ...
0
votes
0answers
17 views

Integrate Phoenix web app with Scala program

As a proof of concept, I wanted to my Phoenix controller (my source code) to call a Scala to return a base-2 string representation of a base-10 number. The Scala program (source) was built and ...
0
votes
0answers
20 views

Implement SizeOf w/ Shapeless

I attempted to implement shapeless's SizeOf: ...
2
votes
0answers
25 views

Reduce sample rate of GPS data based on distance between points

The algorithm needs to reduce an RDD[GPSRecord] based on the distance between several points, e.g. "give me only GPS records when the distance between them exceeds ...
0
votes
1answer
44 views

Scala implicit conversion to add methods to Int

I started learning Scala, and like most functional languages, things get messy pretty quickly for a beginner. Here I have built a wrapper class for Ints so that I ...
3
votes
1answer
202 views

Implement `Penultimate` in Shapeless

I attempted to define Penultimate, i.e. a type class for shapeless.HList's that have a second to last element. ...
0
votes
0answers
36 views

cake pattern object assembly - using a builder function in combination with the cake pattern

I am new to the cake pattern, this is my first attempt at using it. Am I doing something wrong if I use the apply method in ...
1
vote
0answers
23 views

Cake Pattern with implicitly added functionality

I have a scenario where I want to implement a variant of a Cake Pattern, but adding implicit functionality to a class (a Spark DataFrame). So, basically, I want to be able to run a code like the ...
-1
votes
1answer
57 views

Cartesian product in Scala

I'm using this code to compute a cartesian product: ...
3
votes
0answers
55 views

Calculating Pi to a tolerance

I'm taking my first steps in the Scala world, though I'm not wholly unfamiliar with functional style. Apparently one way of calculating Pi is to sum the terms of the infinite series: $$4 * (\frac{1}{...
1
vote
1answer
43 views

Singly linked list in Scala

I've written a basic implementation of a singly linked list in Scala. I would appreciate any feedback and improvements (especially the remove() method, I feel like ...
0
votes
0answers
24 views

Achieving group_concat functionality in Spark 1.4

I am using this code to achieve the group_concat functionality in Spark 1.4 and it tt takes a longer time to execute. How can I optimize the above code to achieve ...
1
vote
1answer
50 views

Extends Scala iterator's drop method to allow for drop(x: Long)

I have a need to drop quantities of elements from an iterator beyond Int.MaxValue so I wrote a helper function that does just that. However, I can't help but feel ...
0
votes
1answer
139 views

Sort Stack using just an additional stack

The problem is from the cracking coding Interview programming book. The problem is that: Sort Stack: Write a program to sort a stack such that the smallest items are on the top. You can use an ...
0
votes
0answers
45 views

Stack of Plates in Scala

The problem is from the cracking code interview problem 3.3: Stack of Plates: Imagine a (literal) stack of plates. If the stack gets too high, it might topple. Therefore, in real life, we ...
3
votes
0answers
90 views

Akka Streams Flow through a cache

Assume I have a cache: ...
0
votes
1answer
58 views

Finding a passcode by comparing MD5 result

This function finds the 8 char passcode from a given "doorId". Is there a way to find the passcode in an undetermined number of steps without using a while? Maybe ...
1
vote
2answers
80 views

Intersection function in Scala

The problem is: Intersection: Given two (singly) linked lists, determine if the two lists intersect. Return the intersecting node. Note that the intersection is defined based on reference, not ...
1
vote
2answers
55 views

Check if a linked list is a palindrome in Scala

The problem: Palindrome: Implement a function to check if a linked list is a palindrome If it's a palindrome, the list must be the same backwards and forwards Below is the code I wrote: ...
1
vote
3answers
107 views

Sum Lists function in Scala

Sum Lists: You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1 's digit is at the head of the list. ...
0
votes
1answer
49 views

Check Permutation in Scala

The problem is: Given two strings, write a method to decide if one is a permutation of the other. I wrote the following code in scala, may I know any other optimization one? ...
3
votes
0answers
187 views

Distributed web crawler [closed]

I am building a distributed web crawler using akka streams. I have built a flow that works, however, I don't know what is truly ran in parallel. ...
3
votes
1answer
90 views

Merge sort in one Single Function in Scala

I have implemented a sortmerge in Scala in one single function. I would like to have it reviewed, so that I can have it well organized, and it is then doing what ...
3
votes
1answer
70 views

MarsRover in Scala

This is my first attempt at Scala programming. I tried to be functional but I'm not sure if I have achieved that. DataTypes.scala ...
0
votes
1answer
49 views

Print Connected Components Scala

Given a file containing adjacent IDs: i1, i2, i5 i3, i4 i2, i6, i7 i4, i8 i9, i3 I would like to print each of the connected components: ...
3
votes
1answer
49 views

FizzBuzz in Scala

As the title suggests, this is my FizzBuzz implementation in Scala. I started learning Scala (and functional programming in general) in small steps about two months ago, and one recent assignment ...
2
votes
1answer
80 views

A general-use For-comprehensible Loan Pattern

I use Scala's loan pattern in order to ensure and automate the resource aquisition and release after its use. When multiple resources have to be acquired at once, however, the function calls must be ...
2
votes
4answers
54 views

Displaying nested arithmetic expressions as a string using Scala pattern matching

I am learning the concepts of pattern matching in Scala. Following is an exercise for the same. The task is to define a show function that outputs an expression as ...
2
votes
1answer
87 views

Generating Fibonacci sequences in Scala

Would you consider this to be idiomatic Scala? If not, what would you do to improve it? ...
14
votes
1answer
217 views

All RGB colors in one image

This is a program to solve: Images with all Colors from Code Golf: Make images where each pixel is a unique color (no color is used twice and no color is missing). Create the image purely ...
2
votes
2answers
117 views

Sum of multiples of 3 or 5 below 1000 in Scala

I'm in the process of learning Scala, and started working through a series of coding puzzles that I've done previously in other languages. For example, this solution, coded in Erlang: ...
1
vote
1answer
70 views

Convert a List of graph edges to a Map of neighboring nodes

What would be best way achieving this? Is it possible to use Immutable map? ...
3
votes
1answer
46 views

Project Euler #12 in Scala — Highly divisible triangular numbers

I generally work in Python for programming competitions, but I'm teaching myself Scala. As an exercise, I've attempted Project Euler problem #12 in Scala. I hope that somebody familiar with Scala can ...
3
votes
0answers
145 views

Simple picture app for storing and viewing

Update: git repo: https://github.com/muhsinali/picture-example-minified This is my first project that I've written using Scala and the Play framework. It's a simple application that allows the user ...
1
vote
2answers
86 views

Taking some JSON data, converting the date format and calculating a user average

I'm originally a Java developer taking a stab at some Scala development. One of the main reasons I'm posting is because I know that in Scala you can write your code in a Java (OOP) way and it will run ...
2
votes
2answers
108 views

A Scala Maze Generator in Functional Style

I'm wondering if there is more I can do to incorporate more idiomatic scala and functional programming principles. I know the maze itself is mutable but i didn't see an easy solution to making it ...
2
votes
1answer
52 views

Building and querying an immutable phone book

I wanted to get your opinion on this immutable implementation of a Phone Book using recursion to process a stream. I am especially interested in ways to speed up the code execution. Here is an ...
1
vote
2answers
74 views

Record parsing to Scala object with some unknown fields

I am getting some customer data but don't know the complete schema beforehand. I want to parse this data and create a Scala object from it. But due to unknown fields in the record, I fill only the ...