3 ms·
Agreed. Example from Scala // Given an Option val maybeThing: Option[String] = getThing() // Classic if (maybeThing.isDefined) { useThing(maybeT
by therealdrag0 4y ago
Agreed. Example from Scala
// Given an Option
val maybeThing: Option[String] = getThing()
// Classic
if (maybeThing.isDefined) {
useThing(maybeThing.get)
} else {
NotFoundResponseEtc()
}
// Pattern matching (not too IDE auto generated exhaustive match cases!)
maybeThing match {
case Some(thing) => useThing(thing)
case None => NotFoundResponseEtc()
}
This scales well when matching a higher cardinality of things like a variety of Exceptions or enums or other tuple responses like Either etc.