Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shamsher31/gostack
gostack is heterogeneous stack which allows you to store any type of value.
https://github.com/shamsher31/gostack
golang package stack
Last synced: 4 days ago
JSON representation
gostack is heterogeneous stack which allows you to store any type of value.
- Host: GitHub
- URL: https://github.com/shamsher31/gostack
- Owner: shamsher31
- License: mit
- Created: 2016-02-29T06:42:01.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-07-14T10:58:21.000Z (over 8 years ago)
- Last Synced: 2024-06-20T08:18:55.420Z (5 months ago)
- Topics: golang, package, stack
- Language: Go
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: license
Awesome Lists containing this project
README
# gostack
[![Godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/shamsher31/gostack)
[![Build Status](https://travis-ci.org/shamsher31/gostack.svg)](https://travis-ci.org/shamsher31/gostack)
[![GitHub release](http://img.shields.io/github/release/shamsher31/gostack.svg?style=flat-square)](release)
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](license)This package implements heterogeneous stack which allows you to store any type of value
as compared to the built-in slice and maps which will only allow specific types. Its a thread safe so it works pretty well with multiple goroutines.### How to install
```go
go get github.com/shamsher31/gostack
```### How to use
```go
package mainimport (
"fmt"
"github.com/shamsher31/gostack"
)func main() {
// Declare new stack
var myStack stack.Stackfmt.Println("Stack is empty : ", myStack.IsEmpty())
//Push some elements of different types in Stack
myStack.Push(10)
myStack.Push([]string{"Shamsher", "Ansari"})
myStack.Push(13.5)
myStack.Push("My Awesome stack")fmt.Println("Elements of stack : ", myStack)
fmt.Println("Stack is empty : ", myStack.IsEmpty())
if myStack.IsEmpty() == false {
fmt.Println("Total elements in stack : ", myStack.Len())
}top, err := myStack.Top()
if err != nil {
fmt.Println(err)
}
fmt.Println("Top of the stack : ", top)elem, err := myStack.Pop()
if err != nil {
fmt.Println(err)
}
fmt.Println("Poped element : ", elem)
fmt.Println("Elements of stack : ", myStack)
}
```
### Why
This package is born while learning and experimenting with golang to understand how pointers, mutual exclusion locks and interface works together.### License
MIT © [Shamsher Ansari](https://github.com/shamsher31)