Skip to content

Instantly share code, notes, and snippets.

@anfederico
Created April 24, 2019 03:02
Show Gist options
  • Save anfederico/2f92d3c36f4c887f00998641484dc6e7 to your computer and use it in GitHub Desktop.
Save anfederico/2f92d3c36f4c887f00998641484dc6e7 to your computer and use it in GitHub Desktop.
A push/pop capable vector in R
library(R6)
pvector <- R6Class("pvector", list(
values = NULL,
initialize = function(values=c()) {
self$values <- values
},
pop = function() {
if (length(self$values) > 0) {
popped.value <- self$values[1]
self$values <- self$values[-1]
return(popped.value)
}
},
push = function(pushed.values) {
self$values <- c(self$values, pushed.values)
}
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment