What is the proper way to code a read-while loop in Scala?

前端 未结 3 511
轮回少年
轮回少年 2021-01-31 09:40

What is the \"proper\" of writing the standard read-while loop in Scala? By proper I mean written in a Scala-like way as opposed to a Java-like way.

Here is the code I

3条回答
  •  情书的邮戳
    2021-01-31 10:26

    Based on Rex's post that he mentioned:

    Stream.continually(input.read(buffer)).takeWhile(_ != -1).foreach(md.update(buffer, 0, _))
    

    You should replace the var readLen + while {...} lines with it, it produces the same result.

    As Rex mentioned, it works with scala 2.8.

提交回复
热议问题