Prepare repository for merge

This commit is contained in:
Angelos Chalaris
2023-05-01 22:43:50 +03:00
parent ab1ea476c5
commit a5ca5190e5
169 changed files with 0 additions and 626 deletions

View File

@ -0,0 +1,26 @@
---
title: Reverse compose functions
type: snippet
tags: [function]
cover: lavender-shelf
dateModified: 2020-11-02T19:27:07+02:00
---
Performs left-to-right function composition.
- Use `functools.reduce()` to perform left-to-right function composition.
- The first (leftmost) function can accept one or more arguments; the remaining functions must be unary.
```py
from functools import reduce
def compose_right(*fns):
return reduce(lambda f, g: lambda *args: g(f(*args)), fns)
```
```py
add = lambda x, y: x + y
square = lambda x: x * x
add_and_square = compose_right(add, square)
add_and_square(1, 2) # 9
```