From: shevegen@... Date: 2017-07-25T14:51:52+00:00 Subject: [ruby-core:82164] [Ruby trunk Feature#13765] Add Proc#bind Issue #13765 has been updated by shevegen (Robert A. Heiler). I do not have any pro or con opinion per se; my slight worry is about the name "bind". When I read .bind, I wonder what is actually bound, and to what it is bound. ---------------------------------------- Feature #13765: Add Proc#bind https://bugs.ruby-lang.org/issues/13765#change-65921 * Author: davidcornu (David Cornu) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- `Proc` has [`curry`](https://ruby-doc.org/core-2.4.1/Proc.html#method-i-curry) but no method to do [partial application](https://en.wikipedia.org/wiki/Partial_application). Something like `Proc#bind` might be handy. A naive implementation might look something like ~~~ ruby class Proc def bind(*bound_args) -> (*args) { self.call(*bound_args, *args) } end end ~~~ ~~~ text irb(main):001:0> foo = -> (first, second) { puts first, second } => # irb(main):002:0> foo.bind(1).call(2) 1 2 => nil irb(main):003:0> foo.bind(1).bind(2).call 1 2 ~~~ which does the job with the downside of only reporting argument mismatches when the returned `Proc` is called. ~~~ irb(main):004:0> foo3 = foo.bind(1).bind(2).bind(3) => # irb(main):005:0> foo.call ArgumentError: wrong number of arguments (given 0, expected 2) from (irb):6:in `block in irb_binding' from (irb):35 from /usr/local/bin/irb:11:in `
' ~~~ -- https://bugs.ruby-lang.org/ Unsubscribe: