UniCoreFW

compose()

Compose multiple functions to execute in sequence.

Implementation

Functions are applied from right to left, just like in mathematical composition. Args: *funcs: Functions to compose Returns: A new function that is the composition of the input functions

Example

compose(lambda x: x + 1, lambda x: x * 2)(3)

Expected output: 7

Source Code

def compose(*funcs: Callable) -> Callable: def composed(value): for func in reversed(funcs): value = func(value) return value return composed