Last active
May 3, 2020 01:08
-
-
Save ngoylufo/3637f6ab1f078ad14b6043b892fae14a to your computer and use it in GitHub Desktop.
A collection of higher order utility functions written in python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
def identity(func): | |
return func | |
def partial(func, *args, **kwargs): | |
return functools.partial(func, *args, **kwargs) | |
def compose(*functions): | |
return lambda arg: reduceRight(lambda x, func: func(x), functions, arg) | |
def reduceRight(func, sequence, init = None): | |
return functools.reduce(func, reversed(sequence), init) | |
def map(func): | |
return lambda sequence: (func(x) for x in sequence) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment