项目作者: dowlandaiello

项目描述 :
Straightforward, functional immutable data collections for Go.
高级语言: Go
项目地址: git://github.com/dowlandaiello/immutable-go.git
创建时间: 2019-10-18T16:09:53Z
项目社区:https://github.com/dowlandaiello/immutable-go

开源协议:MIT License

下载


immutable-go

Straightforward, functional immutable data collections for Go.

Installation

  1. go get -u github.com/dowlandaiello/immutable-go

Lists

Initialization

  1. import "github.com/dowlandaiello/immutable-go"
  2. list := immutable.NewList(1, 2, 3, 4) // Initializes a new list of integers

Getting Values

  1. import "github.com/dowlandaiello/immutable-go"
  2. list := immutable.NewList(1, 2, 3, 4) // Initializes a new list of integers
  3. firstElement := list(0) // Get the element at index 0
  4. secondElement := list(1) // Get the element at index 1
  5. ...

Setting Values

  1. import "github.com/dowlandaiello/immutable-go"
  2. list := immutable.NewList(1, 2, 3, 4) // Initialize a new list of integers
  3. newList := list.Set(0, 37) // Set the element at index 0 to 37

Or, push a value:

  1. import "github.com/dowlandaiello/immutable-go"
  2. list := immutable.NewList(1, 2, 3, 4) // Initialize a new list of integers
  3. newList := list.Push(102) // Push an integer with the value 102 to the list

Finally, pop a value:

  1. import "github.com/dowlandaiello/immutable-go"
  2. list := immutable.NewList(1, 2, 3, 4) // Initialize a new list of integers
  3. newList := list.Pop() // Remove an integer from the list

Getting a List’s Used Size

  1. import "github.com/dowlandaiello/immutable-go"
  2. list := immutable.NewList(1, 2, 3, 4) // Initialize a new list of integers
  3. length := list.Size() // Get the size of the list