package com.zaojiao.app.data.model

sealed class Result {
    data class Success<T>(
        val data: T,
    ) : Result()

    data class Failure(
        val throwable: Throwable,
    ) : Result()
}

inline fun <T> Result.onSuccess(callback: (T) -> Unit): Result {
    if (this is Result.Success<*>) {
        callback(data as T)
    }

    return this
}

inline fun Result.onFailure(callback: (Throwable) -> Unit): Result {
    if (this is Result.Failure) {
        callback(throwable)
    }

    return this
}