Skip to content

Commit cb333f3

Browse files
author
Matthieu Ancellin
committed
Add some examples to the README.
1 parent 5bc2f7a commit cb333f3

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,73 @@ radius length
7878

7979
TODO
8080

81+
## As method chaining (WIP)
82+
83+
The labelled pipeline can also be seen as an alternative to method chaining:
84+
```python
85+
(
86+
my_object
87+
.do_this(1.0)
88+
.do_that(title="foo")
89+
.do_this_other_thing(True)
90+
)
91+
```
92+
93+
In the context of `labelled_function`, the equivalent code would be:
94+
```python
95+
(
96+
do_this
97+
| do_that
98+
| do_this_other_thing
99+
)(
100+
self=my_object,
101+
x=1.0,
102+
title="foo",
103+
all=True,
104+
)
105+
```
106+
or
107+
```python
108+
(
109+
do_this.fix(x=1.0)
110+
| do_that.fix(title="foo")
111+
| do_this_other_thing.fix(all=True)
112+
)(
113+
self=my_object
114+
)
115+
```
116+
or alternatively
117+
```python
118+
(
119+
let(self=my_object)
120+
| do_this.fix(x=1.0)
121+
| do_that.fix(title="foo")
122+
| do_this_other_thing.fix(all=True)
123+
)()
124+
```
125+
126+
Pro of `labelled_functions`:
127+
* More general: can pass more that one object between functions
128+
129+
Cons of `labelled_functions`:
130+
* All argument have to be keyword arguments.
131+
* Too much `fix`. Some syntactic sugar should be added in the future.
132+
133+
# Other tools
134+
135+
```python
136+
from time import sleep
137+
from labelled_functions import time
138+
139+
def f(x):
140+
sleep(x)
141+
y = x/2
142+
return y
143+
144+
print(time(f)(1))
145+
# {'y': 0.5, 'f_execution_time': 1.0011490990873426}
146+
```
147+
81148
## Acknowledgments
82149

83150
Some inspiration comes from the [xarray-simlab](https://github.com/benbovy/xarray-simlab) package by Benoit Bovy.

0 commit comments

Comments
 (0)