Skip to content

Commit

Permalink
Reverse Result.fold params (#9)
Browse files Browse the repository at this point in the history
Signed-off-by: David Greven <[email protected]>
Signed-off-by: Sebastian Becker <[email protected]>
  • Loading branch information
grevend-bosch authored Nov 15, 2021
1 parent 91d8b58 commit 0c17224
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ void flatMapNullPointerException() {

@Test
void fold() {
assertThat(result.<Integer>fold(r -> r + 9, v -> v * 2)).isEqualTo(30);
assertThat(result.<Integer>fold(v -> v * 2, r -> r + 9)).isEqualTo(30);
}

@ParameterizedTest
@NullableParamSource("FOLD")
void foldNullPointerException(Function<? super Integer, ? super Integer> failureFunction,
Function<? super Integer, ? super Integer> successFunction) {
assertThatThrownBy(() -> result.fold(failureFunction, successFunction))
void foldNullPointerException(Function<? super Integer, ? super Integer> successFunction,
Function<? super Integer, ? super Integer> failureFunction) {
assertThatThrownBy(() -> result.fold(successFunction, failureFunction))
.isExactlyInstanceOf(NullPointerException.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ void flatMapNullPointerException() {

@Test
void fold() {
assertThat(result.<Integer>fold(r -> r + 9, v -> v * 2)).isEqualTo(24);
assertThat(result.<Integer>fold(v -> v * 2, r -> r + 9)).isEqualTo(24);
}

@ParameterizedTest
@NullableParamSource("FOLD")
void foldNullPointerException(Function<? super Integer, ? super Integer> failureFunction,
Function<? super Integer, ? super Integer> successFunction) {
assertThatThrownBy(() -> result.fold(failureFunction, successFunction))
void foldNullPointerException(Function<? super Integer, ? super Integer> successFunction,
Function<? super Integer, ? super Integer> failureFunction) {
assertThatThrownBy(() -> result.fold(successFunction, failureFunction))
.isExactlyInstanceOf(NullPointerException.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ public <N> Result<N, F> flatMap(Function<? super S, ? extends Result<? extends N
/**
* {@inheritDoc}
*
* @param failureFunction the mapping function to apply to a
* {@link Failure#reason()}
* @param successFunction the success mapping function to apply to a
* {@link Success#value()}
* @param failureFunction the mapping function to apply to a
* {@link Failure#reason()}
* @param <N> the type of the value returned from the
* mapping functions
* @return the folded value of mapping either this {@link Failure} reason
Expand All @@ -160,7 +160,7 @@ public <N> Result<N, F> flatMap(Function<? super S, ? extends Result<? extends N
*/
@Override
@SuppressWarnings("unchecked")
public <N> N fold(Function<? super F, ? super N> failureFunction, Function<? super S, ? super N> successFunction) {
public <N> N fold(Function<? super S, ? super N> successFunction, Function<? super F, ? super N> failureFunction) {
requireNonNull(successFunction);
return (N) failureFunction.apply(this.reason());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ default boolean isFailure() {
* applied to the {@link Failure#reason()}. Otherwise, the success
* function is applied to the {@link Success#value()}.
*
* @param failureFunction the mapping function to apply to a
* {@link Failure#reason()}
* @param successFunction the success mapping function to apply to a
* {@link Success#value()}
* @param failureFunction the mapping function to apply to a
* {@link Failure#reason()}
* @param <N> the type of the value returned from the
* mapping functions
* @return the folded value of mapping either this {@link Success} value
Expand All @@ -152,7 +152,7 @@ default boolean isFailure() {
* @see Success#value()
* @since 0.1.0
*/
<N> N fold(Function<? super F, ? super N> failureFunction, Function<? super S, ? super N> successFunction);
<N> N fold(Function<? super S, ? super N> successFunction, Function<? super F, ? super N> failureFunction);

/**
* If the {@code Result} is a {@link Success}, and the value matches the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ public <N> Result<N, F> flatMap(Function<? super S, ? extends Result<? extends N
/**
* {@inheritDoc}
*
* @param failureFunction the mapping function to apply to a
* {@link Failure#reason()}
* @param successFunction the success mapping function to apply to a
* {@link Success#value()}
* @param failureFunction the mapping function to apply to a
* {@link Failure#reason()}
* @param <N> the type of the value returned from the
* mapping functions
* @return the folded value of mapping this {@link Success} value
Expand All @@ -161,7 +161,7 @@ public <N> Result<N, F> flatMap(Function<? super S, ? extends Result<? extends N
*/
@Override
@SuppressWarnings("unchecked")
public <N> N fold(Function<? super F, ? super N> failureFunction, Function<? super S, ? super N> successFunction) {
public <N> N fold(Function<? super S, ? super N> successFunction, Function<? super F, ? super N> failureFunction) {
requireNonNull(failureFunction);
return (N) successFunction.apply(this.value());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ public <N> Result<N, F> flatMap(Function<? super S, ? extends Result<? extends N
/**
* {@inheritDoc}
*
* @param failureFunction the mapping function to apply to a
* {@link Failure#reason()}
* @param successFunction the success mapping function to apply to a
* {@link Success#value()}
* @param failureFunction the mapping function to apply to a
* {@link Failure#reason()}
* @param <N> the type of the value returned from the
* mapping functions
* @return the folded value of mapping either this {@link Failure} reason
Expand All @@ -130,7 +130,7 @@ public <N> Result<N, F> flatMap(Function<? super S, ? extends Result<? extends N
*/
@Override
@SuppressWarnings("unchecked")
public <N> N fold(Function<? super F, ? super N> failureFunction, Function<? super S, ? super N> successFunction) {
public <N> N fold(Function<? super S, ? super N> successFunction, Function<? super F, ? super N> failureFunction) {
requireNonNull(successFunction);
return (N) failureFunction.apply(this.reason());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ default boolean isFailure() {
* applied to the {@link Failure#reason()}. Otherwise, the success
* function is applied to the {@link Success#value()}.
*
* @param failureFunction the mapping function to apply to a
* {@link Failure#reason()}
* @param successFunction the success mapping function to apply to a
* {@link Success#value()}
* @param failureFunction the mapping function to apply to a
* {@link Failure#reason()}
* @param <N> the type of the value returned from the
* mapping functions
* @return the folded value of mapping either this {@link Success} value
Expand All @@ -153,7 +153,7 @@ default boolean isFailure() {
* @see Success#value()
* @since 0.1.0
*/
<N> N fold(Function<? super F, ? super N> failureFunction, Function<? super S, ? super N> successFunction);
<N> N fold(Function<? super S, ? super N> successFunction, Function<? super F, ? super N> failureFunction);

/**
* If the {@code Result} is a {@link Success}, and the value matches the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ public <N> Result<N, F> flatMap(Function<? super S, ? extends Result<? extends N
/**
* {@inheritDoc}
*
* @param failureFunction the mapping function to apply to a
* {@link Failure#reason()}
* @param successFunction the success mapping function to apply to a
* {@link Success#value()}
* @param failureFunction the mapping function to apply to a
* {@link Failure#reason()}
* @param <N> the type of the value returned from the
* mapping functions
* @return the folded value of mapping this {@link Success} value
Expand All @@ -131,7 +131,7 @@ public <N> Result<N, F> flatMap(Function<? super S, ? extends Result<? extends N
*/
@Override
@SuppressWarnings("unchecked")
public <N> N fold(Function<? super F, ? super N> failureFunction, Function<? super S, ? super N> successFunction) {
public <N> N fold(Function<? super S, ? super N> successFunction, Function<? super F, ? super N> failureFunction) {
requireNonNull(failureFunction);
return (N) successFunction.apply(this.value());
}
Expand Down

0 comments on commit 0c17224

Please sign in to comment.