exercises-cats icon indicating copy to clipboard operation
exercises-cats copied to clipboard

Monad & Foldable exercises feedback

Open ggalmazor opened this issue 8 years ago • 2 comments

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 use OptionT.
  • 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 avatar Aug 08 '16 09:08 ggalmazor

@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 Options, the 1st non-empty values would be taken

tr4rex avatar Sep 27 '18 23:09 tr4rex

Thanks for the explanation, @tr4rex!

Although it's been some time since I did the exercises, I can see what you say :)

Thanks!

ggalmazor avatar Sep 28 '18 07:09 ggalmazor