miha-x64

    miha-x64

    3 years ago
    reduce
    would be great extension for
    NonEmptyIterable
    https://youtrack.jetbrains.com/issue/KT-21217
    m

    marstran

    3 years ago
    Hmm, makes me think if you could combine contracts with some kind of phantom type feature. So you could do something like this:
    inline class NonEmptyList<T>(val list: List<T>) {
        contract { list.isNotEmpty() implies list is NonEmptyList }
    }
    
    fun someFunction(list: List<T>) {
        if (list.isNotEmpty()) {
            // list is "smart cast" (or conforms) to NonEmptyList.
        }
    }
    dr.dreigh

    dr.dreigh

    3 years ago
    m

    marstran

    3 years ago
    Not the contract and smart cast stuff 🙂
    dr.dreigh

    dr.dreigh

    3 years ago
    I see yeah... be interested to see how that offers compile time safety from creating a non empty list, if you passed in a empty list at runtime (e.g from a web service response)
    m

    marstran

    3 years ago
    The same compile time safety you would get by passing null to a non-null parameter at runtime. 😉
    dr.dreigh

    dr.dreigh

    3 years ago
    oh, ok
    will stick to the arrow one, might be better to implement non empty lists at the type level