From 3b1124a804f999189b920a2e9f269bc9010a1aec Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 30 Oct 2021 12:17:18 +0600 Subject: [PATCH] fixes --- .../kotlin/dev/inmo/micro_utils/common/Either.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Either.kt b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Either.kt index 700580015b3..f57136aefb6 100644 --- a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Either.kt +++ b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Either.kt @@ -44,7 +44,7 @@ inline fun Either.Companion.first(t1: T1): Either = EitherFirst /** * @return New instance of [EitherSecond] */ -inline fun Either.Companion.second(t1: T1): Either = EitherFirst(t1) +inline fun Either.Companion.second(t2: T2): Either = EitherSecond(t2) /** * Will call [block] in case when [Either.t1] of [this] is not null @@ -63,3 +63,9 @@ inline fun > E.onSecond(crossinline block: (T2) -> Un t2 ?.let(block) return this } + +inline fun Any.either() = when (this) { + is T1 -> Either.first(this) + is T2 -> Either.second(this) + else -> error("Incorrect type of either argument $this") +}