I'm developing a functional reactive programming app, in Sodium FRP and Scala, with heavy GUI-based interaction. The challenge is to program the construction of a complex graph with FRP nodes -- event Stream
s and state Cell
s. The construction proceeds in order-dependent steps, with the created objects passed on to next steps. Several domain and UI modules are involved. The process is fragile and not very functional.
It seems that the State Monad (SM) could be a good functional alternative. Indeed, several SM applications are not dissimilar to construction of object graphs, eg: https://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad, or Breadth-First Search using State monad in Haskell. And yet, my search hasn't produced any uses of SM for objects construction or configuration.
Specifically, I plan to split the FRP graph into subgraphs, and for each define something like
case class ConfigureSubGraph {
inputA: Option[Stream[String]] = None
inputB: Option[Stream[String]] = None
inputC: Option[Cell[String]] = None
...
intermediateOutputs: Option[Cell[DomainEntities]] }
with the fields pre-initialised to None
. (Here, Cell
and Stream
are from SodiumFRP.) This would be "loaded" into a State Monad and incrementally configured.
Could a State Monad work for this? If yes, is there any implementation advice? If not, are there other functional approaches to construction of object graphs (not necessarily FRP)?