exercises-cats
exercises-cats copied to clipboard
Monad & Foldable exercises feedback
I'm opening this issue just to give some feedback on these two exercises.
- So in Monad exercise
OptionT
is introduced. You can deduce some of its meaning from the text on the exercise but I've had to expand it with this article. Seems right but can't know it it the same thing. Also, in the article there are some nice examples to understand in what cases you'd useOptionT
. - In Foldable exercise
MonoidK
is referred out from nowhere before having explained it. Also had to go to the sources to expand on this.
It would be nice to explain why OptionT[F, A]
& MonoidK[F, A]
instead of OptionK[F, A]
& MonoidK[F, A]
or OptionT[F, A]
& MonoidT[F, A]
. Don't both suffixes mean the same thing?
- In Foldable, why, oh, why does this hold true?
Foldable[List].foldK(List(None, Option("two"), Option("three"))) should be(Some("two"))
@ggalmazor For the last point - it depends on how the values inside foldable are composed. According to the explanation in exercise:
fold, also called combineAll, combines every value in the foldable using the given Monoid instance
foldK is similar to fold but combines every value in the foldable using the given MonoidK[G] instance instead of Monoid[G]
And for Option
instance combineK
is defined as follows:
def combineK[A](x: Option[A], y: Option[A]): Option[A] = x orElse y
where orElse
is:
@inline final def orElse[B >: A](alternative: => Option[B]): Option[B] =
if (isEmpty) alternative else this
So when it goes about combining a bunch of Option
s, the 1st non-empty values would be taken
Thanks for the explanation, @tr4rex!
Although it's been some time since I did the exercises, I can see what you say :)
Thanks!