Skip to content

Add kotlin compiler plugin to generate helpers and schemas #58

@IlyaGulya

Description

@IlyaGulya

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions