Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request: sample to get return value of eval #14

Open
tateisu opened this issue Jan 30, 2022 · 0 comments
Open

request: sample to get return value of eval #14

tateisu opened this issue Jan 30, 2022 · 0 comments

Comments

@tateisu
Copy link

tateisu commented Jan 30, 2022

can you add sample to get return value of eval() ?

something like this:

val result : ResultWithDiagnostics<EvaluationResult> = eval(...)

result.castOrError<ResultWithDiagnostics.Success<EvaluationResult>> {
    "script evaluation failed. $it"
}.value.returnValue.castOrError<ResultValue.Value> {
    "script evaluation result is $it"
}.value.castOrError<AppConfig> { // your expected class for value
    "script returns value, but it's not AppConfig. ${it?.javaClass?.simpleName}"
}.let { config = it }

inline fun <reified T:Any> Any?.castOrError(noinline messageCreator:(Any?)->String) =
    (this as? T) ?: error(messageCreator(this))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant