The goal here is to build an Event that triggers whenever a Behavior changes under some observation.
To make it a bit more concrete, let's say I have:
- a
bFoo :: Behavior a, which I like to think it as a time-varied state. - a function
diffA :: a -> a -> Maybe bto tell whether certain part of value ofbFoohas been changed (together with a bit more info indicating what has changed, or leaving me some room for avoiding boolean blindness)
and now I want to build an Event eChanged :: Event b that triggers if and only if we have a Just _ coming out from diffA fooBefore fooAfter.
Here comes the problem: it seems the framework only allows you to look at one Behavior value at the Moment. So I don't have access two values to compare against each other. I've been looking at Reactive.Banana.Combinators but still doesn't have much idea about whether it's possible.
Few more bits and pieces in case those are helpful or spark any new ideas:
Event-based rather than Behavior-based?
The first thing I can think of is simply to allow myself to have access to more details:
bFoo is accumB-ed from an Event eUpdate, but eUpdate doesn't necessarily update anything. So yes, we do have access to eFoo :: Event a if we want to, but I want to avoid using it as I think it as an implementation detail of bFoo.
A Failed Attempt
My current attempt looks like:
networkDesc :: MomemtIO ()
networkDesc = do
...
foo <- valueB bFoo
let eChanged = filterJust $ fmap (diffA foo) eUpdate
...
This doesn't work as foo is not changed over time.
Last resort
My last resort is to reactimate on eFoo, do the comparison outside of the framework and feed result back into the network - sounds doable but that defeats the purpose of having this network to take care of all the logic.