{"id":16681759,"url":"https://github.com/casidiablo/ganjika","last_synced_at":"2025-04-09T23:13:20.425Z","repository":{"id":28484481,"uuid":"32000602","full_name":"casidiablo/ganjika","owner":"casidiablo","description":"Java interop glue","archived":false,"fork":false,"pushed_at":"2016-02-18T15:35:57.000Z","size":208,"stargazers_count":2,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T23:13:11.833Z","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/casidiablo.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-03-11T05:45:21.000Z","updated_at":"2015-10-26T05:07:03.000Z","dependencies_parsed_at":"2022-09-03T05:20:49.026Z","dependency_job_id":null,"html_url":"https://github.com/casidiablo/ganjika","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/casidiablo%2Fganjika","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casidiablo%2Fganjika/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casidiablo%2Fganjika/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casidiablo%2Fganjika/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/casidiablo","download_url":"https://codeload.github.com/casidiablo/ganjika/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248125589,"owners_count":21051770,"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-10-12T14:05:13.104Z","updated_at":"2025-04-09T23:13:20.407Z","avatar_url":"https://github.com/casidiablo.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ganjika\n\nGanjika is a library that makes Java interop more clojurish. It provides\nthe `def-java-fns` macro which will define clojure-like functions out of\na Java class or object. This is what it does for you:\n\n- Makes unnecessary to write/use the usual boilerplate associated with\n  wrapping Java libraries\n- Optional and customizable layer of type coercion\n- Optional currying\n- Optional namespacing\n- Optional type-hinting\n\n## Usage\n\nAdd to leiningen `[ganjika 0.3.1]`. Then:\n\n```clojure\n(use 'ganjika.core)\n\n;; This defines clojure-like functions in the current namespace, which are\n;; curried with the provided instance:\n(def robot (new java.awt.Robot))\n(def-java-fns #'robot)\n;; This means now you can do: (mouse-move 200 50) instead of the usual\n;; way (.mouseMove robot 200 50). Notice that the instance was curried.\n\n;; You can specify a namespace to define the functions:\n(def-java-fns #'robot :using-ns 'my.robot)\n(my.robot/mouse-move 30 400)\n\n;; Use refer (instead of require/use) to avoid the namespace prefix\n(refer 'my.robot :only ['mouse-move])\n\n;; In some scenarios currying is not desirable:\n(def-java-fns java.awt.Robot :disable-currying)\n(mouse-move robot 30 400)\n\n;; By default the functions are defined using type hinting. This\n;; behavior can be changed by doing:\n(def-java-fns #'robot :disable-type-hinting)\n\n;; By default functions parameters are coerced to the underlying method\n;; types. If that's a problem it can be disabled:\n(def-java-fns #'robot :disable-coercion)\n\n;; It is possible to filter which functions will be defined by providing\n;; a predicate that must return false or nil when the provided method\n;; must be ignored:\n(def-java-fns #'robot\n  :method-predicate #(not= \"someIgnoredMethod\" (.getName %)))\n```\n\n## Coercion\n\nImagine a Java class defined like this:\n\n```java\npublic void someMethod(String[] list) {\n  // something\n}\n```\n\nIn order to call this from clojure you might have to do something like:\n\n```clojure\n(def obj (new SomeClass))\n(def arr (make-array String 2))\n(aset arr 0 \"foo\")\n(aset arr 1 \"bar\")\n(.someMethod obj arr)\n```\n\nganjika will coerce the function parameters by default, which means you an just do:\n\n```clojure\n;; the vector will be coerced to an array of strings\n(some-method [\"foo\" \"bar\"])\n```\n\nCoercion is driven by an internal map that looks like this:\n\n```clojure\n{src-type-1 {dest-type1 fn1\n             dest-type2 fn2}}\n```\n\nEach top entry in the map represents a supported source type; the inner\nmap represents the supported destination types providing functions that\nwill coerce src-type to dest-type.\n\nThis map can be modified via :coercions-transformer\n\n```clojure\n(def-java-fns #'something\n  :coercions-transformer #(assoc % additional-src-type {des-type fn}))\n```\n\n### TODO\n\n- Take into account repeated arities for methods with the same name but\n  different modifiers (static/non-static)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcasidiablo%2Fganjika","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcasidiablo%2Fganjika","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcasidiablo%2Fganjika/lists"}