ifThen

inline fun <A, B> Iterable<A>.ifThen(fb: Iterable<B>, ffa: (A) -> Iterable<B>): Iterable<B>(source)

Logical conditional. The equivalent of Prolog's soft-cut. If its first argument succeeds at all, then the results will be fed into the success branch. Otherwise, the failure branch is taken.

import arrow.core.*

fun main(args: Array<String>) {
//sampleStart
val result =
listOf(1,2,3).ifThen(listOf("empty")) { i ->
listOf("$i, ${i + 1}")
}
//sampleEnd
println(result)
}

fun <A, B> Sequence<A>.ifThen(fb: Sequence<B>, ffa: (A) -> Sequence<B>): Sequence<B>(source)

Logical conditional. The equivalent of Prolog's soft-cut. If its first argument succeeds at all, then the results will be fed into the success branch. Otherwise, the failure branch is taken.

import arrow.core.ifThen

fun main(args: Array<String>) {
//sampleStart
val result =
sequenceOf(1,2,3).ifThen(sequenceOf("empty")) { i ->
sequenceOf("$i, ${i + 1}")
}
//sampleEnd
println(result.toList())
}