Eugenio
07/21/2018, 9:53 PMEugenio
07/21/2018, 9:53 PM@PublishedApi internal object Function1FunctorInstance_ : Function1FunctorInstance<Any?>
@InlineOnly
inline fun <I, A, B> Kind<Function1PartialOf<I>, A>.map(noinline f: (A) -> B): Function1<I, B> =
with(Function1FunctorInstance_ as Function1FunctorInstance<I>) { this@map.map(f) }
fun test(): Function1<String, Double> =
fun(it: String): Int { return it.length }
.k()
.let { it as Kind<Function1PartialOf<String>, Int> } // just to show we're using our extension!
.map { it.toDouble() }
Eugenio
07/21/2018, 10:07 PMKClass<Function1PartialOf<*>>
doesn't work with Function1PartialOf::class
!Eugenio
07/21/2018, 10:08 PM@InlineOnly
@JvmName("instanceFunctor<Function1PartialOf>")
inline fun <I> KClass<Functor<*>>.function1PartialOf(): Function1FunctorInstance<I> =
Function1FunctorInstance_ as Function1FunctorInstance<I>
val instance = Functor::class.function1PartialOf<String>()
Eugenio
07/21/2018, 10:09 PMFunction1
directly 🤔Eugenio
07/21/2018, 10:11 PM@InlineOnly
@JvmName("instanceFunctor<Function1>")
inline infix fun <I> KClass<Functor<*>>.of(type: KClass<Function1<*, *>>): Function1FunctorInstance<I> =
Function1FunctorInstance_ as Function1FunctorInstance<I>
val instance: Functor<Function1PartialOf<String>> = Functor::class of Function1::class
Eugenio
07/21/2018, 10:13 PMval instance = Functor::class.of<String>(Function1::class)
Eugenio
07/21/2018, 10:41 PM@higherkind
annotation only create a single "partial of" typealias, instead of going all the way down?
typealias Tuple10Of<A, B, C, D, E, F, G, H, I, J> = arrow.Kind10<ForTuple10, A, B, C, D, E, F, G, H, I, J>
typealias Tuple10PartialOf<A, B, C, D, E, F, G, H, I> = arrow.Kind9<ForTuple10, A, B, C, D, E, F, G, H, I>
instead of this
typealias Tuple10Of<A, B, C, D, E, F, G, H, I, J> = arrow.Kind10<ForTuple10, A, B, C, D, E, F, G, H, I, J>
typealias Tuple10PartialOf<A, B, C, D, E, F, G, H, I> = arrow.Kind9<ForTuple10, A, B, C, D, E, F, G, H, I>
typealias Tuple10PartialOf2<A, B, C, D, E, F, G, H> = arrow.Kind8<ForTuple10, A, B, C, D, E, F, G, H>
typealias Tuple10PartialOf3<A, B, C, D, E, F, G> = arrow.Kind7<ForTuple10, A, B, C, D, E, F, G>
typealias Tuple10PartialOf4<A, B, C, D, E, F> = arrow.Kind6<ForTuple10, A, B, C, D, E, F>
typealias Tuple10PartialOf5<A, B, C, D, E> = arrow.Kind5<ForTuple10, A, B, C, D, E>
typealias Tuple10PartialOf6<A, B, C, D> = arrow.Kind4<ForTuple10, A, B, C, D>
typealias Tuple10PartialOf7<A, B, C> = arrow.Kind3<ForTuple10, A, B, C>
typealias Tuple10PartialOf8<A, B> = arrow.Kind2<ForTuple10, A, B>
typealias Tuple10PartialOf9<A> = arrow.Kind<ForTuple10, A>
?pakoito
07/22/2018, 1:43 AMpakoito
07/22/2018, 1:43 AMpakoito
07/22/2018, 1:44 AMpakoito
07/22/2018, 1:45 AMpakoito
07/22/2018, 1:47 AMpakoito
07/22/2018, 1:47 AMEither.functor()
you have to pass or hint the type of the left sidepakoito
07/22/2018, 1:47 AMpakoito
07/22/2018, 1:48 AMEither.functor<Throwable>()
pakoito
07/22/2018, 1:48 AMEither.functor<String>()
even if it doesn’t have functions acting on the left sidepakoito
07/22/2018, 1:51 AMKind<Kind<ForEither, L>, A>
has three possible alias: Kind2<ForEither, L, A>
, Kind<EitherPartialOf<L>, A>
and EitherOf<L, A>
Eugenio
07/22/2018, 9:15 AMEither<Throwable, String>
and I apply a map(String -> Int)
I expect to get back an Either<Throwable, Int>
Eugenio
07/22/2018, 9:16 AMEugenio
07/22/2018, 9:17 AMEugenio
07/22/2018, 9:17 AMEugenio
07/22/2018, 9:18 AMEugenio
07/22/2018, 9:20 AMmapLeft
and mapRight
that have meaning only for EitherEugenio
07/22/2018, 11:15 AMinterface Kind<out F, out A>
class ForEither private constructor() { companion object }
@higherkind
sealed class Either<out A, out B> : EitherOf<A, B> {
to:
sealed class KindOrId
abstract class KindId(val forType: KClass<out Kind<*, *>>) : KindOrId()
open class Kind<out F: KindOrId, out A> : KindOrId()
object ForEither : KindId(Either::class)
@higherkind
sealed class Either<out A, out B> : EitherOf<A, B>() {
Eugenio
07/22/2018, 11:16 AMEugenio
07/22/2018, 11:17 AMEugenio
07/22/2018, 11:19 AMpakoito
07/22/2018, 12:11 PMout F: KindOrId
-> this doesn’t reflect that F is left-associative