This is a commonly recurring pattern. Here is a walk through of a nice
solution to this:
*Step 1. Create the types to give richer meaning to updates*
abstract Action # optional
immutable Update <: Action
val
end
immutable Reset <: Action end
# ... many more such action types can be added as and when required...
*Step 2. Define an combine function which does the right thing given
different kinds of updates*
combine(prev, u::Update) = max(prev, u.val)
combine(prev, ::Reset) = 0.0
# ... can add more as you create Action types
*Step 3. Merge signals of actions*
You will need to create a single source of Signal{Action} using merge
Say you have a reset_btn_clicks (probably coming from a button labeled
"Reset"), you can merge them
updates = map(Update, x)
resets = map(_ -> Reset, reset_btn_clicks)
actions = merge(updates, resets)
*Step 4. use foldp*
peak_x = foldp(combine, actions)
now display/plot peak_x.
The benefit of this approach is it is extensible and makes your code easy
to understand. You can add functionality by simply defining new Action
type, a combine method to update previous state, and finally adding it to
the merged signal of actions.
On Wed, May 4, 2016 at 10:18 PM, Achu <[email protected]> wrote:
> Hi
>
> I have a signal x Signal{Float64} and I have this other signal that
> defined by peak_x=foldp(max,0.0,x). Is there a way for me to reinitialize
> peak_x
> back to 0?
>
> Thanks!
> Achu
>