Skip to content

Commit

Permalink
Simplify the toSingleBox implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
farmdawgnation committed Apr 8, 2014
1 parent 5b8b7b7 commit 2b93d76
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions core/common/src/main/scala/net/liftweb/common/Box.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,10 @@ case class ListOfBoxes[T](theListOfBoxes: List[Box[T]]) {
* @return A Full[List[T]] if no Failures were present. ParamFailure[List[Box[T]]] otherwise.
**/
def toSingleBox(failureErrorMessage: String): Box[List[T]] = {
val fulls = theListOfBoxes.collect {
case aFull: Full[T] => aFull
}

val failures = theListOfBoxes.collect {
case failureBox: Failure => failureBox
}

if (failures.isEmpty) {
Full(fulls.map(_.value))
} else {
if (theListOfBoxes.exists(_.isInstanceOf[Failure])) {
Failure(failureErrorMessage) ~> theListOfBoxes
} else {
Full(theListOfBoxes.flatten)
}
}
}
Expand Down

0 comments on commit 2b93d76

Please sign in to comment.