Open yisraelU opened 2 months ago
While this alone is great. Wwe may also request a default value in
apply
to improve UX as suggested by @Jasper-M
I have added an overloaded apply . WDYT
I have added an overloaded apply . WDYT
Sadly I don't think that would work well: https://scastie.scala-lang.org/BalmungSan/WHoq2ShkTCm3QSs5puHixw
I think the best would be to do what Arman suggested and rather add a withDefault
(better names are welcome) extension method to MapRefOptionOps
. So that users can do:
val m1 = MapRef[IO, K, V] // Returns MapRef[IO, K, Option[V]
val m2 = m1.withDefault(foo) // Returns MapRef[IO, K, V]
I have added an overloaded apply . WDYT
Sadly I don't think that would work well: https://scastie.scala-lang.org/BalmungSan/WHoq2ShkTCm3QSs5puHixw
I think the best would be to do what Arman suggested and rather add a
withDefault
(better names are welcome) extension method toMapRefOptionOps
. So that users can do:val m1 = MapRef[IO, K, V] // Returns MapRef[IO, K, Option[V] val m2 = m1.withDefault(foo) // Returns MapRef[IO, K, V]
I see, it fails for certain types.
If we go back to empty parens for the apply method it should work.
I'm happy with the extension method solution though, and I have nothing better than withDefault
:)
Adds an apply method for MapRef. If the Effect type is an instance of Async , the
ConcurrentHashMap
implementation will be used otherwise thesharedImmutableMap
will be used with the number of shards set to the number of Processors determined byRuntime.getRuntime.availableProcessors
. The goal of this MR is to improve the UX for a user by having a sane defaultcloses #4136
P.S. as this is a first-time PR to this repo, please let me know if there are any conventions/practices, etc.. that I should be adhering to. TY