{"id":13493566,"url":"https://github.com/ahmetb/go-linq","last_synced_at":"2026-02-13T17:05:24.928Z","repository":{"id":12629704,"uuid":"15300997","full_name":"ahmetb/go-linq","owner":"ahmetb","description":".NET LINQ capabilities in Go","archived":false,"fork":false,"pushed_at":"2025-11-24T07:43:24.000Z","size":888,"stargazers_count":3640,"open_issues_count":4,"forks_count":226,"subscribers_count":79,"default_branch":"master","last_synced_at":"2026-01-14T01:23:29.092Z","etag":null,"topics":["generic-functions","go","linq"],"latest_commit_sha":null,"homepage":"https://godoc.org/github.com/ahmetb/go-linq","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ahmetb.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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2013-12-19T03:05:00.000Z","updated_at":"2026-01-12T18:08:13.000Z","dependencies_parsed_at":"2022-07-09T10:31:03.657Z","dependency_job_id":null,"html_url":"https://github.com/ahmetb/go-linq","commit_stats":null,"previous_names":["ahmetalpbalkan/go-linq"],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/ahmetb/go-linq","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmetb%2Fgo-linq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmetb%2Fgo-linq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmetb%2Fgo-linq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmetb%2Fgo-linq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahmetb","download_url":"https://codeload.github.com/ahmetb/go-linq/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmetb%2Fgo-linq/sbom","scorecard":{"id":172215,"data":{"date":"2025-08-11","repo":{"name":"github.com/ahmetb/go-linq","commit":"9b75bfdcd4c49fdfd69601f69c8faec3c8ceff0f"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.8,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":9,"reason":"Found 21/23 approved changesets -- score normalized to 9","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 28 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-16T16:53:19.732Z","repository_id":12629704,"created_at":"2025-08-16T16:53:19.732Z","updated_at":"2025-08-16T16:53:19.732Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29412675,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-13T06:24:03.484Z","status":"ssl_error","status_checked_at":"2026-02-13T06:23:12.830Z","response_time":78,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["generic-functions","go","linq"],"created_at":"2024-07-31T19:01:16.598Z","updated_at":"2026-02-13T17:05:24.922Z","avatar_url":"https://github.com/ahmetb.png","language":"Go","funding_links":[],"categories":["Go","Repositories","Generators","Relational Databases"],"sub_categories":["Utility/Miscellaneous"],"readme":"# go-linq [![GoDoc](https://godoc.org/github.com/ahmetb/go-linq?status.svg)](https://godoc.org/github.com/ahmetb/go-linq) [![Build Status](https://github.com/ahmetb/go-linq/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/ahmetb/go-linq/actions/workflows/ci.yml) [![Coverage Status](https://coveralls.io/repos/github/ahmetb/go-linq/badge.svg?branch=master)](https://coveralls.io/github/ahmetb/go-linq?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/ahmetb/go-linq)](https://goreportcard.com/report/github.com/ahmetb/go-linq)\n\nA powerful language integrated query (LINQ) library for Go.\n\n* Written in vanilla Go, no dependencies!\n* Complete lazy evaluation with iterator pattern\n* Safe for concurrent use\n* Supports generic functions to make your code cleaner and free of type assertions\n* Supports arrays, slices, maps, strings, channels and custom collections\n\n## Installation\n\nWhen used with Go modules, use the following import path:\n\n    go get github.com/ahmetb/go-linq/v4\n\nOlder versions of Go using different dependency management tools can use the\nfollowing import path to prevent breaking API changes:\n\n    go get gopkg.in/ahmetb/go-linq.v4\n\n## Quickstart\n\nUsage is as easy as chaining methods like:\n\n`From(slice)` `.Where(predicate)` `.Select(selector)` `.Union(data)`\n\n**Example 1: Find all owners of cars manufactured after 2015**\n\n```go\nimport . \"github.com/ahmetb/go-linq/v4\"\n\ntype Car struct {\n    year int\n    owner, model string\n}\n\n...\n\n\nvar owners []string\n\nFromSlice(cars).Where(func(c any) bool {\n\treturn c.(Car).year \u003e= 2015\n}).Select(func(c any) any {\n\treturn c.(Car).owner\n}).ToSlice(\u0026owners)\n```\n\nOr, you can use generic functions, like `WhereT` and `SelectT` to simplify your code\n(at a performance penalty):\n\n```go\nvar owners []string\n\nFromSlice(cars).WhereT(func(c Car) bool {\n\treturn c.year \u003e= 2015\n}).SelectT(func(c Car) string {\n\treturn c.owner\n}).ToSlice(\u0026owners)\n```\n\n**Example 2: Find the author who has written the most books**\n\n```go\nimport . \"github.com/ahmetb/go-linq/v4\"\n\ntype Book struct {\n\tid      int\n\ttitle   string\n\tauthors []string\n}\n\nauthor := FromSlice(books).SelectMany( // make a flat array of authors\n\tfunc(book any) Query {\n\t\treturn From(book.(Book).authors)\n\t}).GroupBy( // group by author\n\tfunc(author any) any {\n\t\treturn author // author as key\n\t}, func(author any) any {\n\t\treturn author // author as value\n\t}).OrderByDescending( // sort groups by its length\n\tfunc(group any) any {\n\t\treturn len(group.(Group).Group)\n\t}).Select( // get authors out of groups\n\tfunc(group any) any {\n\t\treturn group.(Group).Key\n\t}).First() // take the first author\n```\n\n**Example 3: Implement a custom method that leaves only values greater than the specified threshold**\n\n```go\ntype MyQuery Query\n\nfunc (q MyQuery) GreaterThan(threshold int) Query {\n    return Query{\n        Iterate: func(yield func(any) bool) {\n            q.Iterate(func(item any) bool {\n                if item.(int) \u003e threshold {\n                    return yield(item)\n                }\n                return true\n            })\n        },\n    }\n}\n\nresult := MyQuery(Range(1,10)).GreaterThan(5).Results()\n```\n\n## Generic Functions\n\nAlthough Go doesn't implement generics, with some reflection tricks, you can use go-linq without\ntyping `any`s and type assertions. This will introduce a performance penalty (5x-10x slower)\nbut will yield in a cleaner and more readable code.\n\nMethods with `T` suffix (such as `WhereT`) accept functions with generic types. So instead of\n\n    .Select(func(v any) any {...})\n\nyou can type:\n\n    .SelectT(func(v YourType) YourOtherType {...})\n\nThis will make your code free of `any` and type assertions.\n\n**Example 4: \"MapReduce\" in a slice of string sentences to list the top 5 most used words using generic functions**\n\n```go\nvar results []string\n\nFromSlice(sentences).\n\t// split sentences to words\n\tSelectManyT(func(sentence string) Query {\n\t\treturn From(strings.Split(sentence, \" \"))\n\t}).\n\t// group the words\n\tGroupByT(\n\t\tfunc(word string) string { return word },\n\t\tfunc(word string) string { return word },\n\t).\n\t// order by count\n\tOrderByDescendingT(func(wordGroup Group) int {\n\t\treturn len(wordGroup.Group)\n\t}).\n\t// order by the word\n\tThenByT(func(wordGroup Group) string {\n\t\treturn wordGroup.Key.(string)\n\t}).\n\tTake(5).  // take the top 5\n\t// project the words using the index as rank\n\tSelectIndexedT(func(index int, wordGroup Group) string {\n\t\treturn fmt.Sprintf(\"Rank: #%d, Word: %s, Counts: %d\", index+1, wordGroup.Key, len(wordGroup.Group))\n\t}).\n\tToSlice(\u0026results)\n```\n\n## Manual Iteration\n\nSince **go-linq v4** manual iteration follows Go’s standard iterator pattern introduced with the `iter` package.\nThe Query type exposes an `Iterate` field of type `iter.Seq[any]`, making it easier to integrate with Go’s native\niteration style.\n\n**Example 5: Iterate over a query using the standard `for ... range` loop**\n\n```go\nq := FromSlice([]int{1, 2, 3, 4})\n\nfor v := range q.Iterate {\n\tfmt.Println(v)\n}\n```\n\n**More examples** can be found in the [documentation](https://godoc.org/github.com/ahmetb/go-linq).\n\n## Data Source Constructors\n\nSince **go-linq v4**, a new family of constructor functions provides a type-safe and efficient way to create queries from\nvarious data sources. Each function is optimized for its specific input type, avoiding the overhead of reflection.\n\nAvailable constructors:\n- `FromSlice` - creates a query from a slice\n- `FromMap` - creates a query from a map\n- `FromChannel` - creates a query from a channel\n- `FromChannelWithContext` - creates a query from a channel with `Context` support\n- `FromString` - creates a query from a string (iterating over runes)\n- `FromIterable` - creates a query from a custom collection implementing the `Iterable` interface\n\nThe older `From` function remains available for backward compatibility, but it relies on runtime reflection and is\nsignificantly less efficient. For all new code, it’s recommended to use the explicit `From*` constructors.\n\n## Release Notes\n\n```text\nv4.0.0 (2025-10-12)\n* Breaking change: Migrated to standard Go iterator pattern. (thanks @kalaninja!)\n* Added typed constructors: FromSlice(), FromMap(), FromChannel(),\n FromChannelWithContext(), FromString().\n* Breaking change: Removed FromChannelT() in favor of FromChannel().\n\nv3.2.0 (2020-12-29)\n* Added FromChannelT().\n* Added DefaultIfEmpty().\n\nv3.1.0 (2019-07-09)\n* Support for Go modules\n* Added IndexOf()/IndexOfT().\n\nv3.0.0 (2017-01-10)\n* Breaking change: ToSlice() now overwrites existing slice starting\n  from index 0 and grows/reslices it as needed.\n* Generic methods support (thanks @cleitonmarx!)\n  - Accepting parametrized functions was originally proposed in #26\n  - You can now avoid type assertions and interface{}s\n  - Functions with generic methods are named as \"MethodNameT\" and\n    signature for the existing LINQ methods are unchanged.\n* Added ForEach(), ForEachIndexed() and AggregateWithSeedBy().\n\nv2.0.0 (2016-09-02)\n* IMPORTANT: This release is a BREAKING CHANGE. The old version\n  is archived at the 'archive/0.9' branch or the 0.9 tags.\n* A COMPLETE REWRITE of go-linq with better performance and memory\n  efficiency. (thanks @kalaninja!)\n* API has significantly changed. Most notably:\n  - linq.T removed in favor of interface{}\n  - library methods no longer return errors\n  - PLINQ removed for now (see channels support)\n  - support for channels, custom collections and comparables\n\nv0.9-rc4\n* GroupBy()\n\nv0.9-rc3.2\n* bugfix: All() iterating over values instead of indices\n\nv0.9-rc3.1\n* bugfix: modifying result slice affects subsequent query methods\n\nv0.9-rc3\n* removed FirstOrNil, LastOrNil, ElementAtOrNil methods\n\nv0.9-rc2.5\n* slice-accepting methods accept slices of any type with reflections\n\nv0.9-rc2\n* parallel linq (plinq) implemented\n* Queryable separated into Query \u0026 ParallelQuery\n* fixed early termination for All\n\nv0.9-rc1\n* many linq methods are implemented\n* methods have error handling support\n* type assertion limitations are unresolved\n* travis-ci.org build integrated\n* open sourced on github, master \u0026 dev branches\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmetb%2Fgo-linq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahmetb%2Fgo-linq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmetb%2Fgo-linq/lists"}