Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Nested Relations And Complex Objects In Databases Lncs 361

Authors: Serge Abiteboul ,Patrick C. Fischer ,Hans-Jorg Schek

1st Edition

ISBN: 3540511717, 978-3540511717

Students also viewed these Databases questions

Question

What is meant by Career Planning and development ?

Answered: 1 week ago

Question

What are Fringe Benefits ? List out some.

Answered: 1 week ago