3 ms·
Or with numbered parameters (since ruby 3.0) list.each { work_on(_1) }
by greenpeas 4y ago
Or with numbered parameters (since ruby 3.0)
list.each { work_on(_1) }
- pmontra 4y agoWhich is exactly the kind of shortcut I loathe.
- greenpeas 4y agoyou're not alone :) https://bugs.ruby-lang.org/issues/15723 https://bugs.ruby-lang.org/issues/15723 This syntax looks ugly, but it's really nice when writing short scripts. Combined with one line function declarations: `def foo(n)= bar`, it can make an irb session much faster/shorter.
- BiteCode_dev 4y agoSwift has this as well, and it's really nice. Doing map(lambda x: x + 1, stuff) or [x + 1 for x in stuff] adds nothing of value for those very simple cases. I wish we had map($1 + 1, stuff), or ever better, stuff |> $1 + 1. Python does a lot of things right, but for a language with a strong emphasis on the iterator design pattern, I wish it would provide more expressive primitives. However, it comes with the FP territory, which Python is not well suited for, and it would also imply a higher cost of entry to beginners.
- kofejnik 4y agoQuite horrible imo. Creeping closer and closer to Perl with each iteration