Created
October 17, 2019 03:14
-
-
Save StrikingLoo/6f1c7b7fe2abdce49b9c89a969ef8a4d to your computer and use it in GitHub Desktop.
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
// 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