//arrow-meta/arrow.meta.phases.analysis/intersect

intersect

[jvm]
fun <C : CallableDescriptor> C.intersect(eq: Eq<KotlinType>, types: KotlinBuiltIns.() -> List<KotlinType>): List<KotlinType>

Given eq this function returns KotlinTypes that intersect with the returnType from the list in types. One concrete example for equality on TypeConstructor may look like this:

import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import arrow.meta.phases.analysis.Eq
import arrow.meta.phases.analysis.intersect
//sampleStart

fun typeConstructorEq(): Eq<KotlinType> =
 Eq { t1, t2 ->
  t1.constructor == t2.constructor
 }

/**
* this function yields true if the type constructor - short [TC] - of the returnType in F is equal to one TC in [types]
*/
fun <F : CallableDescriptor> F.returns( //
  types: KotlinBuiltIns.() -> List<KotlinType>
): Boolean =
  intersect(typeConstructorEq(), types).isNotEmpty()
//sampleEnd

Parameters

jvm

   
eq can be define for e.g.: TypeConstructor, MemberScope or typeArguments List, etc.

See also

   
TypeUtils for more abstractions
functionTypeEq  

[jvm]
fun <D : DeclarationDescriptor> D.intersect(eq: Eq<KotlinType>, list: List<KotlinType>, other: KotlinBuiltIns.() -> List<KotlinType>): List<KotlinType>

given eq this function returns a List of KotlinType that are contained by both list and other

Parameters

jvm

   
eq can be defined for TypeConstructor, MemberScope or typeArguments List, etc.

See also

 
intersect

Do you like Arrow?

Arrow Org
<