Hey guys, is the following a correct explanation, ...
# arrow
b
Hey guys, is the following a correct explanation, and do you think it is understandable for a beginner?
Copy code
interface OptionFunctor : Functor<ForOption> {

    // TODO don't start reading this
    // TODO ... here we basically do the same thing as when we implemented combine for IntSemigroup
    // TODO we reuse functionality from the underlying type Option, namely the map method
    // TODO but there is unfortunate boilerplate here, that will go away with arrow-meta
    // TODO namely we have to call fix() which is nothing more than a safe downcast from the HigherKind
    // TODO which we need to have access to the implementation of map in Option
    override fun <A, B> Kind<ForOption, A>.map(f: (A) -> B): Kind<ForOption, B> =
        fix().map(f)


    // TODO start here
    // TODO we were able to implement combine by reusing functionality that "was already given for the type Int"
    // TODO the plus operator -> now read above
    interface IntSemigroup : Semigroup<Int> {
        override fun Int.combine(b: Int): Int = this + b
    }
    interface Semigroup<A> {
        fun A.combine(b: A): A
    }

}