mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
PY-40431: WSL i18n
GitOrigin-RevId: cdd28e2fe19715dcaf4fcb23bc64244ec9c9b102
This commit is contained in:
committed by
intellij-monorepo-bot
parent
3fba268be2
commit
694162565c
@@ -1,6 +1,9 @@
|
||||
// Copyright 2000-2018 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.
|
||||
package com.jetbrains.python
|
||||
|
||||
import org.jetbrains.annotations.Nls
|
||||
import org.jetbrains.annotations.NonNls
|
||||
|
||||
/**
|
||||
* Operation result to be used with pattern matching.
|
||||
* Must be replaced with stdlib solution after [https://github.com/Kotlin/KEEP/blob/master/proposals/stdlib/result.md] completion.
|
||||
@@ -8,16 +11,17 @@ package com.jetbrains.python
|
||||
* Can't be moved to core module because core modules do not support Kotlin and there is no sealed classes in java.
|
||||
*/
|
||||
sealed class Result<SUCC, ERR> {
|
||||
data class Failure<SUCC, ERR>(val error: ERR) : Result<SUCC, ERR>()
|
||||
data class Failure<SUCC, ERR>(@Nls val error: ERR) : Result<SUCC, ERR>()
|
||||
data class Success<SUCC, ERR>(val result: SUCC) : Result<SUCC, ERR>()
|
||||
|
||||
fun <RES> map(map: (SUCC) -> RES): Result<RES, ERR> =
|
||||
when (this) {
|
||||
is Result.Success -> Result.Success(map(result))
|
||||
is Result.Failure -> Result.Failure(error)
|
||||
is Success -> Success(map(result))
|
||||
is Failure -> Failure(error)
|
||||
}
|
||||
|
||||
val successOrNull:SUCC? get() = if (this is Success) result else null
|
||||
|
||||
|
||||
val successOrNull: SUCC? get() = if (this is Success) result else null
|
||||
fun successOr(@NonNls errorForLog: String): SUCC {
|
||||
return (this as? Success)?.result ?: throw AssertionError(errorForLog)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user