def even(from: Int, to: Int): List[Int] =
for (i <- List.range(from, to) if i % 2 == 0) yield i
If you want to change selection, open document below and click on "Move attachment"
Sequence Comprehensions - Scala Documentation ator which introduces new variables, or it is a filter. A comprehension evaluates the body e for each binding generated by the enumerators and returns a sequence of these values.
Here is an example:
object ComprehensionTest1 extends App {
<span>def even(from: Int, to: Int): List[Int] =
for (i <- List.range(from, to) if i % 2 == 0) yield i
Console.println(even(0, 20))
}
The for-expression in function introduces a new variable i of type Int which is subsequently bound to all values of the list List(from, from + 1, ..., to
Summary
status
not read
reprioritisations
last reprioritisation on
suggested re-reading day
started reading on
finished reading on
Details
Discussion
Do you want to join discussion? Click here to log in or create user.