SupR_supplement {base} | R Documentation |
SupR supplementary functions are intended to provide a set of user-friendly tools.
iterator(has.next, get.next, env=parent.frame()) as.iterator(x, env=parent.frame()) has.next(iter, ...) get.next(iter, ...) implicit(class, fun=NULL)
has.next |
a 'function'. |
get.next |
a 'function', which returns the next value. |
env |
an 'environment', in which 'has.next' and 'get.next' function calls are made. |
iter |
an 'iterator'. |
class |
a 'character' as the class name. |
iter |
an 'iterator'. |
x |
a 'vector'. |
fun |
a function name or object. |
Iterators are used to represent a collection of values that can be obtained with a sequence of function calls. They consist of an environment and two functions, named 'has.next' and 'get.next'. The '$has.next()' call, evaluated in the enviroment, returns TRUE if there are more values available and FALSE otherwise. After a '$has.next()' call returns TRUE, the '$get.next()' call, evaluated in the same enviroment, returns the next available value.
'iterator' makes use of the arguments to create an iterator object.
'as.iterator' is generic. It makes use of the arguments to create an iterator object.
'has.next' and 'get.next' are user interfaces to call the corresponding 'has.next' and 'get.next' functions of the argument 'iter', which must be an 'iterator'.
'implicit' associates non-function objects of the specified class with an anonymous function so that the associated function can be called with non-function objects of the class.
'iterator' and 'as.iterator' return an iterator object.
'has.next' returns TRUE if there are more values available in the iterator object 'iter' and FALSE otherwise.
'get.next' returns the next value if a 'has.next' call has been made to inform that there are more values available, and signals an error otherwise. // FIXME
'implicit(class, fun = NULL)' returns the function associated with the specified class.
'implicit(class, fun = "remove")' removes the function associated with the specified class.
'implicit()' returns the list of the associated classes.
More functions may be added later ...
Chuanhai Liu, ...
http://www.stat.purdue.edu/~chuanhai/SupR
'map.reduce' 'start.master', 'start.worker', 'start.driver', ...
# default implicit function for numeric objects 100(1000) # list all the current implicit functions implicit() # create an iterator object to iterate from 1 to 10 iter = as.iterator(1:10) while(has.next(iter)) print(get.next(iter)) # define a default implicit function to apply a function to # values of iterator objects implicit("iterator", function(iter, fun){ while(has.next(iter)) fun(get.next(iter)) }) # apply the print function to each of the components of 1:5 as.iterator(1:5)(print)