summaryrefslogtreecommitdiffstats
path: root/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae
diff options
context:
space:
mode:
authorPiotr Jaszczyk <piotr.jaszczyk@nokia.com>2019-04-12 06:38:04 +0000
committerGerrit Code Review <gerrit@onap.org>2019-04-12 06:38:04 +0000
commit8b8385d323754903ade492a659548d54b56bd7ad (patch)
tree054cee274f2e9f4702adb232e186b9530775d1e9 /sources/hv-collector-utils/src/main/kotlin/org/onap/dcae
parent24d0a4c08237dc95c7eca55122e9c305750ce248 (diff)
parent0dd7127aa7258d8fd9d434559750c00ca49f66e6 (diff)
Merge "Extract transforming logic from validator"
Diffstat (limited to 'sources/hv-collector-utils/src/main/kotlin/org/onap/dcae')
-rw-r--r--sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/arrow/core.kt15
1 files changed, 15 insertions, 0 deletions
diff --git a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/arrow/core.kt b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/arrow/core.kt
index cfed7f32..ceae62db 100644
--- a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/arrow/core.kt
+++ b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/arrow/core.kt
@@ -17,6 +17,9 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
+@file:Suppress("TooManyFunctions")
+
package org.onap.dcae.collectors.veshv.utils.arrow
import arrow.core.Either
@@ -37,6 +40,7 @@ import java.util.concurrent.atomic.AtomicReference
* @since July 2018
*/
+
object OptionUtils {
fun <A> binding(c: suspend MonadContinuation<ForOption, *>.() -> A)
: Option<A> = Option.monad().binding(c).fix()
@@ -78,6 +82,17 @@ fun <A> Try<A>.doOnFailure(action: (Throwable) -> Unit): Try<A> = apply {
fun <A, B> A.mapBinding(c: suspend MonadContinuation<ForOption, *>.(A) -> B)
: Option<B> = let { OptionUtils.binding { c(it) } }
+fun <T> Option<Boolean>.flatFold(ifEmptyOrFalse: () -> T, ifTrue: () -> T) =
+ fold({
+ ifEmptyOrFalse()
+ }, {
+ if (it) {
+ ifTrue()
+ } else {
+ ifEmptyOrFalse()
+ }
+ })
+