{"id":16662720,"url":"https://github.com/gilch/saccharin","last_synced_at":"2026-05-27T18:31:32.837Z","repository":{"id":95425975,"uuid":"47665998","full_name":"gilch/saccharin","owner":"gilch","description":"Fake syntactic sugar with a metallic aftertaste! Because sometimes Java's hard to swallow.","archived":false,"fork":false,"pushed_at":"2016-10-11T16:37:23.000Z","size":44,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-12T21:36:36.339Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","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/gilch.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-12-09T03:23:36.000Z","updated_at":"2016-01-11T17:35:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"fc04eae3-e630-4b12-a94e-2f831940a13f","html_url":"https://github.com/gilch/saccharin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gilch/saccharin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilch%2Fsaccharin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilch%2Fsaccharin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilch%2Fsaccharin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilch%2Fsaccharin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gilch","download_url":"https://codeload.github.com/gilch/saccharin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilch%2Fsaccharin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33579665,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-27T02:00:06.184Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":"2024-10-12T10:38:42.874Z","updated_at":"2026-05-27T18:31:32.821Z","avatar_url":"https://github.com/gilch.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Saccharin\nSaccharin is a pure Java library that improves upon Java's tediously verbose syntax through clever\nuse of static imports, anonymous inner classes, chained method calls, and the like. Saccharin will\nmake your code shorter. It requires Java 6 or later.\n\nMany of these utilities are based on ideas from more expressive languages like Python, Haskell,\nLisp and even Java 8.\n\n## Fake Literal Syntax\nStrings have a simple literal syntax in Java: `\"Hello, World!\"`. It's simple and easy to use.\nJust imagine if you had to write\n```Java\nnew char[] {'H', 'e', 'l', 'l', 'o', ',', ' ', 'W', 'o', 'r', 'l', 'd', '!'}\n```\nevery time you needed a String? Crazy right? Not only is it harder to use, it's harder to read.\n\nStrings are an exception, but Java makes you put in that level of effort for other common data\nstructures, like mappings:\n```Java\nMap\u003cString, Integer\u003e fooNorf = new HashMap\u003cString, Integer\u003e();\nfooNorf.put(\"one\", 1);\nfooNorf.put(\"two\", 2);\nfooNorf.put(\"three\", 3);\n```\nBut in Python it's a breeze.\n```Python\nfooNorf = {'one': 1, 'two': 2, 'three' 3}\n```\nWhy can't it be that easy in Java?\n\nWith Saccharin it can be!\n```\nMap\u003cInteger, String\u003e fooNorf = _x(\"one\", 1)._(\"two\", 2)._(\"three\", 3);\n```\nTastes like syntactic sugar, but it's fake!\nThe above code is pure Java. No compiler hacks. No bytecode manipulation.\nThere have been no changes to the Java grammar whatsoever. It's a simple static import.\n\nOther common data structures use a similar short prefix.\n```Java\n//List view of an array ([t]uple)\n_t(1,2,3)\n//[f]rozen tuple (an unmodifiable List)\n_f(1,2,3)\n//double-ended [q]ueue\n_q(1,2,3)\n//dynamic [a]rray\n_a(1,2,3)\n// [s]et\n_s(1,2,3)\n// binary literals for Java 6 (long, but you can cast.)\n_0b(\"1010\"+\"0100\")\n```\nAs you may have guessed by now these are just static methods with short names.\nThe fake array literals have slightly longer names.\n```Java\n//array of reference types. The type is implied by the arguments.\nitems(\"foo\",\"bar\") // same as: new String[] {\"foo\", \"bar\"}\n//also works on primitives, but they're auto-boxed.\nitems(1,2,3) // same as: new Integer[] {1,2,3}\n//array of primitive types have their own methods.\nbooleans(true, false)\nchars(\"abc\")  // converts from a String.\nints(1,2,3)\nlongs(1,2,3)\nfloats(1,2,3)  // note the implicit casts.\ndoubles(1,2,3)\n// these are actually List views for easy collections interop,\nList\u003cCharacter\u003e foo = chars(\"abc\");\n// convert to array with the \"._\" suffix.\nchar[] foo = chars(\"abc\")._;\n```\nSimulate pass by reference with `Out` and `Thru`. A `Thru` is-an `Out`, but with an initial value.\n```Java\n// Out literal: _()\nOut\u003cDouble\u003e res = _();\nnew Object() {\n    void test(double a, double b, Out\u003cDouble\u003e res) {\n        res._ = a - b;\n    }\n}.test(3, 7, res);\nassertEquals(res, _(-4.0));\n// Thru literal: _(foo)\nThru\u003cString\u003e foo = _(\"foo\");\nThru\u003cString\u003e bar = _(\"bar\");\n// dereference with the usual \"._\" suffix.\nnew Object() {\n    void test(Thru\u003cString\u003e a, Thru\u003cString\u003e b) {\n        String temp = a._ + b._;\n        b._ += a._;\n        a._ = temp;\n    }\n}.test(foo, bar);\nassertEquals(foo._, \"foobar\");\n// Thru's will delegate equality to their contents.\nassertEquals(bar, _(\"barfoo\"));\n```\nThe cons cell uses the same prefix as `Out` and `Thru`, but with two arguments.\n```Java\n//cons cell. Pairs any two reference types. Even another cons cell.\n_(1,\"one\")\n//cons cell linked list. Arbitrary collections of mixed types with no casting!\n_\u003cFloat, _\u003cDouble, _\u003cCharacter, Void\u003e\u003e\u003e foo = _(1f, _(2d, _('3', null)));\n```\n\n\n\n## Sequence Operations\n### Lazy Sequences\n## Functional Style\n\nfilter/map/reduce\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgilch%2Fsaccharin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgilch%2Fsaccharin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgilch%2Fsaccharin/lists"}