Adetunji Dahunsi

Mutator

A tiny, multiplatform, redux-like library that makes it easy to transform streams of actions into streams of state

TJ Dahunsi

Feb 24 2022 ยท 1 min read

A Mutator is an abstract data type declaration of the form:

1interface Mutator<Action : Any, State : Any> { 2 val state: State 3 val accept: (Action) -> Unit 4}

where Action defines an input type that yields production of the State output type. In other words, a Mutator represents a production pipeline of State which may be altered by input of Action.

The unit of change for processing an Action into a new State is a Mutation, a data class hosting a lambda with the existing State as a receiver, that when invoked produces a new State.

1data class Mutation<T : Any>( 2 val mutate: T.() -> T 3)

The default implementation is the stateFlowMutator.

A sample app utilizing it (and coincidentally what this post was written with) can be found here:

.

Tags:
kmm
kmp

0