{"id":21870628,"url":"https://github.com/matthewstyler/chain_lua","last_synced_at":"2025-08-03T19:08:33.316Z","repository":{"id":131046165,"uuid":"443666632","full_name":"matthewstyler/chain_lua","owner":"matthewstyler","description":"A small simple functional programming library for Lua","archived":false,"fork":false,"pushed_at":"2022-01-02T02:59:22.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-21T22:22:57.262Z","etag":null,"topics":["functional-programming","functional-programming-in-lua","lua","lua-library","lua-script"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matthewstyler.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-02T02:39:13.000Z","updated_at":"2024-03-14T14:26:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"9b37ea12-0f88-4caf-933c-61ea5a7d4fcf","html_url":"https://github.com/matthewstyler/chain_lua","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/matthewstyler/chain_lua","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthewstyler%2Fchain_lua","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthewstyler%2Fchain_lua/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthewstyler%2Fchain_lua/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthewstyler%2Fchain_lua/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matthewstyler","download_url":"https://codeload.github.com/matthewstyler/chain_lua/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthewstyler%2Fchain_lua/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268597489,"owners_count":24276015,"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","status":"online","status_checked_at":"2025-08-03T02:00:12.545Z","response_time":2577,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","functional-programming-in-lua","lua","lua-library","lua-script"],"created_at":"2024-11-28T06:12:02.164Z","updated_at":"2025-08-03T19:08:33.234Z","avatar_url":"https://github.com/matthewstyler.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Chain Lua\n\nChain Lua is a small easy to understand functional library implemented as a module that can wrap Lua tables.\n\nFunction invocations follow the fluent inteface, enabling method chaining for complex but human readable operations:\n\n\n```lua\nChain = require 'Chain'\n\nlocal t1 = Chain:with({ foo = \"bar\", one = \"two\", three = \"four\" })  \n\nlocal output = \n  t1:merge({ five = \"six\" }):\n  map(function(k, v) return k, v .. \"mapped\" end):\n  reject_unless(function(k, v) return k == \"foo\" or v == \"sixmapped\" end)\n ```\n \n ## How To Chain\n-  Create a new chain with an empty table with `Chain:new()`\n-  Wrap an existing table using `Chain:with(...)`\n\n\n\nWhen wrapping an existing table, the exisitng meta table is saved and used to lookup fields before `Chain`:\n\n```lua\n..\nlocal orig_meta_table = getmetatable(t)\n\nindex = {\n  __index = function(g, k)\n    if orig_meta_table and orig_meta_table[k] then\n      return orig_meta_table[k]\n    elseif k == \"is_a_chain\" then\n      return true\n    else\n      return self[k]\n    end\n  end,\n  __original_meta_table = orig_meta_table,\n}\nsetmetatable(t, index)\n```\n\nUnlinking resets the table to its original meta table:\n\n```lua\nfunction Chain:unlink()\n  setmetatable(self, getmetatable(self).__original_meta_table)\n\n  return self\nend\n```\n \n ## Mutation\n \n Functions that alter the internal table state have two flavours: functions with `inline` in the title mutate the table while those without implicitly return a new table instance:\n \n ```lua\n function Chain:merge_inline(t)\n  assert_table(t)\n\n  for k, v in pairs(t) do\n    self[k] = v\n  end\n\n  return self\nend\n\nfunction Chain:merge(t) return Chain:new():merge_inline(self):merge_inline(t) end\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatthewstyler%2Fchain_lua","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatthewstyler%2Fchain_lua","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatthewstyler%2Fchain_lua/lists"}