Skip to content

deotimedev/vision

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Jul 19, 2023
4cf790b · Jul 19, 2023

History

18 Commits
Mar 10, 2023
Jul 19, 2023
Mar 10, 2023
Jul 19, 2023
Jul 19, 2023
Mar 10, 2023
Mar 10, 2023
Mar 10, 2023
Mar 10, 2023

Repository files navigation

vision

Simple visitor pattern alternative

Vision Example:

sealed interface Exampleer {
    sealed interface Thing : Exampleer {
        object One : Thing
        object Two : Thing
    }
    object Other : Exampleer
    object Last : Exampleer
    object Special : Exampleer
}

data class ExampleData(
    var example1: Exampleer.Thing = Exampleer.Thing.One,
    var example2: Exampleer = Exampleer.Other,
    val exampleList: MutableList<Exampleer.Thing> = mutableListOf(),
    var innerExample: Inner = Inner()
) : Eyes<Exampleer> {
    override val sight = vision(::exampleList) + vision(::example1, ::example2) + eyesight(::innerExample)

    data class Inner(
        var innerExample: Exampleer = Exampleer.Special,
        var innerExample2: Exampleer = Exampleer.Special
    ) : Eyes<Exampleer> {
        override val sight = vision(::innerExample, ::innerExample2)
    }
}

fun main() {
    val example = ExampleData()
    val sight = example.sight
    sight.views().forEach {
        println(it.get())
        it.unlock<Exampleer.Thing> {
            it.set(Exampleer.Thing.Two)
        }
    }
}

About

Simple visitor pattern alternative

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages