Skip to content

Instantly share code, notes, and snippets.

@christlc
Created December 10, 2017 08:26
Show Gist options
  • Save christlc/30237941afa727867d6dea4789ec9132 to your computer and use it in GitHub Desktop.
Save christlc/30237941afa727867d6dea4789ec9132 to your computer and use it in GitHub Desktop.
Token cache closure
tokens_pool <- function(tokens){
current_count <- 1
list(get_next_token = function(){
current_count <<- current_count +1
if(current_count>length(tokens)){
current_count <<- 1
}
return(tokens[[current_count]])
},
get_current_token = function(){
return(tokens[[current_count]])
}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment