Without Scalaz, you are going to pay RY. But I would write this as:
_minVal = _minVal map (candidate min) orElse Some(candidate)
EDIT
Eric Torreborr , Specs / Specs2 , was enough to pursue a Scalaz decision that eluded me. As a testing guy, he wrote the answer in a test format instead of the obligatory, side effect of the original. :-)
Here's a version that uses _minVal , Double instead of Int , side effects and some of the highlights now that Eric has done the hard work.
// From the question (candidate provided for testing purposes) var _minVal: Option[Double] = None def candidate = scala.util.Random.nextDouble // A function "min" def min = (_: Double) min (_: Double) // A function "orElse" def orElse = (_: Option[Double]) orElse (_: Option[Double]) // Extract function to decrease noise def updateMin = _minVal map min.curried(_: Double) // This is the Scalaz vesion for the above -- type inference is not kind to it // def updateMin = (_minVal map min.curried).sequence[({type lambda[a] = (Double => a)})
source share