question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Integration of MapRef into cats-effect

See original GitHub issue

MapRef is a fairly simple abstraction that is one of the most critical tools for more advanced concurrent state machines. I propose it move into cats-effect in std that way everyone can leverage it. The name is just what has been used, but its by no means the only name that could be used for it.

https://github.com/davenverse/mapref

trait MapRef[F[_], K, V] extends Function1[K, Ref[F, V]]{
  def apply(k: K): Ref[F, V]
}

This is then implemented for a variety of implementations ConcurrentHashMap, Ref[F, Map[K, V]], Array[Ref[Map[K, V]], etc.

These all expose MapRef[F, K, Option[V]] which when none are not present in the underlying storage and hence does not space leak per key on empty. This is then enhanced via defaulted which lifts MapRef[F, K, Option[V]] => MapRef[F, K, V] where some default value is instead removed from the map. Giving you a fully keyed state machine with no changes to the underlying state machinery.

This is already the baseline for mules, single-fibered, ratelimit, lock, as well as its in process of use for keysemaphore, and used as a keyedcircuit for rediculous concurrent. As well as keypool advanced. The use cases continue to expand as a dominating number of state machines are actually keyed.

This is a fairly fundamental abstraction that enables a whole class of state machines that the current ref/deferred alone do not permit without space leak concerns or building something equivalent to this.

Your thoughts are appreciated.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:6
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rossabakercommented, Oct 21, 2021

The bar is high, but he demos this like once or twice a week at work as the underpinning of something else. The uses are real!

0reactions
ChristopherDavenportcommented, Oct 21, 2021

I’ll try to get it done as soon as I can. 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

typelevel/cats-effect - Gitter
@ChristopherDavenport : In my test case I create only one object, which constains only one Ref . So, it is created only once....
Read more >
Releases · davenverse/mapref - GitHub
Contribute to davenverse/mapref development by creating an account on GitHub. ... Update for Cats-Effect 3; Add Invariant Instance. Assets 2.
Read more >
MapRef - Typelevel
This is a total map from K to Ref[F, V]. This allows us to use the Ref API backed by a ConcurrentHashMap or...
Read more >
Typelevel Ecosystem
Cats Effect, High-performance, asynchronous, composable framework for building real-world applications in a purely functional style.
Read more >
Migration Guide · Cats Effect - Typelevel
Cats Effect 3 splits the code dependency into multiple modules. If you were previously using cats-effect , you can keep doing so, but...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found