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

refactor: simplify empty check #2291

Closed
Closed
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
2 changes: 1 addition & 1 deletion zio-http/src/main/scala/zio/http/Method.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ sealed trait Method { self =>
val name: String

override def toString: String =
if (name.length == 0) "<default-method>" else name
if (name.isEmpty) "<default-method>" else name
}

object Method {
Expand Down
6 changes: 3 additions & 3 deletions zio-http/src/main/scala/zio/http/Path.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ final case class Path private (flags: Path.Flags, segments: Chunk[String]) { sel
*/
def addLeadingSlash: Path =
if (hasLeadingSlash) self
else if (segments.length == 0) Path(Flags(Flag.LeadingSlash), Chunk.empty)
else if (segments.isEmpty) Path(Flags(Flag.LeadingSlash), Chunk.empty)
else Path(Flag.LeadingSlash.add(flags), segments)

/**
* Appends a trailing slash to the path.
*/
def addTrailingSlash: Path =
if (hasTrailingSlash) self
else if (segments.length == 0) Path(Flags(Flag.TrailingSlash), Chunk.empty)
else if (segments.isEmpty) Path(Flags(Flag.TrailingSlash), Chunk.empty)
else Path(Flag.TrailingSlash.add(flags), segments)

/**
Expand Down Expand Up @@ -233,7 +233,7 @@ object Path {
* Decodes a path string into a Path.
*/
def decode(path: String): Path =
if (path.length == 0) Path.empty
if (path.isEmpty) Path.empty
else {
val chunkBuilder = ChunkBuilder.make[String]()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ private[codec] object EncoderDecoder {
else {
val segment = segments(j)

if (segment.length != 0) {
if (segment.nonEmpty) {
val textCodec = flattened.path(i).erase

inputs(i) = textCodec
Expand Down Expand Up @@ -365,7 +365,7 @@ private[codec] object EncoderDecoder {
private def decodeBody(body: Body, inputs: Array[Any])(implicit trace: Trace): Task[Unit] = {
if (isByteStream) {
ZIO.attempt(inputs(0) = body.asStream.orDie)
} else if (jsonDecoders.length == 0) {
} else if (jsonDecoders.isEmpty) {
ZIO.unit
} else if (jsonDecoders.length == 1) {
jsonDecoders(0)(body).map { result => inputs(0) = result }.mapError { err =>
Expand Down Expand Up @@ -499,7 +499,7 @@ private[codec] object EncoderDecoder {
}

private def encodeStatus(inputs: Array[Any]): Option[Status] = {
if (flattened.status.length == 0) {
if (flattened.status.isEmpty) {
None
} else {
flattened.status(0) match {
Expand Down