Simple State Machines in Kotlin (KSSM)

Overview

Simple State Machines in Kotlin (KSSM)

Workflow Status Code Size License Download Latest Release Codacy Grade

What is this?

KSSM (reordered: Kotlin - Simple State Machines) provides an easy and simple DSL (Domain Specific Language) for setting up finite-state machines, and opens a clean API with built-in threading and conflation mechanisms for manipulating states. This library does not solve all state machine problems, nor does it aim to address all possible use-cases related to state machines. It currently works only in the JVM environment.

KSSM is based on the Flow API from Kotlin's coroutine package, more precisely on State Flow.

Quick Intro

Here's a short introduction on how KSSM works. Click here to go at your own pace in presentation mode.

Intro

KSSM DSL looks like this (assuming actions and states are defined):

val sm = stateMachine {
  mappings(
    Heat moves Ice to Liquid,
    Chill moves Steam to Liquid,
    Drink moves Liquid to Empty,
    Fill moves Empty to Liquid
  )
  
  transitionsDispatcher = Dispatchers.Main // optional
  
  initialState = Empty // optional
  
  transitionHandler { println("Detected change: $it\n") } // optional
  errorHandler { err.println("Invalid request: $it\n") } // optional
  
  // other config...
}

// send inputs/actions to that instance
val job = sm.transition(Fill)
job.join() // or job.cancel(), or simply ignore

Wiki

If you prefer longer documentation, check out the longer version of the docs.

You want more? There are code samples in the demo directory that showcase the most interesting features of this library.

How to install KSSM?

It's hosted on JCenter and MavenCentral, and thus easy to depend upon with Gradle:

dependencies {
  // find the latest `$kssm_version` on the top of this page
  implementation "me.angrybyte:kssm:$kssm_version"
}

Contributing & Code of Conduct

Please open a new issue with any requests, issues, complaints or any other type of communication. For sensitive or security-related topics, don't hesitate to reach out to any maintainer directly.

You might also like...
This Project for how to use  MVVM , state flow, Retrofit, dagger hit, coroutine , use cases with Clean architecture.
This Project for how to use MVVM , state flow, Retrofit, dagger hit, coroutine , use cases with Clean architecture.

Clean-architecture This Project for how to use MVVM , state flow, Retrofit, dagger hit, coroutine , use cases with Clean architecture. Why i should us

RoomJetpackCompose is an app written in Kotlin and shows a simple solution to perform CRUD operations in the Room database using Kotlin Flow in clean architecture.
RoomJetpackCompose is an app written in Kotlin and shows a simple solution to perform CRUD operations in the Room database using Kotlin Flow in clean architecture.

RoomJetpackCompose is an app written in Kotlin and shows a simple solution to perform CRUD operations in the Room database using Kotlin Flow in clean architecture.

Simple and light-weight event dispatcher for Kotlin

KDispatcher is a Kotlin EventDispatcher This is light-weight event dispatcher based on KOTLIN priority: Int? = null to subscribe function for sorting

Nice and simple DSL for Espresso in Kotlin
Nice and simple DSL for Espresso in Kotlin

Kakao Nice and simple DSL for Espresso in Kotlin Introduction At Agoda, we have more than 1000 automated tests to ensure our application's quality and

A simple Kotlin wrapper around Anvil.

AnvilKotlin A simple Kotlin wrapper around Anvil. The only purpose of this library is to provide type safety to Anvil through Kotlin. Nothing more, no

A simple way to handle remote image in Kotlin.
A simple way to handle remote image in Kotlin.

Parrot A kotlin extension to load easily remote images in your ImageView. Install Add to gradle in allprojects maven { url 'https://jitpack.io' } the

Dead simple EventBus for Android made with Kotlin and RxJava 2

KBus Super lightweight (13 LOC) and minimalistic (post(), subscribe(), unsubscribe()) EventBus written with idiomatic Kotlin and RxJava 2 KBus in 3 st

A simple 'Slide to Unlock' Material widget for Android, written in Kotlin 📱🎨🦄
A simple 'Slide to Unlock' Material widget for Android, written in Kotlin 📱🎨🦄

Slide To Act A simple Slide to Unlock Material widget for Android, written in Kotlin 🇰. Getting Started Example Features Attributes area_margin inner

A simple demo that shows how WebWorkers can be used in Kotlin/JS

Web Workers in KotlinJS This repo demonstrates how to set up a Web Worker in Kotlin/JS. It is a very simple demo that creates a new worker that sends

Comments
  • Migrate to stable StateFlow

    Migrate to stable StateFlow

    StateFlow and SharedFlow are now stable, migrating should be easy.

    Release notes: https://blog.jetbrains.com/kotlin/2020/10/kotlinx-coroutines-1-4-0-introducing-stateflow-and-sharedflow/

    enhancement 
    opened by milosmns 0
Owner
Milos Marinkovic
Dealing with Software Systems and Processes
Milos Marinkovic
ConstraintSetChangesTest - Simple project showing Changes of ConstraintSet value as part of mutable state in JetpackCompose.

ConstraintSetChangesTest Simple project showing Changes of ConstraintSet value as part of mutable state in JetpackCompose. Version: implementation

Mateusz Perlak 1 Feb 13, 2022
Kotlin coroutine capable Finite-State Machine (multiplatform)

Comachine Features Kotlin corutines. Event handlers can launch coroutines for collecting external events of performing side effects. Structured concur

Sergej Shafarenka 22 Dec 14, 2022
Kotlin coroutine capable Finite-State Machine (multiplatform)

Comachine Features Kotlin corutines. Event handlers can launch coroutines for collecting external events of performing side effects. Structured concur

Sergej Shafarenka 22 Dec 14, 2022
Stresscraft - State-of-art Minecraft stressing software written in Kotlin

StressCraft (W.I.P) State-of-art Minecraft stressing software written in Kotlin.

Cubxity 57 Dec 4, 2022
ScopedState - Android Scoped State With Kotlin

Android Scoped State There is no need for complicated code - just define scopes

Ali Azizi 12 Jan 19, 2022
🔴 A non-deterministic finite-state machine for Android & JVM that won't let you down

HAL is a non-deterministic finite-state machine for Android & JVM built with Coroutines StateFlow and LiveData. Why non-deterministic? Because in a no

Adriel Café 73 Nov 28, 2022
💫 Small microservice to handle state changes of Kubernetes pods and post them to Instatus or Statuspages

?? Kanata Small microservice to handle state changes of Kubernetes pods and post them to Instatus or Statuspages ?? Why? I don't really want to implem

Noel 4 Mar 4, 2022
Basic app to use different type of observables StateFlow, Flow, SharedFlow, LiveData, State, Channel...

stateflow-flow-sharedflow-livedata Basic app to use different type of observables StateFlow, Flow, SharedFlow, LiveData, State, Channel... StateFlow,

Raheem 5 Dec 21, 2022
Advanced State in Jetpack Compose Codelab

Advanced State in Jetpack Compose Codelab This folder contains the source code for the Advanced State in Jetpack Compose Codelab codelab. The project

Carlos Barrios 1 May 12, 2022
Simplify mutating "immutable" state models

Mutekt (Pronunciation: /mjuːˈteɪt/, 'k' is silent) "Simplify mutating "immutable" state models" Generates mutable models from immutable model definiti

Shreyas Patil 179 Nov 30, 2022