commonMain.it.unibo.tuprolog.theory.RetractResult.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of theory-jvm Show documentation
Show all versions of theory-jvm Show documentation
In-memory storage and indexing facilities for ordered and unordered knowledge bases composed by logic clauses
package it.unibo.tuprolog.theory
import it.unibo.tuprolog.core.Clause
import kotlin.js.JsName
/** A result given after a "retract" operation */
sealed class RetractResult {
open val isSuccess: Boolean
get() = false
open val isFailure: Boolean
get() = false
/** The result always present value, is the clause database resulting from the operation execution */
@JsName("theory")
abstract val theory: T
@JsName("clauses")
abstract val clauses: Iterable?
/** Gets the first successfully retracted clause */
@JsName("firstClause")
abstract val firstClause: Clause?
/** A successful "retract" operation result, carrying the new [theory] and removed [clauses] */
data class Success(
override val theory: T,
override val clauses: Iterable,
) : RetractResult() {
override val isSuccess: Boolean
get() = true
override val firstClause: Clause
get() = clauses.first()
}
/** A failed "retract" operation result, carrying the unchanged [theory] */
data class Failure(override val theory: T) : RetractResult() {
override val isFailure: Boolean
get() = true
override val clauses: Nothing?
get() = null
override val firstClause: Nothing?
get() = null
}
}