Skip to content

Commit 9e01a99

Browse files
committed
Pass type parser as a function
1 parent aba6eb0 commit 9e01a99

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/main/java/com/saicone/types/TypeParser.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* @param <T> the type result of the function.
2727
*/
2828
@FunctionalInterface
29-
public interface TypeParser<T> {
29+
public interface TypeParser<T> extends Function<Object, T> {
3030

3131
/**
3232
* Create a type parser with associated type.
@@ -153,6 +153,12 @@ default boolean isInstance(@Nullable Object object) {
153153
throw new RuntimeException("The current type parser doesn't support instance check");
154154
}
155155

156+
@Override
157+
@Contract("null -> null")
158+
default @Nullable T apply(@Nullable Object object) {
159+
return object == null ? null : parse(object);
160+
}
161+
156162
/**
157163
* Parse the given object into required type.
158164
*

0 commit comments

Comments
 (0)