Re: [PHP-DEV] First class callable syntax for instance methods

2023-04-18 Thread Larry Garfield
On Mon, Apr 17, 2023, at 2:52 PM, Zoltán Fekete wrote: >> $a = $obj->getConfig() >> |> array_map($$->getId(), $$) >> That is, using $$ to refer to "the value passed from the previous pipe" and >> "make a closure whose argument is an object that we can then operate on". >> Both of those are "obv

Re: [PHP-DEV] First class callable syntax for instance methods

2023-04-17 Thread Zoltán Fekete
> I can get assistance on a better implementation than my paltry skills were > able to manage before. (And if we can collectively make a stronger argument > for it.) Well sadly that definitely cannot be me. As I just started to get on board with internal development. But I am more than excited

Re: [PHP-DEV] First class callable syntax for instance methods

2023-04-16 Thread Larry Garfield
On Fri, Apr 14, 2023, at 5:52 AM, Zoltán Fekete wrote: > That sure does it, but not that type safe though. Right, which is why I'm fully on board with finding a native syntax way of doing it. (It would be faster, to, without two extra user space function calls.) > The T_BLING (that is the onl

Re: [PHP-DEV] First class callable syntax for instance methods

2023-04-14 Thread Zoltán Fekete
> > I believe the fancy academic name for what we're discussing here is > "lenses", and I agree that they'd be very useful. I currently use a > user-space wrapper like so: > > function prop(string $prop): \Closure > { > return static fn (object $o): mixed => $o->$prop; > } > > function method(

Re: [PHP-DEV] First class callable syntax for instance methods

2023-04-13 Thread Larry Garfield
On Thu, Apr 13, 2023, at 3:04 PM, Zoltán Fekete wrote: > Hey guys! > >> On 13. Apr 2023, at 16:28, Robert Landers wrote: >> >> I'd be down for implementing this in a heartbeat if we >> >> $a = Closure::fromCallable(static fn () => $this->getId()); >> $b = Closure::bindMany($items); // executes `

Re: [PHP-DEV] First class callable syntax for instance methods

2023-04-13 Thread Zoltán Fekete
> I cannot really assess how big of a hassle it would be, but what I personally > think that it look nice is something like this: > > ``` > class Verification > { > public function __construct(private string $id) {} > > public function getId(): string > { > return $this->id; > } >

Re: [PHP-DEV] First class callable syntax for instance methods

2023-04-13 Thread Zoltán Fekete
Hey guys! > On 13. Apr 2023, at 16:28, Robert Landers wrote: > > I'd be down for implementing this in a heartbeat if we > > $a = Closure::fromCallable(static fn () => $this->getId()); > $b = Closure::bindMany($items); // executes `bind` on each item in the > array, returning an array of closure

Re: [PHP-DEV] First class callable syntax for instance methods

2023-04-13 Thread Robert Landers
On Thu, Apr 13, 2023 at 3:47 PM Dan Ackroyd wrote: > I can't see a technical reason not to do it like this, but some people > seem to be having negative gut reactions to it, and it's hard to > persuade someone about aesthetics. > > Notes here: https://phpopendocs.com/rfc_codex/class_method_callabl

Re: [PHP-DEV] First class callable syntax for instance methods

2023-04-13 Thread Dan Ackroyd
On Thu, 13 Apr 2023 at 07:30, Robert Landers wrote: > > This has been brought up a couple of times, but I can't seem to find > it. https://externals.io/message/119392 https://externals.io/message/120011 > I don't think something like this is possible with the current > implementation of first-cl

Re: [PHP-DEV] First class callable syntax for instance methods

2023-04-12 Thread Rowan Tommins
On 13 April 2023 04:59:56 BST, Eugene Sidelnyk wrote: >It would be a great pleasure to have the ability to wrap the instance >method the same way. The first-class callable syntax works just fine with instance methods, but you need to use it on a particular instance: $someInstance->someMethod(

Re: [PHP-DEV] First class callable syntax for instance methods

2023-04-12 Thread Robert Landers
On Thu, Apr 13, 2023 at 6:00 AM Eugene Sidelnyk wrote: > > Hello, internals! I just want to share some thoughts with you regarding > what could be improved in the first class callable syntax. > > It is already possible to create Callable from a static method: > > ``` > class Foo { > public static

[PHP-DEV] First class callable syntax for instance methods

2023-04-12 Thread Eugene Sidelnyk
Hello, internals! I just want to share some thoughts with you regarding what could be improved in the first class callable syntax. It is already possible to create Callable from a static method: ``` class Foo { public static function staticmethod() {} } $c = Foo::staticmethod(...); ``` It would