Last active
December 20, 2017 14:02
-
-
Save justintuchek/0f4f88d7823790010e535219e3031bfe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RxInteropFunction<T, R> implements Func1<T, R>, Function<T, R> { | |
public static <T, R> RxInteropFunction<T, R> wrap(Function<T, R> function) { | |
return new RxInteropFunction<>(function); | |
} | |
private final Function<T, R> function; | |
private RxInteropFunction(Function<T, R> function) { | |
this.function = function; | |
} | |
@Override | |
public R apply(T t) throws Exception { | |
return function.apply(t); | |
} | |
@Override | |
public R call(T t) { | |
try { | |
return function.apply(t); | |
} catch (Throwable throwable) { | |
throw new RuntimeException(throwable); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RxInteropPredicate<T> implements Predicate<T>, Func1<T, Boolean> { | |
public static <T> RxInteropPredicate<T> wrap(Predicate<T> predicate) { | |
return new RxInteropPredicate<>(predicate); | |
} | |
private final Predicate<T> predicate; | |
public RxInteropPredicate(Predicate<T> predicate) { | |
this.predicate = predicate; | |
} | |
@Override | |
public boolean test(T t) throws Exception { | |
return predicate.test(t); | |
} | |
@Override | |
public Boolean call(T t) { | |
try { | |
return predicate.test(t); | |
} catch (Throwable throwable) { | |
throw new RuntimeException(throwable); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment