move Map.reverse extension function to intellij.platform.util

GitOrigin-RevId: 33aa23554a13b6aaa33249d2c57d69746b75d606
This commit is contained in:
Daniil Ovchinnikov
2023-06-13 22:07:28 +00:00
committed by intellij-monorepo-bot
parent 8ad7ba225c
commit 7f3964f4c7
2 changed files with 8 additions and 2 deletions
@@ -1,4 +1,4 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.containers
typealias LookbackValue<T> = Pair<T, T?>
@@ -28,4 +28,8 @@ private class LookbackIterator<T>(private val iterator: Iterator<T>) : Iterator<
}
}
fun <K, V : Any> Map<K, V>.reverse(): Map<V, K> = map { (k, v) -> v to k }.toMap()
@Deprecated(
message = "Moved to another file",
level = DeprecationLevel.HIDDEN,
)
fun <K, V : Any> Map<K, V>.reverse(): Map<V, K> = reverse()
@@ -320,3 +320,5 @@ fun <Node> generateRecursiveSequence(initialSequence: Sequence<Node>, children:
* Returns a new sequence either of single given element, if it is not null, or empty sequence if the element is null.
*/
fun <T : Any> sequenceOfNotNull(element: T?): Sequence<T> = if (element == null) emptySequence() else sequenceOf(element)
fun <K, V : Any> Map<K, V>.reverse(): Map<V, K> = map { (k, v) -> v to k }.toMap()