From: me@... Date: 2017-07-25T19:36:04+00:00 Subject: [ruby-core:82169] [Ruby trunk Feature#13765] Add Proc#bind Issue #13765 has been updated by davidcornu (David Cornu). > I do not have any pro or con opinion per se; my slight worry is about the name "bind". Yeah I share that concern. Ruby has a concept of bound methods which might get confused with this. Lodash/Underscore refer to this as `partial` (https://lodash.com/docs/#partial) which could be a better name. ---------------------------------------- Feature #13765: Add Proc#bind https://bugs.ruby-lang.org/issues/13765#change-65925 * 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: