{"id":15056332,"url":"https://github.com/tomjschuster/gleam_universal_server","last_synced_at":"2026-02-08T23:35:33.225Z","repository":{"id":238948261,"uuid":"798054215","full_name":"tomjschuster/gleam_universal_server","owner":"tomjschuster","description":"A Gleam implementation of Joe Armstrong's Universal Server","archived":false,"fork":false,"pushed_at":"2024-05-10T01:17:19.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-14T06:13:03.508Z","etag":null,"topics":["beam","erlang","gleam"],"latest_commit_sha":null,"homepage":"https://joearms.github.io/published/2013-11-21-My-favorite-erlang-program.html","language":"Gleam","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/tomjschuster.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-05-09T02:14:15.000Z","updated_at":"2024-05-10T01:17:22.000Z","dependencies_parsed_at":"2024-05-09T04:23:49.149Z","dependency_job_id":"81e1f647-4e47-4049-b8d0-867a1cb2558e","html_url":"https://github.com/tomjschuster/gleam_universal_server","commit_stats":null,"previous_names":["tomjschuster/gleam_universal_server"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tomjschuster/gleam_universal_server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomjschuster%2Fgleam_universal_server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomjschuster%2Fgleam_universal_server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomjschuster%2Fgleam_universal_server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomjschuster%2Fgleam_universal_server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomjschuster","download_url":"https://codeload.github.com/tomjschuster/gleam_universal_server/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomjschuster%2Fgleam_universal_server/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268876323,"owners_count":24321982,"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","status":"online","status_checked_at":"2025-08-05T02:00:12.334Z","response_time":2576,"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":["beam","erlang","gleam"],"created_at":"2024-09-24T21:49:57.840Z","updated_at":"2026-02-08T23:35:32.366Z","avatar_url":"https://github.com/tomjschuster.png","language":"Gleam","funding_links":[],"categories":[],"sub_categories":[],"readme":"# universal_server\n\n![test workflow](https://github.com/tomjschuster/gleam_universal_server/actions/workflows/test.yml/badge.svg)\n\nA [Gleam](https://gleam.run/) implementation of the \"Universal Server\" demonstrated by Joe Armstrong in his blog post [My favorite Erlang Program](https://joearms.github.io/published/2013-11-21-My-favorite-erlang-program.html).\n\n```gleam\nimport gleam/erlang/process.{type Subject}\nimport gleam/result.{try}\nimport universal_server\n\npub fn main() {\n  use u_subject \u003c- try(universal_server.start(True))\n  use f_subject \u003c- try(universal_server.become(u_subject, factorial_server))\n\n  let u_pid = process.subject_owner(u_subject)\n  let f_pid = process.subject_owner(f_subject)\n  let assert True = u_pid == f_pid\n\n  let assert Ok(120) = compute(f_subject, 5)\n  let assert Ok(3_628_800) = compute(f_subject, 10)\n\n  Ok(Nil)\n}\n\nfn factorial_server(subject: Subject(#(Subject(Int), Int))) {\n  let #(reply_to, n) =\n    process.new_selector()\n    |\u003e process.selecting(subject, fn(m) { m })\n    |\u003e process.select_forever()\n\n  process.send(reply_to, factorial(n))\n\n  factorial_server(subject)\n}\n\nfn factorial(n: Int) -\u003e Int {\n  case n {\n    0 -\u003e 1\n    n if n \u003e 0 -\u003e n * factorial(n - 1)\n    _ -\u003e panic as \"cannot calculate negative factorial\"\n  }\n}\n\nfn compute(subject: Subject(#(Subject(Int), Int)), n: Int) -\u003e Result(Int, Nil) {\n  let reply_to = process.new_subject()\n  process.send(subject, #(reply_to, n))\n  process.receive(reply_to, 5000)\n}\n```\n\n## Development\n\n```sh\ngleam test  # Run the tests\ngleam shell # Run an Erlang shell\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomjschuster%2Fgleam_universal_server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomjschuster%2Fgleam_universal_server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomjschuster%2Fgleam_universal_server/lists"}