{"id":21401674,"url":"https://github.com/lyuangg/mr","last_synced_at":"2025-03-16T16:18:03.194Z","repository":{"id":192067861,"uuid":"685993243","full_name":"lyuangg/mr","owner":"lyuangg","description":"A Go library based on generics that provides some common collection operation functions.","archived":false,"fork":false,"pushed_at":"2024-01-02T01:21:46.000Z","size":8,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-23T03:15:37.604Z","etag":null,"topics":["collection","golang","golang-library","map","reduce","slice"],"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/lyuangg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-09-01T13:35:23.000Z","updated_at":"2023-12-21T01:38:48.000Z","dependencies_parsed_at":"2024-01-12T20:03:56.099Z","dependency_job_id":null,"html_url":"https://github.com/lyuangg/mr","commit_stats":{"total_commits":5,"total_committers":1,"mean_commits":5.0,"dds":0.0,"last_synced_commit":"a7457ca363af2391e741562d9d17f4f74eb8bbe4"},"previous_names":["lyuangg/mr"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lyuangg%2Fmr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lyuangg%2Fmr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lyuangg%2Fmr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lyuangg%2Fmr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lyuangg","download_url":"https://codeload.github.com/lyuangg/mr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243893901,"owners_count":20364919,"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":["collection","golang","golang-library","map","reduce","slice"],"created_at":"2024-11-22T15:28:51.117Z","updated_at":"2025-03-16T16:18:03.171Z","avatar_url":"https://github.com/lyuangg.png","language":"Go","readme":"mr\n===\n\n`mr` is a Go library based on generics that provides some common collection operation functions and utility functions.\n\n## Installation\n\nUse the go get command to install:\n\n```\ngo get -u github.com/lyuangg/mr\n```\n\n## Usage\n\n```go\nimport \"github.com/lyuangg/mr\"\n```\n\n## Function List\n\nThe mr library provides the following functions:\n\n- `Reduce`: Reduce the elements in a slice.\n- `Contains`: Check if a slice contains a specific element.\n- `Map`: Map the elements in a slice.\n- `ToMap`: Convert a slice to a map.\n- `Filter`: Filter the elements in a slice based on a specified condition.\n- `Diff`: Get the difference between two slices.\n- `Intersect`: Get the intersection of two slices.\n- `Unique`: Remove duplicate elements from a slice.\n- `Merge`: Merge two slices.\n\n## Examples\n\nHere are some usage examples:\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/lyuangg/mr\"\n)\n\nfunc main() {\n    // Reduce\n    numbers := []int{1, 2, 3, 4, 5}\n    sum := mr.Reduce(numbers, func(a, b int) int {\n        return a + b\n    }, 0)\n    fmt.Println(\"Sum:\", sum)\n\n    // Contains\n    names := []string{\"Alice\", \"Bob\", \"Charlie\"}\n    contains := mr.Contains(names, \"Bob\", func(a string) string { return a })\n    fmt.Println(\"Contains Bob:\", contains)\n\n    // Map\n    squares := mr.Map(numbers, func(n int) int {\n        return n * n\n    })\n    fmt.Println(\"Squares:\", squares)\n\n    // ToMap\n    persons := []Person{\n        {ID: 1, Name: \"Alice\"},\n        {ID: 2, Name: \"Bob\"},\n    }\n    personsMap := mr.ToMap(persons, func(p Person) int {\n        return p.ID\n    })\n    fmt.Println(\"Persons Map:\", personsMap)\n\n    // Filter\n    adults := mr.Filter(persons, func(p Person) bool {\n        return p.Age \u003e= 18\n    })\n    fmt.Println(\"Adults:\", adults)\n}\n\ntype Person struct {\n    ID   int\n    Name string\n    Age  int\n}\n```\n\n## License\n\nThis library is released under the MIT License. Please see the license file for more information.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flyuangg%2Fmr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flyuangg%2Fmr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flyuangg%2Fmr/lists"}