Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
9 changes: 9 additions & 0 deletions core-tests/shared/src/test/scala/zio/NonEmptyChunkSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ object NonEmptyChunkSpec extends ZIOBaseSpec {
}
val expected = None
assert(actual)(equalTo(expected))
},
test("matches a NonEmptyChunk") {
val nonEmptyChunk = NonEmptyChunk(1, 2, 3)
val actual = nonEmptyChunk match {
case NonEmptyChunk(x, y, z) => Some((x, y, z))
case _ => None
}
val expected = Some((1, 2, 3))
assert(actual)(equalTo(expected))
}
)
)
Expand Down
8 changes: 7 additions & 1 deletion core/shared/src/main/scala/zio/NonEmptyChunk.scala
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,20 @@ object NonEmptyChunk {
NonEmptyChunk(a)

/**
* Extracts the elements from a `NonEmptyChunk`.
* Extracts the elements from a `Chunk`.
*/
def unapplySeq[A](seq: Seq[A]): Option[Seq[A]] =
seq match {
case chunk: Chunk[A] if chunk.nonEmpty => Some(chunk)
case _ => None
}

/**
* Extracts the elements from a `NonEmptyChunk`.
*/
def unapplySeq[A](nonEmptyChunk: NonEmptyChunk[A]): Some[Seq[A]] =
Some(nonEmptyChunk.chunk)

/**
* The unit non-empty chunk.
*/
Expand Down