aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/utilities/associateWithNotNull.kt
blob: 29e37d133d9828de51f781b1419de7026dc2ecbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
/*
 * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
 */

package org.jetbrains.dokka.utilities

import org.jetbrains.dokka.InternalDokkaApi

@InternalDokkaApi
public inline fun <K, V : Any> Iterable<K>.associateWithNotNull(valueSelector: (K) -> V?): Map<K, V> {
    @Suppress("UNCHECKED_CAST")
    return associateWith { valueSelector(it) }.filterValues { it != null } as Map<K, V>
}