tim
09/24/2020, 8:16 AMdata class State(val foo: Int = 1)
typealias NextState = State
// ...
val action = Action.Ping()
val next: NextState = state
.dispatch(action)
.save()
// Now maybe i'll grab a value off of next to send back to the user if that makes sense in the current context
//...
So this approach works fine, but I'm finding an increasing number of use cases where I want to return NextState and a Result. And I'd appreciate any feedback on what others think is a good way to handle this or a call out if my approach is bonkers ... still new to FP 🙂
I'm considering two approaches to achieve the above:
• fun <T> dispatch(action: Action): Either<Failure, Tuple2<NextState, T>>
• fun dispatch(action: Action): Either<Failure, NextState>
In this approach I modify State to have non-serialised var that holds the return value: data class State(val foo: Int = 1, var result: Option<Any> = None) { fun <T> getResult(): Option<T> }
Is there a better way of doing this, is there a preferred approach, is this sound? Any thoughts welcome.PHaroZ
09/24/2020, 8:22 AMtim
09/24/2020, 8:23 AMtim
09/24/2020, 8:23 AMPHaroZ
09/24/2020, 8:26 AMPHaroZ
09/24/2020, 8:27 AMtim
09/24/2020, 8:48 AMtim
09/24/2020, 8:49 AMtim
09/24/2020, 8:49 AMPHaroZ
09/24/2020, 8:52 AMtim
09/24/2020, 8:53 AMPHaroZ
09/24/2020, 8:56 AMPHaroZ
09/24/2020, 8:58 AMtim
09/24/2020, 8:59 AMtim
09/24/2020, 9:00 AMtim
09/24/2020, 9:00 AMtim
09/24/2020, 9:01 AMScott Christopher
09/25/2020, 3:59 AMScott Christopher
09/25/2020, 4:04 AMdata class Moore<Input, State>(val state: State, val handler: (Input) -> State)
Scott Christopher
09/25/2020, 4:05 AMScott Christopher
09/25/2020, 4:05 AMtim
09/27/2020, 8:25 AMtim
09/27/2020, 8:25 AM