20
20
21
21
import io .vavr .control .Option ;
22
22
23
- import java .util .function .Function ;
24
-
25
23
/**
26
24
* Represents a partial function T -> R that is not necessarily defined for all input values of type T.
27
25
* The caller is responsible for calling the method isDefinedAt() before this function is applied to the value.
@@ -43,62 +41,6 @@ public interface PartialFunction<T, R> extends Function1<T, R> {
43
41
*/
44
42
long serialVersionUID = 1L ;
45
43
46
- /**
47
- * Unlifts a {@code totalFunction} that returns an {@code Option} result into a partial function.
48
- * The total function should be side effect free because it might be invoked twice: when checking if the
49
- * unlifted partial function is defined at a value and when applying the partial function to a value.
50
- *
51
- * @param totalFunction the function returning an {@code Option} result.
52
- * @param <T> type of the function input, called <em>domain</em> of the function
53
- * @param <R> type of the function output, called <em>codomain</em> of the function
54
- * @return a partial function that is not necessarily defined for all input values of type T.
55
- */
56
- static <T , R > PartialFunction <T , R > unlift (Function <? super T , ? extends Option <? extends R >> totalFunction ) {
57
- return new PartialFunction <T , R >() {
58
-
59
- private static final long serialVersionUID = 1L ;
60
-
61
- @ Override
62
- public R apply (T t ) {
63
- return totalFunction .apply (t ).get ();
64
- }
65
-
66
- @ Override
67
- public boolean isDefinedAt (T value ) {
68
- return totalFunction .apply (value ).isDefined ();
69
- }
70
-
71
- };
72
- }
73
-
74
- /**
75
- * Factory method for creating a partial function that maps a given {@code Value} to its underlying value.
76
- * The partial function is defined for an input {@code Value} if and only if the input {@code Value} is not
77
- * empty. If the input {@code Value} is not empty, the partial function will return the underlying value of
78
- * the input {@code Value}.
79
- *
80
- * @param <T> type of the underlying value of the input {@code Value}.
81
- * @param <V> type of the function input, called <em>domain</em> of the function
82
- * @return a partial function that maps a {@code Value} to its underlying value.
83
- */
84
- static <T , V extends Value <T >> PartialFunction <V , T > getIfDefined () {
85
- return new PartialFunction <V , T >() {
86
-
87
- private static final long serialVersionUID = 1L ;
88
-
89
- @ Override
90
- public T apply (V v ) {
91
- return v .get ();
92
- }
93
-
94
- @ Override
95
- public boolean isDefinedAt (V v ) {
96
- return !v .isEmpty ();
97
- }
98
-
99
- };
100
- }
101
-
102
44
/**
103
45
* Applies this function to the given argument and returns the result.
104
46
*
0 commit comments