poohbar
07/11/2019, 2:18 PMassociateBy
that would throw if a key should have more than one value?tseisel
07/11/2019, 2:57 PMinline fun <T, K> Iterable<T>.associateUniquelyBy(crossinline keyProvider: (T) -> K): Map<K, T> {
return groupingBy(keyProvider).aggregate { key, accumulator, element, first ->
if (first) element else error("Duplicated key: an element is already associated to the key $key")
}
}