On Thu, Sep 21, 2017 at 3:13 PM, Stanislav Malyshev <smalys...@gmail.com> wrote: > Hi! > >> After discussion with Levi and others who suggested a simpler >> approach, I'd like to offer >> https://github.com/php/php-src/compare/master...sgolemon:pipe2 as an >> alternate possibility. > > I am still feeling it is a bit weird to do things that way, but other > than that (which is just my personal issue) I do not see any problems in > this proposal. With magic weird $$ thing gone, it seems to be > straightforward and mostly intuitive. So while I am not feeling this is > a must, I think it may be nice to have it. > > It'd be also nice then if we could have some syntax that allowed us to > refer to functions/methods as callables - mostly for the benefit of the > code readers and IDEs. I.e. you can do "hello" |> "strtoupper" and it's > fine but it is not at all intuitive what you're doing sending one string > into another. Same with "hello" |> [$this, 'bar']. Now, if we could do > something like this: > "hello" |> &{strtoupper} > "hello" |> &{$this->bar} > > (yes I know the syntax is ugly, I hope you get the idea though to have a > syntax for this) then you could have better readability, easier IDE > autocompletion and other benefits. Not for this RFC, clearly, but just > putting it out there so I don't forget. > > -- > Stas Malyshev > smalys...@gmail.com > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php
I don't want to get too far off topic but since Stas has wandered off a bit already I'll mention this. Scala has "placeholders": val sum = List(1,2,3,4,5).reduceLeft(_+_) The expression `_ + _` will create a function that takes two parameters and then returns the result of adding them together, equivalent to this: val sum = List(1,2,3,4,5).reduceLeft((a, b) => a + b) The single underscore `_` might not work for PHP because `gettext` has used a single underscore as an alias for... a long time, maybe since its inception. But for this example I'll use it anyway: "hello" |> strtoupper(_) |> $this->bar(_) It's saying, pretty literally, fill in the blank. Remember, though, it's actually creating closures and doesn't directly mean "put the result of the left-hand side here" unlike the previous proposal for `$$`. I brought it up because this can fill the same need as Stas' proposal creating callables with something like `&{strtoupper}`. If we used the symbol `$$` for the same placeholder mechanism from Scala it becomes a more general purpose mechanism that could be used for any callables, not just ones involved in a pipe: $potentially_valid_emails = array_filter($this->isProperlyFormattedEmailAddress($$), $email_list); Anyway, the purpose of this thread is to talk about the pipe operator so I'll stop talking now. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php