scala类的序列化
A sequence comprehension statement consists of a generator part which generates a list of values from the specified range of inputs and a statement which operates on these generated elements which is then stored in the output list to be returned at the end of computation. For example;
序列理解语句由一个生成器部分和一个对这些生成的元素进行操作的语句组成,该生成器部分从指定的输入范围生成一个值列表,这些语句然后存储在输出列表中,以在计算结束时返回。 例如;
object Sequence {
def main(args:Array[String]) {
def increment(from: Int, to:Int):List[Int] =
for(i <- List.range(from,to) if i % 5 == 0) yield i
println(increment(1,30))
}
}
In this example we are creating a method that accepts two Integer parameters from and to that takes the range of the numbers. For every number starting from 1 we are checking whether the number is divisible by 5 as i%5 == 0 which prints only the numbers divisible by 5 in the range 1-30.
在此示例中,我们将创建一个方法,该方法从到接受两个Integer参数,并采用数字范围。 对于从1开始的每个数字,我们都在检查该数字是否可被5整除,因为i%5 == 0,它仅打印在1-30范围内被5整除的数字。