{"id":21981655,"url":"https://github.com/soft/iter","last_synced_at":"2025-07-20T16:33:28.520Z","repository":{"id":39916208,"uuid":"463213618","full_name":"Soft/iter","owner":"Soft","description":"iter is a generic iterator library for Go","archived":false,"fork":false,"pushed_at":"2023-09-16T06:30:36.000Z","size":13,"stargazers_count":71,"open_issues_count":1,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-03T15:10:04.752Z","etag":null,"topics":["generics","go","golang","golang-library","iteration","iterator","iterators","optional"],"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/Soft.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":"2022-02-24T16:09:14.000Z","updated_at":"2024-03-22T00:29:45.000Z","dependencies_parsed_at":"2024-06-20T01:53:54.814Z","dependency_job_id":null,"html_url":"https://github.com/Soft/iter","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Soft/iter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soft%2Fiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soft%2Fiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soft%2Fiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soft%2Fiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Soft","download_url":"https://codeload.github.com/Soft/iter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soft%2Fiter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266160759,"owners_count":23885884,"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":["generics","go","golang","golang-library","iteration","iterator","iterators","optional"],"created_at":"2024-11-29T17:18:59.295Z","updated_at":"2025-07-20T16:33:28.504Z","avatar_url":"https://github.com/Soft.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# iter - Generic Iterators for Go 🦄\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n`iter` is a generic iterator library for Go 1.18 and greater. It should feel\nfamiliar to those familiar with [Rust's Iterator\ntrait](https://doc.rust-lang.org/std/iter/trait.Iterator.html).\n\n# Iterators\n\n```go\ntype Iterator[T any] interface {\n        // Next yields a new value from the Iterator.\n        Next() Option[T]\n}\n```\n\n`Iterator[T]` represents an iterator yielding elements of type `T`.\n\n## Creating Iterators\n\n```go\nfunc Slice[T any](slice []T) Iterator[T]\n```\n\n`Slice` returns an Iterator that yields elements from a slice.\n\n```go\nfunc String(input string) Iterator[rune]\n```\n\n`String` returns an Iterator yielding runes from the supplied string.\n\n```go\nfunc Range(start, stop, step int) Iterator[int]\n```\n\n`Range` returns an Iterator over a range of integers.\n\n```go\nfunc Func[T any](fn func() Option[T]) Iterator[T]\n```\n\n`Func` returns an Iterator from a function.\n\n```go\nfunc Once[T any](value T) Iterator[T]\n```\n\n`Once` returns an Iterator that returns a value exactly once.\n\n```go\nfunc Empty[T any]() Iterator[T]\n```\n\n`Empty` returns an empty Iterator.\n\n```go\nfunc Repeat[T any](value T) Iterator[T]\n```\n\n`Repeat` returns an Iterator that repeatedly returns the same value.\n\n\n## Iterator Adapters\n\n```go\nfunc Chain[T any](first Iterator[T], second Iterator[T]) Iterator[T]\n```\n\n`Chain` returns an Iterator that concatenates two iterators.\n\n```go\nfunc Drop[T any](it Iterator[T], n uint) Iterator[T]\n```\n\n`Drop` returns an Iterator adapter that drops the first n items from the\nunderlying Iterator before yielding any values.\n\n```go\nfunc DropWhile[T any](it Iterator[T], pred func(T) bool) Iterator[T]\n```\n\n`DropWhile` returns an Iterator adapter that drops items from the underlying\nIterator until pred predicate function returns true.\n\n```go\nfunc Filter[T any](it Iterator[T], pred func(T) bool) Iterator[T]\n```\n\n`Filter` returns an Iterator adapter that yields elements from the underlying\nIterator for which pred returns true.\n\n```go\nfunc Flatten[T any](it Iterator[Iterator[T]]) Iterator[T]\n```\n\n`Flatten` returns an Iterator adapter that flattens nested iterators.\n\n```go\nfunc Fuse[T any](it Iterator[T]) Iterator[T]\n```\n\n`Fuse` returns an Iterator adapter that will keep yielding None after the\nunderlying Iterator has yielded None once.\n\n```go\nfunc Map[T, R any](it Iterator[T], fn func(T) R) Iterator[R]\n```\n\n`Map` is an Iterator adapter that transforms each value yielded by the\nunderlying iterator using fn.\n\n```go\nfunc Take[T any](it Iterator[T], n uint) Iterator[T]\n```\n\n`Take` returns an Iterator adapter that yields the n first elements from the\nunderlying Iterator.\n\n```go\nfunc TakeWhile[T any](it Iterator[T], pred func(T) bool) Iterator[T]\n```\n\n`TakeWhile` returns an Iterator adapter that yields values from the underlying\nIterator as long as pred predicate function returns true.\n\n## Consuming Iterators\n\n```go\nfunc Count[T any](it Iterator[T]) uint\n```\n\n`Count` consumes an Iterator and returns the number of items it yielded.\n\n```go\nfunc Fold[T any, B any](it Iterator[T], init B, fn func(B, T) B) B\n```\n\n`Fold` reduces Iterator using function fn.\n\n```go\nfunc ForEach[T any](it Iterator[T], fn func(T))\n```\n\n`ForEach` consumes the Iterator applying fn to each yielded value.\n\n```go\nfunc ToSlice[T any](it Iterator[T]) []T\n```\n\n`ToSlice` consumes an Iterator creating a slice from the yielded values.\n\n```go\nfunc ToString(it Iterator[rune]) string\n```\n\n`ToString` consumes a rune Iterator creating a string.\n\n```go\nfunc Find[T any](it Iterator[T], pred func(T) bool) Option[T]\n```\n\n`Find` the first element from Iterator that satisfies pred predicate function.\n\n```go\nfunc All[T any](it Iterator[T], pred func(T) bool) bool\n```\n\nAll tests if every element of the Iterator matches a predicate. An empty\nIterator returns true.\n\n```go\nfunc Any[T any](it Iterator[T], pred func(T) bool) bool\n```\n\nAny tests if any element of the Iterator matches a predicate. An empty Iterator\nreturns false.\n\n```go\nfunc Equal[T comparable](first Iterator[T], second Iterator[T]) bool\n```\n\nDetermines if the elements of two Iterators are equal.\n\n```go\nfunc EqualBy[T any](first Iterator[T], second Iterator[T], cmp func(T, T) bool) bool\n```\n\nDetermines if the elements of two Iterators are equal using function cmp to\ncompare elements.\n\n```go\nfunc Nth[T any](it Iterator[T], n uint) Option[T]\n```\n\nNth returns nth element of the Iterator.\n\n\n\n# Optional Values\n\n```go\ntype Option[T any] struct {\n        // Has unexported fields.\n}\n```\n\n`Options[T]` represents an optional value of type `T`.\n\n```go\nfunc Some[T any](v T) Option[T]\n```\n\n`Some` returns an Option containing a value.\n\n```go\nfunc None[T any]() Option[T]\n```\n\n`None` returns an empty Option.\n\n```go\nfunc (opt Option[T]) IsSome() bool\n```\n\n`IsSome` returns true if Option contains a value.\n\n```go\nfunc (opt Option[T]) IsNone() bool\n```\n\n`IsNone` returns true if Option is empty.\n\n```go\nfunc (opt Option[T]) Unwrap() T\n```\n\n`Unwrap` extracts a value from Option. Panics if Option does not contain a\nvalue.\n\n```go\nfunc (opt Option[T]) UnwrapOr(def T) T\n```\n\n`UnwrapOr` extracts a value from Option or returns a default value def if the\nOption is empty.\n\n```go\nfunc (opt Option[T]) UnwrapOrElse(fn func() T) T\n```\n\n`UnwrapOrElse` extracts a value from Option or computes a value by calling fn if\nthe Option is empty.\n\n```go\nfunc MapOption[T any, R any](opt Option[T], fn func(T) R) Option[R]\n```\n\n`MapOption` applies a function fn to the contained value if it exists.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoft%2Fiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoft%2Fiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoft%2Fiter/lists"}