Canal
Build functions out of methods.
Examples
Canal can allow point-free expressions. For example, when using map:
%w{10010101 11100 10110}.map(&canal.to_i(2).to_s.reverse.to_i.to_s(2))
is equivalent to
%w{10010101 11100 10110}.map do |x|
x.to_i(2).to_s.reverse.to_i.to_s(2)
end
Identity
An empty canal is the identity function.
[1, 2, 3].map(&canal)
=> [1, 2, 3]
Exemple: Count truthy values.
[true, false, nil, "hey", 4].count(&canal)
=> 3
Operators
Fetch key in list of hash.
people = [{ name: "Alice" }, { name: "Bob" }]
people.map(&canal[:name])
=> ["Alice", "Bob"]
Multiply list of number by 2.
(0..5).map(&canal * 2)
=> [0, 2, 4, 6, 8, 10]
Installation
Add this line to your application's Gemfile:
gem 'canal'
And then execute:
$ bundle
Or install it yourself as:
$ gem install canal
Contributing
- Fork it ( http://github.com/becojo/canal/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request