{"id":21662463,"url":"https://github.com/shalimov/lzdash","last_synced_at":"2025-07-19T03:36:53.664Z","repository":{"id":98501093,"uuid":"142407755","full_name":"Shalimov/lzdash","owner":"Shalimov","description":"Lazy / non-strict evaluation in JavaScript","archived":false,"fork":false,"pushed_at":"2018-08-28T12:37:14.000Z","size":576,"stargazers_count":16,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-01T13:08:06.183Z","etag":null,"topics":["fp","functional-programming","javascript","lazy-evaluation","non-strict"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/Shalimov.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":"2018-07-26T07:52:24.000Z","updated_at":"2025-04-15T16:12:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"d79b71b2-23a1-4b9c-a8af-27deda39ec53","html_url":"https://github.com/Shalimov/lzdash","commit_stats":{"total_commits":70,"total_committers":1,"mean_commits":70.0,"dds":0.0,"last_synced_commit":"6be1ca874bfee217bad97576ba2704a8537503f5"},"previous_names":["shalimov/lazier"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/Shalimov/lzdash","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shalimov%2Flzdash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shalimov%2Flzdash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shalimov%2Flzdash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shalimov%2Flzdash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Shalimov","download_url":"https://codeload.github.com/Shalimov/lzdash/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shalimov%2Flzdash/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265883680,"owners_count":23843800,"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":["fp","functional-programming","javascript","lazy-evaluation","non-strict"],"created_at":"2024-11-25T10:16:18.135Z","updated_at":"2025-07-19T03:36:53.629Z","avatar_url":"https://github.com/Shalimov.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lazy non-strict evaluation in JS; Subset of lodash/fp functions to work with collections effectively\n\n**lzdash** is a functional utility library for JavaScript, contains subset of Lodash functions (api similar to lodash/fp), but with a lazy engine under the hood that strives to do as little work as possible while being as flexible as possible.\n\n**For:**\n- __more information check [API Docs](/docs/api.md)__\n- __explanation how it works, check [Explanation](/docs/expl.md)__\n- [__Caveats__](#caveats)\n\n```javascript\nimport fp from 'lodash/fp'\nimport _ from 'lodash'\n//---------------------\nimport lz from 'lzdash'\n\nconst fpSuperSum = fp.flow(\n  fp.filter(v =\u003e v % 2 === 0),\n  fp.map(v =\u003e v * v),\n  fp.reduce((x, y) =\u003e x + y, 0)\n)\n\n// when u pass a collection to handle\n// it starts from reduce and ask for `y` arg to be evaluated\n// this request goes to map and then map do the same in relation to filter\n// filter ask collection to get 1 item and pass item to map if it fits the condition\n// filter holds map evaluation while predicate gives false (other words: condition is not true)\nconst lzSuperSum = lz.lazy(\n  lz.filter(v =\u003e v % 2 === 0),\n  lz.map(v =\u003e v * v),\n  lz.reduce((x, y) =\u003e x + y, 0)\n)\n\nconst data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n\nconst _filterResult = _.filter(data, v =\u003e v % 2 === 0) // 10 iterations =\u003e [2, 4, 6, 8, 10]\nconst _mapResult = _.map(_filterResult, v =\u003e v * v) // 5 iterations =\u003e [4, 16, 36, 64, 100]\nconst _result = _.reduce(_mapResult, (x, y) =\u003e x + y, 0) // 5 iterations =\u003e 220\n\nconsole.log(\n  fpSuperSum(data), // returns 220, iterations 10 by filter, 5 by map, 5 by reduce, total iterations 20\n  _result, // returns 220, iterations 10 by filter, 5 by map, 5 by reduce, total iterations 20\n  // ---------------------\n  lzSuperSum(data), // returns 220, total iterations 10 because of lazy nature + sharing\n)\n\n```\n\nIt has no external dependencies, so you can get started right away with:\n```\nyarn add lzdash\n// or\nnpm install lzdash\n```\n\n__What we have:__\n```javascript\nexport {\n  lazy,\n  map,\n  flatMap,\n  flatMapDeep,\n  flatten,\n  flattenDeep,\n  consecutive,\n  intersection,\n  intersectionBy,\n  difference,\n  differenceBy,\n  filter,\n  reject,\n  compact,\n  reduce,\n  take,\n  takeWhile,\n  drop,\n  dropWhile,\n  uniq,\n  uniqBy,\n  chunk,\n  zip,\n  zipWith,\n  groupBy,\n  countBy,\n  keys,\n  values,\n  entries,\n  fromPairs,\n  // Infinite/Lazy sources\n  lazySource,\n  range,\n  repeat,\n  generator,\n}\n```\n---\n## __Caveats:__\n[](#caveats)\n\nBecause of the lazy nature of some of the functions, __logical__ restrictions apply; explanation to why can be found below. Here is a list of restrictions:\n- `reduce`, `groupBy`, `countBy`, `fromPairs` makes sense to use only as trailing functions\n- `keys`, `values`, `entries` works a bit different in case if they are not leading (will be shown below)\n\n__NB!__: Main point here being: you can use them wherever you want in the pipeline, but in almost all cases it makes sense for some of them be either trailing or leading. Because they are lazy and work with args as well as other lazy functions (whisper: one by one).\n\n__Example of usage:__\n\n```javascript\nimport lz from 'lzdash'\n\n// # trailing functions\nlz.lazy(\n  lz.filter(value =\u003e value % 2 === 0),\n  lz.map(value =\u003e value ** 2),\n  lz.reduce(...)\n)\n\nlz.lazy(\n  lz.filter(value =\u003e value % 2 === 0),\n  lz.map(value =\u003e value ** 2),\n  lz.groupBy(...)\n)\n\nlz.lazy(\n  lz.filter(value =\u003e value % 2 === 0),\n  lz.map(value =\u003e value ** 2),\n  lz.countBy(...)\n)\n\n// # leading functions\n\nlz.lazy(lz.keys, ...otherFuncs)\nlz.lazy(lz.values, ...otherFuncs)\nlz.lazy(lz.entries, ...otherFuncs)\n```\n\nLet's start with `reduce/groupBy/countBy`:\n\nExample:\n```javascript\n\nconst lzReduce = lz.lazy(\n  lz.filter(value =\u003e value % 2 === 0),\n  lz.map(value =\u003e value ** 2),\n  lz.reduce((x, y) =\u003e x + y, 0)\n)\n\nlzReduce([1, 2, 3, 4, 5, 6]) // 56 -\u003e works fine\n\n// # BIG DIFF IS HERE\n\nconst lzReduce1 = lz.lazy(\n  lz.map(value =\u003e value ** 2),\n  lz.reduce((x, y) =\u003e x + y, 0),\n  lz.map(afterReduce =\u003e afterReduce) // yep that's possible\n)\n\n// pls note, that map takes all intermediate results\n// from reduce work, cuz reduce obey the rules\n// of lazy evaluation and produce one result per iteration\nlzReduce1([1, 2, 3]) // [1, 5, 14]\n\n```\n\nIn `lzReduce` reduce returns the result of only one iteration and that's why we get such an effect.\nIf this is not enough for you to understand, pls let me know in issues (tag your issue as [Question]) and I will replay as soon as I can.\n\n---\n\nWhen I'm talking about `keys/values/entries` I told that we have some diffs while working with this set of functions:\n- if you use them as leading functions, then there is no diff for u in comparison to other libs\n- if you use them inside flow (not leading position), it will take arg and do its magic over it, please take a look:\n\n```javascript\n\nconst fn = lz.lazy(\n  lz.keys,\n  lz.map(k =\u003e `key:${k}`)\n)\n\nfn({ a: 1, b: 2 }) // ['key:a', 'key:b']\n\n\nconst fnKeys = lz.lazy(\n  lz.map(v =\u003e v) // actually we can remove it and it will work the same.\n  lz.keys,\n  lz.map(key =\u003e `_${key}_`)\n)\n\n// lz.lazy(lz.keys, lz.map(key =\u003e `_${key}_`)) almost the same as code example above\n// but diff is in case if `keys` is leading func u can pass object to fnKeys\n// otherwise it should be an array\n\nconst data = [\n  { a: 1, b: 2 },\n  { c: 1, d: 2 },\n]\n\nfnKeys(data) // ['_a_', '_b_', '_c_', '_d_']\n\n```\n\nHere you see that object after first `map(v =\u003e v)` goes to `keys` function, `keys` create a sequence of keys and move first of them to next `map(key ....)` and that's why we got the result like this.\n\n---\nPlease, let me know if something still unclear for you and I will try to reveal all magic around.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshalimov%2Flzdash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshalimov%2Flzdash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshalimov%2Flzdash/lists"}