{"id":16908609,"url":"https://github.com/byteit101/lookaround-enumerable","last_synced_at":"2025-03-20T17:29:59.204Z","repository":{"id":56882240,"uuid":"305629670","full_name":"byteit101/lookaround-enumerable","owner":"byteit101","description":"Ruby gem to add simple windowed enumeration","archived":false,"fork":false,"pushed_at":"2020-10-20T07:51:42.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-25T16:20:19.041Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/byteit101.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}},"created_at":"2020-10-20T07:45:56.000Z","updated_at":"2020-10-20T07:46:50.000Z","dependencies_parsed_at":"2022-08-20T23:10:41.676Z","dependency_job_id":null,"html_url":"https://github.com/byteit101/lookaround-enumerable","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byteit101%2Flookaround-enumerable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byteit101%2Flookaround-enumerable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byteit101%2Flookaround-enumerable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byteit101%2Flookaround-enumerable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/byteit101","download_url":"https://codeload.github.com/byteit101/lookaround-enumerable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244659928,"owners_count":20489251,"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-10-13T18:52:09.716Z","updated_at":"2025-03-20T17:29:59.163Z","avatar_url":"https://github.com/byteit101.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lookaround Enumerable\n\nWhen working with time series, it is common to perform operations that depend on a sliding window of values. Lookaround Enumerable adds two main methods, and several sub-helpers to assist with running map/collect, reduce/inject, and find_all/select queries that depend on the previous values (Enumerable#each_with_prev), or a whole window of values (Enumerable#each_with_window). This gem contains these methods as refinements. \n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'lookaround-enumerable'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install lookaround-enumerable\n\n## Usage\n\n```ruby\nrequire 'lookaround-enumerable'\nusing LookaroundEnum\n```\n\nThe `LookaroundEnum` contains the refinements, so they can be targeted to selected areas of code.\n\n```ruby\n# Maps characters after a capital letter to \"x\"\n\"AbCdefgHiJKl\".each_char.map_with_prev(1, filler: \"a\") {|x, previous| previous.upcase == previous ? \"x\" : x}.join\n# =\u003e \"AxCxefgHxJxx\"\n\n# select characters surrounded by \u003e \u003c, ignoring the bounds (crop)\n\"Ab\u003ec\u003cdefg\u003eh\u003ci\u003ej\u003ckLm\u003en\u003cop\".each_char.select_with_window(-1..1, crop: true) { |left, item, right| left + right == \"\u003e\u003c\" }.join\n# =\u003e \"cjhn\"\n```\n\n * Set what beyond the Enumerable is with `filler:`\n * Ignore all iterations that look beyond the Enumerable with `crop: true`\n * Remove extra details from chains with `trim: true`\n\nSee the documentation spec tests under `spec/` for more examples.\n\n\n### Wait, what are the proc's args?\n\nThat's a tricky question. By default, single left/right views _should_ just work, but you might have to play with the `expand` parameter or do a `p *args` to figure out more advanced usage, like chaining with memos or objects. The `each_with_prev` family does `|(*this), ((*previous1), ..., (*previous_n))|` with older/lower indexes to the right. The `each_with_window` family does `|((*previous_n), ..., (*previous1)), (*this), ((*next1), ..., (*next_n))|` with older/lower indexes on the left. \n\n## Development\n\nAfter checking out the repo, run `bundle install` to install dependencies. Then, run `rake spec` or `rspec` to run the tests. \n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/byteit101/lookaround-enumerable.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbyteit101%2Flookaround-enumerable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbyteit101%2Flookaround-enumerable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbyteit101%2Flookaround-enumerable/lists"}