{"id":16737517,"url":"https://github.com/alexb52/grizzly-rb","last_synced_at":"2025-03-15T22:12:13.369Z","repository":{"id":65590409,"uuid":"298921777","full_name":"AlexB52/grizzly-rb","owner":"AlexB52","description":"The Ruby library you will love to hate","archived":false,"fork":false,"pushed_at":"2023-05-17T09:51:47.000Z","size":446,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-11T21:11:17.070Z","etag":null,"topics":["array","collection","library","list","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/AlexB52.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-09-27T00:19:42.000Z","updated_at":"2023-01-30T20:16:48.000Z","dependencies_parsed_at":"2023-02-16T22:45:25.778Z","dependency_job_id":null,"html_url":"https://github.com/AlexB52/grizzly-rb","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexB52%2Fgrizzly-rb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexB52%2Fgrizzly-rb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexB52%2Fgrizzly-rb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexB52%2Fgrizzly-rb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlexB52","download_url":"https://codeload.github.com/AlexB52/grizzly-rb/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243796730,"owners_count":20349264,"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","collection","library","list","ruby"],"created_at":"2024-10-13T00:26:46.995Z","updated_at":"2025-03-15T22:12:13.348Z","avatar_url":"https://github.com/AlexB52.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":":anger: **DISCLAIMER** :anger:\n\nReading this README isn't for the faint of heart.\n\nThe library isn't meant to replace the Array and the purpose isn't to use it in production. Although you could use it in projects, every part of your body will tell you not to. It feels dirty, it feels **grisly**, yet it now exists, it's there and works as expected.\n\nYou will love to hate it.\n\n# Grizzly library\n\nThe Grizzly library is an attempt to end the predominance of the Array in Ruby by providing a collection that casts itself back while matching the whole Array interface. The work came after reading [Steve Klabnik's warning](https://steveklabnik.com/writing/beware-subclassing-ruby-core-classes) \u0026 [gist](https://gist.github.com/steveklabnik/6071687) about subclassing Ruby core classes. \n\nWe're testing the library against the [Ruby/Spec](https://github.com/ruby/spec) and covers most of the Array methods.\n\nThe library provides four classes/modules:\n\n* Grizzly::Collection (Array subclass)\n* Grizzly::Enumerable (Enumerable extension)\n* Grizzly::Enumerator (Enumerator decorator)\n* Grizzly::LazyEnumerator (Enumerator::Lazy decorator)\n\nYou can find them in the lib folder.\n\n**The Grizzly::Collection is a subclass of Array that works.**\n\n## Usage\n\nFor an extensive use of the library you can see this [file](examples/transactions.rb)\n\n```ruby\nrequire \"grizzly\"\n\nMark = Struct.new(:score)\n\nclass MarkCollection \u003c Grizzly::Collection\n  def average_score\n    sum(\u0026:score) / size.to_f\n  end\nend\n\nmarks = MarkCollection.new (0..100).to_a.map { |i| Mark.new(i) }\n\nmarks.select { |mark| mark.score.even? }.\n      average_score\n\n# =\u003e 50.0\n\nmarks.select { |mark| mark.score.even? }.\n      reject { |mark| mark.score \u003c= 80 }.\n      average_score\n\n# =\u003e 91.0\n```\n\n### Gotchas\n\n`Grizzly::Collection` methods try their best to return what you would expect. That said there are some methods with special behaviour.\n\n* `#map` returns an instance of the subclass and not an Array.\n* `#to_a` returns an Array\n* `#transpose`, `#product`, `#zip`, `#partition`, `#group_by`: check their implementation and specs as they return subgroups\n* `#grep` and `#grep_v` methods are not supported and will raise: See issue https://github.com/AlexB52/grizzly-rb/issues/8\n\n## Ruby support\n\nRuby 2.7+\n\n## Roadmap\n\n- [X] Array\n- [X] Enumerable\n- [X] Enumerator\n- [X] Lazy Enumerator\n- [X] Benchmarks\n\n## Benchmark\n\nYou can run the benchmark with `ruby benchmark.rb`\n\nThe benchmark runs over increments of list with 10\\*\\*n items for a total of 5_000_000 iterations.\n\n### Conclusions\n\nThis library initialize a new collection everytime the Array method returns.\n\nChaining methods with Grizzly::Collection is:\n  * really expensive for list with a small number of items. \u003c= 10\n  * less of a problem with lists over 100 items\n\n### Raw Results\n```\n=== One method ===\n{ |list| list.select(\u0026:odd?) }\n\n                                                                             user     system      total        real\nList of length 1 iterated over 5000000 times - Array                     1.465777   0.010639   1.476416 (  1.484419)\nList of length 1 iterated over 5000000 times - Grizzly::Collection       4.173212   0.025837   4.199049 (  4.219159)\n\n                                                                             user     system      total        real\nList of length 10 iterated over 500000 times - Array                     0.449475   0.002248   0.451723 (  0.453940)\nList of length 10 iterated over 500000 times - Grizzly::Collection       0.848438   0.006855   0.855293 (  0.858316)\n\n                                                                             user     system      total        real\nList of length 100 iterated over 50000 times - Array                     0.342236   0.003515   0.345751 (  0.347207)\nList of length 100 iterated over 50000 times - Grizzly::Collection       0.389331   0.005771   0.395102 (  0.396907)\n\n                                                                             user     system      total        real\nList of length 1000 iterated over 5000 times - Array                     0.367041   0.013971   0.381012 (  0.384799)\nList of length 1000 iterated over 5000 times - Grizzly::Collection       0.338568   0.007703   0.346271 (  0.347265)\n\n                                                                             user     system      total        real\nList of length 10000 iterated over 500 times - Array                     0.332582   0.008056   0.340638 (  0.341963)\nList of length 10000 iterated over 500 times - Grizzly::Collection       0.338311   0.016007   0.354318 (  0.356256)\n\n\n=== Two chained methods ===\n{ |list| list.select(\u0026:odd?).reject(\u0026:odd?) }\n\n                                                                             user     system      total        real\nList of length 1 iterated over 5000000 times - Array                     2.087311   0.016413   2.103724 (  2.114187)\nList of length 1 iterated over 5000000 times - Grizzly::Collection       8.177386   0.051953   8.229339 (  8.265598)\n\n                                                                             user     system      total        real\nList of length 10 iterated over 500000 times - Array                     0.649130   0.002928   0.652058 (  0.654708)\nList of length 10 iterated over 500000 times - Grizzly::Collection       1.408604   0.009925   1.418529 (  1.424733)\n\n                                                                             user     system      total        real\nList of length 100 iterated over 50000 times - Array                     0.503027   0.001814   0.504841 (  0.506741)\nList of length 100 iterated over 50000 times - Grizzly::Collection       0.623167   0.005466   0.628633 (  0.632303)\n\n                                                                             user     system      total        real\nList of length 1000 iterated over 5000 times - Array                     0.486371   0.003466   0.489837 (  0.491048)\nList of length 1000 iterated over 5000 times - Grizzly::Collection       0.500942   0.005642   0.506584 (  0.509051)\n\n                                                                             user     system      total        real\nList of length 10000 iterated over 500 times - Array                     0.492759   0.008542   0.501301 (  0.503459)\nList of length 10000 iterated over 500 times - Grizzly::Collection       0.514448   0.014804   0.529252 (  0.531968)\n\n\n=== Chained enumerators ===\n{ |list| list.select.each.select.reject(\u0026:odd?) }\n\n                                                                             user     system      total        real\nList of length 1 iterated over 5000000 times - Array                     5.537677   0.066783   5.604460 (  5.630154)\nList of length 1 iterated over 5000000 times - Grizzly::Collection      30.203623   0.230334  30.433957 ( 30.573476)\n\n                                                                             user     system      total        real\nList of length 10 iterated over 500000 times - Array                     1.060200   0.008406   1.068606 (  1.073304)\nList of length 10 iterated over 500000 times - Grizzly::Collection       3.674943   0.029664   3.704607 (  3.721847)\n\n                                                                             user     system      total        real\nList of length 100 iterated over 50000 times - Array                     0.570368   0.003019   0.573387 (  0.575771)\nList of length 100 iterated over 50000 times - Grizzly::Collection       0.895747   0.005782   0.901529 (  0.906251)\n\n                                                                             user     system      total        real\nList of length 1000 iterated over 5000 times - Array                     0.518924   0.003155   0.522079 (  0.524788)\nList of length 1000 iterated over 5000 times - Grizzly::Collection       0.553667   0.004346   0.558013 (  0.560381)\n\n                                                                             user     system      total        real\nList of length 10000 iterated over 500 times - Array                     0.518883   0.010600   0.529483 (  0.531777)\nList of length 10000 iterated over 500 times - Grizzly::Collection       0.528470   0.014786   0.543256 (  0.545524)\n```\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'grizzly-rb', require: 'grizzly'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install grizzly-rb\n\n## Development\n\n```bash\n# Setup dependencies: bundler, mspec and ruby-spec\n$ bin/setup\n\n# Run all specs\n$ bin/test\n```\n\n### Prototype with console\n\nYou can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/grizzly-rb.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexb52%2Fgrizzly-rb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexb52%2Fgrizzly-rb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexb52%2Fgrizzly-rb/lists"}