Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #1312 - NonEmptySet#removeNonEmpty #1322

Open
wants to merge 1 commit into
base: series/1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ object NonEmptySetSpec extends DefaultRunnableSpec {
val expected = as.map(f).flatten
actual <-> expected
}
},
testM("removeNonEmpty") {
check(genSet) { as =>
val toRemove = as.head
val actual = NonEmptySet.fromSetOption(as).get.removeNonEmpty(toRemove).map(_.toSet)
val modified = as - toRemove
val expected = Option(modified).filter(_.nonEmpty)
actual <-> expected
}
}
),
suite("constructors")(
Expand Down
2 changes: 1 addition & 1 deletion core/shared/src/main/scala/zio/prelude/NonEmptySet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ final class NonEmptySet[A] private (private val set: Set[A]) { self =>
*/
def removeNonEmpty(elem: A): Option[NonEmptySet[A]] = {
val newSet = set - elem
if (newSet.nonEmpty) Some(new NonEmptySet(set)) else None
if (newSet.nonEmpty) Some(new NonEmptySet(newSet)) else None
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ final class NonEmptySortedSet[A] private (private val set: SortedSet[A]) { self
*/
def removeNonEmpty(elem: A): Option[NonEmptySortedSet[A]] = {
val newSet = set - elem
if (newSet.nonEmpty) Some(new NonEmptySortedSet(set)) else None
if (newSet.nonEmpty) Some(new NonEmptySortedSet(newSet)) else None
}

/**
Expand Down
Loading