ifThen

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

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> <ERROR CLASS><A>.ifThen(fb: <ERROR CLASS><B>, ffa: (A) -> <ERROR CLASS><B>): <ERROR CLASS><B>

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())
}