Tag: 折叠

如何在Kotlin中使用foldRight递归实现dropWhile

我一直在使用.foldRight()递归地实现高阶函数,就像实践一样,但是却一直难以实现。 _Collections.kt有迫切的方法,但我不能将其转换为递归结构。 作为参考,这是takeWhile fun takeWhile(list:List<Int>, func:(Int) -> Boolean):List<Int> = list.foldRight(emptyList(), { next:Int, acc:List<Int> -> if (func(next)) acc.plus(next) else emptyList() })