>
> 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(string $method, ...$args): \Closure
> {
>     return static fn (object $o): mixed => $o->$method(...$args);
> }
>
> Which lets me do this:
>
> $parentNames = pipe($vals,
>   amap(method('getParent')),
>   amap(prop('name')),
> );



But I really don't like the stringy method and property names.


That sure does it, but not that type safe though.

The T_BLING (that is the only name I will allow for $$) marker has been
> discussed on and off a few times over the years, I think first in Sara's
> original pipes proposal many years ago.  I was actually going to suggest
> the same in this thread before I saw you did. :-)
>

Yes I found it. Actually there were many discussions about it. I didn't
really went through them, but how had it never made through? (I'll take
time to read through ofc)


> More abstractly, $$ meaning "the only obvious value in context" has
> potential, but also risk, because "obvious" is not always obvious.  I do
> think it's an area to explore, though, and would definitely help with
> functional style code that relies heavily on closures.
>

I'm not sure I understand how this could not be "always obvious". IF, -
let's say we stick to what hacklang has:
https://docs.hhvm.com/hack/expressions-and-operators/pipe - I think it's
farily straightforward

$a = $obj->getConfig()
 |> array_map($foo => $foo->getId(), $$)
 |> array_filter($foo => $foo !== "woof", $$)
 |> $this->toResponse($bar, $$, $baz);

But to get back to the original topic: I think this is what you were
looking for.

Zoltán Fekete

Reply via email to