{"id":18511723,"url":"https://github.com/jeremywrnr/deepmap","last_synced_at":"2025-04-09T04:34:02.280Z","repository":{"id":62556953,"uuid":"56622707","full_name":"jeremywrnr/deepmap","owner":"jeremywrnr","description":":milky_way: deep ruby hash/array map","archived":false,"fork":false,"pushed_at":"2023-03-10T01:05:33.000Z","size":14,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-23T23:43:13.235Z","etag":null,"topics":["hash","map","ruby","rubygems"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/deepmap","language":"Ruby","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/jeremywrnr.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}},"created_at":"2016-04-19T18:46:53.000Z","updated_at":"2023-03-10T01:06:40.000Z","dependencies_parsed_at":"2022-11-03T06:15:23.204Z","dependency_job_id":null,"html_url":"https://github.com/jeremywrnr/deepmap","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeremywrnr%2Fdeepmap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeremywrnr%2Fdeepmap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeremywrnr%2Fdeepmap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeremywrnr%2Fdeepmap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jeremywrnr","download_url":"https://codeload.github.com/jeremywrnr/deepmap/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247980830,"owners_count":21027803,"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":["hash","map","ruby","rubygems"],"created_at":"2024-11-06T15:29:33.471Z","updated_at":"2025-04-09T04:34:01.868Z","avatar_url":"https://github.com/jeremywrnr.png","language":"Ruby","readme":"# deepmap\n\n[![Gem Version](https://badge.fury.io/rb/deepmap.svg)](https://badge.fury.io/rb/deepmap)\n[![MIT](https://img.shields.io/npm/l/alt.svg?style=flat)](http://jeremywrnr.com/mit-license)\n\n## setup\n\n    [sudo] gem install deepmap\n\n## about\n\nRuby gem that adds three methods to the Hash and Array classes. Overview:\n\n* `#deep_map` - apply block to each key and value in object\n* `#key_map` - apply block to each key in object\n* `#val_map` - apply block to each value in object\n\nThese may be useful when you want to apply a function to each value (or key or\npair) of a complex nested object (such as the result of parsing a YAML or JSON\nfile), which can have hashes or arrays as subfields. The function currently\nneeds to be passed in as a block (see usage).\n\n## usage\n\n```ruby\nirb(main):001:0\u003e require 'deepmap'\n=\u003e true\n\nirb(main):002:0\u003e test = { 1 =\u003e 4, 2 =\u003e [5, 6], 3 =\u003e { 4 =\u003e [1, 2, { 5 =\u003e 10 }] } }\n=\u003e {1=\u003e4, 2=\u003e[5, 6], 3=\u003e{4=\u003e[1, 2, {5=\u003e10}]}}\n\nirb(main):003:0\u003e test.deep_map {|i| i.to_i * 2 }\n=\u003e {2=\u003e8, 4=\u003e[10, 12], 6=\u003e{8=\u003e[2, 4, {10=\u003e20}]}}\n\nirb(main):004:0\u003e test.key_map {|i| i.to_i * 2 }\n=\u003e {2=\u003e4, 4=\u003e[5, 6], 6=\u003e{8=\u003e[1, 2, {10=\u003e10}]}}\n\nirb(main):005:0\u003e test.val_map {|i| i.to_i * 2 }\n=\u003e {1=\u003e8, 2=\u003e[10, 12], 3=\u003e{4=\u003e[2, 4, {5=\u003e20}]}}\n```\n\nOnce you `require 'deepmap'`, you can call any of the three provided functions\non any (existing or new!) hash or array, as demonstrated above. You can also\nuse the (`\u0026:method`) shortcut to call a method on each object concisely:\n\n```ruby\nirb(main):002:0\u003e test = { 'a' =\u003e 'b', 'c' =\u003e ['d', 'e'], 'f' =\u003e { 'g' =\u003e ['h', 'i', { 'j' =\u003e 'k' }] } }\n=\u003e {\"a\"=\u003e\"b\", \"c\"=\u003e[\"d\", \"e\"], \"f\"=\u003e{\"g\"=\u003e[\"h\", \"i\", {\"j\"=\u003e\"k\"}]}}\n\nirb(main):003:0\u003e test.deep_map(\u0026:upcase)\n=\u003e {\"A\"=\u003e\"B\", \"C\"=\u003e[\"D\", \"E\"], \"F\"=\u003e{\"G\"=\u003e[\"H\", \"I\", {\"J\"=\u003e\"K\"}]}}\n\nirb(main):004:0\u003e test.key_map(\u0026:upcase)\n=\u003e {\"A\"=\u003e\"b\", \"C\"=\u003e[\"d\", \"e\"], \"F\"=\u003e{\"G\"=\u003e[\"h\", \"i\", {\"J\"=\u003e\"k\"}]}}\n\nirb(main):005:0\u003e test.val_map(\u0026:upcase)\n=\u003e {\"a\"=\u003e\"B\", \"c\"=\u003e[\"D\", \"E\"], \"f\"=\u003e{\"g\"=\u003e[\"H\", \"I\", {\"j\"=\u003e\"K\"}]}}\n```\n\n## development / testing\n\nFirst, clone this repo:\n\n    git clone https://github.com/jeremywrnr/deepmap.git\n\nTo build from source, first install the project dependencies. This project\nuses `bundler`, the standard ruby gem management system. If you don't have it,\ntry running `gem install bundler`. Once that is done:\n\n    bundle install\n\nNow, we should be able to build the gem locally. This will build the local\ndeepmap gem and link it in your path, so you can playing around with `deepmap`.\n\n    bundle exec rake build\n\nThis uses `rspec` and `rake` to run a suite of unit tests. To run the suite:\n\n    bundle exec rake\n\n## todo\n\n* collison checking/warning/confirmation workflow\n* support key-val iteration in mapping over vals/keys. This would allow support\n  for mapping conditionally based on a key/value, even if you are iterating\n  over all values/keys (`key_map {|k, v| k \u003e 0 ? k : v }`).\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeremywrnr%2Fdeepmap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeremywrnr%2Fdeepmap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeremywrnr%2Fdeepmap/lists"}