From 97a91c4d92afa59d68d769c5f823bcdbb1ef9aaa Mon Sep 17 00:00:00 2001 From: Sascha Grunert Date: Sun, 4 Mar 2018 16:38:45 +0100 Subject: [PATCH] Version 0.3.0 --- include/Either.h | 4 ++-- include/Func.h | 4 ++-- include/Maybe.h | 6 ++++-- test/Spec.cpp | 18 ++++++------------ 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/include/Either.h b/include/Either.h index da7a198..a9c9430 100644 --- a/include/Either.h +++ b/include/Either.h @@ -65,11 +65,11 @@ /** * @brief Retrieve the Left data if possible */ -#define fromLeft(o, x) (isLeft(o) ? x = o.leftData : x) +#define fromLeft(x, o) (isLeft(o) ? o.leftData : x) /** * @brief Retrieve the Right data if possible */ -#define fromRight(o, x) (isRight(o) ? x = o.rightData : x) +#define fromRight(x, o) (isRight(o) ? o.rightData : x) #endif // INCLUDE_EITHER_H_ diff --git a/include/Func.h b/include/Func.h index 31bbf49..4ee45a1 100644 --- a/include/Func.h +++ b/include/Func.h @@ -9,9 +9,9 @@ /** * @brief Version definition */ -#define FUNC_VERSION "0.2.0" +#define FUNC_VERSION "0.3.0" #define FUNC_VERSION_MAJOR 0 -#define FUNC_VERSION_MINOR 2 +#define FUNC_VERSION_MINOR 3 #define FUNC_VERSION_PATCH 0 /** diff --git a/include/Maybe.h b/include/Maybe.h index 0348862..7513001 100644 --- a/include/Maybe.h +++ b/include/Maybe.h @@ -61,8 +61,10 @@ #define isNothing(o) (!isJust(o)) /** - * @brief Retrieve the data if possible + * @brief Takes a default value and a Maybe value. If the Maybe is Nothing, + * it returns the default values; otherwise, it returns the value + * contained in the Maybe. */ -#define fromJust(o, x) (isJust(o) ? x = o.data : x) +#define fromMaybe(x, o) (isJust(o) ? o.data : x) #endif // INCLUDE_MAYBE_H_ diff --git a/test/Spec.cpp b/test/Spec.cpp index 839dbed..88ac085 100644 --- a/test/Spec.cpp +++ b/test/Spec.cpp @@ -19,8 +19,7 @@ SCENARIO("Maybe Data Type", "[Maybe]") { } WHEN("retrieving the inner value") { - int t = 1; - fromJust(sut, t); + int t = fromMaybe(1, sut); THEN("it should fail") { REQUIRE(t == 1); @@ -39,8 +38,7 @@ SCENARIO("Maybe Data Type", "[Maybe]") { } WHEN("retrieving the inner value") { - int t = 0; - fromJust(sut, t); + int t = fromMaybe(0, sut); THEN("it should succeed") { REQUIRE(t == 2); @@ -63,8 +61,7 @@ SCENARIO("Either Data Type", "[Either]") { } WHEN("retrieving the Left value") { - int t = 1; - fromLeft(sut, t); + int t = fromLeft(1, sut); THEN("it should succeed") { REQUIRE(t == 0); @@ -72,8 +69,7 @@ SCENARIO("Either Data Type", "[Either]") { } WHEN("retrieving the Right value") { - int t = 1; - fromRight(sut, t); + int t = fromRight(1, sut); THEN("it should fail") { REQUIRE(t == 1); @@ -92,8 +88,7 @@ SCENARIO("Either Data Type", "[Either]") { } WHEN("retrieving the Right value") { - char t = 'a'; - fromRight(sut, t); + char t = fromRight('a', sut); THEN("it should succeed") { REQUIRE(t == 'c'); @@ -101,8 +96,7 @@ SCENARIO("Either Data Type", "[Either]") { } WHEN("retrieving the Left value") { - int t = 1; - fromLeft(sut, t); + int t = fromLeft(1, sut); THEN("it should fail") { REQUIRE(t == 1);