{"id":21811595,"url":"https://github.com/valsov/laziter","last_synced_at":"2025-03-21T09:15:34.724Z","repository":{"id":196690135,"uuid":"695520843","full_name":"valsov/laziter","owner":"valsov","description":"Lazy loading iterator","archived":false,"fork":false,"pushed_at":"2023-10-15T06:53:14.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-26T05:41:35.338Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/valsov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2023-09-23T12:50:39.000Z","updated_at":"2023-10-13T16:40:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"33ed2ce2-24b1-488c-9da4-c1a248deb20a","html_url":"https://github.com/valsov/laziter","commit_stats":null,"previous_names":["valsov/laziter"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valsov%2Flaziter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valsov%2Flaziter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valsov%2Flaziter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valsov%2Flaziter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/valsov","download_url":"https://codeload.github.com/valsov/laziter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244767798,"owners_count":20507110,"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":[],"created_at":"2024-11-27T13:45:34.075Z","updated_at":"2025-03-21T09:15:34.698Z","avatar_url":"https://github.com/valsov.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laziter\nLazy iterator experimentation. The aim of this lib is to enable lazy loading an iterator's content. The lazy loading is achieved using a goroutine and two channels per iterator.\n\n## Example\n\n### Base use\n```go\nfunc main() {\n    iter := laziter.New[int](false) // No persistence needed here\n    defer iter.Close() // Close() should always be called to prevent leaking goroutines\n\n    // Start values provider goroutine\n    go sampleValuesGenerator(iter.GetValuesProvider(), 5)\n\n    // Iterate over values\n    for iter.Next() {\n        value, _ := iter.GetCurrentValue()\n    }\n}\n\nfunc sampleValuesGenerator(vp *laziter.ValuesProvider[int], valuesCount int) {\n    defer vp.Close()\n    for i := 0; i \u003c valuesCount; i++ {\n        if !vp.Wait() {\n            // Iterator stopped iteration, quit\n            break\n        }\n        vp.Yield(i) // Produce value\n    }\n}\n```\n\n### Partial iteration\nThe following example shows a partial iteration with the lazy iterator. Once `sampleFunction()` returns, `sampleValuesGenerator()` goroutine will end, skipping the last 2 values that won't be evaluated (3 \u0026 4). You may stop the iteration early by calling `iter.Done()`, here it is called in a defer statement.\n\n```go\nfunc sampleFunction() {\n    iter := laziter.New[int](false) // No persistence needed here\n    defer iter.Close()\n\n    // Start values provider goroutine\n    go sampleValuesGenerator(iter.GetValuesProvider(), 5)\n\n    // Get 3 values\n    for i := 0; i \u003c 4; i++ {\n        value, _ := iter.GetCurrentValue()\n    }\n}\n\nfunc sampleValuesGenerator(vp *laziter.ValuesProvider[int], valuesCount int) {\n    // [...] (same as above)\n}\n```\n\n### Values persistence\nThe current `Iterator` implementation allows values persistence which enables, for example, multiple `for iter.Next() { [...] }` statements.\nIt is also possible to call `ResetIteratorPosition()` while iterating. This will pause values retrieval until the iterator needs more.\n\n```go\nfunc main() {\n    iter := laziter.New[int](true) // Persistence enabled\n    defer iter.Close()\n\n    go sampleValuesGenerator(iter.GetValuesProvider(), 5)\n\n    // Iterate over values once\n    for iter.Next() {\n        value, _ := iter.GetCurrentValue()\n    }\n\n    // Reset the iterator position\n    iter.ResetIteratorPosition()\n    // From now on, values are fetched from the iterator's persisted storage.\n    // sampleValuesGenerator() goroutine already exited.\n    \n    // Iterate over values again\n    for iter.Next() {\n        value, _ := iter.GetCurrentValue()\n    }\n}\n\nfunc sampleValuesGenerator(vp *laziter.ValuesProvider[int], valuesCount int) {\n    // [...] (same as above)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalsov%2Flaziter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvalsov%2Flaziter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalsov%2Flaziter/lists"}