代表Scala中的readline循环的最佳方法? [英] Best way to represent a readline loop in Scala?
本文介绍了代表Scala中的readline循环的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
来自C/C ++背景,我对编程的功能风格不太熟悉,因此我的所有代码都非常必要,因为在大多数情况下,我只是看不到更好的方法.
Coming from a C/C++ background, I'm not very familiar with the functional style of programming so all my code tends to be very imperative, as in most cases I just can't see a better way of doing it.
我只是想知道是否有一种方法可以使此 Scala 代码块更具有"功能"功能?
I'm just wondering if there is a way of making this block of Scala code more "functional"?
var line:String = "";
var lines:String = "";
do {
line = reader.readLine();
lines += line;
} while (line != null)
推荐答案
如何?
val lines = Iterator.continually(reader.readLine()).takeWhile(_ != null).mkString
这篇关于代表Scala中的readline循环的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文