Thread
#language-evolution
    Tomasz Krakowiak

    Tomasz Krakowiak

    1 year ago
    Anyone has idea if Kotlin crew already considered implementation of type functions?
    elizarov

    elizarov

    1 year ago
    We don't have near-term plans due to the lack of compelling use-cases to counter-balance the added complexity. If you have a specific use-case in mind, then please share it here or file an issue to https://kotl.in/issue
    Tomasz Krakowiak

    Tomasz Krakowiak

    1 year ago
    @elizarov I do : ) I am working on generic store API:
    public interface Store<in Query, out QueryResult<Q : Query>, in Mutation> {
    	fun <Q : Query>query(q : Q) : QueryResult<Q>
    	// ...
    }
    
    public class PropertyStore<Value>(
        private var value: Value
    ) : Store<GetValue<Value>, <GetValue<Value>> => Value, SetValue<Value>> {
        // ...
    }
    
    public class ListStore<Element>(/*...*/) : Store<ListQuery<Any?>, <ListQuery<Result>> => Result<Element>, ListMutation<Element>> {
        // ...
    }
    
    sealed class ListQuery<out Result<E : Element>>
    
    object ListSize : ListQuery<Int>
    
    class ListGet : ListQuery<<E>=>E>(val index : Int)
    another alternative for me to model it properly would be https://youtrack.jetbrains.com/issue/KT-33262 - and creating base class for
    Query<Result>
    .
    And a neat trick with nullability. We often have functions that result's nullability depends on parameter nullability - This can be expressed with type functions:
    typealias Converter<In, Out, Nullability<X>:X?> = (Nullability<In>) : Nullability<Out>
    typealias NullableConverter<In, Out> = Converter<In, Out, <X>=>X?>
    typealias NonNullConverter<In, Out> = Converter<In, Out, <X>=>X>