A library with a range of useful machines for simprokmachine framework.

Overview

simproktools

simproktools is a small library consisting of useful machines for simprokmachine framework.

Installation

Add this in your project's gradle file:

implementation 'com.github.simprok-dev:simproktools-kotlin:1.1.4'

and this in your settings.gradle file:

repositories {
    ...
    maven { url 'https://jitpack.io' }
}

BasicMachine

A machine with an injectable processing behavior.

val machine = BasicMachine<Input, Output>(dispatcher = Main /* or IO */) { input, callback ->
    // any processing logic
}

ProcessMachine

A machine with an injectable processing behavior over the injected object.

val obj: ObjectType = ...
val machine = ProcessMachine.create<ObjectType, Input, Output>(obj) { obj, input, callback ->
    // any processing logic
}

Works on the main thread.

JustMachine

A machine that emits the injected value when subscribed and every time input is received.

val machine = JustMachine<Input, Int>(0) // Int can be replaced with any type

Works on the main thread.

SingleMachine

A machine that emits the injected value when subscribed.

val machine = SingleMachine<Input, Int>(0) // Int can be replaced with any type

Works on the main thread.

ValueMachine

A machine that accepts a value as input and immediately emits it as output. When subscribed - emits null.

val machine = ValueMachine<Int>() // Int can be replaced with any type

Works on the main thread.

NeverMachine

A machine that when subscribed or receives input - ignores it, never emitting output.

val machine = NeverMachine<Input, Output>() 

Works on the main thread.

ReducerMachine

A machine that receives input, reduces it into state and emits it.

// Boolean and Int can be replaced with any types

val _ = ReducerMachine<Boolean, Int>(0) { state, value -> // Int and Boolean
    // return ReducerResult.Set(0) // 0 will be a new State and will be passed as output 
    // return ReducerResult.Skip() // state won't be changed and passed as output
}

ClassicMachine

A machine that receives input, reduces it into state and array of outputs that are emitted.

// Boolean, Unit, and Int can be replaced with any types

val _ = ClassicMachine<Boolean, Unit, Int>(
    ClassicResult<Boolean, Int>.set(false, outputs = 0, 1, 2) // initial state and initial outputs that are emitted when machine is subscribed to
) { state, event -> 
    ClassicResult<Boolean, Int>.set(true, outputs = 3, 4, 5) // new state `true` and outputs `3, 4, 5` 
}

Scan operator

Takes this and applies specific behavior. When parent machine sends new input, it is either reduced into new child state and sent to this or mapped into parent output and emitted back. When this sends new output, it is either reduced into new child state and sent back to this or mapped into parent output and emitted.

// All the types can be replaced with anything else.

val machine: Machine<Boolean, Int> = ...

val result: Machine<String, Unit> = machine.scan(true) { state, event -> 
    // event has either come from parent as input or from child as output.
    // output should either go to the parent as output or to the child as new input and state.
    
    // Return
    // ScanOutput<Unit, Boolean>.State(Bool) // when input has to be sent to the child machine AND state has to be changed.
    // ScanOutput<Unit, Boolean>.Event(Unit) // when output has to be sent to the parent machine.
    ...
}

ConnectableMachine

A machine for dynamic creation and connection of other machines.

val _ = ConnectableMachine<Input, Output, BasicConnection<Input, Output> /* or any class that conforms to Connection*/>(
    BasicConnection.create(/* machines for connection go here */)
) { connection, input -> 
    // Return
    // ConnectionType<Input, Output, BasicConnection<Input, Output>>.Reduce(BasicConnection<Input, Output>.create(/* machines for connection go here */)) // when we want to connect new array of machines
    // ConnectionType<Input, Output, BasicConnection<Input, Output>>.Inward() // when we want to pass input to the connected machines
}
You might also like...
The Okila server project uses the Spring boot framework and uses the Kotlin language

Okila-Server The Okila server project uses the Spring boot framework and uses the Kotlin language Format Response //The response successfully format

Ktor is an asynchronous framework for creating microservices, web applications and more.
Ktor is an asynchronous framework for creating microservices, web applications and more.

ktor-sample Ktor is an asynchronous framework for creating microservices, web applications and more. Written in Kotlin from the ground up. Application

Used to generate the template code of GetX framework
Used to generate the template code of GetX framework

Language: English | 中文简体 statement some fast code snippet prompt come from getx-snippets-intelliJ Description install Plugin effect Take a look at the

This project uses Quarkus, the Supersonic Subatomic Java Framework.

foodhouse Project This project uses Quarkus, the Supersonic Subatomic Java Framework. If you want to learn more about Quarkus, please visit its websit

A modular framework for building Discord bots in Kotlin using Kordex and Kord

Mik Bot A modular framework for building Discord bots in Kotlin using Kordex and Kord **If you are here for mikmusic, click here and there Deployment

Firebase Authentication plugin for Ktor framework.

Firebase Authentication is a Ktor plugin which verifies requests authorized by a Firebase Auth Id Token.

This project uses Quarkus, the Supersonic Subatomic Java Framework

api Project This project uses Quarkus, the Supersonic Subatomic Java Framework.

MaxonBank is a Kotlin + Spring Boot + Axon Framework application that supports opening, depositing to, and withdrawing from accounts.

MaxonBank MaxonBank is a Kotlin + Spring Boot + Axon Framework application that supports opening, depositing to, and withdrawing from accounts. The ap

Test Case Implementation From Nutrition-Framework
Test Case Implementation From Nutrition-Framework

Android Architecture Blueprints v2 Android Architecture Blueprints is a project to showcase different architectural approaches to developing Android a

Releases(1.1.4)
Owner
simprok
mobile development company
simprok
Andorid app which provides a bunch of useful Linux commands.

Linux Command Library for Android The app currently has 3203 manual pages, 1351 one-line scripts and a bunch of general terminal tips. It works 100% o

Simon Schubert 271 Dec 31, 2022
Some useful Android Kotlin utilities

Android-Kotlin-utilities Some useful Android Kotlin utilities Any PR are welcomed :) Please put your code in several files like this. it helps others

Kaaveh Mohamedi 6 Oct 12, 2021
Combine some useful exts in One place

Helper Extensions Extensions Combine some useful exts in One place Examples : this.errorMsg(msg = "Test error" , duration = 6000)

Mostafa Gad 0 Dec 31, 2021
Kotter - aims to be a relatively thin, declarative, Kotlin-idiomatic API that provides useful functionality for writing delightful console applications.

Kotter (a KOTlin TERminal library) aims to be a relatively thin, declarative, Kotlin-idiomatic API that provides useful functionality for writing delightful console applications.

Varabyte 348 Dec 21, 2022
🍓CookHelper - food social network. The Api and Websocket are based on Ktor framework. Dependency injection with Koin library.

CookHelper [ ?? Work in Progress ?? ] CookHelper is a cross-platform application that will allow you to cook a delicious dish from an existing recipe

Arthur 11 Nov 9, 2022
Jetpack Compose for Desktop and Web, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.

Jetpack Compose for Desktop and Web, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.

JetBrains 10k Jan 7, 2023
A Modern Kotlin-Ktor RESTful API example. Connects to a PostgreSQL database and uses Exposed framework for database operations.

kotlin-ktor-rest-api A Modern Kotlin-Ktor RESTful API example. Connects to a PostgreSQL database and uses Exposed framework for database operations. F

Selim Atasoy 32 Dec 20, 2022
an open source algorithmic trading framework written in Kotlin for anyone serious about algo-trading

Roboquant Roboquant is an algorithmic trading platform that is fast and flexible while at the same time strives to be easy to use. It is fully open so

Neural Layer 132 Jan 2, 2023
A simple MVI framework for Kotlin Multiplatform and Android

Orbit Multiplatform Get in touch What is Orbit Orbit is a Redux/MVI-like library - but without the baggage. It's so simple we think of it as MVVM+. Si

null 521 Jan 1, 2023
Consumer desktop from nutrition-framework API

About This Project (work-in-progress ?? ??️ ??‍♀️ ⛏ ) Consumer Dari Nutrition Framework General Framework for Application Development Around Nutrition

Faisal Amir 6 Dec 1, 2022