Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

When I look at the new pipe syntax ...

    $output = $input
        |> trim(...)
        |> (fn (string $string) => str_replace(' ', '-', $string))
        |> (fn (string $string) => str_replace(['.', '/', '…'], '', $string))
        |> strtolower(...);
... I think why not just something like the following?

    $output = $input
        |> trim($)
        |> str_replace(' ', '-', $)
        |> str_replace(['.', '/', '…'], '', $)
        |> strtolower($);




The three dots in trim(...) make a callable out of a function, that was already in, so seem best to re-use that syntax, at least for now. [1]

As for the partial function application, there is already an RFC to add that, but it's not decided on as of now. [2]

1: https://www.php.net/manual/en/functions.first_class_callable...

2: https://wiki.php.net/rfc/partial_function_application_v2


Your second option was rejected years ago I believe. The pipes were designed to work alongside this rfc that was supposed to be in this new version (8.5) but due to time constraints it had to be delayed and it’s currently being voted https://wiki.php.net/rfc/partial_function_application_v2

That example in article is straight up terrible. The Java version would be:

  var input = "Some kind of string.";  
  var output = Optional.of(input)
    .map(i -> i.trim())
    .map(i -> i.replace(' ', '-'))
    .map(i -> i.replaceAll("[./…]", ""))
    .map(i -> i.toLowerCase())
    .get();
That is until you realize there is no reason to go weird with arrow operators when String is an object:

  var input = "Some kind of string.";        
  var output = input.trim()
    .replace(' ', '-')
    .replaceAll("[./…]", "")
    .toLowerCase();
It looks like they solved the wrong issue but that is probably just side effect of using trivial examples.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: