cats icon indicating copy to clipboard operation
cats copied to clipboard

Instances for Currency

Open massimosiani opened this issue 1 year ago • 7 comments

Hi, I often work with the java Currency type, but wasn't able to find the basic instances for that, e.g. Show and Eq. I also looked in the mouse project. Would them be a good fit somewhere?

massimosiani avatar Feb 19 '24 18:02 massimosiani

Every time I ask "why don't we support ____" from java.*, the answer is lacking support in Scala.js and/or Scala Native. Unless that's also the problem here, I see no reason not to support them.

rossabaker avatar Feb 19 '24 19:02 rossabaker

Lack of support on JS/Native doesn't need to stop us. We can add the instances only for JVM, or add them for all platforms but test only on JVM.

armanbilge avatar Feb 19 '24 19:02 armanbilge

Check out the Typelevel Squants project, one of my favorite projects. Squants includes type-safe value objects representing daily things, including currency.

import squants.market._

val usd3 = USD(30) usd3.toFormattedString should be ("$30.00");

val usd = USD(30) val usd2 = USD(50) val total = usd + usd2 total should be(USD(80))

On Mon, Feb 19, 2024 at 12:21 PM Arman Bilge @.***> wrote:

Lack of support on JS/Native doesn't need to stop us. We can add the instances only for JVM, or add them for all platforms but test only on JVM.

— Reply to this email directly, view it on GitHub https://github.com/typelevel/cats/issues/4562#issuecomment-1953049943, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADEJBLDQBCGKMZ5J3SN4E3YUOQ3HAVCNFSM6AAAAABDP52CFWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNJTGA2DSOJUGM . You are receiving this because you are subscribed to this thread.Message ID: @.***>

dhinojosa avatar Feb 19 '24 19:02 dhinojosa

Lack of support on JS/Native doesn't need to stop us. We can add the instances only for JVM, or add them for all platforms but test only on JVM.

Some times we found libraries that filled the gap, like scala-java-time in cats-time.

TonioGela avatar Feb 20 '24 08:02 TonioGela

Actually there was a proposal to move cats-time instances into Cats core.

  • https://github.com/typelevel/cats/pull/3910#issuecomment-979975262

armanbilge avatar Feb 20 '24 18:02 armanbilge

@dhinojosa thanks for pointing me to squants, I'll play with it and see if it suits in our project.

massimosiani avatar Feb 21 '24 22:02 massimosiani

Every time I ask "why don't we support ____" from java.*, the answer is lacking support in Scala.js and/or Scala Native. Unless that's also the problem here, I see no reason not to support them.

PRAADRONZSU avatar Apr 07 '24 22:04 PRAADRONZSU