{"id":20780680,"url":"https://github.com/aroemers/lifted","last_synced_at":"2025-04-30T20:34:00.123Z","repository":{"id":62432730,"uuid":"265667274","full_name":"aroemers/lifted","owner":"aroemers","description":"Clojure library to lift functions into protocols","archived":false,"fork":false,"pushed_at":"2024-05-24T19:42:30.000Z","size":81,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-30T20:33:38.514Z","etag":null,"topics":["clojure","protocols"],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aroemers.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-20T19:27:12.000Z","updated_at":"2024-05-24T19:42:33.000Z","dependencies_parsed_at":"2024-11-18T00:31:23.455Z","dependency_job_id":null,"html_url":"https://github.com/aroemers/lifted","commit_stats":{"total_commits":10,"total_committers":3,"mean_commits":"3.3333333333333335","dds":0.5,"last_synced_commit":"83855abba2b47e92c17320a046c1a13d97a5a8d7"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aroemers%2Flifted","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aroemers%2Flifted/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aroemers%2Flifted/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aroemers%2Flifted/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aroemers","download_url":"https://codeload.github.com/aroemers/lifted/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251777773,"owners_count":21642223,"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","protocols"],"created_at":"2024-11-17T13:38:50.929Z","updated_at":"2025-04-30T20:34:00.101Z","avatar_url":"https://github.com/aroemers.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Clojars Project](https://img.shields.io/clojars/v/functionalbytes/lifted.svg)](https://clojars.org/functionalbytes/lifted)\n[![cljdoc badge](https://cljdoc.org/badge/functionalbytes/lifted)](https://cljdoc.org/d/functionalbytes/lifted/CURRENT)\n[![Clojure CI](https://github.com/aroemers/lifted/workflows/Clojure%20CI/badge.svg?branch=master)](https://github.com/aroemers/lifted/actions?query=workflow%3A%22Clojure+CI%22)\n[![Clojars Project](https://img.shields.io/clojars/dt/functionalbytes/lifted?color=blue)](https://clojars.org/functionalbytes/lifted)\n[![Blogpost](https://img.shields.io/badge/blog-Introducing%20lifted-blue)](https://functionalbytes.nl/clojure/lifted/protocols/2020/06/11/lifted.html)\n\n# 🚡 Lifted\n\nA small Clojure library for lifting functions into protocols.\nIt allows an easy way to protocolize a (default) implementation, which can be useful for testing (mocking) purposes for example.\n\n![Banner](banner.png)\n\n## Usage\n\nThe library offers two macros and a function.\n\n```clj\n(require '[lifted.core :refer [lift-as lift-on lifted]])\n```\n\nThe `lift-as` macro declares a protocol.\nIts sole argument is the name of the protocol to declare.\nThe macro \"lifts\" the functions in the current namespace which names are prefixed with the `-` character into the protocol.\nThe prefix is stripped from the protocol function names.\nOnly those functions which take at least one argument are lifted.\n\nFor example, let's create a simple prefixed function:\n\n```clj\n(defn -incr\n  \"Incrementer function.\"\n  ([this] (-incr this 1))\n  ([this n] (+ this n)))\n\n(lift-as Incrementer)\n```\n\nThe `lift-as` macro above expands to:\n\n```clj\n(defprotocol Incrementer\n  (incr [this] [this n]\n    \"Incrementer function.\"))\n```\n\nThe `lift-on` macro creates a protocol implementation.\nIts two arguments are the protocol to implement and the object to use as `this`.\nThe protocol simply forwards the calls to the prefixed functions, passing the `this` object as the first argument.\nFor example:\n\n```clj\n(def i (lift-on Incrementer 5))\n```\n\nThe `lift-on` macro above expands to:\n\n```clj\n(def i\n  (let [G__3427 5]\n    (reify Incrementer\n      (incr [this] (-incr G__3427))\n      (incr [this n] (-incr G__3427 n))\n\n      lifted.core/Lifted\n      (lifted [_] G__3427)))\n```\n\nNow you can use the protocol implementation as you would with any protocol.\n\n```\n(incr i)\n;=\u003e 6\n\n(incr i 10)\n;=\u003e 15\n```\n\nTo retrieve the object on which the protocol implementation was lifted on, you can use the `lifted` function.\nFor example:\n\n```clj\n(lifted i)\n;=\u003e 5\n```\n\n### Closing remarks\n\n#### Varargs\n\nClojure protocols do not support varargs.\nTherefore the lifted function argument lists with a vararg are normally stripped from the protocol.\nIf however one needs varargs, you can pass an option map to `lift-as` as follows:\n\n```clj\n(defn -vararg-test [y \u0026 ys]\n  ...)\n\n(lift-as VarargTest {:expand-varargs-for #{vararg-test}})\n```\n\nThis will expand the vararg into concrete arguments, up to a maximum of 20 total arguments.\nFor example, above `lift-as` macro would expand to:\n\n```clj\n(defprotocol VarargTest\n  (vararg-test [y] [y ys_0] [y ys_0 ys_1] . . . [y ys_0 ys_1 .. ys_18]))\n```\n\nThe rule still applies that for a function to be lifted it should at least take one argument.\n\n#### Destructuring\n\nThe macros do not support destructuring syntax in the signatures of the to-be lifted functions.\nPlease do the destructuring inside the function, using a `let` for example.\n\n_That's it. Enjoy!_ 🚀\n\n## License\n\nCopyright © 2020-2024 Functional Bytes\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faroemers%2Flifted","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faroemers%2Flifted","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faroemers%2Flifted/lists"}