Question: package functional import functional.data. { Graph , Tree } trait Foldable [ F [ _ ] ] : def fold Monoid [ A ] def
package functional
import functional.data.Graph Tree
trait FoldableF:
def fold Monoid
def foldMap Monoid :
object ListFoldable extends FoldableList:
override def fold : List m: Monoid : match
case Nil mempty
case fold
override def foldMap List Monoid
object TreeFoldable TODO
object GraphFoldable TODO
def wordCountFt: FStringf: FoldableF: Int
def charCountFt: FStringf: FoldableF: Int
a Implement foldables points
The foldables for the data structures List, Tree and Graph need to be implemented.
Important: The given interfaces do not use any implicit parameters. You need to find the appropriate monoids explicitly
passed as a parameter.
Hints:
Two graphs can be merged using the monoid GraphMerge see task
The neighboring nodes of a graph can be edited using ListFoldable.
b Apply foldables points
Task: Implement the two methods wordCount and charCount in functional.Foldable. The method
Example: wordCountListhello world", "foo bar"ListFoldable
charCount should return the total number of characters in the strings contained within the foldable data structure.
Example: charCountListhello world", "foo bar"ListFoldable
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
