Implementation of scala set.contains

前端 未结 2 1219
礼貌的吻别
礼貌的吻别 2021-01-19 19:21
type Set = Int => Boolean
/**
* Indicates whether a set contains a given element.
*/
def contains(s: Set, elem: Int): Boolean = s(elem)

Why does

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-19 20:20

    Set here is a function from Int to Boolean, so calling s(someInt) returns a boolean, you have of course to provide that function:

    def contains(s: Set, elem: Int): Boolean = s(elem)
    
    contains({ someInt => someInt == 1 }, 1) // returns true
    

提交回复
热议问题