Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
fp2023:lab06 [2023/04/04 13:33]
pdmatei
fp2023:lab06 [2023/04/10 10:53] (current)
pdmatei
Line 69: Line 69:
 The function ''​groupBy''​ takes a list with elements of type ''​A'',​ a criterion ''​A => B''​ and produces a list of pairs ''​(c,​ lp) : (B,​List[A])''​ with the property that each member of the list ''​lp''​ satisfy the criterion with the value ''​c''​. Suppose ''​f:​ A => B''​ is a criterion. Two elements ''​a : A''​ and ''​b : A''​ satisfy the criterion ''​f''​ **iff** ''​f(a) == f(b)''​. Examples: The function ''​groupBy''​ takes a list with elements of type ''​A'',​ a criterion ''​A => B''​ and produces a list of pairs ''​(c,​ lp) : (B,​List[A])''​ with the property that each member of the list ''​lp''​ satisfy the criterion with the value ''​c''​. Suppose ''​f:​ A => B''​ is a criterion. Two elements ''​a : A''​ and ''​b : A''​ satisfy the criterion ''​f''​ **iff** ''​f(a) == f(b)''​. Examples:
 <​code>​ <​code>​
-groupBy(List("​john",​ "​mary",​ "bill"​))(_.size) = List((2,​List("​john","​mary"​)),​ (1, List("bill"))) +groupBy(List("​john",​ "​mary",​ "mihai"​))(_.size) = List((4,​List("​john","​mary"​)),​ (5, List("mihai"))) 
-groupBy(List((1,​2),​ (2,1), (3,3))(p => p._1 + p._2) = List((3,​List((1,​2),​(2,​1)),​ (6, List((3,​3)))+groupBy(List((1,​2),​ (2,1), (3,3))(p => p._1 + p._2) = List((3,​List((1,​2),​(2,​1))), (6, List((3,​3)))
 </​code>​ </​code>​
  
Line 89: Line 89:
 **6.2.3.** Write a function which checks is there exist identical names under different domains in a list of emails (e.g. ''​ana@amazon.com''​ and ''​ana@gmail.com''​) **6.2.3.** Write a function which checks is there exist identical names under different domains in a list of emails (e.g. ''​ana@amazon.com''​ and ''​ana@gmail.com''​)
 <code scala> <code scala>
-def containsDuplicates(l:​ List[Email]): ​List[Email] ​= ???+def containsDuplicates(l:​ List[Email]): ​Boolean ​= ???
 </​code>​ </​code>​
  
Line 97: Line 97:
 </​code>​ </​code>​
  
-**6.2.5.** Write a function which reports **all duplicates** of names under different domains in a list of emails. (e.g. ''​["​ana@aol.com",​ "​ana@aol.ro",​ "​jim@cx.com",​ "​mary@mail.com"​ , "​mary@mail.ro"​]''​ will produce: ''​[["​ana@aol.com",​ "​ana@aol.ro"​],​ ["​mary@mail.com"​ , "​mary@mail.ro"​]]''​+**6.2.5.** Write a function which reports **all duplicates** of names under different domains in a list of emails. (e.g. ''​["​ana@aol.com",​ "​ana@aol.ro",​ "​jim@cx.com",​ "​mary@mail.com"​ , "​mary@mail.ro"​]''​ will produce: ''​[ ["​ana@aol.com",​ "​ana@aol.ro"​],​ ["​mary@mail.com"​ , "​mary@mail.ro"​]]''​
 <code scala> <code scala>
 def extractDuplicates(l:​ List[Email]):​ List[List[Email]] = ??? def extractDuplicates(l:​ List[Email]):​ List[List[Email]] = ???
 </​code>​ </​code>​
  
-**6.2.6.** Write a function which removes **all duplicates** of names under different domains in a list of emails. (e.g. ''​["​ana@aol.com",​ "​ana@aol.ro",​ "​jim@cx.com",​ "​mary@mail.com"​ , "​mary@mail.ro"​]''​ will produce: ''​[["​ana@aol.com",​ "​ana@aol.ro"​],​ ["​mary@mail.com"​ , "​mary@mail.ro"​]]''​+**6.2.6.** Write a function which removes **all duplicates** of names under different domains in a list of emails. (e.g. ''​["​ana@aol.com",​ "​ana@aol.ro",​ "​jim@cx.com",​ "​mary@mail.com"​ , "​mary@mail.ro"​]''​ will produce: ''​[ ["​ana@aol.com",​ "​ana@aol.ro"​],​ ["​mary@mail.com"​ , "​mary@mail.ro"​]]''​
 <code scala> <code scala>
 def extractDuplicates(l:​ List[Email]):​ List[List[Email]] = ??? def extractDuplicates(l:​ List[Email]):​ List[List[Email]] = ???