https://github.com/object88/immutable
Experimental: Golang library for immutable collections
https://github.com/object88/immutable
Last synced: 3 months ago
JSON representation
Experimental: Golang library for immutable collections
- Host: GitHub
- URL: https://github.com/object88/immutable
- Owner: object88
- Created: 2017-01-03T19:20:21.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-14T22:54:18.000Z (over 9 years ago)
- Last Synced: 2025-04-06T03:42:34.210Z (about 1 year ago)
- Language: Go
- Size: 111 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- Roadmap: ROADMAP.md
Awesome Lists containing this project
README
# immutable
#### A Go / Golang library for immutable collections
_Note:_ This library is under development and is not meant for public consumption at this time.
[](https://travis-ci.org/object88/immutable) [](http://waffle.io/object88/immutable)
## Hashmap
The hashmap is a key-value pair collection based on Go's native map implementation.
### Methods
#### `Get(key Element) (result Element, ok bool, err error)`
The get method searches the collection for a key-value pair with the matching key, and returns the value.
If a `nil` pointer receiver is used, then an error is returned. Additionally, `result` is `nil` and `ok` is `false`.
If there is no matching key, then `result` is nil, `ok` is `false`, and `err` is `nil`.
If the key matches in the hash map, a valid value is returned (including `nil`), and `ok` is `true`.
#### `GetKeys() (results []Element, err error)`
The `GetKeys` method returns the collection of `Element` objects used to store values in the hashmap. If the hashmap is unassigned, `err` is non-`nil`, and if the hashmap does not have any contents, then a 0-length array is returned.
It is important to note that, just as the collection functions do not operate in any order, the `GetKeys` method will return the key collection in random order.
#### `Insert(key Element, value Element) (*InternalHashmap, error)`
The insert method creates a copy of the provided hashmap collection with the provided key-value pair added. The `key` may not be `nil`, but `value` may.
#### `Remove(key Element) (*InternalHashmap, error)`
The remove method creates a copy of the provided hashmap collection, with the entry at the specified key removed. If the method would result in no change, the same reference is returned.
## Common functions
Collections have some common functions for operations across the entire collection
#### `Filter`
#### `ForEach`
#### `Map`
#### `Reduce`
#### `Size() int`
The `size` method returns the number of key-value pairs in a collection.