Just looked around cats and scalaz: Both don't def...
# arrow
j
Just looked around cats and scalaz: Both don't define default instances. Something like this is how haskell handles this:
Copy code
inline class All(val getAll: Boolean) {
    companion object {
        fun monoid(): Monoid<All> = object: AllMonoid {}
    }
}
interface AllMonoid : Monoid<All> {
    override fun empty(): All = All(true)
    override fun All.combine(b: All): All = All(getAll && b.getAll)
}
inline class Any(val getAll: Boolean) {
    companion object {
        fun monoid(): Monoid<Any> = object: AnyMonoid {}
    }
}
interface AnyMonoid : Monoid<Any> {
    override fun empty(): Any = Any(true)
    override fun Any.combine(b: Any): Any = Any(getAll || b.getAll)
}