Question: 3 a ) Implement Functors ( 4 points ) Task: Complete the implementations of the functors in functional.Functor. Extend the given objects so that they

3a) Implement Functors (4 points)
Task: Complete the implementations of the functors in functional.Functor. Extend the given objects so that they inherit from Functor and implement the necessary methods.
The functors for the data structures Option, Tree and Graph need to be implemented. 3b) Apply functors (1 point)
Task: Combine ListFunctor and OptionFunctor to implement capitalizeNames method. This receives a list of names for which some entries are not present (hence the type Option[String]). The method is intended to transform the input so that after execution the first letter of all existing entries is capitalized.
Example: capitalizeNames(List(Some("max"), None))== List(Some("Max"), None)
Note: You can use the String.capitalize method to implement it.
package functional
import functional.data.{Graph, Tree}
trait Foldable[F[_]]:
def fold[A](t: F[A])(m: Monoid[A]): A
def foldMap[A, B](t: F[A])(f: A => B)(m: Monoid[B]): B
object ListFoldable extends Foldable[List]:
override def fold[A](t: List[A])(m: Monoid[A]): A = t match
case Nil => m.empty
case hd :: tl => m.combine(hd, fold(tl)(m))
override def foldMap[A, B](t: List[A])(f: A => B)(m: Monoid[B]): B =???
object TreeFoldable // TODO
object GraphFoldable // TODO
def wordCount[F[_]](t: F[String])(f: Foldable[F]): Int =???
def charCount[F[_]](t: F[String])(f: Foldable[F]): Int =???

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!