Skip to content

Instantly share code, notes, and snippets.

@kxbmap
Created December 10, 2011 06:22
Show Gist options
  • Save kxbmap/1454688 to your computer and use it in GitHub Desktop.
Save kxbmap/1454688 to your computer and use it in GitHub Desktop.
Scalazのminimum/maximumならOptionが返るから安心
object Sample extends App {
val seq = Seq(1, 2, 3)
val empty = Seq[Int]()
println(seq.max) // -> 3
// println(empty.max) // -> java.lang.UnsupportedOperationException: empty.max
import scalaz._, Scalaz._
println(seq.maximum) // -> Some(3)
println(empty.maximum) // -> None
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment