https://github.com/lexzaiello/immutable-go
Straightforward, functional immutable data collections for Go.
https://github.com/lexzaiello/immutable-go
golang immutablejs
Last synced: 5 months ago
JSON representation
Straightforward, functional immutable data collections for Go.
- Host: GitHub
- URL: https://github.com/lexzaiello/immutable-go
- Owner: lexzaiello
- License: mit
- Created: 2019-10-18T16:09:53.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-10-22T01:35:23.000Z (over 6 years ago)
- Last Synced: 2025-07-23T12:49:51.212Z (6 months ago)
- Topics: golang, immutablejs
- Language: Go
- Homepage:
- Size: 23.4 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# immutable-go
Straightforward, functional immutable data collections for Go.
## Installation
```bash
go get -u github.com/dowlandaiello/immutable-go
```
## Lists
### Initialization
```go
import "github.com/dowlandaiello/immutable-go"
list := immutable.NewList(1, 2, 3, 4) // Initializes a new list of integers
```
### Getting Values
```go
import "github.com/dowlandaiello/immutable-go"
list := immutable.NewList(1, 2, 3, 4) // Initializes a new list of integers
firstElement := list(0) // Get the element at index 0
secondElement := list(1) // Get the element at index 1
...
```
### Setting Values
```go
import "github.com/dowlandaiello/immutable-go"
list := immutable.NewList(1, 2, 3, 4) // Initialize a new list of integers
newList := list.Set(0, 37) // Set the element at index 0 to 37
```
Or, push a value:
```go
import "github.com/dowlandaiello/immutable-go"
list := immutable.NewList(1, 2, 3, 4) // Initialize a new list of integers
newList := list.Push(102) // Push an integer with the value 102 to the list
```
Finally, pop a value:
```go
import "github.com/dowlandaiello/immutable-go"
list := immutable.NewList(1, 2, 3, 4) // Initialize a new list of integers
newList := list.Pop() // Remove an integer from the list
```
### Getting a List's Used Size
```go
import "github.com/dowlandaiello/immutable-go"
list := immutable.NewList(1, 2, 3, 4) // Initialize a new list of integers
length := list.Size() // Get the size of the list
```