{"id":13507350,"url":"https://github.com/Dkendal/zipper_tree","last_synced_at":"2025-03-30T08:30:29.398Z","repository":{"id":27006003,"uuid":"30470077","full_name":"Dkendal/zipper_tree","owner":"Dkendal","description":"Variadic aritity tree with a zipper for Elixir!","archived":false,"fork":false,"pushed_at":"2015-03-08T21:45:27.000Z","size":280,"stargazers_count":19,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-27T06:11:48.479Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"wtfpl","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Dkendal.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}},"created_at":"2015-02-07T21:00:22.000Z","updated_at":"2023-12-27T09:48:58.000Z","dependencies_parsed_at":"2022-08-31T13:51:39.483Z","dependency_job_id":null,"html_url":"https://github.com/Dkendal/zipper_tree","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/Dkendal%2Fzipper_tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dkendal%2Fzipper_tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dkendal%2Fzipper_tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dkendal%2Fzipper_tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Dkendal","download_url":"https://codeload.github.com/Dkendal/zipper_tree/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246296325,"owners_count":20754623,"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":[],"created_at":"2024-08-01T02:00:31.802Z","updated_at":"2025-03-30T08:30:28.922Z","avatar_url":"https://github.com/Dkendal.png","language":"Elixir","funding_links":[],"categories":["Algorithms and Data structures"],"sub_categories":[],"readme":"ZipperTree\n==========\nProvides traversal and modification methods for variadic arity tree's. All\nmethods maintain an active 'cursor' or focus in the tree. The methods will\nalso technically work for lists too - I guess, if you're into that sorta\nthing.\n\nAll traversal and insertion methods happen in constant time with exception to\nup, which is porportional to how many nodes were junior to the current subtree.\n\nThis is an implementation of Gérard Huet's tree with a zipper (originally\npublished in [Functional Pearl: The\nZipper](https://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/huet-zipper.pdf)),\nessentially a direct conversion of the published oocaml code to elixir.\n\n## WTF is a Zipper\nA zipper is a novel method for encoding a focus, or position state of a collection\nin purely functional languages. The zipper is an analogy for the process of moving\nup and down the structure and how it can be thought of as opening and closing a zipper.\nFor a better description of the data structure I recommend you read the paper linked\nabove, although usage does not necessarily require you understand it's implementation.\n\n## Usage\nJust add `{:zipper_tree, \"~\u003e 0.1.1\"}` to your dependencies.\n\nThe implementation provided works for trees of variadic arity, simply define a\ntree using nested lists\n```elixir\niex(3)\u003e import ZipperTree\n\niex(4)\u003e tree = [\n  1,\n  2,\n  [\n    3,\n    4\n  ]\n]\n\n[1, 2, [3, 4]]\n\niex(5)\u003e tree\n  |\u003e nth(3)\n%ZipperTree.Loc{loc: [3, 4],\n path: %ZipperTree.Node{left: [2, 1], right: [], up: Top}}\n\niex(6)\u003e tree\n  |\u003e nth(3)\n  |\u003e right\n{:error, \"right of last\"}\n\niex(7)\u003e tree\n  |\u003e nth(3)\n  |\u003e down\n%ZipperTree.Loc{loc: 3,\n path: %ZipperTree.Node{left: [], right: [4],\n  up: %ZipperTree.Node{left: [2, 1], right: [], up: Top}}}\n\niex(8)\u003e tree\n  |\u003e nth(3)\n  |\u003e down\n  |\u003e right\n%ZipperTree.Loc{loc: 4,\n path: %ZipperTree.Node{left: [3], right: [],\n  up: %ZipperTree.Node{left: [2, 1], right: [], up: Top}}}\n\niex(9)\u003e tree\n  |\u003e nth(3)\n  |\u003e down\n  |\u003e right\n  |\u003e top\n%ZipperTree.Loc{loc: [1, 2, [3, 4]], path: Top}\n\niex(10)\u003e tree\n  |\u003e nth(3)\n  |\u003e down\n  |\u003e right\n  |\u003e change(:sup)\n  |\u003e top\n%ZipperTree.Loc{loc: [1, 2, [3, :sup]], path: Top}\n\niex(11)\u003e tree\n  |\u003e nth(3)\n  |\u003e down\n  |\u003e right\n  |\u003e insert_left(:over_here_now)\n  |\u003e top\n%ZipperTree.Loc{loc: [1, 2, [3, :over_here_now, 4]], path: Top}\n```\n\nThen move around the tree using `down`, `left`, `right`, `up`, `nth`, `top` and\nmake modifications with `change`, `insert_down`, `insert_left`, `insert_right`.\n\nFor specific method examples check the tests.\n\n## Road map\n- [x] traversal\n- [x] modification and insertion\n- [ ] implement protocols (Enum, etc.)\n- [ ] various search strategies\n- [ ] ???\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDkendal%2Fzipper_tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDkendal%2Fzipper_tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDkendal%2Fzipper_tree/lists"}