From: "phluid61 (Matthew Kerwin)" Date: 2013-02-25T09:18:42+09:00 Subject: [ruby-core:52855] [ruby-trunk - Feature #7939] Alternative curry function creation Issue #7939 has been updated by phluid61 (Matthew Kerwin). marcandre (Marc-Andre Lafortune) wrote: > It's pretty clear Nobu's example is more concise and nicer than what `assuming` would provide. BTW, the `.curry(3)` part can simply be `.curry`. As a philosophical question, would a name like #curry_with or #apply be more appropriate? There is a small amount of utility added by such a method: at first glance I didn't see the .curry on the end of the first line of Nobu's example, and it took a bit of effort on my part to parse the code (or its intent); however the call to .assuming made it clear that something different was intended and happening at that point. The square-bracket invocation falls somewhere in between, in terms of readability. It may just be me, but sometimes I temporarily fail to grasp that foo.bar[baz] is actually two chained method calls. In this case it was counfounded by the fact that I forgot that Proc#curry has an optional arity parameter. I know that those are my issues, that it is up to me to overcome, but having such hints in the code can help. ---------------------------------------- Feature #7939: Alternative curry function creation https://bugs.ruby-lang.org/issues/7939#change-36967 Author: drKreso (Kresimir Bojcic) Status: Assigned Priority: Normal Assignee: matz (Yukihiro Matsumoto) Category: core Target version: next minor =begin I really like the new "(({assuming}))" method used for currying in Perl 6. For example if I loose my mind and implement ((%fizzbuzz%)) via currying I can do it like this: fb = ->(modulo_number, message, x) { message if x % modulo_number == 0 } fizzbuzz = fb.curry[15,"FizzBuzz"] fizz = fb.curry[3, "Fizz"] buzz = fb.curry[5, "Buzz"] (1..100).each { |i| puts fizzbuzz[i] || fizz[i] || buzz[i] || i } Here the first hurdle is that curry is somewhat mathematical, and the secons is that you need to use (({[]})) for function invoking... If we had something similar to this: class Proc def assuming(*args) curry.call *args end end It could be written more naturally IMO: fb = ->(modulo_number, message, x) { message if x % modulo_number == 0 } fizzbuzz = fb.assuming(15,"FizzBuzz") buzz = fb.assuming(5, "Buzz") fizz = fb.assuming(3,"Fizz") (1..100).each { |i| puts fizzbuzz[i] || fizz[i] || buzz[i] || i } =end -- http://bugs.ruby-lang.org/