Skip to content

Commit

Permalink
Move reverse to the accumulator & remove TODO
Browse files Browse the repository at this point in the history
  • Loading branch information
adamw committed Aug 17, 2023
1 parent e0425c9 commit ea43d96
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions core/src/main/scala/sttp/model/headers/AcceptEncoding.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import sttp.model.internal.Validate.RichEither
import scala.annotation.tailrec

case class AcceptEncoding(encodings: List[WeightedEncoding]) {

override def toString: String = encodings.map(_.toString).mkString(",")
}

Expand All @@ -22,7 +21,7 @@ object AcceptEncoding {
else {
@tailrec
def go(es: List[WeightedEncoding], validated: List[WeightedEncoding]): Either[String, AcceptEncoding] = es match {
case Nil => Right(AcceptEncoding(validated))
case Nil => Right(AcceptEncoding(validated.reverse))
case head :: tail =>
validate(head, str) match {
case Left(s) => Left(s)
Expand All @@ -35,7 +34,7 @@ object AcceptEncoding {
}

private def processString(str: String): List[WeightedEncoding] =
str.trim.split(",").map(x => parsSingleEncoding(x.trim)).reverse.toList // TODO: do we really need `.reverse` here?
str.trim.split(",").map(x => parsSingleEncoding(x.trim)).toList

private def parsSingleEncoding(s: String): WeightedEncoding =
s.split(";") match {
Expand Down

0 comments on commit ea43d96

Please sign in to comment.