Keep precisely those elements with no strictly smaller element in the input. Express strictness using the partial order itself, avoiding reliance on Scala reference equality.In a partial order, means and . ThereforeThe empty set produces the empty set. An incomparable pair is retained in full; a minimal element need not be a least element. At most order comparisons are needed, and only the supplied F-bounded generic interface is required.
def minimal[T <: Ordered[T]](xs: Set[T]): Set[T] =
xs.filter { x =>
!xs.exists(y => (y <= x) && !(x <= y))
} Articles by others on the same topic
There are currently no matching articles.