diff options
author | 2019-04-10 11:36:48 +0200 | |
---|---|---|
committer | 2019-04-12 08:20:15 +0200 | |
commit | 0dd7127aa7258d8fd9d434559750c00ca49f66e6 (patch) | |
tree | 484dfd8f93e1e52901e621203200763e2760bee1 /sources/hv-collector-utils/src/main/kotlin/org | |
parent | 6a7e8dce0126f355a0ef5663304825bea4c79a20 (diff) |
Extract transforming logic from validator
Change-Id: Ic019b1796e17d24f14f41a817af6e5ecd8c7244b
Issue-ID: DCAEGEN2-1416
Signed-off-by: Filip Krzywka <filip.krzywka@nokia.com>
Diffstat (limited to 'sources/hv-collector-utils/src/main/kotlin/org')
-rw-r--r-- | sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/arrow/core.kt | 15 |
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() + } + }) + |