{"id":16302135,"url":"https://github.com/sjsyrek/lazy-linked-lists","last_synced_at":"2025-03-16T13:31:45.752Z","repository":{"id":83074986,"uuid":"66291762","full_name":"sjsyrek/lazy-linked-lists","owner":"sjsyrek","description":"Lazy and infinite linked lists for JavaScript.","archived":false,"fork":false,"pushed_at":"2017-05-27T21:49:47.000Z","size":87,"stargazers_count":15,"open_issues_count":73,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-27T09:50:37.411Z","etag":null,"topics":["functional-programming","haskell","infinite-lists","javascript","lazy-lists","linked-list","npm"],"latest_commit_sha":null,"homepage":null,"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/sjsyrek.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","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":"2016-08-22T17:05:23.000Z","updated_at":"2025-02-25T17:52:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"e37aab31-a64d-42a8-8cea-a3a1b65ecf2b","html_url":"https://github.com/sjsyrek/lazy-linked-lists","commit_stats":{"total_commits":73,"total_committers":3,"mean_commits":"24.333333333333332","dds":0.0547945205479452,"last_synced_commit":"c13295637168557cede28bdd4b4f94b420a8161d"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sjsyrek%2Flazy-linked-lists","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sjsyrek%2Flazy-linked-lists/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sjsyrek%2Flazy-linked-lists/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sjsyrek%2Flazy-linked-lists/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sjsyrek","download_url":"https://codeload.github.com/sjsyrek/lazy-linked-lists/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243817306,"owners_count":20352535,"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":["functional-programming","haskell","infinite-lists","javascript","lazy-lists","linked-list","npm"],"created_at":"2024-10-10T20:56:31.253Z","updated_at":"2025-03-16T13:31:45.747Z","avatar_url":"https://github.com/sjsyrek.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Lazy and infinite linked lists for JavaScript\n\n[![license](https://img.shields.io/badge/license-ISC-blue.svg)](https://github.com/sjsyrek/lazy-linked-lists/blob/master/LICENSE.txt)\n[![build status](https://travis-ci.org/sjsyrek/lazy-linked-lists.svg?branch=master)](https://travis-ci.org/sjsyrek/lazy-linked-lists)\n[![test coverage](https://codeclimate.com/github/sjsyrek/lazy-linked-lists/badges/coverage.svg)](https://codeclimate.com/github/sjsyrek/lazy-linked-lists/coverage)\n[![bitHound score](https://www.bithound.io/github/sjsyrek/lazy-linked-lists/badges/score.svg)](https://www.bithound.io/github/sjsyrek/lazy-linked-lists)\n[![dependencies status](https://david-dm.org/sjsyrek/lazy-linked-lists.svg)](https://david-dm.org/sjsyrek/lazy-linked-lists)\n[![devDependencies status](https://david-dm.org/sjsyrek/lazy-linked-lists/dev-status.svg)](https://david-dm.org/sjsyrek/lazy-linked-lists?type=dev)\n[![dependency status](https://dependencyci.com/github/sjsyrek/lazy-linked-lists/badge)](https://dependencyci.com/github/sjsyrek/lazy-linked-lists)\n[![style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/334/badge)](https://bestpractices.coreinfrastructure.org/projects/334)\n\n[![NPM](https://nodei.co/npm/lazy-linked-lists.png?downloads=true)](https://nodei.co/npm/lazy-linked-lists/)\n\n\u003e A spectre is haunting ECMAScript—the spectre of tail call optimization.\n\u003e — Karl Marxdown\n\n## About\n\nThis library is adapted from [maryamyriameliamurphies.js](https://github.com/sjsyrek/maryamyriameliamurphies.js) with several modifications. It includes functions for creating both eagerly and lazily-evaluated linked list data structures, including infinite lists, and a core subset of functions for working with them. Unlike **maryamyriameliamurphies.js**, however, **lazy-linked-lists** does not implement function currying, partial application, or type checking. It does, however, implement most of the standard [Haskell](https://www.haskell.org) type classes as instance methods, and it also implements the [ES2015 iteration protocols](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols), so you can use them in `for...of` loops or otherwise as regular iterators.\n\nThe lazy lists provided by this library are implemented using the new `Proxy` API in ES2015. Briefly, the lists returned from most of the list constructors are actually hidden behind proxy objects that trap references to their \"tail\" property, so that list elements, produced by an ES2015 generator function, are only evaluated on demand. Obviously, if you request the entire tail (by, for example, calling the `length()` function on a list), then the entire tail will be evaluated. You will want to avoid doing that with infinite lists.\n\nNote that as of this writing, most implementations of the ES2015 standard do not yet support [proper tail calls](http://www.2ality.com/2015/06/tail-call-optimization.html). But support is on its way! The newest versions of node and Safari have already rolled it out, and other vendors are surely not far behind. See the top line of this [compatibility chart](https://kangax.github.io/compat-table/es6/) to track the progress of the feature that will make recursively defined, fully-functional, high octane linked lists in JavaScript a reality. Until that fateful day, however, you may be limited to lists of only 10,000 elements or so.\n\nFor further details, see the [documentation](http://sjsyrek.github.io/maryamyriameliamurphies.js/) for **maryamyriameliamurphies.js**.\n\n##### [Try it now with Tonic](https://tonicdev.com/npm/lazy-linked-lists)\n\n## Examples\n\nLinked list, eagerly evaluated:\n```js\nconst lst = list(1,2,3,4,5,6,7,8,9,10);\nlst.valueOf(); // =\u003e '[1:2:3:4:5:6:7:8:9:10:[]]'\n```\n\nLinked list, lazily evaluated:\n```js\nconst lst = listRange(1, 10);\nlst.valueOf(); // =\u003e '[1:2:3:4:5:6:7:8:9:10:[]]'\n```\n\nLinked list, lazily evaluated with a user-defined step function:\n```js\nconst lst1 = listRangeBy(0, 100, x =\u003e x + 10);\nconst lst2 = listRangeBy(10, 0, x =\u003e x - 1);\nlst1.valueOf(); // =\u003e '[0:10:20:30:40:50:60:70:80:90:100:[]]'\nlst2.valueOf(); // =\u003e '[10:9:8:7:6:5:4:3:2:1:[]]'\n```\n\nIterating over a linked list:\n```js\nconst lst = listRange(1, 5);\nfor (let value of lst) { console.log(value); }\n// 1\n// 2\n// 3\n// 4\n// 5\n```\n\nInfinite list:\n```js\nconst lst = listInf(1);\ntake(10, lst).valueOf(); // =\u003e '[1:2:3:4:5:6:7:8:9:10:[]]'\nlst.valueOf(); // =\u003e RangeError: Maximum call stack size exceeded\n```\n\nInfinite list with a user-defined step function:\n```js\nconst lst = listInfBy(0, x =\u003e x + 10);\ntake(11, lst).valueOf(); // =\u003e '[0:10:20:30:40:50:60:70:80:90:100:[]]'\n```\n\nHaskell-style type class action:\n```js\nconst lst1 = list(1,2,3);\nconst lst2 = list(3,2,1);\n\n// Eq\nlst1.isEq(list(1,2,3)); // =\u003e true\nlst1.isEq(lst2); // =\u003e false\n\n// Ord\nlst1.compare(lst2); // =\u003e Symbol()\nlst1.compare(lst2) === LT; // =\u003e true\nlst1.isLessThan(lst2); // =\u003e true\nlst1.isGreaterThan(lst2); // =\u003e false\n\n// Monoid\nlst1.mappend(lst1.mempty()); // =\u003e '[1:2:3:[]]'\nlst1.mappend(lst2); // =\u003e '[1:2:3:4:5:6:[]]'\n\n// Foldable\nlst1.foldr((x,y) =\u003e x * y, 1); // =\u003e 6\n\n// Traversable\nlst1.traverse(x =\u003e list(x * 10)); // =\u003e '[[10:20:30:[]]:[]]'\n\n// Functor\nlst1.fmap(x =\u003e x * 10); // =\u003e '[10:20:30:[]]'\n\n// Applicative\nconst f = x =\u003e x * 10;\nconst fs1 = list(f);\nconst fs2 = list(f,f,f);\nfs1.ap(lst1); // =\u003e '[10:20:30:[]]'\nfs2.ap(lst1); // =\u003e '[10:20:30:10:20:30:10:20:30:[]]'\n\n// Monad\nlst1.flatMap(x =\u003e list(x * 10)); // =\u003e '[10:20:30:[]]'\nlst1.then(lst2); // =\u003e '[4:5:6:4:5:6:4:5:6:[]]'\nconst stringify = x =\u003e list(`${x}`);\nlst1.flatMap(x =\u003e list(x, x * 10, x * x)).flatMap(stringify); // =\u003e '[110122043309]'\n```\n\nOther fun stuff:\n```js\nconst lst1 = listInfBy(0, x =\u003e x + 2);\nconst lst2 = take(10, lst1);\nconst lst3 = reverse(lst2);\nconst lst4 = sort(lst3);\nlst3.valueOf(); // =\u003e '[18:16:14:12:10:8:6:4:2:0:[]]'\nlst4.valueOf(); // =\u003e '[0:2:4:6:8:10:12:14:16:18:[]]'\n\nconst lst5 = iterate(x =\u003e x * 2, 1);\nconst lst6 = take(10, lst5);\nlst6.valueOf(); // =\u003e '[1:2:4:8:16:32:64:128:256:512:[]]'\nindex(lst6, 10); // =\u003e Error: *** Exception: index: range error\nindex(lst5, 10); // =\u003e 1024\n\nconst lst7 = repeat(3);\nconst lst8 = take(10, lst7);\nlst8.valueOf(); // =\u003e '[3:3:3:3:3:3:3:3:3:3:[]]'\nindex(lst7, 100); // =\u003e 3\n\nconst lst9 = replicate(10, 3);\nlst9.valueOf(); // =\u003e [3:3:3:3:3:3:3:3:3:3:[]]\n\nconst lst10 = list(1,2,3);\nconst lst11 = cycle(lst10);\nconst lst12 = take(9, lst11);\nlst12.valueOf(); // =\u003e [1:2:3:1:2:3:1:2:3:[]]\nindex(lst11, 99); // =\u003e 1\nindex(lst11, 100); // =\u003e 2\nindex(lst11, 101); // =\u003e 3\n```\n\nSee also the files in the example directory.\n\n### How to install and use\n\n- [Install with npm](https://www.npmjs.com/package/lazy-linked-lists) `npm install --save-dev lazy-linked-lists`. _Do not_ install this package globally.\n- If you're transpiling \u003e=ES2015 code with [Babel](http://babeljs.io), put `import * as lazy from 'lazy-linked-lists';` at the top of your script files.\n- Or, to pollute your namespace, import functions individually: `import {listRange, listRangeBy} from 'lazy-linked-lists';`.\n- Or, if you aren't transpiling (or you're old school), use node's require syntax: `const lazy = require('lazy-linked-lists');`.\n\n### How to develop\n\n- [Fork this repo](https://help.github.com/articles/fork-a-repo/) and [clone it locally](https://help.github.com/articles/cloning-a-repository/).\n- `npm install` to download the dependencies.\n- `npm run compile` to run Babel on ES2015 code in `./source` and output transpiled ES5 code to `./distribution`.\n- `npm run lint` to run ESlint to check the source code for errors.\n- `npm test` to run Mocha on the test code in `./test`.\n- `npm run cover` to run nyc on the source code and generate testing coverage reports.\n- `npm run clean` to delete all files in `./distribution`.\n\n#### See also\n\n* [lazy.js](https://github.com/dtao/lazy.js)\n* [node-lazy](https://github.com/pkrumins/node-lazy)\n* [lazy-list](https://github.com/luochen1990/lazy-list)\n* [js-list-lazy](https://github.com/dankogai/js-list-lazy)\n* [fantasy-land](https://github.com/fantasyland/fantasy-land)\n* [js-algebraic](https://github.com/tel/js-algebraic)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsjsyrek%2Flazy-linked-lists","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsjsyrek%2Flazy-linked-lists","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsjsyrek%2Flazy-linked-lists/lists"}