diff options
author | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2022-04-07 21:36:40 +0300 |
---|---|---|
committer | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2022-04-07 21:36:40 +0300 |
commit | 9cd6b0fca87679e570fbdd4942e3068feb3439fa (patch) | |
tree | 557bf877d71854480f4171e9dd324cebb5606056 /stack.go |
initial
Diffstat (limited to 'stack.go')
-rw-r--r-- | stack.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/stack.go b/stack.go new file mode 100644 index 0000000..7908c98 --- /dev/null +++ b/stack.go @@ -0,0 +1,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] +} |