Last active
March 30, 2018 13:09
-
-
Save saschagrunert/ccddd1d405fe24dbbffe7d7f51172958 to your computer and use it in GitHub Desktop.
Either example with structs
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
#include "include/Func.h" | |
#include <stdio.h> | |
struct baz { int value; }; | |
EITHER(struct baz *, baz, char, bax); | |
int main(void) { | |
struct baz value = { 3 }; | |
Either(baz, bax) result = Left_baz_bax(&value); | |
if (isLeft(result)) { | |
printf("should be printed\n"); | |
} | |
if (isRight(result)) { | |
printf("should not be printed\n"); | |
} | |
// the alternative value | |
struct baz defaultValue = { 0 }; | |
struct baz * newResult = fromLeft(&defaultValue, result); | |
printf("extracted result = %d\n", newResult->value); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment