Skip to content

Instantly share code, notes, and snippets.

@ChadSki
Created October 10, 2014 16:59
Show Gist options
  • Save ChadSki/fe803bfeb5d34c731b28 to your computer and use it in GitHub Desktop.
Save ChadSki/fe803bfeb5d34c731b28 to your computer and use it in GitHub Desktop.
def compose(f1, f2):
return lambda x: f1(f2(x))
/* declare a typedef for a function pointer */
typedef double (*Class2Func)(double);
typedef struct sComposition {
Class2Func f1;
Class2Func f2;
} *Composition;
Composition Compose( Class2Func f1, Class2Func f2)
{
Composition comp = malloc(sizeof(struct sComposition));
comp->f1 = f1;
comp->f2 = f2;
return comp;
}
double CallComposed( Composition comp, double val )
{
return comp->f1( comp->f2(val) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment