Method chaining creates readable, declarative code. Each method returns self to allow chaining.
# dirty — verbose, repetitive reassignment
def solve(items):
result = items
result = [x for x in result if x > 0]
result = [x * 2 for x in result]
result = result[:3]
return resultImplement a `Pipeline` class (via create_pipeline(items)) with filter(fn), map(fn), take(n) and value() methods — all chainable (each returns self except value).
create_pipeline([1,-2,3,4,5]).filter(lambda x: x>0).map(lambda x: x*2).take(2).value() → [2, 6]
Sample tests