andyg
01/12/2020, 6:15 PMget
the first of a list of possible keys from a map -- for example if the keys might not always be exact: personMap.getFrom("lastname", "LastName", "last_name", "nameLast")
?Milan Hruban
01/12/2020, 7:19 PMfun <K,V> Map<K,V>.getFrom(vararg getKeys: K): V? {
check(getKeys.isNotEmpty()) { "..." }
val key: K? = getKeys.firstOrNull { it in this.keys }
return if (key != null) this[key] else null
}
andyg
01/12/2020, 7:53 PMandyg
01/14/2020, 12:34 AMandyg
01/14/2020, 12:34 AMfun <K, V : Any> Map<K, V>.getFrom(vararg potentialKeys: K) : V? {
return potentialKeys.find { k -> this.containsKey(k) }?.let { this[it] }
}
andyg
01/14/2020, 12:35 AMMilan Hruban
01/14/2020, 9:07 AM