{"id":17201380,"url":"https://github.com/timwspence/cats-stm","last_synced_at":"2025-04-04T17:07:17.834Z","repository":{"id":35301547,"uuid":"183214399","full_name":"TimWSpence/cats-stm","owner":"TimWSpence","description":"A STM implementation for Cats Effect","archived":false,"fork":false,"pushed_at":"2025-03-25T17:30:20.000Z","size":6585,"stargazers_count":148,"open_issues_count":11,"forks_count":17,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-28T16:06:45.663Z","etag":null,"topics":["cats","cats-effect","functional-programming","monad","scala","software-transactional-memory","transactional-memory"],"latest_commit_sha":null,"homepage":"https://timwspence.github.io/cats-stm/","language":"Scala","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/TimWSpence.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2019-04-24T11:24:40.000Z","updated_at":"2025-03-25T17:28:44.000Z","dependencies_parsed_at":"2023-02-14T18:46:29.552Z","dependency_job_id":"aa185b83-6fdc-42b0-9a2b-e5c2495d3aa4","html_url":"https://github.com/TimWSpence/cats-stm","commit_stats":{"total_commits":772,"total_committers":16,"mean_commits":48.25,"dds":0.5673575129533679,"last_synced_commit":"098e423d56af7148df69c94c99d2f430d5685201"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimWSpence%2Fcats-stm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimWSpence%2Fcats-stm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimWSpence%2Fcats-stm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimWSpence%2Fcats-stm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TimWSpence","download_url":"https://codeload.github.com/TimWSpence/cats-stm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247217180,"owners_count":20903009,"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":["cats","cats-effect","functional-programming","monad","scala","software-transactional-memory","transactional-memory"],"created_at":"2024-10-15T02:11:40.772Z","updated_at":"2025-04-04T17:07:17.806Z","avatar_url":"https://github.com/TimWSpence.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg align=\"right\" src=\"docs/static/logo.png\" height=\"200px\" style=\"padding-left: 20px\"/\u003e\n\n# Cats STM\n\n[![Build Status](https://github.com/TimWSpence/cats-stm/workflows/Continuous%20Integration/badge.svg)](https://github.com/TimWSpence/cats-stm/actions?query=workflow%3A%22Continuous+Integration%22)\n[![Latest version](https://index.scala-lang.org/timwspence/cats-stm/cats-stm/latest.svg?color=orange)](https://index.scala-lang.org/timwspence/cats-stm/cats-stm)\n[![Discord](https://img.shields.io/discord/632277896739946517.svg?label=\u0026logo=discord\u0026logoColor=ffffff\u0026color=404244\u0026labelColor=6A7EC2)](https://discord.gg/QNnHKHq5Ts)\n[![Scala Steward badge](https://img.shields.io/badge/Scala_Steward-helping-blue.svg?style=flat\u0026logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAQCAMAAAARSr4IAAAAVFBMVEUAAACHjojlOy5NWlrKzcYRKjGFjIbp293YycuLa3pYY2LSqql4f3pCUFTgSjNodYRmcXUsPD/NTTbjRS+2jomhgnzNc223cGvZS0HaSD0XLjbaSjElhIr+AAAAAXRSTlMAQObYZgAAAHlJREFUCNdNyosOwyAIhWHAQS1Vt7a77/3fcxxdmv0xwmckutAR1nkm4ggbyEcg/wWmlGLDAA3oL50xi6fk5ffZ3E2E3QfZDCcCN2YtbEWZt+Drc6u6rlqv7Uk0LdKqqr5rk2UCRXOk0vmQKGfc94nOJyQjouF9H/wCc9gECEYfONoAAAAASUVORK5CYII=)](https://scala-steward.org)\n\nComposable in-memory transactions for [Cats\nEffect](https://typelevel.org/cats-effect/) which will handle locking,\noptimistic concurrency and automatic retries for you. The STM runtime takes care\nof acquiring locks in the correct order so your transactions are safe and should\nnot deadlock. This locking is optimistic so it will only acquire the minimal set\nof locks and only when necessary to commit the result of a transaction.\n\nFor more information, see the\n[microsite](https://timwspence.github.io/cats-stm/).\n\n### Example\n\n```scala\nimport scala.concurrent.duration._\n\nimport cats.effect.{IO, IOApp}\n\nimport io.github.timwspence.cats.stm.__\n\nobject Main extends IOApp.Simple {\n\n  override def run: IO[Unit] = STM.runtime[IO].flatMap(run(_))\n\n  def run(stm: STM[IO]): IO[Unit] = {\n    import stm._\n\n    def transfer(accountForTim: TVar[Long], accountForSteve: TVar[Long]): IO[Unit] =\n      stm.commit {\n        for {\n          balance \u003c- accountForTim.get\n          _       \u003c- stm.check(balance \u003e 100)\n          _       \u003c- accountForTim.modify(_ - 100)\n          _       \u003c- accountForSteve.modify(_ + 100)\n        } yield ()\n      }\n\n    def giveTimMoreMoney(accountForTim: TVar[Long]): IO[Unit] =\n      for {\n        _ \u003c- IO.sleep(5000.millis)\n        _ \u003c- stm.commit(accountForTim.modify(_ + 1))\n      } yield ()\n\n    def printBalances(accountForTim: TVar[Long], accountForSteve: TVar[Long]): IO[Unit] =\n      for {\n        t \u003c- stm.commit(for {\n          t \u003c- accountForTim.get\n          s \u003c- accountForSteve.get\n        } yield (t, s))\n        (amountForTim, amountForSteve) = t\n        _ \u003c- IO(println(s\"Tim: $amountForTim\"))\n        _ \u003c- IO(println(s\"Steve: $amountForSteve\"))\n      } yield ()\n\n    for {\n      accountForTim   \u003c- stm.commit(TVar.of[Long](100))\n      accountForSteve \u003c- stm.commit(TVar.of[Long](0))\n      _               \u003c- printBalances(accountForTim, accountForSteve)\n      _               \u003c- giveTimMoreMoney(accountForTim).start\n      _               \u003c- transfer(accountForTim, accountForSteve)\n      _               \u003c- printBalances(accountForTim, accountForSteve)\n    } yield ()\n\n  }\n\n}\n```\n\n### Documentation\n\nThe documentation is built using [docusaurus](https://docusaurus.io/). You can\ngenerate it via `nix-shell --run \"sbt docs/docusaurusCreateSite\"` . You can then\nview it via `nix-shell --run \"cd website \u0026\u0026 npm start\"`.\n\n### Credits\n\nThis software was inspired by [Beautiful Concurrency](https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/beautiful.pdf) and the [stm package](http://hackage.haskell.org/package/stm).\n\nMany thanks to [@impurepics](https://twitter.com/impurepics) for the awesome logo!\n\n## Tool Sponsorship\n\n\u003cimg width=\"185px\" height=\"44px\" align=\"right\" src=\"https://www.yourkit.com/images/yklogo.png\"/\u003eDevelopment of Cats STM is generously supported in part by [YourKit](https://www.yourkit.com) through the use of their excellent Java profiler.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimwspence%2Fcats-stm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimwspence%2Fcats-stm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimwspence%2Fcats-stm/lists"}