diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/EitherTypeAdapter.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/EitherTypeAdapter.kt index dd34ffae..4a827759 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/EitherTypeAdapter.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/EitherTypeAdapter.kt @@ -13,7 +13,7 @@ import java.lang.reflect.ParameterizedType /** * При объявлении [Either] для (де)сериализации *НЕОБХОДИМО* объявить - * такое *левое* свойство, которое имеет [TypeAdapter] который не "засоряет" JsonReader + * такое *левое* свойство, которое имеет [TypeAdapter] который не "засоряет" [JsonReader] */ object EitherTypeAdapter : TypeAdapterFactory { override fun create(gson: Gson, type: TypeToken): TypeAdapter? { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/util/Either.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/util/Either.kt index 8f735733..ddc7c3d4 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/util/Either.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/util/Either.kt @@ -20,6 +20,13 @@ data class Either(val left: L?, val right: R?) { right.invoke(this.right!!) } + inline fun reduce(left: (L) -> T, right: (R) -> T): T { + return if (this.left != null) + left.invoke(this.left) + else + right.invoke(this.right!!) + } + companion object { @JvmStatic fun left(value: L): Either {