Recursive set union: how does it work really?

前端 未结 6 2044
梦谈多话
梦谈多话 2020-12-13 14:29

I am currently taking the Scala course on Coursera on my free time after work, in an attempt to finally give a try to functional programming. I am currently working on an as

6条回答
  •  孤城傲影
    2020-12-13 15:20

    So based on all the responses above, I think the real workhorse is incl and the recursive way of calling union is just for going through all the elements in the sets.

    I came up with the following implementation of union, is this better?

    def union(other:BTSet) :BTSet = right union (left union (other incl element))
    

提交回复
热议问题