package convert
Ordering
- Alphabetic
Visibility
- Public
- All
Type Members
-
sealed
trait
Convert
extends AnyRef
An object for handling a conversion between two types.
An object for handling a conversion between two types.
Convert.Valid returns the result of a conversion as is, and throws an exception if the conversion fails.
Convert.Any returns the result of a conversion wrapped in an Option, and returns None if the conversion fails.
/* Convert a string to a boolean */ def parseBoolean(s: String)(implicit c: Convert): c.Result[Boolean] = { c.conversion { s.toLowerCase match { case "true" => true case "false" => false case _ => c.fail(new IllegalArgumentException(s"'$s' is not 'true' or 'false'")) } } } val res1: Boolean = parseBoolean("true")(Convert.Valid) val res2: Option[Boolean] = parseBoolean("true")(Convert.Any)
Example: