All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.hnau.jutils.producer.extensions.ProducerExtensionsBoolean.kt Maven / Gradle / Ivy

The newest version!
package ru.hnau.jutils.producer.extensions

import ru.hnau.jutils.*
import ru.hnau.jutils.producer.Producer


fun Producer.callIfTrue() = callIf { it }
fun Producer.callIfTrueOrNull() = callIf { it != false }
fun Producer.callIfFalse() = callIf { !it }
fun Producer.callIfFalseOrNull() = callIf { it != true }

operator fun Producer.not() = map(Boolean::not)

fun  Producer.map(forTrue: T, forFalse: T) =
        map { it.handle(forTrue = forTrue, forFalse = forFalse) }

fun  Producer.map(onTrue: () -> T, onFalse: () -> T) =
        map { it.handle(onTrue = onTrue, onFalse = onFalse) }

fun Producer.toInt() = map(Boolean::toInt)
fun Producer.toLong() = map(Boolean::toLong)
fun Producer.toByte() = map(Boolean::toByte)
fun Producer.toShort() = map(Boolean::toShort)
fun Producer.toFloat() = map(Boolean::toFloat)
fun Producer.toDouble() = map(Boolean::toDouble)




© 2015 - 2025 Weber Informatics LLC | Privacy Policy