Skip to content

Instantly share code, notes, and snippets.

@ngoylufo
Last active May 3, 2020 01:08
Show Gist options
  • Save ngoylufo/3637f6ab1f078ad14b6043b892fae14a to your computer and use it in GitHub Desktop.
Save ngoylufo/3637f6ab1f078ad14b6043b892fae14a to your computer and use it in GitHub Desktop.
A collection of higher order utility functions written in python.
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