lambdista/money

Missing implicit value for num

Closed this issue ยท 8 comments

Hi,

I'm using yr Money class to represent product prices. I have a bill of products class that calculates totals from line items by summing using map over Vector of line items, etc. Standard stuff. I was using Double as the price, but when I switched to yr Money, I get compile errors:

[error] /Users/k/work/bofe/play/app/models/Life.scala:181: could not find implicit value for parameter num: Numeric[models.BillOfProducts.Price]
[error] val theTotal = t.map(calcItem).map(_.price).sum

Of course if I say .map(_price.amount).sum instead, it compiles, but then the return type isn't Money any more.

Thoughts?

Hi,
the compiler is complaining about not finding an implicit value of Numeric[models.BillOfProducts.Price]. Now if you say the price was a Double and then you switched to Money then you just need to provide an implementation of Numeric[Money] and be sure it's available in the scope implicitly. See Numeric for more info.

Thanks, Scala newbie here. I'll try to figure out how to implement Numeric[Money]. ๐Ÿ‘

No problem. You're welcome and keep hacking! ๐Ÿ‘

Hi,
I implemented Numeric[Money]. See README for details.

Having problems publishing the 0.2.0 version to the OSSRH repo. I'll close this issue when I'm done. However, for now, you could just use the 0.1.0 version and copy/paste my implementation of Numeric[Money].

I implemented it yesterday, too. Slightly differently. I also implemented
Ordering. I'll use yrs as soon as you get 020 pub'd.

Cheers!

On Thursday, June 18, 2015, Alessandro Lacava notifications@github.com
wrote:

Having problems publishing the 0.2.0 version to the OSSRH repo. I'll close
this issue when I'm done. However, for now, you could just use the 0.1.0
version and copy/paste my implementation of Numeric[Money].

โ€”
Reply to this email directly or view it on GitHub
#1 (comment).

Published.

Cheers!

awesome, updated and tests pass ๐Ÿ‘