{"id":18394431,"url":"https://github.com/romac/choreo","last_synced_at":"2025-04-14T08:31:57.804Z","repository":{"id":222889363,"uuid":"749888408","full_name":"romac/choreo","owner":"romac","description":"Choreographic programming in Scala","archived":false,"fork":false,"pushed_at":"2024-02-08T17:07:25.000Z","size":45,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-27T22:05:34.023Z","etag":null,"topics":["haschor","scala"],"latest_commit_sha":null,"homepage":"","language":"Scala","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/romac.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}},"created_at":"2024-01-29T15:44:26.000Z","updated_at":"2024-06-27T23:25:41.000Z","dependencies_parsed_at":"2024-02-16T20:40:33.063Z","dependency_job_id":null,"html_url":"https://github.com/romac/choreo","commit_stats":null,"previous_names":["romac/choreo"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romac%2Fchoreo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romac%2Fchoreo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romac%2Fchoreo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romac%2Fchoreo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/romac","download_url":"https://codeload.github.com/romac/choreo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248845906,"owners_count":21170867,"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":["haschor","scala"],"created_at":"2024-11-06T02:05:44.189Z","updated_at":"2025-04-14T08:31:57.752Z","avatar_url":"https://github.com/romac.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Continuous Integration][ci-badge]][ci-link]\n\n# Choreo\n\nA library for choregraphic programming in Scala.\n\nThe implementation is based on the paper [_HasChor: Functional Choreographic Programming for All_][haschor-paper] by Gan Shen, Shun Kashiwa and Lindsey Kuper, \nand its [Haskell implementation][haschor-github].\n\n## Example\n\n```scala\npackage choreo\npackage examples\npackage kv\n\nimport cats.effect.IO\nimport cats.effect.IO.asyncForIO\nimport cats.effect.kernel.Ref\nimport cats.syntax.all.*\n\ntype State = Map[String, String]\n\nenum Request:\n  case Get(key: String)\n  case Put(key: String, value: String)\n\ntype Response = Option[String]\n\nval client: \"client\" = \"client\"\nval server: \"server\" = \"server\"\n\ndef main: IO[Unit] =\n  for\n    backend \u003c- Backend.local(List(client, server))\n    clientTask = choreo.run(backend, client)\n    serverTask = choreo.run(backend, server)\n    _ \u003c- (clientTask, serverTask).parTupled\n  yield ()\n\ndef choreo: Choreo[IO, Unit] =\n  for\n    stateS \u003c- server.locally(Ref.of[IO, State](Map.empty))\n    _ \u003c- step(stateS).foreverM\n  yield ()\n\ndef step(stateS: Ref[IO, State] @@ \"server\"): Choreo[IO, Unit] =\n  for\n    reqC \u003c- client.locally(readRequest)\n    resC \u003c- kvs(reqC, stateS)\n    _ \u003c- client.locally:\n      resC.!.fold(IO.println(\"Key not found\")):\n        IO.print(\"\u003e \") *\u003e IO.println(_)\n  yield ()\n\ndef kvs(\n    reqC: Request @@ \"client\",\n    stateS: Ref[IO, State] @@ \"server\"\n): Choreo[IO, Response @@ \"client\"] =\n  for\n    reqS \u003c- client.send(reqC).to(server)\n    resS \u003c- server.locally(handleRequest(reqS.!, stateS.!))\n    resC \u003c- server.send(resS).to(client)\n  yield resC\n\ndef handleRequest(\n    req: Request,\n    state: Ref[IO, State]\n): IO[Response] =\n  req match\n    case Request.Get(key) =\u003e\n      state.get.map(_.get(key))\n\n    case Request.Put(key, value) =\u003e\n      state.update(_.updated(key, value)).as(Some(value))\n\ndef readRequest: IO[Request] =\n  for\n    _ \u003c- IO.print(\"\u003e \")\n    line \u003c- IO.readLine\n    req \u003c- line.split(\" \") match\n      case Array(\"GET\", key) =\u003e\n        IO.pure(Request.Get(key))\n\n      case Array(\"PUT\", key, value) =\u003e\n        IO.pure(Request.Put(key, value))\n\n      case _ =\u003e\n        IO.raiseError(new Exception(\"Invalid request\"))\n  yield req\n```\n\n## License\n\nThis library is released under the same license as HasChor, namely the BSD-3 license.\n\nPlease see the [`LICENSE`](./LICENSE) within this repository for the full text of the license.\n\n[ci-badge]: https://github.com/romac/choreo/actions/workflows/ci.yml/badge.svg\n[ci-link]: https://github.com/romac/choreo/actions/workflows/ci.yml\n[haschor-paper]: https://dl.acm.org/doi/10.1145/3607849\n[haschor-github]: https://github.com/gshen42/HasChor\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fromac%2Fchoreo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fromac%2Fchoreo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fromac%2Fchoreo/lists"}