Last active
November 7, 2024 18:21
-
-
Save theoknock/7af8df031f00302fe6760233bd3de15d to your computer and use it in GitHub Desktop.
Block 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
typedef const bool (^ __strong object_block)(const bool); | |
object_block object_blk = ^ bool (const bool b) { | |
printf("object_blk state == %s\n", (b) ? "TRUE" : "FALSE"); | |
return b; | |
}; | |
object_block object_blk_2 = ^ bool (const bool b) { | |
printf("object_blk_2 state == %s\n", (b) ? "TRUE" : "FALSE"); | |
return b; | |
}; | |
object_block object_blk_3 = ^ bool (const bool b) { | |
printf("object_blk_3 state == %s\n", (b) ? "TRUE" : "FALSE"); | |
return b; | |
}; | |
object_block (^object_blk_composition)(object_block, object_block) = ^ (object_block object_blk_a, object_block object_blk_b) { | |
return ^ bool (const bool b) { | |
return object_blk_b(object_blk_a(b)); | |
}; | |
}; | |
static bool (^(^(^audio_controller_)(const _Nonnull audio_state))(object_block))(void) = ^ (const audio_state _Nonnull state) { | |
static object_block object_composition = ^ bool (bool cond) { return cond; }; | |
static retained_object object_composition_t = &object_composition; | |
return ^ (object_block object) { | |
*object_composition_t = object_blk_composition(object, *object_composition_t); | |
return ^ bool { | |
return (*object_composition_t)(state()); | |
}; | |
}; | |
}; | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view. | |
bool (^(^audio_controller_ref)(object_block))(void) = audio_controller_(audio_state_ref_init(audio_engine(audio_source(audio_renderer())), audio_session())); | |
audio_controller_ref(object_blk); // Add a block to the composition | |
audio_controller_ref(object_blk_2); // Add another block to the composition | |
audio_controller_ref(object_blk_3)(); // Add one more block to the composition and invoke the composition block | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment