Given a set represented as a String, we can compute its powerset using foldLeft, as shown below.
def powerset(s: String) =
s.foldLeft(Set("")) {
case (acc, x) => acc ++ acc.map(
There are several ways to accomplish this. Next code snippet shows how to compute min and max using reduceLeft.
val ls = List(1,2,3,4,5)
ls.reduceLeft(_ min _) // is equivalent to
This post discusses a O(n) algorithm that construct a balanced binary search tree (BST) from a sorted list. For instance, consider that we are given a sorted list: [1,2,3,4,
Following is a simple solution to the LeetCode's Reverse Words in a String problem.
def reverseWords(s: String) =
s.split (" ")
.reverse
.mkString(" ")
Lets execute it in the
"Functional Scala" is a set of tutorials on Scala programming language by Mario Gleichmann. Although a bit verbose, it introduces the key constructs of Scala, and outlines Scala's primary