aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordmaclach <dmaclach@gmail.com>2021-07-14 18:55:10 -0700
committerGitHub <noreply@github.com>2021-07-14 21:55:10 -0400
commit775f66fb282ba8e7f24a27994942c7fbb82163f0 (patch)
treec279466a70cfac72c5131794ba8d3ac36bdd6658
parentfd75066f159234265efb8f838b056be5a2e00a59 (diff)
downloadbazel-skylib-775f66fb282ba8e7f24a27994942c7fbb82163f0.tar.gz
Update partial_doc.md (#308)
Clean up the docs to make them look significantly better. No semantics changes, just styling.
-rwxr-xr-xdocs/partial_doc.md25
1 files changed, 21 insertions, 4 deletions
diff --git a/docs/partial_doc.md b/docs/partial_doc.md
index 4559ba3..71987d6 100755
--- a/docs/partial_doc.md
+++ b/docs/partial_doc.md
@@ -12,16 +12,22 @@ passed to it at the call sites.
A partial 'function' can be defined with positional args and kwargs:
# function with no args
+ ```
def function1():
...
+ ```
# function with 2 args
+ ```
def function2(arg1, arg2):
...
+ ```
# function with 2 args and keyword args
+ ```
def function3(arg1, arg2, x, y):
...
+ ```
The positional args passed to the function are the args passed into make
followed by any additional positional args given to call. The below example
@@ -29,24 +35,30 @@ illustrates a function with two positional arguments where one is supplied by
make and the other by call:
# function demonstrating 1 arg at make site, and 1 arg at call site
+ ```
def _foo(make_arg1, func_arg1):
- print(make_arg1 + " " + func_arg1 + "!")
+ print(make_arg1 + " " + func_arg1 + "!")
+ ```
For example:
+ ```
hi_func = partial.make(_foo, "Hello")
bye_func = partial.make(_foo, "Goodbye")
partial.call(hi_func, "Jennifer")
partial.call(hi_func, "Dave")
partial.call(bye_func, "Jennifer")
partial.call(bye_func, "Dave")
+ ```
prints:
+ ```
"Hello, Jennifer!"
"Hello, Dave!"
"Goodbye, Jennifer!"
"Goodbye, Dave!"
+ ```
The keyword args given to the function are the kwargs passed into make
unioned with the keyword args given to call. In case of a conflict, the
@@ -56,29 +68,34 @@ value for keyword arguments and override it at the call site.
Example with a make site arg, a call site arg, a make site kwarg and a
call site kwarg:
+ ```
def _foo(make_arg1, call_arg1, make_location, call_location):
print(make_arg1 + " is from " + make_location + " and " +
call_arg1 + " is from " + call_location + "!")
func = partial.make(_foo, "Ben", make_location="Hollywood")
partial.call(func, "Jennifer", call_location="Denver")
-
+ ```
+
Prints "Ben is from Hollywood and Jennifer is from Denver!".
+ ```
partial.call(func, "Jennifer", make_location="LA", call_location="Denver")
-
+ ```
+
Prints "Ben is from LA and Jennifer is from Denver!".
Note that keyword args may not overlap with positional args, regardless of
whether they are given during the make or call step. For instance, you can't
do:
+```
def foo(x):
pass
func = partial.make(foo, 1)
partial.call(func, x=2)
-
+```
### Parameters