Skip to content

Instantly share code, notes, and snippets.

@theoknock
Created August 16, 2022 22:33
Show Gist options
  • Save theoknock/8b69062185e84e4d08d3effb2106993a to your computer and use it in GitHub Desktop.
Save theoknock/8b69062185e84e4d08d3effb2106993a to your computer and use it in GitHub Desktop.
Map-Reduce-Filter Block (In-Progress)
static void (^(^(^(^array_pointer_test)(const unsigned int))(CFTypeRef(^)(void)))(void(^)(CFTypeRef)))(CFTypeRef(^)(CFTypeRef)) = ^ (unsigned int object_count) {
typedef CFTypeRef objects[object_count];
typeof(objects) objects_ptr[object_count];
__block unsigned long (^recursive_block)(unsigned long);
(recursive_block = ^ unsigned long (unsigned long index) {
printf("index == %lu\n", index);
return (unsigned long)(index ^ 0UL) && (unsigned long)(recursive_block)(~-index);
})(object_count);
return ^ (CFTypeRef * objects_t) {
return ^ (CFTypeRef(^write_object)(void)) {
for (unsigned int index = 0; index < object_count; index++) {
*((CFTypeRef *)objects_t + index) = CFBridgingRetain((__bridge id _Nullable)(write_object()));
printf("stored_number = %lu\n", [(NSNumber *)((__bridge id)(*((CFTypeRef *)objects_t + index))) unsignedLongValue]);
}
return ^ (void(^read_object)(CFTypeRef)) {
for (unsigned int index = 0; index < object_count; index++)
read_object((*((CFTypeRef *)objects_t + index)));
// printf("number_read = %lu\n", [(NSNumber *)((__bridge id)(*((CFTypeRef *)objects_t + index))) unsignedLongValue]);
return ^ (CFTypeRef(^modify_object)(CFTypeRef)) {
for (unsigned int index = 0; index < object_count; index++) {
*((CFTypeRef *)objects_t + index) = CFBridgingRetain((__bridge id _Nullable)(modify_object((*((CFTypeRef *)objects_t + index)))));
printf("modify_number = %lu\n", [(NSNumber *)((__bridge id)(*((CFTypeRef *)objects_t + index))) unsignedLongValue]);
}
};
};
};
}(objects_ptr);
};
// ---- Sample usage
__block int c = 0;
array_pointer_test(10)(^ CFTypeRef {
__block NSNumber * number = [[NSNumber alloc] initWithUnsignedLong:c++];
printf("number_write == %p\n", number);
return (__bridge CFTypeRef)(number);
})(^ (CFTypeRef number) {
printf("number_read == %lu\n", [(__bridge NSNumber *)number unsignedLongValue]);
})(^ CFTypeRef (CFTypeRef number) {
// number = (__bridge CFTypeRef)([[NSNumber alloc] initWithUnsignedLong:c++]);
return (CFTypeRef)(number);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment