Utils module
Utils module
The utils module contains several utilities.
SetUtils
Example of a utility function
partition of a set
paritition(s,n)
generates a partition of a set in n
sets whose union gives that set again
import es.weso.utils.SetUtils._
partition(Set(1,2,3),2)
// res0: es.weso.utils.internal.CollectionCompat.LazyList[List[Set[Int]]] = Stream(
// List(Set(1, 2, 3), Set()),
// List(Set(2, 3), Set(1)),
// List(Set(1, 3), Set(2)),
// List(Set(3), Set(1, 2)),
// List(Set(1, 2), Set(3)),
// List(Set(2), Set(1, 3)),
// List(Set(1), Set(2, 3)),
// List(Set(), Set(1, 2, 3))
// )
pSet
pSet(s)
generates the power set of s
, pairing each subset with its complement.
pSet(Set(1,2,3))
// res1: es.weso.utils.internal.CollectionCompat.LazyList[(Set[Int], Set[Int])] = Stream(
// (Set(1, 2, 3), Set()),
// (Set(2, 3), Set(1)),
// (Set(1, 3), Set(2)),
// (Set(3), Set(1, 2)),
// (Set(1, 2), Set(3)),
// (Set(2), Set(1, 3)),
// (Set(1), Set(2, 3)),
// (Set(), Set(1, 2, 3))
// )