collection/stack.go

13 lines
283 B
Go
Raw Normal View History

2022-04-07 21:36:40 +03:00
package collection
func Push[T any](collection []T, element T) []T {
return append(collection, element)
}
func Pop[T any](collection []T) ([]T, T) {
if len(collection) == 0 {
return collection, *new(T)
}
return collection[:len(collection)-1], collection[len(collection)-1]
}