{"id":15439763,"url":"https://github.com/bcherny/lazy-arr","last_synced_at":"2025-04-19T18:49:52.782Z","repository":{"id":66101173,"uuid":"93642260","full_name":"bcherny/lazy-arr","owner":"bcherny","description":"Arrays that look just like regular JavaScript arrays, but are computed lazily.","archived":false,"fork":false,"pushed_at":"2017-06-09T07:34:50.000Z","size":9,"stargazers_count":65,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-17T03:03:24.048Z","etag":null,"topics":["array","lazy","stream","swift"],"latest_commit_sha":null,"homepage":"https://performancejs.com/post/ewffd34/Introducing:-Lazy-arrays-in-JavaScript","language":"TypeScript","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/bcherny.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":"2017-06-07T14:06:21.000Z","updated_at":"2023-04-18T19:09:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"da26fb81-5451-48f1-90a9-85f76034009c","html_url":"https://github.com/bcherny/lazy-arr","commit_stats":{"total_commits":8,"total_committers":1,"mean_commits":8.0,"dds":0.0,"last_synced_commit":"245f934ea552c2b4830d9d2d0cdfa8010f6a9ade"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcherny%2Flazy-arr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcherny%2Flazy-arr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcherny%2Flazy-arr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcherny%2Flazy-arr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bcherny","download_url":"https://codeload.github.com/bcherny/lazy-arr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249239233,"owners_count":21235820,"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":["array","lazy","stream","swift"],"created_at":"2024-10-01T19:09:20.965Z","updated_at":"2025-04-16T12:30:35.774Z","avatar_url":"https://github.com/bcherny.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lazy-arr [![Build Status][build]](https://circleci.com/gh/bcherny/lazy-arr) [![npm]](https://www.npmjs.com/package/lazy-arr) [![mit]](https://opensource.org/licenses/MIT)\n\n[build]: https://img.shields.io/circleci/project/bcherny/lazy-arr.svg?branch=master\u0026style=flat-square\n[npm]: https://img.shields.io/npm/v/lazy-arr.svg?style=flat-square\n[mit]: https://img.shields.io/npm/l/lazy-arr.svg?style=flat-square\n\n\u003e Arrays that look just like regular JavaScript arrays, but are computed lazily. Like Scala or Haskell's lazy streams. Read more about it in the introductory blog post: https://performancejs.com/post/ewffd34/Introducing:-Lazy-arrays-in-JavaScript.\n\n## Install\n\n```sh\nnpm i lazy-arr -S\n```\n\n## Usage\n\nLazy-arr takes a function, and uses it to lazily generate values for the array. The function takes a numerical array index (eg. `5`) and should return the value for that index in the array. The function doesn't have to be idempotent, but its return value *will* be cached (you can then delete it from cache, if you want).\n\nIt supports 2 usage patterns:\n\n1. Call it with just a function:\n\n  ```js\n  import { lazy } from 'lazy-arr'\n  lazy(index =\u003e index + 1)\n  ```\n\n2. Call it with a function and an initial value:\n\n  ```js\n  import { lazy } from 'lazy-arr'\n  let seq = lazy([0])(index =\u003e index + seq[index - 1])\n  ```\n\n## Examples\n\n```js\nimport { lazy } from 'lazy-arr'\n\n// even numbers\nlet numbers = lazy(_ =\u003e _ * 2)\nnumbers[0] // 0\nnumbers[5] // 10\n\n// fibonacci numbers (with initial value of [0, 1])\nlet fibs = lazy([0, 1])(_ =\u003e fibs[_ - 1] + fibs[_ - 2])\n\nfibs[0]  // 0\nfibs[1]  // 1\nfibs[10] // 55\n```\n\n## Other operations\n\n```js\nimport { lazy } from 'lazy-arr'\n\nlet numbers = lazy(_ =\u003e _ * 2)\nnumbers[3]   // 6\n\n// membership\n2 in numbers // true\n3 in numbers // true\n4 in numbers // false\n\n// deleting\ndelete numbers[3]\n3 in numbers // false\n```\n\nNote that you *cannot* directly set values:\n\n```js\nimport { lazy } from 'lazy-arr'\n\nlet numbers = lazy(_ =\u003e _ * 2)\nnumbers[7] = 3 // THROWS ERROR\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbcherny%2Flazy-arr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbcherny%2Flazy-arr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbcherny%2Flazy-arr/lists"}