{"id":22092860,"url":"https://github.com/toyokumo/nested-sets-clj","last_synced_at":"2025-07-24T20:32:24.615Z","repository":{"id":62434954,"uuid":"271429651","full_name":"toyokumo/nested-sets-clj","owner":"toyokumo","description":"Nested Sets Model for Clojure and ClojureScript","archived":false,"fork":false,"pushed_at":"2020-10-16T06:05:49.000Z","size":29,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-30T14:55:44.632Z","etag":null,"topics":["clojure","clojurescript","nested-sets"],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/toyokumo.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}},"created_at":"2020-06-11T02:10:01.000Z","updated_at":"2023-05-10T07:36:00.000Z","dependencies_parsed_at":"2022-11-01T21:02:21.966Z","dependency_job_id":null,"html_url":"https://github.com/toyokumo/nested-sets-clj","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toyokumo%2Fnested-sets-clj","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toyokumo%2Fnested-sets-clj/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toyokumo%2Fnested-sets-clj/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toyokumo%2Fnested-sets-clj/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/toyokumo","download_url":"https://codeload.github.com/toyokumo/nested-sets-clj/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227379611,"owners_count":17771862,"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":["clojure","clojurescript","nested-sets"],"created_at":"2024-12-01T03:11:07.505Z","updated_at":"2024-12-01T03:11:08.306Z","avatar_url":"https://github.com/toyokumo.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nested-sets-clj\nIt helps to use [Nested Sets Model](https://en.wikipedia.org/wiki/Nested_set_model) with Clojure and ClojureScript.\n\n[![CircleCI](https://circleci.com/gh/toyokumo/nested-sets-clj.svg?style=svg\u0026circle-token=c5ad3729a43000831bdfa56adb625c0584ea0b38)](https://circleci.com/gh/toyokumo/nested-sets-clj)\n[![cljdoc badge](https://cljdoc.org/badge/toyokumo/nested-sets-clj)](https://cljdoc.org/d/toyokumo/nested-sets-clj/CURRENT)\n[![Clojars Project](https://img.shields.io/clojars/v/toyokumo/nested-sets-clj.svg)](https://clojars.org/toyokumo/nested-sets-clj)\n\n## Usage\n\nMake a vector tree from nested sets which is sometimes gotton from DB.\n\n```clj\n(require '[nested-sets.core :as nested])\n\n;; A-----B-----C\n;; |\n;; |-----D-----E----F\n;; |     |     |\n;; |     |     -----G---H\n;; |      -----I\n(let [a {:id :a :lft 1 :rgt 18}\n      b {:id :b :lft 2 :rgt 5}\n      c {:id :c :lft 3 :rgt 4}\n      d {:id :d :lft 6 :rgt 17}\n      e {:id :e :lft 7 :rgt 14}\n      f {:id :f :lft 8 :rgt 9}\n      g {:id :g :lft 10 :rgt 13}\n      h {:id :h :lft 11 :rgt 12}\n      i {:id :i :lft 15 :rgt 16}]\n  (= [a\n      [b [c]]\n      [d\n       [e\n        [f]\n        [g [h]]]\n       [i]]]\n     (nested/nested-sets-\u003evec-tree [a b c d e f g h i])))\n;=\u003e true\n```\n\n`nested-sets-\u003evec-tree` can also take a function which controls how to make a node in the tree.\n\n```clojure\n(let [a {:id :a :lft 1 :rgt 18}\n      b {:id :b :lft 2 :rgt 5}\n      c {:id :c :lft 3 :rgt 4}\n      d {:id :d :lft 6 :rgt 17}\n      e {:id :e :lft 7 :rgt 14}\n      f {:id :f :lft 8 :rgt 9}\n      g {:id :g :lft 10 :rgt 13}\n      h {:id :h :lft 11 :rgt 12}\n      i {:id :i :lft 15 :rgt 16}]\n  (= [:Node a\n      [:Node b [:Node c]]\n      [:Node d\n       [:Node e\n        [:Node f]\n        [:Node g [:Node h]]]\n       [:Node i]]]\n     (nested/nested-sets-\u003evec-tree [a b c d e f g h i]\n                                   {:make-node (fn [node] [:Node node])})))\n;=\u003e true\n```\n\nOn the contary, it enable to make nested sets form a vector tree.\n\n```clj\n(require '[nested-sets.core :as nested])\n\n;; A-----B-----C\n;; |\n;; |-----D-----E----F\n;; |     |     |\n;; |     |     -----G---H\n;; |      -----I\n(let [a {:id :a}\n      b {:id :b}\n      c {:id :c}\n      d {:id :d}\n      e {:id :e}\n      f {:id :f}\n      g {:id :g}\n      h {:id :h}\n      i {:id :i}]\n  (= [{:id :a :lft 1 :rgt 18}\n      {:id :b :lft 2 :rgt 5}\n      {:id :c :lft 3 :rgt 4}\n      {:id :d :lft 6 :rgt 17}\n      {:id :e :lft 7 :rgt 14}\n      {:id :f :lft 8 :rgt 9}\n      {:id :g :lft 10 :rgt 13}\n      {:id :h :lft 11 :rgt 12}\n      {:id :i :lft 15 :rgt 16}]\n     (nested/vec-tree-\u003enested-sets [a\n                                    [b [c]]\n                                    [d\n                                     [e\n                                      [f]\n                                      [g [h]]]\n                                     [i]]])))\n;=\u003e true\n```\n\nIt also provides a function to make a vector tree from adjacency list.\n\n```clj\n(require '[nested-sets.core :as nested])\n\n;; A-----B-----C\n;; |\n;; |-----D-----E----F\n;; |     |     |\n;; |     |     -----G---H\n;; |      -----I\n(let [a {:id :a :parent-id nil}\n      b {:id :b :parent-id :a}\n      c {:id :c :parent-id :b}\n      d {:id :d :parent-id :a}\n      e {:id :e :parent-id :d}\n      f {:id :f :parent-id :e}\n      g {:id :g :parent-id :e}\n      h {:id :h :parent-id :g}\n      i {:id :i :parent-id :d}]\n  (= [a\n      [b [c]]\n      [d\n       [e\n        [f]\n        [g [h]]]\n       [i]]]\n     (nested/adjacency-list-\u003evec-tree :id :parent-id [a b c d e f g h i])))\n```\n\n`adjacency-list-\u003evec-tree` can also take a function which controls how to make a node in the tree.\n\n```clojure\n(let [a {:id :a :parent-id nil}\n      b {:id :b :parent-id :a}\n      c {:id :c :parent-id :b}\n      d {:id :d :parent-id :a}\n      e {:id :e :parent-id :d}\n      f {:id :f :parent-id :e}\n      g {:id :g :parent-id :e}\n      h {:id :h :parent-id :g}\n      i {:id :i :parent-id :d}]\n  (= [:Node a\n      [:Node b [:Node c]]\n      [:Node d\n       [:Node e\n        [:Node f]\n        [:Node g [:Node h]]]\n       [:Node i]]]\n     (nested/adjacency-list-\u003evec-tree :id\n                                      :parent-id\n                                      [a b c d e f g h i]\n                                      {:make-node (fn [node] [:Node node])})))\n```\n\n## License\n\nCopyright 2020 TOYOKUMO,Inc.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoyokumo%2Fnested-sets-clj","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoyokumo%2Fnested-sets-clj","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoyokumo%2Fnested-sets-clj/lists"}