{"id":21064036,"url":"https://github.com/luochen1990/functional-lazy-list","last_synced_at":"2025-07-20T09:33:02.268Z","repository":{"id":57243064,"uuid":"168666911","full_name":"luochen1990/functional-lazy-list","owner":"luochen1990","description":"Functional Lazy List, lightweight implimented via ES6 generator","archived":false,"fork":false,"pushed_at":"2019-02-01T08:37:44.000Z","size":7,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-19T17:09:37.787Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/luochen1990.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":"2019-02-01T08:35:56.000Z","updated_at":"2019-11-21T09:22:09.000Z","dependencies_parsed_at":"2022-09-15T00:50:45.644Z","dependency_job_id":null,"html_url":"https://github.com/luochen1990/functional-lazy-list","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/luochen1990/functional-lazy-list","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luochen1990%2Ffunctional-lazy-list","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luochen1990%2Ffunctional-lazy-list/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luochen1990%2Ffunctional-lazy-list/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luochen1990%2Ffunctional-lazy-list/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luochen1990","download_url":"https://codeload.github.com/luochen1990/functional-lazy-list/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luochen1990%2Ffunctional-lazy-list/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266100774,"owners_count":23876654,"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-11-19T17:48:06.249Z","updated_at":"2025-07-20T09:33:02.148Z","avatar_url":"https://github.com/luochen1990.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Functional Lazy List\n====================\n\nFunctional Lazy List, lightweight implimented via ES6 generator.\n\nDemo\n----\n\n```javascript\n\u003e console.log(list(lazy([1,2,3])))\n[ 1, 2, 3 ]\n\n\u003e console.log(list(take(10)(range(10, Infinity))))\n[ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ]\n\n\u003e console.log(list(take(10)(drop(1)(primes))))\n[ 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 ]\n\n\u003e console.log(list(takeWhile(x =\u003e x \u003c 100)(primes)))\n[ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 ]\n\n\u003e console.log(list(concat(lazy([range(10,15), range(5)]))))\n[ 10, 11, 12, 13, 14, 0, 1, 2, 3, 4 ]\n\n\u003e console.log(list(concat(lazy([lazy([1,2,3])]))))\n[ 1, 2, 3 ]\n\n\u003e console.log(last([1,2,3]))\n3\n\n\u003e console.log(last(range(3)))\n2\n\n\u003e console.log(list(group([1,2,2,3,4,4,5,1,3])))\n[ [ 1 ], [ 2, 2 ], [ 3 ], [ 4, 4 ], [ 5 ], [ 1 ], [ 3 ] ]\n\n\u003e console.log(list(groupWithKey(x=\u003ex)([1,2,2,3,4,4,5,1,3])))\n{ '1': [ 1, 1 ], '2': [ 2, 2 ], '3': [ 3, 3 ], '4': [ 4, 4 ], '5': [ 5 ] }\n\n\u003e console.log(list(group([])))\n[]\n\n\u003e console.log(empty([]))\ntrue\n\n\u003e console.log(empty([1]))\nfalse\n\n\u003e console.log(empty(filter(x =\u003e x \u003e 0)([1,2,3])))\nfalse\n\n\u003e console.log(empty(filter(x =\u003e x \u003c 0)([1,2,3])))\ntrue\n\n\u003e console.log(list(take(3)(naturals)))\n[ 0, 1, 2 ]\n\n\u003e console.log(tail([1,2,3]))\n[ 2, 3 ]\n\n\u003e console.log(list(tail(range(3))))\n[ 1, 2 ]\n\n\u003e console.log(foldl(x=\u003ey=\u003ex+y)(0)([1,2,3]))\n6\n```\n\nMost Possible Abuse\n-------------------\n\n### use `map` to do side effect.\n\nyou should **never** do side effect in the argument function of `map` or any other decorators/combiners. if you want to enumerate a LazyList to do something, `for ... of` syntax is exactly what you want.\n\nie. lots of people used to do things like this:\n\n```javascript\nmap((x) =\u003e {\n\tconsole.log(x)\n}) range(10)\n```\n\nit is strongly recommended that you use `for ... of` instead:\n\n```javascript\nfor (let x of iter(range(10))) {\n\tconsole.log(x)\n}\n```\n\nThe abuse of `map` will make thing unclear since `map` is designed to return a LazyList and changes nothing else. Actually the `map` one won't work since the mapping function is not called immediately.\n\nAnd `for ... of` is designed to enumerate items in a LazyList and do side effects.\n\nDo right things in right way keeps bugs away.\n\nInstall\n-------\n\n#### install \u0026 require in nodejs\n\n- install with npm: `your/repo/\u003e npm install lazy-list`\n- require: `const L = require('lazy-list')`\n- require separately: `const {map, filter} = L`\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluochen1990%2Ffunctional-lazy-list","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluochen1990%2Ffunctional-lazy-list","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluochen1990%2Ffunctional-lazy-list/lists"}