{"id":46095985,"url":"https://github.com/zalgonoise/cur","last_synced_at":"2026-03-01T18:36:57.468Z","repository":{"id":65051701,"uuid":"579802688","full_name":"zalgonoise/cur","owner":"zalgonoise","description":"a generic Cursor interface for Go slices","archived":false,"fork":false,"pushed_at":"2022-12-28T21:21:42.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-08-12T04:47:12.393Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/zalgonoise.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}},"created_at":"2022-12-19T00:33:25.000Z","updated_at":"2022-12-19T00:41:11.000Z","dependencies_parsed_at":"2023-01-31T07:30:38.878Z","dependency_job_id":null,"html_url":"https://github.com/zalgonoise/cur","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"purl":"pkg:github/zalgonoise/cur","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zalgonoise%2Fcur","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zalgonoise%2Fcur/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zalgonoise%2Fcur/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zalgonoise%2Fcur/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zalgonoise","download_url":"https://codeload.github.com/zalgonoise/cur/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zalgonoise%2Fcur/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29979125,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-01T16:35:47.903Z","status":"ssl_error","status_checked_at":"2026-03-01T16:35:44.899Z","response_time":124,"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":[],"created_at":"2026-03-01T18:36:57.370Z","updated_at":"2026-03-01T18:36:57.457Z","avatar_url":"https://github.com/zalgonoise.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cur\n\n*a generic Cursor interface for Go slices*\n\n__________________\n\n## Overview\n\n`cur` is a generic Cursor interface for Go slices, allowing the caller to navigate through a slice in a controlled manner, freely moving forwards and backwards within a slice, and also to peek certain elements without actually moving the reference index.\n\n## Features\n\nThe Cursor interface exposes a series of helper methods to navigate through a slice:\n\n```go\n// Cursor navigates through a slice in a controlled manner, allowing the\n// caller to move forward, backwards, and jump around the slice as they need\ntype Cursor[T any] interface {\n\n\t// Cur returns the same indexed item in the slice\n\tCur() T\n\n\t// Pos returns the current position in the cursor\n\tPos() int\n\n\t// Len returns the total size of the underlying slice\n\tLen() int\n\n\t// Next returns the next item in the slice, or the zero-value for T as EOF\n\tNext() T\n\n\t// Prev returns the previous item in the slice, or the zero-value for T as EOF if\n\t// index is / would be less than zero\n\tPrev() T\n\n\t// Peek returns the next indexed item without advancing the cursor\n\t//\n\t// If the next token overflows the slice, returns the zero-value for T as EOF\n\tPeek() T\n\n\t// Head returns to the beginning of the slice\n\tHead() T\n\n\t// Tail jumps to the end of the slice\n\tTail() T\n\n\t// Idx jumps to the specific index `idx` in the slice\n\t//\n\t// If the input index is below 0, the zero-value for T as EOF\n\t// If the input index is greater than the size of the slice, the zero-value for T as EOF\n\tIdx(idx int) T\n\n\t// Offset advances or rewinds `amount` steps in the slice, be it a positive or negative\n\t// input.\n\t//\n\t// If the result offset is below 0, the zero-value for T as EOF\n\t// If the result offset is greater than the size of the slice, the zero-value for T as EOF\n\tOffset(amount int) T\n\n\t// PeekIdx returns the next indexed item without advancing the cursor,\n\t// with the index `idx`\n\t//\n\t// If the input index is below 0, the zero-value for T as EOF\n\t// If the input index is greater than the size of the slice, the zero-value for T as EOF\n\tPeekIdx(idx int) T\n\n\t// PeekOffset returns the next indexed item without advancing the cursor,\n\t// with offset `amount`\n\t//\n\t// If the result offset is below 0, the zero-value for T as EOF\n\t// If the result offset is greater than the size of the slice, the zero-value for T as EOF\n\tPeekOffset(amount int) T\n\n\t// Extract returns a slice from index `start` to index `end`\n\tExtract(start, end int) []T\n}\n```\n\nCreating a cursor only takes an input slice, provided that it has one or more elements in it. An empty slice will return a `nil` Cursor:\n\n```go\ntype cursor[T any] struct {\n\tslice []T\n\tidx   int\n}\n\n// NewCursor returns a Cursor for the input slice, or nil if the slice is empty\nfunc NewCursor[T any](slice []T) Cursor[T] {\n\tif len(slice) == 0 {\n\t\treturn nil\n\t}\n\treturn \u0026cursor[T]{\n\t\tslice: slice,\n\t}\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzalgonoise%2Fcur","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzalgonoise%2Fcur","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzalgonoise%2Fcur/lists"}