Scala set function

后端 未结 6 1885
忘掉有多难
忘掉有多难 2020-12-13 08:04

In Stanford Scala course I\'ve come across the following assignment:

Exercise 1 – Sets as Functions:

In this exercise we will represent sets

6条回答
  •  独厮守ぢ
    2020-12-13 08:17

    We have

    Set A = 
        Returns the intersection of the two given sets,
        the set of all elements that are both in `s` and `t`.
    
    Set B = 
        Returns the subset of `s` for which `p` holds.
    

    Isn't Set A is equivalent to Set B

    def filter(s: Set, p: Int => Boolean): Set = intersect(s, p)
    

提交回复
热议问题