Class Upcast<A extends B,B>
java.lang.Object
com.jnape.palatable.lambda.functions.builtin.fn1.Upcast<A,B>
- Type Parameters:
A- the covariant typeB- the contravariant type
- All Implemented Interfaces:
Fn1<A,,B> Applicative<B,,Fn1<A, ?>> Cartesian<A,,B, Fn1<?, ?>> Cocartesian<A,,B, Fn1<?, ?>> Contravariant<A,,Profunctor<?, B, Fn1<?, ?>>> Functor<B,,Fn1<A, ?>> Profunctor<A,,B, Fn1<?, ?>> Monad<B,,Fn1<A, ?>> MonadReader<A,,B, Fn1<A, ?>> MonadRec<B,,Fn1<A, ?>> MonadWriter<A,B, Fn1<A, ?>>
Upcast a value of type
B to a value of type A that B extends. This is
principally useful when dealing with parametric types that are invariant in their parameters and a cast is
necessary for compatibility purposes.
Example:
Iterable<String> have = new ArrayList<>();
Iterable<CharSequence> want = map(upcast(), have); // necessary due to invariance in parameter
Note that this is universally safe.
-
Field Details
-
INSTANCE
-
-
Constructor Details
-
Upcast
private Upcast()
-
-
Method Details
-
checkedApply
Description copied from interface:Fn1Invoke this function with the given argument, potentially throwing anyThrowable.- Specified by:
checkedApplyin interfaceFn1<A extends B,B> - Parameters:
a- the argument- Returns:
- the result of the function application
-
upcast
-
upcast
public static <A extends B,B> B upcast(A a)
-