Description Usage Arguments Details Value Author(s) Examples
Functions to create and manipulate counters.
1 2 3 |
start |
counter starting value. |
x |
counter stored value. |
step |
value to increment/decrement from the counter stored value. |
A counter is a function that takes another function as an argument. When no function is supplied, the counter just returns its stored value.
The increment and decrement functions are provided because they are the most likely to be of any use, but any function may be used.
Copied counters created from the same original countre share the same stored value. This may be used to share states between objects.
A counter returns its value when called without any argument, or the return value of the supplied function applied to the stored value.
Antoine Filipovic Pierucci
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | # counter creation
counter <- makeCounter()
# return stored value
counter()
# incrementing/decrementing
counter(increment)
counter(increment, 5)
counter(decrement, 2)
# arbitrary function
counter(function(x) x * x)
# shared memory
counter2 <- counter
counter()
counter2(increment)
counter()
# starting value may be anything
counter3 <- makeCounter(start = "a")
counter3()
counter3(function(x) c(x, "b"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.