列表中每个元素的链条
是否存在列表中每个元素上调用功能的优雅方式与接下来的接合?
例如,我有:
val list = listOf(1,5,3,4)
fun Int.foo(next: Int) = //some logic
我想生成此表达式:
val result = 1.foo(5).foo(3).foo(4)
Is exist elegant way to call function on every element in list to tie with next till the end?
For example I have:
val list = listOf(1,5,3,4)
fun Int.foo(next: Int) = //some logic
I want to generate this expression:
val result = 1.foo(5).foo(3).foo(4)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此类操作称为降低或折叠收集,并使用 redion():
例如:
Such operation is called reducing or folding a collection and is done using reduce():
For example: