Skip to content

Commit

Permalink
Merge pull request #1 from saschagrunert/version_0.3.0
Browse files Browse the repository at this point in the history
Improve fromLeft, fromRight and fromMaybe handling
  • Loading branch information
saschagrunert authored Mar 4, 2018
2 parents 54acfbe + 97a91c4 commit 5745179
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
4 changes: 2 additions & 2 deletions include/Either.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
4 changes: 2 additions & 2 deletions include/Func.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
6 changes: 4 additions & 2 deletions include/Maybe.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
18 changes: 6 additions & 12 deletions test/Spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -63,17 +61,15 @@ 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);
}
}

WHEN("retrieving the Right value") {
int t = 1;
fromRight(sut, t);
int t = fromRight(1, sut);

THEN("it should fail") {
REQUIRE(t == 1);
Expand All @@ -92,17 +88,15 @@ 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');
}
}

WHEN("retrieving the Left value") {
int t = 1;
fromLeft(sut, t);
int t = fromLeft(1, sut);

THEN("it should fail") {
REQUIRE(t == 1);
Expand Down

0 comments on commit 5745179

Please sign in to comment.