package at.hannibal2.skyhanni.config.migration sealed interface LoadResult { fun map(mapper: (T?) -> V?): LoadResult { if (this is Instance) { return Instance(mapper(this.instance)) } return this as LoadResult } fun or(other: LoadResult<@UnsafeVariance T>): LoadResult data class Instance(val instance: T?) : LoadResult { override fun or(other: LoadResult): LoadResult { return this } } data class Failure(val exception: Throwable, val path: ResolutionPath) : LoadResult { override fun or(other: LoadResult): LoadResult { if (other is Invalid || other is Failure) return this return other } } object UseDefault : LoadResult { override fun or(other: LoadResult): LoadResult { if (other is Instance) return other return this } } object Invalid : LoadResult { override fun or(other: LoadResult): LoadResult { return other } } }