Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monad & Foldable exercises feedback #37

Open
ggalmazor opened this issue Aug 8, 2016 · 2 comments
Open

Monad & Foldable exercises feedback #37

ggalmazor opened this issue Aug 8, 2016 · 2 comments

Comments

@ggalmazor
Copy link

ggalmazor commented Aug 8, 2016

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"))
@tr4rex
Copy link
Contributor

tr4rex commented Sep 27, 2018

@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

@ggalmazor
Copy link
Author

Thanks for the explanation, @tr4rex!

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

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants