I tried to look for some algorithms to find all of the sub lists of a given list and this is what I found:
The only sublist of the empty list is the empty list. The sublists of x:xs (i.e. the list with the head x and the tail xs) are all of the sublists of xs as well as each of the sublists of xs with x prepended to them.
taken from Sublists of a list using list comprehension
Here is what I implemented:
def combinations(occurrences: Occurrences): List[Occurrences] = occurrences match{
case List() => List()
case x::xs => combinations(xs) ::: combinations(x :: xs)
}
This function gives a stack overflow error as I expected however in the example from that question it worked for him. It might've been that I misunderstood the principle he explained? How could I tackle such a problem using recursion? Where was my mistake here?
Where can I look for such an algorithm?