package com.laseroptek.raman.data.model

/**
 * A generic class that holds a value or an exception
 */
sealed class SerialResult<out R> {
    data class Success<out T>(val data: T) : SerialResult<T>()
    data class Error(val exception: Exception) : SerialResult<Nothing>()
    //data class Loading<out T>(val isLoading: Boolean) : SerialResult<T>()
}

fun <T> SerialResult<T>.successOr(fallback: T): T {
    return (this as? SerialResult.Success<T>)?.data ?: fallback
}
