does Algebra have scaladocs page?

I’ve this problem

I have defined a function

`override def value(implicit monoid: Monoid[Int]): Int = monoid.combineAll(payload.withDefaultValue(0).valuesIterator)`

but when I try to compile this with a simple test I get back could not find implicit value for parameter monoid

```
[error] /Users/schrepfler/Documents/sources/crdt-kit/src/test/scala/net/sigmalab/crdt/GCounterImplTest.scala:17: could not find implicit value for parameter monoid: algebra.Monoid[Int]
[error] assert(0 == counter123.value)
```

Monoid is algebra’s monoid

I’m trying to make this value work for things other than Int

do you have an

`implicit Monoid[Int]`

in scope?
currently algebra doesn't provide a default

`Monoid[Int]`

-- this is probably what is tripping you up
(and it's something that @johnynek and i were just talking about fixing.)

I’ve first tried to add it to my class (GCounterImpl)

that didn’t work

but then I’ve imported

`cats.implicits_`

to my test and that worked
what did you add to you class exactly?

to the class nothing

the implicit needs to be in scope at all call sites

@schrepfler the

`MonoidInstances`

for the standard types aren't in the `Monoid`

companion object or their own companion object.
You always need to import the implicits for those.

that’s fine to leave it as it is, you might just want to be clear how it works.

this works because where you call the code, your import includes importing an

`implicit Monoid[Int]`

.
If you're happy if that particular instance, you can just remove the

`implicit`

from the method since you know the type.
and add the import in the class.

you could define your own on line 10 here: https://github.com/schrepfler/crdt-kit/blob/master/src/test/scala/net/sigmalab/crdt/GCounterImplTest.scala#L10

and it would also work:

I want to refactor this further and support all things algebra monoid supports

so not only ints

```
implicit val intM: Monoid[Int] = new Monoid[Int] { def empty = 0
def combine(a: Int, b: Int) = a + b }
```

Ah, ok. Then you'll have to remember to import for the std types.

@sp(Int, Long, Float, Double)

also, I think you want

`CommutativeMonoid`

there are lots or commutative monoids you might want to use with this (max of a timestamp can be interesting)

(hyperloglog to get approximate unique counts)

also, for crdts, you might want to look at

`Semilattice`

which is a main property that CRDTs are using.
wait...

schrepfler @schrepfler Java developer continues nodding with the head pretending to understand :)

you are using

`Monoid[Int]`

I think you want `Monoid[T]`

and replace `Int`

with `T`

everywhere
commutative monoid means

`a + b == b + a`

yes I do

that’s the next step

which is what you want with a distributed counter

:D

indeed

also, I don’t see why you have

`assert(amt >= 0, s"GCounters can only grow, increment $amt is negative”)`

I don’t see why you care if counters are positive, and that is not well defined for a lot of interesting cases

`Semilattice`

is in algebra, and it means `combine(a, a) == a`

like max, or min.

CRDTs use this, and I assume you are doing something with crdts based on the name of the project

I’ve followed Noel Welsh’s presentation more/less

and try to be faithfull to that

`comprehensive`

review of CRDT’s abstract
as far as API goes

I don’t remember now why it could only hold this property for growing only to be honest, need to revisit it

honestly, you are probably better off using

`Numeric`

which is built into scala, or `spire`

or `algebird`

if you just want to get something going
I imagine it is because the CRDT is going to use the max semilattice down the line, which is going to fail if you do subtraction

but just a guess...

probably

for that use case I’ll implement the PNCounter

which is essentially made of two GCounters

(also, note, your GCounter type would have Monoid[GCounter[Id, T, E]] if there is a Monoid[E])

spire’s Numeric seems ok

for what you have here: http://www.scala-lang.org/api/2.11.8/#scala.math.Numeric that would work

so then Monoid[T :> s.m.Numeric] ?

algebra, algebird, cats, spire, etc… are about writing abstract, and reusable code. Here it is pretty concrete.

no.

if you have a

`Numeric[T]`

you can build a `Monoid[T]`

but not in the way you have above.
`def fromNumeric[T](num: Numeric[T]): Monoid[T] = …`

not

`Monoid[T >: Numeric]`