{"id":15471951,"url":"https://github.com/mooreniemi/array_collapse","last_synced_at":"2025-04-22T13:46:45.785Z","repository":{"id":56842617,"uuid":"68460182","full_name":"mooreniemi/array_collapse","owner":"mooreniemi","description":":boom: Array#collapse","archived":false,"fork":false,"pushed_at":"2016-10-08T16:24:03.000Z","size":85,"stargazers_count":32,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T15:35:17.738Z","etag":null,"topics":["array","c-extension","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/mooreniemi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-17T15:22:54.000Z","updated_at":"2020-11-21T03:24:17.000Z","dependencies_parsed_at":"2022-08-29T07:42:15.807Z","dependency_job_id":null,"html_url":"https://github.com/mooreniemi/array_collapse","commit_stats":null,"previous_names":["mooreniemi/array-collapse"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mooreniemi%2Farray_collapse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mooreniemi%2Farray_collapse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mooreniemi%2Farray_collapse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mooreniemi%2Farray_collapse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mooreniemi","download_url":"https://codeload.github.com/mooreniemi/array_collapse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250251361,"owners_count":21399805,"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":["array","c-extension","ruby"],"created_at":"2024-10-02T02:22:38.243Z","updated_at":"2025-04-22T13:46:45.766Z","avatar_url":"https://github.com/mooreniemi.png","language":"Ruby","readme":"# Array#collapse\n\nA C extension alternative to using `flatten.compact` or `flatten.map`.\nSlight performance improvement (just a constant factor better) than the\ncommon idioms, with exactly the same memory performance.\n\n![collapse performance](perf.gif)\n\nSee [this blog post](http://mooreniemi.github.io/2016/09/15/flatten.html)\nfor the background and a chart of memory performance.\n\nIn addition, `collapse` makes two other slightly different choices from\ncore Ruby's `flatten`. 1. Attempting to `flatten` a recursive Array will\nerror normally. `collapse` just drops the recursive reference, and\ncontinues on its merry way. 2. `collapse` doesn't accept\na [level](https://ruby-doc.org/core-2.2.0/Array.html#method-i-flatten)\nargument. It's all or nothing.\n\n## Disclaimer\n\nShould you use this? Needing to compile a native extension for\na performance benefit that is not asymptotic is a trade-off I wouldn't\nalways make myself.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'array_collapse'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install array_collapse\n\n## Usage\n\n```ruby\n2.2.2 :001 \u003e require 'array_collapse'\n =\u003e true\n2.2.2 :002 \u003e [1, 2, [3], nil].collapse {|e| e.nil? ? e : e * 2 }\n =\u003e [2, 4, 6]\n2.2.2 :003 \u003e [1, [2, [3, nil]]].collapse\n =\u003e [1, 2, 3]\n2.2.2 :004 \u003e a = [1, [2, [3]]]\n =\u003e [1, [2, [3]]]\n2.2.2 :005 \u003e a \u003c\u003c a\n =\u003e [1, [2, [3]], [...]]\n2.2.2 :006 \u003e a.collapse {|e| e * 3 }\n =\u003e [3, 6, 9]\n2.2.2 :007 \u003e a.flatten\n =\u003e ArgumentError: tried to flatten recursive array\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on\n[GitHub](https://github.com/mooreniemi/array_collapse). This project is\nintended to be a safe, welcoming space for collaboration, and contributors\nare expected to adhere to the [Contributor\nCovenant](http://contributor-covenant.org) code of conduct.\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmooreniemi%2Farray_collapse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmooreniemi%2Farray_collapse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmooreniemi%2Farray_collapse/lists"}