Skip to content

Instantly share code, notes, and snippets.

@StrikingLoo
Created October 17, 2019 03:14
Show Gist options
  • Save StrikingLoo/6f1c7b7fe2abdce49b9c89a969ef8a4d to your computer and use it in GitHub Desktop.
Save StrikingLoo/6f1c7b7fe2abdce49b9c89a969ef8a4d to your computer and use it in GitHub Desktop.
// generic single-threaded map implementation using void* and pointer arithmetics.
void** map(void** things, void* (*f)(void*), int length){
void** results = malloc(sizeof(void*)*length);
for(int i = 0; i < length; i++){
void* thing = things[i];
void* result = (*f)(thing);
results[i] = result;
}
return results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment