{"id":16659832,"url":"https://github.com/bsless/impedance","last_synced_at":"2025-07-08T05:13:51.103Z","repository":{"id":55867149,"uuid":"304891914","full_name":"bsless/impedance","owner":"bsless","description":"Fast declarative Clojure map transforms to solve impedance mismatch","archived":false,"fork":false,"pushed_at":"2020-12-10T15:57:56.000Z","size":24,"stargazers_count":56,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-08T19:34:37.438Z","etag":null,"topics":["clojure","data-driven","declarative","performance","transformations"],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bsless.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":"2020-10-17T14:08:36.000Z","updated_at":"2025-01-16T09:01:42.000Z","dependencies_parsed_at":"2022-08-15T08:10:15.498Z","dependency_job_id":null,"html_url":"https://github.com/bsless/impedance","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/bsless%2Fimpedance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsless%2Fimpedance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsless%2Fimpedance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsless%2Fimpedance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bsless","download_url":"https://codeload.github.com/bsless/impedance/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243832776,"owners_count":20355145,"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","data-driven","declarative","performance","transformations"],"created_at":"2024-10-12T10:26:46.068Z","updated_at":"2025-03-16T23:31:34.879Z","avatar_url":"https://github.com/bsless.png","language":"Clojure","readme":"[![Clojars Project](https://img.shields.io/clojars/v/bsless/impedance.svg)](https://clojars.org/bsless/impedance)\n[![cljdoc badge](https://cljdoc.org/badge/bsless/impedance)](https://cljdoc.org/d/bsless/impedance/CURRENT)\n[![CircleCI](https://circleci.com/gh/bsless/impedance/tree/master.svg?style=shield)](https://circleci.com/gh/bsless/impedance/tree/master)\n\n# Impedance\n\nTransform Clojure maps at speed.\n\n## Rationale\n\nIn electronics, impedance mismatch is a case where an electrical load's\nor source's impedance doesn't match that of the driver/sink system\n(respectively). Impedance matching allows us to maximize the power\ntransfer across that boundary.\n\nA similar phenomenon happens in software, where in the boundary between\nprocesses there is a mismatch between the representation model in one\nand the other. This library, like a transformer in electronics, allows\nus to easily transform an input map to look how our system would expect\nand maximize the information flow.\n\n### Just maps\n\nMaps are pervasive in Clojure for information modeling. While you can\ncheat and access vectors associatively, the library does not yet support\nmapping over sequences.\n\n## Why not Meander?\n\nMeander is great. It's feature rich and beautiful. It is a whole\narsenal. On the other hand, Impedance is a simple hatchet. Good for one\nthing, sharp enough, and simple. It's also faster.\n\n### Differences\n\n- No scanning or Cartesian product. Only leaves can be matched.\n\n### Performance differences\n\nAs tested with criterium:\n\n```clojure\n{:a {:b ?x :c ?y} \"x\" ?z} ;; from\n{:x ?x :y ?y :z ?z} ;; to\n;;; Bench transform default\n;;;              Execution time mean : 107.636019 ns\n;;; Bench transform checked\n;;;              Execution time mean : 76.051257 ns\n;;; Bench transform unchecked\n;;;              Execution time mean : 73.565921 ns\n;;; Bench meander\n;;;              Execution time mean : 430.781144 ns\n```\n\n## Usage\n\n### Dependency\n\n```clojure\n[bsless/impedance \"0.0.0-alpha1\"]\n```\n\n### A basic transformer\n\n```clojure\n(require '[impedance.transform :as t])\n(def f (t/transform {:a {:b ?x :c ?y} \"x\" ?z} {:x (inc ?x) :y ?y :z ?z}))\n(f {:a {:b 1 :c 2} \"x\" 3}) ;; =\u003e {:x 2, :y 2, :z 3}\n```\n\n### Creating a transformer programmatically\n\nWarning: uses `eval`. Use at your own risk.\n\n```clojure\n(def from {:a {:b ?x :c ?y} \"x\" ?z})\n(def to {:x (inc ?x) :y ?y :z ?z})\n(def f (t/eval-transform from to))\n(f {:a {:b 1 :c 2} \"x\" 3}) ;; =\u003e {:x 2, :y 2, :z 3}\n```\n\n### Inferred Context - Poor Man's jq\n\nAn alternate syntax for transformations is the inferred context one:\n\n```clojure\n(require '[impedance.context :as c])\n(c/with-inferred-context ctx\n  {:a {:b (or ^:? [:foo :bar] ^:? [:fizz :buzz])\n       :c ^:? [:fizz :bazz]}\n   :x ^:? [:foo :quux]})\n```\n\nHere, specify only the shape of the desired output, and use the `:?`\nmetadata on vectors to mark them as paths referring to the map `ctx`.\n\nThis syntax can be used to create and define functions:\n\n```clojure\n(fntx :checked\n      {:a {:b (or ^:? [:foo :bar] ^:? [:fizz :buzz])\n           :c ^:? [:fizz :bazz]}\n       :x ^:? [:foo :quux]})\n(defntx f :unchecked\n  {:a {:b (or ^:? [:foo :bar] ^:? [:fizz :buzz])\n       :c ^:? [:fizz :bazz]}\n   :x ^:? [:foo :quux]})\n```\n\n### Context compiler modes\n\nAll context compilers and transformers receive an optional argument for mode, which can be one of the following:\n- `:poly` - will use `clojure.core/get` to get values out of a collection. Highly polymorphic at the slight cost of performance.\n- `:unchecked` - will use direct method invoke of `.valAt` on an object. Will throw if an object doesn't implement `ILookup` and NPE for `nil`.\n- `:checked` - same as `:unchecked` but `nil` checks before every call to `.valAt`.\n\n## License\n\nCopyright © 2020 Ben Sless\n\nThis program and the accompanying materials are made available under the\nterms of the Eclipse Public License 2.0 which is available at\nhttp://www.eclipse.org/legal/epl-2.0.\n\nThis Source Code may also be made available under the following Secondary\nLicenses when the conditions for such availability set forth in the Eclipse\nPublic License, v. 2.0 are satisfied: GNU General Public License as published by\nthe Free Software Foundation, either version 2 of the License, or (at your\noption) any later version, with the GNU Classpath Exception which is available\nat https://www.gnu.org/software/classpath/license.html.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsless%2Fimpedance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbsless%2Fimpedance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsless%2Fimpedance/lists"}