Popular Python recipes tagged "composition"http://code.activestate.com/recipes/langs/python/tags/composition/2012-10-06T22:15:17-07:00ActiveState Code Recipesfmap(): a kind of inverse of the built-in Python map() function (Python)
2012-10-06T22:15:17-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578281-fmap-a-kind-of-inverse-of-the-built-in-python-map-/
<p style="color: grey">
Python
recipe 578281
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/composition/">composition</a>, <a href="/recipes/tags/fmap/">fmap</a>, <a href="/recipes/tags/functional/">functional</a>, <a href="/recipes/tags/map/">map</a>).
</p>
<p>The Python map() function returns a list of the results of applying the function to the items of the argument sequence(s).</p>
<p>The fmap() function does the inverse, in a sense. It returns the result of applying a list of functions to a given argument.</p>
Composition of classes instead of multiple inheritance (Python)
2011-04-16T03:40:19-07:00Ethan Furmanhttp://code.activestate.com/recipes/users/4177684/http://code.activestate.com/recipes/577658-composition-of-classes-instead-of-multiple-inherit/
<p style="color: grey">
Python
recipe 577658
by <a href="/recipes/users/4177684/">Ethan Furman</a>
(<a href="/recipes/tags/class_decorator/">class_decorator</a>, <a href="/recipes/tags/composition/">composition</a>, <a href="/recipes/tags/inheritance/">inheritance</a>, <a href="/recipes/tags/multiple_inheritance/">multiple_inheritance</a>).
</p>
<p>MI can be difficult and confusing, and if the base classes don't cooperate -- well, cooperative MI won't work.</p>
<p>One way around this is to use composition instead. This class decorator will combine the source classes with the target class, ensuring that no duplications occur (raises a TypeError if there are any).</p>