https://github.com/vendethiel/autounderscore.rb
Magical `it`, `_`, and `_N` lambda builders (where 0 <= N <= 9)
https://github.com/vendethiel/autounderscore.rb
lambda ruby
Last synced: about 1 year ago
JSON representation
Magical `it`, `_`, and `_N` lambda builders (where 0 <= N <= 9)
- Host: GitHub
- URL: https://github.com/vendethiel/autounderscore.rb
- Owner: vendethiel
- Created: 2022-05-16T11:53:58.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-01-31T15:50:36.000Z (over 2 years ago)
- Last Synced: 2025-03-22T08:48:22.891Z (over 1 year ago)
- Topics: lambda, ruby
- Language: Ruby
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# AutoUnderscore
Allows you to write succinct lambdas with `it` (groovy-style) or numbered `_` helpers (where `_` is the same as `it` and
as `_0`).
The operator to call the final function is `[]` (like for closures).
Some examples:
```ruby
# A simple identity example
it[0]
#=> 0
it.to_s[:foo]
#=> "foo"
(_(0) + _(1))[1, 10]
# => 11
# A more convoluted example
((_0.split(" ") + _1.split(" ")).join(_2))["a b", "c d", ","]
#=> a,b,c,d
# _ is the "next argument" placeholder
(_ + _)[1, 2]
#=> 3
```