-
-
Notifications
You must be signed in to change notification settings - Fork 654
New feature: .mapTo(U) and .mapToVoid() for Value<T> #3086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
a9c5c55
d0c911a
1ce4c46
9d3a3d1
333fc3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -416,6 +416,14 @@ default T getOrNull() { | |
| return isEmpty() ? null : get(); | ||
| } | ||
|
|
||
| default <U> Value<U> as(U val) { | ||
| return map((ignored) -> val); | ||
| } | ||
|
|
||
| default Value<Void> voided() { | ||
|
||
| return map((ignored) -> null); | ||
| } | ||
|
|
||
| /** | ||
| * Checks if this {@code Value} is asynchronously (short: async) computed. | ||
| * <p> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -218,6 +218,25 @@ public void shouldReturnValueWhenGetOrNullOfNonEmpty() { | |
| assertThat(of(1).getOrNull()).isEqualTo(1); | ||
| } | ||
|
|
||
| // -- as | ||
|
||
|
|
||
| @TestTemplate | ||
| public void shouldExecuteAsCorrectly() { | ||
| assertThat(empty().as(1)).isEqualTo(empty().as(2)); | ||
| assertThat(of(2).as(1)).isEqualTo(of(3).as(1)); | ||
| assertThat(of(2).as(1)).isEqualTo(of(3).map(ignored -> 1)); | ||
| assertThat(of(3).as(2)).isEqualTo(of(1).map(ignored -> 2)); | ||
| } | ||
|
|
||
| // -- voided | ||
|
||
|
|
||
| @TestTemplate | ||
| public void shouldExecuteVoidedCorrectly() { | ||
| assertThat(empty().voided()).isEqualTo(empty()); | ||
| assertThat(of(1).voided()).isEqualTo(of(1).as(null)); | ||
| assertThat(of(1).voided()).isEqualTo(of(1).map(ignored -> null)); | ||
| } | ||
|
|
||
| // -- forEach | ||
|
|
||
| @TestTemplate | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.