haskellfrpnetwire

Is there a netwire equivalent of stepper?


Reactive-banana has a function named stepper (of type MonadMoment m => a -> Event a -> m (Behavior a)), which converts an event into a behaviour where the behaviour's value is the value of the last event, or the initial value if no event has occurred yet.

In a talk by Conal Elliott, the name of which I cannot remember, he presents this as being one of the fundamental operations on events and behaviours. However, I cannot find a similar function in netwire. With my limited understanding of netwire, I would expect it to have type:

a -> Wire s e m (Event a) a


Solution

  • The function I was looking for is called hold, in Control.Wire.Interval.

    This does not need an initial value, because the wire inhibits until the first event is received. If this behaviour is needed, it can be implemented like so

    stepper init = hold <|> pure init