This is the code snippet:
OS.config flatMap {_.Allocation } flatMap {_.memory}
The value obtained from the memory parameter is Option[Long].
How can I compare and check if it is greater than zero?
I tried using filter, but the answer obtained is Option[Boolean]. I need to check for many objects and if the value is greater than zero increment the counter.
You could use the exists method. This method, when run on an option, takes a function that returns a boolean. If your Option is a None, it will return false.
eg.
scala> var x = Some(123)
x: Some[Int] = Some(123)
scala> x.exists(_ > 0)
res0: Boolean = true
scala> x.exists(_ < 0)
res1: Boolean = false
You can fold over it to either get false if it hasn't been specified or check if it's greater than 0:
(OS.config flatMap {_.Allocation } flatMap {_.memory}).fold(false)(_ > 0)
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