Add Stack ref class

This commit is contained in:
Winston Chang
2014-07-23 11:53:56 -05:00
parent f0942d58e8
commit a9bb440e6c
2 changed files with 29 additions and 0 deletions

View File

@@ -54,6 +54,7 @@ Collate:
'reactives.R'
'run-url.R'
'server.R'
'stack.R'
'shiny.R'
'shinyui.R'
'shinywrappers.R'

28
R/stack.R Normal file
View File

@@ -0,0 +1,28 @@
Stack <- setRefClass(
'Stack',
fields = list(
.stack = 'list'
),
methods = list(
push = function(obj) {
.stack <<- c(.stack, list(obj))
invisible(.self)
},
pop = function() {
len <- length(.stack)
if (len == 0)
return(NULL)
obj <- .stack[[len]]
.stack <<- .stack[-len]
obj
},
peek = function() {
len <- length(.stack)
if (len == 0) return(NULL)
.stack[[len]]
},
size = function() {
length(.stack)
}
)
)