[#77789] [Ruby trunk Feature#12012] Add Boolean method — prodis@...
Issue #12012 has been updated by Fernando Hamasaki de Amorim.
4 messages
2016/10/27
[ruby-core:77534] [Ruby trunk Feature#6284] Add composition for procs
From:
bigbadmath@...
Date:
2016-10-09 14:30:16 UTC
List:
ruby-core #77534
Issue #6284 has been updated by Alexander Moore-Niemi.
I wrote a gem with a C extension of `Proc#compose`: https://github.com/mooreniemi/proc_compose#usage
What motivated me was `map f (map g xs) = map (f . g) xs`, and what I still don't understand (being a newbie to extending Ruby or understanding its internals) is that `.map(&some_proc).map(&some_other_proc)` still behaves better than `.map(&(some_proc * some_other_proc))` given my current implementation of `compose`. Although I think composition has a lot of uses, the admittedly small but free performance benefit I expected to gain was top of my list.
I do think emphasis on composition suggests a somewhat different style of writing Ruby, but I think it can be a good one, actually.
Paul: what's the performance of your `compose`? If I have time later I can use https://github.com/mooreniemi/graph-function to try and see.
----------------------------------------
Feature #6284: Add composition for procs
https://bugs.ruby-lang.org/issues/6284#change-60805
* Author: Pablo Herrero
* Status: Feedback
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
=begin
It would be nice to be able to compose procs like functions in functional programming languages:
to_camel = :capitalize.to_proc
add_header = ->val {"Title: " + val}
format_as_title = add_header << to_camel << :strip
instead of:
format_as_title = lambda {|val| "Title: " + val.strip.capitalize }
It's pretty easy to implement in pure ruby:
class Proc
def << block
proc { |*args| self.call( block.to_proc.call(*args) ) }
end
end
=end
---Files--------------------------------
0001-proc.c-Implement-Proc-for-Proc-composition.patch (3.65 KB)
0002-proc.c-Implement-Method-for-Method-composition.patch (2.67 KB)
0003-proc.c-Support-any-callable-when-composing-Procs.patch (3.97 KB)
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>