summaryrefslogblamecommitdiff
path: root/stack.go
blob: 7908c98b0480026ad349a7b333f2634a58f92178 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12











                                                                            
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]
}