df
03/29/2020, 4:25 PMinline fun <T> withLoggingContext(map: Map<String, String>, body: () -> T): T {
invoking it like this
withLoggingContext(browserInfo.toMap()) {
logger.warn { "Payment context provides no customer ip address" }
}
leads to following compilation error
Error:(28, 13) Kotlin: None of the following functions can be called with the arguments supplied:
public inline fun <T> withLoggingContext(vararg pair: Pair<String, String>, body: () -> ???): ??? defined in mu
public inline fun <T> withLoggingContext(pair: Pair<String, String>, body: () -> ???): ??? defined in mu
public inline fun <T> withLoggingContext(map: Map<String, String>, body: () -> ???): ??? defined in mu
Help is appreciatedStephan Schroeder
03/29/2020, 4:36 PMlogger.warn ( "Payment context provides no customer ip address" )
df
03/29/2020, 4:40 PMactual fun warn(msg: () -> Any?)
df
03/29/2020, 4:40 PMStephan Schroeder
03/29/2020, 4:41 PMStephan Schroeder
03/29/2020, 4:42 PMStephan Schroeder
03/29/2020, 4:43 PMMap<String,String>
?df
03/29/2020, 4:45 PMMap<String,String?>
. Is there a neat utility function that turns Map<String,String?>
into Map<String,String>
like listOfNotNull
for lists?df
03/29/2020, 4:46 PMStephan Schroeder
03/29/2020, 4:48 PMmap.entries.mapNotNull {(key, value)->value?.let{key to it}}.toMap()
df
03/29/2020, 4:50 PMStephan Schroeder
03/29/2020, 4:52 PM.mapNotNull{key, value->value?.let{key to it}}.toMap()
df
03/29/2020, 4:55 PMdf
03/29/2020, 4:56 PMStephan Schroeder
03/29/2020, 4:56 PMentries
Kotlin wants type annotations. so back to `
map.entries.mapNotNull{(key, value)->value?.let{key to it}}.toMap()
Stephan Schroeder
03/29/2020, 4:57 PMfilterNotNullValues
and filterNonNullKeys
: those would be nice! The ticket is already two years old though.Stephan Schroeder
03/29/2020, 5:00 PMfun <K: Any, V> Map<K,V>.filterNotNullValues() = this.entries.mapNotNull{(key, value)->value?.let{key to it}}.toMap()
df
03/29/2020, 5:01 PMStephan Schroeder
03/29/2020, 5:02 PMfun <K: Any, V:Any> Map<K,V?>.filterNotNullValues(): Map<K,V> = this.entries.mapNotNull{(key, value)->value?.let{key to it}}.toMap()