{"id":18473427,"url":"https://github.com/0xopenbytes/c","last_synced_at":"2025-07-17T07:03:13.886Z","repository":{"id":40253631,"uuid":"462946795","full_name":"0xOpenBytes/c","owner":"0xOpenBytes","description":"📦 Micro Composition using Transformations and Cache","archived":false,"fork":false,"pushed_at":"2023-03-06T23:45:37.000Z","size":35,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-16T07:13:38.259Z","etag":null,"topics":["cache","swift","transformations","transformers"],"latest_commit_sha":null,"homepage":"https://0xopenbytes.github.io/c/","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/0xOpenBytes.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":"2022-02-23T23:59:01.000Z","updated_at":"2024-11-02T17:58:22.000Z","dependencies_parsed_at":"2024-11-06T10:43:49.009Z","dependency_job_id":null,"html_url":"https://github.com/0xOpenBytes/c","commit_stats":{"total_commits":39,"total_committers":2,"mean_commits":19.5,"dds":0.02564102564102566,"last_synced_commit":"36eeea26335183a759006d6e7a32fbf19fbe3cb8"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/0xOpenBytes/c","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xOpenBytes%2Fc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xOpenBytes%2Fc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xOpenBytes%2Fc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xOpenBytes%2Fc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/0xOpenBytes","download_url":"https://codeload.github.com/0xOpenBytes/c/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xOpenBytes%2Fc/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265575438,"owners_count":23790772,"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":["cache","swift","transformations","transformers"],"created_at":"2024-11-06T10:24:54.713Z","updated_at":"2025-07-17T07:03:13.834Z","avatar_url":"https://github.com/0xOpenBytes.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n   \u003cimg src=\"https://openbytes.dev/assets/projects/images/openbytes-c.png\" alt=\"Icon representing the OpenBytes c project.\" width=\"35%\"/\u003e\n   \u003ch1\u003ec\u003c/h1\u003e\n   \u003ch3\u003eMicro Composition\u003c/h3\u003e\n   \u003ca href=\"https://github.com/0xOpenBytes/c/blob/main/LICENSE\"\u003e\n     \u003cimg src=\"https://img.shields.io/badge/license-MIT-blue\" alt=\"MIT License\"/\u003e\n   \u003c/a\u003e\n   \u003cimg src=\"https://img.shields.io/github/v/release/0xOpenBytes/c\"/\u003e\n   \u003ca href=\"https://discord.gg/HUmaDXVsW7\"\u003e\n     \u003cimg src=\"https://img.shields.io/discord/933406727150391376\" alt=\"Community Chat\"/\u003e\n   \u003c/a\u003e\n \u003c/div\u003e\n\n## What is `c`?\n`c` is a simple composition framework. You have the ability to create transformations that are either unidirectional or bidirectional. There is also a cache that values can be set and resolved. \n\n## Where can `c` be used?\n`c` can be used anywhere to create transformations or interact with the cache.\n\n## Examples\n\n### BiDirectionalTransformation of String and Int\n\n```swift\nlet transformer = c.transformer(\n    from: { string in Int(string) },\n    to: { int in \"\\(String(describing: int))\" }\n)\n\nlet string = transformer.to(3)\nlet int = transformer.from(\"3\")\n\ntry t.assert(transformer.to(int), isEqualTo: string)\n```\n\n### Cache\n\n```swift\nlet cache = c.Cache()\n\ncache.set(value: Double.pi, forKey: \"🥧\")\n\nlet pi: Double = cache.get(\"🥧\") ?? 0\n\ntry t.assert(pi, isEqualTo: .pi)\n\nlet resolvedValue: Double = try cache.resolve(\"🥧\")\n\ntry t.assert(resolvedValue, isEqualTo: .pi)\n                    \ncache.remove(\"🥧\")\n\nlet nilValue: Double? = cache.get(\"🥧\")\n\ntry t.assert(isNil: nilValue)\n```\n\n### Cache\n\n```swift\nenum CacheKey: Hashable { ... }\n\nlet cache = c.Cache\u003cCacheKey, Any\u003e()\n\ncache.set(value: Double.pi, forKey: CacheKey.piKey)\n\nlet pi: Double = cache.get(.piKey) ?? 0\n\ntry t.assert(pi, isEqualTo: .pi)\n\nlet resolvedValue: Double = try cache.resolve(.piKey)\n\ntry t.assert(resolvedValue, isEqualTo: .pi)\n                    \ncache.remove(.piKey)\n\nlet nilValue: Double? = cache.get(.piKey)\n\ntry t.assert(isNil: nilValue)\n```\n\n### JSON\n```swift\nenum MockJSONKey: String, Hashable {\n    case name, number, bool, invalid_key\n}\n\nstruct MockJSON: Codable {\n    var name: String\n    var number: Int\n    var bool: Bool\n}\n\nlet jsonData: Data = try! JSONEncoder().encode(MockJSON(name: \"Twitch\", number: 5, bool: false))\n\nlet json: c.JSON\u003cMockJSONKey\u003e = .init(data: jsonData)\n\nXCTAssertEqual(try! json.resolve(.name), \"Twitch\")\nXCTAssertEqual(try! json.resolve(.number), 5)\nXCTAssertEqual(try! json.resolve(.bool), false)\n\nlet invalid_key: Bool? = json.get(.invalid_key)\n\nXCTAssertNil(json.get(.invalid_key))\nXCTAssertNil(invalid_key)\n\njson.set(value: \"Leif\", forKey: .name)\n\nXCTAssertEqual(try! json.resolve(.name), \"Leif\")\n```\n\n\n### Global Cache\n\n```swift\nlet someCache: Cache = ...\n\n// Set the value of a Cache with any hashable key\nc.set(value: someCache, forKey: \"someCache\")\n\n// Get an optional Cache using any hashable key\nlet anotherCache: Cache? = c.get(0)\n\n// Require that a Cache exist using a `.get` with a force unwrap\nlet requiredCache: Cache = try c.resolve(0)\n\nlet keyedCache: KeyedCache\u003cString\u003e = try c.resolve(...)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0xopenbytes%2Fc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F0xopenbytes%2Fc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0xopenbytes%2Fc/lists"}