Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature make shorter syntaxes #8

Merged
merged 8 commits into from
May 2, 2022
Merged

Conversation

omitobi
Copy link
Contributor

@omitobi omitobi commented May 1, 2022

PHP 8.1+ enables First-class Callable class syntax which gives cleaner call with Piper.
This PR adds the following:

Getting ['H', 'E', 'L', 'L', 'O', ' ', 'W', 'O', 'R', 'L', 'D'] examples:

Use line - as in the line in Pipe"line"

piper("Hello World")
    ->ln(
        htmlentities(...),
        str_split(...),
        [array_map(...), strtoupper(...)],
    );

Think about ductape on a pipe. Ducter allows such neat calls to your functions

ducter(
    "Hello World",
    htmlentities(...),
    str_split(...),
    [array_map(...), strtoupper(...)],
)

Call functions like an array:

_p("Hello World")
    [htmlentities(...)]
    [str_split(...)]
    [[array_map(...), strtoupper(...)]]()

How about Closure() on Closure

_p("Hello World")
    (htmlentities(...))
    (strtoupper(...))
    (str_split(...))
    (array_map(...), strtoupper(...))()

Cleaner with underscore _

_p("Hello World")
    ->_(htmlentities(...))
    ->_(str_split(...))
    ->_(array_map(...), strtoupper(...));

Shortcut to pipe() is p()

_p("Hello World")
    ->p(htmlentities(...))
    ->p(str_split(...))
    ->p(array_map(...), strtoupper(...))()

PHP 7.4 fn() like

_p("Hello World")
    ->fn(htmlentities(...))
    ->fn(str_split(...))
    ->fn(array_map(...), strtoupper(...))
    ->fn()

Proxied call to globally available functions

_p("Hello World")
    ->htmlentities()
    ->str_split()
    ->array_map(strtoupper($part))()

@omitobi omitobi merged commit 1f64fdf into master May 2, 2022
@omitobi omitobi deleted the feature-make-shorter-syntaxes branch August 8, 2023 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant