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
3
votes
2answers
64 views

Naming a not-quite-flatMap method

I recently created Argyle, a small library for parsing command-line arguments in Scala. I'd be happy for anyone to take a look and provide general feedback on it. But there is also one specific issue ...
0
votes
2answers
93 views

Extract value from scala collect case

I have the following code which reads data from a key/value data storage. At some stage I want to go through everything in the storage and check expiry times and remove values - as done in the code ...
4
votes
3answers
103 views

Compare ZIP codes, disregarding leading zeros

I have a function that compares ZIP codes. It also has to handle cases where the input ZIP code be missing leading zeros, have extraneous leading zeros. This is what I've come up with. I don't have ...
5
votes
1answer
160 views

Scala Docx generator from CSV input, using the docx4j library and Scala Swing

I am working on an application which takes as input a CSV file containing a list of attributes and a .docx template containing variable names equal to the columns ...
1
vote
0answers
70 views

Choosing names for “logic” and “implementation” traits in Stackable trait pattern

I have a trait that is to be mixed-in with existing types of Actor classes in Akka and offer a certain functionality. To offer better maintenance, I am using the stackable trait pattern. The ...
4
votes
1answer
164 views

List replication problem from Hacker rank

Problem: Given a list, repeat each element in the list n amount of times. Solution: ...
4
votes
2answers
102 views

Find the minimum number of operations (concat, add and subtract) for the numbers 1-9 to equal 100

I am beginning to learn Scala and functional programming, and I came across this puzzle. This looked like good practice and I have a solution but just want some hints in terms of functional approach ...
1
vote
0answers
92 views

Purely functional minecraft-like mesh compiler

I'm creating a minecraft clone (for practice), in scala, using largely functional programming. When a chunk doesn't have a mesh loaded into VRAM, it create a Future for the vertex and index arrays, ...
6
votes
1answer
655 views

Convert time 24hr format into time as words

I'm currently writing a Scala Object that converts time 24hr format (i.e. 00:00 - 23:59) into Time As Words (i.e. Eight o'clock, Half past eight, Quarter to nine etc). How can I refactor the current ...
4
votes
0answers
90 views

Checking membership of object in set without pattern matching

I'm curious in how to best structure code that checks for membership of an instance of an ADT in a set of elements without using pattern matching. Given the following ADT, methods and functions, ...
1
vote
2answers
126 views

Find the most frequent character in a string

I'm trying to solve this problem https://community.topcoder.com/stat?c=problem_statement&pm=40 Given a string made up of ONLY letters and digits, determine which character is repeated the ...
1
vote
0answers
63 views

Sample Banking System Deposit Function

I am working on a sample banking system and have the following for deposit functionality, I was wondering if this is idiomatic, and how it can be improved. I have separated the algebra of the service ...
3
votes
0answers
2k views

Adding columns in Spark dataframe based on rules

I have a dataframe df, which contains below data: ...
2
votes
0answers
272 views

Scala Performance in Solving Sudoku

I translated Peter Norvig Python Sudoku solver to Scala and my Scala implementation was slower in the order of few magnitudes e.g. instantaneous, in Python, vs 4 to 5 seconds. I suspected I didn't ...
0
votes
1answer
72 views

Translate boolean flags to collection of numbers in scala

I'm having trouble to implement the following requirement in a functional way in scala. Given a predefined number of boolean flags, I want to build up a collection of numbers. For each (true) flag, a ...
3
votes
1answer
176 views

Scala Codility GenomicRangeQuery performance

I solved Codility's GenomicRangeQuery challenge in Scala. We are given a long DNA sequence (up to 100000 bases), where A, C, G, T are assigned values 1, 2, 3, 4, respectively. There are up to 50000 ...
2
votes
1answer
89 views

Generate a sequence of coin flips until pattern is hit

A book on probability says that a sequence of heads and tails is generated by a fair coin asking what is the probability that the pattern T, H, H, H occurs before the pattern H, H, H, H. I have made a ...
3
votes
1answer
730 views

Producer - multiple consumer implementation using futures

I've tried to implement a producer-multiple consumer pattern using futures and I was wondering should it ever deadlock, and if it should, why? I have this method ...
1
vote
0answers
99 views

Scala Functional Programming ODE Solver

I'm new to both Scala and Functional programming. I've been doing the excellent course Functional Programming Principles in Scala on Coursera and I want to test out what I've learned. I've written a ...
5
votes
1answer
174 views

Bowling game Kata in Scala - pattern match

This is a functional approach to problem described by standard Bowling Game Kata - to implement the rules of calculating a score in a bowling game. The inspiration was the implementation by Uncle Bob: ...
0
votes
1answer
1k views

Re-inventing the wheel: Binary search in Scala

I am trying to implement the code described in this post about how Reddit uses binary search to identify duplicate user names, in Scala. Just to clarify, this is mainly for me figuring out how these ...
1
vote
0answers
77 views

Extending a simple Tree parser and lexer

Yesterday, I decided to learn about scala's Parser-Combinator library. After a while, I was able to write a simple Tree parser and lexer which understands trees written like this: ...
3
votes
1answer
773 views

Scala traits for arithmetic expressions

I am learning Scala and want to know, what is preferred style of writing a function for a trait. First: ...
3
votes
1answer
81 views

Akka actor to calculate a soccer league rank

I am new to Scala / Akka and this is my first attempt at writing an actor. The task that I am trying to accomplish is: given a sequence of soccer matches, generate a ranking based on the usual rules ...
4
votes
1answer
362 views

Reverse Polish Notation calculator in Scala

I wrote an RPN solver in Scala. I'd love to get some feedback on approaches to make this feel more idiomatic. ...
3
votes
1answer
2k views

All combinations of 2-value variables

Introduction 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, ...
8
votes
1answer
276 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 ...
6
votes
0answers
396 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 ...
2
votes
1answer
1k 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
64 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-...
5
votes
0answers
64 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
213 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: ...
3
votes
3answers
1k views

Find next prime

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

Simplified Kata of BankOCR using Shapeless

I attempted to solve a simplification of User Story 2 using shapeless: Namely, define the implementation of: ...
3
votes
1answer
284 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 ...
2
votes
1answer
248 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 ...
4
votes
1answer
537 views

Heap Sort in Scala

Trying to implement Heap Sort in Scala ...
2
votes
0answers
140 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
183 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 ...
4
votes
1answer
277 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. ...
1
vote
0answers
46 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
45 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
1k views

Cartesian product in Scala

I'm using this code to compute a cartesian product: ...
2
votes
0answers
155 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
606 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 ...
1
vote
1answer
71 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
552 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 ...
5
votes
0answers
742 views

Akka Streams Flow through a cache

Assume I have a cache: ...
1
vote
1answer
106 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 ...
2
votes
2answers
857 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 2
3
4 5
10