Invoke a callable mapping Sketch to Sketch or None. Supports also callables that take no arguments such as breakpoint. Returns self if callable returns None. :param f: Callable to be invoked. :return: Sketch object.
(
self: T, f: Union[Callable[[T], T], Callable[[T], None], Callable[[], None]]
)
| 1319 | return self |
| 1320 | |
| 1321 | def invoke( |
| 1322 | self: T, f: Union[Callable[[T], T], Callable[[T], None], Callable[[], None]] |
| 1323 | ): |
| 1324 | """ |
| 1325 | Invoke a callable mapping Sketch to Sketch or None. Supports also |
| 1326 | callables that take no arguments such as breakpoint. Returns self if callable |
| 1327 | returns None. |
| 1328 | |
| 1329 | :param f: Callable to be invoked. |
| 1330 | :return: Sketch object. |
| 1331 | """ |
| 1332 | |
| 1333 | arity = get_arity(f) |
| 1334 | rv = self |
| 1335 | |
| 1336 | if arity == 0: |
| 1337 | f() # type: ignore |
| 1338 | elif arity == 1: |
| 1339 | res = f(self) # type: ignore |
| 1340 | if res is not None: |
| 1341 | rv = res |
| 1342 | else: |
| 1343 | raise ValueError("Provided function {f} accepts too many arguments") |
| 1344 | |
| 1345 | return rv |
| 1346 | |
| 1347 | def export( |
| 1348 | self: T, |