我正在尝试用rxscala https://medium.com/bystevenp/comment-trees-and-recursion-with-rxjava-d147a904610a重写此示例,但是卡住了使其变为尾递归
case class Item(hasKids: Boolean, kids: List[Int])
def getItem(i: Int): Observable[Item] = ???
@tailrec
def getComments(parentItem: Item): Observable[Item] = {
if (parentItem.hasKids) {
Observable.from(parentItem.kids)
.flatMap {
id =>
getItem(id)
}.flatMap {
item =>
getComments(item)
} merge Observable.just(parentItem)
} else {
Observable.just(parentItem)
}
}