{"id":24944512,"url":"https://github.com/benji6/imlazy","last_synced_at":"2025-04-05T04:12:39.415Z","repository":{"id":2313214,"uuid":"45711354","full_name":"benji6/imlazy","owner":"benji6","description":"😴 Functional programming with lazy immutable iterables","archived":false,"fork":false,"pushed_at":"2025-03-01T21:34:19.000Z","size":1831,"stargazers_count":102,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-29T03:07:03.094Z","etag":null,"topics":["curried","functional-programming","generator","haskell","immutable","infinite","iterables","iterator","lazy","ramda"],"latest_commit_sha":null,"homepage":"https://imlazy.netlify.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/benji6.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2015-11-06T22:27:52.000Z","updated_at":"2025-03-01T21:34:22.000Z","dependencies_parsed_at":"2024-06-02T21:22:58.107Z","dependency_job_id":"c5ae5f1e-0a10-479f-b536-663e04bb2fb3","html_url":"https://github.com/benji6/imlazy","commit_stats":{"total_commits":495,"total_committers":7,"mean_commits":70.71428571428571,"dds":0.5595959595959596,"last_synced_commit":"9e2b53d11ed6f06456738a607ddeedca396a544d"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benji6%2Fimlazy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benji6%2Fimlazy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benji6%2Fimlazy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benji6%2Fimlazy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benji6","download_url":"https://codeload.github.com/benji6/imlazy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247284951,"owners_count":20913704,"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":["curried","functional-programming","generator","haskell","immutable","infinite","iterables","iterator","lazy","ramda"],"created_at":"2025-02-02T19:54:11.440Z","updated_at":"2025-04-05T04:12:39.386Z","avatar_url":"https://github.com/benji6.png","language":"JavaScript","funding_links":[],"categories":["Libraries"],"sub_categories":["[Javascript](https://developer.mozilla.org/en-US/docs/Web/JavaScript)","Data Structures"],"readme":"# imlazy\n\n[![npm version](https://badge.fury.io/js/imlazy.svg)](https://badge.fury.io/js/imlazy)\n![CI/CD](https://github.com/benji6/imlazy/workflows/CI/CD/badge.svg)\n![NPM](https://img.shields.io/npm/l/imlazy)\n[![Netlify Status](https://api.netlify.com/api/v1/badges/f5f3984d-617b-418a-9c5b-8881aceb7adb/deploy-status)](https://app.netlify.com/sites/imlazy/deploys)\n\n###### Functional programming with lazy immutable iterables\n\n## Introduction\n\nimlazy let's you harness the power of the [ES2015 iteration protocols](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols). With it you can create infinite or circular iterables which are lazy, immutable and performant. For instance:\n\n```js\nconst { filter, range } = require(\"imlazy\");\n\nconst isEven = (x) =\u003e x % 2 === 0;\n\nconst positiveIntegers = range(1, Infinity); // =\u003e (1 2 3 4 5 6 7 8 9 10...)\nconst positiveEvenIntegers = filter(isEven, positiveIntegers); // =\u003e (2 4 6 8 10 12 14 16 18 20...)\n```\n\nAll functions are auto-curried and iterable-last (like in [lodash/fp](https://github.com/lodash/lodash/wiki/FP-Guide) and [ramda](http://ramdajs.com/)) which allows developers to build up reusable functions with partial application like so:\n\n```js\nconst { take } = require(\"imlazy\");\n\nconst takeThree = take(3);\n\nconst oneTwoThree = takeThree(positiveIntegers); // =\u003e (1 2 3)\nconst twoFourSix = takeThree(positiveEvenIntegers); // =\u003e (2 4 6)\n```\n\nPutting iterables into an array, or set, or using them as arguments to a function call is simple (be careful with anything infinite or circular though!):\n\n```js\n[...twoFourSix]; // =\u003e [2, 4, 6]\nArray.from(twoFourSix); // =\u003e [2, 4, 6]\nnew Set(twoFourSix); // =\u003e Set { 2, 4, 6 }\nMath.max(...twoFourSix); // =\u003e 6\n```\n\nBecause imlazy uses the ES2015 iteration protocols it is compatible with all native iterables (including the `Generator`, `String`, `Array`, `TypedArray`, `Map` and `Set` types) and many libraries (including [Immutable.js](https://github.com/facebook/immutable-js)):\n\n```js\nconst { sum } = require(\"imlazy\");\nconst Immutable = require(\"immutable\");\n\nsum(twoFourSix); // =\u003e 12\nsum([2, 4, 6]); // =\u003e 12\nsum(new Set(twoFourSix)); // =\u003e 12\nsum(Immutable.List.of(2, 4, 6)); // =\u003e 12\n\nconst fibonacciGenerator = function* () {\n  let [a, b] = [0, 1];\n  while (true) yield ([a, b] = [b, a + b])[0];\n};\n\ntake(8, fibonacciGenerator()); // =\u003e (1 1 2 3 5 8 13 21)\n```\n\nAll iterables created by imlazy are frozen with `Object.freeze` so, not only are they lazy, they're also immutable.\n\nIf you want to find out more about the ES2015 iteration protocols [this MDN article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) is a good place to start.\n\n## Getting Started\n\n### Installation\n\n```sh\nnpm i imlazy\n```\n\n### API Documentation\n\n[API docs are here](https://imlazy.netlify.com).\n\n### Support\n\nimlazy is written in ES2015 and will run in any environment that supports that specification. If using in Node.js use version 6 or greater.\n\n### Debugging\n\nimlazy implements a custom `toString` method for the iterables it returns. Just invoke `String` on an iterable returned by one of imlazy's functions to see what's inside it:\n\n```js\nString(range(1, 8)); // =\u003e (1 2 3 4 5 6 7 8)\nString(range(1, Infinity)); // =\u003e (1 2 3 4 5 6 7 8 9 10...)\n```\n\nThe custom `toString` method can handle nested and infinite iterables (in which case it lists the first 10 elements followed by ellipsis) and uses a LISP-like notation to differentiate iterables from arrays and other JS data structures\n\n## Static Land\n\n\u003ca href=\"https://github.com/rpominov/static-land\"\u003e\u003cimg width=\"131\" height=\"82\" src=\"https://raw.githubusercontent.com/rpominov/static-land/master/logo/logo.png\" /\u003e\u003c/a\u003e\n\nThis library implements the following [Static Land](https://github.com/rpominov/static-land) algebraic types:\n\n- `Functor`\n  - `Apply`\n    - `Applicative`\n    - `Chain`\n      - `Monad`\n- `Foldable`\n  - `Traversable`\n- `Filterable`\n- `Semigroup`\n  - `Monoid`\n- `Setoid`\n\n## Performance\n\nThere is a `benchmarks` dir in the root of this repo. Here are the results on my machine running node 8.9.3:\n\n`benchmarks/filter.js`\n\n```sh\nimlazy - filter 1x over array x 3,762 ops/sec ±0.27% (98 runs sampled)\nimlazy - filter 2x over array x 3,104 ops/sec ±0.37% (96 runs sampled)\nimlazy - filter 3x over array x 3,022 ops/sec ±0.18% (100 runs sampled)\nnative - filter 1x over array x 42,003 ops/sec ±15.10% (90 runs sampled)\nnative - filter 2x over array x 21,413 ops/sec ±13.20% (98 runs sampled)\nnative - filter 3x over array x 18,075 ops/sec ±13.47% (95 runs sampled)\n```\n\n`benchmarks/map.js`\n\n```sh\nimlazy - map 1x over array x 2,726 ops/sec ±0.24% (99 runs sampled)\nimlazy - map 2x over array x 1,584 ops/sec ±0.28% (98 runs sampled)\nimlazy - map 3x over array x 999 ops/sec ±0.44% (97 runs sampled)\nnative - map 1x over array x 60,221 ops/sec ±17.07% (96 runs sampled)\nnative - map 2x over array x 9,820 ops/sec ±10.96% (97 runs sampled)\nnative - map 3x over array x 3,899 ops/sec ±0.16% (100 runs sampled)\n```\n\n## Influences\n\n- [Ramda](https://github.com/ramda/ramda)\n- Haskell\n- Clojure\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenji6%2Fimlazy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenji6%2Fimlazy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenji6%2Fimlazy/lists"}