scala 尾递归示例


为递归优化

  def append(buff:BufferedReader, builder:String) : String = {
  Option(buff.readLine()) match {
    case Some(v)=>  {
      append(buff, builder + v + "\n")
    }
    case None => builder
  }
}
val html = append(br, "")

经验1: 分支代码上直接调用,不应该有其他的运算

经验2: 代码必须精简


参考:http://blog.csdn.net/wsscy2004/article/details/25561797