7 ms·
In Python: sum(range(10)) In Rust: Vec![1..10].iter().reduce(|x,y| x+y)
by rthomas6 5y ago
In Python:
sum(range(10))
In Rust:
Vec![1..10].iter().reduce(|x,y| x+y)
- miniupuchaty 5y agoIn Rust: (1..10).sum()
- rthomas6 5y agoI guess that shows how new I still am at Rust...
- comonoid 5y agoAll these languages took a lot from Lisp (especially former) and functional languages (especially latter). So it's like complaining to Newton that's his laws of mechanics are known by almost everyone these days, so Newton did nothing special.
- rthomas6 5y agoI'm not complaining. I just wanted to add more languages.
- PinkMilkshake 5y agoIn Raku: sum(1..10) (1..10).sum or just sum 1..10
- lizmat 5y agoOr more generically: [+] 1..10 You can use any infix op (core or custom) to do a reduction: [*] 1..10 # 3628800 basically faculty