1

Note: This question is based on rethinking of my previous similar question.

I would like to know if Erlang's sofs:partition does the same thing which is described in Wikipedia's page about Set partitions.

If it does, how can I get the following result?

Given a data structure (a set of sets or a list of lists):

   [a,b,c]
    [a,b]
    [c]
    [d,e,f]
    [d,f]
    [e]

which contains the following unique elements:

a,b,c,d,e,f

the result of running the function with the argument N = 2 should be:

[[a,b,c], [d,e,f]]

While the following partitions should be filtered out in the process of executing sofs:partition:

[[a,b,c], [d,f], [e]]
[[a,b], [c], [d,e,f]]
[[a,b], [c], [d,f], [e]]

Can I do this with sofs:partition? If yes, can I do it iteratively, throwing out the partitions of length(Partition) =/= N during the execution? Is it possible to somehow redefine the sofs:partition function to introduce the N argument?

Community
  • 1
  • 1
skanatek
  • 5,133
  • 3
  • 47
  • 75

1 Answers1

0

You probably can just pass the result of sofs:partition to lists:foldl and filter out the partitions with wrong length manually.

If it does not fit your task (for example second run is unacceptable), you can just go take a look at sofs sources, use it as example and make your own function that does exactly what you need in one pass.

Ivan Blinkov
  • 2,466
  • 15
  • 17