CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
y33-j3T

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: y33-j3T/Coursera-Deep-Learning
Path: blob/master/Convolutional Neural Networks/week3/Car detection for Autonomous Driving/yad2k/utils/utils.py
Views: 13383
1
"""Miscellaneous utility functions."""
2
3
from functools import reduce
4
5
6
def compose(*funcs):
7
"""Compose arbitrarily many functions, evaluated left to right.
8
9
Reference: https://mathieularose.com/function-composition-in-python/
10
"""
11
# return lambda x: reduce(lambda v, f: f(v), funcs, x)
12
if funcs:
13
return reduce(lambda f, g: lambda *a, **kw: g(f(*a, **kw)), funcs)
14
else:
15
raise ValueError('Composition of empty sequence not supported.')
16
17