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

feat(siu): allow pipe func to accept args and kwargs #413

Merged
merged 12 commits into from Aug 26, 2022
Merged

feat(siu): allow pipe func to accept args and kwargs #413

merged 12 commits into from Aug 26, 2022

Conversation

machow
Copy link
Owner

@machow machow commented Apr 3, 2022

This PR expands the pipe function, and adds a call() function, to allow...

  • pipe() for a manual version of making pipes w/ >>
  • call() for making a specific step of pipe
    • arbitrary *args and **kwargs
    • a siu expression allowed as the first argument, rather than a regular callable
    • the ability choose where the data should go in the call
  • Pipeable() is now deprecated.

Note that this means that the old pipe() was essentially renamed call(). Because pipe() had very limited behavior, these changes are fully backwards compatible.

Should address #246 #408 #207. See #47 for a docs related issue.

⚠️ TODO: Note that I still need to add support for things like call(mutate, _, a = _.x + 1). Going to release as-is, though, since functions like mutate can already be used in a pipe..!

Examples from call docstring

The simplest use of call is passing just the to-be-called function.

s = "a string"
s >> call(print)
# a string

This is equivalent to explicitly passing _ as a placeholder.

from siuba import _
s >> call(print, _)
# a string

The explicit syntax is useful, because it allows us to pass more arguments.
For example, the code below passes additional arguments to print.

"a" >> call(print, _, "string", sep=" ")
# a string

You can transform the input data. For example, the code below passes "shout".upper()
to print.

"shout" >> call(print, _.upper())
# SHOUT

Since _ is just a placeholder for the data on the left-hand-side of >>, you
can pass it multiple times to the to-be-called function (e.g. print).

"nice" >> call(print, _, _, sep=" ")
# nice nice

Alternatively, you can pass a siu expression straight to call.

"abc" >> call(_[0].upper())
# 'A'

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.

None yet

1 participant