{"id":31595276,"url":"https://github.com/escherize/restructure","last_synced_at":"2026-03-03T16:02:01.558Z","repository":{"id":62434437,"uuid":"116171049","full_name":"escherize/restructure","owner":"escherize","description":"function based restructuring of clj{s} data","archived":false,"fork":false,"pushed_at":"2018-01-03T22:38:13.000Z","size":11,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-10-06T03:58:59.166Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/escherize.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":"2018-01-03T18:54:31.000Z","updated_at":"2022-02-14T15:16:30.000Z","dependencies_parsed_at":"2022-11-01T21:15:39.999Z","dependency_job_id":null,"html_url":"https://github.com/escherize/restructure","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/escherize/restructure","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/escherize%2Frestructure","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/escherize%2Frestructure/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/escherize%2Frestructure/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/escherize%2Frestructure/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/escherize","download_url":"https://codeload.github.com/escherize/restructure/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/escherize%2Frestructure/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30051098,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-03T15:26:47.567Z","status":"ssl_error","status_checked_at":"2026-03-03T15:26:17.132Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":"2025-10-06T03:58:54.863Z","updated_at":"2026-03-03T16:02:01.519Z","avatar_url":"https://github.com/escherize.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# restructure\n\nA Clojure library designed to declaritively reshape data.\n\n[![Clojars Project](https://img.shields.io/clojars/v/restructure.svg)](https://clojars.org/restructure)\n\n        _H_              _H_               _H_                  o88o.\n      .=|_|===========v==|_|============v==|_|===========.    (8%8898),\n     /                |                 |                 \\ ,(8888%8688)\n    /_________________|_________________|__________________(898%88688HJW)\n    |=|_|_|_|  =|_|_|=|X|)^^^(|X|=|/ \\|=||_|_|_|=| ||_|_|=|`(86888%8%9b)\n    |=|_|_|_|== |_|_|=|X|\\___/|X|=||_||=||_____|=|_||_|_|=|___(88%%8888)\n    |=_________= ,-. =|\"\"\"\"\"\"\"\"\"\"=\"\"\"\"\"=|=_________== == =|_______\\//`'\n    |=|__|__|_| //O\\\\=|X|\"\"\"\"\"|X|=//\"\\\\=|=|_|_|_|_| .---.=|.=====.||\n    |=|__|__|_|=|| ||=|X|_____|X|=|| ||=|=|_______|=||\"||=||=====|||\n    |___d%8b____||_||_|=_________=||_||_|__d8%o%8b_=|j_j|=|j==o==j|\\---\n## Usage\n\nI often find myself wondering what shape of data is expected by a certain piece of code.\n\nThis library sprang forth from those thoughts.\n\nConsider an api that will return to us information about a user. Of course, the information is presented to us in a manner that makes sense for the producer of the data rather than our purpoises. We want to =restructure= the data so that it makes senses for our usecases.\n\nUsing *restructure* we will define a function `user-function` which will reshape our data the way we want it.\n\n``` clojure\n(def user-function\n  (rs\n  ;; user-function expects a value like\n    {:user_id :rs/id\n     :user_info {:user_age_on_date [\"_\" :rs/age]}}\n    ;; and returns a restructured value that matches\n    {:id :rs/id :age :rs/age}))\n```\n\nNotice that the exact shape of the incoming data:\n\n```clojure\n(user-function\n  {:user_id  1910191\n   :user_info {:user_age_on_date [\"ignore me\" 10.5]}})\n;;=\u003e {:id 1910191, :age 10.5}\n```\n\nIf the input is missing a particular key, it will become nil:\n\n``` clojure\n(user-function {:user_id  1910191})\n;; =\u003e {:id 1910191, :age nil}\n```\n\nOther included keys are left alone:\n\n```clojure\n(user-function {:user_id  1910191\n                :user_info {:user_age_on_date [\"ignore me\" 10.5]}\n                :user_title \"Person\"})\n;;=\u003e {:id 1910191, :age 10.5, :user_title \"Person\"}\n```\n\nif you want to ensure the existance of certian keys:\n\n```clojure\n(def safe-user-function\n  (rs\n    {:user_id :rs/id\n     :user_info {:user_age_on_date [\"_\" :rs/age]}}\n    ;; and returns a restructured value that matches\n    {:id :rs/id :age :rs/age}\n    {:rs/id\n     #(when (nil? %)\n        (throw\n          (ex-info \"expected a value for :rs/id\" {:value :rs/id})))}))\n\n(safe-user-function {})\n;;=\u003e  1. Unhandled clojure.lang.ExceptionInfo\n;;=\u003e  expected a value for :rs/id\n;;=\u003e  {:value :rs/id}\n```\n\n### Notes\n\nNote that I used keywords with the rs namespace above. That's actually not nessicary to do.\n\nWe can also use _sample data_ to show exactly what we expect to recieve.\n\n``` clojure\n(rs {:user_info {:u_id 12345 :u_first_name \"Bryan\"}\n    {:name \"Bryan\" :id 12345})\n```\n\nThe function returned by the prior call to rs is identical to this:\n``` clojure\n(rs {:user_info {:u_id 0 :u_first_name 1}\n    {:name 1 :id 0})\n```\n\nand\n``` clojure\n(rs {:user_info {:u_id ::uid :u_first_name ::fn}\n    {:name ::fn :id ::uid})\n```\n\nSo the user has the flexibility to show what they mean, which is a noble principle to uphold.\n\n## License\n\nCopyright © 2018 Bryan Maass\n\nDistributed under the Eclipse Public License either version 1.0 or (at your option) any later version.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fescherize%2Frestructure","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fescherize%2Frestructure","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fescherize%2Frestructure/lists"}