I am investigating Functional Programming, namely Arrow-kt
with Kotlin
my use case is as follows:
I want to perform an Action
and return the associated Reaction
Both Action
and Reaction
have associated Side Effects
the sequence of events is
1). On accepting the Action
immediately tigger the associated Actions Side Effects
2). Perform the Action
and obtain the Reaction
3). Trigger the Reactions Side Effects
4). Return the Reaction
result.
Additional factors to take into account when the Action is requested to be performed
a). When the Action has never been performed; complete the entire sequence, e.g. steps 1 - 4.
b). When the Action
is being performed; short circuit the sequence so that steps 2 - 4 are not completed
c). When the Action
has completed; short circuit steps 1 - 3 and return the Reaction
result
The Side Effects mentioned above include Logging
, Analytics
, and User Interface
effects.
I've a feeling that my requirement that the Action
and Reaction
Side Effects are triggered immediately means that a Functional Programming solution is not appropriate for my use case
The Arrow-kt
presentations and blogs I have found describe how Either
can be used to short circuit sequences based on Error Conditions being raised or using Option
with Some
and None
to achieve the same type of behaviour.
What I am having difficulty with
i). is where to start????
ii). with four steps to complete, how to control/manage "short circuiting" so that either steps 1 - 4, just step 1, or just step 4 is completed
Is it possible to achieve the desired behaviour using Functional Programming?