Last active
October 8, 2022 02:49
-
-
Save theoknock/df16ca0d5c6a4bb6d0ae1ad4cf94d6bd to your computer and use it in GitHub Desktop.
Stream composition
This file contains hidden or 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
static void(^stream_composition_demo)(void) = ^{ | |
typedef typeof(unsigned long) predicate; | |
typedef typeof(predicate(^)(predicate)) predicate_function; | |
typedef typeof(predicate(^(*))(predicate)) predicate_function_t; | |
typeof(predicate_function) stream_op; | |
typeof(predicate_function_t) stream_op_t = &stream_op; | |
typeof(predicate_function) predicate_op; | |
typeof(predicate_function_t) predicate_op_t = &predicate_op; | |
predicate_op = ^ predicate (predicate p) { | |
printf("\t\tpredicate\n"); | |
return (unsigned long)(((unsigned long)nil ^ p) && (*predicate_op_t)(~-p)); | |
}; | |
typeof(predicate_function) function_op; | |
typeof(predicate_function_t) function_op_t = &function_op; | |
function_op = ^ predicate (predicate p) { | |
printf("function\n"); | |
return (unsigned long)(((unsigned long)nil ^ (*predicate_op_t)(p))); | |
}; | |
stream_op = ^ (typeof(predicate_function_t) func, typeof(predicate_function_t) pred) { | |
__block predicate_function_t operation = pred; | |
return ^ predicate (predicate p) { | |
return (*(typeof(predicate_function_t))((operation = (predicate_function_t)(void *)(uintptr_t)((uintptr_t)(pred) ^ (uintptr_t)(func) ^ (uintptr_t)(operation)))))(p); | |
}; | |
}(function_op_t, predicate_op_t); | |
stream_op(5UL); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment