This is a page from my book, Functional Programming, Simplified
How to Enable Filtering in a Scala `for` Expression
Next, let’s see if we can use a filtering clause inside of a for
expression with the Sequence
code we have so far.
Trying to use a filtering expression
When I paste the current Sequence
class and this code into the Scala REPL:
val ints = Sequence(1,2,3,4,5)
val res = for {
i <- ints
if i > 2
} yield i*2
I see the following error message: