Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/io/vavr/PartialFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public boolean isDefinedAt(V v) {
* if the function is defined for the given arguments, and {@code None} otherwise.
*/
default Function1<T, Option<R>> lift() {
return t -> Option.when(isDefinedAt(t), apply(t));
return t -> Option.when(isDefinedAt(t), () -> apply(t));
}

}
6 changes: 6 additions & 0 deletions src/test/java/io/vavr/control/OptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,12 @@ public void shouldThrowExceptionOnNullCollectPartialFunction() {
Option.some(1).collect(pf);
}

@Test
public void shouldNotCallPartialFunctionOnUndefinedArg() {
final PartialFunction<Integer, Integer> pf = Function1.<Integer, Integer> of(x -> 1/x).partial(i -> i != 0);
assertThat(Option.of(0).collect(pf)).isEqualTo(Option.none());
}

// -- iterator

@Test
Expand Down