title: How do you combine custom objects in Python to create a collection that maintains the interface of the underlying objects?
body: <p>I have a group of objects in python I'd like to sum without losing access to the functionality implemented in the objects.</p>
  <p>To illustrate the point, consider this class:</p>
  <pre><code>class PlaneTicket:
      def __init__(self, origin:str, destination:str):
          ...
  
      def price(self, pricingDate:date)-&gt;float:
          '''Returns the best price available on a given date'''
          ...
  </code></pre>
  <p>In my application I need to be able to sum these objects. You can think of it as having to create a journey that requires two plane tickets.</p>
  <pre><code>flight1 = PlaneTicket('london', 'new-york')
  flight2 = PlaneTicket('new-york', 'paris')
  
  journey = flight1 + flight2
  </code></pre>
  <p>Now, the interesting thing is, I also want to be able to use the methods in the underlying objects. Eg.</p>
  <pre><code>journey.price('2021-06-19') 
  # Should equal sum(flight.price('2021-06-19') for flight in journey.flights)
  </code></pre>
  <p>So, I could implement a class <code>Journey</code> and make the sum of <code>PlaneTicket</code> objects a <code>Journey</code> object, and also then implement a <code>.price</code> on the <code>Journey</code> class.</p>
  <p>However, I may be missing a better solution as I'm sure this is a common problem. Moreover, I'd need different implementations of the <code>Journey</code> class if I'm summing, averaging, or multiplying the <code>PlaneTicket</code> objects.</p>
  <p><strong>I suppose the general formulation would be:</strong></p>
  <ol>
  <li>I have a collection of objects that implement a method <code>foo()</code></li>
  <li>I want to aggregate these objects (eg. summing them)</li>
  <li>I want to be able to call <code>foo</code> on the aggregation and have the return values of the constituent objects aggregated.</li>
  </ol>