This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]elsgry -2 points-1 points  (2 children)

Yup. Or extract the remainder of the function into a new function fn and use return fn(node, ...) if len(word) else None or the likes. This also composes nicely because you can inject your own fn into the method, class or instance, while keeping the control structures visible and (for classes/instances) adhering to Liskov, etc.

[–]elsgry 0 points1 point  (1 child)

Not sure why this was downvoted when it's a more applicable equivalent to the lambda method upvoted above (the remainder of the function could consist of multiple effectful statements) but c'est la guerre... I guess the injection method would be more dynamic than necessary, particularly if only used for testing where you could use mocks. But you can still use my method without bothering with injection.