{"id":23508975,"url":"https://github.com/maxbolgarin/lang","last_synced_at":"2025-05-13T15:36:02.463Z","repository":{"id":257800952,"uuid":"862729988","full_name":"maxbolgarin/lang","owner":"maxbolgarin","description":"Generic one-liners to work with variables, slices and maps","archived":false,"fork":false,"pushed_at":"2025-04-20T19:18:09.000Z","size":49,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-20T20:26:21.643Z","etag":null,"topics":["go","golang"],"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/maxbolgarin.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}},"created_at":"2024-09-25T05:12:38.000Z","updated_at":"2025-04-20T19:14:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"1c63dc25-4861-420e-b109-b14c42baef81","html_url":"https://github.com/maxbolgarin/lang","commit_stats":null,"previous_names":["maxbolgarin/lang"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxbolgarin%2Flang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxbolgarin%2Flang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxbolgarin%2Flang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxbolgarin%2Flang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxbolgarin","download_url":"https://codeload.github.com/maxbolgarin/lang/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253971097,"owners_count":21992647,"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","golang"],"created_at":"2024-12-25T11:36:15.473Z","updated_at":"2025-05-13T15:36:02.452Z","avatar_url":"https://github.com/maxbolgarin.png","language":"Go","funding_links":[],"categories":["Utilities","公用事业公司"],"sub_categories":["Utility/Miscellaneous","实用程序/Miscellaneous"],"readme":"# lang\n\n[![Go Version][version-img]][doc] [![GoDoc][doc-img]][doc] [![Build][ci-img]][ci] [![GoReport][report-img]][report]\n\n**Package `lang` provides useful generic one-liners to work with variables, slices and maps**\n\n```\ngo get -u github.com/maxbolgarin/lang\n```\n\n## Overview\n\n`lang` is a lightweight utility library that adds a functional programming style to Go. It leverages Go's generics to provide type-safe operations for collections. This library saves you from writing boilerplate code for common operations, making your code more readable and maintainable.\n\n## Features\n\n### Slice Operations\n\n- **Transformation**: `Map`, `Convert`, `ConvertWithErr`\n- **Filtering**: `Filter`, `WithoutEmpty`, `NotEmpty`\n- **Aggregation**: `Reduce`\n- **Search**: `FindFirst`, `Contains`, `ContainsFunc`, `IndexOf`, `LastIndexOf`\n- **Manipulation**: `Copy`, `SplitByChunkSize`, `Chunk`, `Flatten`, `Reverse`, `Distinct`, `Take`, `Skip`\n- **Set Operations**: `Intersect`, `Union`, `Difference`\n- **Iteration**: `ForEach`\n- **Testing**: `All`, `Any`\n- **Advanced**: `Partition`, `Compact`\n\n### Map Operations\n\n- **Creation**: `SliceToMap`, `SliceToMapByKey`, `Mapping`, `ConvertToMap`, `PairsToMap`, `ZipToMap`\n- **Transformation**: `ConvertMap`, `ConvertMapWithErr`, `ConvertFromMap`, `ConvertFromMapWithErr`\n- **Filtering**: `FilterMap`, `WithoutEmptyKeys`, `WithoutEmptyValues`, `NotEmptyMap`\n- **Retrieval**: `Keys`, `KeysIf`, `Values`, `ValuesIf`\n- **Manipulation**: `CopyMap`, `MergeMap`\n- **Grouping**: `GroupBy`\n\n## Examples\n\nHere are a few examples to get you started:\n\n### Filter even numbers\n```go\nnumbers := []int{1, 2, 3, 4, 5}\nevens := lang.Filter(numbers, func(n int) bool {\n    return n%2 == 0\n})\n// evens = [2, 4]\n```\n\n### Transform a slice\n```go\nnumbers := []int{1, 2, 3}\nsquares := lang.Convert(numbers, func(n int) int {\n    return n * n\n})\n// squares = [1, 4, 9]\n```\n\n### Group items by a key\n```go\ntype Person struct {\n    Name string\n    Age  int\n}\n\npeople := []Person{\n    {\"Alice\", 25},\n    {\"Bob\", 30},\n    {\"Charlie\", 25},\n}\n\nbyAge := lang.GroupBy(people, func(p Person) int {\n    return p.Age\n})\n// byAge = map[int][]Person{\n//     25: [{\"Alice\", 25}, {\"Charlie\", 25}],\n//     30: [{\"Bob\", 30}],\n// }\n```\n\n### Create a map from a slice\n```go\nusers := []string{\"user1\", \"user2\", \"user3\"}\nuserMap := lang.SliceToMap(users, func(user string) (string, int) {\n    return user, len(user)\n})\n// userMap = {\"user1\": 5, \"user2\": 5, \"user3\": 5}\n```\n\n### Merge multiple maps\n```go\nmap1 := map[string]int{\"a\": 1, \"b\": 2}\nmap2 := map[string]int{\"b\": 3, \"c\": 4}\nmerged := lang.MergeMap(map1, map2)\n// merged = {\"a\": 1, \"b\": 3, \"c\": 4}\n```\n\n## Comparison with Native Go\n\nWithout generics, operations like filtering or mapping require writing full implementations each time:\n\n```go\n// Without lang\nevens := []int{}\nfor _, n := range numbers {\n    if n%2 == 0 {\n        evens = append(evens, n)\n    }\n}\n\n// With lang\nevens := lang.Filter(numbers, func(n int) bool {\n    return n%2 == 0\n})\n```\n\nAdd to your Go program a spice of functional languages: [docs][doc].\n\nYou also should try this package: [lo](https://github.com/samber/lo).\n\n\n[version-img]: https://img.shields.io/badge/Go-%3E%3D%201.19-%23007d9c\n[doc-img]: https://pkg.go.dev/badge/github.com/maxbolgarin/lang\n[doc]: https://pkg.go.dev/github.com/maxbolgarin/lang\n[ci-img]: https://github.com/maxbolgarin/lang/actions/workflows/go.yml/badge.svg\n[ci]: https://github.com/maxbolgarin/lang/actions\n[report-img]: https://goreportcard.com/badge/github.com/maxbolgarin/lang\n[report]: https://goreportcard.com/report/github.com/maxbolgarin/lang\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxbolgarin%2Flang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxbolgarin%2Flang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxbolgarin%2Flang/lists"}