I often find myself with an Option[T]
for some type T
and wish to test the value of the option against some value. For example:
val opt = Some("oxbow") if (opt.isDefined && opt.get == "lakes") //do something
The following code is equivalent and removes the requirement to test the existence of the value of the option
if (opt.map(_ == "lakes").getOrElse(false)) //do something
However this seems less readable to me. Other possibilities are:
if (opt.filter(_ == "lakes").isDefined) if (opt.find(_ == "lakes").isDefined) //uses implicit conversion to Iterable
But I don't think these clearly express the intent either which would be better as:
if (opt.isDefinedAnd(_ == "lakes"))
Has anyone got a better way of doing this test?
Time value is calculated by taking the difference between the option's premium and the intrinsic value, and this means that an option's premium is the sum of the intrinsic value and time value: Time Value = Option Premium - Intrinsic Value.
An option's premium is comprised of intrinsic value and extrinsic value. Intrinsic value is reflective of the actual value of the strike price versus the current market price. Extrinsic value is made up of time until expiration, implied volatility, dividends and interest rate risks.
In cost–benefit analysis and social welfare economics, the term option value refers to the value that is placed on private willingness to pay for maintaining or preserving a public asset or service even if there is little or no likelihood of the individual actually ever using it.
How about
if (opt == Some("lakes"))
This expresses the intent clearly and is straight forward.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With