{"id":28089180,"url":"https://github.com/sonirico/gozo","last_synced_at":"2025-05-13T12:54:34.225Z","repository":{"id":291150951,"uuid":"976756036","full_name":"sonirico/gozo","owner":"sonirico","description":"A practical Go toolkit with generic utilities for working with slices, maps, and functional programming primitives like Option and Result.","archived":false,"fork":false,"pushed_at":"2025-05-02T17:40:00.000Z","size":0,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-02T18:32:48.801Z","etag":null,"topics":["functional","generics","go","golang","maps","monads","programming","slices","toolkit","utils"],"latest_commit_sha":null,"homepage":"","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/sonirico.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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,"zenodo":null}},"created_at":"2025-05-02T17:32:52.000Z","updated_at":"2025-05-02T18:07:54.000Z","dependencies_parsed_at":"2025-05-02T18:47:57.678Z","dependency_job_id":null,"html_url":"https://github.com/sonirico/gozo","commit_stats":null,"previous_names":["sonirico/gozo"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonirico%2Fgozo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonirico%2Fgozo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonirico%2Fgozo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonirico%2Fgozo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sonirico","download_url":"https://codeload.github.com/sonirico/gozo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253948327,"owners_count":21988953,"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":["functional","generics","go","golang","maps","monads","programming","slices","toolkit","utils"],"created_at":"2025-05-13T12:54:33.716Z","updated_at":"2025-05-13T12:54:34.201Z","avatar_url":"https://github.com/sonirico.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# gozo\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/sonirico/gozo)](https://goreportcard.com/report/github.com/sonirico/gozo)\n[![Go Reference](https://pkg.go.dev/badge/github.com/sonirico/gozo.svg)](https://pkg.go.dev/github.com/sonirico/gozo)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n[![gozo Art](gozo.png)](https://github.com/sonirico/gozo/gozo.png)\n\nThe ultimate toolkit for Go developers. A comprehensive collection of functions, data structures, and utilities designed to enhance productivity and code quality.\n\n## Modules\n\n## \u003ca name=\"table-of-contents\"\u003e\u003c/a\u003eTable of Contents\n\n- [🪄 Fp](#fp)\n  - [Err](#err)\n  - [None](#none)\n  - [Ok](#ok)\n  - [OkZero](#okzero)\n  - [OptionFromPtr](#optionfromptr)\n  - [OptionFromTuple](#optionfromtuple)\n  - [OptionFromZero](#optionfromzero)\n  - [Some](#some)\n- [🗝️ Maps](#maps)\n  - [Equals](#equals)\n  - [Filter](#filter)\n  - [FilterInPlace](#filterinplace)\n  - [FilterMap](#filtermap)\n  - [FilterMapTuple](#filtermaptuple)\n  - [Fold](#fold)\n  - [Map](#map)\n  - [Reduce](#reduce)\n  - [Slice](#slice)\n- [⛓️ Slices](#slices)\n  - [All](#all)\n  - [Any](#any)\n  - [Append](#append)\n  - [AppendVector](#appendvector)\n  - [Contains](#contains)\n  - [Cut](#cut)\n  - [Delete](#delete)\n  - [DeleteOrder](#deleteorder)\n  - [Equals](#equals)\n  - [Extract](#extract)\n  - [ExtractIdx](#extractidx)\n  - [Filter](#filter)\n  - [FilterInPlace](#filterinplace)\n  - [FilterInPlaceCopy](#filterinplacecopy)\n  - [FilterMap](#filtermap)\n  - [FilterMapTuple](#filtermaptuple)\n  - [Find](#find)\n  - [FindIdx](#findidx)\n  - [Fold](#fold)\n  - [FoldSame](#foldsame)\n  - [Includes](#includes)\n  - [IndexOf](#indexof)\n  - [Insert](#insert)\n  - [InsertVector](#insertvector)\n  - [Map](#map)\n  - [MapInPlace](#mapinplace)\n  - [Peek](#peek)\n  - [Pop](#pop)\n  - [PopFront](#popfront)\n  - [PushFront](#pushfront)\n  - [Reduce](#reduce)\n  - [ReduceSame](#reducesame)\n  - [Shift](#shift)\n  - [Some](#some)\n  - [ToMap](#tomap)\n  - [ToMapIdx](#tomapidx)\n  - [Unshift](#unshift)\n\n## \u003ca name=\"fp\"\u003e\u003c/a\u003e🪄 Fp\n\nPackage fp provides functional programming primitives for Go.\nIt implements monadic types like Option and Result for more expressive error handling.\n\n\n### Functions\n\n- [Err](#err)\n- [None](#none)\n- [Ok](#ok)\n- [OkZero](#okzero)\n- [OptionFromPtr](#optionfromptr)\n- [OptionFromTuple](#optionfromtuple)\n- [OptionFromZero](#optionfromzero)\n- [Some](#some)\n\n#### \u003ca name=\"err\"\u003e\u003c/a\u003eErr\n\nErr creates a new Result in the error state with the given error.\nThis is a constructor function for creating a Result that represents failure.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Err[T any](err error) Result[T] {\n\treturn Result[T]{err: err}\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"none\"\u003e\u003c/a\u003eNone\n\nNone creates a new Option in the None state.\nThis is a constructor function for creating an Option that does not contain a value.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc None[T any]() Option[T] {\n\treturn Option[T]{}\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"ok\"\u003e\u003c/a\u003eOk\n\nOk creates a new Result in the Ok state with the given value.\nThis is a constructor function for creating a Result that represents success.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Ok[T any](v T) Result[T] {\n\treturn Result[T]{value: v, err: nil}\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"okzero\"\u003e\u003c/a\u003eOkZero\n\nOkZero creates a new Result in the Ok state with the zero value.\nThis is a constructor function for creating a Result that represents success\nbut doesn't carry a meaningful value.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc OkZero[T any]() Result[T] {\n\treturn Result[T]{err: nil}\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"optionfromptr\"\u003e\u003c/a\u003eOptionFromPtr\n\nOptionFromPtr creates an Option from a pointer.\nIf the pointer is nil, returns None, otherwise returns Some with the dereferenced value.\nThis is useful for converting nullable pointers to the Option type.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc OptionFromPtr[T any](x *T) Option[T] {\n\tif x == nil {\n\t\treturn None[T]()\n\t}\n\treturn Some(*x)\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"optionfromtuple\"\u003e\u003c/a\u003eOptionFromTuple\n\nOptionFromTuple creates an Option from a tuple-like return (value, ok).\nIf ok is true, returns Some(x), otherwise returns None.\nThis is useful for converting Go's common (value, ok) pattern to an Option.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc OptionFromTuple[T any](x T, ok bool) Option[T] {\n\tif ok {\n\t\treturn Some(x)\n\t}\n\treturn None[T]()\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"optionfromzero\"\u003e\u003c/a\u003eOptionFromZero\n\nOptionFromZero creates an Option from a value, treating zero values as None.\nIf the value equals the zero value for its type, returns None, otherwise returns Some(x).\nThis is useful when zero values are treated as invalid or unset.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc OptionFromZero[T comparable](x T) Option[T] {\n\tvar zero T\n\tif x == zero {\n\t\treturn None[T]()\n\t}\n\treturn Some(x)\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"some\"\u003e\u003c/a\u003eSome\n\nSome creates a new Option in the Some state with the given value.\nThis is a constructor function for creating an Option that contains a value.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Some[T any](t T) Option[T] {\n\treturn Option[T]{value: t, isSome: true}\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n\n[⬆️ Back to Top](#table-of-contents)\n\n\n\u003cbr/\u003e\n\n## \u003ca name=\"maps\"\u003e\u003c/a\u003e🗝️ Maps\n\nPackage maps provides generic utility functions to work with Go maps.\nIt offers a functional approach to common map operations like filtering, mapping,\nreducing, and comparing maps.\n\n\n### Functions\n\n- [Equals](#equals)\n- [Filter](#filter)\n- [FilterInPlace](#filterinplace)\n- [FilterMap](#filtermap)\n- [FilterMapTuple](#filtermaptuple)\n- [Fold](#fold)\n- [Map](#map)\n- [Reduce](#reduce)\n- [Slice](#slice)\n\n#### \u003ca name=\"equals\"\u003e\u003c/a\u003eEquals\n\nEquals compares two maps and returns whether they are equal in values.\nTwo maps are considered equal if:\n- They have the same length\n- They contain the same keys\n- For each key, the values in both maps satisfy the equality function\n\nMaps are compared using the provided equality function for values.\nThis allows for deep equality checks on complex value types.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Equals[K comparable, V any](m1, m2 map[K]V, eq func(V, V) bool) bool {\n\tif len(m1) != len(m2) {\n\t\treturn false\n\t}\n\n\tif m1 == nil \u0026\u0026 m2 != nil {\n\t\treturn false\n\t}\n\n\tif m1 != nil \u0026\u0026 m2 == nil {\n\t\treturn false\n\t}\n\n\tfor k1, v1 := range m1 {\n\t\tv2, ok := m2[k1]\n\t\tif !ok {\n\t\t\treturn false\n\t\t}\n\n\t\tif !eq(v1, v2) {\n\t\t\treturn false\n\t\t}\n\t}\n\n\treturn true\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"filter\"\u003e\u003c/a\u003eFilter\n\nFilter creates a new map containing only the key-value pairs that satisfy the predicate.\nThe predicate function takes a key and value and returns a boolean indicating\nwhether to include the entry in the result.\n\nUnlike FilterInPlace, this function creates a new map and does not modify the input map.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Filter[K comparable, V any](\n\tm map[K]V,\n\tp func(K, V) bool,\n) map[K]V {\n\tif m == nil {\n\t\treturn nil\n\t}\n\n\tres := make(map[K]V, len(m))\n\n\tfor k, v := range m {\n\t\tif p(k, v) {\n\t\t\tres[k] = v\n\t\t}\n\t}\n\n\treturn res\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"filterinplace\"\u003e\u003c/a\u003eFilterInPlace\n\nFilterInPlace modifies the given map by removing entries that do not satisfy the predicate.\nThe predicate function takes a key and value and returns a boolean indicating\nwhether to keep the entry in the map.\n\nThis function directly modifies the input map for better performance when\ncreating a new map is not necessary.\nIt returns the modified map for convenience in chaining operations.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc FilterInPlace[K comparable, V any](\n\tm map[K]V,\n\tp func(K, V) bool,\n) map[K]V {\n\tif m == nil {\n\t\treturn nil\n\t}\n\n\tfor k, v := range m {\n\t\tif !p(k, v) {\n\t\t\tdelete(m, k)\n\t\t}\n\t}\n\n\treturn m\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"filtermap\"\u003e\u003c/a\u003eFilterMap\n\nFilterMap both filters and maps a map into a new map, potentially with different key and value types.\nThe predicate function should return an fp.Option monad containing a tuple of the new key and value:\n- fp.Some to include the entry in the result (with transformed key and value)\n- fp.None to exclude the entry from the result\n\nThis provides a powerful way to simultaneously transform and filter map entries\nwhile leveraging the Option monad for expressing presence/absence.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc FilterMap[K1 comparable, V1 any, K2 comparable, V2 any](\n\tm map[K1]V1,\n\tp func(K1, V1) fp.Option[tuples.Tuple2[K2, V2]],\n) map[K2]V2 {\n\tif m == nil {\n\t\treturn nil\n\t}\n\n\tres := make(map[K2]V2, len(m))\n\n\tfor k1, v1 := range m {\n\t\ttpl := p(k1, v1)\n\t\tif tpl.IsSome() {\n\t\t\tv := tpl.UnwrapUnsafe()\n\t\t\tres[v.V1] = v.V2\n\t\t}\n\t}\n\n\treturn res\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"filtermaptuple\"\u003e\u003c/a\u003eFilterMapTuple\n\nFilterMapTuple both filters and maps the given map into a new map, potentially with different key and value types.\nThe predicate function returns three values:\n- The new key (K2)\n- The new value (V2)\n- A boolean indicating whether to include this entry in the result\n\nThis function is an alternative to FilterMap that uses Go's native boolean return\ninstead of the Option monad for expressing presence/absence.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc FilterMapTuple[K1 comparable, V1 any, K2 comparable, V2 any](\n\tm map[K1]V1,\n\tp func(K1, V1) (K2, V2, bool),\n) map[K2]V2 {\n\tif m == nil {\n\t\treturn nil\n\t}\n\n\tres := make(map[K2]V2, len(m))\n\n\tfor k1, v1 := range m {\n\t\tif k2, v2, ok := p(k1, v1); ok {\n\t\t\tres[k2] = v2\n\t\t}\n\t}\n\n\treturn res\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"fold\"\u003e\u003c/a\u003eFold\n\nFold compacts a map into a single value by iteratively applying a reduction function\nwith an explicit initial value.\nThe reduction function takes the accumulator, a key, and a value, and returns\nthe updated accumulator.\n\nUnlike Reduce, Fold takes an explicit initial value for the accumulator.\nThis is useful when the zero value of the result type is not appropriate\nas the starting value.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Fold[K comparable, V any, R any](\n\tm map[K]V,\n\tp func(R, K, V) R,\n\tinitial R,\n) R {\n\tif m == nil {\n\t\treturn initial\n\t}\n\n\tr := initial\n\n\tfor k, v := range m {\n\t\tr = p(r, k, v)\n\t}\n\n\treturn r\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"map\"\u003e\u003c/a\u003eMap\n\nMap transforms a map into another map, with potentially different key and value types.\nThe transformation is applied to each key-value pair by the provided function,\nwhich returns the new key and value for the resulting map.\n\nThis function preserves nil semantics: if the input map is nil, the output will also be nil.\nOtherwise, a new map is created with the transformed key-value pairs.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Map[K1 comparable, V1 any, K2 comparable, V2 any](\n\tm map[K1]V1,\n\tp func(K1, V1) (K2, V2),\n) map[K2]V2 {\n\tif m == nil {\n\t\treturn nil\n\t}\n\n\tres := make(map[K2]V2, len(m))\n\n\tfor k1, v1 := range m {\n\t\tk2, v2 := p(k1, v1)\n\t\tres[k2] = v2\n\t}\n\n\treturn res\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"reduce\"\u003e\u003c/a\u003eReduce\n\nReduce compacts a map into a single value by iteratively applying a reduction function.\nThe reduction function takes the accumulator, a key, and a value, and returns\nthe updated accumulator.\n\nThe initial value for the accumulator is the zero value of type R.\nIf you need a different initial value, use Fold instead.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Reduce[K comparable, V any, R any](\n\tm map[K]V,\n\tp func(R, K, V) R,\n) R {\n\tvar r R\n\n\tif m == nil {\n\t\treturn r\n\t}\n\n\tfor k, v := range m {\n\t\tr = p(r, k, v)\n\t}\n\n\treturn r\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"slice\"\u003e\u003c/a\u003eSlice\n\nSlice converts a map into a slice by applying a transformation function to each key-value pair.\nThe transformation function takes a key and value and returns an element\nfor the resulting slice.\n\nThe order of elements in the resulting slice is not guaranteed, as map iteration\nin Go is not deterministic.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Slice[K comparable, V, R any](\n\tm map[K]V,\n\tp func(K, V) R,\n) slices.Slice[R] {\n\tres := make([]R, len(m))\n\ti := 0\n\n\tfor k, v := range m {\n\t\tres[i] = p(k, v)\n\t\ti++\n\t}\n\n\treturn res\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n\n[⬆️ Back to Top](#table-of-contents)\n\n\n\u003cbr/\u003e\n\n## \u003ca name=\"slices\"\u003e\u003c/a\u003e⛓️ Slices\n\nPackage slices provides a comprehensive set of generic utility functions for working with slices.\nIt offers a functional approach to common slice operations such as transforming, filtering,\nsearching, and manipulating elements in a type-safe manner.\n\n\n### Functions\n\n- [All](#all)\n- [Any](#any)\n- [Append](#append)\n- [AppendVector](#appendvector)\n- [Contains](#contains)\n- [Cut](#cut)\n- [Delete](#delete)\n- [DeleteOrder](#deleteorder)\n- [Equals](#equals)\n- [Extract](#extract)\n- [ExtractIdx](#extractidx)\n- [Filter](#filter)\n- [FilterInPlace](#filterinplace)\n- [FilterInPlaceCopy](#filterinplacecopy)\n- [FilterMap](#filtermap)\n- [FilterMapTuple](#filtermaptuple)\n- [Find](#find)\n- [FindIdx](#findidx)\n- [Fold](#fold)\n- [FoldSame](#foldsame)\n- [Includes](#includes)\n- [IndexOf](#indexof)\n- [Insert](#insert)\n- [InsertVector](#insertvector)\n- [Map](#map)\n- [MapInPlace](#mapinplace)\n- [Peek](#peek)\n- [Pop](#pop)\n- [PopFront](#popfront)\n- [PushFront](#pushfront)\n- [Reduce](#reduce)\n- [ReduceSame](#reducesame)\n- [Shift](#shift)\n- [Some](#some)\n- [ToMap](#tomap)\n- [ToMapIdx](#tomapidx)\n- [Unshift](#unshift)\n\n#### \u003ca name=\"all\"\u003e\u003c/a\u003eAll\n\nAll checks if all elements in the slice satisfy the predicate.\nReturns true if all elements match the predicate, false otherwise.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc All[T any](arr []T, predicate func(t T) bool) bool {\n\tfor _, x := range arr {\n\t\tif !predicate(x) {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"any\"\u003e\u003c/a\u003eAny\n\nAny checks if at least one element in the slice satisfies the predicate.\nReturns true if any element matches the predicate, false otherwise.\nAlias for Contains.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Any[T any](arr []T, predicate func(t T) bool) bool {\n\treturn Contains(arr, predicate)\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"append\"\u003e\u003c/a\u003eAppend\n\nAppend adds an element to the end of the slice and returns the result.\nUnlike the builtin append, this function is explicitly named for clarity.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Append[T any](arr []T, item T) []T {\n\treturn append(arr, item)\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"appendvector\"\u003e\u003c/a\u003eAppendVector\n\nAppendVector adds all elements from another slice to the end of this slice.\nReturns the resulting concatenated slice.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc AppendVector[T any](arr, items []T) []T {\n\treturn append(arr, items...)\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"contains\"\u003e\u003c/a\u003eContains\n\nContains checks if the slice contains an element that satisfies the predicate.\nReturns true if any element matches the predicate, false otherwise.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Contains[T any](arr []T, predicate func(t T) bool) bool {\n\treturn IndexOf(arr, predicate) \u003e= 0\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"cut\"\u003e\u003c/a\u003eCut\n\nCut removes a sector from slice given lower and upper bounds. Bounds are\nrepresented as indices of the slice. E.g:\nCut([1, 2, 3, 4], 1, 2) -\u003e [1, 4]\nCut([4], 0, 0) -\u003e []\nCut will returned the original slice without the cut subslice.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Cut[T any](arr []T, from, to int) []T {\n\tif len(arr) \u003c 1 {\n\t\treturn arr\n\t}\n\n\tif from \u003c 0 {\n\t\tfrom = 0\n\t}\n\n\tif from \u003e= len(arr) {\n\t\tfrom = len(arr) - 1\n\t}\n\n\tif to \u003c 0 {\n\t\tto = 0\n\t}\n\n\tif to \u003e= len(arr) {\n\t\tto = len(arr) - 1\n\t}\n\n\tif len(arr) == 1 {\n\t\treturn arr[:0]\n\t}\n\n\tif from \u003e to {\n\n\t\treturn append(arr[:from], arr[from+to+1:]...)\n\t}\n\n\treturn append(arr[:from], arr[to+1:]...)\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"delete\"\u003e\u003c/a\u003eDelete\n\nDelete removes the element at the specified index without preserving order.\nThis provides better performance than DeleteOrder but changes the order of elements.\nIf the index is out of bounds, returns the original slice unchanged.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Delete[T any](arr []T, idx int) []T {\n\tle := len(arr) - 1\n\tif le \u003c 0 || idx \u003e le || idx \u003c 0 {\n\t\treturn arr\n\t}\n\tvar t T\n\tarr[idx] = arr[le]\n\tarr[le] = t\n\tarr = arr[:le]\n\treturn arr\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"deleteorder\"\u003e\u003c/a\u003eDeleteOrder\n\nDeleteOrder removes the element at the specified index while preserving order.\nThis is slower than Delete but maintains the relative order of the remaining elements.\nIf the index is out of bounds, returns the original slice unchanged.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc DeleteOrder[T any](arr []T, idx int) []T {\n\tle := len(arr) - 1\n\tif le \u003c 0 || idx \u003e le || idx \u003c 0 {\n\t\treturn arr\n\t}\n\tvar t T\n\n\tif le \u003e 0 {\n\t\tcopy(arr[idx:], arr[idx+1:])\n\t}\n\n\tarr[le] = t\n\tarr = arr[:le]\n\treturn arr\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"equals\"\u003e\u003c/a\u003eEquals\n\nEquals compares two slices and returns whether they contain equal elements.\nTwo slices are considered equal if they have the same length and corresponding\nelements satisfy the equality function.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Equals[T any](one, other []T, predicate func(x, y T) bool) (res bool) {\n\tif len(one) != len(other) {\n\t\treturn\n\t}\n\n\tres = true\n\n\tfor idx, otherItem := range other {\n\t\tres = predicate(one[idx], otherItem)\n\t\tif !res {\n\t\t\treturn\n\t\t}\n\t}\n\treturn\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"extract\"\u003e\u003c/a\u003eExtract\n\nExtract gets and deletes the first element that matches the predicate.\nReturns the modified slice, the extracted element, and a success flag.\nIf no element matches, returns the original slice, zero value, and false.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Extract[T any](arr []T, predicate func(t T) bool) ([]T, T, bool) {\n\tres, idx := FindIdx(arr, predicate)\n\tif idx \u003c 0 {\n\t\treturn arr, res, false\n\t}\n\n\tarr = Delete(arr, idx)\n\treturn arr, res, true\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"extractidx\"\u003e\u003c/a\u003eExtractIdx\n\nExtractIdx gets and deletes the element at the given position.\nReturns the modified slice, the extracted element, and a success flag.\nIf the index is out of bounds, returns the original slice, zero value, and false.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc ExtractIdx[T any](arr []T, idx int) (res []T, item T, ok bool) {\n\tif idx \u003e= len(arr) || idx \u003c 0 {\n\t\treturn\n\t}\n\n\tok = true\n\titem = arr[idx]\n\tres = Delete(arr, idx)\n\n\treturn\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"filter\"\u003e\u003c/a\u003eFilter\n\nFilter creates a new slice containing only the elements that satisfy the predicate.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Filter[T any](arr []T, predicate func(t T) bool) []T {\n\tres := make([]T, 0, len(arr))\n\n\tfor _, x := range arr {\n\t\tif predicate(x) {\n\t\t\tres = append(res, x)\n\t\t}\n\t}\n\n\treturn res\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"filterinplace\"\u003e\u003c/a\u003eFilterInPlace\n\nFilterInPlace modifies the slice in place to contain only elements that\nsatisfy the predicate. This is more efficient than Filter when creating\na new slice is not necessary.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc FilterInPlace[T any](arr []T, predicate func(t T) bool) []T {\n\tn := 0\n\tfor i, x := range arr {\n\t\tif predicate(x) {\n\t\t\tif n != i {\n\t\t\t\tarr[n] = x\n\t\t\t}\n\t\t\tn++\n\t\t}\n\t}\n\n\tarr = arr[:n]\n\n\treturn arr\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"filterinplacecopy\"\u003e\u003c/a\u003eFilterInPlaceCopy\n\nFilterInPlaceCopy filters the slice in place and returns a copy of the result.\nThis combines the efficiency of FilterInPlace with the safety of creating a new slice.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc FilterInPlaceCopy[T any](arr []T, predicate func(t T) bool) []T {\n\tn := 0\n\tfor i, x := range arr {\n\t\tif predicate(x) {\n\t\t\tif n != i {\n\t\t\t\tarr[n] = x\n\t\t\t}\n\t\t\tn++\n\t\t}\n\t}\n\n\tarr = arr[:n]\n\n\tres := make([]T, n)\n\n\tcopy(res, arr[:n])\n\n\treturn res\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"filtermap\"\u003e\u003c/a\u003eFilterMap\n\nFilterMap creates a new slice by applying a transformation function that\nreturns an Option. Elements with Some options are included in the result,\nwhile None options are excluded.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc FilterMap[T, U any](arr []T, predicate func(t T) fp.Option[U]) []U {\n\tpre := func(t T) (U, bool) {\n\t\treturn predicate(t).Unwrap()\n\t}\n\n\treturn FilterMapTuple[T, U](arr, pre)\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"filtermaptuple\"\u003e\u003c/a\u003eFilterMapTuple\n\nFilterMapTuple creates a new slice by applying a transformation function that\nalso filters elements. The function should return the transformed value and\na boolean indicating whether to include the element.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc FilterMapTuple[T, U any](arr []T, predicate func(t T) (U, bool)) []U {\n\tres := make([]U, 0, len(arr))\n\n\tfor _, x := range arr {\n\t\tif mapped, ok := predicate(x); ok {\n\t\t\tres = append(res, mapped)\n\t\t}\n\t}\n\n\treturn res\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"find\"\u003e\u003c/a\u003eFind\n\nFind returns the first element that satisfies the predicate.\nReturns the element and true if found, otherwise the zero value and false.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Find[T any](arr []T, predicate func(t T) bool) (res T, ok bool) {\n\tvar idx int\n\tres, idx = FindIdx(arr, predicate)\n\tok = idx \u003e -1\n\treturn\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"findidx\"\u003e\u003c/a\u003eFindIdx\n\nFindIdx returns the first element that satisfies the predicate and its index.\nReturns the element and its index if found, otherwise the zero value and -1.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc FindIdx[T any](arr []T, predicate func(t T) bool) (res T, idx int) {\n\tidx = IndexOf(arr, predicate)\n\tif idx \u003c 0 {\n\t\treturn\n\t}\n\n\tres = arr[idx]\n\treturn\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"fold\"\u003e\u003c/a\u003eFold\n\nFold compacts the slice into a single value by iteratively applying\nthe reduction function, starting with the provided initial value.\nThe accumulator type can be different from the element type.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Fold[T, U any](arr []T, p func(U, T) U, initial U) U {\n\tif len(arr) \u003c 1 {\n\t\treturn initial\n\t}\n\n\tinitial = p(initial, arr[0])\n\n\tif len(arr) \u003c 2 {\n\t\treturn initial\n\t}\n\n\ti := 1\n\n\tfor i \u003c len(arr) {\n\t\tinitial = p(initial, arr[i])\n\n\t\ti++\n\t}\n\n\treturn initial\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"foldsame\"\u003e\u003c/a\u003eFoldSame\n\nFoldSame is a convenience wrapper around Fold for when the accumulator\nand element types are the same.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc FoldSame[T any](arr []T, p func(T, T) T, initial T) T {\n\treturn Fold[T, T](arr, p, initial)\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"includes\"\u003e\u003c/a\u003eIncludes\n\nIncludes checks if the slice contains a specific element using the equality operator.\nReturns true if the element is found, false otherwise.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Includes[T comparable](arr []T, target T) bool {\n\treturn Contains(arr, func(t T) bool {\n\t\treturn t == target\n\t})\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"indexof\"\u003e\u003c/a\u003eIndexOf\n\nIndexOf returns the index of the first element that satisfies the predicate.\nReturns the index where the element was found, or -1 if not found.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc IndexOf[T any](arr []T, predicate func(t T) bool) (pos int) {\n\tpos = -1\n\tfor i, x := range arr {\n\t\tif predicate(x) {\n\t\t\tpos = i\n\t\t\treturn\n\t\t}\n\t}\n\treturn\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"insert\"\u003e\u003c/a\u003eInsert\n\nInsert places an element at the specified index in the slice.\nElements at or after the index are shifted to the right.\nReturns the resulting slice with the new element inserted.\nIf the index is out of bounds, returns the original slice unchanged.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Insert[T any](arr []T, item T, idx int) []T {\n\tif arr == nil {\n\t\treturn []T{item}\n\t}\n\n\tif idx \u003c 0 || idx \u003e len(arr) {\n\t\treturn arr\n\t}\n\n\treturn append(arr[:idx], append([]T{item}, arr[idx:]...)...)\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"insertvector\"\u003e\u003c/a\u003eInsertVector\n\nInsertVector places a slice of elements at the specified index in the slice.\nElements at or after the index are shifted to the right.\nReturns the resulting slice with the new elements inserted.\nIf the index is out of bounds, returns the original slice unchanged.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc InsertVector[T any](arr, items []T, idx int) (res []T) {\n\tif arr == nil {\n\t\tres = items[:]\n\t\treturn\n\t}\n\n\tif items == nil || len(items) == 0 {\n\t\tres = arr\n\t\treturn\n\t}\n\n\tif idx \u003c 0 || idx \u003e len(arr) {\n\t\treturn arr\n\t}\n\n\treturn append(arr[:idx], append(items, arr[idx:]...)...)\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"map\"\u003e\u003c/a\u003eMap\n\nMap creates a new slice by applying the transformation function to each element.\nThe transformation can change the type of the elements.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Map[T, U any](arr []T, predicate func(t T) U) []U {\n\tres := make([]U, 0, len(arr))\n\n\tfor _, x := range arr {\n\t\tres = append(res, predicate(x))\n\t}\n\n\treturn res\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"mapinplace\"\u003e\u003c/a\u003eMapInPlace\n\nMapInPlace transforms each element in the slice using the provided function.\nModifies the slice in place and returns it.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc MapInPlace[T any](arr []T, predicate func(t T) T) []T {\n\tfor i, x := range arr {\n\t\tarr[i] = predicate(x)\n\t}\n\n\treturn arr\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"peek\"\u003e\u003c/a\u003ePeek\n\nPeek returns the item at the specified index without modifying the slice.\nReturns the element and true if the index is valid, otherwise the zero value and false.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Peek[T any](arr []T, idx int) (item T, ok bool) {\n\tif len(arr) \u003c 1 || idx \u003e= len(arr) {\n\t\treturn\n\t}\n\n\titem = arr[idx]\n\tok = true\n\n\treturn\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"pop\"\u003e\u003c/a\u003ePop\n\nPop deletes and returns the last item from the slice.\nReturns the modified slice, the popped element, and a success flag.\nIf the slice is empty, returns the original slice, zero value, and false.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Pop[T any](arr []T) (res []T, item T, ok bool) {\n\tif len(arr) \u003c 1 {\n\t\treturn\n\t}\n\n\tvar t T\n\tle := len(arr) - 1\n\tres = arr[:le]\n\titem = arr[le]\n\tok = true\n\n\tarr[le] = t\n\n\treturn\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"popfront\"\u003e\u003c/a\u003ePopFront\n\nPopFront removes and returns the first element of the slice.\nReturns the modified slice (without the first element), the removed element, and a success flag.\nIf the slice is empty, returns the original slice, zero value, and false.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc PopFront[T any](arr []T) (res []T, item T, ok bool) {\n\tif len(arr) \u003c 1 {\n\t\tres = arr\n\t\treturn\n\t}\n\n\titem, res = arr[0], arr[1:]\n\treturn\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"pushfront\"\u003e\u003c/a\u003ePushFront\n\nPushFront inserts an element at the beginning of the slice.\nReturns the resulting slice with the new element at the front.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc PushFront[T any](arr []T, item T) []T {\n\treturn append([]T{item}, arr...)\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"reduce\"\u003e\u003c/a\u003eReduce\n\nReduce compacts the slice into a single value by iteratively applying\nthe reduction function to each element. Starts with the zero value.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Reduce[T, U any](arr []T, p func(T, T) T) (res T) {\n\treturn Fold(arr, p, res)\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"reducesame\"\u003e\u003c/a\u003eReduceSame\n\nReduceSame is a convenience wrapper around Reduce for when the accumulator\nand element types are the same.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc ReduceSame[T any](arr []T, p func(T, T) T) T {\n\treturn Reduce[T, T](arr, p)\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"shift\"\u003e\u003c/a\u003eShift\n\nShift removes and returns the first element of the slice.\nAlias for PopFront, following JavaScript array method naming conventions.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Shift[T any](arr []T) ([]T, T, bool) {\n\treturn PopFront(arr)\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"some\"\u003e\u003c/a\u003eSome\n\nSome checks if at least one element in the slice satisfies the predicate.\nReturns true if any element matches the predicate, false otherwise.\nAlias for Contains.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Some[T any](arr []T, predicate func(t T) bool) bool {\n\treturn Contains(arr, predicate)\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"tomap\"\u003e\u003c/a\u003eToMap\n\nToMap creates a map from a slice, using the provided function to determine the key\nfor each element. The element itself becomes the value in the map.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc ToMap[V any, K comparable](arr []V, predicate func(x V) K) map[K]V {\n\tres := make(map[K]V, len(arr))\n\n\tfor _, x := range arr {\n\t\tres[predicate(x)] = x\n\t}\n\n\treturn res\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"tomapidx\"\u003e\u003c/a\u003eToMapIdx\n\nToMapIdx creates a map from a slice, preserving each element's original index.\nUses the provided function to determine the key for each element.\nThe value in the map is a WrappedIdx containing both the element and its original index.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc ToMapIdx[V any, K comparable](arr []V, predicate func(x V) K) map[K]WrappedIdx[V] {\n\tres := make(map[K]WrappedIdx[V], len(arr))\n\n\tfor i, x := range arr {\n\t\tres[predicate(x)] = WrappedIdx[V]{value: x, idx: i}\n\t}\n\n\treturn res\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n#### \u003ca name=\"unshift\"\u003e\u003c/a\u003eUnshift\n\nUnshift inserts an element at the beginning of the slice.\nAlias for PushFront, following JavaScript array method naming conventions.\n\n\n\u003cdetails\u003e\u003csummary\u003eCode\u003c/summary\u003e\n\n```go\nfunc Unshift[T any](arr []T, item T) []T {\n\treturn PushFront(arr, item)\n}\n```\n\n\u003c/details\u003e\n\n\n---\n\n\n[⬆️ Back to Top](#table-of-contents)\n\n\n\u003cbr/\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsonirico%2Fgozo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsonirico%2Fgozo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsonirico%2Fgozo/lists"}