Ruby Issue Tracking System: Issueshttps://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112013-02-24T20:38:59ZRuby Issue Tracking System
Redmine Ruby master - Feature #7939 (Feedback): Alternative curry function creationhttps://redmine.ruby-lang.org/issues/79392013-02-24T20:38:59ZdrKreso (Kresimir Bojcic)kresimir.bojcic@gmail.com
<p>=begin<br>
I really like the new "(({assuming}))" method used for currying in Perl 6.</p>
<p>For example if I loose my mind and implement ((%fizzbuzz%)) via currying I can do it like this:</p>
<p>fb = ->(modulo_number, message, x) { message if x % modulo_number == 0 }<br>
fizzbuzz = fb.curry[15,"FizzBuzz"]<br>
fizz = fb.curry[3, "Fizz"]<br>
buzz = fb.curry[5, "Buzz"]<br>
(1..100).each { |i| puts fizzbuzz[i] || fizz[i] || buzz[i] || i }</p>
<p>Here the first hurdle is that curry is somewhat mathematical, and the secons is that you need to use (({[]})) for function invoking...<br>
If we had something similar to this:</p>
<p>class Proc<br>
def assuming(*args)<br>
curry.call *args<br>
end<br>
end</p>
<p>It could be written more naturally IMO:</p>
<p>fb = ->(modulo_number, message, x) { message if x % modulo_number == 0 }<br>
fizzbuzz = fb.assuming(15,"FizzBuzz")<br>
buzz = fb.assuming(5, "Buzz")<br>
fizz = fb.assuming(3,"Fizz")</p>
<p>(1..100).each { |i| puts fizzbuzz[i] || fizz[i] || buzz[i] || i }<br>
=end</p>