Tag: 效用法

是否有一个内置的Kotlin方法来将void函数应用于值?

我写了这个方法来将一个void函数应用到一个值并返回值。 public inline fun T.apply(f: (T) -> Unit): T { f(this) return this } 这在减少这样的事情上是有用的: return values.map { var other = it.toOther() doStuff(other) return other } 像这样的东西: return values.map { it.toOther().apply({ doStuff(it) }) } 有没有这样的语言function或方法已经建立到Kotlin?