[#80531] Re: [ruby-cvs:65407] normal:r58236 (trunk): thread.c: comments on M:N threading [ci skip] — Eric Wong <normalperson@...>

SASADA Koichi <[email protected]> wrote:

24 messages 2017/04/02
[#80532] Re: [ruby-cvs:65407] normal:r58236 (trunk): thread.c: comments on M:N threading [ci skip] — SASADA Koichi <ko1@...> 2017/04/02

On 2017/04/02 11:35, Eric Wong wrote:

[#80540] Re: [ruby-cvs:65407] normal:r58236 (trunk): thread.c: comments on M:N threading [ci skip] — Eric Wong <normalperson@...> 2017/04/03

SASADA Koichi <[email protected]> wrote:

[#81027] Re: [ruby-cvs:65407] normal:r58236 (trunk): thread.c: comments on M:N threading [ci skip] — Eric Wong <normalperson@...> 2017/05/08

Eric Wong <[email protected]> wrote:

[#81028] Re: [ruby-cvs:65407] normal:r58236 (trunk): thread.c: comments on M:N threading [ci skip] — SASADA Koichi <ko1@...> 2017/05/08

On 2017/05/08 9:33, Eric Wong wrote:

[#81029] Re: [ruby-cvs:65407] normal:r58236 (trunk): thread.c: comments on M:N threading [ci skip] — SASADA Koichi <ko1@...> 2017/05/08

On 2017/05/08 10:53, SASADA Koichi wrote:

[#81031] Re: [ruby-cvs:65407] normal:r58236 (trunk): thread.c: comments on M:N threading [ci skip] — Eric Wong <normalperson@...> 2017/05/08

SASADA Koichi <[email protected]> wrote:

[#81033] Re: [ruby-cvs:65407] normal:r58236 (trunk): thread.c: comments on M:N threading [ci skip] — SASADA Koichi <ko1@...> 2017/05/08

On 2017/05/08 12:01, Eric Wong wrote:

[#81035] Re: [ruby-cvs:65407] normal:r58236 (trunk): thread.c: comments on M:N threading [ci skip] — Eric Wong <normalperson@...> 2017/05/08

SASADA Koichi <[email protected]> wrote:

[#81042] Re: [ruby-cvs:65407] normal:r58236 (trunk): thread.c: comments on M:N threading [ci skip] — SASADA Koichi <ko1@...> 2017/05/09

On 2017/05/08 15:36, Eric Wong wrote:

[#81044] Re: [ruby-cvs:65407] normal:r58236 (trunk): thread.c: comments on M:N threading [ci skip] — Eric Wong <normalperson@...> 2017/05/09

SASADA Koichi <[email protected]> wrote:

[#81045] Re: [ruby-cvs:65407] normal:r58236 (trunk): thread.c: comments on M:N threading [ci skip] — SASADA Koichi <ko1@...> 2017/05/09

On 2017/05/09 12:38, Eric Wong wrote:

[#81047] Re: [ruby-cvs:65407] normal:r58236 (trunk): thread.c: comments on M:N threading [ci skip] — Eric Wong <normalperson@...> 2017/05/09

SASADA Koichi <[email protected]> wrote:

[#80892] [Ruby trunk Misc#13514] [PATCH] thread_pthread.c (native_sleep): preserve old unblock function — ko1@...

Issue #13514 has been updated by ko1 (Koichi Sasada).

8 messages 2017/04/26

[ruby-core:80931] [Ruby trunk Feature#6284] Add composition for procs

From: ritchie@...
Date: 2017-04-28 19:47:27 UTC
List: ruby-core #80931
Issue #6284 has been updated by RichOrElse (Richie Paul Buitre).


matz (Yukihiro Matsumoto) wrote:
> I want to make sure if everyone agrees with "*" instead of OP's "<<".
> Besides that I also wanted to mention that Koichi concerns that function composition may be far slower than method chaining.
> 
> Matz.

+1 for #*

Initially I thought of the F# convention #<< and it's counter part #>> as intuitive. But after giving it some thought, and practice, I prefer #* and #+.

~~~ ruby
class Proc
  def +(other) # forward compose operation
    other.to_proc * self
  end

  def *(other) # backward compose operation
    -> arg { self.call other.(arg) } # with only one argument for performance reason.
  end
end

f = -> n { n  * 2 }
g = -> n { n  * 4 }
h = f * g                            # equivalent to (g + f)

puts h.(5)                           #=> 40
puts  (h  + :odd?).call(3)           #=> false
~~~

Instead of composition I see potential use for shovel operations #<< and #>> for piping purposes similar to Elixir's #|>.

~~~ ruby
class Object
  def >>(transform) # piping operation
    transform.(self)
  end
end

class Integer
  def >>(num_or_func)
    return num_or_func.(self) if num_or_func.respond_to? :call
    super
  end
end

class Proc
  def <<(input) # feed value
    call input
  end
end

add_header = ->val {"Title: " + val}
format_as_title = add_header + :capitalize + :strip

puts 'Title goes here.' >> format_as_title  #=> Title: title goes here.
puts format_as_title << 'Title goes there.' #=> Title: title goes there.
~~~





----------------------------------------
Feature #6284: Add composition for procs
https://bugs.ruby-lang.org/issues/6284#change-64565

* Author: pabloh (Pablo Herrero)
* Status: Feedback
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
=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:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread