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

Why not foldp? #85

Open
yakir12 opened this issue May 3, 2022 · 0 comments
Open

Why not foldp? #85

yakir12 opened this issue May 3, 2022 · 0 comments

Comments

@yakir12
Copy link

yakir12 commented May 3, 2022

In Reactive there's foldp which is useful for accumulating state over updates (https://juliagizmos.github.io/Reactive.jl/#maintaining-state). I found it pretty useful. Right now I accomplish this with:

u = Observable(0)
oldu = Ref(u[])
p = Observable(0)
map!(p, u) do newu
  s = oldu[] + newu
  oldu[] = newu
  p[] + s
end

which seems a bit cumbersome considering what it could be:

p = foldp(+, u)
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

1 participant