All Projects → ToxicBakery → Kfin State Machine

ToxicBakery / Kfin State Machine

Licence: apache-2.0
Kotlin Finite State Machine

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Kfin State Machine

State Machine Cat
write beautiful state charts 🙀
Stars: ✭ 509 (+1313.89%)
Mutual labels:  state-machine
Finite machine
A minimal finite state machine with a straightforward syntax.
Stars: ✭ 772 (+2044.44%)
Mutual labels:  state-machine
Cycle State Machine Demo
Non-trivial, real use case demo of a hierarchical state machine library with cyclejs
Stars: ✭ 25 (-30.56%)
Mutual labels:  state-machine
Sml
SML: C++14 State Machine Library
Stars: ✭ 540 (+1400%)
Mutual labels:  state-machine
Little State Machine
📠 React custom hook for persist state management
Stars: ✭ 654 (+1716.67%)
Mutual labels:  state-machine
Behaviortree.cpp
Behavior Trees Library in C++. Batteries included.
Stars: ✭ 793 (+2102.78%)
Mutual labels:  state-machine
Tinyfsm
A simple C++ finite state machine library
Stars: ✭ 452 (+1155.56%)
Mutual labels:  state-machine
Oqaml
An OCaml based implementation of a Quil QVM
Stars: ✭ 31 (-13.89%)
Mutual labels:  state-machine
Rxautomaton
🤖 RxSwift + State Machine, inspired by Redux and Elm.
Stars: ✭ 711 (+1875%)
Mutual labels:  state-machine
Perl Workflow
Simple, flexible system to implement workflows
Stars: ✭ 10 (-72.22%)
Mutual labels:  state-machine
Copycat
A novel implementation of the Raft consensus algorithm
Stars: ✭ 551 (+1430.56%)
Mutual labels:  state-machine
Django River
Django workflow library that supports on the fly changes ⛵
Stars: ✭ 609 (+1591.67%)
Mutual labels:  state-machine
State jacket
A simple & intuitive state machine
Stars: ✭ 5 (-86.11%)
Mutual labels:  state-machine
Automatonymous
A state machine library for .Net - 100% code - No doodleware
Stars: ✭ 516 (+1333.33%)
Mutual labels:  state-machine
Workflow
A Swift and Kotlin library for making composable state machines, and UIs driven by those state machines.
Stars: ✭ 860 (+2288.89%)
Mutual labels:  state-machine
Aasm
AASM - State machines for Ruby classes (plain Ruby, ActiveRecord, Mongoid, NoBrainer, Dynamoid)
Stars: ✭ 4,474 (+12327.78%)
Mutual labels:  state-machine
Stately.js
Stately.js is a JavaScript based finite-state machine (FSM) engine for Node.js and the browser.
Stars: ✭ 785 (+2080.56%)
Mutual labels:  state-machine
Mineflayer Statemachine
A state machine plugin for Mineflayer to aid in designing more complex behavior trees.
Stars: ✭ 32 (-11.11%)
Mutual labels:  state-machine
Rust fsm macros
FSM in Rust's macros.
Stars: ✭ 20 (-44.44%)
Mutual labels:  state-machine
Laravel Stager
Laravel Stager State Machine, Its purpose is to add state machine functionality to models
Stars: ✭ 16 (-55.56%)
Mutual labels:  state-machine

Kotlin Finite State Machine

CircleCI codecov Maven Central Maven Central
Kotlin library for creating finite state machines.

It is an abstract machine that can be in exactly one of a finite number of states at any given time. The FSM can change from one state to another in response to some external inputs; the change from one state to another is called a transition. An FSM is defined by a list of its states, its initial state, and the conditions for each transition.
Wikipedia - Finite-state machine

Sample Usage

sealed class Energy {
    object Kinetic : Energy()
    object Potential : Energy()
}

sealed class EnergyTransition {
    object Store : EnergyTransition()
    object Release : EnergyTransition()
}

val stateMachine = StateMachine(
        Potential,
        Potential onEvent Release::class resultsIn Kinetic,
        Kinetic onEvent Store::class resultsIn Potential
)

// Get the current state, will initially return `Potential`
machine.state

// Move the machine to `Kinetic`
machine.transition(Release)

Samples

Samples intend to show various ways the library might be used.

  • Dungeon - MUD style application allowing a player to explore a randomly generated dungeon
  • Stopwatch - Simple stopwatch that counts from zero at one second intervals until stopped.

Install

Kfin is now a Kotlin Multiplatform project supporting js, jvm, and jvmRx platforms.

kfin - includes base state machine implementation

compile "com.ToxicBakery.kfinstatemachine:kfin-<platform>:4.+"

Graph - includes directed graph implementation which can be used to create large state machines more easily

compile "com.ToxicBakery.kfinstatemachine:graph-<platform>:4.+"

Build

The library depends on gradle for compilation and requires JDK 8 or higher.

./gradlew build

Considerations

This library originally took a classical approach using a directed graph for state and callbacks for listening to state and transition changes. Thanks to a talk given by Ray Ryan from Square, I created an implementation generally following their state machine API and reworked my examples to fit. The exact slide can be found here and the talk in its whole is worth the watch.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].