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

Add kotlin compiler plugin to generate helpers and schemas #58

Open
IlyaGulya opened this issue Oct 31, 2020 · 0 comments
Open

Add kotlin compiler plugin to generate helpers and schemas #58

IlyaGulya opened this issue Oct 31, 2020 · 0 comments

Comments

@IlyaGulya
Copy link

Current API is a bit cursed.
I'd really like to have an ability to treat Schemas as usual data classes.
At least, when I'm constructing or changing them.
For instance, compiler plugin can generate constructor functions, copy functions, etc.

object Player : Schema<Player>() {
    val Name = "name" let string
    val Surname = "surname" let string
    val Score = "score".mut(i32, default = 0)

    // Can be generated by compiler plugin
    operator fun invoke(
        name: String,
        surname: String,
        score: Int? = null
    ): StructSnapshot<Player> = Player { p ->
        p[Name] = "John"
        p[Surname] = "Galt"
        score?.let { p[Score] = it }
    }
}

// Can be generated by compiler plugin
fun StructSnapshot<Player>.copy(
    name: String? = null,
    surname: String? = null,
    score: Int? = null
): StructSnapshot<Player> = copy { p ->
    name?.let { p[Name] = name }
    surname?.let { p[Surname] = surname }
    score?.let { p[Score] = score }
}
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