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,?>>
public final class Upcast<A extends B,B> extends java.lang.Object implements Fn1<A,B>
Upcast a value of typeB
to a value of typeA
thatB
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.
-
-
Constructor Summary
Constructors Modifier Constructor Description private
Upcast()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description B
checkedApply(A a)
Invoke this function with the given argument, potentially throwing anyThrowable
.static <A extends B,B>
Upcast<A,B>upcast()
static <A extends B,B>
Bupcast(A a)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Field Detail
-
INSTANCE
private static final Upcast<?,?> INSTANCE
-
-
Method Detail
-
checkedApply
public B checkedApply(A a)
Description copied from interface:Fn1
Invoke this function with the given argument, potentially throwing anyThrowable
.- Specified by:
checkedApply
in interfaceFn1<A extends B,B>
- Parameters:
a
- the argument- Returns:
- the result of the function application
-
upcast
public static <A extends B,B> Upcast<A,B> upcast()
-
upcast
public static <A extends B,B> B upcast(A a)
-
-