Skip to content

request: sample to get return value of eval #14

@tateisu

Description

@tateisu

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))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy