`reduce` would be great extension for `NonEmptyIte...
# stdlib
m
reduce
would be great extension for
NonEmptyIterable
https://youtrack.jetbrains.com/issue/KT-21217
m
Hmm, makes me think if you could combine contracts with some kind of phantom type feature. So you could do something like this:
Copy code
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.
    }
}
d
m
Not the contract and smart cast stuff 🙂
d
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
The same compile time safety you would get by passing null to a non-null parameter at runtime. 😉
d
oh, ok
will stick to the arrow one, might be better to implement non empty lists at the type level