{"id":16207934,"url":"https://github.com/applejag/typ","last_synced_at":"2025-03-19T08:30:38.974Z","repository":{"id":40557836,"uuid":"450933809","full_name":"applejag/typ","owner":"applejag","description":"Generic types and functions that are missing from Go, including sets, linked lists, trees, etc. ","archived":false,"fork":false,"pushed_at":"2025-02-19T12:06:08.000Z","size":326,"stargazers_count":32,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-16T01:00:23.319Z","etag":null,"topics":["go","go-generics","go-lib","go-library","go118","golang"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/gopkg.in/typ.v4","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/applejag.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-22T20:57:14.000Z","updated_at":"2025-02-19T12:05:56.000Z","dependencies_parsed_at":"2024-10-27T20:25:06.693Z","dependency_job_id":"e0119a32-3747-4800-b30a-8f41dc31bc85","html_url":"https://github.com/applejag/typ","commit_stats":null,"previous_names":["applejag/typ"],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/applejag%2Ftyp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/applejag%2Ftyp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/applejag%2Ftyp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/applejag%2Ftyp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/applejag","download_url":"https://codeload.github.com/applejag/typ/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243976461,"owners_count":20377691,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","go-generics","go-lib","go-library","go118","golang"],"created_at":"2024-10-10T10:14:50.696Z","updated_at":"2025-03-19T08:30:37.994Z","avatar_url":"https://github.com/applejag.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!--\nSPDX-FileCopyrightText: 2022 Kalle Fagerberg\n\nSPDX-License-Identifier: CC-BY-4.0\n--\u003e\n\n# go-typ\n\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/6b0289f204c044c2911a53c67a4833d9)](https://app.codacy.com/gh/go-typ/typ?utm_source=github.com\\\u0026utm_medium=referral\\\u0026utm_content=go-typ/typ\\\u0026utm_campaign=Badge_Grade_Settings)\n[![REUSE status](https://api.reuse.software/badge/github.com/go-typ/typ)](https://api.reuse.software/info/github.com/go-typ/typ)\n[![Go Reference](https://pkg.go.dev/badge/gopkg.in/typ.v4.svg)](https://pkg.go.dev/gopkg.in/typ.v4)\n\nGeneric types and functions that are missing from Go, including sets, trees,\nlinked lists, etc.\n\nAll code is implemented with 0 dependencies and in pure Go code (no CGo).\n\n## Background\n\nGo v1.18 is about to be released now in February 2022, and with it comes some\nfeatures that has been talked about for a really long time. One of which being\n**generics!** [(Go 1.18 beta release notes)](https://tip.golang.org/doc/go1.18)\n\nThey have moved generics from the Go v2.0 milestone over to Go v1.18, which\nmeans they have to stay backwards compatible and cannot alter any existing\ntypes. On top of this, they do not seem to plan on releasing any generic data\ntypes in the Go standard library until Go v1.19. All in all, to use generic\ndata types with Go v1.18, you'll have to either write your own, or use a\nthird-party package, like this one :)\n\nThis repository includes those generic functions and types that I find are\nmissing from the release of Go v1.18-beta1, as well as a number of other\ndata structures and utility functions I think should've been included in the\nstandard library a long time ago. But now with generics, we can finally have\nsensible implementations of sets, trees, stacks, etc without excessive casting.\n\n## Compatibility\n\nRequires Go v1.18rc1 or later as the code makes heavy use of generics.\n\n## Installation and usage\n\n```sh\ngo get -u gopkg.in/typ.v4\n```\n\n```go\nimport (\n\t\"fmt\"\n\n\t\"gopkg.in/typ.v4/avl\"\n\t\"gopkg.in/typ.v4/maps\"\n)\n\nfunc UsingSets() {\n\tset1 := make(maps.Set[string])\n\tset1.Add(\"A\")\n\tset1.Add(\"B\")\n\tset1.Add(\"C\")\n\tfmt.Println(\"set1:\", set1) // {A B C}\n\n\tset2 := make(maps.Set[string])\n\tset2.Add(\"B\")\n\tset2.Add(\"C\")\n\tset2.Add(\"D\")\n\tfmt.Println(\"set2:\", set2) // {B C D}\n\n\tfmt.Println(\"union:\", set1.Union(set2))         // {A B C D}\n\tfmt.Println(\"intersect:\", set1.Intersect(set2)) // {B C}\n\tfmt.Println(\"set diff:\", set1.SetDiff(set2))    // {A}\n\tfmt.Println(\"sym diff:\", set1.SymDiff(set2))    // {A D}\n}\n\nfunc UsingAVLTree() {\n\ttree := avl.NewOrdered[string]()\n\n\t// Unordered input\n\ttree.Add(\"E\")\n\ttree.Add(\"B\")\n\ttree.Add(\"D\")\n\ttree.Add(\"C\")\n\ttree.Add(\"A\")\n\n\t// Sorted output\n\tfmt.Println(tree.Len(), tree) // 5 [A B C D E]\n}\n```\n\n## Features\n\n\u003c!-- lint disable maximum-line-length --\u003e\n\n- `gopkg.in/typ.v4/arrays`:\n\n  - `arrays.Array2D[T]`: 2-dimensional array.\n\n- `gopkg.in/typ.v4/sync2`:\n\n  - `sync2.AtomicValue[T]`: Atomic value store, wrapper around [`sync/atomic.Value`](https://pkg.go.dev/sync/atomic#Value).\n  - `sync2.KeyedMutex[T]`: Mutual exclusive lock on a per-key basis.\n  - `sync2.KeyedRWMutex[T]`: Mutual exclusive reader/writer lock on a per-key basis.\n  - `sync2.Map[K,V]`: Concurrent map, forked from [`sync.Map`](https://pkg.go.dev/sync#Map).\n  - `sync2.Set[V]`: Concurrent set, based on `sync2.Map`.\n  - `sync2.Once1[R1]`: Run action once, and tracks return values, wrapper around [`sync.Once`](https://pkg.go.dev/sync#Once).\n  - `sync2.Once2[R1,R2]`: Run action once, and tracks return values, wrapper around [`sync.Once`](https://pkg.go.dev/sync#Once).\n  - `sync2.Once3[R1,R2,R3]`: Run action once, and tracks return values, wrapper around [`sync.Once`](https://pkg.go.dev/sync#Once).\n  - `sync2.Pool[T]`: Object pool, wrapper around [`sync.Pool`](https://pkg.go.dev/sync#Pool).\n\n- `gopkg.in/typ.v4/lists`:\n\n  - `lists.List[T]`: Linked list, forked from [`container/list`](https://pkg.go.dev/container/list).\n  - `lists.Queue[T]`: First-in-first-out collection.\n  - `lists.Ring[T]`: Circular list, forked from [`container/ring`](https://pkg.go.dev/container/ring).\n  - `lists.Stack[T]`: First-in-last-out collection.\n\n- `gopkg.in/typ.v4/avl`:\n\n  - `avl.Tree[T]`: AVL-tree (auto-balancing binary search tree) implementation.\n\n- `gopkg.in/typ.v4/chans`:\n\n  - `chans.PubSub[T]`: Publish-subscribe pattern using channels.\n\n- `gopkg.in/typ.v4/maps`:\n\n  - `maps.Bimap[K,V]`: Bi-directional map.\n  - `maps.Set[V]`: Set of distinct values, based on set theory.\n\n- `gopkg.in/typ.v4/sets`:\n\n  - `sets.Set[T]`: Generic set interface, implemented by `sync2.Set` and `maps.Set`\n\n- `gopkg.in/typ.v4/slices`:\n\n  - `slices.Sorted[T]`: Always-sorted slice. Requires custom `less` function.\n\n\u003c!-- lint enable maximum-line-length --\u003e\n\n\u003e Explanation:\n\u003e\n\u003e - Forked type: Copied their code and modified it so it uses generic types down\n\u003e   to the backing struct layer. This benefits the most from generics support.\n\u003e\n\u003e - Wrapped type: Code depends on the underlying non-generic type, and adds\n\u003e   abstraction to hide the type casting. Less performant than full generic\n\u003e   support, but is done to reduce excessive complexity in this repository.\n\u003e\n\u003e - Neither forked nor wrapped: Original code written by yours truly.\n\n## Development\n\nPlease read the [CONTRIBUTING.md](CONTRIBUTING.md) for information about\ndevelopment environment and guidelines.\n\n## Similar projects\n\nAll the below include multiple data structure implementations each, all with\nGo 1.18 generics support.\n\n- \u003chttps://github.com/zyedidia/generic\u003e: An experimental collection of generic\n  data structures written in Go.\n\n- \u003chttps://github.com/marstr/collection\u003e: Generic Golang implementation of a few\n  basic data structures.\n\n- \u003chttps://github.com/Kytabyte/go2-generic-containers\u003e: Some container data\n  structures written in the next generation of Golang with generics.\n\n- \u003chttps://github.com/tomyl/collection\u003e: Generic data structures for Go.\n\n- \u003chttps://github.com/gabstv/container\u003e: Generic data structures now that\n  Go 1.18+ supports generics.\n\n- \u003chttps://github.com/go-generics/collections\u003e: Go generic collections\n\n- \u003chttps://github.com/golang-design/go2generics\u003e: 🧪 A chunk of experiments and\n  demos about Go 2 generics design (type parameter \u0026 type set)\n\nOfficial Go packages:\n\n- [`golang.org/x/exp/constraints`](https://pkg.go.dev/golang.org/x/exp/constraints):\n  Constraints that are useful for generic code, such as constraints.Ordered.\n\n- [`golang.org/x/exp/maps`](https://pkg.go.dev/golang.org/x/exp/maps):\n  A collection of generic functions that operate on slices of any element type.\n\n- [`golang.org/x/exp/slices`](https://pkg.go.dev/golang.org/x/exp/slices):\n  A collection of generic functions that operate on maps of any key or element\n  type.\n\n## License\n\nThis project is primarily licensed under the MIT license:\n\n- My Go code in this project is licensed under the MIT license:\n  [LICENSES/MIT.txt](LICENSES/MIT.txt)\n\n- Some Go code in this project is forked from Go's source code, which is\n  licensed under the 3-Clause BSD license: [LICENSES/BSD-3-Clause.txt](LICENSES/BSD-3-Clause.txt)\n\n- Documentation is licensed under the Creative Commons Attribution 4.0\n  International (CC-BY-4.0) license: [LICENSES](LICENSES/CC-BY-4.0.txt)\n\n- Miscellanious files are licensed under the Creative Commons Zero Universal\n  license (CC0-1.0): [LICENSES](LICENSES/CC0-1.0.txt)\n\n- GitHub Action for REUSE linting (and not any of go-typ's code) is licensed\n  under GNU General Public License 3.0 or later (GPL-3.0-or-later):\n  [LICENSES/GPL-3.0-or-later.txt](LICENSES/GPL-3.0-or-later.txt)\n\nCopyright © Kalle Fagerberg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapplejag%2Ftyp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapplejag%2Ftyp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapplejag%2Ftyp/lists"}