Skip to content

Multiplatform (JVM, JS) Kotlin DSL for FSM (finite state machine)

License

Notifications You must be signed in to change notification settings

tomoya0x00/statek

Repository files navigation

statek

Maven Version

Multiplatform (JVM, JS, iOS Kotlin/Native) Kotlin DSL for FSM (finite state machine)

Some samples:

stateMachine(initial = MyState.NOT_LOANED) {
   state(MyState.NOT_LOANED) {
       edge<MyEvent.PressRental>(MyState.LOCK)
   }
   state(MyState.ON_LOAN, entry = { /* LED ON */ }, exit = { /* LED OFF */ }) {
       state(MyState.LOCK) {
           edge<MyEvent.PressUnLock>(MyState.UNLOCK)
           edge<MyEvent.PressLock>(MyState.NOT_LOANED, guard = { it.isLongPress })
       }
       state(MyState.UNLOCK) {
           edge<MyEvent.PressLock>(MyState.LOCK, guard = { !it.isLongPress })
       }
   }
}

for more details, please see FsmTest

Usage with gradle:

repositories {
    mavenCentral()
}

def statekVersion = "0.5.0"

// For multiplatform projects
implementation "io.github.tomoya0x00:statek:$statekVersion"

// For jvm projects
implementation "io.github.tomoya0x00:statek-jvm:$statekVersion"

About

Multiplatform (JVM, JS) Kotlin DSL for FSM (finite state machine)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages