I’m looking for some example of arrow `State` I h...
# arrow
e
I’m looking for some example of arrow
State
I have an object (
Customer
) that has his current status as a enum val , I wanna model the posible change from a state to next (as in a state machine pending->...-> review —> onaboarded) and I think using this type is the right way but can’t find a good example
s
So you want to model state transitions? Something like this? https://typelevel.org/cats/datatypes/state.html#changing-states I wrote
IndexedState
like 3 years ago, but there were some issues at the time with the Compiler. It would probably be possible today, but I haven't gone back to it due to other priorities. There is still a outdated branch of it 😅 https://github.com/arrow-kt/arrow-core/tree/simon-indexedstatet
o
What about https://arrow-kt.io/docs/arrow/ui/moore/ - isn't that some sort of minimal state-machine?
e
Thanks a lot! My question started after reading about the State and StateT datatypes of arrow but the problem here is that neither me or my team are strong with some "advanced" (for us) arrow datatypes, etc. We use massively Either and ADTs etc. but to be honest, I was trying to read and understand (understand to the point to be able to explain and justify to the team to use these) and, well, I don't fell I can... (sure my fault) So I have one more question: Having an immutable class, with a property keeping the current status of the class as an enum, and just assuring that the class change that property on a "state" transition is not enough? what does that datatypes add to this simple solution:
Copy code
data class Customer(val status: CustomerStatus)
enum class CustomerStatus{INIT, PENDING, ONBOARDED}
fun Customer.onBoard(): Either<TransitionError,Customer> { 
  // will check invariants and change Customer to status=ONBOARDED
}
Thanks a lot!
o
I'm also just starting my journey, so my answer was really a question. Where I work, I introduced a state-machine open-sourced by Tinder - but I'd love to read an anwer to your question, too! 🙂 It seems like the next logical step for me after learning functional error handling / using ADTs. The only difference I see between Moore and your example is, that it is event-based. I don't know yet, what comonadic means. 😞