This question is closely related to the problem of zero crossings.
Suppose I have a list l = {-1, -1, 0, 1, 0, 0, -1, -1, 1, 1, 1, 0, 0, 0, -1}
and I want to replace the zeros with the previous nonzero value, like this:
{-1, -1, -1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, -1}
A rather clunky way to do this is with:
f = TimeSeries[l /. 0 -> Missing[],
MissingDataMethod -> {"Interpolation", InterpolationOrder -> 0}]
Then indeed f[-1 + Range@Length@l]
gives the required result.
However, there must be a more elegant way to achieve same, with patterns.
Can anyone supply a suggestion?