Scala在Predef中有一个通用的identity
函数:
def identity[A](x: A): A
Kotlin 在标准图书馆有类似的设施吗?当然,我可以简单地使用{ it }
,但我发现identity
更容易阅读,实例化所有这些lambda有点浪费.
I must be able to use this identity
function in places where a function (Foo) -> Foo
is expected, for any type Foo
. Is such a function even possible in Kotlin's type system? (In the case of Scala, there is an implicit conversion that wraps the method inside a function object or something.)