File tree Expand file tree Collapse file tree 1 file changed +67
-0
lines changed Expand file tree Collapse file tree 1 file changed +67
-0
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,73 @@ radius length
78
78
79
79
TODO
80
80
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
+
81
148
## Acknowledgments
82
149
83
150
Some inspiration comes from the [ xarray-simlab] ( https://github.com/benbovy/xarray-simlab ) package by Benoit Bovy.
You can’t perform that action at this time.
0 commit comments