In the context of a programmer newly learning functional programming and completing the online Scala Exercises for Cats here, the following result seems puzzling:
import cats._
import cats.implicits._
object Foo {
def main(args: Array[String]): Unit =
println(Foldable[List].fold(List(None, Option("two"), Option("three"))))
//Some("twothree")
println(Foldable[List].foldK(List(None, Option("two"), Option("three"))))
//Some("two")
}
I can follow the example for fold but not for foldK. The documentation for foldK says:
This method is identical to fold, except that we use the universal monoid (
MonoidK[G]) to get aMonoid[G[A]]instance.
I don't understand how this difference would cause the behaviour seen above where somehow the third element in the list (Option("three")) is "ignored" for the foldK.
Can someone please explain?