Skip to content

Commit

Permalink
add subtraction method on AtLeast2[Set, X] which yields NonEmptySet[X]
Browse files Browse the repository at this point in the history
  • Loading branch information
vreuter committed Nov 16, 2024
1 parent 112d1f9 commit 6d0763c
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions modules/pan/src/main/scala/collections.scala
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ object collections:
infix def +(x: X): AtLeast2Set[X] =
(xs + x).refineUnsafe[MinLength[2]]

def subtract(x: X)(using ord: Order[X]): NonEmptySet[X] =
NonEmptySet.fromSetUnsafe(SortedSet.from(xs - x)(using ord.toOrdering))

/** With knowledge that the given container type is an set, we can use the underlying
* collection's {@code .contains} member.
*
Expand Down

0 comments on commit 6d0763c

Please sign in to comment.