Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to handle past or historic values #102

Open
sirinath opened this issue Jun 22, 2016 · 3 comments
Open

Add ability to handle past or historic values #102

sirinath opened this issue Jun 22, 2016 · 3 comments

Comments

@sirinath
Copy link

sirinath commented Jun 22, 2016

Can we have functionality to record history and retrieve it. E.g.

x = Signal(0)
xhist = history(skip(1, x), 10)
sma10 = skip(10, xhist) do a
   foldp(0, a) do b
      if len(b) >= 10 
         return (last(b, 1) - last(b, 10)) / 10
      elseif
         return last(b, 1) / 10
      end
      0
   end
end

Basicall what functions to deal with history:

  • history - record n historic values
  • last - retrieve ith historic value.
  • last - retrieve ith historic value. If a default is specified return the default value if not full.
  • skip - skip n initial values
  • take - takes only 1st n initial value and none after
@Non-Contradiction
Copy link

Actually you can make the record of a signal be a signal. For example, suppose x is a signal of number and X is a signal of vector which stores all the values of x, every time x is updated, X is updated correspondingly. Making all the things recordable is a waste of space and time, so I think explicitly recording things may be better if it is needed.

@sirinath
Copy link
Author

Yes. Don't record it in signal but provide something like history which records it.

@JobJob
Copy link
Member

JobJob commented May 7, 2017

Try this:

history(s::Signal) = foldp((hist,val)->push!(hist, val), eltype(s)[value(s)], s)

usage

a = Signal(1)
b = history(a)
@show value(b)
foreach(i->push!(a,i), 1:10)
@show value(b)

edited to add eltype(s)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants