https://github.com/dowlandaiello/immutable-go
Straightforward, functional immutable data collections for Go.
https://github.com/dowlandaiello/immutable-go
golang immutablejs
Last synced: 10 months ago
JSON representation
Straightforward, functional immutable data collections for Go.
- Host: GitHub
- URL: https://github.com/dowlandaiello/immutable-go
- Owner: dowlandaiello
- 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-02-03T23:59:36.169Z (12 months ago)
- Topics: golang, immutablejs
- Language: Go
- Homepage:
- Size: 23.4 KB
- Stars: 1
- Watchers: 2
- 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
```