Linq Map! or Collect!
什么是Linq 等价于map!或收集! Ruby 中的方法?
1 2 3
|
a = [“a”,“b”,“c”,“d” ]
a.collect! {|x| x +“!” }
a #=> [“a!”,”b!”,”c!”,”d!” ]
|
我可以通过使用 foreach 遍历集合来做到这一点,但我想知道是否有更优雅的 Linq 解决方案。
- Linq 采用函数式方法,因此您通常不会像上面的示例那样进行就地修改。但是,这更符合 ruby?? 中 map 和 collect 的预期用途(没有!)
地图=选择
1
|
var x = new string[] {“a”,“b”,“c”,“d”}.Select(s => s+“!”);
|
高阶函数 map 最好用 Enumerable.Select 表示,它是 System.Linq.
中的扩展方法
如果你很好奇,其他高阶函数会这样展开:
reduce -> 可枚举。聚合
filter -> 可枚举.Where
来源:https://www.codenong.com/702123/
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_10814.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57