{"id":23175766,"url":"https://github.com/treble37/nested_filter","last_synced_at":"2025-08-18T10:31:45.605Z","repository":{"id":19000547,"uuid":"85782137","full_name":"treble37/nested_filter","owner":"treble37","description":"Providing Map#drop (by key or value) and Map#take functionality for nested maps ","archived":false,"fork":false,"pushed_at":"2024-01-05T13:37:43.000Z","size":96,"stargazers_count":35,"open_issues_count":4,"forks_count":8,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-17T17:49:29.787Z","etag":null,"topics":["elixir","elixir-library","hacktoberfest","nested-maps"],"latest_commit_sha":null,"homepage":"","language":"Elixir","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/treble37.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2017-03-22T03:43:44.000Z","updated_at":"2023-11-15T02:29:39.000Z","dependencies_parsed_at":"2023-02-14T07:45:38.984Z","dependency_job_id":"21fd7181-b578-4c74-975a-4ea7690b3784","html_url":"https://github.com/treble37/nested_filter","commit_stats":{"total_commits":69,"total_committers":7,"mean_commits":9.857142857142858,"dds":"0.42028985507246375","last_synced_commit":"830684b34fc004a4d137d6f33ad08e51ec70cf3f"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treble37%2Fnested_filter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treble37%2Fnested_filter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treble37%2Fnested_filter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treble37%2Fnested_filter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/treble37","download_url":"https://codeload.github.com/treble37/nested_filter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230168504,"owners_count":18183939,"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":["elixir","elixir-library","hacktoberfest","nested-maps"],"created_at":"2024-12-18T06:09:22.095Z","updated_at":"2024-12-18T06:09:22.549Z","avatar_url":"https://github.com/treble37.png","language":"Elixir","readme":"# NestedFilter\n![Build](https://github.com/treble37/nested_filter/actions/workflows/nested_filter_ci.yml/badge.svg?branch=main)\n[![Maintainability](https://api.codeclimate.com/v1/badges/ba239c585908a0aad2ac/maintainability)](https://codeclimate.com/github/treble37/nested_filter/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/ba239c585908a0aad2ac/test_coverage)](https://codeclimate.com/github/treble37/nested_filter/test_coverage)\n[![Coverage Status](https://coveralls.io/repos/github/treble37/nested_filter/badge.svg?branch=master)](https://coveralls.io/github/treble37/nested_filter?branch=master)\n[![Hex.pm](https://img.shields.io/hexpm/v/nested_filter.svg)](https://hex.pm/packages/nested_filter)\n[![Hex.pm Downloads](https://img.shields.io/hexpm/dt/nested_filter.svg)](https://hex.pm/packages/nested_filter)\n[![GitHub stars](https://img.shields.io/github/stars/treble37/nested_filter.svg)](https://github.com/treble37/nested_filter/stargazers)\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/treble37/nested_filter/master/LICENSE)\n\n## The Problems\n\n1.  You have a nested map (or a struct that you converted to a nested map) and you want to remove ALL the keys with specific values such as nil.\n2.  You want to do a Map#take on a nested map\n\n##### Example: Remove all the map keys with nil values\n\n```elixir\nnested_map = %{a: 1, b: %{c: nil, d: nil}, c: nil}\n\nMap.drop(nested_map, [:c, :d])\n# =\u003e %{a: 1, b: %{c: nil, d: nil}}\n\n# But you actually wanted:\n# =\u003e %{a: 1}\n```\n\n## The Solution: NestedFilter\n\nNestedFilter drills down into a nested map and can do any of the following:\n\n1.  filters out keys according to user specified values.\n2.  filters out values according to user specified keys.\n\n## Installation\n\nIf [available in Hex](https://hex.pm/docs/publish), the package can be installed\nby adding `nested_filter` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [{:nested_filter, \"~\u003e 1.2.2\"}]\nend\n```\n\nDocumentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)\nand published on [HexDocs](https://hexdocs.pm). Once published, the docs can\nbe found at \u003chttps://hexdocs.pm/nested_filter\u003e.\n\n## Usage\n\nBy default, when removing user specified values, empty values will be preserved\n(see Case 1 below). You can add empty values to the user specified values list\nif you wish those \"empty values\" (e.g., empty maps) to be removed.\n\n### NestedFilter.drop_by_value\n\n```elixir\n# Case 1: Remove the nil values from a nested map, preserving empty map values\n\nnested_map = %{a: 1, b: %{m: nil, n: 2}, c: %{p: %{q: nil, r: nil}, s: %{t: 2, u: 3}} }\nNestedFilter.drop_by_value(nested_map, [nil])\n\n# =\u003e %{a: 1, b: %{n: 2}, c: %{p: %{}, s: %{t: 2, u: 3}} }\n\n# Case 2: Remove the nil values from a nested map, removing empty map values\n\nnested_map = %{a: 1, b: %{m: nil, n: 2}, c: %{p: %{q: nil, r: nil}, s: %{t: 2, u: 3}} }\nNestedFilter.drop_by_value(nested_map, [nil, %{}])\n# =\u003e %{a: 1, b: %{n: 2}, c: %{s: %{t: 2, u: 3}} }\n```\n\n### NestedFilter.drop_by_key\n\n```elixir\n# Case 1: Remove values from a nested map by key\n\nnested_map = %{a: 1, b: %{a: 2, b: 3}, c: %{a: %{a: 1, b: 2}, b: 2, c: %{d: 1, e: 2}}}\nassert NestedFilter.drop_by_key(nested_map, [:a]) == %{b: %{b: 3},c: %{b: 2, c: %{d: 1, e: 2}}}\n```\n\n### NestedFilter.take_by_key\n\n```elixir\n# Case 1: Take values from a nested map by key\n\nnested_map = %{a: %{b: 1}, c: 3, e: %{f: 4}}\nassert NestedFilter.take_by_key(nested_map, [:b, :f]) == %{b: 1, f: 4 }\n```\n\nYou can browse the tests for more usage examples.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftreble37%2Fnested_filter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftreble37%2Fnested_filter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftreble37%2Fnested_filter/lists"}