package com.kanawish.sample.mvi.intent interface Intent { fun reduce(oldState: T): T } /** * DSL function to help build intents from code blocks. * * NOTE: Magic of extension functions, (T)->T and T.()->T interchangeable. */ fun intent(block: T.() -> T) : Intent = object : Intent { override fun reduce(oldState: T): T = block(oldState) } /** * By delegating work to other models, repositories or services, we * end up with situations where we don't need to update our ModelStore * state until the delegated work completes. * * Use the `sideEffect {}` DSL function for those situations. */ fun sideEffect(block: T.() -> Unit) : Intent = object : Intent { override fun reduce(oldState: T): T = oldState.apply(block) }