datastructures
datastructures copied to clipboard
Stack is not type stable when inserting/popping list objects
The ability to insert a list and have the elements added individually is nice, however when pushing a list of length 1, the list is not unwrapped. This requires the user to detect length 1 lists and handle them specially which is surprising and cumbersome.
library(datastructures)
#> Loading required package: Rcpp
#>
#> Attaching package: 'datastructures'
#> The following object is masked from 'package:utils':
#>
#> stack
s1 <- stack()
s2 <- stack()
insert(s1, list("1"))
#> An object of class stack<SEXP>
#>
#> Peek: list, ...
pop(s1)
#> [[1]]
#> [1] "1"
# class list
insert(s2, list("1","2"))
#> An object of class stack<SEXP>
#>
#> Peek: character, ...
pop(s2)
#> [1] "2"
# class character
Created on 2019-05-15 by the reprex package (v0.2.1)